]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-3.0-3.17.7-201412211910.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-3.0-3.17.7-201412211910.patch
1 diff --git a/Documentation/dontdiff b/Documentation/dontdiff
2 index 9de9813..1462492 100644
3 --- a/Documentation/dontdiff
4 +++ b/Documentation/dontdiff
5 @@ -3,9 +3,11 @@
6 *.bc
7 *.bin
8 *.bz2
9 +*.c.[012]*.*
10 *.cis
11 *.cpio
12 *.csp
13 +*.dbg
14 *.dsp
15 *.dvi
16 *.elf
17 @@ -15,6 +17,7 @@
18 *.gcov
19 *.gen.S
20 *.gif
21 +*.gmo
22 *.grep
23 *.grp
24 *.gz
25 @@ -51,14 +54,17 @@
26 *.tab.h
27 *.tex
28 *.ver
29 +*.vim
30 *.xml
31 *.xz
32 *_MODULES
33 +*_reg_safe.h
34 *_vga16.c
35 *~
36 \#*#
37 *.9
38 -.*
39 +.[^g]*
40 +.gen*
41 .*.d
42 .mm
43 53c700_d.h
44 @@ -72,9 +78,11 @@ Image
45 Module.markers
46 Module.symvers
47 PENDING
48 +PERF*
49 SCCS
50 System.map*
51 TAGS
52 +TRACEEVENT-CFLAGS
53 aconf
54 af_names.h
55 aic7*reg.h*
56 @@ -83,6 +91,7 @@ aic7*seq.h*
57 aicasm
58 aicdb.h*
59 altivec*.c
60 +ashldi3.S
61 asm-offsets.h
62 asm_offsets.h
63 autoconf.h*
64 @@ -95,32 +104,40 @@ bounds.h
65 bsetup
66 btfixupprep
67 build
68 +builtin-policy.h
69 bvmlinux
70 bzImage*
71 capability_names.h
72 capflags.c
73 classlist.h*
74 +clut_vga16.c
75 +common-cmds.h
76 comp*.log
77 compile.h*
78 conf
79 config
80 config-*
81 config_data.h*
82 +config.c
83 config.mak
84 config.mak.autogen
85 +config.tmp
86 conmakehash
87 consolemap_deftbl.c*
88 cpustr.h
89 crc32table.h*
90 cscope.*
91 defkeymap.c
92 +devicetable-offsets.h
93 devlist.h*
94 dnotify_test
95 docproc
96 dslm
97 +dtc-lexer.lex.c
98 elf2ecoff
99 elfconfig.h*
100 evergreen_reg_safe.h
101 +exception_policy.conf
102 fixdep
103 flask.h
104 fore200e_mkfirm
105 @@ -128,12 +145,15 @@ fore200e_pca_fw.c*
106 gconf
107 gconf.glade.h
108 gen-devlist
109 +gen-kdb_cmds.c
110 gen_crc32table
111 gen_init_cpio
112 generated
113 genheaders
114 genksyms
115 *_gray256.c
116 +hash
117 +hid-example
118 hpet_example
119 hugepage-mmap
120 hugepage-shm
121 @@ -148,14 +168,14 @@ int32.c
122 int4.c
123 int8.c
124 kallsyms
125 -kconfig
126 +kern_constants.h
127 keywords.c
128 ksym.c*
129 ksym.h*
130 kxgettext
131 lex.c
132 lex.*.c
133 -linux
134 +lib1funcs.S
135 logo_*.c
136 logo_*_clut224.c
137 logo_*_mono.c
138 @@ -165,14 +185,15 @@ mach-types.h
139 machtypes.h
140 map
141 map_hugetlb
142 -media
143 mconf
144 +mdp
145 miboot*
146 mk_elfconfig
147 mkboot
148 mkbugboot
149 mkcpustr
150 mkdep
151 +mkpiggy
152 mkprep
153 mkregtable
154 mktables
155 @@ -188,6 +209,8 @@ oui.c*
156 page-types
157 parse.c
158 parse.h
159 +parse-events*
160 +pasyms.h
161 patches*
162 pca200e.bin
163 pca200e_ecd.bin2
164 @@ -197,6 +220,7 @@ perf-archive
165 piggyback
166 piggy.gzip
167 piggy.S
168 +pmu-*
169 pnmtologo
170 ppc_defs.h*
171 pss_boot.h
172 @@ -206,7 +230,12 @@ r200_reg_safe.h
173 r300_reg_safe.h
174 r420_reg_safe.h
175 r600_reg_safe.h
176 +randomize_layout_hash.h
177 +randomize_layout_seed.h
178 +realmode.lds
179 +realmode.relocs
180 recordmcount
181 +regdb.c
182 relocs
183 rlim_names.h
184 rn50_reg_safe.h
185 @@ -216,8 +245,12 @@ series
186 setup
187 setup.bin
188 setup.elf
189 +signing_key*
190 +size_overflow_hash.h
191 sImage
192 +slabinfo
193 sm_tbl*
194 +sortextable
195 split-include
196 syscalltab.h
197 tables.c
198 @@ -227,6 +260,7 @@ tftpboot.img
199 timeconst.h
200 times.h*
201 trix_boot.h
202 +user_constants.h
203 utsrelease.h*
204 vdso-syms.lds
205 vdso.lds
206 @@ -238,13 +272,17 @@ vdso32.lds
207 vdso32.so.dbg
208 vdso64.lds
209 vdso64.so.dbg
210 +vdsox32.lds
211 +vdsox32-syms.lds
212 version.h*
213 vmImage
214 vmlinux
215 vmlinux-*
216 vmlinux.aout
217 vmlinux.bin.all
218 +vmlinux.bin.bz2
219 vmlinux.lds
220 +vmlinux.relocs
221 vmlinuz
222 voffset.h
223 vsyscall.lds
224 @@ -252,9 +290,12 @@ vsyscall_32.lds
225 wanxlfw.inc
226 uImage
227 unifdef
228 +utsrelease.h
229 wakeup.bin
230 wakeup.elf
231 wakeup.lds
232 +x509*
233 zImage*
234 zconf.hash.c
235 +zconf.lex.c
236 zoffset.h
237 diff --git a/Documentation/kbuild/makefiles.txt b/Documentation/kbuild/makefiles.txt
238 index 764f599..c600e2f 100644
239 --- a/Documentation/kbuild/makefiles.txt
240 +++ b/Documentation/kbuild/makefiles.txt
241 @@ -23,10 +23,11 @@ This document describes the Linux kernel Makefiles.
242 === 4 Host Program support
243 --- 4.1 Simple Host Program
244 --- 4.2 Composite Host Programs
245 - --- 4.3 Using C++ for host programs
246 - --- 4.4 Controlling compiler options for host programs
247 - --- 4.5 When host programs are actually built
248 - --- 4.6 Using hostprogs-$(CONFIG_FOO)
249 + --- 4.3 Defining shared libraries
250 + --- 4.4 Using C++ for host programs
251 + --- 4.5 Controlling compiler options for host programs
252 + --- 4.6 When host programs are actually built
253 + --- 4.7 Using hostprogs-$(CONFIG_FOO)
254
255 === 5 Kbuild clean infrastructure
256
257 @@ -642,7 +643,29 @@ Both possibilities are described in the following.
258 Finally, the two .o files are linked to the executable, lxdialog.
259 Note: The syntax <executable>-y is not permitted for host-programs.
260
261 ---- 4.3 Using C++ for host programs
262 +--- 4.3 Defining shared libraries
263 +
264 + Objects with extension .so are considered shared libraries, and
265 + will be compiled as position independent objects.
266 + Kbuild provides support for shared libraries, but the usage
267 + shall be restricted.
268 + In the following example the libkconfig.so shared library is used
269 + to link the executable conf.
270 +
271 + Example:
272 + #scripts/kconfig/Makefile
273 + hostprogs-y := conf
274 + conf-objs := conf.o libkconfig.so
275 + libkconfig-objs := expr.o type.o
276 +
277 + Shared libraries always require a corresponding -objs line, and
278 + in the example above the shared library libkconfig is composed by
279 + the two objects expr.o and type.o.
280 + expr.o and type.o will be built as position independent code and
281 + linked as a shared library libkconfig.so. C++ is not supported for
282 + shared libraries.
283 +
284 +--- 4.4 Using C++ for host programs
285
286 kbuild offers support for host programs written in C++. This was
287 introduced solely to support kconfig, and is not recommended
288 @@ -665,7 +688,7 @@ Both possibilities are described in the following.
289 qconf-cxxobjs := qconf.o
290 qconf-objs := check.o
291
292 ---- 4.4 Controlling compiler options for host programs
293 +--- 4.5 Controlling compiler options for host programs
294
295 When compiling host programs, it is possible to set specific flags.
296 The programs will always be compiled utilising $(HOSTCC) passed
297 @@ -693,7 +716,7 @@ Both possibilities are described in the following.
298 When linking qconf, it will be passed the extra option
299 "-L$(QTDIR)/lib".
300
301 ---- 4.5 When host programs are actually built
302 +--- 4.6 When host programs are actually built
303
304 Kbuild will only build host-programs when they are referenced
305 as a prerequisite.
306 @@ -724,7 +747,7 @@ Both possibilities are described in the following.
307 This will tell kbuild to build lxdialog even if not referenced in
308 any rule.
309
310 ---- 4.6 Using hostprogs-$(CONFIG_FOO)
311 +--- 4.7 Using hostprogs-$(CONFIG_FOO)
312
313 A typical pattern in a Kbuild file looks like this:
314
315 diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
316 index 1edd5fd..107ff46 100644
317 --- a/Documentation/kernel-parameters.txt
318 +++ b/Documentation/kernel-parameters.txt
319 @@ -1155,6 +1155,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
320 Format: <unsigned int> such that (rxsize & ~0x1fffc0) == 0.
321 Default: 1024
322
323 + grsec_proc_gid= [GRKERNSEC_PROC_USERGROUP] Chooses GID to
324 + ignore grsecurity's /proc restrictions
325 +
326 +
327 hashdist= [KNL,NUMA] Large hashes allocated during boot
328 are distributed across NUMA nodes. Defaults on
329 for 64-bit NUMA, off otherwise.
330 @@ -2175,6 +2179,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
331 noexec=on: enable non-executable mappings (default)
332 noexec=off: disable non-executable mappings
333
334 + nopcid [X86-64]
335 + Disable PCID (Process-Context IDentifier) even if it
336 + is supported by the processor.
337 +
338 nosmap [X86]
339 Disable SMAP (Supervisor Mode Access Prevention)
340 even if it is supported by processor.
341 @@ -2467,6 +2475,30 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
342 the specified number of seconds. This is to be used if
343 your oopses keep scrolling off the screen.
344
345 + pax_nouderef [X86] disables UDEREF. Most likely needed under certain
346 + virtualization environments that don't cope well with the
347 + expand down segment used by UDEREF on X86-32 or the frequent
348 + page table updates on X86-64.
349 +
350 + pax_sanitize_slab=
351 + Format: { 0 | 1 | off | fast | full }
352 + Options '0' and '1' are only provided for backward
353 + compatibility, 'off' or 'fast' should be used instead.
354 + 0|off : disable slab object sanitization
355 + 1|fast: enable slab object sanitization excluding
356 + whitelisted slabs (default)
357 + full : sanitize all slabs, even the whitelisted ones
358 +
359 + pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
360 +
361 + pax_extra_latent_entropy
362 + Enable a very simple form of latent entropy extraction
363 + from the first 4GB of memory as the bootmem allocator
364 + passes the memory pages to the buddy allocator.
365 +
366 + pax_weakuderef [X86-64] enables the weaker but faster form of UDEREF
367 + when the processor supports PCID.
368 +
369 pcbit= [HW,ISDN]
370
371 pcd. [PARIDE]
372 diff --git a/Makefile b/Makefile
373 index 267f893..78c2d4b 100644
374 --- a/Makefile
375 +++ b/Makefile
376 @@ -303,8 +303,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
377
378 HOSTCC = gcc
379 HOSTCXX = g++
380 -HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
381 -HOSTCXXFLAGS = -O2
382 +HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
383 +HOSTCFLAGS += $(call cc-option, -Wno-empty-body)
384 +HOSTCXXFLAGS = -O2 -Wall -W -Wno-array-bounds
385
386 ifeq ($(shell $(HOSTCC) -v 2>&1 | grep -c "clang version"), 1)
387 HOSTCFLAGS += -Wno-unused-value -Wno-unused-parameter \
388 @@ -450,8 +451,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
389 # Rules shared between *config targets and build targets
390
391 # Basic helpers built in scripts/
392 -PHONY += scripts_basic
393 -scripts_basic:
394 +PHONY += scripts_basic gcc-plugins
395 +scripts_basic: gcc-plugins
396 $(Q)$(MAKE) $(build)=scripts/basic
397 $(Q)rm -f .tmp_quiet_recordmcount
398
399 @@ -625,6 +626,72 @@ endif
400 # Tell gcc to never replace conditional load with a non-conditional one
401 KBUILD_CFLAGS += $(call cc-option,--param=allow-store-data-races=0)
402
403 +ifndef DISABLE_PAX_PLUGINS
404 +ifeq ($(call cc-ifversion, -ge, 0408, y), y)
405 +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCXX)" "$(HOSTCXX)" "$(CC)")
406 +else
407 +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
408 +endif
409 +ifneq ($(PLUGINCC),)
410 +ifdef CONFIG_PAX_CONSTIFY_PLUGIN
411 +CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
412 +endif
413 +ifdef CONFIG_PAX_MEMORY_STACKLEAK
414 +STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
415 +STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
416 +endif
417 +ifdef CONFIG_KALLOCSTAT_PLUGIN
418 +KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
419 +endif
420 +ifdef CONFIG_PAX_KERNEXEC_PLUGIN
421 +KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
422 +KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
423 +KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
424 +endif
425 +ifdef CONFIG_GRKERNSEC_RANDSTRUCT
426 +RANDSTRUCT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/randomize_layout_plugin.so -DRANDSTRUCT_PLUGIN
427 +ifdef CONFIG_GRKERNSEC_RANDSTRUCT_PERFORMANCE
428 +RANDSTRUCT_PLUGIN_CFLAGS += -fplugin-arg-randomize_layout_plugin-performance-mode
429 +endif
430 +endif
431 +ifdef CONFIG_CHECKER_PLUGIN
432 +ifeq ($(call cc-ifversion, -ge, 0406, y), y)
433 +CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
434 +endif
435 +endif
436 +COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
437 +ifdef CONFIG_PAX_SIZE_OVERFLOW
438 +SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
439 +endif
440 +ifdef CONFIG_PAX_LATENT_ENTROPY
441 +LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
442 +endif
443 +ifdef CONFIG_PAX_MEMORY_STRUCTLEAK
444 +STRUCTLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/structleak_plugin.so -DSTRUCTLEAK_PLUGIN
445 +endif
446 +GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
447 +GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
448 +GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS) $(STRUCTLEAK_PLUGIN_CFLAGS)
449 +GCC_PLUGINS_CFLAGS += $(RANDSTRUCT_PLUGIN_CFLAGS)
450 +GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
451 +export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN LATENT_ENTROPY_PLUGIN_CFLAGS
452 +ifeq ($(KBUILD_EXTMOD),)
453 +gcc-plugins:
454 + $(Q)$(MAKE) $(build)=tools/gcc
455 +else
456 +gcc-plugins: ;
457 +endif
458 +else
459 +gcc-plugins:
460 +ifeq ($(call cc-ifversion, -ge, 0405, y), y)
461 + $(error Your gcc installation does not support plugins. If the necessary headers for plugin support are missing, they should be installed. On Debian, apt-get install gcc-<ver>-plugin-dev. If you choose to ignore this error and lessen the improvements provided by this patch, re-run make with the DISABLE_PAX_PLUGINS=y argument.))
462 +else
463 + $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
464 +endif
465 + $(Q)echo "PAX_MEMORY_STACKLEAK, constification, PAX_LATENT_ENTROPY and other features will be less secure. PAX_SIZE_OVERFLOW will not be active."
466 +endif
467 +endif
468 +
469 ifdef CONFIG_READABLE_ASM
470 # Disable optimizations that make assembler listings hard to read.
471 # reorder blocks reorders the control in the function
472 @@ -717,7 +784,7 @@ KBUILD_CFLAGS += $(call cc-option, -gsplit-dwarf, -g)
473 else
474 KBUILD_CFLAGS += -g
475 endif
476 -KBUILD_AFLAGS += -Wa,-gdwarf-2
477 +KBUILD_AFLAGS += -Wa,--gdwarf-2
478 endif
479 ifdef CONFIG_DEBUG_INFO_DWARF4
480 KBUILD_CFLAGS += $(call cc-option, -gdwarf-4,)
481 @@ -867,7 +934,7 @@ export mod_sign_cmd
482
483
484 ifeq ($(KBUILD_EXTMOD),)
485 -core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
486 +core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
487
488 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
489 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
490 @@ -916,6 +983,8 @@ endif
491
492 # The actual objects are generated when descending,
493 # make sure no implicit rule kicks in
494 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
495 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
496 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
497
498 # Handle descending into subdirectories listed in $(vmlinux-dirs)
499 @@ -925,7 +994,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
500 # Error messages still appears in the original language
501
502 PHONY += $(vmlinux-dirs)
503 -$(vmlinux-dirs): prepare scripts
504 +$(vmlinux-dirs): gcc-plugins prepare scripts
505 $(Q)$(MAKE) $(build)=$@
506
507 define filechk_kernel.release
508 @@ -968,10 +1037,13 @@ prepare1: prepare2 $(version_h) include/generated/utsrelease.h \
509
510 archprepare: archheaders archscripts prepare1 scripts_basic
511
512 +prepare0: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
513 +prepare0: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
514 prepare0: archprepare FORCE
515 $(Q)$(MAKE) $(build)=.
516
517 # All the preparing..
518 +prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
519 prepare: prepare0
520
521 # Generate some files
522 @@ -1086,6 +1158,8 @@ all: modules
523 # using awk while concatenating to the final file.
524
525 PHONY += modules
526 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
527 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
528 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
529 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
530 @$(kecho) ' Building modules, stage 2.';
531 @@ -1101,7 +1175,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
532
533 # Target to prepare building external modules
534 PHONY += modules_prepare
535 -modules_prepare: prepare scripts
536 +modules_prepare: gcc-plugins prepare scripts
537
538 # Target to install modules
539 PHONY += modules_install
540 @@ -1167,7 +1241,10 @@ MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \
541 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
542 signing_key.priv signing_key.x509 x509.genkey \
543 extra_certificates signing_key.x509.keyid \
544 - signing_key.x509.signer include/linux/version.h
545 + signing_key.x509.signer include/linux/version.h \
546 + tools/gcc/size_overflow_plugin/size_overflow_hash_aux.h \
547 + tools/gcc/size_overflow_plugin/size_overflow_hash.h \
548 + tools/gcc/randomize_layout_seed.h
549
550 # clean - Delete most, but leave enough to build external modules
551 #
552 @@ -1206,7 +1283,7 @@ distclean: mrproper
553 @find $(srctree) $(RCS_FIND_IGNORE) \
554 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
555 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
556 - -o -name '.*.rej' -o -name '*%' -o -name 'core' \) \
557 + -o -name '.*.rej' -o -name '*.so' -o -name '*%' -o -name 'core' \) \
558 -type f -print | xargs rm -f
559
560
561 @@ -1372,6 +1449,8 @@ PHONY += $(module-dirs) modules
562 $(module-dirs): crmodverdir $(objtree)/Module.symvers
563 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
564
565 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
566 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
567 modules: $(module-dirs)
568 @$(kecho) ' Building modules, stage 2.';
569 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
570 @@ -1512,17 +1591,21 @@ else
571 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
572 endif
573
574 -%.s: %.c prepare scripts FORCE
575 +%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
576 +%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
577 +%.s: %.c gcc-plugins prepare scripts FORCE
578 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
579 %.i: %.c prepare scripts FORCE
580 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
581 -%.o: %.c prepare scripts FORCE
582 +%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
583 +%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
584 +%.o: %.c gcc-plugins prepare scripts FORCE
585 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
586 %.lst: %.c prepare scripts FORCE
587 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
588 -%.s: %.S prepare scripts FORCE
589 +%.s: %.S gcc-plugins prepare scripts FORCE
590 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
591 -%.o: %.S prepare scripts FORCE
592 +%.o: %.S gcc-plugins prepare scripts FORCE
593 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
594 %.symtypes: %.c prepare scripts FORCE
595 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
596 @@ -1532,11 +1615,15 @@ endif
597 $(cmd_crmodverdir)
598 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
599 $(build)=$(build-dir)
600 -%/: prepare scripts FORCE
601 +%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
602 +%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
603 +%/: gcc-plugins prepare scripts FORCE
604 $(cmd_crmodverdir)
605 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
606 $(build)=$(build-dir)
607 -%.ko: prepare scripts FORCE
608 +%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
609 +%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
610 +%.ko: gcc-plugins prepare scripts FORCE
611 $(cmd_crmodverdir)
612 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
613 $(build)=$(build-dir) $(@:.ko=.o)
614 diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
615 index ed60a1e..47f1a55 100644
616 --- a/arch/alpha/include/asm/atomic.h
617 +++ b/arch/alpha/include/asm/atomic.h
618 @@ -292,4 +292,14 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
619 #define atomic_dec(v) atomic_sub(1,(v))
620 #define atomic64_dec(v) atomic64_sub(1,(v))
621
622 +#define atomic64_read_unchecked(v) atomic64_read(v)
623 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
624 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
625 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
626 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
627 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
628 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
629 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
630 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
631 +
632 #endif /* _ALPHA_ATOMIC_H */
633 diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
634 index ad368a9..fbe0f25 100644
635 --- a/arch/alpha/include/asm/cache.h
636 +++ b/arch/alpha/include/asm/cache.h
637 @@ -4,19 +4,19 @@
638 #ifndef __ARCH_ALPHA_CACHE_H
639 #define __ARCH_ALPHA_CACHE_H
640
641 +#include <linux/const.h>
642
643 /* Bytes per L1 (data) cache line. */
644 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
645 -# define L1_CACHE_BYTES 64
646 # define L1_CACHE_SHIFT 6
647 #else
648 /* Both EV4 and EV5 are write-through, read-allocate,
649 direct-mapped, physical.
650 */
651 -# define L1_CACHE_BYTES 32
652 # define L1_CACHE_SHIFT 5
653 #endif
654
655 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
656 #define SMP_CACHE_BYTES L1_CACHE_BYTES
657
658 #endif
659 diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
660 index 968d999..d36b2df 100644
661 --- a/arch/alpha/include/asm/elf.h
662 +++ b/arch/alpha/include/asm/elf.h
663 @@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
664
665 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
666
667 +#ifdef CONFIG_PAX_ASLR
668 +#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
669 +
670 +#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
671 +#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
672 +#endif
673 +
674 /* $0 is set by ld.so to a pointer to a function which might be
675 registered using atexit. This provides a mean for the dynamic
676 linker to call DT_FINI functions for shared libraries that have
677 diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
678 index aab14a0..b4fa3e7 100644
679 --- a/arch/alpha/include/asm/pgalloc.h
680 +++ b/arch/alpha/include/asm/pgalloc.h
681 @@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
682 pgd_set(pgd, pmd);
683 }
684
685 +static inline void
686 +pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
687 +{
688 + pgd_populate(mm, pgd, pmd);
689 +}
690 +
691 extern pgd_t *pgd_alloc(struct mm_struct *mm);
692
693 static inline void
694 diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
695 index d8f9b7e..f6222fa 100644
696 --- a/arch/alpha/include/asm/pgtable.h
697 +++ b/arch/alpha/include/asm/pgtable.h
698 @@ -102,6 +102,17 @@ struct vm_area_struct;
699 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
700 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
701 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
702 +
703 +#ifdef CONFIG_PAX_PAGEEXEC
704 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
705 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
706 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
707 +#else
708 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
709 +# define PAGE_COPY_NOEXEC PAGE_COPY
710 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
711 +#endif
712 +
713 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
714
715 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
716 diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
717 index 2fd00b7..cfd5069 100644
718 --- a/arch/alpha/kernel/module.c
719 +++ b/arch/alpha/kernel/module.c
720 @@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
721
722 /* The small sections were sorted to the end of the segment.
723 The following should definitely cover them. */
724 - gp = (u64)me->module_core + me->core_size - 0x8000;
725 + gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
726 got = sechdrs[me->arch.gotsecindex].sh_addr;
727
728 for (i = 0; i < n; i++) {
729 diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
730 index 1402fcc..0b1abd2 100644
731 --- a/arch/alpha/kernel/osf_sys.c
732 +++ b/arch/alpha/kernel/osf_sys.c
733 @@ -1298,10 +1298,11 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
734 generic version except that we know how to honor ADDR_LIMIT_32BIT. */
735
736 static unsigned long
737 -arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
738 - unsigned long limit)
739 +arch_get_unmapped_area_1(struct file *filp, unsigned long addr, unsigned long len,
740 + unsigned long limit, unsigned long flags)
741 {
742 struct vm_unmapped_area_info info;
743 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
744
745 info.flags = 0;
746 info.length = len;
747 @@ -1309,6 +1310,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
748 info.high_limit = limit;
749 info.align_mask = 0;
750 info.align_offset = 0;
751 + info.threadstack_offset = offset;
752 return vm_unmapped_area(&info);
753 }
754
755 @@ -1341,20 +1343,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
756 merely specific addresses, but regions of memory -- perhaps
757 this feature should be incorporated into all ports? */
758
759 +#ifdef CONFIG_PAX_RANDMMAP
760 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
761 +#endif
762 +
763 if (addr) {
764 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
765 + addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(addr), len, limit, flags);
766 if (addr != (unsigned long) -ENOMEM)
767 return addr;
768 }
769
770 /* Next, try allocating at TASK_UNMAPPED_BASE. */
771 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
772 - len, limit);
773 + addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(current->mm->mmap_base), len, limit, flags);
774 +
775 if (addr != (unsigned long) -ENOMEM)
776 return addr;
777
778 /* Finally, try allocating in low memory. */
779 - addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
780 + addr = arch_get_unmapped_area_1 (filp, PAGE_SIZE, len, limit, flags);
781
782 return addr;
783 }
784 diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
785 index 98838a0..b304fb4 100644
786 --- a/arch/alpha/mm/fault.c
787 +++ b/arch/alpha/mm/fault.c
788 @@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
789 __reload_thread(pcb);
790 }
791
792 +#ifdef CONFIG_PAX_PAGEEXEC
793 +/*
794 + * PaX: decide what to do with offenders (regs->pc = fault address)
795 + *
796 + * returns 1 when task should be killed
797 + * 2 when patched PLT trampoline was detected
798 + * 3 when unpatched PLT trampoline was detected
799 + */
800 +static int pax_handle_fetch_fault(struct pt_regs *regs)
801 +{
802 +
803 +#ifdef CONFIG_PAX_EMUPLT
804 + int err;
805 +
806 + do { /* PaX: patched PLT emulation #1 */
807 + unsigned int ldah, ldq, jmp;
808 +
809 + err = get_user(ldah, (unsigned int *)regs->pc);
810 + err |= get_user(ldq, (unsigned int *)(regs->pc+4));
811 + err |= get_user(jmp, (unsigned int *)(regs->pc+8));
812 +
813 + if (err)
814 + break;
815 +
816 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
817 + (ldq & 0xFFFF0000U) == 0xA77B0000U &&
818 + jmp == 0x6BFB0000U)
819 + {
820 + unsigned long r27, addr;
821 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
822 + unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
823 +
824 + addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
825 + err = get_user(r27, (unsigned long *)addr);
826 + if (err)
827 + break;
828 +
829 + regs->r27 = r27;
830 + regs->pc = r27;
831 + return 2;
832 + }
833 + } while (0);
834 +
835 + do { /* PaX: patched PLT emulation #2 */
836 + unsigned int ldah, lda, br;
837 +
838 + err = get_user(ldah, (unsigned int *)regs->pc);
839 + err |= get_user(lda, (unsigned int *)(regs->pc+4));
840 + err |= get_user(br, (unsigned int *)(regs->pc+8));
841 +
842 + if (err)
843 + break;
844 +
845 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
846 + (lda & 0xFFFF0000U) == 0xA77B0000U &&
847 + (br & 0xFFE00000U) == 0xC3E00000U)
848 + {
849 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
850 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
851 + unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
852 +
853 + regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
854 + regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
855 + return 2;
856 + }
857 + } while (0);
858 +
859 + do { /* PaX: unpatched PLT emulation */
860 + unsigned int br;
861 +
862 + err = get_user(br, (unsigned int *)regs->pc);
863 +
864 + if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
865 + unsigned int br2, ldq, nop, jmp;
866 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
867 +
868 + addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
869 + err = get_user(br2, (unsigned int *)addr);
870 + err |= get_user(ldq, (unsigned int *)(addr+4));
871 + err |= get_user(nop, (unsigned int *)(addr+8));
872 + err |= get_user(jmp, (unsigned int *)(addr+12));
873 + err |= get_user(resolver, (unsigned long *)(addr+16));
874 +
875 + if (err)
876 + break;
877 +
878 + if (br2 == 0xC3600000U &&
879 + ldq == 0xA77B000CU &&
880 + nop == 0x47FF041FU &&
881 + jmp == 0x6B7B0000U)
882 + {
883 + regs->r28 = regs->pc+4;
884 + regs->r27 = addr+16;
885 + regs->pc = resolver;
886 + return 3;
887 + }
888 + }
889 + } while (0);
890 +#endif
891 +
892 + return 1;
893 +}
894 +
895 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
896 +{
897 + unsigned long i;
898 +
899 + printk(KERN_ERR "PAX: bytes at PC: ");
900 + for (i = 0; i < 5; i++) {
901 + unsigned int c;
902 + if (get_user(c, (unsigned int *)pc+i))
903 + printk(KERN_CONT "???????? ");
904 + else
905 + printk(KERN_CONT "%08x ", c);
906 + }
907 + printk("\n");
908 +}
909 +#endif
910
911 /*
912 * This routine handles page faults. It determines the address,
913 @@ -133,8 +251,29 @@ retry:
914 good_area:
915 si_code = SEGV_ACCERR;
916 if (cause < 0) {
917 - if (!(vma->vm_flags & VM_EXEC))
918 + if (!(vma->vm_flags & VM_EXEC)) {
919 +
920 +#ifdef CONFIG_PAX_PAGEEXEC
921 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
922 + goto bad_area;
923 +
924 + up_read(&mm->mmap_sem);
925 + switch (pax_handle_fetch_fault(regs)) {
926 +
927 +#ifdef CONFIG_PAX_EMUPLT
928 + case 2:
929 + case 3:
930 + return;
931 +#endif
932 +
933 + }
934 + pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
935 + do_group_exit(SIGKILL);
936 +#else
937 goto bad_area;
938 +#endif
939 +
940 + }
941 } else if (!cause) {
942 /* Allow reads even for write-only mappings */
943 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
944 diff --git a/arch/arc/kernel/kgdb.c b/arch/arc/kernel/kgdb.c
945 index a2ff5c5..ecf6a78 100644
946 --- a/arch/arc/kernel/kgdb.c
947 +++ b/arch/arc/kernel/kgdb.c
948 @@ -158,11 +158,6 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
949 return -1;
950 }
951
952 -unsigned long kgdb_arch_pc(int exception, struct pt_regs *regs)
953 -{
954 - return instruction_pointer(regs);
955 -}
956 -
957 int kgdb_arch_init(void)
958 {
959 single_step_data.armed = 0;
960 diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
961 index 32cbbd5..c102df9 100644
962 --- a/arch/arm/Kconfig
963 +++ b/arch/arm/Kconfig
964 @@ -1719,7 +1719,7 @@ config ALIGNMENT_TRAP
965
966 config UACCESS_WITH_MEMCPY
967 bool "Use kernel mem{cpy,set}() for {copy_to,clear}_user()"
968 - depends on MMU
969 + depends on MMU && !PAX_MEMORY_UDEREF
970 default y if CPU_FEROCEON
971 help
972 Implement faster copy_to_user and clear_user methods for CPU
973 @@ -1983,6 +1983,7 @@ config XIP_PHYS_ADDR
974 config KEXEC
975 bool "Kexec system call (EXPERIMENTAL)"
976 depends on (!SMP || PM_SLEEP_SMP)
977 + depends on !GRKERNSEC_KMEM
978 help
979 kexec is a system call that implements the ability to shutdown your
980 current kernel, and to start another kernel. It is like a reboot
981 diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
982 index 3040359..2e964a2 100644
983 --- a/arch/arm/include/asm/atomic.h
984 +++ b/arch/arm/include/asm/atomic.h
985 @@ -18,17 +18,41 @@
986 #include <asm/barrier.h>
987 #include <asm/cmpxchg.h>
988
989 +#ifdef CONFIG_GENERIC_ATOMIC64
990 +#include <asm-generic/atomic64.h>
991 +#endif
992 +
993 #define ATOMIC_INIT(i) { (i) }
994
995 #ifdef __KERNEL__
996
997 +#ifdef CONFIG_THUMB2_KERNEL
998 +#define REFCOUNT_TRAP_INSN "bkpt 0xf1"
999 +#else
1000 +#define REFCOUNT_TRAP_INSN "bkpt 0xf103"
1001 +#endif
1002 +
1003 +#define _ASM_EXTABLE(from, to) \
1004 +" .pushsection __ex_table,\"a\"\n"\
1005 +" .align 3\n" \
1006 +" .long " #from ", " #to"\n" \
1007 +" .popsection"
1008 +
1009 /*
1010 * On ARM, ordinary assignment (str instruction) doesn't clear the local
1011 * strex/ldrex monitor on some implementations. The reason we can use it for
1012 * atomic_set() is the clrex or dummy strex done on every exception return.
1013 */
1014 #define atomic_read(v) (*(volatile int *)&(v)->counter)
1015 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
1016 +{
1017 + return *(const volatile int *)&v->counter;
1018 +}
1019 #define atomic_set(v,i) (((v)->counter) = (i))
1020 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
1021 +{
1022 + v->counter = i;
1023 +}
1024
1025 #if __LINUX_ARM_ARCH__ >= 6
1026
1027 @@ -44,6 +68,36 @@ static inline void atomic_add(int i, atomic_t *v)
1028
1029 prefetchw(&v->counter);
1030 __asm__ __volatile__("@ atomic_add\n"
1031 +"1: ldrex %1, [%3]\n"
1032 +" adds %0, %1, %4\n"
1033 +
1034 +#ifdef CONFIG_PAX_REFCOUNT
1035 +" bvc 3f\n"
1036 +"2: " REFCOUNT_TRAP_INSN "\n"
1037 +"3:\n"
1038 +#endif
1039 +
1040 +" strex %1, %0, [%3]\n"
1041 +" teq %1, #0\n"
1042 +" bne 1b"
1043 +
1044 +#ifdef CONFIG_PAX_REFCOUNT
1045 +"\n4:\n"
1046 + _ASM_EXTABLE(2b, 4b)
1047 +#endif
1048 +
1049 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1050 + : "r" (&v->counter), "Ir" (i)
1051 + : "cc");
1052 +}
1053 +
1054 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1055 +{
1056 + unsigned long tmp;
1057 + int result;
1058 +
1059 + prefetchw(&v->counter);
1060 + __asm__ __volatile__("@ atomic_add_unchecked\n"
1061 "1: ldrex %0, [%3]\n"
1062 " add %0, %0, %4\n"
1063 " strex %1, %0, [%3]\n"
1064 @@ -63,6 +117,43 @@ static inline int atomic_add_return(int i, atomic_t *v)
1065 prefetchw(&v->counter);
1066
1067 __asm__ __volatile__("@ atomic_add_return\n"
1068 +"1: ldrex %1, [%3]\n"
1069 +" adds %0, %1, %4\n"
1070 +
1071 +#ifdef CONFIG_PAX_REFCOUNT
1072 +" bvc 3f\n"
1073 +" mov %0, %1\n"
1074 +"2: " REFCOUNT_TRAP_INSN "\n"
1075 +"3:\n"
1076 +#endif
1077 +
1078 +" strex %1, %0, [%3]\n"
1079 +" teq %1, #0\n"
1080 +" bne 1b"
1081 +
1082 +#ifdef CONFIG_PAX_REFCOUNT
1083 +"\n4:\n"
1084 + _ASM_EXTABLE(2b, 4b)
1085 +#endif
1086 +
1087 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1088 + : "r" (&v->counter), "Ir" (i)
1089 + : "cc");
1090 +
1091 + smp_mb();
1092 +
1093 + return result;
1094 +}
1095 +
1096 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1097 +{
1098 + unsigned long tmp;
1099 + int result;
1100 +
1101 + smp_mb();
1102 + prefetchw(&v->counter);
1103 +
1104 + __asm__ __volatile__("@ atomic_add_return_unchecked\n"
1105 "1: ldrex %0, [%3]\n"
1106 " add %0, %0, %4\n"
1107 " strex %1, %0, [%3]\n"
1108 @@ -84,6 +175,36 @@ static inline void atomic_sub(int i, atomic_t *v)
1109
1110 prefetchw(&v->counter);
1111 __asm__ __volatile__("@ atomic_sub\n"
1112 +"1: ldrex %1, [%3]\n"
1113 +" subs %0, %1, %4\n"
1114 +
1115 +#ifdef CONFIG_PAX_REFCOUNT
1116 +" bvc 3f\n"
1117 +"2: " REFCOUNT_TRAP_INSN "\n"
1118 +"3:\n"
1119 +#endif
1120 +
1121 +" strex %1, %0, [%3]\n"
1122 +" teq %1, #0\n"
1123 +" bne 1b"
1124 +
1125 +#ifdef CONFIG_PAX_REFCOUNT
1126 +"\n4:\n"
1127 + _ASM_EXTABLE(2b, 4b)
1128 +#endif
1129 +
1130 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1131 + : "r" (&v->counter), "Ir" (i)
1132 + : "cc");
1133 +}
1134 +
1135 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1136 +{
1137 + unsigned long tmp;
1138 + int result;
1139 +
1140 + prefetchw(&v->counter);
1141 + __asm__ __volatile__("@ atomic_sub_unchecked\n"
1142 "1: ldrex %0, [%3]\n"
1143 " sub %0, %0, %4\n"
1144 " strex %1, %0, [%3]\n"
1145 @@ -103,11 +224,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1146 prefetchw(&v->counter);
1147
1148 __asm__ __volatile__("@ atomic_sub_return\n"
1149 -"1: ldrex %0, [%3]\n"
1150 -" sub %0, %0, %4\n"
1151 +"1: ldrex %1, [%3]\n"
1152 +" subs %0, %1, %4\n"
1153 +
1154 +#ifdef CONFIG_PAX_REFCOUNT
1155 +" bvc 3f\n"
1156 +" mov %0, %1\n"
1157 +"2: " REFCOUNT_TRAP_INSN "\n"
1158 +"3:\n"
1159 +#endif
1160 +
1161 " strex %1, %0, [%3]\n"
1162 " teq %1, #0\n"
1163 " bne 1b"
1164 +
1165 +#ifdef CONFIG_PAX_REFCOUNT
1166 +"\n4:\n"
1167 + _ASM_EXTABLE(2b, 4b)
1168 +#endif
1169 +
1170 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1171 : "r" (&v->counter), "Ir" (i)
1172 : "cc");
1173 @@ -152,12 +287,24 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1174 __asm__ __volatile__ ("@ atomic_add_unless\n"
1175 "1: ldrex %0, [%4]\n"
1176 " teq %0, %5\n"
1177 -" beq 2f\n"
1178 -" add %1, %0, %6\n"
1179 +" beq 4f\n"
1180 +" adds %1, %0, %6\n"
1181 +
1182 +#ifdef CONFIG_PAX_REFCOUNT
1183 +" bvc 3f\n"
1184 +"2: " REFCOUNT_TRAP_INSN "\n"
1185 +"3:\n"
1186 +#endif
1187 +
1188 " strex %2, %1, [%4]\n"
1189 " teq %2, #0\n"
1190 " bne 1b\n"
1191 -"2:"
1192 +"4:"
1193 +
1194 +#ifdef CONFIG_PAX_REFCOUNT
1195 + _ASM_EXTABLE(2b, 4b)
1196 +#endif
1197 +
1198 : "=&r" (oldval), "=&r" (newval), "=&r" (tmp), "+Qo" (v->counter)
1199 : "r" (&v->counter), "r" (u), "r" (a)
1200 : "cc");
1201 @@ -168,6 +315,28 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1202 return oldval;
1203 }
1204
1205 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
1206 +{
1207 + unsigned long oldval, res;
1208 +
1209 + smp_mb();
1210 +
1211 + do {
1212 + __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
1213 + "ldrex %1, [%3]\n"
1214 + "mov %0, #0\n"
1215 + "teq %1, %4\n"
1216 + "strexeq %0, %5, [%3]\n"
1217 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1218 + : "r" (&ptr->counter), "Ir" (old), "r" (new)
1219 + : "cc");
1220 + } while (res);
1221 +
1222 + smp_mb();
1223 +
1224 + return oldval;
1225 +}
1226 +
1227 #else /* ARM_ARCH_6 */
1228
1229 #ifdef CONFIG_SMP
1230 @@ -186,7 +355,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1231
1232 return val;
1233 }
1234 +
1235 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1236 +{
1237 + return atomic_add_return(i, v);
1238 +}
1239 +
1240 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1241 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1242 +{
1243 + (void) atomic_add_return(i, v);
1244 +}
1245
1246 static inline int atomic_sub_return(int i, atomic_t *v)
1247 {
1248 @@ -201,6 +380,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1249 return val;
1250 }
1251 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1252 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1253 +{
1254 + (void) atomic_sub_return(i, v);
1255 +}
1256
1257 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1258 {
1259 @@ -216,6 +399,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1260 return ret;
1261 }
1262
1263 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1264 +{
1265 + return atomic_cmpxchg(v, old, new);
1266 +}
1267 +
1268 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1269 {
1270 int c, old;
1271 @@ -229,13 +417,33 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1272 #endif /* __LINUX_ARM_ARCH__ */
1273
1274 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1275 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1276 +{
1277 + return xchg(&v->counter, new);
1278 +}
1279
1280 #define atomic_inc(v) atomic_add(1, v)
1281 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1282 +{
1283 + atomic_add_unchecked(1, v);
1284 +}
1285 #define atomic_dec(v) atomic_sub(1, v)
1286 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1287 +{
1288 + atomic_sub_unchecked(1, v);
1289 +}
1290
1291 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1292 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1293 +{
1294 + return atomic_add_return_unchecked(1, v) == 0;
1295 +}
1296 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1297 #define atomic_inc_return(v) (atomic_add_return(1, v))
1298 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1299 +{
1300 + return atomic_add_return_unchecked(1, v);
1301 +}
1302 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1303 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1304
1305 @@ -246,6 +454,14 @@ typedef struct {
1306 long long counter;
1307 } atomic64_t;
1308
1309 +#ifdef CONFIG_PAX_REFCOUNT
1310 +typedef struct {
1311 + long long counter;
1312 +} atomic64_unchecked_t;
1313 +#else
1314 +typedef atomic64_t atomic64_unchecked_t;
1315 +#endif
1316 +
1317 #define ATOMIC64_INIT(i) { (i) }
1318
1319 #ifdef CONFIG_ARM_LPAE
1320 @@ -262,6 +478,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1321 return result;
1322 }
1323
1324 +static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1325 +{
1326 + long long result;
1327 +
1328 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1329 +" ldrd %0, %H0, [%1]"
1330 + : "=&r" (result)
1331 + : "r" (&v->counter), "Qo" (v->counter)
1332 + );
1333 +
1334 + return result;
1335 +}
1336 +
1337 static inline void atomic64_set(atomic64_t *v, long long i)
1338 {
1339 __asm__ __volatile__("@ atomic64_set\n"
1340 @@ -270,6 +499,15 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1341 : "r" (&v->counter), "r" (i)
1342 );
1343 }
1344 +
1345 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1346 +{
1347 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1348 +" strd %2, %H2, [%1]"
1349 + : "=Qo" (v->counter)
1350 + : "r" (&v->counter), "r" (i)
1351 + );
1352 +}
1353 #else
1354 static inline long long atomic64_read(const atomic64_t *v)
1355 {
1356 @@ -284,6 +522,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1357 return result;
1358 }
1359
1360 +static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1361 +{
1362 + long long result;
1363 +
1364 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1365 +" ldrexd %0, %H0, [%1]"
1366 + : "=&r" (result)
1367 + : "r" (&v->counter), "Qo" (v->counter)
1368 + );
1369 +
1370 + return result;
1371 +}
1372 +
1373 static inline void atomic64_set(atomic64_t *v, long long i)
1374 {
1375 long long tmp;
1376 @@ -298,6 +549,21 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1377 : "r" (&v->counter), "r" (i)
1378 : "cc");
1379 }
1380 +
1381 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1382 +{
1383 + long long tmp;
1384 +
1385 + prefetchw(&v->counter);
1386 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1387 +"1: ldrexd %0, %H0, [%2]\n"
1388 +" strexd %0, %3, %H3, [%2]\n"
1389 +" teq %0, #0\n"
1390 +" bne 1b"
1391 + : "=&r" (tmp), "=Qo" (v->counter)
1392 + : "r" (&v->counter), "r" (i)
1393 + : "cc");
1394 +}
1395 #endif
1396
1397 static inline void atomic64_add(long long i, atomic64_t *v)
1398 @@ -309,6 +575,37 @@ static inline void atomic64_add(long long i, atomic64_t *v)
1399 __asm__ __volatile__("@ atomic64_add\n"
1400 "1: ldrexd %0, %H0, [%3]\n"
1401 " adds %Q0, %Q0, %Q4\n"
1402 +" adcs %R0, %R0, %R4\n"
1403 +
1404 +#ifdef CONFIG_PAX_REFCOUNT
1405 +" bvc 3f\n"
1406 +"2: " REFCOUNT_TRAP_INSN "\n"
1407 +"3:\n"
1408 +#endif
1409 +
1410 +" strexd %1, %0, %H0, [%3]\n"
1411 +" teq %1, #0\n"
1412 +" bne 1b"
1413 +
1414 +#ifdef CONFIG_PAX_REFCOUNT
1415 +"\n4:\n"
1416 + _ASM_EXTABLE(2b, 4b)
1417 +#endif
1418 +
1419 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1420 + : "r" (&v->counter), "r" (i)
1421 + : "cc");
1422 +}
1423 +
1424 +static inline void atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
1425 +{
1426 + long long result;
1427 + unsigned long tmp;
1428 +
1429 + prefetchw(&v->counter);
1430 + __asm__ __volatile__("@ atomic64_add_unchecked\n"
1431 +"1: ldrexd %0, %H0, [%3]\n"
1432 +" adds %Q0, %Q0, %Q4\n"
1433 " adc %R0, %R0, %R4\n"
1434 " strexd %1, %0, %H0, [%3]\n"
1435 " teq %1, #0\n"
1436 @@ -329,6 +626,44 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
1437 __asm__ __volatile__("@ atomic64_add_return\n"
1438 "1: ldrexd %0, %H0, [%3]\n"
1439 " adds %Q0, %Q0, %Q4\n"
1440 +" adcs %R0, %R0, %R4\n"
1441 +
1442 +#ifdef CONFIG_PAX_REFCOUNT
1443 +" bvc 3f\n"
1444 +" mov %0, %1\n"
1445 +" mov %H0, %H1\n"
1446 +"2: " REFCOUNT_TRAP_INSN "\n"
1447 +"3:\n"
1448 +#endif
1449 +
1450 +" strexd %1, %0, %H0, [%3]\n"
1451 +" teq %1, #0\n"
1452 +" bne 1b"
1453 +
1454 +#ifdef CONFIG_PAX_REFCOUNT
1455 +"\n4:\n"
1456 + _ASM_EXTABLE(2b, 4b)
1457 +#endif
1458 +
1459 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1460 + : "r" (&v->counter), "r" (i)
1461 + : "cc");
1462 +
1463 + smp_mb();
1464 +
1465 + return result;
1466 +}
1467 +
1468 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
1469 +{
1470 + long long result;
1471 + unsigned long tmp;
1472 +
1473 + smp_mb();
1474 +
1475 + __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1476 +"1: ldrexd %0, %H0, [%3]\n"
1477 +" adds %Q0, %Q0, %Q4\n"
1478 " adc %R0, %R0, %R4\n"
1479 " strexd %1, %0, %H0, [%3]\n"
1480 " teq %1, #0\n"
1481 @@ -351,6 +686,37 @@ static inline void atomic64_sub(long long i, atomic64_t *v)
1482 __asm__ __volatile__("@ atomic64_sub\n"
1483 "1: ldrexd %0, %H0, [%3]\n"
1484 " subs %Q0, %Q0, %Q4\n"
1485 +" sbcs %R0, %R0, %R4\n"
1486 +
1487 +#ifdef CONFIG_PAX_REFCOUNT
1488 +" bvc 3f\n"
1489 +"2: " REFCOUNT_TRAP_INSN "\n"
1490 +"3:\n"
1491 +#endif
1492 +
1493 +" strexd %1, %0, %H0, [%3]\n"
1494 +" teq %1, #0\n"
1495 +" bne 1b"
1496 +
1497 +#ifdef CONFIG_PAX_REFCOUNT
1498 +"\n4:\n"
1499 + _ASM_EXTABLE(2b, 4b)
1500 +#endif
1501 +
1502 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1503 + : "r" (&v->counter), "r" (i)
1504 + : "cc");
1505 +}
1506 +
1507 +static inline void atomic64_sub_unchecked(long long i, atomic64_unchecked_t *v)
1508 +{
1509 + long long result;
1510 + unsigned long tmp;
1511 +
1512 + prefetchw(&v->counter);
1513 + __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1514 +"1: ldrexd %0, %H0, [%3]\n"
1515 +" subs %Q0, %Q0, %Q4\n"
1516 " sbc %R0, %R0, %R4\n"
1517 " strexd %1, %0, %H0, [%3]\n"
1518 " teq %1, #0\n"
1519 @@ -371,10 +737,25 @@ static inline long long atomic64_sub_return(long long i, atomic64_t *v)
1520 __asm__ __volatile__("@ atomic64_sub_return\n"
1521 "1: ldrexd %0, %H0, [%3]\n"
1522 " subs %Q0, %Q0, %Q4\n"
1523 -" sbc %R0, %R0, %R4\n"
1524 +" sbcs %R0, %R0, %R4\n"
1525 +
1526 +#ifdef CONFIG_PAX_REFCOUNT
1527 +" bvc 3f\n"
1528 +" mov %0, %1\n"
1529 +" mov %H0, %H1\n"
1530 +"2: " REFCOUNT_TRAP_INSN "\n"
1531 +"3:\n"
1532 +#endif
1533 +
1534 " strexd %1, %0, %H0, [%3]\n"
1535 " teq %1, #0\n"
1536 " bne 1b"
1537 +
1538 +#ifdef CONFIG_PAX_REFCOUNT
1539 +"\n4:\n"
1540 + _ASM_EXTABLE(2b, 4b)
1541 +#endif
1542 +
1543 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1544 : "r" (&v->counter), "r" (i)
1545 : "cc");
1546 @@ -410,6 +791,31 @@ static inline long long atomic64_cmpxchg(atomic64_t *ptr, long long old,
1547 return oldval;
1548 }
1549
1550 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, long long old,
1551 + long long new)
1552 +{
1553 + long long oldval;
1554 + unsigned long res;
1555 +
1556 + smp_mb();
1557 +
1558 + do {
1559 + __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1560 + "ldrexd %1, %H1, [%3]\n"
1561 + "mov %0, #0\n"
1562 + "teq %1, %4\n"
1563 + "teqeq %H1, %H4\n"
1564 + "strexdeq %0, %5, %H5, [%3]"
1565 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1566 + : "r" (&ptr->counter), "r" (old), "r" (new)
1567 + : "cc");
1568 + } while (res);
1569 +
1570 + smp_mb();
1571 +
1572 + return oldval;
1573 +}
1574 +
1575 static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1576 {
1577 long long result;
1578 @@ -435,21 +841,35 @@ static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1579 static inline long long atomic64_dec_if_positive(atomic64_t *v)
1580 {
1581 long long result;
1582 - unsigned long tmp;
1583 + u64 tmp;
1584
1585 smp_mb();
1586 prefetchw(&v->counter);
1587
1588 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1589 -"1: ldrexd %0, %H0, [%3]\n"
1590 -" subs %Q0, %Q0, #1\n"
1591 -" sbc %R0, %R0, #0\n"
1592 +"1: ldrexd %1, %H1, [%3]\n"
1593 +" subs %Q0, %Q1, #1\n"
1594 +" sbcs %R0, %R1, #0\n"
1595 +
1596 +#ifdef CONFIG_PAX_REFCOUNT
1597 +" bvc 3f\n"
1598 +" mov %Q0, %Q1\n"
1599 +" mov %R0, %R1\n"
1600 +"2: " REFCOUNT_TRAP_INSN "\n"
1601 +"3:\n"
1602 +#endif
1603 +
1604 " teq %R0, #0\n"
1605 -" bmi 2f\n"
1606 +" bmi 4f\n"
1607 " strexd %1, %0, %H0, [%3]\n"
1608 " teq %1, #0\n"
1609 " bne 1b\n"
1610 -"2:"
1611 +"4:\n"
1612 +
1613 +#ifdef CONFIG_PAX_REFCOUNT
1614 + _ASM_EXTABLE(2b, 4b)
1615 +#endif
1616 +
1617 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1618 : "r" (&v->counter)
1619 : "cc");
1620 @@ -473,13 +893,25 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1621 " teq %0, %5\n"
1622 " teqeq %H0, %H5\n"
1623 " moveq %1, #0\n"
1624 -" beq 2f\n"
1625 +" beq 4f\n"
1626 " adds %Q0, %Q0, %Q6\n"
1627 -" adc %R0, %R0, %R6\n"
1628 +" adcs %R0, %R0, %R6\n"
1629 +
1630 +#ifdef CONFIG_PAX_REFCOUNT
1631 +" bvc 3f\n"
1632 +"2: " REFCOUNT_TRAP_INSN "\n"
1633 +"3:\n"
1634 +#endif
1635 +
1636 " strexd %2, %0, %H0, [%4]\n"
1637 " teq %2, #0\n"
1638 " bne 1b\n"
1639 -"2:"
1640 +"4:\n"
1641 +
1642 +#ifdef CONFIG_PAX_REFCOUNT
1643 + _ASM_EXTABLE(2b, 4b)
1644 +#endif
1645 +
1646 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1647 : "r" (&v->counter), "r" (u), "r" (a)
1648 : "cc");
1649 @@ -492,10 +924,13 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1650
1651 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1652 #define atomic64_inc(v) atomic64_add(1LL, (v))
1653 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1654 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1655 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1656 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1657 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1658 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1659 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1660 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1661 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1662 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1663 diff --git a/arch/arm/include/asm/barrier.h b/arch/arm/include/asm/barrier.h
1664 index c6a3e73..35cca85 100644
1665 --- a/arch/arm/include/asm/barrier.h
1666 +++ b/arch/arm/include/asm/barrier.h
1667 @@ -63,7 +63,7 @@
1668 do { \
1669 compiletime_assert_atomic_type(*p); \
1670 smp_mb(); \
1671 - ACCESS_ONCE(*p) = (v); \
1672 + ACCESS_ONCE_RW(*p) = (v); \
1673 } while (0)
1674
1675 #define smp_load_acquire(p) \
1676 diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1677 index 75fe66b..ba3dee4 100644
1678 --- a/arch/arm/include/asm/cache.h
1679 +++ b/arch/arm/include/asm/cache.h
1680 @@ -4,8 +4,10 @@
1681 #ifndef __ASMARM_CACHE_H
1682 #define __ASMARM_CACHE_H
1683
1684 +#include <linux/const.h>
1685 +
1686 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1687 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1688 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1689
1690 /*
1691 * Memory returned by kmalloc() may be used for DMA, so we must make
1692 @@ -24,5 +26,6 @@
1693 #endif
1694
1695 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1696 +#define __read_only __attribute__ ((__section__(".data..read_only")))
1697
1698 #endif
1699 diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1700 index 10e78d0..dc8505d 100644
1701 --- a/arch/arm/include/asm/cacheflush.h
1702 +++ b/arch/arm/include/asm/cacheflush.h
1703 @@ -116,7 +116,7 @@ struct cpu_cache_fns {
1704 void (*dma_unmap_area)(const void *, size_t, int);
1705
1706 void (*dma_flush_range)(const void *, const void *);
1707 -};
1708 +} __no_const;
1709
1710 /*
1711 * Select the calling method
1712 diff --git a/arch/arm/include/asm/checksum.h b/arch/arm/include/asm/checksum.h
1713 index 5233151..87a71fa 100644
1714 --- a/arch/arm/include/asm/checksum.h
1715 +++ b/arch/arm/include/asm/checksum.h
1716 @@ -37,7 +37,19 @@ __wsum
1717 csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
1718
1719 __wsum
1720 -csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1721 +__csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1722 +
1723 +static inline __wsum
1724 +csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr)
1725 +{
1726 + __wsum ret;
1727 + pax_open_userland();
1728 + ret = __csum_partial_copy_from_user(src, dst, len, sum, err_ptr);
1729 + pax_close_userland();
1730 + return ret;
1731 +}
1732 +
1733 +
1734
1735 /*
1736 * Fold a partial checksum without adding pseudo headers
1737 diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1738 index abb2c37..96db950 100644
1739 --- a/arch/arm/include/asm/cmpxchg.h
1740 +++ b/arch/arm/include/asm/cmpxchg.h
1741 @@ -104,6 +104,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1742
1743 #define xchg(ptr,x) \
1744 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1745 +#define xchg_unchecked(ptr,x) \
1746 + ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1747
1748 #include <asm-generic/cmpxchg-local.h>
1749
1750 diff --git a/arch/arm/include/asm/domain.h b/arch/arm/include/asm/domain.h
1751 index 6ddbe44..b5e38b1 100644
1752 --- a/arch/arm/include/asm/domain.h
1753 +++ b/arch/arm/include/asm/domain.h
1754 @@ -48,18 +48,37 @@
1755 * Domain types
1756 */
1757 #define DOMAIN_NOACCESS 0
1758 -#define DOMAIN_CLIENT 1
1759 #ifdef CONFIG_CPU_USE_DOMAINS
1760 +#define DOMAIN_USERCLIENT 1
1761 +#define DOMAIN_KERNELCLIENT 1
1762 #define DOMAIN_MANAGER 3
1763 +#define DOMAIN_VECTORS DOMAIN_USER
1764 #else
1765 +
1766 +#ifdef CONFIG_PAX_KERNEXEC
1767 #define DOMAIN_MANAGER 1
1768 +#define DOMAIN_KERNEXEC 3
1769 +#else
1770 +#define DOMAIN_MANAGER 1
1771 +#endif
1772 +
1773 +#ifdef CONFIG_PAX_MEMORY_UDEREF
1774 +#define DOMAIN_USERCLIENT 0
1775 +#define DOMAIN_UDEREF 1
1776 +#define DOMAIN_VECTORS DOMAIN_KERNEL
1777 +#else
1778 +#define DOMAIN_USERCLIENT 1
1779 +#define DOMAIN_VECTORS DOMAIN_USER
1780 +#endif
1781 +#define DOMAIN_KERNELCLIENT 1
1782 +
1783 #endif
1784
1785 #define domain_val(dom,type) ((type) << (2*(dom)))
1786
1787 #ifndef __ASSEMBLY__
1788
1789 -#ifdef CONFIG_CPU_USE_DOMAINS
1790 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1791 static inline void set_domain(unsigned val)
1792 {
1793 asm volatile(
1794 @@ -68,15 +87,7 @@ static inline void set_domain(unsigned val)
1795 isb();
1796 }
1797
1798 -#define modify_domain(dom,type) \
1799 - do { \
1800 - struct thread_info *thread = current_thread_info(); \
1801 - unsigned int domain = thread->cpu_domain; \
1802 - domain &= ~domain_val(dom, DOMAIN_MANAGER); \
1803 - thread->cpu_domain = domain | domain_val(dom, type); \
1804 - set_domain(thread->cpu_domain); \
1805 - } while (0)
1806 -
1807 +extern void modify_domain(unsigned int dom, unsigned int type);
1808 #else
1809 static inline void set_domain(unsigned val) { }
1810 static inline void modify_domain(unsigned dom, unsigned type) { }
1811 diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1812 index afb9caf..9a0bac0 100644
1813 --- a/arch/arm/include/asm/elf.h
1814 +++ b/arch/arm/include/asm/elf.h
1815 @@ -115,7 +115,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1816 the loader. We need to make sure that it is out of the way of the program
1817 that it will "exec", and that there is sufficient room for the brk. */
1818
1819 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1820 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1821 +
1822 +#ifdef CONFIG_PAX_ASLR
1823 +#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1824 +
1825 +#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1826 +#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1827 +#endif
1828
1829 /* When the program starts, a1 contains a pointer to a function to be
1830 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1831 @@ -125,10 +132,6 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1832 extern void elf_set_personality(const struct elf32_hdr *);
1833 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1834
1835 -struct mm_struct;
1836 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1837 -#define arch_randomize_brk arch_randomize_brk
1838 -
1839 #ifdef CONFIG_MMU
1840 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
1841 struct linux_binprm;
1842 diff --git a/arch/arm/include/asm/fncpy.h b/arch/arm/include/asm/fncpy.h
1843 index de53547..52b9a28 100644
1844 --- a/arch/arm/include/asm/fncpy.h
1845 +++ b/arch/arm/include/asm/fncpy.h
1846 @@ -81,7 +81,9 @@
1847 BUG_ON((uintptr_t)(dest_buf) & (FNCPY_ALIGN - 1) || \
1848 (__funcp_address & ~(uintptr_t)1 & (FNCPY_ALIGN - 1))); \
1849 \
1850 + pax_open_kernel(); \
1851 memcpy(dest_buf, (void const *)(__funcp_address & ~1), size); \
1852 + pax_close_kernel(); \
1853 flush_icache_range((unsigned long)(dest_buf), \
1854 (unsigned long)(dest_buf) + (size)); \
1855 \
1856 diff --git a/arch/arm/include/asm/futex.h b/arch/arm/include/asm/futex.h
1857 index 53e69da..3fdc896 100644
1858 --- a/arch/arm/include/asm/futex.h
1859 +++ b/arch/arm/include/asm/futex.h
1860 @@ -46,6 +46,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1861 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1862 return -EFAULT;
1863
1864 + pax_open_userland();
1865 +
1866 smp_mb();
1867 /* Prefetching cannot fault */
1868 prefetchw(uaddr);
1869 @@ -63,6 +65,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1870 : "cc", "memory");
1871 smp_mb();
1872
1873 + pax_close_userland();
1874 +
1875 *uval = val;
1876 return ret;
1877 }
1878 @@ -93,6 +97,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1879 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1880 return -EFAULT;
1881
1882 + pax_open_userland();
1883 +
1884 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1885 "1: " TUSER(ldr) " %1, [%4]\n"
1886 " teq %1, %2\n"
1887 @@ -103,6 +109,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1888 : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)
1889 : "cc", "memory");
1890
1891 + pax_close_userland();
1892 +
1893 *uval = val;
1894 return ret;
1895 }
1896 @@ -125,6 +133,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1897 return -EFAULT;
1898
1899 pagefault_disable(); /* implies preempt_disable() */
1900 + pax_open_userland();
1901
1902 switch (op) {
1903 case FUTEX_OP_SET:
1904 @@ -146,6 +155,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1905 ret = -ENOSYS;
1906 }
1907
1908 + pax_close_userland();
1909 pagefault_enable(); /* subsumes preempt_enable() */
1910
1911 if (!ret) {
1912 diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1913 index 83eb2f7..ed77159 100644
1914 --- a/arch/arm/include/asm/kmap_types.h
1915 +++ b/arch/arm/include/asm/kmap_types.h
1916 @@ -4,6 +4,6 @@
1917 /*
1918 * This is the "bare minimum". AIO seems to require this.
1919 */
1920 -#define KM_TYPE_NR 16
1921 +#define KM_TYPE_NR 17
1922
1923 #endif
1924 diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
1925 index 9e614a1..3302cca 100644
1926 --- a/arch/arm/include/asm/mach/dma.h
1927 +++ b/arch/arm/include/asm/mach/dma.h
1928 @@ -22,7 +22,7 @@ struct dma_ops {
1929 int (*residue)(unsigned int, dma_t *); /* optional */
1930 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
1931 const char *type;
1932 -};
1933 +} __do_const;
1934
1935 struct dma_struct {
1936 void *addr; /* single DMA address */
1937 diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1938 index f98c7f3..e5c626d 100644
1939 --- a/arch/arm/include/asm/mach/map.h
1940 +++ b/arch/arm/include/asm/mach/map.h
1941 @@ -23,17 +23,19 @@ struct map_desc {
1942
1943 /* types 0-3 are defined in asm/io.h */
1944 enum {
1945 - MT_UNCACHED = 4,
1946 - MT_CACHECLEAN,
1947 - MT_MINICLEAN,
1948 + MT_UNCACHED_RW = 4,
1949 + MT_CACHECLEAN_RO,
1950 + MT_MINICLEAN_RO,
1951 MT_LOW_VECTORS,
1952 MT_HIGH_VECTORS,
1953 - MT_MEMORY_RWX,
1954 + __MT_MEMORY_RWX,
1955 MT_MEMORY_RW,
1956 - MT_ROM,
1957 - MT_MEMORY_RWX_NONCACHED,
1958 + MT_MEMORY_RX,
1959 + MT_ROM_RX,
1960 + MT_MEMORY_RW_NONCACHED,
1961 + MT_MEMORY_RX_NONCACHED,
1962 MT_MEMORY_RW_DTCM,
1963 - MT_MEMORY_RWX_ITCM,
1964 + MT_MEMORY_RX_ITCM,
1965 MT_MEMORY_RW_SO,
1966 MT_MEMORY_DMA_READY,
1967 };
1968 diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1969 index 891a56b..48f337e 100644
1970 --- a/arch/arm/include/asm/outercache.h
1971 +++ b/arch/arm/include/asm/outercache.h
1972 @@ -36,7 +36,7 @@ struct outer_cache_fns {
1973
1974 /* This is an ARM L2C thing */
1975 void (*write_sec)(unsigned long, unsigned);
1976 -};
1977 +} __no_const;
1978
1979 extern struct outer_cache_fns outer_cache;
1980
1981 diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1982 index 4355f0e..cd9168e 100644
1983 --- a/arch/arm/include/asm/page.h
1984 +++ b/arch/arm/include/asm/page.h
1985 @@ -23,6 +23,7 @@
1986
1987 #else
1988
1989 +#include <linux/compiler.h>
1990 #include <asm/glue.h>
1991
1992 /*
1993 @@ -114,7 +115,7 @@ struct cpu_user_fns {
1994 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1995 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1996 unsigned long vaddr, struct vm_area_struct *vma);
1997 -};
1998 +} __no_const;
1999
2000 #ifdef MULTI_USER
2001 extern struct cpu_user_fns cpu_user;
2002 diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
2003 index 78a7793..e3dc06c 100644
2004 --- a/arch/arm/include/asm/pgalloc.h
2005 +++ b/arch/arm/include/asm/pgalloc.h
2006 @@ -17,6 +17,7 @@
2007 #include <asm/processor.h>
2008 #include <asm/cacheflush.h>
2009 #include <asm/tlbflush.h>
2010 +#include <asm/system_info.h>
2011
2012 #define check_pgt_cache() do { } while (0)
2013
2014 @@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2015 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
2016 }
2017
2018 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2019 +{
2020 + pud_populate(mm, pud, pmd);
2021 +}
2022 +
2023 #else /* !CONFIG_ARM_LPAE */
2024
2025 /*
2026 @@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2027 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
2028 #define pmd_free(mm, pmd) do { } while (0)
2029 #define pud_populate(mm,pmd,pte) BUG()
2030 +#define pud_populate_kernel(mm,pmd,pte) BUG()
2031
2032 #endif /* CONFIG_ARM_LPAE */
2033
2034 @@ -128,6 +135,19 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
2035 __free_page(pte);
2036 }
2037
2038 +static inline void __section_update(pmd_t *pmdp, unsigned long addr, pmdval_t prot)
2039 +{
2040 +#ifdef CONFIG_ARM_LPAE
2041 + pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
2042 +#else
2043 + if (addr & SECTION_SIZE)
2044 + pmdp[1] = __pmd(pmd_val(pmdp[1]) | prot);
2045 + else
2046 + pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
2047 +#endif
2048 + flush_pmd_entry(pmdp);
2049 +}
2050 +
2051 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
2052 pmdval_t prot)
2053 {
2054 @@ -157,7 +177,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
2055 static inline void
2056 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
2057 {
2058 - __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
2059 + __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
2060 }
2061 #define pmd_pgtable(pmd) pmd_page(pmd)
2062
2063 diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
2064 index 5cfba15..f415e1a 100644
2065 --- a/arch/arm/include/asm/pgtable-2level-hwdef.h
2066 +++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
2067 @@ -20,12 +20,15 @@
2068 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
2069 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
2070 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
2071 +#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* v7 */
2072 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
2073 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
2074 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
2075 +
2076 /*
2077 * - section
2078 */
2079 +#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0) /* v7 */
2080 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
2081 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
2082 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
2083 @@ -37,6 +40,7 @@
2084 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
2085 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
2086 #define PMD_SECT_AF (_AT(pmdval_t, 0))
2087 +#define PMD_SECT_RDONLY (_AT(pmdval_t, 0))
2088
2089 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
2090 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
2091 @@ -66,6 +70,7 @@
2092 * - extended small page/tiny page
2093 */
2094 #define PTE_EXT_XN (_AT(pteval_t, 1) << 0) /* v6 */
2095 +#define PTE_EXT_PXN (_AT(pteval_t, 1) << 2) /* v7 */
2096 #define PTE_EXT_AP_MASK (_AT(pteval_t, 3) << 4)
2097 #define PTE_EXT_AP0 (_AT(pteval_t, 1) << 4)
2098 #define PTE_EXT_AP1 (_AT(pteval_t, 2) << 4)
2099 diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
2100 index 219ac88..73ec32a 100644
2101 --- a/arch/arm/include/asm/pgtable-2level.h
2102 +++ b/arch/arm/include/asm/pgtable-2level.h
2103 @@ -126,6 +126,9 @@
2104 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
2105 #define L_PTE_NONE (_AT(pteval_t, 1) << 11)
2106
2107 +/* Two-level page tables only have PXN in the PGD, not in the PTE. */
2108 +#define L_PTE_PXN (_AT(pteval_t, 0))
2109 +
2110 /*
2111 * These are the memory types, defined to be compatible with
2112 * pre-ARMv6 CPUs cacheable and bufferable bits: XXCB
2113 diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
2114 index 9fd61c7..f8f1cff 100644
2115 --- a/arch/arm/include/asm/pgtable-3level-hwdef.h
2116 +++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
2117 @@ -76,6 +76,7 @@
2118 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
2119 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
2120 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
2121 +#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
2122 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
2123
2124 /*
2125 diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
2126 index 06e0bc0..c65bca8 100644
2127 --- a/arch/arm/include/asm/pgtable-3level.h
2128 +++ b/arch/arm/include/asm/pgtable-3level.h
2129 @@ -81,6 +81,7 @@
2130 #define L_PTE_USER (_AT(pteval_t, 1) << 6) /* AP[1] */
2131 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
2132 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
2133 +#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
2134 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
2135 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55)
2136 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56)
2137 @@ -92,10 +93,12 @@
2138 #define L_PMD_SECT_SPLITTING (_AT(pmdval_t, 1) << 56)
2139 #define L_PMD_SECT_NONE (_AT(pmdval_t, 1) << 57)
2140 #define L_PMD_SECT_RDONLY (_AT(pteval_t, 1) << 58)
2141 +#define PMD_SECT_RDONLY PMD_SECT_AP2
2142
2143 /*
2144 * To be used in assembly code with the upper page attributes.
2145 */
2146 +#define L_PTE_PXN_HIGH (1 << (53 - 32))
2147 #define L_PTE_XN_HIGH (1 << (54 - 32))
2148 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
2149
2150 diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
2151 index 01baef0..73c156e 100644
2152 --- a/arch/arm/include/asm/pgtable.h
2153 +++ b/arch/arm/include/asm/pgtable.h
2154 @@ -33,6 +33,9 @@
2155 #include <asm/pgtable-2level.h>
2156 #endif
2157
2158 +#define ktla_ktva(addr) (addr)
2159 +#define ktva_ktla(addr) (addr)
2160 +
2161 /*
2162 * Just any arbitrary offset to the start of the vmalloc VM area: the
2163 * current 8MB value just means that there will be a 8MB "hole" after the
2164 @@ -48,6 +51,9 @@
2165 #define LIBRARY_TEXT_START 0x0c000000
2166
2167 #ifndef __ASSEMBLY__
2168 +extern pteval_t __supported_pte_mask;
2169 +extern pmdval_t __supported_pmd_mask;
2170 +
2171 extern void __pte_error(const char *file, int line, pte_t);
2172 extern void __pmd_error(const char *file, int line, pmd_t);
2173 extern void __pgd_error(const char *file, int line, pgd_t);
2174 @@ -56,6 +62,48 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2175 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
2176 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
2177
2178 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
2179 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
2180 +
2181 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2182 +#include <asm/domain.h>
2183 +#include <linux/thread_info.h>
2184 +#include <linux/preempt.h>
2185 +
2186 +static inline int test_domain(int domain, int domaintype)
2187 +{
2188 + return ((current_thread_info()->cpu_domain) & domain_val(domain, 3)) == domain_val(domain, domaintype);
2189 +}
2190 +#endif
2191 +
2192 +#ifdef CONFIG_PAX_KERNEXEC
2193 +static inline unsigned long pax_open_kernel(void) {
2194 +#ifdef CONFIG_ARM_LPAE
2195 + /* TODO */
2196 +#else
2197 + preempt_disable();
2198 + BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
2199 + modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
2200 +#endif
2201 + return 0;
2202 +}
2203 +
2204 +static inline unsigned long pax_close_kernel(void) {
2205 +#ifdef CONFIG_ARM_LPAE
2206 + /* TODO */
2207 +#else
2208 + BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
2209 + /* DOMAIN_MANAGER = "client" under KERNEXEC */
2210 + modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
2211 + preempt_enable_no_resched();
2212 +#endif
2213 + return 0;
2214 +}
2215 +#else
2216 +static inline unsigned long pax_open_kernel(void) { return 0; }
2217 +static inline unsigned long pax_close_kernel(void) { return 0; }
2218 +#endif
2219 +
2220 /*
2221 * This is the lowest virtual address we can permit any user space
2222 * mapping to be mapped at. This is particularly important for
2223 @@ -75,8 +123,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2224 /*
2225 * The pgprot_* and protection_map entries will be fixed up in runtime
2226 * to include the cachable and bufferable bits based on memory policy,
2227 - * as well as any architecture dependent bits like global/ASID and SMP
2228 - * shared mapping bits.
2229 + * as well as any architecture dependent bits like global/ASID, PXN,
2230 + * and SMP shared mapping bits.
2231 */
2232 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
2233
2234 @@ -269,7 +317,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
2235 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
2236 {
2237 const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER |
2238 - L_PTE_NONE | L_PTE_VALID;
2239 + L_PTE_NONE | L_PTE_VALID | __supported_pte_mask;
2240 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
2241 return pte;
2242 }
2243 diff --git a/arch/arm/include/asm/psci.h b/arch/arm/include/asm/psci.h
2244 index c25ef3e..735f14b 100644
2245 --- a/arch/arm/include/asm/psci.h
2246 +++ b/arch/arm/include/asm/psci.h
2247 @@ -32,7 +32,7 @@ struct psci_operations {
2248 int (*affinity_info)(unsigned long target_affinity,
2249 unsigned long lowest_affinity_level);
2250 int (*migrate_info_type)(void);
2251 -};
2252 +} __no_const;
2253
2254 extern struct psci_operations psci_ops;
2255 extern struct smp_operations psci_smp_ops;
2256 diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
2257 index 2ec765c..beb1fe16 100644
2258 --- a/arch/arm/include/asm/smp.h
2259 +++ b/arch/arm/include/asm/smp.h
2260 @@ -113,7 +113,7 @@ struct smp_operations {
2261 int (*cpu_disable)(unsigned int cpu);
2262 #endif
2263 #endif
2264 -};
2265 +} __no_const;
2266
2267 struct of_cpu_method {
2268 const char *method;
2269 diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
2270 index ce73ab6..7310f8a 100644
2271 --- a/arch/arm/include/asm/thread_info.h
2272 +++ b/arch/arm/include/asm/thread_info.h
2273 @@ -78,9 +78,9 @@ struct thread_info {
2274 .flags = 0, \
2275 .preempt_count = INIT_PREEMPT_COUNT, \
2276 .addr_limit = KERNEL_DS, \
2277 - .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2278 - domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2279 - domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
2280 + .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
2281 + domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
2282 + domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
2283 .restart_block = { \
2284 .fn = do_no_restart_syscall, \
2285 }, \
2286 @@ -154,7 +154,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2287 #define TIF_SYSCALL_AUDIT 9
2288 #define TIF_SYSCALL_TRACEPOINT 10
2289 #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
2290 -#define TIF_NOHZ 12 /* in adaptive nohz mode */
2291 +/* within 8 bits of TIF_SYSCALL_TRACE
2292 + * to meet flexible second operand requirements
2293 + */
2294 +#define TIF_GRSEC_SETXID 12
2295 +#define TIF_NOHZ 13 /* in adaptive nohz mode */
2296 #define TIF_USING_IWMMXT 17
2297 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
2298 #define TIF_RESTORE_SIGMASK 20
2299 @@ -168,10 +172,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2300 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
2301 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
2302 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
2303 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
2304
2305 /* Checks for any syscall work in entry-common.S */
2306 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
2307 - _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
2308 + _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
2309
2310 /*
2311 * Change these and you break ASM code in entry-common.S
2312 diff --git a/arch/arm/include/asm/tls.h b/arch/arm/include/asm/tls.h
2313 index 5f833f7..76e6644 100644
2314 --- a/arch/arm/include/asm/tls.h
2315 +++ b/arch/arm/include/asm/tls.h
2316 @@ -3,6 +3,7 @@
2317
2318 #include <linux/compiler.h>
2319 #include <asm/thread_info.h>
2320 +#include <asm/pgtable.h>
2321
2322 #ifdef __ASSEMBLY__
2323 #include <asm/asm-offsets.h>
2324 @@ -89,7 +90,9 @@ static inline void set_tls(unsigned long val)
2325 * at 0xffff0fe0 must be used instead. (see
2326 * entry-armv.S for details)
2327 */
2328 + pax_open_kernel();
2329 *((unsigned int *)0xffff0ff0) = val;
2330 + pax_close_kernel();
2331 #endif
2332 }
2333
2334 diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
2335 index 4767eb9..bf00668 100644
2336 --- a/arch/arm/include/asm/uaccess.h
2337 +++ b/arch/arm/include/asm/uaccess.h
2338 @@ -18,6 +18,7 @@
2339 #include <asm/domain.h>
2340 #include <asm/unified.h>
2341 #include <asm/compiler.h>
2342 +#include <asm/pgtable.h>
2343
2344 #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
2345 #include <asm-generic/uaccess-unaligned.h>
2346 @@ -70,11 +71,38 @@ extern int __put_user_bad(void);
2347 static inline void set_fs(mm_segment_t fs)
2348 {
2349 current_thread_info()->addr_limit = fs;
2350 - modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
2351 + modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
2352 }
2353
2354 #define segment_eq(a,b) ((a) == (b))
2355
2356 +#define __HAVE_ARCH_PAX_OPEN_USERLAND
2357 +#define __HAVE_ARCH_PAX_CLOSE_USERLAND
2358 +
2359 +static inline void pax_open_userland(void)
2360 +{
2361 +
2362 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2363 + if (segment_eq(get_fs(), USER_DS)) {
2364 + BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
2365 + modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
2366 + }
2367 +#endif
2368 +
2369 +}
2370 +
2371 +static inline void pax_close_userland(void)
2372 +{
2373 +
2374 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2375 + if (segment_eq(get_fs(), USER_DS)) {
2376 + BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
2377 + modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
2378 + }
2379 +#endif
2380 +
2381 +}
2382 +
2383 #define __addr_ok(addr) ({ \
2384 unsigned long flag; \
2385 __asm__("cmp %2, %0; movlo %0, #0" \
2386 @@ -198,8 +226,12 @@ extern int __get_user_64t_4(void *);
2387
2388 #define get_user(x,p) \
2389 ({ \
2390 + int __e; \
2391 might_fault(); \
2392 - __get_user_check(x,p); \
2393 + pax_open_userland(); \
2394 + __e = __get_user_check(x,p); \
2395 + pax_close_userland(); \
2396 + __e; \
2397 })
2398
2399 extern int __put_user_1(void *, unsigned int);
2400 @@ -244,8 +276,12 @@ extern int __put_user_8(void *, unsigned long long);
2401
2402 #define put_user(x,p) \
2403 ({ \
2404 + int __e; \
2405 might_fault(); \
2406 - __put_user_check(x,p); \
2407 + pax_open_userland(); \
2408 + __e = __put_user_check(x,p); \
2409 + pax_close_userland(); \
2410 + __e; \
2411 })
2412
2413 #else /* CONFIG_MMU */
2414 @@ -269,6 +305,7 @@ static inline void set_fs(mm_segment_t fs)
2415
2416 #endif /* CONFIG_MMU */
2417
2418 +#define access_ok_noprefault(type,addr,size) access_ok((type),(addr),(size))
2419 #define access_ok(type,addr,size) (__range_ok(addr,size) == 0)
2420
2421 #define user_addr_max() \
2422 @@ -286,13 +323,17 @@ static inline void set_fs(mm_segment_t fs)
2423 #define __get_user(x,ptr) \
2424 ({ \
2425 long __gu_err = 0; \
2426 + pax_open_userland(); \
2427 __get_user_err((x),(ptr),__gu_err); \
2428 + pax_close_userland(); \
2429 __gu_err; \
2430 })
2431
2432 #define __get_user_error(x,ptr,err) \
2433 ({ \
2434 + pax_open_userland(); \
2435 __get_user_err((x),(ptr),err); \
2436 + pax_close_userland(); \
2437 (void) 0; \
2438 })
2439
2440 @@ -368,13 +409,17 @@ do { \
2441 #define __put_user(x,ptr) \
2442 ({ \
2443 long __pu_err = 0; \
2444 + pax_open_userland(); \
2445 __put_user_err((x),(ptr),__pu_err); \
2446 + pax_close_userland(); \
2447 __pu_err; \
2448 })
2449
2450 #define __put_user_error(x,ptr,err) \
2451 ({ \
2452 + pax_open_userland(); \
2453 __put_user_err((x),(ptr),err); \
2454 + pax_close_userland(); \
2455 (void) 0; \
2456 })
2457
2458 @@ -474,11 +519,44 @@ do { \
2459
2460
2461 #ifdef CONFIG_MMU
2462 -extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
2463 -extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
2464 +extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
2465 +extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
2466 +
2467 +static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
2468 +{
2469 + unsigned long ret;
2470 +
2471 + check_object_size(to, n, false);
2472 + pax_open_userland();
2473 + ret = ___copy_from_user(to, from, n);
2474 + pax_close_userland();
2475 + return ret;
2476 +}
2477 +
2478 +static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
2479 +{
2480 + unsigned long ret;
2481 +
2482 + check_object_size(from, n, true);
2483 + pax_open_userland();
2484 + ret = ___copy_to_user(to, from, n);
2485 + pax_close_userland();
2486 + return ret;
2487 +}
2488 +
2489 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
2490 -extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
2491 +extern unsigned long __must_check ___clear_user(void __user *addr, unsigned long n);
2492 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
2493 +
2494 +static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
2495 +{
2496 + unsigned long ret;
2497 + pax_open_userland();
2498 + ret = ___clear_user(addr, n);
2499 + pax_close_userland();
2500 + return ret;
2501 +}
2502 +
2503 #else
2504 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
2505 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
2506 @@ -487,6 +565,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
2507
2508 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2509 {
2510 + if ((long)n < 0)
2511 + return n;
2512 +
2513 if (access_ok(VERIFY_READ, from, n))
2514 n = __copy_from_user(to, from, n);
2515 else /* security hole - plug it */
2516 @@ -496,6 +577,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
2517
2518 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2519 {
2520 + if ((long)n < 0)
2521 + return n;
2522 +
2523 if (access_ok(VERIFY_WRITE, to, n))
2524 n = __copy_to_user(to, from, n);
2525 return n;
2526 diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
2527 index 5af0ed1..cea83883 100644
2528 --- a/arch/arm/include/uapi/asm/ptrace.h
2529 +++ b/arch/arm/include/uapi/asm/ptrace.h
2530 @@ -92,7 +92,7 @@
2531 * ARMv7 groups of PSR bits
2532 */
2533 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
2534 -#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
2535 +#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
2536 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
2537 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
2538
2539 diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
2540 index a88671c..1cc895e 100644
2541 --- a/arch/arm/kernel/armksyms.c
2542 +++ b/arch/arm/kernel/armksyms.c
2543 @@ -55,7 +55,7 @@ EXPORT_SYMBOL(arm_delay_ops);
2544
2545 /* networking */
2546 EXPORT_SYMBOL(csum_partial);
2547 -EXPORT_SYMBOL(csum_partial_copy_from_user);
2548 +EXPORT_SYMBOL(__csum_partial_copy_from_user);
2549 EXPORT_SYMBOL(csum_partial_copy_nocheck);
2550 EXPORT_SYMBOL(__csum_ipv6_magic);
2551
2552 @@ -91,9 +91,9 @@ EXPORT_SYMBOL(__memzero);
2553 #ifdef CONFIG_MMU
2554 EXPORT_SYMBOL(copy_page);
2555
2556 -EXPORT_SYMBOL(__copy_from_user);
2557 -EXPORT_SYMBOL(__copy_to_user);
2558 -EXPORT_SYMBOL(__clear_user);
2559 +EXPORT_SYMBOL(___copy_from_user);
2560 +EXPORT_SYMBOL(___copy_to_user);
2561 +EXPORT_SYMBOL(___clear_user);
2562
2563 EXPORT_SYMBOL(__get_user_1);
2564 EXPORT_SYMBOL(__get_user_2);
2565 diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
2566 index 36276cd..9d7b13b 100644
2567 --- a/arch/arm/kernel/entry-armv.S
2568 +++ b/arch/arm/kernel/entry-armv.S
2569 @@ -47,6 +47,87 @@
2570 9997:
2571 .endm
2572
2573 + .macro pax_enter_kernel
2574 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2575 + @ make aligned space for saved DACR
2576 + sub sp, sp, #8
2577 + @ save regs
2578 + stmdb sp!, {r1, r2}
2579 + @ read DACR from cpu_domain into r1
2580 + mov r2, sp
2581 + @ assume 8K pages, since we have to split the immediate in two
2582 + bic r2, r2, #(0x1fc0)
2583 + bic r2, r2, #(0x3f)
2584 + ldr r1, [r2, #TI_CPU_DOMAIN]
2585 + @ store old DACR on stack
2586 + str r1, [sp, #8]
2587 +#ifdef CONFIG_PAX_KERNEXEC
2588 + @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2589 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2590 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2591 +#endif
2592 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2593 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2594 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2595 +#endif
2596 + @ write r1 to current_thread_info()->cpu_domain
2597 + str r1, [r2, #TI_CPU_DOMAIN]
2598 + @ write r1 to DACR
2599 + mcr p15, 0, r1, c3, c0, 0
2600 + @ instruction sync
2601 + instr_sync
2602 + @ restore regs
2603 + ldmia sp!, {r1, r2}
2604 +#endif
2605 + .endm
2606 +
2607 + .macro pax_open_userland
2608 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2609 + @ save regs
2610 + stmdb sp!, {r0, r1}
2611 + @ read DACR from cpu_domain into r1
2612 + mov r0, sp
2613 + @ assume 8K pages, since we have to split the immediate in two
2614 + bic r0, r0, #(0x1fc0)
2615 + bic r0, r0, #(0x3f)
2616 + ldr r1, [r0, #TI_CPU_DOMAIN]
2617 + @ set current DOMAIN_USER to DOMAIN_CLIENT
2618 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2619 + orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2620 + @ write r1 to current_thread_info()->cpu_domain
2621 + str r1, [r0, #TI_CPU_DOMAIN]
2622 + @ write r1 to DACR
2623 + mcr p15, 0, r1, c3, c0, 0
2624 + @ instruction sync
2625 + instr_sync
2626 + @ restore regs
2627 + ldmia sp!, {r0, r1}
2628 +#endif
2629 + .endm
2630 +
2631 + .macro pax_close_userland
2632 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2633 + @ save regs
2634 + stmdb sp!, {r0, r1}
2635 + @ read DACR from cpu_domain into r1
2636 + mov r0, sp
2637 + @ assume 8K pages, since we have to split the immediate in two
2638 + bic r0, r0, #(0x1fc0)
2639 + bic r0, r0, #(0x3f)
2640 + ldr r1, [r0, #TI_CPU_DOMAIN]
2641 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2642 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2643 + @ write r1 to current_thread_info()->cpu_domain
2644 + str r1, [r0, #TI_CPU_DOMAIN]
2645 + @ write r1 to DACR
2646 + mcr p15, 0, r1, c3, c0, 0
2647 + @ instruction sync
2648 + instr_sync
2649 + @ restore regs
2650 + ldmia sp!, {r0, r1}
2651 +#endif
2652 + .endm
2653 +
2654 .macro pabt_helper
2655 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
2656 #ifdef MULTI_PABORT
2657 @@ -89,11 +170,15 @@
2658 * Invalid mode handlers
2659 */
2660 .macro inv_entry, reason
2661 +
2662 + pax_enter_kernel
2663 +
2664 sub sp, sp, #S_FRAME_SIZE
2665 ARM( stmib sp, {r1 - lr} )
2666 THUMB( stmia sp, {r0 - r12} )
2667 THUMB( str sp, [sp, #S_SP] )
2668 THUMB( str lr, [sp, #S_LR] )
2669 +
2670 mov r1, #\reason
2671 .endm
2672
2673 @@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
2674 .macro svc_entry, stack_hole=0
2675 UNWIND(.fnstart )
2676 UNWIND(.save {r0 - pc} )
2677 +
2678 + pax_enter_kernel
2679 +
2680 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2681 +
2682 #ifdef CONFIG_THUMB2_KERNEL
2683 SPFIX( str r0, [sp] ) @ temporarily saved
2684 SPFIX( mov r0, sp )
2685 @@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
2686 ldmia r0, {r3 - r5}
2687 add r7, sp, #S_SP - 4 @ here for interlock avoidance
2688 mov r6, #-1 @ "" "" "" ""
2689 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2690 + @ offset sp by 8 as done in pax_enter_kernel
2691 + add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
2692 +#else
2693 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2694 +#endif
2695 SPFIX( addeq r2, r2, #4 )
2696 str r3, [sp, #-4]! @ save the "real" r0 copied
2697 @ from the exception stack
2698 @@ -317,6 +411,9 @@ ENDPROC(__pabt_svc)
2699 .macro usr_entry
2700 UNWIND(.fnstart )
2701 UNWIND(.cantunwind ) @ don't unwind the user space
2702 +
2703 + pax_enter_kernel_user
2704 +
2705 sub sp, sp, #S_FRAME_SIZE
2706 ARM( stmib sp, {r1 - r12} )
2707 THUMB( stmia sp, {r0 - r12} )
2708 @@ -421,7 +518,9 @@ __und_usr:
2709 tst r3, #PSR_T_BIT @ Thumb mode?
2710 bne __und_usr_thumb
2711 sub r4, r2, #4 @ ARM instr at LR - 4
2712 + pax_open_userland
2713 1: ldrt r0, [r4]
2714 + pax_close_userland
2715 ARM_BE8(rev r0, r0) @ little endian instruction
2716
2717 @ r0 = 32-bit ARM instruction which caused the exception
2718 @@ -455,11 +554,15 @@ __und_usr_thumb:
2719 */
2720 .arch armv6t2
2721 #endif
2722 + pax_open_userland
2723 2: ldrht r5, [r4]
2724 + pax_close_userland
2725 ARM_BE8(rev16 r5, r5) @ little endian instruction
2726 cmp r5, #0xe800 @ 32bit instruction if xx != 0
2727 blo __und_usr_fault_16 @ 16bit undefined instruction
2728 + pax_open_userland
2729 3: ldrht r0, [r2]
2730 + pax_close_userland
2731 ARM_BE8(rev16 r0, r0) @ little endian instruction
2732 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
2733 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
2734 @@ -489,7 +592,8 @@ ENDPROC(__und_usr)
2735 */
2736 .pushsection .fixup, "ax"
2737 .align 2
2738 -4: str r4, [sp, #S_PC] @ retry current instruction
2739 +4: pax_close_userland
2740 + str r4, [sp, #S_PC] @ retry current instruction
2741 ret r9
2742 .popsection
2743 .pushsection __ex_table,"a"
2744 @@ -698,7 +802,7 @@ ENTRY(__switch_to)
2745 THUMB( str lr, [ip], #4 )
2746 ldr r4, [r2, #TI_TP_VALUE]
2747 ldr r5, [r2, #TI_TP_VALUE + 4]
2748 -#ifdef CONFIG_CPU_USE_DOMAINS
2749 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2750 ldr r6, [r2, #TI_CPU_DOMAIN]
2751 #endif
2752 switch_tls r1, r4, r5, r3, r7
2753 @@ -707,7 +811,7 @@ ENTRY(__switch_to)
2754 ldr r8, =__stack_chk_guard
2755 ldr r7, [r7, #TSK_STACK_CANARY]
2756 #endif
2757 -#ifdef CONFIG_CPU_USE_DOMAINS
2758 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2759 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
2760 #endif
2761 mov r5, r0
2762 diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
2763 index e52fe5a..1b0a924 100644
2764 --- a/arch/arm/kernel/entry-common.S
2765 +++ b/arch/arm/kernel/entry-common.S
2766 @@ -11,18 +11,46 @@
2767 #include <asm/assembler.h>
2768 #include <asm/unistd.h>
2769 #include <asm/ftrace.h>
2770 +#include <asm/domain.h>
2771 #include <asm/unwind.h>
2772
2773 +#include "entry-header.S"
2774 +
2775 #ifdef CONFIG_NEED_RET_TO_USER
2776 #include <mach/entry-macro.S>
2777 #else
2778 .macro arch_ret_to_user, tmp1, tmp2
2779 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2780 + @ save regs
2781 + stmdb sp!, {r1, r2}
2782 + @ read DACR from cpu_domain into r1
2783 + mov r2, sp
2784 + @ assume 8K pages, since we have to split the immediate in two
2785 + bic r2, r2, #(0x1fc0)
2786 + bic r2, r2, #(0x3f)
2787 + ldr r1, [r2, #TI_CPU_DOMAIN]
2788 +#ifdef CONFIG_PAX_KERNEXEC
2789 + @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2790 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2791 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2792 +#endif
2793 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2794 + @ set current DOMAIN_USER to DOMAIN_UDEREF
2795 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2796 + orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2797 +#endif
2798 + @ write r1 to current_thread_info()->cpu_domain
2799 + str r1, [r2, #TI_CPU_DOMAIN]
2800 + @ write r1 to DACR
2801 + mcr p15, 0, r1, c3, c0, 0
2802 + @ instruction sync
2803 + instr_sync
2804 + @ restore regs
2805 + ldmia sp!, {r1, r2}
2806 +#endif
2807 .endm
2808 #endif
2809
2810 -#include "entry-header.S"
2811 -
2812 -
2813 .align 5
2814 /*
2815 * This is the fast syscall return path. We do as little as
2816 @@ -406,6 +434,12 @@ ENTRY(vector_swi)
2817 USER( ldr scno, [lr, #-4] ) @ get SWI instruction
2818 #endif
2819
2820 + /*
2821 + * do this here to avoid a performance hit of wrapping the code above
2822 + * that directly dereferences userland to parse the SWI instruction
2823 + */
2824 + pax_enter_kernel_user
2825 +
2826 adr tbl, sys_call_table @ load syscall table pointer
2827
2828 #if defined(CONFIG_OABI_COMPAT)
2829 diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
2830 index 2fdf867..6e909e4 100644
2831 --- a/arch/arm/kernel/entry-header.S
2832 +++ b/arch/arm/kernel/entry-header.S
2833 @@ -188,6 +188,60 @@
2834 msr cpsr_c, \rtemp @ switch back to the SVC mode
2835 .endm
2836
2837 + .macro pax_enter_kernel_user
2838 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2839 + @ save regs
2840 + stmdb sp!, {r0, r1}
2841 + @ read DACR from cpu_domain into r1
2842 + mov r0, sp
2843 + @ assume 8K pages, since we have to split the immediate in two
2844 + bic r0, r0, #(0x1fc0)
2845 + bic r0, r0, #(0x3f)
2846 + ldr r1, [r0, #TI_CPU_DOMAIN]
2847 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2848 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2849 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2850 +#endif
2851 +#ifdef CONFIG_PAX_KERNEXEC
2852 + @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2853 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2854 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2855 +#endif
2856 + @ write r1 to current_thread_info()->cpu_domain
2857 + str r1, [r0, #TI_CPU_DOMAIN]
2858 + @ write r1 to DACR
2859 + mcr p15, 0, r1, c3, c0, 0
2860 + @ instruction sync
2861 + instr_sync
2862 + @ restore regs
2863 + ldmia sp!, {r0, r1}
2864 +#endif
2865 + .endm
2866 +
2867 + .macro pax_exit_kernel
2868 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2869 + @ save regs
2870 + stmdb sp!, {r0, r1}
2871 + @ read old DACR from stack into r1
2872 + ldr r1, [sp, #(8 + S_SP)]
2873 + sub r1, r1, #8
2874 + ldr r1, [r1]
2875 +
2876 + @ write r1 to current_thread_info()->cpu_domain
2877 + mov r0, sp
2878 + @ assume 8K pages, since we have to split the immediate in two
2879 + bic r0, r0, #(0x1fc0)
2880 + bic r0, r0, #(0x3f)
2881 + str r1, [r0, #TI_CPU_DOMAIN]
2882 + @ write r1 to DACR
2883 + mcr p15, 0, r1, c3, c0, 0
2884 + @ instruction sync
2885 + instr_sync
2886 + @ restore regs
2887 + ldmia sp!, {r0, r1}
2888 +#endif
2889 + .endm
2890 +
2891 #ifndef CONFIG_THUMB2_KERNEL
2892 .macro svc_exit, rpsr, irq = 0
2893 .if \irq != 0
2894 @@ -207,6 +261,9 @@
2895 blne trace_hardirqs_off
2896 #endif
2897 .endif
2898 +
2899 + pax_exit_kernel
2900 +
2901 msr spsr_cxsf, \rpsr
2902 #if defined(CONFIG_CPU_V6) || defined(CONFIG_CPU_32v6K)
2903 @ We must avoid clrex due to Cortex-A15 erratum #830321
2904 @@ -254,6 +311,9 @@
2905 blne trace_hardirqs_off
2906 #endif
2907 .endif
2908 +
2909 + pax_exit_kernel
2910 +
2911 ldr lr, [sp, #S_SP] @ top of the stack
2912 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
2913
2914 diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
2915 index 918875d..cd5fa27 100644
2916 --- a/arch/arm/kernel/fiq.c
2917 +++ b/arch/arm/kernel/fiq.c
2918 @@ -87,7 +87,10 @@ void set_fiq_handler(void *start, unsigned int length)
2919 void *base = vectors_page;
2920 unsigned offset = FIQ_OFFSET;
2921
2922 + pax_open_kernel();
2923 memcpy(base + offset, start, length);
2924 + pax_close_kernel();
2925 +
2926 if (!cache_is_vipt_nonaliasing())
2927 flush_icache_range((unsigned long)base + offset, offset +
2928 length);
2929 diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
2930 index 664eee8..f470938 100644
2931 --- a/arch/arm/kernel/head.S
2932 +++ b/arch/arm/kernel/head.S
2933 @@ -437,7 +437,7 @@ __enable_mmu:
2934 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2935 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2936 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
2937 - domain_val(DOMAIN_IO, DOMAIN_CLIENT))
2938 + domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
2939 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
2940 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
2941 #endif
2942 diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
2943 index 6a4dffe..4a86a70 100644
2944 --- a/arch/arm/kernel/module.c
2945 +++ b/arch/arm/kernel/module.c
2946 @@ -38,12 +38,39 @@
2947 #endif
2948
2949 #ifdef CONFIG_MMU
2950 -void *module_alloc(unsigned long size)
2951 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
2952 {
2953 + if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
2954 + return NULL;
2955 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
2956 - GFP_KERNEL, PAGE_KERNEL_EXEC, NUMA_NO_NODE,
2957 + GFP_KERNEL, prot, NUMA_NO_NODE,
2958 __builtin_return_address(0));
2959 }
2960 +
2961 +void *module_alloc(unsigned long size)
2962 +{
2963 +
2964 +#ifdef CONFIG_PAX_KERNEXEC
2965 + return __module_alloc(size, PAGE_KERNEL);
2966 +#else
2967 + return __module_alloc(size, PAGE_KERNEL_EXEC);
2968 +#endif
2969 +
2970 +}
2971 +
2972 +#ifdef CONFIG_PAX_KERNEXEC
2973 +void module_free_exec(struct module *mod, void *module_region)
2974 +{
2975 + module_free(mod, module_region);
2976 +}
2977 +EXPORT_SYMBOL(module_free_exec);
2978 +
2979 +void *module_alloc_exec(unsigned long size)
2980 +{
2981 + return __module_alloc(size, PAGE_KERNEL_EXEC);
2982 +}
2983 +EXPORT_SYMBOL(module_alloc_exec);
2984 +#endif
2985 #endif
2986
2987 int
2988 diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
2989 index 07314af..c46655c 100644
2990 --- a/arch/arm/kernel/patch.c
2991 +++ b/arch/arm/kernel/patch.c
2992 @@ -18,6 +18,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2993 bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL);
2994 int size;
2995
2996 + pax_open_kernel();
2997 if (thumb2 && __opcode_is_thumb16(insn)) {
2998 *(u16 *)addr = __opcode_to_mem_thumb16(insn);
2999 size = sizeof(u16);
3000 @@ -39,6 +40,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
3001 *(u32 *)addr = insn;
3002 size = sizeof(u32);
3003 }
3004 + pax_close_kernel();
3005
3006 flush_icache_range((uintptr_t)(addr),
3007 (uintptr_t)(addr) + size);
3008 diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
3009 index a35f6eb..7af43a0 100644
3010 --- a/arch/arm/kernel/process.c
3011 +++ b/arch/arm/kernel/process.c
3012 @@ -212,6 +212,7 @@ void machine_power_off(void)
3013
3014 if (pm_power_off)
3015 pm_power_off();
3016 + BUG();
3017 }
3018
3019 /*
3020 @@ -225,7 +226,7 @@ void machine_power_off(void)
3021 * executing pre-reset code, and using RAM that the primary CPU's code wishes
3022 * to use. Implementing such co-ordination would be essentially impossible.
3023 */
3024 -void machine_restart(char *cmd)
3025 +__noreturn void machine_restart(char *cmd)
3026 {
3027 local_irq_disable();
3028 smp_send_stop();
3029 @@ -248,8 +249,8 @@ void __show_regs(struct pt_regs *regs)
3030
3031 show_regs_print_info(KERN_DEFAULT);
3032
3033 - print_symbol("PC is at %s\n", instruction_pointer(regs));
3034 - print_symbol("LR is at %s\n", regs->ARM_lr);
3035 + printk("PC is at %pA\n", (void *)instruction_pointer(regs));
3036 + printk("LR is at %pA\n", (void *)regs->ARM_lr);
3037 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
3038 "sp : %08lx ip : %08lx fp : %08lx\n",
3039 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
3040 @@ -427,12 +428,6 @@ unsigned long get_wchan(struct task_struct *p)
3041 return 0;
3042 }
3043
3044 -unsigned long arch_randomize_brk(struct mm_struct *mm)
3045 -{
3046 - unsigned long range_end = mm->brk + 0x02000000;
3047 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
3048 -}
3049 -
3050 #ifdef CONFIG_MMU
3051 #ifdef CONFIG_KUSER_HELPERS
3052 /*
3053 @@ -448,7 +443,7 @@ static struct vm_area_struct gate_vma = {
3054
3055 static int __init gate_vma_init(void)
3056 {
3057 - gate_vma.vm_page_prot = PAGE_READONLY_EXEC;
3058 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
3059 return 0;
3060 }
3061 arch_initcall(gate_vma_init);
3062 @@ -474,41 +469,16 @@ int in_gate_area_no_mm(unsigned long addr)
3063
3064 const char *arch_vma_name(struct vm_area_struct *vma)
3065 {
3066 - return is_gate_vma(vma) ? "[vectors]" :
3067 - (vma->vm_mm && vma->vm_start == vma->vm_mm->context.sigpage) ?
3068 - "[sigpage]" : NULL;
3069 + return is_gate_vma(vma) ? "[vectors]" : NULL;
3070 }
3071
3072 -static struct page *signal_page;
3073 -extern struct page *get_signal_page(void);
3074 -
3075 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
3076 {
3077 struct mm_struct *mm = current->mm;
3078 - unsigned long addr;
3079 - int ret;
3080 -
3081 - if (!signal_page)
3082 - signal_page = get_signal_page();
3083 - if (!signal_page)
3084 - return -ENOMEM;
3085
3086 down_write(&mm->mmap_sem);
3087 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
3088 - if (IS_ERR_VALUE(addr)) {
3089 - ret = addr;
3090 - goto up_fail;
3091 - }
3092 -
3093 - ret = install_special_mapping(mm, addr, PAGE_SIZE,
3094 - VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC,
3095 - &signal_page);
3096 -
3097 - if (ret == 0)
3098 - mm->context.sigpage = addr;
3099 -
3100 - up_fail:
3101 + mm->context.sigpage = (PAGE_OFFSET + (get_random_int() % 0x3FFEFFE0)) & 0xFFFFFFFC;
3102 up_write(&mm->mmap_sem);
3103 - return ret;
3104 + return 0;
3105 }
3106 #endif
3107 diff --git a/arch/arm/kernel/psci.c b/arch/arm/kernel/psci.c
3108 index f73891b..cf3004e 100644
3109 --- a/arch/arm/kernel/psci.c
3110 +++ b/arch/arm/kernel/psci.c
3111 @@ -28,7 +28,7 @@
3112 #include <asm/psci.h>
3113 #include <asm/system_misc.h>
3114
3115 -struct psci_operations psci_ops;
3116 +struct psci_operations psci_ops __read_only;
3117
3118 static int (*invoke_psci_fn)(u32, u32, u32, u32);
3119 typedef int (*psci_initcall_t)(const struct device_node *);
3120 diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
3121 index 0c27ed6..b67388e 100644
3122 --- a/arch/arm/kernel/ptrace.c
3123 +++ b/arch/arm/kernel/ptrace.c
3124 @@ -928,10 +928,19 @@ static void tracehook_report_syscall(struct pt_regs *regs,
3125 regs->ARM_ip = ip;
3126 }
3127
3128 +#ifdef CONFIG_GRKERNSEC_SETXID
3129 +extern void gr_delayed_cred_worker(void);
3130 +#endif
3131 +
3132 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
3133 {
3134 current_thread_info()->syscall = scno;
3135
3136 +#ifdef CONFIG_GRKERNSEC_SETXID
3137 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
3138 + gr_delayed_cred_worker();
3139 +#endif
3140 +
3141 /* Do the secure computing check first; failures should be fast. */
3142 if (secure_computing(scno) == -1)
3143 return -1;
3144 diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
3145 index 84db893d..bd8213a 100644
3146 --- a/arch/arm/kernel/setup.c
3147 +++ b/arch/arm/kernel/setup.c
3148 @@ -104,21 +104,23 @@ EXPORT_SYMBOL(elf_hwcap);
3149 unsigned int elf_hwcap2 __read_mostly;
3150 EXPORT_SYMBOL(elf_hwcap2);
3151
3152 +pteval_t __supported_pte_mask __read_only;
3153 +pmdval_t __supported_pmd_mask __read_only;
3154
3155 #ifdef MULTI_CPU
3156 -struct processor processor __read_mostly;
3157 +struct processor processor __read_only;
3158 #endif
3159 #ifdef MULTI_TLB
3160 -struct cpu_tlb_fns cpu_tlb __read_mostly;
3161 +struct cpu_tlb_fns cpu_tlb __read_only;
3162 #endif
3163 #ifdef MULTI_USER
3164 -struct cpu_user_fns cpu_user __read_mostly;
3165 +struct cpu_user_fns cpu_user __read_only;
3166 #endif
3167 #ifdef MULTI_CACHE
3168 -struct cpu_cache_fns cpu_cache __read_mostly;
3169 +struct cpu_cache_fns cpu_cache __read_only;
3170 #endif
3171 #ifdef CONFIG_OUTER_CACHE
3172 -struct outer_cache_fns outer_cache __read_mostly;
3173 +struct outer_cache_fns outer_cache __read_only;
3174 EXPORT_SYMBOL(outer_cache);
3175 #endif
3176
3177 @@ -251,9 +253,13 @@ static int __get_cpu_architecture(void)
3178 asm("mrc p15, 0, %0, c0, c1, 4"
3179 : "=r" (mmfr0));
3180 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
3181 - (mmfr0 & 0x000000f0) >= 0x00000030)
3182 + (mmfr0 & 0x000000f0) >= 0x00000030) {
3183 cpu_arch = CPU_ARCH_ARMv7;
3184 - else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3185 + if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
3186 + __supported_pte_mask |= L_PTE_PXN;
3187 + __supported_pmd_mask |= PMD_PXNTABLE;
3188 + }
3189 + } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3190 (mmfr0 & 0x000000f0) == 0x00000020)
3191 cpu_arch = CPU_ARCH_ARMv6;
3192 else
3193 diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
3194 index bd19834..e4d8c66 100644
3195 --- a/arch/arm/kernel/signal.c
3196 +++ b/arch/arm/kernel/signal.c
3197 @@ -24,8 +24,6 @@
3198
3199 extern const unsigned long sigreturn_codes[7];
3200
3201 -static unsigned long signal_return_offset;
3202 -
3203 #ifdef CONFIG_CRUNCH
3204 static int preserve_crunch_context(struct crunch_sigframe __user *frame)
3205 {
3206 @@ -396,8 +394,7 @@ setup_return(struct pt_regs *regs, struct ksignal *ksig,
3207 * except when the MPU has protected the vectors
3208 * page from PL0
3209 */
3210 - retcode = mm->context.sigpage + signal_return_offset +
3211 - (idx << 2) + thumb;
3212 + retcode = mm->context.sigpage + (idx << 2) + thumb;
3213 } else
3214 #endif
3215 {
3216 @@ -604,33 +601,3 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)
3217 } while (thread_flags & _TIF_WORK_MASK);
3218 return 0;
3219 }
3220 -
3221 -struct page *get_signal_page(void)
3222 -{
3223 - unsigned long ptr;
3224 - unsigned offset;
3225 - struct page *page;
3226 - void *addr;
3227 -
3228 - page = alloc_pages(GFP_KERNEL, 0);
3229 -
3230 - if (!page)
3231 - return NULL;
3232 -
3233 - addr = page_address(page);
3234 -
3235 - /* Give the signal return code some randomness */
3236 - offset = 0x200 + (get_random_int() & 0x7fc);
3237 - signal_return_offset = offset;
3238 -
3239 - /*
3240 - * Copy signal return handlers into the vector page, and
3241 - * set sigreturn to be a pointer to these.
3242 - */
3243 - memcpy(addr + offset, sigreturn_codes, sizeof(sigreturn_codes));
3244 -
3245 - ptr = (unsigned long)addr + offset;
3246 - flush_icache_range(ptr, ptr + sizeof(sigreturn_codes));
3247 -
3248 - return page;
3249 -}
3250 diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
3251 index bbe22fc..d7737f5 100644
3252 --- a/arch/arm/kernel/smp.c
3253 +++ b/arch/arm/kernel/smp.c
3254 @@ -76,7 +76,7 @@ enum ipi_msg_type {
3255
3256 static DECLARE_COMPLETION(cpu_running);
3257
3258 -static struct smp_operations smp_ops;
3259 +static struct smp_operations smp_ops __read_only;
3260
3261 void __init smp_set_ops(struct smp_operations *ops)
3262 {
3263 diff --git a/arch/arm/kernel/tcm.c b/arch/arm/kernel/tcm.c
3264 index 7a3be1d..b00c7de 100644
3265 --- a/arch/arm/kernel/tcm.c
3266 +++ b/arch/arm/kernel/tcm.c
3267 @@ -61,7 +61,7 @@ static struct map_desc itcm_iomap[] __initdata = {
3268 .virtual = ITCM_OFFSET,
3269 .pfn = __phys_to_pfn(ITCM_OFFSET),
3270 .length = 0,
3271 - .type = MT_MEMORY_RWX_ITCM,
3272 + .type = MT_MEMORY_RX_ITCM,
3273 }
3274 };
3275
3276 @@ -267,7 +267,9 @@ no_dtcm:
3277 start = &__sitcm_text;
3278 end = &__eitcm_text;
3279 ram = &__itcm_start;
3280 + pax_open_kernel();
3281 memcpy(start, ram, itcm_code_sz);
3282 + pax_close_kernel();
3283 pr_debug("CPU ITCM: copied code from %p - %p\n",
3284 start, end);
3285 itcm_present = true;
3286 diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
3287 index bea63f5..bc660a7 100644
3288 --- a/arch/arm/kernel/traps.c
3289 +++ b/arch/arm/kernel/traps.c
3290 @@ -64,7 +64,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
3291 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
3292 {
3293 #ifdef CONFIG_KALLSYMS
3294 - printk("[<%08lx>] (%ps) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
3295 + printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
3296 #else
3297 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
3298 #endif
3299 @@ -266,6 +266,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
3300 static int die_owner = -1;
3301 static unsigned int die_nest_count;
3302
3303 +extern void gr_handle_kernel_exploit(void);
3304 +
3305 static unsigned long oops_begin(void)
3306 {
3307 int cpu;
3308 @@ -308,6 +310,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
3309 panic("Fatal exception in interrupt");
3310 if (panic_on_oops)
3311 panic("Fatal exception");
3312 +
3313 + gr_handle_kernel_exploit();
3314 +
3315 if (signr)
3316 do_exit(signr);
3317 }
3318 @@ -860,7 +865,11 @@ void __init early_trap_init(void *vectors_base)
3319 kuser_init(vectors_base);
3320
3321 flush_icache_range(vectors, vectors + PAGE_SIZE * 2);
3322 - modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
3323 +
3324 +#ifndef CONFIG_PAX_MEMORY_UDEREF
3325 + modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
3326 +#endif
3327 +
3328 #else /* ifndef CONFIG_CPU_V7M */
3329 /*
3330 * on V7-M there is no need to copy the vector table to a dedicated
3331 diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
3332 index 6f57cb9..645f8c4 100644
3333 --- a/arch/arm/kernel/vmlinux.lds.S
3334 +++ b/arch/arm/kernel/vmlinux.lds.S
3335 @@ -8,7 +8,11 @@
3336 #include <asm/thread_info.h>
3337 #include <asm/memory.h>
3338 #include <asm/page.h>
3339 -
3340 +
3341 +#ifdef CONFIG_PAX_KERNEXEC
3342 +#include <asm/pgtable.h>
3343 +#endif
3344 +
3345 #define PROC_INFO \
3346 . = ALIGN(4); \
3347 VMLINUX_SYMBOL(__proc_info_begin) = .; \
3348 @@ -34,7 +38,7 @@
3349 #endif
3350
3351 #if (defined(CONFIG_SMP_ON_UP) && !defined(CONFIG_DEBUG_SPINLOCK)) || \
3352 - defined(CONFIG_GENERIC_BUG)
3353 + defined(CONFIG_GENERIC_BUG) || defined(CONFIG_PAX_REFCOUNT)
3354 #define ARM_EXIT_KEEP(x) x
3355 #define ARM_EXIT_DISCARD(x)
3356 #else
3357 @@ -90,6 +94,11 @@ SECTIONS
3358 _text = .;
3359 HEAD_TEXT
3360 }
3361 +
3362 +#ifdef CONFIG_PAX_KERNEXEC
3363 + . = ALIGN(1<<SECTION_SHIFT);
3364 +#endif
3365 +
3366 .text : { /* Real text segment */
3367 _stext = .; /* Text and read-only data */
3368 __exception_text_start = .;
3369 @@ -112,6 +121,8 @@ SECTIONS
3370 ARM_CPU_KEEP(PROC_INFO)
3371 }
3372
3373 + _etext = .; /* End of text section */
3374 +
3375 RO_DATA(PAGE_SIZE)
3376
3377 . = ALIGN(4);
3378 @@ -142,7 +153,9 @@ SECTIONS
3379
3380 NOTES
3381
3382 - _etext = .; /* End of text and rodata section */
3383 +#ifdef CONFIG_PAX_KERNEXEC
3384 + . = ALIGN(1<<SECTION_SHIFT);
3385 +#endif
3386
3387 #ifndef CONFIG_XIP_KERNEL
3388 . = ALIGN(PAGE_SIZE);
3389 @@ -220,6 +233,11 @@ SECTIONS
3390 . = PAGE_OFFSET + TEXT_OFFSET;
3391 #else
3392 __init_end = .;
3393 +
3394 +#ifdef CONFIG_PAX_KERNEXEC
3395 + . = ALIGN(1<<SECTION_SHIFT);
3396 +#endif
3397 +
3398 . = ALIGN(THREAD_SIZE);
3399 __data_loc = .;
3400 #endif
3401 diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
3402 index a99e0cd..ab56421d 100644
3403 --- a/arch/arm/kvm/arm.c
3404 +++ b/arch/arm/kvm/arm.c
3405 @@ -57,7 +57,7 @@ static unsigned long hyp_default_vectors;
3406 static DEFINE_PER_CPU(struct kvm_vcpu *, kvm_arm_running_vcpu);
3407
3408 /* The VMID used in the VTTBR */
3409 -static atomic64_t kvm_vmid_gen = ATOMIC64_INIT(1);
3410 +static atomic64_unchecked_t kvm_vmid_gen = ATOMIC64_INIT(1);
3411 static u8 kvm_next_vmid;
3412 static DEFINE_SPINLOCK(kvm_vmid_lock);
3413
3414 @@ -372,7 +372,7 @@ void force_vm_exit(const cpumask_t *mask)
3415 */
3416 static bool need_new_vmid_gen(struct kvm *kvm)
3417 {
3418 - return unlikely(kvm->arch.vmid_gen != atomic64_read(&kvm_vmid_gen));
3419 + return unlikely(kvm->arch.vmid_gen != atomic64_read_unchecked(&kvm_vmid_gen));
3420 }
3421
3422 /**
3423 @@ -405,7 +405,7 @@ static void update_vttbr(struct kvm *kvm)
3424
3425 /* First user of a new VMID generation? */
3426 if (unlikely(kvm_next_vmid == 0)) {
3427 - atomic64_inc(&kvm_vmid_gen);
3428 + atomic64_inc_unchecked(&kvm_vmid_gen);
3429 kvm_next_vmid = 1;
3430
3431 /*
3432 @@ -422,7 +422,7 @@ static void update_vttbr(struct kvm *kvm)
3433 kvm_call_hyp(__kvm_flush_vm_context);
3434 }
3435
3436 - kvm->arch.vmid_gen = atomic64_read(&kvm_vmid_gen);
3437 + kvm->arch.vmid_gen = atomic64_read_unchecked(&kvm_vmid_gen);
3438 kvm->arch.vmid = kvm_next_vmid;
3439 kvm_next_vmid++;
3440
3441 @@ -997,7 +997,7 @@ static void check_kvm_target_cpu(void *ret)
3442 /**
3443 * Initialize Hyp-mode and memory mappings on all CPUs.
3444 */
3445 -int kvm_arch_init(void *opaque)
3446 +int kvm_arch_init(const void *opaque)
3447 {
3448 int err;
3449 int ret, cpu;
3450 diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3451 index 14a0d98..7771a7d 100644
3452 --- a/arch/arm/lib/clear_user.S
3453 +++ b/arch/arm/lib/clear_user.S
3454 @@ -12,14 +12,14 @@
3455
3456 .text
3457
3458 -/* Prototype: int __clear_user(void *addr, size_t sz)
3459 +/* Prototype: int ___clear_user(void *addr, size_t sz)
3460 * Purpose : clear some user memory
3461 * Params : addr - user memory address to clear
3462 * : sz - number of bytes to clear
3463 * Returns : number of bytes NOT cleared
3464 */
3465 ENTRY(__clear_user_std)
3466 -WEAK(__clear_user)
3467 +WEAK(___clear_user)
3468 stmfd sp!, {r1, lr}
3469 mov r2, #0
3470 cmp r1, #4
3471 @@ -44,7 +44,7 @@ WEAK(__clear_user)
3472 USER( strnebt r2, [r0])
3473 mov r0, #0
3474 ldmfd sp!, {r1, pc}
3475 -ENDPROC(__clear_user)
3476 +ENDPROC(___clear_user)
3477 ENDPROC(__clear_user_std)
3478
3479 .pushsection .fixup,"ax"
3480 diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3481 index 66a477a..bee61d3 100644
3482 --- a/arch/arm/lib/copy_from_user.S
3483 +++ b/arch/arm/lib/copy_from_user.S
3484 @@ -16,7 +16,7 @@
3485 /*
3486 * Prototype:
3487 *
3488 - * size_t __copy_from_user(void *to, const void *from, size_t n)
3489 + * size_t ___copy_from_user(void *to, const void *from, size_t n)
3490 *
3491 * Purpose:
3492 *
3493 @@ -84,11 +84,11 @@
3494
3495 .text
3496
3497 -ENTRY(__copy_from_user)
3498 +ENTRY(___copy_from_user)
3499
3500 #include "copy_template.S"
3501
3502 -ENDPROC(__copy_from_user)
3503 +ENDPROC(___copy_from_user)
3504
3505 .pushsection .fixup,"ax"
3506 .align 0
3507 diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3508 index 6ee2f67..d1cce76 100644
3509 --- a/arch/arm/lib/copy_page.S
3510 +++ b/arch/arm/lib/copy_page.S
3511 @@ -10,6 +10,7 @@
3512 * ASM optimised string functions
3513 */
3514 #include <linux/linkage.h>
3515 +#include <linux/const.h>
3516 #include <asm/assembler.h>
3517 #include <asm/asm-offsets.h>
3518 #include <asm/cache.h>
3519 diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3520 index d066df6..df28194 100644
3521 --- a/arch/arm/lib/copy_to_user.S
3522 +++ b/arch/arm/lib/copy_to_user.S
3523 @@ -16,7 +16,7 @@
3524 /*
3525 * Prototype:
3526 *
3527 - * size_t __copy_to_user(void *to, const void *from, size_t n)
3528 + * size_t ___copy_to_user(void *to, const void *from, size_t n)
3529 *
3530 * Purpose:
3531 *
3532 @@ -88,11 +88,11 @@
3533 .text
3534
3535 ENTRY(__copy_to_user_std)
3536 -WEAK(__copy_to_user)
3537 +WEAK(___copy_to_user)
3538
3539 #include "copy_template.S"
3540
3541 -ENDPROC(__copy_to_user)
3542 +ENDPROC(___copy_to_user)
3543 ENDPROC(__copy_to_user_std)
3544
3545 .pushsection .fixup,"ax"
3546 diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3547 index 7d08b43..f7ca7ea 100644
3548 --- a/arch/arm/lib/csumpartialcopyuser.S
3549 +++ b/arch/arm/lib/csumpartialcopyuser.S
3550 @@ -57,8 +57,8 @@
3551 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3552 */
3553
3554 -#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3555 -#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3556 +#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3557 +#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3558
3559 #include "csumpartialcopygeneric.S"
3560
3561 diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3562 index 312d43e..21d2322 100644
3563 --- a/arch/arm/lib/delay.c
3564 +++ b/arch/arm/lib/delay.c
3565 @@ -29,7 +29,7 @@
3566 /*
3567 * Default to the loop-based delay implementation.
3568 */
3569 -struct arm_delay_ops arm_delay_ops = {
3570 +struct arm_delay_ops arm_delay_ops __read_only = {
3571 .delay = __loop_delay,
3572 .const_udelay = __loop_const_udelay,
3573 .udelay = __loop_udelay,
3574 diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3575 index 3e58d71..029817c 100644
3576 --- a/arch/arm/lib/uaccess_with_memcpy.c
3577 +++ b/arch/arm/lib/uaccess_with_memcpy.c
3578 @@ -136,7 +136,7 @@ out:
3579 }
3580
3581 unsigned long
3582 -__copy_to_user(void __user *to, const void *from, unsigned long n)
3583 +___copy_to_user(void __user *to, const void *from, unsigned long n)
3584 {
3585 /*
3586 * This test is stubbed out of the main function above to keep
3587 @@ -190,7 +190,7 @@ out:
3588 return n;
3589 }
3590
3591 -unsigned long __clear_user(void __user *addr, unsigned long n)
3592 +unsigned long ___clear_user(void __user *addr, unsigned long n)
3593 {
3594 /* See rational for this in __copy_to_user() above. */
3595 if (n < 64)
3596 diff --git a/arch/arm/mach-at91/setup.c b/arch/arm/mach-at91/setup.c
3597 index f7a07a5..258e1f7 100644
3598 --- a/arch/arm/mach-at91/setup.c
3599 +++ b/arch/arm/mach-at91/setup.c
3600 @@ -81,7 +81,7 @@ void __init at91_init_sram(int bank, unsigned long base, unsigned int length)
3601
3602 desc->pfn = __phys_to_pfn(base);
3603 desc->length = length;
3604 - desc->type = MT_MEMORY_RWX_NONCACHED;
3605 + desc->type = MT_MEMORY_RW_NONCACHED;
3606
3607 pr_info("AT91: sram at 0x%lx of 0x%x mapped at 0x%lx\n",
3608 base, length, desc->virtual);
3609 diff --git a/arch/arm/mach-keystone/keystone.c b/arch/arm/mach-keystone/keystone.c
3610 index 7f352de..6dc0929 100644
3611 --- a/arch/arm/mach-keystone/keystone.c
3612 +++ b/arch/arm/mach-keystone/keystone.c
3613 @@ -27,7 +27,7 @@
3614
3615 #include "keystone.h"
3616
3617 -static struct notifier_block platform_nb;
3618 +static notifier_block_no_const platform_nb;
3619 static unsigned long keystone_dma_pfn_offset __read_mostly;
3620
3621 static int keystone_platform_notifier(struct notifier_block *nb,
3622 diff --git a/arch/arm/mach-mvebu/coherency.c b/arch/arm/mach-mvebu/coherency.c
3623 index 044b511..afd1da8 100644
3624 --- a/arch/arm/mach-mvebu/coherency.c
3625 +++ b/arch/arm/mach-mvebu/coherency.c
3626 @@ -316,7 +316,7 @@ static void __init armada_370_coherency_init(struct device_node *np)
3627
3628 /*
3629 * This ioremap hook is used on Armada 375/38x to ensure that PCIe
3630 - * memory areas are mapped as MT_UNCACHED instead of MT_DEVICE. This
3631 + * memory areas are mapped as MT_UNCACHED_RW instead of MT_DEVICE. This
3632 * is needed as a workaround for a deadlock issue between the PCIe
3633 * interface and the cache controller.
3634 */
3635 @@ -329,7 +329,7 @@ armada_pcie_wa_ioremap_caller(phys_addr_t phys_addr, size_t size,
3636 mvebu_mbus_get_pcie_mem_aperture(&pcie_mem);
3637
3638 if (pcie_mem.start <= phys_addr && (phys_addr + size) <= pcie_mem.end)
3639 - mtype = MT_UNCACHED;
3640 + mtype = MT_UNCACHED_RW;
3641
3642 return __arm_ioremap_caller(phys_addr, size, mtype, caller);
3643 }
3644 diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3645 index aead77a..a2253fa 100644
3646 --- a/arch/arm/mach-omap2/board-n8x0.c
3647 +++ b/arch/arm/mach-omap2/board-n8x0.c
3648 @@ -568,7 +568,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3649 }
3650 #endif
3651
3652 -static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3653 +static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3654 .late_init = n8x0_menelaus_late_init,
3655 };
3656
3657 diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
3658 index 2f97228..6ce10e1 100644
3659 --- a/arch/arm/mach-omap2/gpmc.c
3660 +++ b/arch/arm/mach-omap2/gpmc.c
3661 @@ -151,7 +151,6 @@ struct omap3_gpmc_regs {
3662 };
3663
3664 static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
3665 -static struct irq_chip gpmc_irq_chip;
3666 static int gpmc_irq_start;
3667
3668 static struct resource gpmc_mem_root;
3669 @@ -736,6 +735,18 @@ static void gpmc_irq_noop(struct irq_data *data) { }
3670
3671 static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
3672
3673 +static struct irq_chip gpmc_irq_chip = {
3674 + .name = "gpmc",
3675 + .irq_startup = gpmc_irq_noop_ret,
3676 + .irq_enable = gpmc_irq_enable,
3677 + .irq_disable = gpmc_irq_disable,
3678 + .irq_shutdown = gpmc_irq_noop,
3679 + .irq_ack = gpmc_irq_noop,
3680 + .irq_mask = gpmc_irq_noop,
3681 + .irq_unmask = gpmc_irq_noop,
3682 +
3683 +};
3684 +
3685 static int gpmc_setup_irq(void)
3686 {
3687 int i;
3688 @@ -750,15 +761,6 @@ static int gpmc_setup_irq(void)
3689 return gpmc_irq_start;
3690 }
3691
3692 - gpmc_irq_chip.name = "gpmc";
3693 - gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
3694 - gpmc_irq_chip.irq_enable = gpmc_irq_enable;
3695 - gpmc_irq_chip.irq_disable = gpmc_irq_disable;
3696 - gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
3697 - gpmc_irq_chip.irq_ack = gpmc_irq_noop;
3698 - gpmc_irq_chip.irq_mask = gpmc_irq_noop;
3699 - gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
3700 -
3701 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
3702 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
3703
3704 diff --git a/arch/arm/mach-omap2/omap-mpuss-lowpower.c b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3705 index 4001325..b14e2a0 100644
3706 --- a/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3707 +++ b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3708 @@ -84,7 +84,7 @@ struct cpu_pm_ops {
3709 int (*finish_suspend)(unsigned long cpu_state);
3710 void (*resume)(void);
3711 void (*scu_prepare)(unsigned int cpu_id, unsigned int cpu_state);
3712 -};
3713 +} __no_const;
3714
3715 static DEFINE_PER_CPU(struct omap4_cpu_pm_info, omap4_pm_info);
3716 static struct powerdomain *mpuss_pd;
3717 @@ -102,7 +102,7 @@ static void dummy_cpu_resume(void)
3718 static void dummy_scu_prepare(unsigned int cpu_id, unsigned int cpu_state)
3719 {}
3720
3721 -struct cpu_pm_ops omap_pm_ops = {
3722 +static struct cpu_pm_ops omap_pm_ops __read_only = {
3723 .finish_suspend = default_finish_suspend,
3724 .resume = dummy_cpu_resume,
3725 .scu_prepare = dummy_scu_prepare,
3726 diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3727 index 37843a7..a98df13 100644
3728 --- a/arch/arm/mach-omap2/omap-wakeupgen.c
3729 +++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3730 @@ -343,7 +343,7 @@ static int irq_cpu_hotplug_notify(struct notifier_block *self,
3731 return NOTIFY_OK;
3732 }
3733
3734 -static struct notifier_block __refdata irq_hotplug_notifier = {
3735 +static struct notifier_block irq_hotplug_notifier = {
3736 .notifier_call = irq_cpu_hotplug_notify,
3737 };
3738
3739 diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
3740 index d22c30d..23697a1 100644
3741 --- a/arch/arm/mach-omap2/omap_device.c
3742 +++ b/arch/arm/mach-omap2/omap_device.c
3743 @@ -510,7 +510,7 @@ void omap_device_delete(struct omap_device *od)
3744 struct platform_device __init *omap_device_build(const char *pdev_name,
3745 int pdev_id,
3746 struct omap_hwmod *oh,
3747 - void *pdata, int pdata_len)
3748 + const void *pdata, int pdata_len)
3749 {
3750 struct omap_hwmod *ohs[] = { oh };
3751
3752 @@ -538,7 +538,7 @@ struct platform_device __init *omap_device_build(const char *pdev_name,
3753 struct platform_device __init *omap_device_build_ss(const char *pdev_name,
3754 int pdev_id,
3755 struct omap_hwmod **ohs,
3756 - int oh_cnt, void *pdata,
3757 + int oh_cnt, const void *pdata,
3758 int pdata_len)
3759 {
3760 int ret = -ENOMEM;
3761 diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_device.h
3762 index 78c02b3..c94109a 100644
3763 --- a/arch/arm/mach-omap2/omap_device.h
3764 +++ b/arch/arm/mach-omap2/omap_device.h
3765 @@ -72,12 +72,12 @@ int omap_device_idle(struct platform_device *pdev);
3766 /* Core code interface */
3767
3768 struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
3769 - struct omap_hwmod *oh, void *pdata,
3770 + struct omap_hwmod *oh, const void *pdata,
3771 int pdata_len);
3772
3773 struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
3774 struct omap_hwmod **oh, int oh_cnt,
3775 - void *pdata, int pdata_len);
3776 + const void *pdata, int pdata_len);
3777
3778 struct omap_device *omap_device_alloc(struct platform_device *pdev,
3779 struct omap_hwmod **ohs, int oh_cnt);
3780 diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3781 index 9e91a4e..357ed0d 100644
3782 --- a/arch/arm/mach-omap2/omap_hwmod.c
3783 +++ b/arch/arm/mach-omap2/omap_hwmod.c
3784 @@ -194,10 +194,10 @@ struct omap_hwmod_soc_ops {
3785 int (*init_clkdm)(struct omap_hwmod *oh);
3786 void (*update_context_lost)(struct omap_hwmod *oh);
3787 int (*get_context_lost)(struct omap_hwmod *oh);
3788 -};
3789 +} __no_const;
3790
3791 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3792 -static struct omap_hwmod_soc_ops soc_ops;
3793 +static struct omap_hwmod_soc_ops soc_ops __read_only;
3794
3795 /* omap_hwmod_list contains all registered struct omap_hwmods */
3796 static LIST_HEAD(omap_hwmod_list);
3797 diff --git a/arch/arm/mach-omap2/powerdomains43xx_data.c b/arch/arm/mach-omap2/powerdomains43xx_data.c
3798 index 95fee54..cfa9cf1 100644
3799 --- a/arch/arm/mach-omap2/powerdomains43xx_data.c
3800 +++ b/arch/arm/mach-omap2/powerdomains43xx_data.c
3801 @@ -10,6 +10,7 @@
3802
3803 #include <linux/kernel.h>
3804 #include <linux/init.h>
3805 +#include <asm/pgtable.h>
3806
3807 #include "powerdomain.h"
3808
3809 @@ -129,7 +130,9 @@ static int am43xx_check_vcvp(void)
3810
3811 void __init am43xx_powerdomains_init(void)
3812 {
3813 - omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
3814 + pax_open_kernel();
3815 + *(void **)&omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
3816 + pax_close_kernel();
3817 pwrdm_register_platform_funcs(&omap4_pwrdm_operations);
3818 pwrdm_register_pwrdms(powerdomains_am43xx);
3819 pwrdm_complete_init();
3820 diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
3821 index 97d6607..8429d14 100644
3822 --- a/arch/arm/mach-omap2/wd_timer.c
3823 +++ b/arch/arm/mach-omap2/wd_timer.c
3824 @@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
3825 struct omap_hwmod *oh;
3826 char *oh_name = "wd_timer2";
3827 char *dev_name = "omap_wdt";
3828 - struct omap_wd_timer_platform_data pdata;
3829 + static struct omap_wd_timer_platform_data pdata = {
3830 + .read_reset_sources = prm_read_reset_sources
3831 + };
3832
3833 if (!cpu_class_is_omap2() || of_have_populated_dt())
3834 return 0;
3835 @@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
3836 return -EINVAL;
3837 }
3838
3839 - pdata.read_reset_sources = prm_read_reset_sources;
3840 -
3841 pdev = omap_device_build(dev_name, id, oh, &pdata,
3842 sizeof(struct omap_wd_timer_platform_data));
3843 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n",
3844 diff --git a/arch/arm/mach-tegra/cpuidle-tegra20.c b/arch/arm/mach-tegra/cpuidle-tegra20.c
3845 index b30bf5c..d0825bf 100644
3846 --- a/arch/arm/mach-tegra/cpuidle-tegra20.c
3847 +++ b/arch/arm/mach-tegra/cpuidle-tegra20.c
3848 @@ -180,7 +180,7 @@ static int tegra20_idle_lp2_coupled(struct cpuidle_device *dev,
3849 bool entered_lp2 = false;
3850
3851 if (tegra_pending_sgi())
3852 - ACCESS_ONCE(abort_flag) = true;
3853 + ACCESS_ONCE_RW(abort_flag) = true;
3854
3855 cpuidle_coupled_parallel_barrier(dev, &abort_barrier);
3856
3857 diff --git a/arch/arm/mach-ux500/setup.h b/arch/arm/mach-ux500/setup.h
3858 index 2dea8b5..6499da2 100644
3859 --- a/arch/arm/mach-ux500/setup.h
3860 +++ b/arch/arm/mach-ux500/setup.h
3861 @@ -33,13 +33,6 @@ extern void ux500_timer_init(void);
3862 .type = MT_DEVICE, \
3863 }
3864
3865 -#define __MEM_DEV_DESC(x, sz) { \
3866 - .virtual = IO_ADDRESS(x), \
3867 - .pfn = __phys_to_pfn(x), \
3868 - .length = sz, \
3869 - .type = MT_MEMORY_RWX, \
3870 -}
3871 -
3872 extern struct smp_operations ux500_smp_ops;
3873 extern void ux500_cpu_die(unsigned int cpu);
3874
3875 diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3876 index 7eb94e6..799ad3e 100644
3877 --- a/arch/arm/mm/Kconfig
3878 +++ b/arch/arm/mm/Kconfig
3879 @@ -446,6 +446,7 @@ config CPU_32v5
3880
3881 config CPU_32v6
3882 bool
3883 + select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3884 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3885
3886 config CPU_32v6K
3887 @@ -600,6 +601,7 @@ config CPU_CP15_MPU
3888
3889 config CPU_USE_DOMAINS
3890 bool
3891 + depends on !ARM_LPAE && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3892 help
3893 This option enables or disables the use of domain switching
3894 via the set_fs() function.
3895 @@ -798,7 +800,7 @@ config NEED_KUSER_HELPERS
3896
3897 config KUSER_HELPERS
3898 bool "Enable kuser helpers in vector page" if !NEED_KUSER_HELPERS
3899 - depends on MMU
3900 + depends on MMU && (!(CPU_V6 || CPU_V6K || CPU_V7) || GRKERNSEC_OLD_ARM_USERLAND)
3901 default y
3902 help
3903 Warning: disabling this option may break user programs.
3904 @@ -812,7 +814,7 @@ config KUSER_HELPERS
3905 See Documentation/arm/kernel_user_helpers.txt for details.
3906
3907 However, the fixed address nature of these helpers can be used
3908 - by ROP (return orientated programming) authors when creating
3909 + by ROP (Return Oriented Programming) authors when creating
3910 exploits.
3911
3912 If all of the binaries and libraries which run on your platform
3913 diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c
3914 index 83792f4..c25d36b 100644
3915 --- a/arch/arm/mm/alignment.c
3916 +++ b/arch/arm/mm/alignment.c
3917 @@ -216,10 +216,12 @@ union offset_union {
3918 #define __get16_unaligned_check(ins,val,addr) \
3919 do { \
3920 unsigned int err = 0, v, a = addr; \
3921 + pax_open_userland(); \
3922 __get8_unaligned_check(ins,v,a,err); \
3923 val = v << ((BE) ? 8 : 0); \
3924 __get8_unaligned_check(ins,v,a,err); \
3925 val |= v << ((BE) ? 0 : 8); \
3926 + pax_close_userland(); \
3927 if (err) \
3928 goto fault; \
3929 } while (0)
3930 @@ -233,6 +235,7 @@ union offset_union {
3931 #define __get32_unaligned_check(ins,val,addr) \
3932 do { \
3933 unsigned int err = 0, v, a = addr; \
3934 + pax_open_userland(); \
3935 __get8_unaligned_check(ins,v,a,err); \
3936 val = v << ((BE) ? 24 : 0); \
3937 __get8_unaligned_check(ins,v,a,err); \
3938 @@ -241,6 +244,7 @@ union offset_union {
3939 val |= v << ((BE) ? 8 : 16); \
3940 __get8_unaligned_check(ins,v,a,err); \
3941 val |= v << ((BE) ? 0 : 24); \
3942 + pax_close_userland(); \
3943 if (err) \
3944 goto fault; \
3945 } while (0)
3946 @@ -254,6 +258,7 @@ union offset_union {
3947 #define __put16_unaligned_check(ins,val,addr) \
3948 do { \
3949 unsigned int err = 0, v = val, a = addr; \
3950 + pax_open_userland(); \
3951 __asm__( FIRST_BYTE_16 \
3952 ARM( "1: "ins" %1, [%2], #1\n" ) \
3953 THUMB( "1: "ins" %1, [%2]\n" ) \
3954 @@ -273,6 +278,7 @@ union offset_union {
3955 " .popsection\n" \
3956 : "=r" (err), "=&r" (v), "=&r" (a) \
3957 : "0" (err), "1" (v), "2" (a)); \
3958 + pax_close_userland(); \
3959 if (err) \
3960 goto fault; \
3961 } while (0)
3962 @@ -286,6 +292,7 @@ union offset_union {
3963 #define __put32_unaligned_check(ins,val,addr) \
3964 do { \
3965 unsigned int err = 0, v = val, a = addr; \
3966 + pax_open_userland(); \
3967 __asm__( FIRST_BYTE_32 \
3968 ARM( "1: "ins" %1, [%2], #1\n" ) \
3969 THUMB( "1: "ins" %1, [%2]\n" ) \
3970 @@ -315,6 +322,7 @@ union offset_union {
3971 " .popsection\n" \
3972 : "=r" (err), "=&r" (v), "=&r" (a) \
3973 : "0" (err), "1" (v), "2" (a)); \
3974 + pax_close_userland(); \
3975 if (err) \
3976 goto fault; \
3977 } while (0)
3978 diff --git a/arch/arm/mm/cache-l2x0.c b/arch/arm/mm/cache-l2x0.c
3979 index 5f2c988..221412d 100644
3980 --- a/arch/arm/mm/cache-l2x0.c
3981 +++ b/arch/arm/mm/cache-l2x0.c
3982 @@ -41,7 +41,7 @@ struct l2c_init_data {
3983 void (*fixup)(void __iomem *, u32, struct outer_cache_fns *);
3984 void (*save)(void __iomem *);
3985 struct outer_cache_fns outer_cache;
3986 -};
3987 +} __do_const;
3988
3989 #define CACHE_LINE_SIZE 32
3990
3991 diff --git a/arch/arm/mm/context.c b/arch/arm/mm/context.c
3992 index 6eb97b3..ac509f6 100644
3993 --- a/arch/arm/mm/context.c
3994 +++ b/arch/arm/mm/context.c
3995 @@ -43,7 +43,7 @@
3996 #define NUM_USER_ASIDS ASID_FIRST_VERSION
3997
3998 static DEFINE_RAW_SPINLOCK(cpu_asid_lock);
3999 -static atomic64_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
4000 +static atomic64_unchecked_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
4001 static DECLARE_BITMAP(asid_map, NUM_USER_ASIDS);
4002
4003 static DEFINE_PER_CPU(atomic64_t, active_asids);
4004 @@ -182,7 +182,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
4005 {
4006 static u32 cur_idx = 1;
4007 u64 asid = atomic64_read(&mm->context.id);
4008 - u64 generation = atomic64_read(&asid_generation);
4009 + u64 generation = atomic64_read_unchecked(&asid_generation);
4010
4011 if (asid != 0 && is_reserved_asid(asid)) {
4012 /*
4013 @@ -203,7 +203,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
4014 */
4015 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, cur_idx);
4016 if (asid == NUM_USER_ASIDS) {
4017 - generation = atomic64_add_return(ASID_FIRST_VERSION,
4018 + generation = atomic64_add_return_unchecked(ASID_FIRST_VERSION,
4019 &asid_generation);
4020 flush_context(cpu);
4021 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
4022 @@ -234,14 +234,14 @@ void check_and_switch_context(struct mm_struct *mm, struct task_struct *tsk)
4023 cpu_set_reserved_ttbr0();
4024
4025 asid = atomic64_read(&mm->context.id);
4026 - if (!((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS)
4027 + if (!((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS)
4028 && atomic64_xchg(&per_cpu(active_asids, cpu), asid))
4029 goto switch_mm_fastpath;
4030
4031 raw_spin_lock_irqsave(&cpu_asid_lock, flags);
4032 /* Check that our ASID belongs to the current generation. */
4033 asid = atomic64_read(&mm->context.id);
4034 - if ((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS) {
4035 + if ((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS) {
4036 asid = new_context(mm, cpu);
4037 atomic64_set(&mm->context.id, asid);
4038 }
4039 diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
4040 index eb8830a..e8ff52e 100644
4041 --- a/arch/arm/mm/fault.c
4042 +++ b/arch/arm/mm/fault.c
4043 @@ -25,6 +25,7 @@
4044 #include <asm/system_misc.h>
4045 #include <asm/system_info.h>
4046 #include <asm/tlbflush.h>
4047 +#include <asm/sections.h>
4048
4049 #include "fault.h"
4050
4051 @@ -138,6 +139,31 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
4052 if (fixup_exception(regs))
4053 return;
4054
4055 +#ifdef CONFIG_PAX_MEMORY_UDEREF
4056 + if (addr < TASK_SIZE) {
4057 + if (current->signal->curr_ip)
4058 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
4059 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
4060 + else
4061 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
4062 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
4063 + }
4064 +#endif
4065 +
4066 +#ifdef CONFIG_PAX_KERNEXEC
4067 + if ((fsr & FSR_WRITE) &&
4068 + (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
4069 + (MODULES_VADDR <= addr && addr < MODULES_END)))
4070 + {
4071 + if (current->signal->curr_ip)
4072 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
4073 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
4074 + else
4075 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
4076 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
4077 + }
4078 +#endif
4079 +
4080 /*
4081 * No handler, we'll have to terminate things with extreme prejudice.
4082 */
4083 @@ -174,6 +200,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
4084 }
4085 #endif
4086
4087 +#ifdef CONFIG_PAX_PAGEEXEC
4088 + if (fsr & FSR_LNX_PF) {
4089 + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
4090 + do_group_exit(SIGKILL);
4091 + }
4092 +#endif
4093 +
4094 tsk->thread.address = addr;
4095 tsk->thread.error_code = fsr;
4096 tsk->thread.trap_no = 14;
4097 @@ -401,6 +434,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
4098 }
4099 #endif /* CONFIG_MMU */
4100
4101 +#ifdef CONFIG_PAX_PAGEEXEC
4102 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4103 +{
4104 + long i;
4105 +
4106 + printk(KERN_ERR "PAX: bytes at PC: ");
4107 + for (i = 0; i < 20; i++) {
4108 + unsigned char c;
4109 + if (get_user(c, (__force unsigned char __user *)pc+i))
4110 + printk(KERN_CONT "?? ");
4111 + else
4112 + printk(KERN_CONT "%02x ", c);
4113 + }
4114 + printk("\n");
4115 +
4116 + printk(KERN_ERR "PAX: bytes at SP-4: ");
4117 + for (i = -1; i < 20; i++) {
4118 + unsigned long c;
4119 + if (get_user(c, (__force unsigned long __user *)sp+i))
4120 + printk(KERN_CONT "???????? ");
4121 + else
4122 + printk(KERN_CONT "%08lx ", c);
4123 + }
4124 + printk("\n");
4125 +}
4126 +#endif
4127 +
4128 /*
4129 * First Level Translation Fault Handler
4130 *
4131 @@ -548,9 +608,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
4132 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
4133 struct siginfo info;
4134
4135 +#ifdef CONFIG_PAX_MEMORY_UDEREF
4136 + if (addr < TASK_SIZE && is_domain_fault(fsr)) {
4137 + if (current->signal->curr_ip)
4138 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
4139 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
4140 + else
4141 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
4142 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
4143 + goto die;
4144 + }
4145 +#endif
4146 +
4147 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
4148 return;
4149
4150 +die:
4151 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
4152 inf->name, fsr, addr);
4153
4154 @@ -574,15 +647,104 @@ hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int, struct pt_regs *
4155 ifsr_info[nr].name = name;
4156 }
4157
4158 +asmlinkage int sys_sigreturn(struct pt_regs *regs);
4159 +asmlinkage int sys_rt_sigreturn(struct pt_regs *regs);
4160 +
4161 asmlinkage void __exception
4162 do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
4163 {
4164 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
4165 struct siginfo info;
4166 + unsigned long pc = instruction_pointer(regs);
4167 +
4168 + if (user_mode(regs)) {
4169 + unsigned long sigpage = current->mm->context.sigpage;
4170 +
4171 + if (sigpage <= pc && pc < sigpage + 7*4) {
4172 + if (pc < sigpage + 3*4)
4173 + sys_sigreturn(regs);
4174 + else
4175 + sys_rt_sigreturn(regs);
4176 + return;
4177 + }
4178 + if (pc == 0xffff0f60UL) {
4179 + /*
4180 + * PaX: __kuser_cmpxchg64 emulation
4181 + */
4182 + // TODO
4183 + //regs->ARM_pc = regs->ARM_lr;
4184 + //return;
4185 + }
4186 + if (pc == 0xffff0fa0UL) {
4187 + /*
4188 + * PaX: __kuser_memory_barrier emulation
4189 + */
4190 + // dmb(); implied by the exception
4191 + regs->ARM_pc = regs->ARM_lr;
4192 + return;
4193 + }
4194 + if (pc == 0xffff0fc0UL) {
4195 + /*
4196 + * PaX: __kuser_cmpxchg emulation
4197 + */
4198 + // TODO
4199 + //long new;
4200 + //int op;
4201 +
4202 + //op = FUTEX_OP_SET << 28;
4203 + //new = futex_atomic_op_inuser(op, regs->ARM_r2);
4204 + //regs->ARM_r0 = old != new;
4205 + //regs->ARM_pc = regs->ARM_lr;
4206 + //return;
4207 + }
4208 + if (pc == 0xffff0fe0UL) {
4209 + /*
4210 + * PaX: __kuser_get_tls emulation
4211 + */
4212 + regs->ARM_r0 = current_thread_info()->tp_value[0];
4213 + regs->ARM_pc = regs->ARM_lr;
4214 + return;
4215 + }
4216 + }
4217 +
4218 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4219 + else if (is_domain_fault(ifsr) || is_xn_fault(ifsr)) {
4220 + if (current->signal->curr_ip)
4221 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
4222 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4223 + pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4224 + else
4225 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
4226 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4227 + pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4228 + goto die;
4229 + }
4230 +#endif
4231 +
4232 +#ifdef CONFIG_PAX_REFCOUNT
4233 + if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
4234 +#ifdef CONFIG_THUMB2_KERNEL
4235 + unsigned short bkpt;
4236 +
4237 + if (!probe_kernel_address(pc, bkpt) && cpu_to_le16(bkpt) == 0xbef1) {
4238 +#else
4239 + unsigned int bkpt;
4240 +
4241 + if (!probe_kernel_address(pc, bkpt) && cpu_to_le32(bkpt) == 0xe12f1073) {
4242 +#endif
4243 + current->thread.error_code = ifsr;
4244 + current->thread.trap_no = 0;
4245 + pax_report_refcount_overflow(regs);
4246 + fixup_exception(regs);
4247 + return;
4248 + }
4249 + }
4250 +#endif
4251
4252 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
4253 return;
4254
4255 +die:
4256 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
4257 inf->name, ifsr, addr);
4258
4259 diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
4260 index cf08bdf..772656c 100644
4261 --- a/arch/arm/mm/fault.h
4262 +++ b/arch/arm/mm/fault.h
4263 @@ -3,6 +3,7 @@
4264
4265 /*
4266 * Fault status register encodings. We steal bit 31 for our own purposes.
4267 + * Set when the FSR value is from an instruction fault.
4268 */
4269 #define FSR_LNX_PF (1 << 31)
4270 #define FSR_WRITE (1 << 11)
4271 @@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
4272 }
4273 #endif
4274
4275 +/* valid for LPAE and !LPAE */
4276 +static inline int is_xn_fault(unsigned int fsr)
4277 +{
4278 + return ((fsr_fs(fsr) & 0x3c) == 0xc);
4279 +}
4280 +
4281 +static inline int is_domain_fault(unsigned int fsr)
4282 +{
4283 + return ((fsr_fs(fsr) & 0xD) == 0x9);
4284 +}
4285 +
4286 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
4287 unsigned long search_exception_table(unsigned long addr);
4288
4289 diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
4290 index 659c75d..6f8c029 100644
4291 --- a/arch/arm/mm/init.c
4292 +++ b/arch/arm/mm/init.c
4293 @@ -31,6 +31,8 @@
4294 #include <asm/setup.h>
4295 #include <asm/tlb.h>
4296 #include <asm/fixmap.h>
4297 +#include <asm/system_info.h>
4298 +#include <asm/cp15.h>
4299
4300 #include <asm/mach/arch.h>
4301 #include <asm/mach/map.h>
4302 @@ -619,7 +621,46 @@ void free_initmem(void)
4303 {
4304 #ifdef CONFIG_HAVE_TCM
4305 extern char __tcm_start, __tcm_end;
4306 +#endif
4307
4308 +#ifdef CONFIG_PAX_KERNEXEC
4309 + unsigned long addr;
4310 + pgd_t *pgd;
4311 + pud_t *pud;
4312 + pmd_t *pmd;
4313 + int cpu_arch = cpu_architecture();
4314 + unsigned int cr = get_cr();
4315 +
4316 + if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
4317 + /* make pages tables, etc before .text NX */
4318 + for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
4319 + pgd = pgd_offset_k(addr);
4320 + pud = pud_offset(pgd, addr);
4321 + pmd = pmd_offset(pud, addr);
4322 + __section_update(pmd, addr, PMD_SECT_XN);
4323 + }
4324 + /* make init NX */
4325 + for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
4326 + pgd = pgd_offset_k(addr);
4327 + pud = pud_offset(pgd, addr);
4328 + pmd = pmd_offset(pud, addr);
4329 + __section_update(pmd, addr, PMD_SECT_XN);
4330 + }
4331 + /* make kernel code/rodata RX */
4332 + for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
4333 + pgd = pgd_offset_k(addr);
4334 + pud = pud_offset(pgd, addr);
4335 + pmd = pmd_offset(pud, addr);
4336 +#ifdef CONFIG_ARM_LPAE
4337 + __section_update(pmd, addr, PMD_SECT_RDONLY);
4338 +#else
4339 + __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
4340 +#endif
4341 + }
4342 + }
4343 +#endif
4344 +
4345 +#ifdef CONFIG_HAVE_TCM
4346 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
4347 free_reserved_area(&__tcm_start, &__tcm_end, -1, "TCM link");
4348 #endif
4349 diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
4350 index d1e5ad7..84dcbf2 100644
4351 --- a/arch/arm/mm/ioremap.c
4352 +++ b/arch/arm/mm/ioremap.c
4353 @@ -392,9 +392,9 @@ __arm_ioremap_exec(phys_addr_t phys_addr, size_t size, bool cached)
4354 unsigned int mtype;
4355
4356 if (cached)
4357 - mtype = MT_MEMORY_RWX;
4358 + mtype = MT_MEMORY_RX;
4359 else
4360 - mtype = MT_MEMORY_RWX_NONCACHED;
4361 + mtype = MT_MEMORY_RX_NONCACHED;
4362
4363 return __arm_ioremap_caller(phys_addr, size, mtype,
4364 __builtin_return_address(0));
4365 diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
4366 index 5e85ed3..b10a7ed 100644
4367 --- a/arch/arm/mm/mmap.c
4368 +++ b/arch/arm/mm/mmap.c
4369 @@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4370 struct vm_area_struct *vma;
4371 int do_align = 0;
4372 int aliasing = cache_is_vipt_aliasing();
4373 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4374 struct vm_unmapped_area_info info;
4375
4376 /*
4377 @@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4378 if (len > TASK_SIZE)
4379 return -ENOMEM;
4380
4381 +#ifdef CONFIG_PAX_RANDMMAP
4382 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4383 +#endif
4384 +
4385 if (addr) {
4386 if (do_align)
4387 addr = COLOUR_ALIGN(addr, pgoff);
4388 @@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4389 addr = PAGE_ALIGN(addr);
4390
4391 vma = find_vma(mm, addr);
4392 - if (TASK_SIZE - len >= addr &&
4393 - (!vma || addr + len <= vma->vm_start))
4394 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4395 return addr;
4396 }
4397
4398 @@ -99,6 +103,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4399 info.high_limit = TASK_SIZE;
4400 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4401 info.align_offset = pgoff << PAGE_SHIFT;
4402 + info.threadstack_offset = offset;
4403 return vm_unmapped_area(&info);
4404 }
4405
4406 @@ -112,6 +117,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4407 unsigned long addr = addr0;
4408 int do_align = 0;
4409 int aliasing = cache_is_vipt_aliasing();
4410 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4411 struct vm_unmapped_area_info info;
4412
4413 /*
4414 @@ -132,6 +138,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4415 return addr;
4416 }
4417
4418 +#ifdef CONFIG_PAX_RANDMMAP
4419 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4420 +#endif
4421 +
4422 /* requesting a specific address */
4423 if (addr) {
4424 if (do_align)
4425 @@ -139,8 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4426 else
4427 addr = PAGE_ALIGN(addr);
4428 vma = find_vma(mm, addr);
4429 - if (TASK_SIZE - len >= addr &&
4430 - (!vma || addr + len <= vma->vm_start))
4431 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4432 return addr;
4433 }
4434
4435 @@ -150,6 +159,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4436 info.high_limit = mm->mmap_base;
4437 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4438 info.align_offset = pgoff << PAGE_SHIFT;
4439 + info.threadstack_offset = offset;
4440 addr = vm_unmapped_area(&info);
4441
4442 /*
4443 @@ -173,6 +183,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4444 {
4445 unsigned long random_factor = 0UL;
4446
4447 +#ifdef CONFIG_PAX_RANDMMAP
4448 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4449 +#endif
4450 +
4451 /* 8 bits of randomness in 20 address space bits */
4452 if ((current->flags & PF_RANDOMIZE) &&
4453 !(current->personality & ADDR_NO_RANDOMIZE))
4454 @@ -180,9 +194,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4455
4456 if (mmap_is_legacy()) {
4457 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4458 +
4459 +#ifdef CONFIG_PAX_RANDMMAP
4460 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4461 + mm->mmap_base += mm->delta_mmap;
4462 +#endif
4463 +
4464 mm->get_unmapped_area = arch_get_unmapped_area;
4465 } else {
4466 mm->mmap_base = mmap_base(random_factor);
4467 +
4468 +#ifdef CONFIG_PAX_RANDMMAP
4469 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4470 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4471 +#endif
4472 +
4473 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4474 }
4475 }
4476 diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
4477 index 8348ed6..b73a807 100644
4478 --- a/arch/arm/mm/mmu.c
4479 +++ b/arch/arm/mm/mmu.c
4480 @@ -40,6 +40,22 @@
4481 #include "mm.h"
4482 #include "tcm.h"
4483
4484 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4485 +void modify_domain(unsigned int dom, unsigned int type)
4486 +{
4487 + struct thread_info *thread = current_thread_info();
4488 + unsigned int domain = thread->cpu_domain;
4489 + /*
4490 + * DOMAIN_MANAGER might be defined to some other value,
4491 + * use the arch-defined constant
4492 + */
4493 + domain &= ~domain_val(dom, 3);
4494 + thread->cpu_domain = domain | domain_val(dom, type);
4495 + set_domain(thread->cpu_domain);
4496 +}
4497 +EXPORT_SYMBOL(modify_domain);
4498 +#endif
4499 +
4500 /*
4501 * empty_zero_page is a special page that is used for
4502 * zero-initialized data and COW.
4503 @@ -239,7 +255,15 @@ __setup("noalign", noalign_setup);
4504 #define PROT_PTE_S2_DEVICE PROT_PTE_DEVICE
4505 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
4506
4507 -static struct mem_type mem_types[] = {
4508 +#ifdef CONFIG_PAX_KERNEXEC
4509 +#define L_PTE_KERNEXEC L_PTE_RDONLY
4510 +#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
4511 +#else
4512 +#define L_PTE_KERNEXEC L_PTE_DIRTY
4513 +#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
4514 +#endif
4515 +
4516 +static struct mem_type mem_types[] __read_only = {
4517 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
4518 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
4519 L_PTE_SHARED,
4520 @@ -268,19 +292,19 @@ static struct mem_type mem_types[] = {
4521 .prot_sect = PROT_SECT_DEVICE,
4522 .domain = DOMAIN_IO,
4523 },
4524 - [MT_UNCACHED] = {
4525 + [MT_UNCACHED_RW] = {
4526 .prot_pte = PROT_PTE_DEVICE,
4527 .prot_l1 = PMD_TYPE_TABLE,
4528 .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4529 .domain = DOMAIN_IO,
4530 },
4531 - [MT_CACHECLEAN] = {
4532 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4533 + [MT_CACHECLEAN_RO] = {
4534 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_RDONLY,
4535 .domain = DOMAIN_KERNEL,
4536 },
4537 #ifndef CONFIG_ARM_LPAE
4538 - [MT_MINICLEAN] = {
4539 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
4540 + [MT_MINICLEAN_RO] = {
4541 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_XN | PMD_SECT_RDONLY,
4542 .domain = DOMAIN_KERNEL,
4543 },
4544 #endif
4545 @@ -288,15 +312,15 @@ static struct mem_type mem_types[] = {
4546 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4547 L_PTE_RDONLY,
4548 .prot_l1 = PMD_TYPE_TABLE,
4549 - .domain = DOMAIN_USER,
4550 + .domain = DOMAIN_VECTORS,
4551 },
4552 [MT_HIGH_VECTORS] = {
4553 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4554 L_PTE_USER | L_PTE_RDONLY,
4555 .prot_l1 = PMD_TYPE_TABLE,
4556 - .domain = DOMAIN_USER,
4557 + .domain = DOMAIN_VECTORS,
4558 },
4559 - [MT_MEMORY_RWX] = {
4560 + [__MT_MEMORY_RWX] = {
4561 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4562 .prot_l1 = PMD_TYPE_TABLE,
4563 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4564 @@ -309,17 +333,30 @@ static struct mem_type mem_types[] = {
4565 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4566 .domain = DOMAIN_KERNEL,
4567 },
4568 - [MT_ROM] = {
4569 - .prot_sect = PMD_TYPE_SECT,
4570 + [MT_MEMORY_RX] = {
4571 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4572 + .prot_l1 = PMD_TYPE_TABLE,
4573 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4574 + .domain = DOMAIN_KERNEL,
4575 + },
4576 + [MT_ROM_RX] = {
4577 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4578 .domain = DOMAIN_KERNEL,
4579 },
4580 - [MT_MEMORY_RWX_NONCACHED] = {
4581 + [MT_MEMORY_RW_NONCACHED] = {
4582 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4583 L_PTE_MT_BUFFERABLE,
4584 .prot_l1 = PMD_TYPE_TABLE,
4585 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4586 .domain = DOMAIN_KERNEL,
4587 },
4588 + [MT_MEMORY_RX_NONCACHED] = {
4589 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
4590 + L_PTE_MT_BUFFERABLE,
4591 + .prot_l1 = PMD_TYPE_TABLE,
4592 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4593 + .domain = DOMAIN_KERNEL,
4594 + },
4595 [MT_MEMORY_RW_DTCM] = {
4596 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4597 L_PTE_XN,
4598 @@ -327,9 +364,10 @@ static struct mem_type mem_types[] = {
4599 .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4600 .domain = DOMAIN_KERNEL,
4601 },
4602 - [MT_MEMORY_RWX_ITCM] = {
4603 - .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4604 + [MT_MEMORY_RX_ITCM] = {
4605 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4606 .prot_l1 = PMD_TYPE_TABLE,
4607 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4608 .domain = DOMAIN_KERNEL,
4609 },
4610 [MT_MEMORY_RW_SO] = {
4611 @@ -547,9 +585,14 @@ static void __init build_mem_type_table(void)
4612 * Mark cache clean areas and XIP ROM read only
4613 * from SVC mode and no access from userspace.
4614 */
4615 - mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4616 - mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4617 - mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4618 + mem_types[MT_ROM_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4619 +#ifdef CONFIG_PAX_KERNEXEC
4620 + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4621 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4622 + mem_types[MT_MEMORY_RX_ITCM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4623 +#endif
4624 + mem_types[MT_MINICLEAN_RO].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4625 + mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4626 #endif
4627
4628 /*
4629 @@ -566,13 +609,17 @@ static void __init build_mem_type_table(void)
4630 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
4631 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
4632 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
4633 - mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4634 - mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4635 + mem_types[__MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4636 + mem_types[__MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4637 mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
4638 mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
4639 + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
4640 + mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
4641 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
4642 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= PMD_SECT_S;
4643 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_pte |= L_PTE_SHARED;
4644 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= PMD_SECT_S;
4645 + mem_types[MT_MEMORY_RW_NONCACHED].prot_pte |= L_PTE_SHARED;
4646 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_S;
4647 + mem_types[MT_MEMORY_RX_NONCACHED].prot_pte |= L_PTE_SHARED;
4648 }
4649 }
4650
4651 @@ -583,15 +630,20 @@ static void __init build_mem_type_table(void)
4652 if (cpu_arch >= CPU_ARCH_ARMv6) {
4653 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4654 /* Non-cacheable Normal is XCB = 001 */
4655 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |=
4656 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |=
4657 + PMD_SECT_BUFFERED;
4658 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |=
4659 PMD_SECT_BUFFERED;
4660 } else {
4661 /* For both ARMv6 and non-TEX-remapping ARMv7 */
4662 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |=
4663 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |=
4664 + PMD_SECT_TEX(1);
4665 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |=
4666 PMD_SECT_TEX(1);
4667 }
4668 } else {
4669 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4670 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4671 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4672 }
4673
4674 #ifdef CONFIG_ARM_LPAE
4675 @@ -607,6 +659,8 @@ static void __init build_mem_type_table(void)
4676 vecs_pgprot |= PTE_EXT_AF;
4677 #endif
4678
4679 + user_pgprot |= __supported_pte_mask;
4680 +
4681 for (i = 0; i < 16; i++) {
4682 pteval_t v = pgprot_val(protection_map[i]);
4683 protection_map[i] = __pgprot(v | user_pgprot);
4684 @@ -624,21 +678,24 @@ static void __init build_mem_type_table(void)
4685
4686 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
4687 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
4688 - mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4689 - mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4690 + mem_types[__MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4691 + mem_types[__MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4692 mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
4693 mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
4694 + mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
4695 + mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
4696 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
4697 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= ecc_mask;
4698 - mem_types[MT_ROM].prot_sect |= cp->pmd;
4699 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= ecc_mask;
4700 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= ecc_mask;
4701 + mem_types[MT_ROM_RX].prot_sect |= cp->pmd;
4702
4703 switch (cp->pmd) {
4704 case PMD_SECT_WT:
4705 - mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WT;
4706 + mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_WT;
4707 break;
4708 case PMD_SECT_WB:
4709 case PMD_SECT_WBWA:
4710 - mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WB;
4711 + mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_WB;
4712 break;
4713 }
4714 pr_info("Memory policy: %sData cache %s\n",
4715 @@ -856,7 +913,7 @@ static void __init create_mapping(struct map_desc *md)
4716 return;
4717 }
4718
4719 - if ((md->type == MT_DEVICE || md->type == MT_ROM) &&
4720 + if ((md->type == MT_DEVICE || md->type == MT_ROM_RX) &&
4721 md->virtual >= PAGE_OFFSET &&
4722 (md->virtual < VMALLOC_START || md->virtual >= VMALLOC_END)) {
4723 printk(KERN_WARNING "BUG: mapping for 0x%08llx"
4724 @@ -1224,18 +1281,15 @@ void __init arm_mm_memblock_reserve(void)
4725 * called function. This means you can't use any function or debugging
4726 * method which may touch any device, otherwise the kernel _will_ crash.
4727 */
4728 +
4729 +static char vectors[PAGE_SIZE * 2] __read_only __aligned(PAGE_SIZE);
4730 +
4731 static void __init devicemaps_init(const struct machine_desc *mdesc)
4732 {
4733 struct map_desc map;
4734 unsigned long addr;
4735 - void *vectors;
4736
4737 - /*
4738 - * Allocate the vector page early.
4739 - */
4740 - vectors = early_alloc(PAGE_SIZE * 2);
4741 -
4742 - early_trap_init(vectors);
4743 + early_trap_init(&vectors);
4744
4745 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
4746 pmd_clear(pmd_off_k(addr));
4747 @@ -1248,7 +1302,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4748 map.pfn = __phys_to_pfn(CONFIG_XIP_PHYS_ADDR & SECTION_MASK);
4749 map.virtual = MODULES_VADDR;
4750 map.length = ((unsigned long)_etext - map.virtual + ~SECTION_MASK) & SECTION_MASK;
4751 - map.type = MT_ROM;
4752 + map.type = MT_ROM_RX;
4753 create_mapping(&map);
4754 #endif
4755
4756 @@ -1259,14 +1313,14 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4757 map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS);
4758 map.virtual = FLUSH_BASE;
4759 map.length = SZ_1M;
4760 - map.type = MT_CACHECLEAN;
4761 + map.type = MT_CACHECLEAN_RO;
4762 create_mapping(&map);
4763 #endif
4764 #ifdef FLUSH_BASE_MINICACHE
4765 map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS + SZ_1M);
4766 map.virtual = FLUSH_BASE_MINICACHE;
4767 map.length = SZ_1M;
4768 - map.type = MT_MINICLEAN;
4769 + map.type = MT_MINICLEAN_RO;
4770 create_mapping(&map);
4771 #endif
4772
4773 @@ -1275,7 +1329,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4774 * location (0xffff0000). If we aren't using high-vectors, also
4775 * create a mapping at the low-vectors virtual address.
4776 */
4777 - map.pfn = __phys_to_pfn(virt_to_phys(vectors));
4778 + map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
4779 map.virtual = 0xffff0000;
4780 map.length = PAGE_SIZE;
4781 #ifdef CONFIG_KUSER_HELPERS
4782 @@ -1335,8 +1389,10 @@ static void __init kmap_init(void)
4783 static void __init map_lowmem(void)
4784 {
4785 struct memblock_region *reg;
4786 +#ifndef CONFIG_PAX_KERNEXEC
4787 unsigned long kernel_x_start = round_down(__pa(_stext), SECTION_SIZE);
4788 unsigned long kernel_x_end = round_up(__pa(__init_end), SECTION_SIZE);
4789 +#endif
4790
4791 /* Map all the lowmem memory banks. */
4792 for_each_memblock(memory, reg) {
4793 @@ -1349,11 +1405,48 @@ static void __init map_lowmem(void)
4794 if (start >= end)
4795 break;
4796
4797 +#ifdef CONFIG_PAX_KERNEXEC
4798 + map.pfn = __phys_to_pfn(start);
4799 + map.virtual = __phys_to_virt(start);
4800 + map.length = end - start;
4801 +
4802 + if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
4803 + struct map_desc kernel;
4804 + struct map_desc initmap;
4805 +
4806 + /* when freeing initmem we will make this RW */
4807 + initmap.pfn = __phys_to_pfn(__pa(__init_begin));
4808 + initmap.virtual = (unsigned long)__init_begin;
4809 + initmap.length = _sdata - __init_begin;
4810 + initmap.type = __MT_MEMORY_RWX;
4811 + create_mapping(&initmap);
4812 +
4813 + /* when freeing initmem we will make this RX */
4814 + kernel.pfn = __phys_to_pfn(__pa(_stext));
4815 + kernel.virtual = (unsigned long)_stext;
4816 + kernel.length = __init_begin - _stext;
4817 + kernel.type = __MT_MEMORY_RWX;
4818 + create_mapping(&kernel);
4819 +
4820 + if (map.virtual < (unsigned long)_stext) {
4821 + map.length = (unsigned long)_stext - map.virtual;
4822 + map.type = __MT_MEMORY_RWX;
4823 + create_mapping(&map);
4824 + }
4825 +
4826 + map.pfn = __phys_to_pfn(__pa(_sdata));
4827 + map.virtual = (unsigned long)_sdata;
4828 + map.length = end - __pa(_sdata);
4829 + }
4830 +
4831 + map.type = MT_MEMORY_RW;
4832 + create_mapping(&map);
4833 +#else
4834 if (end < kernel_x_start || start >= kernel_x_end) {
4835 map.pfn = __phys_to_pfn(start);
4836 map.virtual = __phys_to_virt(start);
4837 map.length = end - start;
4838 - map.type = MT_MEMORY_RWX;
4839 + map.type = __MT_MEMORY_RWX;
4840
4841 create_mapping(&map);
4842 } else {
4843 @@ -1370,7 +1463,7 @@ static void __init map_lowmem(void)
4844 map.pfn = __phys_to_pfn(kernel_x_start);
4845 map.virtual = __phys_to_virt(kernel_x_start);
4846 map.length = kernel_x_end - kernel_x_start;
4847 - map.type = MT_MEMORY_RWX;
4848 + map.type = __MT_MEMORY_RWX;
4849
4850 create_mapping(&map);
4851
4852 @@ -1383,6 +1476,7 @@ static void __init map_lowmem(void)
4853 create_mapping(&map);
4854 }
4855 }
4856 +#endif
4857 }
4858 }
4859
4860 diff --git a/arch/arm/net/bpf_jit_32.c b/arch/arm/net/bpf_jit_32.c
4861 index a37b989..5c9ae75 100644
4862 --- a/arch/arm/net/bpf_jit_32.c
4863 +++ b/arch/arm/net/bpf_jit_32.c
4864 @@ -71,7 +71,11 @@ struct jit_ctx {
4865 #endif
4866 };
4867
4868 +#ifdef CONFIG_GRKERNSEC_BPF_HARDEN
4869 +int bpf_jit_enable __read_only;
4870 +#else
4871 int bpf_jit_enable __read_mostly;
4872 +#endif
4873
4874 static u64 jit_get_skb_b(struct sk_buff *skb, unsigned offset)
4875 {
4876 @@ -930,5 +934,6 @@ void bpf_jit_free(struct bpf_prog *fp)
4877 {
4878 if (fp->jited)
4879 module_free(NULL, fp->bpf_func);
4880 - kfree(fp);
4881 +
4882 + bpf_prog_unlock_free(fp);
4883 }
4884 diff --git a/arch/arm/plat-iop/setup.c b/arch/arm/plat-iop/setup.c
4885 index 5b217f4..c23f40e 100644
4886 --- a/arch/arm/plat-iop/setup.c
4887 +++ b/arch/arm/plat-iop/setup.c
4888 @@ -24,7 +24,7 @@ static struct map_desc iop3xx_std_desc[] __initdata = {
4889 .virtual = IOP3XX_PERIPHERAL_VIRT_BASE,
4890 .pfn = __phys_to_pfn(IOP3XX_PERIPHERAL_PHYS_BASE),
4891 .length = IOP3XX_PERIPHERAL_SIZE,
4892 - .type = MT_UNCACHED,
4893 + .type = MT_UNCACHED_RW,
4894 },
4895 };
4896
4897 diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4898 index a5bc92d..0bb4730 100644
4899 --- a/arch/arm/plat-omap/sram.c
4900 +++ b/arch/arm/plat-omap/sram.c
4901 @@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4902 * Looks like we need to preserve some bootloader code at the
4903 * beginning of SRAM for jumping to flash for reboot to work...
4904 */
4905 + pax_open_kernel();
4906 memset_io(omap_sram_base + omap_sram_skip, 0,
4907 omap_sram_size - omap_sram_skip);
4908 + pax_close_kernel();
4909 }
4910 diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4911 index ce6d763..cfea917 100644
4912 --- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4913 +++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4914 @@ -47,7 +47,7 @@ struct samsung_dma_ops {
4915 int (*started)(unsigned ch);
4916 int (*flush)(unsigned ch);
4917 int (*stop)(unsigned ch);
4918 -};
4919 +} __no_const;
4920
4921 extern void *samsung_dmadev_get_ops(void);
4922 extern void *s3c_dma_get_ops(void);
4923 diff --git a/arch/arm64/include/asm/barrier.h b/arch/arm64/include/asm/barrier.h
4924 index 6389d60..b5d3bdd 100644
4925 --- a/arch/arm64/include/asm/barrier.h
4926 +++ b/arch/arm64/include/asm/barrier.h
4927 @@ -41,7 +41,7 @@
4928 do { \
4929 compiletime_assert_atomic_type(*p); \
4930 barrier(); \
4931 - ACCESS_ONCE(*p) = (v); \
4932 + ACCESS_ONCE_RW(*p) = (v); \
4933 } while (0)
4934
4935 #define smp_load_acquire(p) \
4936 diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h
4937 index 3bf8f4e..5dd5491 100644
4938 --- a/arch/arm64/include/asm/uaccess.h
4939 +++ b/arch/arm64/include/asm/uaccess.h
4940 @@ -99,6 +99,7 @@ static inline void set_fs(mm_segment_t fs)
4941 flag; \
4942 })
4943
4944 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
4945 #define access_ok(type, addr, size) __range_ok(addr, size)
4946 #define user_addr_max get_fs
4947
4948 diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4949 index c3a58a1..78fbf54 100644
4950 --- a/arch/avr32/include/asm/cache.h
4951 +++ b/arch/avr32/include/asm/cache.h
4952 @@ -1,8 +1,10 @@
4953 #ifndef __ASM_AVR32_CACHE_H
4954 #define __ASM_AVR32_CACHE_H
4955
4956 +#include <linux/const.h>
4957 +
4958 #define L1_CACHE_SHIFT 5
4959 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4960 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4961
4962 /*
4963 * Memory returned by kmalloc() may be used for DMA, so we must make
4964 diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4965 index d232888..87c8df1 100644
4966 --- a/arch/avr32/include/asm/elf.h
4967 +++ b/arch/avr32/include/asm/elf.h
4968 @@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4969 the loader. We need to make sure that it is out of the way of the program
4970 that it will "exec", and that there is sufficient room for the brk. */
4971
4972 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4973 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4974
4975 +#ifdef CONFIG_PAX_ASLR
4976 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4977 +
4978 +#define PAX_DELTA_MMAP_LEN 15
4979 +#define PAX_DELTA_STACK_LEN 15
4980 +#endif
4981
4982 /* This yields a mask that user programs can use to figure out what
4983 instruction set this CPU supports. This could be done in user space,
4984 diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4985 index 479330b..53717a8 100644
4986 --- a/arch/avr32/include/asm/kmap_types.h
4987 +++ b/arch/avr32/include/asm/kmap_types.h
4988 @@ -2,9 +2,9 @@
4989 #define __ASM_AVR32_KMAP_TYPES_H
4990
4991 #ifdef CONFIG_DEBUG_HIGHMEM
4992 -# define KM_TYPE_NR 29
4993 +# define KM_TYPE_NR 30
4994 #else
4995 -# define KM_TYPE_NR 14
4996 +# define KM_TYPE_NR 15
4997 #endif
4998
4999 #endif /* __ASM_AVR32_KMAP_TYPES_H */
5000 diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
5001 index 0eca933..eb78c7b 100644
5002 --- a/arch/avr32/mm/fault.c
5003 +++ b/arch/avr32/mm/fault.c
5004 @@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
5005
5006 int exception_trace = 1;
5007
5008 +#ifdef CONFIG_PAX_PAGEEXEC
5009 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5010 +{
5011 + unsigned long i;
5012 +
5013 + printk(KERN_ERR "PAX: bytes at PC: ");
5014 + for (i = 0; i < 20; i++) {
5015 + unsigned char c;
5016 + if (get_user(c, (unsigned char *)pc+i))
5017 + printk(KERN_CONT "???????? ");
5018 + else
5019 + printk(KERN_CONT "%02x ", c);
5020 + }
5021 + printk("\n");
5022 +}
5023 +#endif
5024 +
5025 /*
5026 * This routine handles page faults. It determines the address and the
5027 * problem, and then passes it off to one of the appropriate routines.
5028 @@ -176,6 +193,16 @@ bad_area:
5029 up_read(&mm->mmap_sem);
5030
5031 if (user_mode(regs)) {
5032 +
5033 +#ifdef CONFIG_PAX_PAGEEXEC
5034 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
5035 + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
5036 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
5037 + do_group_exit(SIGKILL);
5038 + }
5039 + }
5040 +#endif
5041 +
5042 if (exception_trace && printk_ratelimit())
5043 printk("%s%s[%d]: segfault at %08lx pc %08lx "
5044 "sp %08lx ecr %lu\n",
5045 diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
5046 index 568885a..f8008df 100644
5047 --- a/arch/blackfin/include/asm/cache.h
5048 +++ b/arch/blackfin/include/asm/cache.h
5049 @@ -7,6 +7,7 @@
5050 #ifndef __ARCH_BLACKFIN_CACHE_H
5051 #define __ARCH_BLACKFIN_CACHE_H
5052
5053 +#include <linux/const.h>
5054 #include <linux/linkage.h> /* for asmlinkage */
5055
5056 /*
5057 @@ -14,7 +15,7 @@
5058 * Blackfin loads 32 bytes for cache
5059 */
5060 #define L1_CACHE_SHIFT 5
5061 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5062 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5063 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5064
5065 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5066 diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
5067 index aea2718..3639a60 100644
5068 --- a/arch/cris/include/arch-v10/arch/cache.h
5069 +++ b/arch/cris/include/arch-v10/arch/cache.h
5070 @@ -1,8 +1,9 @@
5071 #ifndef _ASM_ARCH_CACHE_H
5072 #define _ASM_ARCH_CACHE_H
5073
5074 +#include <linux/const.h>
5075 /* Etrax 100LX have 32-byte cache-lines. */
5076 -#define L1_CACHE_BYTES 32
5077 #define L1_CACHE_SHIFT 5
5078 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5079
5080 #endif /* _ASM_ARCH_CACHE_H */
5081 diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
5082 index 7caf25d..ee65ac5 100644
5083 --- a/arch/cris/include/arch-v32/arch/cache.h
5084 +++ b/arch/cris/include/arch-v32/arch/cache.h
5085 @@ -1,11 +1,12 @@
5086 #ifndef _ASM_CRIS_ARCH_CACHE_H
5087 #define _ASM_CRIS_ARCH_CACHE_H
5088
5089 +#include <linux/const.h>
5090 #include <arch/hwregs/dma.h>
5091
5092 /* A cache-line is 32 bytes. */
5093 -#define L1_CACHE_BYTES 32
5094 #define L1_CACHE_SHIFT 5
5095 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5096
5097 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
5098
5099 diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
5100 index f6c3a16..cd422a4 100644
5101 --- a/arch/frv/include/asm/atomic.h
5102 +++ b/arch/frv/include/asm/atomic.h
5103 @@ -181,6 +181,16 @@ static inline void atomic64_dec(atomic64_t *v)
5104 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
5105 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
5106
5107 +#define atomic64_read_unchecked(v) atomic64_read(v)
5108 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5109 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5110 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5111 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5112 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
5113 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5114 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
5115 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5116 +
5117 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5118 {
5119 int c, old;
5120 diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
5121 index 2797163..c2a401df9 100644
5122 --- a/arch/frv/include/asm/cache.h
5123 +++ b/arch/frv/include/asm/cache.h
5124 @@ -12,10 +12,11 @@
5125 #ifndef __ASM_CACHE_H
5126 #define __ASM_CACHE_H
5127
5128 +#include <linux/const.h>
5129
5130 /* bytes per L1 cache line */
5131 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
5132 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5133 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5134
5135 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
5136 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
5137 diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
5138 index 43901f2..0d8b865 100644
5139 --- a/arch/frv/include/asm/kmap_types.h
5140 +++ b/arch/frv/include/asm/kmap_types.h
5141 @@ -2,6 +2,6 @@
5142 #ifndef _ASM_KMAP_TYPES_H
5143 #define _ASM_KMAP_TYPES_H
5144
5145 -#define KM_TYPE_NR 17
5146 +#define KM_TYPE_NR 18
5147
5148 #endif
5149 diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
5150 index 836f147..4cf23f5 100644
5151 --- a/arch/frv/mm/elf-fdpic.c
5152 +++ b/arch/frv/mm/elf-fdpic.c
5153 @@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5154 {
5155 struct vm_area_struct *vma;
5156 struct vm_unmapped_area_info info;
5157 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
5158
5159 if (len > TASK_SIZE)
5160 return -ENOMEM;
5161 @@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5162 if (addr) {
5163 addr = PAGE_ALIGN(addr);
5164 vma = find_vma(current->mm, addr);
5165 - if (TASK_SIZE - len >= addr &&
5166 - (!vma || addr + len <= vma->vm_start))
5167 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
5168 goto success;
5169 }
5170
5171 @@ -85,6 +85,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5172 info.high_limit = (current->mm->start_stack - 0x00200000);
5173 info.align_mask = 0;
5174 info.align_offset = 0;
5175 + info.threadstack_offset = offset;
5176 addr = vm_unmapped_area(&info);
5177 if (!(addr & ~PAGE_MASK))
5178 goto success;
5179 diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
5180 index 2635117..fa223cb 100644
5181 --- a/arch/hexagon/include/asm/cache.h
5182 +++ b/arch/hexagon/include/asm/cache.h
5183 @@ -21,9 +21,11 @@
5184 #ifndef __ASM_CACHE_H
5185 #define __ASM_CACHE_H
5186
5187 +#include <linux/const.h>
5188 +
5189 /* Bytes per L1 cache line */
5190 -#define L1_CACHE_SHIFT (5)
5191 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5192 +#define L1_CACHE_SHIFT 5
5193 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5194
5195 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
5196 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
5197 diff --git a/arch/ia64/Kconfig b/arch/ia64/Kconfig
5198 index c84c88b..2a6e1ba 100644
5199 --- a/arch/ia64/Kconfig
5200 +++ b/arch/ia64/Kconfig
5201 @@ -549,6 +549,7 @@ source "drivers/sn/Kconfig"
5202 config KEXEC
5203 bool "kexec system call"
5204 depends on !IA64_HP_SIM && (!SMP || HOTPLUG_CPU)
5205 + depends on !GRKERNSEC_KMEM
5206 help
5207 kexec is a system call that implements the ability to shutdown your
5208 current kernel, and to start another kernel. It is like a reboot
5209 diff --git a/arch/ia64/Makefile b/arch/ia64/Makefile
5210 index 5441b14..039a446 100644
5211 --- a/arch/ia64/Makefile
5212 +++ b/arch/ia64/Makefile
5213 @@ -99,5 +99,6 @@ endef
5214 archprepare: make_nr_irqs_h FORCE
5215 PHONY += make_nr_irqs_h FORCE
5216
5217 +make_nr_irqs_h: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
5218 make_nr_irqs_h: FORCE
5219 $(Q)$(MAKE) $(build)=arch/ia64/kernel include/generated/nr-irqs.h
5220 diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
5221 index 0f8bf48..40ea950 100644
5222 --- a/arch/ia64/include/asm/atomic.h
5223 +++ b/arch/ia64/include/asm/atomic.h
5224 @@ -209,4 +209,14 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
5225 #define atomic64_inc(v) atomic64_add(1, (v))
5226 #define atomic64_dec(v) atomic64_sub(1, (v))
5227
5228 +#define atomic64_read_unchecked(v) atomic64_read(v)
5229 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5230 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5231 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5232 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5233 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
5234 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5235 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
5236 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5237 +
5238 #endif /* _ASM_IA64_ATOMIC_H */
5239 diff --git a/arch/ia64/include/asm/barrier.h b/arch/ia64/include/asm/barrier.h
5240 index a48957c..e097b56 100644
5241 --- a/arch/ia64/include/asm/barrier.h
5242 +++ b/arch/ia64/include/asm/barrier.h
5243 @@ -67,7 +67,7 @@
5244 do { \
5245 compiletime_assert_atomic_type(*p); \
5246 barrier(); \
5247 - ACCESS_ONCE(*p) = (v); \
5248 + ACCESS_ONCE_RW(*p) = (v); \
5249 } while (0)
5250
5251 #define smp_load_acquire(p) \
5252 diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
5253 index 988254a..e1ee885 100644
5254 --- a/arch/ia64/include/asm/cache.h
5255 +++ b/arch/ia64/include/asm/cache.h
5256 @@ -1,6 +1,7 @@
5257 #ifndef _ASM_IA64_CACHE_H
5258 #define _ASM_IA64_CACHE_H
5259
5260 +#include <linux/const.h>
5261
5262 /*
5263 * Copyright (C) 1998-2000 Hewlett-Packard Co
5264 @@ -9,7 +10,7 @@
5265
5266 /* Bytes per L1 (data) cache line. */
5267 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
5268 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5269 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5270
5271 #ifdef CONFIG_SMP
5272 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
5273 diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
5274 index 5a83c5c..4d7f553 100644
5275 --- a/arch/ia64/include/asm/elf.h
5276 +++ b/arch/ia64/include/asm/elf.h
5277 @@ -42,6 +42,13 @@
5278 */
5279 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
5280
5281 +#ifdef CONFIG_PAX_ASLR
5282 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
5283 +
5284 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
5285 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
5286 +#endif
5287 +
5288 #define PT_IA_64_UNWIND 0x70000001
5289
5290 /* IA-64 relocations: */
5291 diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
5292 index 5767cdf..7462574 100644
5293 --- a/arch/ia64/include/asm/pgalloc.h
5294 +++ b/arch/ia64/include/asm/pgalloc.h
5295 @@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
5296 pgd_val(*pgd_entry) = __pa(pud);
5297 }
5298
5299 +static inline void
5300 +pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
5301 +{
5302 + pgd_populate(mm, pgd_entry, pud);
5303 +}
5304 +
5305 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
5306 {
5307 return quicklist_alloc(0, GFP_KERNEL, NULL);
5308 @@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5309 pud_val(*pud_entry) = __pa(pmd);
5310 }
5311
5312 +static inline void
5313 +pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5314 +{
5315 + pud_populate(mm, pud_entry, pmd);
5316 +}
5317 +
5318 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5319 {
5320 return quicklist_alloc(0, GFP_KERNEL, NULL);
5321 diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
5322 index 7935115..c0eca6a 100644
5323 --- a/arch/ia64/include/asm/pgtable.h
5324 +++ b/arch/ia64/include/asm/pgtable.h
5325 @@ -12,7 +12,7 @@
5326 * David Mosberger-Tang <davidm@hpl.hp.com>
5327 */
5328
5329 -
5330 +#include <linux/const.h>
5331 #include <asm/mman.h>
5332 #include <asm/page.h>
5333 #include <asm/processor.h>
5334 @@ -142,6 +142,17 @@
5335 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5336 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5337 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
5338 +
5339 +#ifdef CONFIG_PAX_PAGEEXEC
5340 +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
5341 +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5342 +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5343 +#else
5344 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
5345 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
5346 +# define PAGE_COPY_NOEXEC PAGE_COPY
5347 +#endif
5348 +
5349 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
5350 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
5351 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
5352 diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
5353 index 45698cd..e8e2dbc 100644
5354 --- a/arch/ia64/include/asm/spinlock.h
5355 +++ b/arch/ia64/include/asm/spinlock.h
5356 @@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
5357 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
5358
5359 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
5360 - ACCESS_ONCE(*p) = (tmp + 2) & ~1;
5361 + ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
5362 }
5363
5364 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
5365 diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
5366 index 449c8c0..3d4b1e9 100644
5367 --- a/arch/ia64/include/asm/uaccess.h
5368 +++ b/arch/ia64/include/asm/uaccess.h
5369 @@ -70,6 +70,7 @@
5370 && ((segment).seg == KERNEL_DS.seg \
5371 || likely(REGION_OFFSET((unsigned long) (addr)) < RGN_MAP_LIMIT))); \
5372 })
5373 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
5374 #define access_ok(type, addr, size) __access_ok((addr), (size), get_fs())
5375
5376 /*
5377 @@ -240,12 +241,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
5378 static inline unsigned long
5379 __copy_to_user (void __user *to, const void *from, unsigned long count)
5380 {
5381 + if (count > INT_MAX)
5382 + return count;
5383 +
5384 + if (!__builtin_constant_p(count))
5385 + check_object_size(from, count, true);
5386 +
5387 return __copy_user(to, (__force void __user *) from, count);
5388 }
5389
5390 static inline unsigned long
5391 __copy_from_user (void *to, const void __user *from, unsigned long count)
5392 {
5393 + if (count > INT_MAX)
5394 + return count;
5395 +
5396 + if (!__builtin_constant_p(count))
5397 + check_object_size(to, count, false);
5398 +
5399 return __copy_user((__force void __user *) to, from, count);
5400 }
5401
5402 @@ -255,10 +268,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5403 ({ \
5404 void __user *__cu_to = (to); \
5405 const void *__cu_from = (from); \
5406 - long __cu_len = (n); \
5407 + unsigned long __cu_len = (n); \
5408 \
5409 - if (__access_ok(__cu_to, __cu_len, get_fs())) \
5410 + if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
5411 + if (!__builtin_constant_p(n)) \
5412 + check_object_size(__cu_from, __cu_len, true); \
5413 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
5414 + } \
5415 __cu_len; \
5416 })
5417
5418 @@ -266,11 +282,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5419 ({ \
5420 void *__cu_to = (to); \
5421 const void __user *__cu_from = (from); \
5422 - long __cu_len = (n); \
5423 + unsigned long __cu_len = (n); \
5424 \
5425 __chk_user_ptr(__cu_from); \
5426 - if (__access_ok(__cu_from, __cu_len, get_fs())) \
5427 + if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
5428 + if (!__builtin_constant_p(n)) \
5429 + check_object_size(__cu_to, __cu_len, false); \
5430 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
5431 + } \
5432 __cu_len; \
5433 })
5434
5435 diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
5436 index 24603be..948052d 100644
5437 --- a/arch/ia64/kernel/module.c
5438 +++ b/arch/ia64/kernel/module.c
5439 @@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
5440 void
5441 module_free (struct module *mod, void *module_region)
5442 {
5443 - if (mod && mod->arch.init_unw_table &&
5444 - module_region == mod->module_init) {
5445 + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
5446 unw_remove_unwind_table(mod->arch.init_unw_table);
5447 mod->arch.init_unw_table = NULL;
5448 }
5449 @@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
5450 }
5451
5452 static inline int
5453 +in_init_rx (const struct module *mod, uint64_t addr)
5454 +{
5455 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
5456 +}
5457 +
5458 +static inline int
5459 +in_init_rw (const struct module *mod, uint64_t addr)
5460 +{
5461 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
5462 +}
5463 +
5464 +static inline int
5465 in_init (const struct module *mod, uint64_t addr)
5466 {
5467 - return addr - (uint64_t) mod->module_init < mod->init_size;
5468 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
5469 +}
5470 +
5471 +static inline int
5472 +in_core_rx (const struct module *mod, uint64_t addr)
5473 +{
5474 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
5475 +}
5476 +
5477 +static inline int
5478 +in_core_rw (const struct module *mod, uint64_t addr)
5479 +{
5480 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
5481 }
5482
5483 static inline int
5484 in_core (const struct module *mod, uint64_t addr)
5485 {
5486 - return addr - (uint64_t) mod->module_core < mod->core_size;
5487 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
5488 }
5489
5490 static inline int
5491 @@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
5492 break;
5493
5494 case RV_BDREL:
5495 - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
5496 + if (in_init_rx(mod, val))
5497 + val -= (uint64_t) mod->module_init_rx;
5498 + else if (in_init_rw(mod, val))
5499 + val -= (uint64_t) mod->module_init_rw;
5500 + else if (in_core_rx(mod, val))
5501 + val -= (uint64_t) mod->module_core_rx;
5502 + else if (in_core_rw(mod, val))
5503 + val -= (uint64_t) mod->module_core_rw;
5504 break;
5505
5506 case RV_LTV:
5507 @@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
5508 * addresses have been selected...
5509 */
5510 uint64_t gp;
5511 - if (mod->core_size > MAX_LTOFF)
5512 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
5513 /*
5514 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
5515 * at the end of the module.
5516 */
5517 - gp = mod->core_size - MAX_LTOFF / 2;
5518 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
5519 else
5520 - gp = mod->core_size / 2;
5521 - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
5522 + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
5523 + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
5524 mod->arch.gp = gp;
5525 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
5526 }
5527 diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
5528 index c39c3cd..3c77738 100644
5529 --- a/arch/ia64/kernel/palinfo.c
5530 +++ b/arch/ia64/kernel/palinfo.c
5531 @@ -980,7 +980,7 @@ static int palinfo_cpu_callback(struct notifier_block *nfb,
5532 return NOTIFY_OK;
5533 }
5534
5535 -static struct notifier_block __refdata palinfo_cpu_notifier =
5536 +static struct notifier_block palinfo_cpu_notifier =
5537 {
5538 .notifier_call = palinfo_cpu_callback,
5539 .priority = 0,
5540 diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
5541 index 41e33f8..65180b2a 100644
5542 --- a/arch/ia64/kernel/sys_ia64.c
5543 +++ b/arch/ia64/kernel/sys_ia64.c
5544 @@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5545 unsigned long align_mask = 0;
5546 struct mm_struct *mm = current->mm;
5547 struct vm_unmapped_area_info info;
5548 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5549
5550 if (len > RGN_MAP_LIMIT)
5551 return -ENOMEM;
5552 @@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5553 if (REGION_NUMBER(addr) == RGN_HPAGE)
5554 addr = 0;
5555 #endif
5556 +
5557 +#ifdef CONFIG_PAX_RANDMMAP
5558 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5559 + addr = mm->free_area_cache;
5560 + else
5561 +#endif
5562 +
5563 if (!addr)
5564 addr = TASK_UNMAPPED_BASE;
5565
5566 @@ -61,6 +69,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5567 info.high_limit = TASK_SIZE;
5568 info.align_mask = align_mask;
5569 info.align_offset = 0;
5570 + info.threadstack_offset = offset;
5571 return vm_unmapped_area(&info);
5572 }
5573
5574 diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
5575 index 84f8a52..7c76178 100644
5576 --- a/arch/ia64/kernel/vmlinux.lds.S
5577 +++ b/arch/ia64/kernel/vmlinux.lds.S
5578 @@ -192,7 +192,7 @@ SECTIONS {
5579 /* Per-cpu data: */
5580 . = ALIGN(PERCPU_PAGE_SIZE);
5581 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
5582 - __phys_per_cpu_start = __per_cpu_load;
5583 + __phys_per_cpu_start = per_cpu_load;
5584 /*
5585 * ensure percpu data fits
5586 * into percpu page size
5587 diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
5588 index 7225dad..2a7c8256 100644
5589 --- a/arch/ia64/mm/fault.c
5590 +++ b/arch/ia64/mm/fault.c
5591 @@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
5592 return pte_present(pte);
5593 }
5594
5595 +#ifdef CONFIG_PAX_PAGEEXEC
5596 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5597 +{
5598 + unsigned long i;
5599 +
5600 + printk(KERN_ERR "PAX: bytes at PC: ");
5601 + for (i = 0; i < 8; i++) {
5602 + unsigned int c;
5603 + if (get_user(c, (unsigned int *)pc+i))
5604 + printk(KERN_CONT "???????? ");
5605 + else
5606 + printk(KERN_CONT "%08x ", c);
5607 + }
5608 + printk("\n");
5609 +}
5610 +#endif
5611 +
5612 # define VM_READ_BIT 0
5613 # define VM_WRITE_BIT 1
5614 # define VM_EXEC_BIT 2
5615 @@ -151,8 +168,21 @@ retry:
5616 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
5617 goto bad_area;
5618
5619 - if ((vma->vm_flags & mask) != mask)
5620 + if ((vma->vm_flags & mask) != mask) {
5621 +
5622 +#ifdef CONFIG_PAX_PAGEEXEC
5623 + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
5624 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
5625 + goto bad_area;
5626 +
5627 + up_read(&mm->mmap_sem);
5628 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
5629 + do_group_exit(SIGKILL);
5630 + }
5631 +#endif
5632 +
5633 goto bad_area;
5634 + }
5635
5636 /*
5637 * If for any reason at all we couldn't handle the fault, make
5638 diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
5639 index 76069c1..c2aa816 100644
5640 --- a/arch/ia64/mm/hugetlbpage.c
5641 +++ b/arch/ia64/mm/hugetlbpage.c
5642 @@ -149,6 +149,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5643 unsigned long pgoff, unsigned long flags)
5644 {
5645 struct vm_unmapped_area_info info;
5646 + unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
5647
5648 if (len > RGN_MAP_LIMIT)
5649 return -ENOMEM;
5650 @@ -172,6 +173,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5651 info.high_limit = HPAGE_REGION_BASE + RGN_MAP_LIMIT;
5652 info.align_mask = PAGE_MASK & (HPAGE_SIZE - 1);
5653 info.align_offset = 0;
5654 + info.threadstack_offset = offset;
5655 return vm_unmapped_area(&info);
5656 }
5657
5658 diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
5659 index 6b33457..88b5124 100644
5660 --- a/arch/ia64/mm/init.c
5661 +++ b/arch/ia64/mm/init.c
5662 @@ -120,6 +120,19 @@ ia64_init_addr_space (void)
5663 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
5664 vma->vm_end = vma->vm_start + PAGE_SIZE;
5665 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
5666 +
5667 +#ifdef CONFIG_PAX_PAGEEXEC
5668 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
5669 + vma->vm_flags &= ~VM_EXEC;
5670 +
5671 +#ifdef CONFIG_PAX_MPROTECT
5672 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
5673 + vma->vm_flags &= ~VM_MAYEXEC;
5674 +#endif
5675 +
5676 + }
5677 +#endif
5678 +
5679 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5680 down_write(&current->mm->mmap_sem);
5681 if (insert_vm_struct(current->mm, vma)) {
5682 @@ -286,7 +299,7 @@ static int __init gate_vma_init(void)
5683 gate_vma.vm_start = FIXADDR_USER_START;
5684 gate_vma.vm_end = FIXADDR_USER_END;
5685 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
5686 - gate_vma.vm_page_prot = __P101;
5687 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
5688
5689 return 0;
5690 }
5691 diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
5692 index 40b3ee9..8c2c112 100644
5693 --- a/arch/m32r/include/asm/cache.h
5694 +++ b/arch/m32r/include/asm/cache.h
5695 @@ -1,8 +1,10 @@
5696 #ifndef _ASM_M32R_CACHE_H
5697 #define _ASM_M32R_CACHE_H
5698
5699 +#include <linux/const.h>
5700 +
5701 /* L1 cache line size */
5702 #define L1_CACHE_SHIFT 4
5703 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5704 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5705
5706 #endif /* _ASM_M32R_CACHE_H */
5707 diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
5708 index 82abd15..d95ae5d 100644
5709 --- a/arch/m32r/lib/usercopy.c
5710 +++ b/arch/m32r/lib/usercopy.c
5711 @@ -14,6 +14,9 @@
5712 unsigned long
5713 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5714 {
5715 + if ((long)n < 0)
5716 + return n;
5717 +
5718 prefetch(from);
5719 if (access_ok(VERIFY_WRITE, to, n))
5720 __copy_user(to,from,n);
5721 @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5722 unsigned long
5723 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
5724 {
5725 + if ((long)n < 0)
5726 + return n;
5727 +
5728 prefetchw(to);
5729 if (access_ok(VERIFY_READ, from, n))
5730 __copy_user_zeroing(to,from,n);
5731 diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
5732 index 0395c51..5f26031 100644
5733 --- a/arch/m68k/include/asm/cache.h
5734 +++ b/arch/m68k/include/asm/cache.h
5735 @@ -4,9 +4,11 @@
5736 #ifndef __ARCH_M68K_CACHE_H
5737 #define __ARCH_M68K_CACHE_H
5738
5739 +#include <linux/const.h>
5740 +
5741 /* bytes per L1 cache line */
5742 #define L1_CACHE_SHIFT 4
5743 -#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
5744 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5745
5746 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5747
5748 diff --git a/arch/metag/include/asm/barrier.h b/arch/metag/include/asm/barrier.h
5749 index c7591e8..ecef036 100644
5750 --- a/arch/metag/include/asm/barrier.h
5751 +++ b/arch/metag/include/asm/barrier.h
5752 @@ -89,7 +89,7 @@ static inline void fence(void)
5753 do { \
5754 compiletime_assert_atomic_type(*p); \
5755 smp_mb(); \
5756 - ACCESS_ONCE(*p) = (v); \
5757 + ACCESS_ONCE_RW(*p) = (v); \
5758 } while (0)
5759
5760 #define smp_load_acquire(p) \
5761 diff --git a/arch/metag/mm/hugetlbpage.c b/arch/metag/mm/hugetlbpage.c
5762 index 3c32075..ae0ae75 100644
5763 --- a/arch/metag/mm/hugetlbpage.c
5764 +++ b/arch/metag/mm/hugetlbpage.c
5765 @@ -200,6 +200,7 @@ hugetlb_get_unmapped_area_new_pmd(unsigned long len)
5766 info.high_limit = TASK_SIZE;
5767 info.align_mask = PAGE_MASK & HUGEPT_MASK;
5768 info.align_offset = 0;
5769 + info.threadstack_offset = 0;
5770 return vm_unmapped_area(&info);
5771 }
5772
5773 diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
5774 index 4efe96a..60e8699 100644
5775 --- a/arch/microblaze/include/asm/cache.h
5776 +++ b/arch/microblaze/include/asm/cache.h
5777 @@ -13,11 +13,12 @@
5778 #ifndef _ASM_MICROBLAZE_CACHE_H
5779 #define _ASM_MICROBLAZE_CACHE_H
5780
5781 +#include <linux/const.h>
5782 #include <asm/registers.h>
5783
5784 #define L1_CACHE_SHIFT 5
5785 /* word-granular cache in microblaze */
5786 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5787 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5788
5789 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5790
5791 diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
5792 index 574c430..470200d 100644
5793 --- a/arch/mips/Kconfig
5794 +++ b/arch/mips/Kconfig
5795 @@ -2399,6 +2399,7 @@ source "kernel/Kconfig.preempt"
5796
5797 config KEXEC
5798 bool "Kexec system call"
5799 + depends on !GRKERNSEC_KMEM
5800 help
5801 kexec is a system call that implements the ability to shutdown your
5802 current kernel, and to start another kernel. It is like a reboot
5803 diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-octeon.c
5804 index 02f2444..506969c 100644
5805 --- a/arch/mips/cavium-octeon/dma-octeon.c
5806 +++ b/arch/mips/cavium-octeon/dma-octeon.c
5807 @@ -199,7 +199,7 @@ static void octeon_dma_free_coherent(struct device *dev, size_t size,
5808 if (dma_release_from_coherent(dev, order, vaddr))
5809 return;
5810
5811 - swiotlb_free_coherent(dev, size, vaddr, dma_handle);
5812 + swiotlb_free_coherent(dev, size, vaddr, dma_handle, attrs);
5813 }
5814
5815 static dma_addr_t octeon_unity_phys_to_dma(struct device *dev, phys_addr_t paddr)
5816 diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
5817 index 37b2bef..02122b8 100644
5818 --- a/arch/mips/include/asm/atomic.h
5819 +++ b/arch/mips/include/asm/atomic.h
5820 @@ -21,15 +21,39 @@
5821 #include <asm/cmpxchg.h>
5822 #include <asm/war.h>
5823
5824 +#ifdef CONFIG_GENERIC_ATOMIC64
5825 +#include <asm-generic/atomic64.h>
5826 +#endif
5827 +
5828 #define ATOMIC_INIT(i) { (i) }
5829
5830 +#ifdef CONFIG_64BIT
5831 +#define _ASM_EXTABLE(from, to) \
5832 +" .section __ex_table,\"a\"\n" \
5833 +" .dword " #from ", " #to"\n" \
5834 +" .previous\n"
5835 +#else
5836 +#define _ASM_EXTABLE(from, to) \
5837 +" .section __ex_table,\"a\"\n" \
5838 +" .word " #from ", " #to"\n" \
5839 +" .previous\n"
5840 +#endif
5841 +
5842 /*
5843 * atomic_read - read atomic variable
5844 * @v: pointer of type atomic_t
5845 *
5846 * Atomically reads the value of @v.
5847 */
5848 -#define atomic_read(v) (*(volatile int *)&(v)->counter)
5849 +static inline int atomic_read(const atomic_t *v)
5850 +{
5851 + return (*(volatile const int *) &v->counter);
5852 +}
5853 +
5854 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5855 +{
5856 + return (*(volatile const int *) &v->counter);
5857 +}
5858
5859 /*
5860 * atomic_set - set atomic variable
5861 @@ -38,7 +62,15 @@
5862 *
5863 * Atomically sets the value of @v to @i.
5864 */
5865 -#define atomic_set(v, i) ((v)->counter = (i))
5866 +static inline void atomic_set(atomic_t *v, int i)
5867 +{
5868 + v->counter = i;
5869 +}
5870 +
5871 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5872 +{
5873 + v->counter = i;
5874 +}
5875
5876 /*
5877 * atomic_add - add integer to atomic variable
5878 @@ -47,7 +79,67 @@
5879 *
5880 * Atomically adds @i to @v.
5881 */
5882 -static __inline__ void atomic_add(int i, atomic_t * v)
5883 +static __inline__ void atomic_add(int i, atomic_t *v)
5884 +{
5885 + int temp;
5886 +
5887 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
5888 + __asm__ __volatile__(
5889 + " .set mips3 \n"
5890 + "1: ll %0, %1 # atomic_add \n"
5891 +#ifdef CONFIG_PAX_REFCOUNT
5892 + /* Exception on overflow. */
5893 + "2: add %0, %2 \n"
5894 +#else
5895 + " addu %0, %2 \n"
5896 +#endif
5897 + " sc %0, %1 \n"
5898 + " beqzl %0, 1b \n"
5899 +#ifdef CONFIG_PAX_REFCOUNT
5900 + "3: \n"
5901 + _ASM_EXTABLE(2b, 3b)
5902 +#endif
5903 + " .set mips0 \n"
5904 + : "=&r" (temp), "+m" (v->counter)
5905 + : "Ir" (i));
5906 + } else if (kernel_uses_llsc) {
5907 + __asm__ __volatile__(
5908 + " .set mips3 \n"
5909 + "1: ll %0, %1 # atomic_add \n"
5910 +#ifdef CONFIG_PAX_REFCOUNT
5911 + /* Exception on overflow. */
5912 + "2: add %0, %2 \n"
5913 +#else
5914 + " addu %0, %2 \n"
5915 +#endif
5916 + " sc %0, %1 \n"
5917 + " beqz %0, 1b \n"
5918 +#ifdef CONFIG_PAX_REFCOUNT
5919 + "3: \n"
5920 + _ASM_EXTABLE(2b, 3b)
5921 +#endif
5922 + " .set mips0 \n"
5923 + : "=&r" (temp), "+m" (v->counter)
5924 + : "Ir" (i));
5925 + } else {
5926 + unsigned long flags;
5927 +
5928 + raw_local_irq_save(flags);
5929 + __asm__ __volatile__(
5930 +#ifdef CONFIG_PAX_REFCOUNT
5931 + /* Exception on overflow. */
5932 + "1: add %0, %1 \n"
5933 + "2: \n"
5934 + _ASM_EXTABLE(1b, 2b)
5935 +#else
5936 + " addu %0, %1 \n"
5937 +#endif
5938 + : "+r" (v->counter) : "Ir" (i));
5939 + raw_local_irq_restore(flags);
5940 + }
5941 +}
5942 +
5943 +static __inline__ void atomic_add_unchecked(int i, atomic_unchecked_t *v)
5944 {
5945 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5946 int temp;
5947 @@ -90,7 +182,67 @@ static __inline__ void atomic_add(int i, atomic_t * v)
5948 *
5949 * Atomically subtracts @i from @v.
5950 */
5951 -static __inline__ void atomic_sub(int i, atomic_t * v)
5952 +static __inline__ void atomic_sub(int i, atomic_t *v)
5953 +{
5954 + int temp;
5955 +
5956 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
5957 + __asm__ __volatile__(
5958 + " .set mips3 \n"
5959 + "1: ll %0, %1 # atomic64_sub \n"
5960 +#ifdef CONFIG_PAX_REFCOUNT
5961 + /* Exception on overflow. */
5962 + "2: sub %0, %2 \n"
5963 +#else
5964 + " subu %0, %2 \n"
5965 +#endif
5966 + " sc %0, %1 \n"
5967 + " beqzl %0, 1b \n"
5968 +#ifdef CONFIG_PAX_REFCOUNT
5969 + "3: \n"
5970 + _ASM_EXTABLE(2b, 3b)
5971 +#endif
5972 + " .set mips0 \n"
5973 + : "=&r" (temp), "+m" (v->counter)
5974 + : "Ir" (i));
5975 + } else if (kernel_uses_llsc) {
5976 + __asm__ __volatile__(
5977 + " .set mips3 \n"
5978 + "1: ll %0, %1 # atomic64_sub \n"
5979 +#ifdef CONFIG_PAX_REFCOUNT
5980 + /* Exception on overflow. */
5981 + "2: sub %0, %2 \n"
5982 +#else
5983 + " subu %0, %2 \n"
5984 +#endif
5985 + " sc %0, %1 \n"
5986 + " beqz %0, 1b \n"
5987 +#ifdef CONFIG_PAX_REFCOUNT
5988 + "3: \n"
5989 + _ASM_EXTABLE(2b, 3b)
5990 +#endif
5991 + " .set mips0 \n"
5992 + : "=&r" (temp), "+m" (v->counter)
5993 + : "Ir" (i));
5994 + } else {
5995 + unsigned long flags;
5996 +
5997 + raw_local_irq_save(flags);
5998 + __asm__ __volatile__(
5999 +#ifdef CONFIG_PAX_REFCOUNT
6000 + /* Exception on overflow. */
6001 + "1: sub %0, %1 \n"
6002 + "2: \n"
6003 + _ASM_EXTABLE(1b, 2b)
6004 +#else
6005 + " subu %0, %1 \n"
6006 +#endif
6007 + : "+r" (v->counter) : "Ir" (i));
6008 + raw_local_irq_restore(flags);
6009 + }
6010 +}
6011 +
6012 +static __inline__ void atomic_sub_unchecked(long i, atomic_unchecked_t *v)
6013 {
6014 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6015 int temp;
6016 @@ -129,7 +281,93 @@ static __inline__ void atomic_sub(int i, atomic_t * v)
6017 /*
6018 * Same as above, but return the result value
6019 */
6020 -static __inline__ int atomic_add_return(int i, atomic_t * v)
6021 +static __inline__ int atomic_add_return(int i, atomic_t *v)
6022 +{
6023 + int result;
6024 + int temp;
6025 +
6026 + smp_mb__before_llsc();
6027 +
6028 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6029 + __asm__ __volatile__(
6030 + " .set mips3 \n"
6031 + "1: ll %1, %2 # atomic_add_return \n"
6032 +#ifdef CONFIG_PAX_REFCOUNT
6033 + "2: add %0, %1, %3 \n"
6034 +#else
6035 + " addu %0, %1, %3 \n"
6036 +#endif
6037 + " sc %0, %2 \n"
6038 + " beqzl %0, 1b \n"
6039 +#ifdef CONFIG_PAX_REFCOUNT
6040 + " b 4f \n"
6041 + " .set noreorder \n"
6042 + "3: b 5f \n"
6043 + " move %0, %1 \n"
6044 + " .set reorder \n"
6045 + _ASM_EXTABLE(2b, 3b)
6046 +#endif
6047 + "4: addu %0, %1, %3 \n"
6048 +#ifdef CONFIG_PAX_REFCOUNT
6049 + "5: \n"
6050 +#endif
6051 + " .set mips0 \n"
6052 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6053 + : "Ir" (i));
6054 + } else if (kernel_uses_llsc) {
6055 + __asm__ __volatile__(
6056 + " .set mips3 \n"
6057 + "1: ll %1, %2 # atomic_add_return \n"
6058 +#ifdef CONFIG_PAX_REFCOUNT
6059 + "2: add %0, %1, %3 \n"
6060 +#else
6061 + " addu %0, %1, %3 \n"
6062 +#endif
6063 + " sc %0, %2 \n"
6064 + " bnez %0, 4f \n"
6065 + " b 1b \n"
6066 +#ifdef CONFIG_PAX_REFCOUNT
6067 + " .set noreorder \n"
6068 + "3: b 5f \n"
6069 + " move %0, %1 \n"
6070 + " .set reorder \n"
6071 + _ASM_EXTABLE(2b, 3b)
6072 +#endif
6073 + "4: addu %0, %1, %3 \n"
6074 +#ifdef CONFIG_PAX_REFCOUNT
6075 + "5: \n"
6076 +#endif
6077 + " .set mips0 \n"
6078 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6079 + : "Ir" (i));
6080 + } else {
6081 + unsigned long flags;
6082 +
6083 + raw_local_irq_save(flags);
6084 + __asm__ __volatile__(
6085 + " lw %0, %1 \n"
6086 +#ifdef CONFIG_PAX_REFCOUNT
6087 + /* Exception on overflow. */
6088 + "1: add %0, %2 \n"
6089 +#else
6090 + " addu %0, %2 \n"
6091 +#endif
6092 + " sw %0, %1 \n"
6093 +#ifdef CONFIG_PAX_REFCOUNT
6094 + /* Note: Dest reg is not modified on overflow */
6095 + "2: \n"
6096 + _ASM_EXTABLE(1b, 2b)
6097 +#endif
6098 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6099 + raw_local_irq_restore(flags);
6100 + }
6101 +
6102 + smp_llsc_mb();
6103 +
6104 + return result;
6105 +}
6106 +
6107 +static __inline__ int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
6108 {
6109 int result;
6110
6111 @@ -178,7 +416,93 @@ static __inline__ int atomic_add_return(int i, atomic_t * v)
6112 return result;
6113 }
6114
6115 -static __inline__ int atomic_sub_return(int i, atomic_t * v)
6116 +static __inline__ int atomic_sub_return(int i, atomic_t *v)
6117 +{
6118 + int result;
6119 + int temp;
6120 +
6121 + smp_mb__before_llsc();
6122 +
6123 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6124 + __asm__ __volatile__(
6125 + " .set mips3 \n"
6126 + "1: ll %1, %2 # atomic_sub_return \n"
6127 +#ifdef CONFIG_PAX_REFCOUNT
6128 + "2: sub %0, %1, %3 \n"
6129 +#else
6130 + " subu %0, %1, %3 \n"
6131 +#endif
6132 + " sc %0, %2 \n"
6133 + " beqzl %0, 1b \n"
6134 +#ifdef CONFIG_PAX_REFCOUNT
6135 + " b 4f \n"
6136 + " .set noreorder \n"
6137 + "3: b 5f \n"
6138 + " move %0, %1 \n"
6139 + " .set reorder \n"
6140 + _ASM_EXTABLE(2b, 3b)
6141 +#endif
6142 + "4: subu %0, %1, %3 \n"
6143 +#ifdef CONFIG_PAX_REFCOUNT
6144 + "5: \n"
6145 +#endif
6146 + " .set mips0 \n"
6147 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6148 + : "Ir" (i), "m" (v->counter)
6149 + : "memory");
6150 + } else if (kernel_uses_llsc) {
6151 + __asm__ __volatile__(
6152 + " .set mips3 \n"
6153 + "1: ll %1, %2 # atomic_sub_return \n"
6154 +#ifdef CONFIG_PAX_REFCOUNT
6155 + "2: sub %0, %1, %3 \n"
6156 +#else
6157 + " subu %0, %1, %3 \n"
6158 +#endif
6159 + " sc %0, %2 \n"
6160 + " bnez %0, 4f \n"
6161 + " b 1b \n"
6162 +#ifdef CONFIG_PAX_REFCOUNT
6163 + " .set noreorder \n"
6164 + "3: b 5f \n"
6165 + " move %0, %1 \n"
6166 + " .set reorder \n"
6167 + _ASM_EXTABLE(2b, 3b)
6168 +#endif
6169 + "4: subu %0, %1, %3 \n"
6170 +#ifdef CONFIG_PAX_REFCOUNT
6171 + "5: \n"
6172 +#endif
6173 + " .set mips0 \n"
6174 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6175 + : "Ir" (i));
6176 + } else {
6177 + unsigned long flags;
6178 +
6179 + raw_local_irq_save(flags);
6180 + __asm__ __volatile__(
6181 + " lw %0, %1 \n"
6182 +#ifdef CONFIG_PAX_REFCOUNT
6183 + /* Exception on overflow. */
6184 + "1: sub %0, %2 \n"
6185 +#else
6186 + " subu %0, %2 \n"
6187 +#endif
6188 + " sw %0, %1 \n"
6189 +#ifdef CONFIG_PAX_REFCOUNT
6190 + /* Note: Dest reg is not modified on overflow */
6191 + "2: \n"
6192 + _ASM_EXTABLE(1b, 2b)
6193 +#endif
6194 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6195 + raw_local_irq_restore(flags);
6196 + }
6197 +
6198 + smp_llsc_mb();
6199 +
6200 + return result;
6201 +}
6202 +static __inline__ int atomic_sub_return_unchecked(int i, atomic_unchecked_t *v)
6203 {
6204 int result;
6205
6206 @@ -238,7 +562,7 @@ static __inline__ int atomic_sub_return(int i, atomic_t * v)
6207 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6208 * The function returns the old value of @v minus @i.
6209 */
6210 -static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
6211 +static __inline__ int atomic_sub_if_positive(int i, atomic_t *v)
6212 {
6213 int result;
6214
6215 @@ -295,8 +619,26 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
6216 return result;
6217 }
6218
6219 -#define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
6220 -#define atomic_xchg(v, new) (xchg(&((v)->counter), (new)))
6221 +static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
6222 +{
6223 + return cmpxchg(&v->counter, old, new);
6224 +}
6225 +
6226 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old,
6227 + int new)
6228 +{
6229 + return cmpxchg(&(v->counter), old, new);
6230 +}
6231 +
6232 +static inline int atomic_xchg(atomic_t *v, int new)
6233 +{
6234 + return xchg(&v->counter, new);
6235 +}
6236 +
6237 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
6238 +{
6239 + return xchg(&(v->counter), new);
6240 +}
6241
6242 /**
6243 * __atomic_add_unless - add unless the number is a given value
6244 @@ -324,6 +666,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6245
6246 #define atomic_dec_return(v) atomic_sub_return(1, (v))
6247 #define atomic_inc_return(v) atomic_add_return(1, (v))
6248 +static __inline__ int atomic_inc_return_unchecked(atomic_unchecked_t *v)
6249 +{
6250 + return atomic_add_return_unchecked(1, v);
6251 +}
6252
6253 /*
6254 * atomic_sub_and_test - subtract value from variable and test result
6255 @@ -345,6 +691,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6256 * other cases.
6257 */
6258 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
6259 +static __inline__ int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
6260 +{
6261 + return atomic_add_return_unchecked(1, v) == 0;
6262 +}
6263
6264 /*
6265 * atomic_dec_and_test - decrement by 1 and test
6266 @@ -369,6 +719,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6267 * Atomically increments @v by 1.
6268 */
6269 #define atomic_inc(v) atomic_add(1, (v))
6270 +static __inline__ void atomic_inc_unchecked(atomic_unchecked_t *v)
6271 +{
6272 + atomic_add_unchecked(1, v);
6273 +}
6274
6275 /*
6276 * atomic_dec - decrement and test
6277 @@ -377,6 +731,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6278 * Atomically decrements @v by 1.
6279 */
6280 #define atomic_dec(v) atomic_sub(1, (v))
6281 +static __inline__ void atomic_dec_unchecked(atomic_unchecked_t *v)
6282 +{
6283 + atomic_sub_unchecked(1, v);
6284 +}
6285
6286 /*
6287 * atomic_add_negative - add and test if negative
6288 @@ -398,14 +756,30 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6289 * @v: pointer of type atomic64_t
6290 *
6291 */
6292 -#define atomic64_read(v) (*(volatile long *)&(v)->counter)
6293 +static inline long atomic64_read(const atomic64_t *v)
6294 +{
6295 + return (*(volatile const long *) &v->counter);
6296 +}
6297 +
6298 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
6299 +{
6300 + return (*(volatile const long *) &v->counter);
6301 +}
6302
6303 /*
6304 * atomic64_set - set atomic variable
6305 * @v: pointer of type atomic64_t
6306 * @i: required value
6307 */
6308 -#define atomic64_set(v, i) ((v)->counter = (i))
6309 +static inline void atomic64_set(atomic64_t *v, long i)
6310 +{
6311 + v->counter = i;
6312 +}
6313 +
6314 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
6315 +{
6316 + v->counter = i;
6317 +}
6318
6319 /*
6320 * atomic64_add - add integer to atomic variable
6321 @@ -414,7 +788,66 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6322 *
6323 * Atomically adds @i to @v.
6324 */
6325 -static __inline__ void atomic64_add(long i, atomic64_t * v)
6326 +static __inline__ void atomic64_add(long i, atomic64_t *v)
6327 +{
6328 + long temp;
6329 +
6330 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6331 + __asm__ __volatile__(
6332 + " .set mips3 \n"
6333 + "1: lld %0, %1 # atomic64_add \n"
6334 +#ifdef CONFIG_PAX_REFCOUNT
6335 + /* Exception on overflow. */
6336 + "2: dadd %0, %2 \n"
6337 +#else
6338 + " daddu %0, %2 \n"
6339 +#endif
6340 + " scd %0, %1 \n"
6341 + " beqzl %0, 1b \n"
6342 +#ifdef CONFIG_PAX_REFCOUNT
6343 + "3: \n"
6344 + _ASM_EXTABLE(2b, 3b)
6345 +#endif
6346 + " .set mips0 \n"
6347 + : "=&r" (temp), "+m" (v->counter)
6348 + : "Ir" (i));
6349 + } else if (kernel_uses_llsc) {
6350 + __asm__ __volatile__(
6351 + " .set mips3 \n"
6352 + "1: lld %0, %1 # atomic64_add \n"
6353 +#ifdef CONFIG_PAX_REFCOUNT
6354 + /* Exception on overflow. */
6355 + "2: dadd %0, %2 \n"
6356 +#else
6357 + " daddu %0, %2 \n"
6358 +#endif
6359 + " scd %0, %1 \n"
6360 + " beqz %0, 1b \n"
6361 +#ifdef CONFIG_PAX_REFCOUNT
6362 + "3: \n"
6363 + _ASM_EXTABLE(2b, 3b)
6364 +#endif
6365 + " .set mips0 \n"
6366 + : "=&r" (temp), "+m" (v->counter)
6367 + : "Ir" (i));
6368 + } else {
6369 + unsigned long flags;
6370 +
6371 + raw_local_irq_save(flags);
6372 + __asm__ __volatile__(
6373 +#ifdef CONFIG_PAX_REFCOUNT
6374 + /* Exception on overflow. */
6375 + "1: dadd %0, %1 \n"
6376 + "2: \n"
6377 + _ASM_EXTABLE(1b, 2b)
6378 +#else
6379 + " daddu %0, %1 \n"
6380 +#endif
6381 + : "+r" (v->counter) : "Ir" (i));
6382 + raw_local_irq_restore(flags);
6383 + }
6384 +}
6385 +static __inline__ void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
6386 {
6387 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6388 long temp;
6389 @@ -457,7 +890,67 @@ static __inline__ void atomic64_add(long i, atomic64_t * v)
6390 *
6391 * Atomically subtracts @i from @v.
6392 */
6393 -static __inline__ void atomic64_sub(long i, atomic64_t * v)
6394 +static __inline__ void atomic64_sub(long i, atomic64_t *v)
6395 +{
6396 + long temp;
6397 +
6398 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6399 + __asm__ __volatile__(
6400 + " .set mips3 \n"
6401 + "1: lld %0, %1 # atomic64_sub \n"
6402 +#ifdef CONFIG_PAX_REFCOUNT
6403 + /* Exception on overflow. */
6404 + "2: dsub %0, %2 \n"
6405 +#else
6406 + " dsubu %0, %2 \n"
6407 +#endif
6408 + " scd %0, %1 \n"
6409 + " beqzl %0, 1b \n"
6410 +#ifdef CONFIG_PAX_REFCOUNT
6411 + "3: \n"
6412 + _ASM_EXTABLE(2b, 3b)
6413 +#endif
6414 + " .set mips0 \n"
6415 + : "=&r" (temp), "+m" (v->counter)
6416 + : "Ir" (i));
6417 + } else if (kernel_uses_llsc) {
6418 + __asm__ __volatile__(
6419 + " .set mips3 \n"
6420 + "1: lld %0, %1 # atomic64_sub \n"
6421 +#ifdef CONFIG_PAX_REFCOUNT
6422 + /* Exception on overflow. */
6423 + "2: dsub %0, %2 \n"
6424 +#else
6425 + " dsubu %0, %2 \n"
6426 +#endif
6427 + " scd %0, %1 \n"
6428 + " beqz %0, 1b \n"
6429 +#ifdef CONFIG_PAX_REFCOUNT
6430 + "3: \n"
6431 + _ASM_EXTABLE(2b, 3b)
6432 +#endif
6433 + " .set mips0 \n"
6434 + : "=&r" (temp), "+m" (v->counter)
6435 + : "Ir" (i));
6436 + } else {
6437 + unsigned long flags;
6438 +
6439 + raw_local_irq_save(flags);
6440 + __asm__ __volatile__(
6441 +#ifdef CONFIG_PAX_REFCOUNT
6442 + /* Exception on overflow. */
6443 + "1: dsub %0, %1 \n"
6444 + "2: \n"
6445 + _ASM_EXTABLE(1b, 2b)
6446 +#else
6447 + " dsubu %0, %1 \n"
6448 +#endif
6449 + : "+r" (v->counter) : "Ir" (i));
6450 + raw_local_irq_restore(flags);
6451 + }
6452 +}
6453 +
6454 +static __inline__ void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
6455 {
6456 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6457 long temp;
6458 @@ -496,7 +989,93 @@ static __inline__ void atomic64_sub(long i, atomic64_t * v)
6459 /*
6460 * Same as above, but return the result value
6461 */
6462 -static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6463 +static __inline__ long atomic64_add_return(long i, atomic64_t *v)
6464 +{
6465 + long result;
6466 + long temp;
6467 +
6468 + smp_mb__before_llsc();
6469 +
6470 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6471 + __asm__ __volatile__(
6472 + " .set mips3 \n"
6473 + "1: lld %1, %2 # atomic64_add_return \n"
6474 +#ifdef CONFIG_PAX_REFCOUNT
6475 + "2: dadd %0, %1, %3 \n"
6476 +#else
6477 + " daddu %0, %1, %3 \n"
6478 +#endif
6479 + " scd %0, %2 \n"
6480 + " beqzl %0, 1b \n"
6481 +#ifdef CONFIG_PAX_REFCOUNT
6482 + " b 4f \n"
6483 + " .set noreorder \n"
6484 + "3: b 5f \n"
6485 + " move %0, %1 \n"
6486 + " .set reorder \n"
6487 + _ASM_EXTABLE(2b, 3b)
6488 +#endif
6489 + "4: daddu %0, %1, %3 \n"
6490 +#ifdef CONFIG_PAX_REFCOUNT
6491 + "5: \n"
6492 +#endif
6493 + " .set mips0 \n"
6494 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6495 + : "Ir" (i));
6496 + } else if (kernel_uses_llsc) {
6497 + __asm__ __volatile__(
6498 + " .set mips3 \n"
6499 + "1: lld %1, %2 # atomic64_add_return \n"
6500 +#ifdef CONFIG_PAX_REFCOUNT
6501 + "2: dadd %0, %1, %3 \n"
6502 +#else
6503 + " daddu %0, %1, %3 \n"
6504 +#endif
6505 + " scd %0, %2 \n"
6506 + " bnez %0, 4f \n"
6507 + " b 1b \n"
6508 +#ifdef CONFIG_PAX_REFCOUNT
6509 + " .set noreorder \n"
6510 + "3: b 5f \n"
6511 + " move %0, %1 \n"
6512 + " .set reorder \n"
6513 + _ASM_EXTABLE(2b, 3b)
6514 +#endif
6515 + "4: daddu %0, %1, %3 \n"
6516 +#ifdef CONFIG_PAX_REFCOUNT
6517 + "5: \n"
6518 +#endif
6519 + " .set mips0 \n"
6520 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6521 + : "Ir" (i), "m" (v->counter)
6522 + : "memory");
6523 + } else {
6524 + unsigned long flags;
6525 +
6526 + raw_local_irq_save(flags);
6527 + __asm__ __volatile__(
6528 + " ld %0, %1 \n"
6529 +#ifdef CONFIG_PAX_REFCOUNT
6530 + /* Exception on overflow. */
6531 + "1: dadd %0, %2 \n"
6532 +#else
6533 + " daddu %0, %2 \n"
6534 +#endif
6535 + " sd %0, %1 \n"
6536 +#ifdef CONFIG_PAX_REFCOUNT
6537 + /* Note: Dest reg is not modified on overflow */
6538 + "2: \n"
6539 + _ASM_EXTABLE(1b, 2b)
6540 +#endif
6541 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6542 + raw_local_irq_restore(flags);
6543 + }
6544 +
6545 + smp_llsc_mb();
6546 +
6547 + return result;
6548 +}
6549 +static __inline__ long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
6550 {
6551 long result;
6552
6553 @@ -546,7 +1125,97 @@ static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6554 return result;
6555 }
6556
6557 -static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6558 +static __inline__ long atomic64_sub_return(long i, atomic64_t *v)
6559 +{
6560 + long result;
6561 + long temp;
6562 +
6563 + smp_mb__before_llsc();
6564 +
6565 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6566 + long temp;
6567 +
6568 + __asm__ __volatile__(
6569 + " .set mips3 \n"
6570 + "1: lld %1, %2 # atomic64_sub_return \n"
6571 +#ifdef CONFIG_PAX_REFCOUNT
6572 + "2: dsub %0, %1, %3 \n"
6573 +#else
6574 + " dsubu %0, %1, %3 \n"
6575 +#endif
6576 + " scd %0, %2 \n"
6577 + " beqzl %0, 1b \n"
6578 +#ifdef CONFIG_PAX_REFCOUNT
6579 + " b 4f \n"
6580 + " .set noreorder \n"
6581 + "3: b 5f \n"
6582 + " move %0, %1 \n"
6583 + " .set reorder \n"
6584 + _ASM_EXTABLE(2b, 3b)
6585 +#endif
6586 + "4: dsubu %0, %1, %3 \n"
6587 +#ifdef CONFIG_PAX_REFCOUNT
6588 + "5: \n"
6589 +#endif
6590 + " .set mips0 \n"
6591 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6592 + : "Ir" (i), "m" (v->counter)
6593 + : "memory");
6594 + } else if (kernel_uses_llsc) {
6595 + __asm__ __volatile__(
6596 + " .set mips3 \n"
6597 + "1: lld %1, %2 # atomic64_sub_return \n"
6598 +#ifdef CONFIG_PAX_REFCOUNT
6599 + "2: dsub %0, %1, %3 \n"
6600 +#else
6601 + " dsubu %0, %1, %3 \n"
6602 +#endif
6603 + " scd %0, %2 \n"
6604 + " bnez %0, 4f \n"
6605 + " b 1b \n"
6606 +#ifdef CONFIG_PAX_REFCOUNT
6607 + " .set noreorder \n"
6608 + "3: b 5f \n"
6609 + " move %0, %1 \n"
6610 + " .set reorder \n"
6611 + _ASM_EXTABLE(2b, 3b)
6612 +#endif
6613 + "4: dsubu %0, %1, %3 \n"
6614 +#ifdef CONFIG_PAX_REFCOUNT
6615 + "5: \n"
6616 +#endif
6617 + " .set mips0 \n"
6618 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6619 + : "Ir" (i), "m" (v->counter)
6620 + : "memory");
6621 + } else {
6622 + unsigned long flags;
6623 +
6624 + raw_local_irq_save(flags);
6625 + __asm__ __volatile__(
6626 + " ld %0, %1 \n"
6627 +#ifdef CONFIG_PAX_REFCOUNT
6628 + /* Exception on overflow. */
6629 + "1: dsub %0, %2 \n"
6630 +#else
6631 + " dsubu %0, %2 \n"
6632 +#endif
6633 + " sd %0, %1 \n"
6634 +#ifdef CONFIG_PAX_REFCOUNT
6635 + /* Note: Dest reg is not modified on overflow */
6636 + "2: \n"
6637 + _ASM_EXTABLE(1b, 2b)
6638 +#endif
6639 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6640 + raw_local_irq_restore(flags);
6641 + }
6642 +
6643 + smp_llsc_mb();
6644 +
6645 + return result;
6646 +}
6647 +
6648 +static __inline__ long atomic64_sub_return_unchecked(long i, atomic64_unchecked_t *v)
6649 {
6650 long result;
6651
6652 @@ -605,7 +1274,7 @@ static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6653 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6654 * The function returns the old value of @v minus @i.
6655 */
6656 -static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6657 +static __inline__ long atomic64_sub_if_positive(long i, atomic64_t *v)
6658 {
6659 long result;
6660
6661 @@ -662,9 +1331,26 @@ static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6662 return result;
6663 }
6664
6665 -#define atomic64_cmpxchg(v, o, n) \
6666 - ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
6667 -#define atomic64_xchg(v, new) (xchg(&((v)->counter), (new)))
6668 +static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
6669 +{
6670 + return cmpxchg(&v->counter, old, new);
6671 +}
6672 +
6673 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old,
6674 + long new)
6675 +{
6676 + return cmpxchg(&(v->counter), old, new);
6677 +}
6678 +
6679 +static inline long atomic64_xchg(atomic64_t *v, long new)
6680 +{
6681 + return xchg(&v->counter, new);
6682 +}
6683 +
6684 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
6685 +{
6686 + return xchg(&(v->counter), new);
6687 +}
6688
6689 /**
6690 * atomic64_add_unless - add unless the number is a given value
6691 @@ -694,6 +1380,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6692
6693 #define atomic64_dec_return(v) atomic64_sub_return(1, (v))
6694 #define atomic64_inc_return(v) atomic64_add_return(1, (v))
6695 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1, (v))
6696
6697 /*
6698 * atomic64_sub_and_test - subtract value from variable and test result
6699 @@ -715,6 +1402,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6700 * other cases.
6701 */
6702 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
6703 +#define atomic64_inc_and_test_unchecked(v) atomic64_add_return_unchecked(1, (v)) == 0)
6704
6705 /*
6706 * atomic64_dec_and_test - decrement by 1 and test
6707 @@ -739,6 +1427,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6708 * Atomically increments @v by 1.
6709 */
6710 #define atomic64_inc(v) atomic64_add(1, (v))
6711 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1, (v))
6712
6713 /*
6714 * atomic64_dec - decrement and test
6715 @@ -747,6 +1436,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6716 * Atomically decrements @v by 1.
6717 */
6718 #define atomic64_dec(v) atomic64_sub(1, (v))
6719 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1, (v))
6720
6721 /*
6722 * atomic64_add_negative - add and test if negative
6723 diff --git a/arch/mips/include/asm/barrier.h b/arch/mips/include/asm/barrier.h
6724 index d0101dd..266982c 100644
6725 --- a/arch/mips/include/asm/barrier.h
6726 +++ b/arch/mips/include/asm/barrier.h
6727 @@ -184,7 +184,7 @@
6728 do { \
6729 compiletime_assert_atomic_type(*p); \
6730 smp_mb(); \
6731 - ACCESS_ONCE(*p) = (v); \
6732 + ACCESS_ONCE_RW(*p) = (v); \
6733 } while (0)
6734
6735 #define smp_load_acquire(p) \
6736 diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
6737 index b4db69f..8f3b093 100644
6738 --- a/arch/mips/include/asm/cache.h
6739 +++ b/arch/mips/include/asm/cache.h
6740 @@ -9,10 +9,11 @@
6741 #ifndef _ASM_CACHE_H
6742 #define _ASM_CACHE_H
6743
6744 +#include <linux/const.h>
6745 #include <kmalloc.h>
6746
6747 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
6748 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6749 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6750
6751 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
6752 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6753 diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
6754 index 1d38fe0..9beabc9 100644
6755 --- a/arch/mips/include/asm/elf.h
6756 +++ b/arch/mips/include/asm/elf.h
6757 @@ -381,13 +381,16 @@ extern const char *__elf_platform;
6758 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
6759 #endif
6760
6761 +#ifdef CONFIG_PAX_ASLR
6762 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6763 +
6764 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6765 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6766 +#endif
6767 +
6768 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
6769 struct linux_binprm;
6770 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
6771 int uses_interp);
6772
6773 -struct mm_struct;
6774 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6775 -#define arch_randomize_brk arch_randomize_brk
6776 -
6777 #endif /* _ASM_ELF_H */
6778 diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
6779 index c1f6afa..38cc6e9 100644
6780 --- a/arch/mips/include/asm/exec.h
6781 +++ b/arch/mips/include/asm/exec.h
6782 @@ -12,6 +12,6 @@
6783 #ifndef _ASM_EXEC_H
6784 #define _ASM_EXEC_H
6785
6786 -extern unsigned long arch_align_stack(unsigned long sp);
6787 +#define arch_align_stack(x) ((x) & ~0xfUL)
6788
6789 #endif /* _ASM_EXEC_H */
6790 diff --git a/arch/mips/include/asm/hw_irq.h b/arch/mips/include/asm/hw_irq.h
6791 index 9e8ef59..1139d6b 100644
6792 --- a/arch/mips/include/asm/hw_irq.h
6793 +++ b/arch/mips/include/asm/hw_irq.h
6794 @@ -10,7 +10,7 @@
6795
6796 #include <linux/atomic.h>
6797
6798 -extern atomic_t irq_err_count;
6799 +extern atomic_unchecked_t irq_err_count;
6800
6801 /*
6802 * interrupt-retrigger: NOP for now. This may not be appropriate for all
6803 diff --git a/arch/mips/include/asm/local.h b/arch/mips/include/asm/local.h
6804 index 46dfc3c..a16b13a 100644
6805 --- a/arch/mips/include/asm/local.h
6806 +++ b/arch/mips/include/asm/local.h
6807 @@ -12,15 +12,25 @@ typedef struct
6808 atomic_long_t a;
6809 } local_t;
6810
6811 +typedef struct {
6812 + atomic_long_unchecked_t a;
6813 +} local_unchecked_t;
6814 +
6815 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
6816
6817 #define local_read(l) atomic_long_read(&(l)->a)
6818 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
6819 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
6820 +#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
6821
6822 #define local_add(i, l) atomic_long_add((i), (&(l)->a))
6823 +#define local_add_unchecked(i, l) atomic_long_add_unchecked((i), (&(l)->a))
6824 #define local_sub(i, l) atomic_long_sub((i), (&(l)->a))
6825 +#define local_sub_unchecked(i, l) atomic_long_sub_unchecked((i), (&(l)->a))
6826 #define local_inc(l) atomic_long_inc(&(l)->a)
6827 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
6828 #define local_dec(l) atomic_long_dec(&(l)->a)
6829 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
6830
6831 /*
6832 * Same as above, but return the result value
6833 @@ -70,6 +80,51 @@ static __inline__ long local_add_return(long i, local_t * l)
6834 return result;
6835 }
6836
6837 +static __inline__ long local_add_return_unchecked(long i, local_unchecked_t * l)
6838 +{
6839 + unsigned long result;
6840 +
6841 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6842 + unsigned long temp;
6843 +
6844 + __asm__ __volatile__(
6845 + " .set mips3 \n"
6846 + "1:" __LL "%1, %2 # local_add_return \n"
6847 + " addu %0, %1, %3 \n"
6848 + __SC "%0, %2 \n"
6849 + " beqzl %0, 1b \n"
6850 + " addu %0, %1, %3 \n"
6851 + " .set mips0 \n"
6852 + : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6853 + : "Ir" (i), "m" (l->a.counter)
6854 + : "memory");
6855 + } else if (kernel_uses_llsc) {
6856 + unsigned long temp;
6857 +
6858 + __asm__ __volatile__(
6859 + " .set mips3 \n"
6860 + "1:" __LL "%1, %2 # local_add_return \n"
6861 + " addu %0, %1, %3 \n"
6862 + __SC "%0, %2 \n"
6863 + " beqz %0, 1b \n"
6864 + " addu %0, %1, %3 \n"
6865 + " .set mips0 \n"
6866 + : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6867 + : "Ir" (i), "m" (l->a.counter)
6868 + : "memory");
6869 + } else {
6870 + unsigned long flags;
6871 +
6872 + local_irq_save(flags);
6873 + result = l->a.counter;
6874 + result += i;
6875 + l->a.counter = result;
6876 + local_irq_restore(flags);
6877 + }
6878 +
6879 + return result;
6880 +}
6881 +
6882 static __inline__ long local_sub_return(long i, local_t * l)
6883 {
6884 unsigned long result;
6885 @@ -117,6 +172,8 @@ static __inline__ long local_sub_return(long i, local_t * l)
6886
6887 #define local_cmpxchg(l, o, n) \
6888 ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6889 +#define local_cmpxchg_unchecked(l, o, n) \
6890 + ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6891 #define local_xchg(l, n) (atomic_long_xchg((&(l)->a), (n)))
6892
6893 /**
6894 diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
6895 index 3be8180..c4798d5 100644
6896 --- a/arch/mips/include/asm/page.h
6897 +++ b/arch/mips/include/asm/page.h
6898 @@ -120,7 +120,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
6899 #ifdef CONFIG_CPU_MIPS32
6900 typedef struct { unsigned long pte_low, pte_high; } pte_t;
6901 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
6902 - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
6903 + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
6904 #else
6905 typedef struct { unsigned long long pte; } pte_t;
6906 #define pte_val(x) ((x).pte)
6907 diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
6908 index b336037..5b874cc 100644
6909 --- a/arch/mips/include/asm/pgalloc.h
6910 +++ b/arch/mips/include/asm/pgalloc.h
6911 @@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6912 {
6913 set_pud(pud, __pud((unsigned long)pmd));
6914 }
6915 +
6916 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6917 +{
6918 + pud_populate(mm, pud, pmd);
6919 +}
6920 #endif
6921
6922 /*
6923 diff --git a/arch/mips/include/asm/pgtable.h b/arch/mips/include/asm/pgtable.h
6924 index df49a30..c0d3dd6 100644
6925 --- a/arch/mips/include/asm/pgtable.h
6926 +++ b/arch/mips/include/asm/pgtable.h
6927 @@ -20,6 +20,9 @@
6928 #include <asm/io.h>
6929 #include <asm/pgtable-bits.h>
6930
6931 +#define ktla_ktva(addr) (addr)
6932 +#define ktva_ktla(addr) (addr)
6933 +
6934 struct mm_struct;
6935 struct vm_area_struct;
6936
6937 diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
6938 index 7de8658..c109224 100644
6939 --- a/arch/mips/include/asm/thread_info.h
6940 +++ b/arch/mips/include/asm/thread_info.h
6941 @@ -105,6 +105,9 @@ static inline struct thread_info *current_thread_info(void)
6942 #define TIF_SECCOMP 4 /* secure computing */
6943 #define TIF_NOTIFY_RESUME 5 /* callback before returning to user */
6944 #define TIF_RESTORE_SIGMASK 9 /* restore signal mask in do_signal() */
6945 +/* li takes a 32bit immediate */
6946 +#define TIF_GRSEC_SETXID 10 /* update credentials on syscall entry/exit */
6947 +
6948 #define TIF_USEDFPU 16 /* FPU was used by this task this quantum (SMP) */
6949 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
6950 #define TIF_NOHZ 19 /* in adaptive nohz mode */
6951 @@ -138,14 +141,16 @@ static inline struct thread_info *current_thread_info(void)
6952 #define _TIF_USEDMSA (1<<TIF_USEDMSA)
6953 #define _TIF_MSA_CTX_LIVE (1<<TIF_MSA_CTX_LIVE)
6954 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6955 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6956
6957 #define _TIF_WORK_SYSCALL_ENTRY (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6958 _TIF_SYSCALL_AUDIT | \
6959 - _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
6960 + _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | \
6961 + _TIF_GRSEC_SETXID)
6962
6963 /* work to do in syscall_trace_leave() */
6964 #define _TIF_WORK_SYSCALL_EXIT (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6965 - _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
6966 + _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6967
6968 /* work to do on interrupt/exception return */
6969 #define _TIF_WORK_MASK \
6970 @@ -153,7 +158,7 @@ static inline struct thread_info *current_thread_info(void)
6971 /* work to do on any return to u-space */
6972 #define _TIF_ALLWORK_MASK (_TIF_NOHZ | _TIF_WORK_MASK | \
6973 _TIF_WORK_SYSCALL_EXIT | \
6974 - _TIF_SYSCALL_TRACEPOINT)
6975 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6976
6977 /*
6978 * We stash processor id into a COP0 register to retrieve it fast
6979 diff --git a/arch/mips/include/asm/uaccess.h b/arch/mips/include/asm/uaccess.h
6980 index b9ab717..3a15c28 100644
6981 --- a/arch/mips/include/asm/uaccess.h
6982 +++ b/arch/mips/include/asm/uaccess.h
6983 @@ -130,6 +130,7 @@ extern u64 __ua_limit;
6984 __ok == 0; \
6985 })
6986
6987 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
6988 #define access_ok(type, addr, size) \
6989 likely(__access_ok((addr), (size), __access_mask))
6990
6991 @@ -301,7 +302,8 @@ do { \
6992 __get_kernel_common((x), size, __gu_ptr); \
6993 else \
6994 __get_user_common((x), size, __gu_ptr); \
6995 - } \
6996 + } else \
6997 + (x) = 0; \
6998 \
6999 __gu_err; \
7000 })
7001 @@ -316,6 +318,7 @@ do { \
7002 " .insn \n" \
7003 " .section .fixup,\"ax\" \n" \
7004 "3: li %0, %4 \n" \
7005 + " move %1, $0 \n" \
7006 " j 2b \n" \
7007 " .previous \n" \
7008 " .section __ex_table,\"a\" \n" \
7009 @@ -630,6 +633,7 @@ do { \
7010 " .insn \n" \
7011 " .section .fixup,\"ax\" \n" \
7012 "3: li %0, %4 \n" \
7013 + " move %1, $0 \n" \
7014 " j 2b \n" \
7015 " .previous \n" \
7016 " .section __ex_table,\"a\" \n" \
7017 diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
7018 index 1188e00..41cf144 100644
7019 --- a/arch/mips/kernel/binfmt_elfn32.c
7020 +++ b/arch/mips/kernel/binfmt_elfn32.c
7021 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
7022 #undef ELF_ET_DYN_BASE
7023 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
7024
7025 +#ifdef CONFIG_PAX_ASLR
7026 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
7027 +
7028 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
7029 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
7030 +#endif
7031 +
7032 #include <asm/processor.h>
7033 #include <linux/module.h>
7034 #include <linux/elfcore.h>
7035 diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
7036 index 9287678..f870e47 100644
7037 --- a/arch/mips/kernel/binfmt_elfo32.c
7038 +++ b/arch/mips/kernel/binfmt_elfo32.c
7039 @@ -70,6 +70,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
7040 #undef ELF_ET_DYN_BASE
7041 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
7042
7043 +#ifdef CONFIG_PAX_ASLR
7044 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
7045 +
7046 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
7047 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
7048 +#endif
7049 +
7050 #include <asm/processor.h>
7051
7052 #include <linux/module.h>
7053 diff --git a/arch/mips/kernel/i8259.c b/arch/mips/kernel/i8259.c
7054 index 50b3648..c2f3cec 100644
7055 --- a/arch/mips/kernel/i8259.c
7056 +++ b/arch/mips/kernel/i8259.c
7057 @@ -201,7 +201,7 @@ spurious_8259A_irq:
7058 printk(KERN_DEBUG "spurious 8259A interrupt: IRQ%d.\n", irq);
7059 spurious_irq_mask |= irqmask;
7060 }
7061 - atomic_inc(&irq_err_count);
7062 + atomic_inc_unchecked(&irq_err_count);
7063 /*
7064 * Theoretically we do not have to handle this IRQ,
7065 * but in Linux this does not cause problems and is
7066 diff --git a/arch/mips/kernel/irq-gt641xx.c b/arch/mips/kernel/irq-gt641xx.c
7067 index 44a1f79..2bd6aa3 100644
7068 --- a/arch/mips/kernel/irq-gt641xx.c
7069 +++ b/arch/mips/kernel/irq-gt641xx.c
7070 @@ -110,7 +110,7 @@ void gt641xx_irq_dispatch(void)
7071 }
7072 }
7073
7074 - atomic_inc(&irq_err_count);
7075 + atomic_inc_unchecked(&irq_err_count);
7076 }
7077
7078 void __init gt641xx_irq_init(void)
7079 diff --git a/arch/mips/kernel/irq.c b/arch/mips/kernel/irq.c
7080 index d2bfbc2..a8eacd2 100644
7081 --- a/arch/mips/kernel/irq.c
7082 +++ b/arch/mips/kernel/irq.c
7083 @@ -76,17 +76,17 @@ void ack_bad_irq(unsigned int irq)
7084 printk("unexpected IRQ # %d\n", irq);
7085 }
7086
7087 -atomic_t irq_err_count;
7088 +atomic_unchecked_t irq_err_count;
7089
7090 int arch_show_interrupts(struct seq_file *p, int prec)
7091 {
7092 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
7093 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
7094 return 0;
7095 }
7096
7097 asmlinkage void spurious_interrupt(void)
7098 {
7099 - atomic_inc(&irq_err_count);
7100 + atomic_inc_unchecked(&irq_err_count);
7101 }
7102
7103 void __init init_IRQ(void)
7104 @@ -109,7 +109,10 @@ void __init init_IRQ(void)
7105 #endif
7106 }
7107
7108 +
7109 #ifdef DEBUG_STACKOVERFLOW
7110 +extern void gr_handle_kernel_exploit(void);
7111 +
7112 static inline void check_stack_overflow(void)
7113 {
7114 unsigned long sp;
7115 @@ -125,6 +128,7 @@ static inline void check_stack_overflow(void)
7116 printk("do_IRQ: stack overflow: %ld\n",
7117 sp - sizeof(struct thread_info));
7118 dump_stack();
7119 + gr_handle_kernel_exploit();
7120 }
7121 }
7122 #else
7123 diff --git a/arch/mips/kernel/pm-cps.c b/arch/mips/kernel/pm-cps.c
7124 index 0614717..002fa43 100644
7125 --- a/arch/mips/kernel/pm-cps.c
7126 +++ b/arch/mips/kernel/pm-cps.c
7127 @@ -172,7 +172,7 @@ int cps_pm_enter_state(enum cps_pm_state state)
7128 nc_core_ready_count = nc_addr;
7129
7130 /* Ensure ready_count is zero-initialised before the assembly runs */
7131 - ACCESS_ONCE(*nc_core_ready_count) = 0;
7132 + ACCESS_ONCE_RW(*nc_core_ready_count) = 0;
7133 coupled_barrier(&per_cpu(pm_barrier, core), online);
7134
7135 /* Run the generated entry code */
7136 diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
7137 index 636b074..8fbb91f 100644
7138 --- a/arch/mips/kernel/process.c
7139 +++ b/arch/mips/kernel/process.c
7140 @@ -520,15 +520,3 @@ unsigned long get_wchan(struct task_struct *task)
7141 out:
7142 return pc;
7143 }
7144 -
7145 -/*
7146 - * Don't forget that the stack pointer must be aligned on a 8 bytes
7147 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
7148 - */
7149 -unsigned long arch_align_stack(unsigned long sp)
7150 -{
7151 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7152 - sp -= get_random_int() & ~PAGE_MASK;
7153 -
7154 - return sp & ALMASK;
7155 -}
7156 diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
7157 index 645b3c4..909c75a 100644
7158 --- a/arch/mips/kernel/ptrace.c
7159 +++ b/arch/mips/kernel/ptrace.c
7160 @@ -761,6 +761,10 @@ long arch_ptrace(struct task_struct *child, long request,
7161 return ret;
7162 }
7163
7164 +#ifdef CONFIG_GRKERNSEC_SETXID
7165 +extern void gr_delayed_cred_worker(void);
7166 +#endif
7167 +
7168 /*
7169 * Notification of system call entry/exit
7170 * - triggered by current->work.syscall_trace
7171 @@ -777,6 +781,11 @@ asmlinkage long syscall_trace_enter(struct pt_regs *regs, long syscall)
7172 tracehook_report_syscall_entry(regs))
7173 ret = -1;
7174
7175 +#ifdef CONFIG_GRKERNSEC_SETXID
7176 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
7177 + gr_delayed_cred_worker();
7178 +#endif
7179 +
7180 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
7181 trace_sys_enter(regs, regs->regs[2]);
7182
7183 diff --git a/arch/mips/kernel/reset.c b/arch/mips/kernel/reset.c
7184 index 07fc524..b9d7f28 100644
7185 --- a/arch/mips/kernel/reset.c
7186 +++ b/arch/mips/kernel/reset.c
7187 @@ -13,6 +13,7 @@
7188 #include <linux/reboot.h>
7189
7190 #include <asm/reboot.h>
7191 +#include <asm/bug.h>
7192
7193 /*
7194 * Urgs ... Too many MIPS machines to handle this in a generic way.
7195 @@ -29,16 +30,19 @@ void machine_restart(char *command)
7196 {
7197 if (_machine_restart)
7198 _machine_restart(command);
7199 + BUG();
7200 }
7201
7202 void machine_halt(void)
7203 {
7204 if (_machine_halt)
7205 _machine_halt();
7206 + BUG();
7207 }
7208
7209 void machine_power_off(void)
7210 {
7211 if (pm_power_off)
7212 pm_power_off();
7213 + BUG();
7214 }
7215 diff --git a/arch/mips/kernel/sync-r4k.c b/arch/mips/kernel/sync-r4k.c
7216 index 2242bdd..b284048 100644
7217 --- a/arch/mips/kernel/sync-r4k.c
7218 +++ b/arch/mips/kernel/sync-r4k.c
7219 @@ -18,8 +18,8 @@
7220 #include <asm/mipsregs.h>
7221
7222 static atomic_t count_start_flag = ATOMIC_INIT(0);
7223 -static atomic_t count_count_start = ATOMIC_INIT(0);
7224 -static atomic_t count_count_stop = ATOMIC_INIT(0);
7225 +static atomic_unchecked_t count_count_start = ATOMIC_INIT(0);
7226 +static atomic_unchecked_t count_count_stop = ATOMIC_INIT(0);
7227 static atomic_t count_reference = ATOMIC_INIT(0);
7228
7229 #define COUNTON 100
7230 @@ -58,13 +58,13 @@ void synchronise_count_master(int cpu)
7231
7232 for (i = 0; i < NR_LOOPS; i++) {
7233 /* slaves loop on '!= 2' */
7234 - while (atomic_read(&count_count_start) != 1)
7235 + while (atomic_read_unchecked(&count_count_start) != 1)
7236 mb();
7237 - atomic_set(&count_count_stop, 0);
7238 + atomic_set_unchecked(&count_count_stop, 0);
7239 smp_wmb();
7240
7241 /* this lets the slaves write their count register */
7242 - atomic_inc(&count_count_start);
7243 + atomic_inc_unchecked(&count_count_start);
7244
7245 /*
7246 * Everyone initialises count in the last loop:
7247 @@ -75,11 +75,11 @@ void synchronise_count_master(int cpu)
7248 /*
7249 * Wait for all slaves to leave the synchronization point:
7250 */
7251 - while (atomic_read(&count_count_stop) != 1)
7252 + while (atomic_read_unchecked(&count_count_stop) != 1)
7253 mb();
7254 - atomic_set(&count_count_start, 0);
7255 + atomic_set_unchecked(&count_count_start, 0);
7256 smp_wmb();
7257 - atomic_inc(&count_count_stop);
7258 + atomic_inc_unchecked(&count_count_stop);
7259 }
7260 /* Arrange for an interrupt in a short while */
7261 write_c0_compare(read_c0_count() + COUNTON);
7262 @@ -112,8 +112,8 @@ void synchronise_count_slave(int cpu)
7263 initcount = atomic_read(&count_reference);
7264
7265 for (i = 0; i < NR_LOOPS; i++) {
7266 - atomic_inc(&count_count_start);
7267 - while (atomic_read(&count_count_start) != 2)
7268 + atomic_inc_unchecked(&count_count_start);
7269 + while (atomic_read_unchecked(&count_count_start) != 2)
7270 mb();
7271
7272 /*
7273 @@ -122,8 +122,8 @@ void synchronise_count_slave(int cpu)
7274 if (i == NR_LOOPS-1)
7275 write_c0_count(initcount);
7276
7277 - atomic_inc(&count_count_stop);
7278 - while (atomic_read(&count_count_stop) != 2)
7279 + atomic_inc_unchecked(&count_count_stop);
7280 + while (atomic_read_unchecked(&count_count_stop) != 2)
7281 mb();
7282 }
7283 /* Arrange for an interrupt in a short while */
7284 diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
7285 index 22b19c2..c5cc8c4 100644
7286 --- a/arch/mips/kernel/traps.c
7287 +++ b/arch/mips/kernel/traps.c
7288 @@ -688,7 +688,18 @@ asmlinkage void do_ov(struct pt_regs *regs)
7289 siginfo_t info;
7290
7291 prev_state = exception_enter();
7292 - die_if_kernel("Integer overflow", regs);
7293 + if (unlikely(!user_mode(regs))) {
7294 +
7295 +#ifdef CONFIG_PAX_REFCOUNT
7296 + if (fixup_exception(regs)) {
7297 + pax_report_refcount_overflow(regs);
7298 + exception_exit(prev_state);
7299 + return;
7300 + }
7301 +#endif
7302 +
7303 + die("Integer overflow", regs);
7304 + }
7305
7306 info.si_code = FPE_INTOVF;
7307 info.si_signo = SIGFPE;
7308 diff --git a/arch/mips/kvm/mips.c b/arch/mips/kvm/mips.c
7309 index cd71141..e02c4df 100644
7310 --- a/arch/mips/kvm/mips.c
7311 +++ b/arch/mips/kvm/mips.c
7312 @@ -839,7 +839,7 @@ long kvm_arch_vm_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg)
7313 return r;
7314 }
7315
7316 -int kvm_arch_init(void *opaque)
7317 +int kvm_arch_init(const void *opaque)
7318 {
7319 if (kvm_mips_callbacks) {
7320 kvm_err("kvm: module already exists\n");
7321 diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
7322 index becc42b..9e43d4b 100644
7323 --- a/arch/mips/mm/fault.c
7324 +++ b/arch/mips/mm/fault.c
7325 @@ -28,6 +28,23 @@
7326 #include <asm/highmem.h> /* For VMALLOC_END */
7327 #include <linux/kdebug.h>
7328
7329 +#ifdef CONFIG_PAX_PAGEEXEC
7330 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7331 +{
7332 + unsigned long i;
7333 +
7334 + printk(KERN_ERR "PAX: bytes at PC: ");
7335 + for (i = 0; i < 5; i++) {
7336 + unsigned int c;
7337 + if (get_user(c, (unsigned int *)pc+i))
7338 + printk(KERN_CONT "???????? ");
7339 + else
7340 + printk(KERN_CONT "%08x ", c);
7341 + }
7342 + printk("\n");
7343 +}
7344 +#endif
7345 +
7346 /*
7347 * This routine handles page faults. It determines the address,
7348 * and the problem, and then passes it off to one of the appropriate
7349 @@ -199,6 +216,14 @@ bad_area:
7350 bad_area_nosemaphore:
7351 /* User mode accesses just cause a SIGSEGV */
7352 if (user_mode(regs)) {
7353 +
7354 +#ifdef CONFIG_PAX_PAGEEXEC
7355 + if (cpu_has_rixi && (mm->pax_flags & MF_PAX_PAGEEXEC) && !write && address == instruction_pointer(regs)) {
7356 + pax_report_fault(regs, (void *)address, (void *)user_stack_pointer(regs));
7357 + do_group_exit(SIGKILL);
7358 + }
7359 +#endif
7360 +
7361 tsk->thread.cp0_badvaddr = address;
7362 tsk->thread.error_code = write;
7363 #if 0
7364 diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
7365 index f1baadd..5472dca 100644
7366 --- a/arch/mips/mm/mmap.c
7367 +++ b/arch/mips/mm/mmap.c
7368 @@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7369 struct vm_area_struct *vma;
7370 unsigned long addr = addr0;
7371 int do_color_align;
7372 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7373 struct vm_unmapped_area_info info;
7374
7375 if (unlikely(len > TASK_SIZE))
7376 @@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7377 do_color_align = 1;
7378
7379 /* requesting a specific address */
7380 +
7381 +#ifdef CONFIG_PAX_RANDMMAP
7382 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
7383 +#endif
7384 +
7385 if (addr) {
7386 if (do_color_align)
7387 addr = COLOUR_ALIGN(addr, pgoff);
7388 @@ -91,14 +97,14 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7389 addr = PAGE_ALIGN(addr);
7390
7391 vma = find_vma(mm, addr);
7392 - if (TASK_SIZE - len >= addr &&
7393 - (!vma || addr + len <= vma->vm_start))
7394 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7395 return addr;
7396 }
7397
7398 info.length = len;
7399 info.align_mask = do_color_align ? (PAGE_MASK & shm_align_mask) : 0;
7400 info.align_offset = pgoff << PAGE_SHIFT;
7401 + info.threadstack_offset = offset;
7402
7403 if (dir == DOWN) {
7404 info.flags = VM_UNMAPPED_AREA_TOPDOWN;
7405 @@ -146,6 +152,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7406 {
7407 unsigned long random_factor = 0UL;
7408
7409 +#ifdef CONFIG_PAX_RANDMMAP
7410 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7411 +#endif
7412 +
7413 if (current->flags & PF_RANDOMIZE) {
7414 random_factor = get_random_int();
7415 random_factor = random_factor << PAGE_SHIFT;
7416 @@ -157,40 +167,25 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7417
7418 if (mmap_is_legacy()) {
7419 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
7420 +
7421 +#ifdef CONFIG_PAX_RANDMMAP
7422 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7423 + mm->mmap_base += mm->delta_mmap;
7424 +#endif
7425 +
7426 mm->get_unmapped_area = arch_get_unmapped_area;
7427 } else {
7428 mm->mmap_base = mmap_base(random_factor);
7429 +
7430 +#ifdef CONFIG_PAX_RANDMMAP
7431 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7432 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7433 +#endif
7434 +
7435 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7436 }
7437 }
7438
7439 -static inline unsigned long brk_rnd(void)
7440 -{
7441 - unsigned long rnd = get_random_int();
7442 -
7443 - rnd = rnd << PAGE_SHIFT;
7444 - /* 8MB for 32bit, 256MB for 64bit */
7445 - if (TASK_IS_32BIT_ADDR)
7446 - rnd = rnd & 0x7ffffful;
7447 - else
7448 - rnd = rnd & 0xffffffful;
7449 -
7450 - return rnd;
7451 -}
7452 -
7453 -unsigned long arch_randomize_brk(struct mm_struct *mm)
7454 -{
7455 - unsigned long base = mm->brk;
7456 - unsigned long ret;
7457 -
7458 - ret = PAGE_ALIGN(base + brk_rnd());
7459 -
7460 - if (ret < mm->brk)
7461 - return mm->brk;
7462 -
7463 - return ret;
7464 -}
7465 -
7466 int __virt_addr_valid(const volatile void *kaddr)
7467 {
7468 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
7469 diff --git a/arch/mips/net/bpf_jit.c b/arch/mips/net/bpf_jit.c
7470 index 1588716..42cfa97 100644
7471 --- a/arch/mips/net/bpf_jit.c
7472 +++ b/arch/mips/net/bpf_jit.c
7473 @@ -1428,5 +1428,6 @@ void bpf_jit_free(struct bpf_prog *fp)
7474 {
7475 if (fp->jited)
7476 module_free(NULL, fp->bpf_func);
7477 - kfree(fp);
7478 +
7479 + bpf_prog_unlock_free(fp);
7480 }
7481 diff --git a/arch/mips/pci/pci-octeon.c b/arch/mips/pci/pci-octeon.c
7482 index 59cccd9..f39ac2f 100644
7483 --- a/arch/mips/pci/pci-octeon.c
7484 +++ b/arch/mips/pci/pci-octeon.c
7485 @@ -327,8 +327,8 @@ static int octeon_write_config(struct pci_bus *bus, unsigned int devfn,
7486
7487
7488 static struct pci_ops octeon_pci_ops = {
7489 - octeon_read_config,
7490 - octeon_write_config,
7491 + .read = octeon_read_config,
7492 + .write = octeon_write_config,
7493 };
7494
7495 static struct resource octeon_pci_mem_resource = {
7496 diff --git a/arch/mips/pci/pcie-octeon.c b/arch/mips/pci/pcie-octeon.c
7497 index 5e36c33..eb4a17b 100644
7498 --- a/arch/mips/pci/pcie-octeon.c
7499 +++ b/arch/mips/pci/pcie-octeon.c
7500 @@ -1792,8 +1792,8 @@ static int octeon_dummy_write_config(struct pci_bus *bus, unsigned int devfn,
7501 }
7502
7503 static struct pci_ops octeon_pcie0_ops = {
7504 - octeon_pcie0_read_config,
7505 - octeon_pcie0_write_config,
7506 + .read = octeon_pcie0_read_config,
7507 + .write = octeon_pcie0_write_config,
7508 };
7509
7510 static struct resource octeon_pcie0_mem_resource = {
7511 @@ -1813,8 +1813,8 @@ static struct pci_controller octeon_pcie0_controller = {
7512 };
7513
7514 static struct pci_ops octeon_pcie1_ops = {
7515 - octeon_pcie1_read_config,
7516 - octeon_pcie1_write_config,
7517 + .read = octeon_pcie1_read_config,
7518 + .write = octeon_pcie1_write_config,
7519 };
7520
7521 static struct resource octeon_pcie1_mem_resource = {
7522 @@ -1834,8 +1834,8 @@ static struct pci_controller octeon_pcie1_controller = {
7523 };
7524
7525 static struct pci_ops octeon_dummy_ops = {
7526 - octeon_dummy_read_config,
7527 - octeon_dummy_write_config,
7528 + .read = octeon_dummy_read_config,
7529 + .write = octeon_dummy_write_config,
7530 };
7531
7532 static struct resource octeon_dummy_mem_resource = {
7533 diff --git a/arch/mips/sgi-ip27/ip27-nmi.c b/arch/mips/sgi-ip27/ip27-nmi.c
7534 index a2358b4..7cead4f 100644
7535 --- a/arch/mips/sgi-ip27/ip27-nmi.c
7536 +++ b/arch/mips/sgi-ip27/ip27-nmi.c
7537 @@ -187,9 +187,9 @@ void
7538 cont_nmi_dump(void)
7539 {
7540 #ifndef REAL_NMI_SIGNAL
7541 - static atomic_t nmied_cpus = ATOMIC_INIT(0);
7542 + static atomic_unchecked_t nmied_cpus = ATOMIC_INIT(0);
7543
7544 - atomic_inc(&nmied_cpus);
7545 + atomic_inc_unchecked(&nmied_cpus);
7546 #endif
7547 /*
7548 * Only allow 1 cpu to proceed
7549 @@ -233,7 +233,7 @@ cont_nmi_dump(void)
7550 udelay(10000);
7551 }
7552 #else
7553 - while (atomic_read(&nmied_cpus) != num_online_cpus());
7554 + while (atomic_read_unchecked(&nmied_cpus) != num_online_cpus());
7555 #endif
7556
7557 /*
7558 diff --git a/arch/mips/sni/rm200.c b/arch/mips/sni/rm200.c
7559 index a046b30..6799527 100644
7560 --- a/arch/mips/sni/rm200.c
7561 +++ b/arch/mips/sni/rm200.c
7562 @@ -270,7 +270,7 @@ spurious_8259A_irq:
7563 "spurious RM200 8259A interrupt: IRQ%d.\n", irq);
7564 spurious_irq_mask |= irqmask;
7565 }
7566 - atomic_inc(&irq_err_count);
7567 + atomic_inc_unchecked(&irq_err_count);
7568 /*
7569 * Theoretically we do not have to handle this IRQ,
7570 * but in Linux this does not cause problems and is
7571 diff --git a/arch/mips/vr41xx/common/icu.c b/arch/mips/vr41xx/common/icu.c
7572 index 41e873b..34d33a7 100644
7573 --- a/arch/mips/vr41xx/common/icu.c
7574 +++ b/arch/mips/vr41xx/common/icu.c
7575 @@ -653,7 +653,7 @@ static int icu_get_irq(unsigned int irq)
7576
7577 printk(KERN_ERR "spurious ICU interrupt: %04x,%04x\n", pend1, pend2);
7578
7579 - atomic_inc(&irq_err_count);
7580 + atomic_inc_unchecked(&irq_err_count);
7581
7582 return -1;
7583 }
7584 diff --git a/arch/mips/vr41xx/common/irq.c b/arch/mips/vr41xx/common/irq.c
7585 index ae0e4ee..e8f0692 100644
7586 --- a/arch/mips/vr41xx/common/irq.c
7587 +++ b/arch/mips/vr41xx/common/irq.c
7588 @@ -64,7 +64,7 @@ static void irq_dispatch(unsigned int irq)
7589 irq_cascade_t *cascade;
7590
7591 if (irq >= NR_IRQS) {
7592 - atomic_inc(&irq_err_count);
7593 + atomic_inc_unchecked(&irq_err_count);
7594 return;
7595 }
7596
7597 @@ -84,7 +84,7 @@ static void irq_dispatch(unsigned int irq)
7598 ret = cascade->get_irq(irq);
7599 irq = ret;
7600 if (ret < 0)
7601 - atomic_inc(&irq_err_count);
7602 + atomic_inc_unchecked(&irq_err_count);
7603 else
7604 irq_dispatch(irq);
7605 if (!irqd_irq_disabled(idata) && chip->irq_unmask)
7606 diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7607 index 967d144..db12197 100644
7608 --- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
7609 +++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7610 @@ -11,12 +11,14 @@
7611 #ifndef _ASM_PROC_CACHE_H
7612 #define _ASM_PROC_CACHE_H
7613
7614 +#include <linux/const.h>
7615 +
7616 /* L1 cache */
7617
7618 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7619 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
7620 -#define L1_CACHE_BYTES 16 /* bytes per entry */
7621 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
7622 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7623 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
7624
7625 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7626 diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7627 index bcb5df2..84fabd2 100644
7628 --- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7629 +++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7630 @@ -16,13 +16,15 @@
7631 #ifndef _ASM_PROC_CACHE_H
7632 #define _ASM_PROC_CACHE_H
7633
7634 +#include <linux/const.h>
7635 +
7636 /*
7637 * L1 cache
7638 */
7639 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7640 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
7641 -#define L1_CACHE_BYTES 32 /* bytes per entry */
7642 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
7643 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7644 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
7645
7646 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7647 diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
7648 index 4ce7a01..449202a 100644
7649 --- a/arch/openrisc/include/asm/cache.h
7650 +++ b/arch/openrisc/include/asm/cache.h
7651 @@ -19,11 +19,13 @@
7652 #ifndef __ASM_OPENRISC_CACHE_H
7653 #define __ASM_OPENRISC_CACHE_H
7654
7655 +#include <linux/const.h>
7656 +
7657 /* FIXME: How can we replace these with values from the CPU...
7658 * they shouldn't be hard-coded!
7659 */
7660
7661 -#define L1_CACHE_BYTES 16
7662 #define L1_CACHE_SHIFT 4
7663 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7664
7665 #endif /* __ASM_OPENRISC_CACHE_H */
7666 diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
7667 index 0be2db2..1b0f26d 100644
7668 --- a/arch/parisc/include/asm/atomic.h
7669 +++ b/arch/parisc/include/asm/atomic.h
7670 @@ -248,6 +248,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
7671 return dec;
7672 }
7673
7674 +#define atomic64_read_unchecked(v) atomic64_read(v)
7675 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7676 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7677 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7678 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7679 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
7680 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7681 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
7682 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7683 +
7684 #endif /* !CONFIG_64BIT */
7685
7686
7687 diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
7688 index 47f11c7..3420df2 100644
7689 --- a/arch/parisc/include/asm/cache.h
7690 +++ b/arch/parisc/include/asm/cache.h
7691 @@ -5,6 +5,7 @@
7692 #ifndef __ARCH_PARISC_CACHE_H
7693 #define __ARCH_PARISC_CACHE_H
7694
7695 +#include <linux/const.h>
7696
7697 /*
7698 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
7699 @@ -15,13 +16,13 @@
7700 * just ruin performance.
7701 */
7702 #ifdef CONFIG_PA20
7703 -#define L1_CACHE_BYTES 64
7704 #define L1_CACHE_SHIFT 6
7705 #else
7706 -#define L1_CACHE_BYTES 32
7707 #define L1_CACHE_SHIFT 5
7708 #endif
7709
7710 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7711 +
7712 #ifndef __ASSEMBLY__
7713
7714 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7715 diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
7716 index 3391d06..c23a2cc 100644
7717 --- a/arch/parisc/include/asm/elf.h
7718 +++ b/arch/parisc/include/asm/elf.h
7719 @@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
7720
7721 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
7722
7723 +#ifdef CONFIG_PAX_ASLR
7724 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
7725 +
7726 +#define PAX_DELTA_MMAP_LEN 16
7727 +#define PAX_DELTA_STACK_LEN 16
7728 +#endif
7729 +
7730 /* This yields a mask that user programs can use to figure out what
7731 instruction set this CPU supports. This could be done in user space,
7732 but it's not easy, and we've already done it here. */
7733 diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
7734 index f213f5b..0af3e8e 100644
7735 --- a/arch/parisc/include/asm/pgalloc.h
7736 +++ b/arch/parisc/include/asm/pgalloc.h
7737 @@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7738 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
7739 }
7740
7741 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7742 +{
7743 + pgd_populate(mm, pgd, pmd);
7744 +}
7745 +
7746 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
7747 {
7748 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
7749 @@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
7750 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
7751 #define pmd_free(mm, x) do { } while (0)
7752 #define pgd_populate(mm, pmd, pte) BUG()
7753 +#define pgd_populate_kernel(mm, pmd, pte) BUG()
7754
7755 #endif
7756
7757 diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
7758 index 22b89d1..ce34230 100644
7759 --- a/arch/parisc/include/asm/pgtable.h
7760 +++ b/arch/parisc/include/asm/pgtable.h
7761 @@ -223,6 +223,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
7762 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
7763 #define PAGE_COPY PAGE_EXECREAD
7764 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
7765 +
7766 +#ifdef CONFIG_PAX_PAGEEXEC
7767 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
7768 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7769 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7770 +#else
7771 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
7772 +# define PAGE_COPY_NOEXEC PAGE_COPY
7773 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
7774 +#endif
7775 +
7776 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
7777 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
7778 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
7779 diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
7780 index 4006964..fcb3cc2 100644
7781 --- a/arch/parisc/include/asm/uaccess.h
7782 +++ b/arch/parisc/include/asm/uaccess.h
7783 @@ -246,10 +246,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
7784 const void __user *from,
7785 unsigned long n)
7786 {
7787 - int sz = __compiletime_object_size(to);
7788 + size_t sz = __compiletime_object_size(to);
7789 int ret = -EFAULT;
7790
7791 - if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
7792 + if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
7793 ret = __copy_from_user(to, from, n);
7794 else
7795 copy_from_user_overflow();
7796 diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
7797 index 50dfafc..b9fc230 100644
7798 --- a/arch/parisc/kernel/module.c
7799 +++ b/arch/parisc/kernel/module.c
7800 @@ -98,16 +98,38 @@
7801
7802 /* three functions to determine where in the module core
7803 * or init pieces the location is */
7804 +static inline int in_init_rx(struct module *me, void *loc)
7805 +{
7806 + return (loc >= me->module_init_rx &&
7807 + loc < (me->module_init_rx + me->init_size_rx));
7808 +}
7809 +
7810 +static inline int in_init_rw(struct module *me, void *loc)
7811 +{
7812 + return (loc >= me->module_init_rw &&
7813 + loc < (me->module_init_rw + me->init_size_rw));
7814 +}
7815 +
7816 static inline int in_init(struct module *me, void *loc)
7817 {
7818 - return (loc >= me->module_init &&
7819 - loc <= (me->module_init + me->init_size));
7820 + return in_init_rx(me, loc) || in_init_rw(me, loc);
7821 +}
7822 +
7823 +static inline int in_core_rx(struct module *me, void *loc)
7824 +{
7825 + return (loc >= me->module_core_rx &&
7826 + loc < (me->module_core_rx + me->core_size_rx));
7827 +}
7828 +
7829 +static inline int in_core_rw(struct module *me, void *loc)
7830 +{
7831 + return (loc >= me->module_core_rw &&
7832 + loc < (me->module_core_rw + me->core_size_rw));
7833 }
7834
7835 static inline int in_core(struct module *me, void *loc)
7836 {
7837 - return (loc >= me->module_core &&
7838 - loc <= (me->module_core + me->core_size));
7839 + return in_core_rx(me, loc) || in_core_rw(me, loc);
7840 }
7841
7842 static inline int in_local(struct module *me, void *loc)
7843 @@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
7844 }
7845
7846 /* align things a bit */
7847 - me->core_size = ALIGN(me->core_size, 16);
7848 - me->arch.got_offset = me->core_size;
7849 - me->core_size += gots * sizeof(struct got_entry);
7850 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
7851 + me->arch.got_offset = me->core_size_rw;
7852 + me->core_size_rw += gots * sizeof(struct got_entry);
7853
7854 - me->core_size = ALIGN(me->core_size, 16);
7855 - me->arch.fdesc_offset = me->core_size;
7856 - me->core_size += fdescs * sizeof(Elf_Fdesc);
7857 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
7858 + me->arch.fdesc_offset = me->core_size_rw;
7859 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
7860
7861 me->arch.got_max = gots;
7862 me->arch.fdesc_max = fdescs;
7863 @@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7864
7865 BUG_ON(value == 0);
7866
7867 - got = me->module_core + me->arch.got_offset;
7868 + got = me->module_core_rw + me->arch.got_offset;
7869 for (i = 0; got[i].addr; i++)
7870 if (got[i].addr == value)
7871 goto out;
7872 @@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7873 #ifdef CONFIG_64BIT
7874 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7875 {
7876 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
7877 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
7878
7879 if (!value) {
7880 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
7881 @@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7882
7883 /* Create new one */
7884 fdesc->addr = value;
7885 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7886 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7887 return (Elf_Addr)fdesc;
7888 }
7889 #endif /* CONFIG_64BIT */
7890 @@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
7891
7892 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
7893 end = table + sechdrs[me->arch.unwind_section].sh_size;
7894 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7895 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7896
7897 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
7898 me->arch.unwind_section, table, end, gp);
7899 diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
7900 index e1ffea2..46ed66e 100644
7901 --- a/arch/parisc/kernel/sys_parisc.c
7902 +++ b/arch/parisc/kernel/sys_parisc.c
7903 @@ -89,6 +89,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7904 unsigned long task_size = TASK_SIZE;
7905 int do_color_align, last_mmap;
7906 struct vm_unmapped_area_info info;
7907 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7908
7909 if (len > task_size)
7910 return -ENOMEM;
7911 @@ -106,6 +107,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7912 goto found_addr;
7913 }
7914
7915 +#ifdef CONFIG_PAX_RANDMMAP
7916 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7917 +#endif
7918 +
7919 if (addr) {
7920 if (do_color_align && last_mmap)
7921 addr = COLOR_ALIGN(addr, last_mmap, pgoff);
7922 @@ -124,6 +129,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7923 info.high_limit = mmap_upper_limit();
7924 info.align_mask = last_mmap ? (PAGE_MASK & (SHM_COLOUR - 1)) : 0;
7925 info.align_offset = shared_align_offset(last_mmap, pgoff);
7926 + info.threadstack_offset = offset;
7927 addr = vm_unmapped_area(&info);
7928
7929 found_addr:
7930 @@ -143,6 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7931 unsigned long addr = addr0;
7932 int do_color_align, last_mmap;
7933 struct vm_unmapped_area_info info;
7934 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7935
7936 #ifdef CONFIG_64BIT
7937 /* This should only ever run for 32-bit processes. */
7938 @@ -167,6 +174,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7939 }
7940
7941 /* requesting a specific address */
7942 +#ifdef CONFIG_PAX_RANDMMAP
7943 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7944 +#endif
7945 +
7946 if (addr) {
7947 if (do_color_align && last_mmap)
7948 addr = COLOR_ALIGN(addr, last_mmap, pgoff);
7949 @@ -184,6 +195,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7950 info.high_limit = mm->mmap_base;
7951 info.align_mask = last_mmap ? (PAGE_MASK & (SHM_COLOUR - 1)) : 0;
7952 info.align_offset = shared_align_offset(last_mmap, pgoff);
7953 + info.threadstack_offset = offset;
7954 addr = vm_unmapped_area(&info);
7955 if (!(addr & ~PAGE_MASK))
7956 goto found_addr;
7957 @@ -249,6 +261,13 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7958 mm->mmap_legacy_base = mmap_legacy_base();
7959 mm->mmap_base = mmap_upper_limit();
7960
7961 +#ifdef CONFIG_PAX_RANDMMAP
7962 + if (mm->pax_flags & MF_PAX_RANDMMAP) {
7963 + mm->mmap_legacy_base += mm->delta_mmap;
7964 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7965 + }
7966 +#endif
7967 +
7968 if (mmap_is_legacy()) {
7969 mm->mmap_base = mm->mmap_legacy_base;
7970 mm->get_unmapped_area = arch_get_unmapped_area;
7971 diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
7972 index 47ee620..1107387 100644
7973 --- a/arch/parisc/kernel/traps.c
7974 +++ b/arch/parisc/kernel/traps.c
7975 @@ -726,9 +726,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
7976
7977 down_read(&current->mm->mmap_sem);
7978 vma = find_vma(current->mm,regs->iaoq[0]);
7979 - if (vma && (regs->iaoq[0] >= vma->vm_start)
7980 - && (vma->vm_flags & VM_EXEC)) {
7981 -
7982 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
7983 fault_address = regs->iaoq[0];
7984 fault_space = regs->iasq[0];
7985
7986 diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
7987 index 3ca9c11..d163ef7 100644
7988 --- a/arch/parisc/mm/fault.c
7989 +++ b/arch/parisc/mm/fault.c
7990 @@ -15,6 +15,7 @@
7991 #include <linux/sched.h>
7992 #include <linux/interrupt.h>
7993 #include <linux/module.h>
7994 +#include <linux/unistd.h>
7995
7996 #include <asm/uaccess.h>
7997 #include <asm/traps.h>
7998 @@ -50,7 +51,7 @@ int show_unhandled_signals = 1;
7999 static unsigned long
8000 parisc_acctyp(unsigned long code, unsigned int inst)
8001 {
8002 - if (code == 6 || code == 16)
8003 + if (code == 6 || code == 7 || code == 16)
8004 return VM_EXEC;
8005
8006 switch (inst & 0xf0000000) {
8007 @@ -136,6 +137,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
8008 }
8009 #endif
8010
8011 +#ifdef CONFIG_PAX_PAGEEXEC
8012 +/*
8013 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
8014 + *
8015 + * returns 1 when task should be killed
8016 + * 2 when rt_sigreturn trampoline was detected
8017 + * 3 when unpatched PLT trampoline was detected
8018 + */
8019 +static int pax_handle_fetch_fault(struct pt_regs *regs)
8020 +{
8021 +
8022 +#ifdef CONFIG_PAX_EMUPLT
8023 + int err;
8024 +
8025 + do { /* PaX: unpatched PLT emulation */
8026 + unsigned int bl, depwi;
8027 +
8028 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
8029 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
8030 +
8031 + if (err)
8032 + break;
8033 +
8034 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
8035 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
8036 +
8037 + err = get_user(ldw, (unsigned int *)addr);
8038 + err |= get_user(bv, (unsigned int *)(addr+4));
8039 + err |= get_user(ldw2, (unsigned int *)(addr+8));
8040 +
8041 + if (err)
8042 + break;
8043 +
8044 + if (ldw == 0x0E801096U &&
8045 + bv == 0xEAC0C000U &&
8046 + ldw2 == 0x0E881095U)
8047 + {
8048 + unsigned int resolver, map;
8049 +
8050 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
8051 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
8052 + if (err)
8053 + break;
8054 +
8055 + regs->gr[20] = instruction_pointer(regs)+8;
8056 + regs->gr[21] = map;
8057 + regs->gr[22] = resolver;
8058 + regs->iaoq[0] = resolver | 3UL;
8059 + regs->iaoq[1] = regs->iaoq[0] + 4;
8060 + return 3;
8061 + }
8062 + }
8063 + } while (0);
8064 +#endif
8065 +
8066 +#ifdef CONFIG_PAX_EMUTRAMP
8067 +
8068 +#ifndef CONFIG_PAX_EMUSIGRT
8069 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
8070 + return 1;
8071 +#endif
8072 +
8073 + do { /* PaX: rt_sigreturn emulation */
8074 + unsigned int ldi1, ldi2, bel, nop;
8075 +
8076 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
8077 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
8078 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
8079 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
8080 +
8081 + if (err)
8082 + break;
8083 +
8084 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
8085 + ldi2 == 0x3414015AU &&
8086 + bel == 0xE4008200U &&
8087 + nop == 0x08000240U)
8088 + {
8089 + regs->gr[25] = (ldi1 & 2) >> 1;
8090 + regs->gr[20] = __NR_rt_sigreturn;
8091 + regs->gr[31] = regs->iaoq[1] + 16;
8092 + regs->sr[0] = regs->iasq[1];
8093 + regs->iaoq[0] = 0x100UL;
8094 + regs->iaoq[1] = regs->iaoq[0] + 4;
8095 + regs->iasq[0] = regs->sr[2];
8096 + regs->iasq[1] = regs->sr[2];
8097 + return 2;
8098 + }
8099 + } while (0);
8100 +#endif
8101 +
8102 + return 1;
8103 +}
8104 +
8105 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
8106 +{
8107 + unsigned long i;
8108 +
8109 + printk(KERN_ERR "PAX: bytes at PC: ");
8110 + for (i = 0; i < 5; i++) {
8111 + unsigned int c;
8112 + if (get_user(c, (unsigned int *)pc+i))
8113 + printk(KERN_CONT "???????? ");
8114 + else
8115 + printk(KERN_CONT "%08x ", c);
8116 + }
8117 + printk("\n");
8118 +}
8119 +#endif
8120 +
8121 int fixup_exception(struct pt_regs *regs)
8122 {
8123 const struct exception_table_entry *fix;
8124 @@ -234,8 +345,33 @@ retry:
8125
8126 good_area:
8127
8128 - if ((vma->vm_flags & acc_type) != acc_type)
8129 + if ((vma->vm_flags & acc_type) != acc_type) {
8130 +
8131 +#ifdef CONFIG_PAX_PAGEEXEC
8132 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
8133 + (address & ~3UL) == instruction_pointer(regs))
8134 + {
8135 + up_read(&mm->mmap_sem);
8136 + switch (pax_handle_fetch_fault(regs)) {
8137 +
8138 +#ifdef CONFIG_PAX_EMUPLT
8139 + case 3:
8140 + return;
8141 +#endif
8142 +
8143 +#ifdef CONFIG_PAX_EMUTRAMP
8144 + case 2:
8145 + return;
8146 +#endif
8147 +
8148 + }
8149 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
8150 + do_group_exit(SIGKILL);
8151 + }
8152 +#endif
8153 +
8154 goto bad_area;
8155 + }
8156
8157 /*
8158 * If for any reason at all we couldn't handle the fault, make
8159 diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
8160 index 4bc7b62..107e0b2 100644
8161 --- a/arch/powerpc/Kconfig
8162 +++ b/arch/powerpc/Kconfig
8163 @@ -399,6 +399,7 @@ config PPC64_SUPPORTS_MEMORY_FAILURE
8164 config KEXEC
8165 bool "kexec system call"
8166 depends on (PPC_BOOK3S || FSL_BOOKE || (44x && !SMP))
8167 + depends on !GRKERNSEC_KMEM
8168 help
8169 kexec is a system call that implements the ability to shutdown your
8170 current kernel, and to start another kernel. It is like a reboot
8171 diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
8172 index 28992d0..bbbff7e 100644
8173 --- a/arch/powerpc/include/asm/atomic.h
8174 +++ b/arch/powerpc/include/asm/atomic.h
8175 @@ -12,6 +12,11 @@
8176
8177 #define ATOMIC_INIT(i) { (i) }
8178
8179 +#define _ASM_EXTABLE(from, to) \
8180 +" .section __ex_table,\"a\"\n" \
8181 + PPC_LONG" " #from ", " #to"\n" \
8182 +" .previous\n"
8183 +
8184 static __inline__ int atomic_read(const atomic_t *v)
8185 {
8186 int t;
8187 @@ -21,16 +26,61 @@ static __inline__ int atomic_read(const atomic_t *v)
8188 return t;
8189 }
8190
8191 +static __inline__ int atomic_read_unchecked(const atomic_unchecked_t *v)
8192 +{
8193 + int t;
8194 +
8195 + __asm__ __volatile__("lwz%U1%X1 %0,%1" : "=r"(t) : "m"(v->counter));
8196 +
8197 + return t;
8198 +}
8199 +
8200 static __inline__ void atomic_set(atomic_t *v, int i)
8201 {
8202 __asm__ __volatile__("stw%U0%X0 %1,%0" : "=m"(v->counter) : "r"(i));
8203 }
8204
8205 +static __inline__ void atomic_set_unchecked(atomic_unchecked_t *v, int i)
8206 +{
8207 + __asm__ __volatile__("stw%U0%X0 %1,%0" : "=m"(v->counter) : "r"(i));
8208 +}
8209 +
8210 static __inline__ void atomic_add(int a, atomic_t *v)
8211 {
8212 int t;
8213
8214 __asm__ __volatile__(
8215 +"1: lwarx %0,0,%3 # atomic_add\n"
8216 +
8217 +#ifdef CONFIG_PAX_REFCOUNT
8218 +" mcrxr cr0\n"
8219 +" addo. %0,%2,%0\n"
8220 +" bf 4*cr0+so, 3f\n"
8221 +"2:.long " "0x00c00b00""\n"
8222 +#else
8223 +" add %0,%2,%0\n"
8224 +#endif
8225 +
8226 +"3:\n"
8227 + PPC405_ERR77(0,%3)
8228 +" stwcx. %0,0,%3 \n\
8229 + bne- 1b"
8230 +
8231 +#ifdef CONFIG_PAX_REFCOUNT
8232 +"\n4:\n"
8233 + _ASM_EXTABLE(2b, 4b)
8234 +#endif
8235 +
8236 + : "=&r" (t), "+m" (v->counter)
8237 + : "r" (a), "r" (&v->counter)
8238 + : "cc");
8239 +}
8240 +
8241 +static __inline__ void atomic_add_unchecked(int a, atomic_unchecked_t *v)
8242 +{
8243 + int t;
8244 +
8245 + __asm__ __volatile__(
8246 "1: lwarx %0,0,%3 # atomic_add\n\
8247 add %0,%2,%0\n"
8248 PPC405_ERR77(0,%3)
8249 @@ -41,12 +91,49 @@ static __inline__ void atomic_add(int a, atomic_t *v)
8250 : "cc");
8251 }
8252
8253 +/* Same as atomic_add but return the value */
8254 static __inline__ int atomic_add_return(int a, atomic_t *v)
8255 {
8256 int t;
8257
8258 __asm__ __volatile__(
8259 PPC_ATOMIC_ENTRY_BARRIER
8260 +"1: lwarx %0,0,%2 # atomic_add_return\n"
8261 +
8262 +#ifdef CONFIG_PAX_REFCOUNT
8263 +" mcrxr cr0\n"
8264 +" addo. %0,%1,%0\n"
8265 +" bf 4*cr0+so, 3f\n"
8266 +"2:.long " "0x00c00b00""\n"
8267 +#else
8268 +" add %0,%1,%0\n"
8269 +#endif
8270 +
8271 +"3:\n"
8272 + PPC405_ERR77(0,%2)
8273 +" stwcx. %0,0,%2 \n\
8274 + bne- 1b\n"
8275 +"4:"
8276 +
8277 +#ifdef CONFIG_PAX_REFCOUNT
8278 + _ASM_EXTABLE(2b, 4b)
8279 +#endif
8280 +
8281 + PPC_ATOMIC_EXIT_BARRIER
8282 + : "=&r" (t)
8283 + : "r" (a), "r" (&v->counter)
8284 + : "cc", "memory");
8285 +
8286 + return t;
8287 +}
8288 +
8289 +/* Same as atomic_add_unchecked but return the value */
8290 +static __inline__ int atomic_add_return_unchecked(int a, atomic_unchecked_t *v)
8291 +{
8292 + int t;
8293 +
8294 + __asm__ __volatile__(
8295 + PPC_ATOMIC_ENTRY_BARRIER
8296 "1: lwarx %0,0,%2 # atomic_add_return\n\
8297 add %0,%1,%0\n"
8298 PPC405_ERR77(0,%2)
8299 @@ -67,6 +154,37 @@ static __inline__ void atomic_sub(int a, atomic_t *v)
8300 int t;
8301
8302 __asm__ __volatile__(
8303 +"1: lwarx %0,0,%3 # atomic_sub\n"
8304 +
8305 +#ifdef CONFIG_PAX_REFCOUNT
8306 +" mcrxr cr0\n"
8307 +" subfo. %0,%2,%0\n"
8308 +" bf 4*cr0+so, 3f\n"
8309 +"2:.long " "0x00c00b00""\n"
8310 +#else
8311 +" subf %0,%2,%0\n"
8312 +#endif
8313 +
8314 +"3:\n"
8315 + PPC405_ERR77(0,%3)
8316 +" stwcx. %0,0,%3 \n\
8317 + bne- 1b\n"
8318 +"4:"
8319 +
8320 +#ifdef CONFIG_PAX_REFCOUNT
8321 + _ASM_EXTABLE(2b, 4b)
8322 +#endif
8323 +
8324 + : "=&r" (t), "+m" (v->counter)
8325 + : "r" (a), "r" (&v->counter)
8326 + : "cc");
8327 +}
8328 +
8329 +static __inline__ void atomic_sub_unchecked(int a, atomic_unchecked_t *v)
8330 +{
8331 + int t;
8332 +
8333 + __asm__ __volatile__(
8334 "1: lwarx %0,0,%3 # atomic_sub\n\
8335 subf %0,%2,%0\n"
8336 PPC405_ERR77(0,%3)
8337 @@ -77,12 +195,49 @@ static __inline__ void atomic_sub(int a, atomic_t *v)
8338 : "cc");
8339 }
8340
8341 +/* Same as atomic_sub but return the value */
8342 static __inline__ int atomic_sub_return(int a, atomic_t *v)
8343 {
8344 int t;
8345
8346 __asm__ __volatile__(
8347 PPC_ATOMIC_ENTRY_BARRIER
8348 +"1: lwarx %0,0,%2 # atomic_sub_return\n"
8349 +
8350 +#ifdef CONFIG_PAX_REFCOUNT
8351 +" mcrxr cr0\n"
8352 +" subfo. %0,%1,%0\n"
8353 +" bf 4*cr0+so, 3f\n"
8354 +"2:.long " "0x00c00b00""\n"
8355 +#else
8356 +" subf %0,%1,%0\n"
8357 +#endif
8358 +
8359 +"3:\n"
8360 + PPC405_ERR77(0,%2)
8361 +" stwcx. %0,0,%2 \n\
8362 + bne- 1b\n"
8363 + PPC_ATOMIC_EXIT_BARRIER
8364 +"4:"
8365 +
8366 +#ifdef CONFIG_PAX_REFCOUNT
8367 + _ASM_EXTABLE(2b, 4b)
8368 +#endif
8369 +
8370 + : "=&r" (t)
8371 + : "r" (a), "r" (&v->counter)
8372 + : "cc", "memory");
8373 +
8374 + return t;
8375 +}
8376 +
8377 +/* Same as atomic_sub_unchecked but return the value */
8378 +static __inline__ int atomic_sub_return_unchecked(int a, atomic_unchecked_t *v)
8379 +{
8380 + int t;
8381 +
8382 + __asm__ __volatile__(
8383 + PPC_ATOMIC_ENTRY_BARRIER
8384 "1: lwarx %0,0,%2 # atomic_sub_return\n\
8385 subf %0,%1,%0\n"
8386 PPC405_ERR77(0,%2)
8387 @@ -96,38 +251,23 @@ static __inline__ int atomic_sub_return(int a, atomic_t *v)
8388 return t;
8389 }
8390
8391 -static __inline__ void atomic_inc(atomic_t *v)
8392 -{
8393 - int t;
8394 +/*
8395 + * atomic_inc - increment atomic variable
8396 + * @v: pointer of type atomic_t
8397 + *
8398 + * Automatically increments @v by 1
8399 + */
8400 +#define atomic_inc(v) atomic_add(1, (v))
8401 +#define atomic_inc_return(v) atomic_add_return(1, (v))
8402
8403 - __asm__ __volatile__(
8404 -"1: lwarx %0,0,%2 # atomic_inc\n\
8405 - addic %0,%0,1\n"
8406 - PPC405_ERR77(0,%2)
8407 -" stwcx. %0,0,%2 \n\
8408 - bne- 1b"
8409 - : "=&r" (t), "+m" (v->counter)
8410 - : "r" (&v->counter)
8411 - : "cc", "xer");
8412 +static __inline__ void atomic_inc_unchecked(atomic_unchecked_t *v)
8413 +{
8414 + atomic_add_unchecked(1, v);
8415 }
8416
8417 -static __inline__ int atomic_inc_return(atomic_t *v)
8418 +static __inline__ int atomic_inc_return_unchecked(atomic_unchecked_t *v)
8419 {
8420 - int t;
8421 -
8422 - __asm__ __volatile__(
8423 - PPC_ATOMIC_ENTRY_BARRIER
8424 -"1: lwarx %0,0,%1 # atomic_inc_return\n\
8425 - addic %0,%0,1\n"
8426 - PPC405_ERR77(0,%1)
8427 -" stwcx. %0,0,%1 \n\
8428 - bne- 1b"
8429 - PPC_ATOMIC_EXIT_BARRIER
8430 - : "=&r" (t)
8431 - : "r" (&v->counter)
8432 - : "cc", "xer", "memory");
8433 -
8434 - return t;
8435 + return atomic_add_return_unchecked(1, v);
8436 }
8437
8438 /*
8439 @@ -140,43 +280,38 @@ static __inline__ int atomic_inc_return(atomic_t *v)
8440 */
8441 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
8442
8443 -static __inline__ void atomic_dec(atomic_t *v)
8444 +static __inline__ int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
8445 {
8446 - int t;
8447 -
8448 - __asm__ __volatile__(
8449 -"1: lwarx %0,0,%2 # atomic_dec\n\
8450 - addic %0,%0,-1\n"
8451 - PPC405_ERR77(0,%2)\
8452 -" stwcx. %0,0,%2\n\
8453 - bne- 1b"
8454 - : "=&r" (t), "+m" (v->counter)
8455 - : "r" (&v->counter)
8456 - : "cc", "xer");
8457 + return atomic_add_return_unchecked(1, v) == 0;
8458 }
8459
8460 -static __inline__ int atomic_dec_return(atomic_t *v)
8461 +/*
8462 + * atomic_dec - decrement atomic variable
8463 + * @v: pointer of type atomic_t
8464 + *
8465 + * Atomically decrements @v by 1
8466 + */
8467 +#define atomic_dec(v) atomic_sub(1, (v))
8468 +#define atomic_dec_return(v) atomic_sub_return(1, (v))
8469 +
8470 +static __inline__ void atomic_dec_unchecked(atomic_unchecked_t *v)
8471 {
8472 - int t;
8473 -
8474 - __asm__ __volatile__(
8475 - PPC_ATOMIC_ENTRY_BARRIER
8476 -"1: lwarx %0,0,%1 # atomic_dec_return\n\
8477 - addic %0,%0,-1\n"
8478 - PPC405_ERR77(0,%1)
8479 -" stwcx. %0,0,%1\n\
8480 - bne- 1b"
8481 - PPC_ATOMIC_EXIT_BARRIER
8482 - : "=&r" (t)
8483 - : "r" (&v->counter)
8484 - : "cc", "xer", "memory");
8485 -
8486 - return t;
8487 + atomic_sub_unchecked(1, v);
8488 }
8489
8490 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
8491 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
8492
8493 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
8494 +{
8495 + return cmpxchg(&(v->counter), old, new);
8496 +}
8497 +
8498 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
8499 +{
8500 + return xchg(&(v->counter), new);
8501 +}
8502 +
8503 /**
8504 * __atomic_add_unless - add unless the number is a given value
8505 * @v: pointer of type atomic_t
8506 @@ -194,11 +329,27 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
8507 PPC_ATOMIC_ENTRY_BARRIER
8508 "1: lwarx %0,0,%1 # __atomic_add_unless\n\
8509 cmpw 0,%0,%3 \n\
8510 - beq- 2f \n\
8511 - add %0,%2,%0 \n"
8512 + beq- 2f \n"
8513 +
8514 +#ifdef CONFIG_PAX_REFCOUNT
8515 +" mcrxr cr0\n"
8516 +" addo. %0,%2,%0\n"
8517 +" bf 4*cr0+so, 4f\n"
8518 +"3:.long " "0x00c00b00""\n"
8519 +"4:\n"
8520 +#else
8521 + "add %0,%2,%0 \n"
8522 +#endif
8523 +
8524 PPC405_ERR77(0,%2)
8525 " stwcx. %0,0,%1 \n\
8526 bne- 1b \n"
8527 +"5:"
8528 +
8529 +#ifdef CONFIG_PAX_REFCOUNT
8530 + _ASM_EXTABLE(3b, 5b)
8531 +#endif
8532 +
8533 PPC_ATOMIC_EXIT_BARRIER
8534 " subf %0,%2,%0 \n\
8535 2:"
8536 @@ -271,6 +422,11 @@ static __inline__ int atomic_dec_if_positive(atomic_t *v)
8537 }
8538 #define atomic_dec_if_positive atomic_dec_if_positive
8539
8540 +#define smp_mb__before_atomic_dec() smp_mb()
8541 +#define smp_mb__after_atomic_dec() smp_mb()
8542 +#define smp_mb__before_atomic_inc() smp_mb()
8543 +#define smp_mb__after_atomic_inc() smp_mb()
8544 +
8545 #ifdef __powerpc64__
8546
8547 #define ATOMIC64_INIT(i) { (i) }
8548 @@ -284,11 +440,25 @@ static __inline__ long atomic64_read(const atomic64_t *v)
8549 return t;
8550 }
8551
8552 +static __inline__ long atomic64_read_unchecked(const atomic64_unchecked_t *v)
8553 +{
8554 + long t;
8555 +
8556 + __asm__ __volatile__("ld%U1%X1 %0,%1" : "=r"(t) : "m"(v->counter));
8557 +
8558 + return t;
8559 +}
8560 +
8561 static __inline__ void atomic64_set(atomic64_t *v, long i)
8562 {
8563 __asm__ __volatile__("std%U0%X0 %1,%0" : "=m"(v->counter) : "r"(i));
8564 }
8565
8566 +static __inline__ void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
8567 +{
8568 + __asm__ __volatile__("std%U0%X0 %1,%0" : "=m"(v->counter) : "r"(i));
8569 +}
8570 +
8571 static __inline__ void atomic64_add(long a, atomic64_t *v)
8572 {
8573 long t;
8574 @@ -303,12 +473,76 @@ static __inline__ void atomic64_add(long a, atomic64_t *v)
8575 : "cc");
8576 }
8577
8578 +static __inline__ void atomic64_add_unchecked(long a, atomic64_unchecked_t *v)
8579 +{
8580 + long t;
8581 +
8582 + __asm__ __volatile__(
8583 +"1: ldarx %0,0,%3 # atomic64_add\n"
8584 +
8585 +#ifdef CONFIG_PAX_REFCOUNT
8586 +" mcrxr cr0\n"
8587 +" addo. %0,%2,%0\n"
8588 +" bf 4*cr0+so, 3f\n"
8589 +"2:.long " "0x00c00b00""\n"
8590 +#else
8591 +" add %0,%2,%0\n"
8592 +#endif
8593 +
8594 +"3:\n"
8595 +" stdcx. %0,0,%3 \n\
8596 + bne- 1b\n"
8597 +"4:"
8598 +
8599 +#ifdef CONFIG_PAX_REFCOUNT
8600 + _ASM_EXTABLE(2b, 4b)
8601 +#endif
8602 +
8603 + : "=&r" (t), "+m" (v->counter)
8604 + : "r" (a), "r" (&v->counter)
8605 + : "cc");
8606 +}
8607 +
8608 static __inline__ long atomic64_add_return(long a, atomic64_t *v)
8609 {
8610 long t;
8611
8612 __asm__ __volatile__(
8613 PPC_ATOMIC_ENTRY_BARRIER
8614 +"1: ldarx %0,0,%2 # atomic64_add_return\n"
8615 +
8616 +#ifdef CONFIG_PAX_REFCOUNT
8617 +" mcrxr cr0\n"
8618 +" addo. %0,%1,%0\n"
8619 +" bf 4*cr0+so, 3f\n"
8620 +"2:.long " "0x00c00b00""\n"
8621 +#else
8622 +" add %0,%1,%0\n"
8623 +#endif
8624 +
8625 +"3:\n"
8626 +" stdcx. %0,0,%2 \n\
8627 + bne- 1b\n"
8628 + PPC_ATOMIC_EXIT_BARRIER
8629 +"4:"
8630 +
8631 +#ifdef CONFIG_PAX_REFCOUNT
8632 + _ASM_EXTABLE(2b, 4b)
8633 +#endif
8634 +
8635 + : "=&r" (t)
8636 + : "r" (a), "r" (&v->counter)
8637 + : "cc", "memory");
8638 +
8639 + return t;
8640 +}
8641 +
8642 +static __inline__ long atomic64_add_return_unchecked(long a, atomic64_unchecked_t *v)
8643 +{
8644 + long t;
8645 +
8646 + __asm__ __volatile__(
8647 + PPC_ATOMIC_ENTRY_BARRIER
8648 "1: ldarx %0,0,%2 # atomic64_add_return\n\
8649 add %0,%1,%0\n\
8650 stdcx. %0,0,%2 \n\
8651 @@ -328,6 +562,36 @@ static __inline__ void atomic64_sub(long a, atomic64_t *v)
8652 long t;
8653
8654 __asm__ __volatile__(
8655 +"1: ldarx %0,0,%3 # atomic64_sub\n"
8656 +
8657 +#ifdef CONFIG_PAX_REFCOUNT
8658 +" mcrxr cr0\n"
8659 +" subfo. %0,%2,%0\n"
8660 +" bf 4*cr0+so, 3f\n"
8661 +"2:.long " "0x00c00b00""\n"
8662 +#else
8663 +" subf %0,%2,%0\n"
8664 +#endif
8665 +
8666 +"3:\n"
8667 +" stdcx. %0,0,%3 \n\
8668 + bne- 1b"
8669 +"4:"
8670 +
8671 +#ifdef CONFIG_PAX_REFCOUNT
8672 + _ASM_EXTABLE(2b, 4b)
8673 +#endif
8674 +
8675 + : "=&r" (t), "+m" (v->counter)
8676 + : "r" (a), "r" (&v->counter)
8677 + : "cc");
8678 +}
8679 +
8680 +static __inline__ void atomic64_sub_unchecked(long a, atomic64_unchecked_t *v)
8681 +{
8682 + long t;
8683 +
8684 + __asm__ __volatile__(
8685 "1: ldarx %0,0,%3 # atomic64_sub\n\
8686 subf %0,%2,%0\n\
8687 stdcx. %0,0,%3 \n\
8688 @@ -343,6 +607,40 @@ static __inline__ long atomic64_sub_return(long a, atomic64_t *v)
8689
8690 __asm__ __volatile__(
8691 PPC_ATOMIC_ENTRY_BARRIER
8692 +"1: ldarx %0,0,%2 # atomic64_sub_return\n"
8693 +
8694 +#ifdef CONFIG_PAX_REFCOUNT
8695 +" mcrxr cr0\n"
8696 +" subfo. %0,%1,%0\n"
8697 +" bf 4*cr0+so, 3f\n"
8698 +"2:.long " "0x00c00b00""\n"
8699 +#else
8700 +" subf %0,%1,%0\n"
8701 +#endif
8702 +
8703 +"3:\n"
8704 +" stdcx. %0,0,%2 \n\
8705 + bne- 1b\n"
8706 + PPC_ATOMIC_EXIT_BARRIER
8707 +"4:"
8708 +
8709 +#ifdef CONFIG_PAX_REFCOUNT
8710 + _ASM_EXTABLE(2b, 4b)
8711 +#endif
8712 +
8713 + : "=&r" (t)
8714 + : "r" (a), "r" (&v->counter)
8715 + : "cc", "memory");
8716 +
8717 + return t;
8718 +}
8719 +
8720 +static __inline__ long atomic64_sub_return_unchecked(long a, atomic64_unchecked_t *v)
8721 +{
8722 + long t;
8723 +
8724 + __asm__ __volatile__(
8725 + PPC_ATOMIC_ENTRY_BARRIER
8726 "1: ldarx %0,0,%2 # atomic64_sub_return\n\
8727 subf %0,%1,%0\n\
8728 stdcx. %0,0,%2 \n\
8729 @@ -355,36 +653,23 @@ static __inline__ long atomic64_sub_return(long a, atomic64_t *v)
8730 return t;
8731 }
8732
8733 -static __inline__ void atomic64_inc(atomic64_t *v)
8734 -{
8735 - long t;
8736 +/*
8737 + * atomic64_inc - increment atomic variable
8738 + * @v: pointer of type atomic64_t
8739 + *
8740 + * Automatically increments @v by 1
8741 + */
8742 +#define atomic64_inc(v) atomic64_add(1, (v))
8743 +#define atomic64_inc_return(v) atomic64_add_return(1, (v))
8744
8745 - __asm__ __volatile__(
8746 -"1: ldarx %0,0,%2 # atomic64_inc\n\
8747 - addic %0,%0,1\n\
8748 - stdcx. %0,0,%2 \n\
8749 - bne- 1b"
8750 - : "=&r" (t), "+m" (v->counter)
8751 - : "r" (&v->counter)
8752 - : "cc", "xer");
8753 +static __inline__ void atomic64_inc_unchecked(atomic64_unchecked_t *v)
8754 +{
8755 + atomic64_add_unchecked(1, v);
8756 }
8757
8758 -static __inline__ long atomic64_inc_return(atomic64_t *v)
8759 +static __inline__ long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
8760 {
8761 - long t;
8762 -
8763 - __asm__ __volatile__(
8764 - PPC_ATOMIC_ENTRY_BARRIER
8765 -"1: ldarx %0,0,%1 # atomic64_inc_return\n\
8766 - addic %0,%0,1\n\
8767 - stdcx. %0,0,%1 \n\
8768 - bne- 1b"
8769 - PPC_ATOMIC_EXIT_BARRIER
8770 - : "=&r" (t)
8771 - : "r" (&v->counter)
8772 - : "cc", "xer", "memory");
8773 -
8774 - return t;
8775 + return atomic64_add_return_unchecked(1, v);
8776 }
8777
8778 /*
8779 @@ -397,36 +682,18 @@ static __inline__ long atomic64_inc_return(atomic64_t *v)
8780 */
8781 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
8782
8783 -static __inline__ void atomic64_dec(atomic64_t *v)
8784 +/*
8785 + * atomic64_dec - decrement atomic variable
8786 + * @v: pointer of type atomic64_t
8787 + *
8788 + * Atomically decrements @v by 1
8789 + */
8790 +#define atomic64_dec(v) atomic64_sub(1, (v))
8791 +#define atomic64_dec_return(v) atomic64_sub_return(1, (v))
8792 +
8793 +static __inline__ void atomic64_dec_unchecked(atomic64_unchecked_t *v)
8794 {
8795 - long t;
8796 -
8797 - __asm__ __volatile__(
8798 -"1: ldarx %0,0,%2 # atomic64_dec\n\
8799 - addic %0,%0,-1\n\
8800 - stdcx. %0,0,%2\n\
8801 - bne- 1b"
8802 - : "=&r" (t), "+m" (v->counter)
8803 - : "r" (&v->counter)
8804 - : "cc", "xer");
8805 -}
8806 -
8807 -static __inline__ long atomic64_dec_return(atomic64_t *v)
8808 -{
8809 - long t;
8810 -
8811 - __asm__ __volatile__(
8812 - PPC_ATOMIC_ENTRY_BARRIER
8813 -"1: ldarx %0,0,%1 # atomic64_dec_return\n\
8814 - addic %0,%0,-1\n\
8815 - stdcx. %0,0,%1\n\
8816 - bne- 1b"
8817 - PPC_ATOMIC_EXIT_BARRIER
8818 - : "=&r" (t)
8819 - : "r" (&v->counter)
8820 - : "cc", "xer", "memory");
8821 -
8822 - return t;
8823 + atomic64_sub_unchecked(1, v);
8824 }
8825
8826 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
8827 @@ -459,6 +726,16 @@ static __inline__ long atomic64_dec_if_positive(atomic64_t *v)
8828 #define atomic64_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
8829 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
8830
8831 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
8832 +{
8833 + return cmpxchg(&(v->counter), old, new);
8834 +}
8835 +
8836 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
8837 +{
8838 + return xchg(&(v->counter), new);
8839 +}
8840 +
8841 /**
8842 * atomic64_add_unless - add unless the number is a given value
8843 * @v: pointer of type atomic64_t
8844 @@ -474,13 +751,29 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
8845
8846 __asm__ __volatile__ (
8847 PPC_ATOMIC_ENTRY_BARRIER
8848 -"1: ldarx %0,0,%1 # __atomic_add_unless\n\
8849 +"1: ldarx %0,0,%1 # atomic64_add_unless\n\
8850 cmpd 0,%0,%3 \n\
8851 - beq- 2f \n\
8852 - add %0,%2,%0 \n"
8853 + beq- 2f \n"
8854 +
8855 +#ifdef CONFIG_PAX_REFCOUNT
8856 +" mcrxr cr0\n"
8857 +" addo. %0,%2,%0\n"
8858 +" bf 4*cr0+so, 4f\n"
8859 +"3:.long " "0x00c00b00""\n"
8860 +"4:\n"
8861 +#else
8862 + "add %0,%2,%0 \n"
8863 +#endif
8864 +
8865 " stdcx. %0,0,%1 \n\
8866 bne- 1b \n"
8867 PPC_ATOMIC_EXIT_BARRIER
8868 +"5:"
8869 +
8870 +#ifdef CONFIG_PAX_REFCOUNT
8871 + _ASM_EXTABLE(3b, 5b)
8872 +#endif
8873 +
8874 " subf %0,%2,%0 \n\
8875 2:"
8876 : "=&r" (t)
8877 diff --git a/arch/powerpc/include/asm/barrier.h b/arch/powerpc/include/asm/barrier.h
8878 index bab79a1..4a3eabc 100644
8879 --- a/arch/powerpc/include/asm/barrier.h
8880 +++ b/arch/powerpc/include/asm/barrier.h
8881 @@ -73,7 +73,7 @@
8882 do { \
8883 compiletime_assert_atomic_type(*p); \
8884 __lwsync(); \
8885 - ACCESS_ONCE(*p) = (v); \
8886 + ACCESS_ONCE_RW(*p) = (v); \
8887 } while (0)
8888
8889 #define smp_load_acquire(p) \
8890 diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
8891 index 34a05a1..a1f2c67 100644
8892 --- a/arch/powerpc/include/asm/cache.h
8893 +++ b/arch/powerpc/include/asm/cache.h
8894 @@ -4,6 +4,7 @@
8895 #ifdef __KERNEL__
8896
8897 #include <asm/reg.h>
8898 +#include <linux/const.h>
8899
8900 /* bytes per L1 cache line */
8901 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
8902 @@ -23,7 +24,7 @@
8903 #define L1_CACHE_SHIFT 7
8904 #endif
8905
8906 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8907 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8908
8909 #define SMP_CACHE_BYTES L1_CACHE_BYTES
8910
8911 diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
8912 index 888d8f3..66f581c 100644
8913 --- a/arch/powerpc/include/asm/elf.h
8914 +++ b/arch/powerpc/include/asm/elf.h
8915 @@ -28,8 +28,19 @@
8916 the loader. We need to make sure that it is out of the way of the program
8917 that it will "exec", and that there is sufficient room for the brk. */
8918
8919 -extern unsigned long randomize_et_dyn(unsigned long base);
8920 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
8921 +#define ELF_ET_DYN_BASE (0x20000000)
8922 +
8923 +#ifdef CONFIG_PAX_ASLR
8924 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
8925 +
8926 +#ifdef __powerpc64__
8927 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
8928 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
8929 +#else
8930 +#define PAX_DELTA_MMAP_LEN 15
8931 +#define PAX_DELTA_STACK_LEN 15
8932 +#endif
8933 +#endif
8934
8935 #define ELF_CORE_EFLAGS (is_elf2_task() ? 2 : 0)
8936
8937 @@ -129,10 +140,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
8938 (0x7ff >> (PAGE_SHIFT - 12)) : \
8939 (0x3ffff >> (PAGE_SHIFT - 12)))
8940
8941 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
8942 -#define arch_randomize_brk arch_randomize_brk
8943 -
8944 -
8945 #ifdef CONFIG_SPU_BASE
8946 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
8947 #define NT_SPU 1
8948 diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
8949 index 8196e9c..d83a9f3 100644
8950 --- a/arch/powerpc/include/asm/exec.h
8951 +++ b/arch/powerpc/include/asm/exec.h
8952 @@ -4,6 +4,6 @@
8953 #ifndef _ASM_POWERPC_EXEC_H
8954 #define _ASM_POWERPC_EXEC_H
8955
8956 -extern unsigned long arch_align_stack(unsigned long sp);
8957 +#define arch_align_stack(x) ((x) & ~0xfUL)
8958
8959 #endif /* _ASM_POWERPC_EXEC_H */
8960 diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
8961 index 5acabbd..7ea14fa 100644
8962 --- a/arch/powerpc/include/asm/kmap_types.h
8963 +++ b/arch/powerpc/include/asm/kmap_types.h
8964 @@ -10,7 +10,7 @@
8965 * 2 of the License, or (at your option) any later version.
8966 */
8967
8968 -#define KM_TYPE_NR 16
8969 +#define KM_TYPE_NR 17
8970
8971 #endif /* __KERNEL__ */
8972 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
8973 diff --git a/arch/powerpc/include/asm/local.h b/arch/powerpc/include/asm/local.h
8974 index b8da913..c02b593 100644
8975 --- a/arch/powerpc/include/asm/local.h
8976 +++ b/arch/powerpc/include/asm/local.h
8977 @@ -9,21 +9,65 @@ typedef struct
8978 atomic_long_t a;
8979 } local_t;
8980
8981 +typedef struct
8982 +{
8983 + atomic_long_unchecked_t a;
8984 +} local_unchecked_t;
8985 +
8986 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
8987
8988 #define local_read(l) atomic_long_read(&(l)->a)
8989 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
8990 #define local_set(l,i) atomic_long_set(&(l)->a, (i))
8991 +#define local_set_unchecked(l,i) atomic_long_set_unchecked(&(l)->a, (i))
8992
8993 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
8994 +#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
8995 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
8996 +#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
8997 #define local_inc(l) atomic_long_inc(&(l)->a)
8998 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
8999 #define local_dec(l) atomic_long_dec(&(l)->a)
9000 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
9001
9002 static __inline__ long local_add_return(long a, local_t *l)
9003 {
9004 long t;
9005
9006 __asm__ __volatile__(
9007 +"1:" PPC_LLARX(%0,0,%2,0) " # local_add_return\n"
9008 +
9009 +#ifdef CONFIG_PAX_REFCOUNT
9010 +" mcrxr cr0\n"
9011 +" addo. %0,%1,%0\n"
9012 +" bf 4*cr0+so, 3f\n"
9013 +"2:.long " "0x00c00b00""\n"
9014 +#else
9015 +" add %0,%1,%0\n"
9016 +#endif
9017 +
9018 +"3:\n"
9019 + PPC405_ERR77(0,%2)
9020 + PPC_STLCX "%0,0,%2 \n\
9021 + bne- 1b"
9022 +
9023 +#ifdef CONFIG_PAX_REFCOUNT
9024 +"\n4:\n"
9025 + _ASM_EXTABLE(2b, 4b)
9026 +#endif
9027 +
9028 + : "=&r" (t)
9029 + : "r" (a), "r" (&(l->a.counter))
9030 + : "cc", "memory");
9031 +
9032 + return t;
9033 +}
9034 +
9035 +static __inline__ long local_add_return_unchecked(long a, local_unchecked_t *l)
9036 +{
9037 + long t;
9038 +
9039 + __asm__ __volatile__(
9040 "1:" PPC_LLARX(%0,0,%2,0) " # local_add_return\n\
9041 add %0,%1,%0\n"
9042 PPC405_ERR77(0,%2)
9043 @@ -101,6 +145,8 @@ static __inline__ long local_dec_return(local_t *l)
9044
9045 #define local_cmpxchg(l, o, n) \
9046 (cmpxchg_local(&((l)->a.counter), (o), (n)))
9047 +#define local_cmpxchg_unchecked(l, o, n) \
9048 + (cmpxchg_local(&((l)->a.counter), (o), (n)))
9049 #define local_xchg(l, n) (xchg_local(&((l)->a.counter), (n)))
9050
9051 /**
9052 diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
9053 index 8565c25..2865190 100644
9054 --- a/arch/powerpc/include/asm/mman.h
9055 +++ b/arch/powerpc/include/asm/mman.h
9056 @@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
9057 }
9058 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
9059
9060 -static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
9061 +static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
9062 {
9063 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
9064 }
9065 diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
9066 index 26fe1ae..987ffc5 100644
9067 --- a/arch/powerpc/include/asm/page.h
9068 +++ b/arch/powerpc/include/asm/page.h
9069 @@ -227,8 +227,9 @@ extern long long virt_phys_offset;
9070 * and needs to be executable. This means the whole heap ends
9071 * up being executable.
9072 */
9073 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
9074 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
9075 +#define VM_DATA_DEFAULT_FLAGS32 \
9076 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
9077 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
9078
9079 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
9080 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
9081 @@ -256,6 +257,9 @@ extern long long virt_phys_offset;
9082 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
9083 #endif
9084
9085 +#define ktla_ktva(addr) (addr)
9086 +#define ktva_ktla(addr) (addr)
9087 +
9088 #ifndef CONFIG_PPC_BOOK3S_64
9089 /*
9090 * Use the top bit of the higher-level page table entries to indicate whether
9091 diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
9092 index 88693ce..ac6f9ab 100644
9093 --- a/arch/powerpc/include/asm/page_64.h
9094 +++ b/arch/powerpc/include/asm/page_64.h
9095 @@ -153,15 +153,18 @@ do { \
9096 * stack by default, so in the absence of a PT_GNU_STACK program header
9097 * we turn execute permission off.
9098 */
9099 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
9100 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
9101 +#define VM_STACK_DEFAULT_FLAGS32 \
9102 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
9103 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
9104
9105 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
9106 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
9107
9108 +#ifndef CONFIG_PAX_PAGEEXEC
9109 #define VM_STACK_DEFAULT_FLAGS \
9110 (is_32bit_task() ? \
9111 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
9112 +#endif
9113
9114 #include <asm-generic/getorder.h>
9115
9116 diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
9117 index 4b0be20..c15a27d 100644
9118 --- a/arch/powerpc/include/asm/pgalloc-64.h
9119 +++ b/arch/powerpc/include/asm/pgalloc-64.h
9120 @@ -54,6 +54,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
9121 #ifndef CONFIG_PPC_64K_PAGES
9122
9123 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
9124 +#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
9125
9126 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
9127 {
9128 @@ -71,6 +72,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
9129 pud_set(pud, (unsigned long)pmd);
9130 }
9131
9132 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
9133 +{
9134 + pud_populate(mm, pud, pmd);
9135 +}
9136 +
9137 #define pmd_populate(mm, pmd, pte_page) \
9138 pmd_populate_kernel(mm, pmd, page_address(pte_page))
9139 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
9140 @@ -173,6 +179,7 @@ extern void __tlb_remove_table(void *_table);
9141 #endif
9142
9143 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
9144 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
9145
9146 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
9147 pte_t *pte)
9148 diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
9149 index d98c1ec..9f61569 100644
9150 --- a/arch/powerpc/include/asm/pgtable.h
9151 +++ b/arch/powerpc/include/asm/pgtable.h
9152 @@ -2,6 +2,7 @@
9153 #define _ASM_POWERPC_PGTABLE_H
9154 #ifdef __KERNEL__
9155
9156 +#include <linux/const.h>
9157 #ifndef __ASSEMBLY__
9158 #include <linux/mmdebug.h>
9159 #include <asm/processor.h> /* For TASK_SIZE */
9160 diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
9161 index 4aad413..85d86bf 100644
9162 --- a/arch/powerpc/include/asm/pte-hash32.h
9163 +++ b/arch/powerpc/include/asm/pte-hash32.h
9164 @@ -21,6 +21,7 @@
9165 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
9166 #define _PAGE_USER 0x004 /* usermode access allowed */
9167 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
9168 +#define _PAGE_EXEC _PAGE_GUARDED
9169 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
9170 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
9171 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
9172 diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
9173 index 0c05059..7e056e4 100644
9174 --- a/arch/powerpc/include/asm/reg.h
9175 +++ b/arch/powerpc/include/asm/reg.h
9176 @@ -251,6 +251,7 @@
9177 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
9178 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
9179 #define DSISR_NOHPTE 0x40000000 /* no translation found */
9180 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
9181 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
9182 #define DSISR_ISSTORE 0x02000000 /* access was a store */
9183 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
9184 diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
9185 index 5a6614a..d89995d1 100644
9186 --- a/arch/powerpc/include/asm/smp.h
9187 +++ b/arch/powerpc/include/asm/smp.h
9188 @@ -51,7 +51,7 @@ struct smp_ops_t {
9189 int (*cpu_disable)(void);
9190 void (*cpu_die)(unsigned int nr);
9191 int (*cpu_bootable)(unsigned int nr);
9192 -};
9193 +} __no_const;
9194
9195 extern void smp_send_debugger_break(void);
9196 extern void start_secondary_resume(void);
9197 diff --git a/arch/powerpc/include/asm/spinlock.h b/arch/powerpc/include/asm/spinlock.h
9198 index 4dbe072..b803275 100644
9199 --- a/arch/powerpc/include/asm/spinlock.h
9200 +++ b/arch/powerpc/include/asm/spinlock.h
9201 @@ -204,13 +204,29 @@ static inline long __arch_read_trylock(arch_rwlock_t *rw)
9202 __asm__ __volatile__(
9203 "1: " PPC_LWARX(%0,0,%1,1) "\n"
9204 __DO_SIGN_EXTEND
9205 -" addic. %0,%0,1\n\
9206 - ble- 2f\n"
9207 +
9208 +#ifdef CONFIG_PAX_REFCOUNT
9209 +" mcrxr cr0\n"
9210 +" addico. %0,%0,1\n"
9211 +" bf 4*cr0+so, 3f\n"
9212 +"2:.long " "0x00c00b00""\n"
9213 +#else
9214 +" addic. %0,%0,1\n"
9215 +#endif
9216 +
9217 +"3:\n"
9218 + "ble- 4f\n"
9219 PPC405_ERR77(0,%1)
9220 " stwcx. %0,0,%1\n\
9221 bne- 1b\n"
9222 PPC_ACQUIRE_BARRIER
9223 -"2:" : "=&r" (tmp)
9224 +"4:"
9225 +
9226 +#ifdef CONFIG_PAX_REFCOUNT
9227 + _ASM_EXTABLE(2b,4b)
9228 +#endif
9229 +
9230 + : "=&r" (tmp)
9231 : "r" (&rw->lock)
9232 : "cr0", "xer", "memory");
9233
9234 @@ -286,11 +302,27 @@ static inline void arch_read_unlock(arch_rwlock_t *rw)
9235 __asm__ __volatile__(
9236 "# read_unlock\n\t"
9237 PPC_RELEASE_BARRIER
9238 -"1: lwarx %0,0,%1\n\
9239 - addic %0,%0,-1\n"
9240 +"1: lwarx %0,0,%1\n"
9241 +
9242 +#ifdef CONFIG_PAX_REFCOUNT
9243 +" mcrxr cr0\n"
9244 +" addico. %0,%0,-1\n"
9245 +" bf 4*cr0+so, 3f\n"
9246 +"2:.long " "0x00c00b00""\n"
9247 +#else
9248 +" addic. %0,%0,-1\n"
9249 +#endif
9250 +
9251 +"3:\n"
9252 PPC405_ERR77(0,%1)
9253 " stwcx. %0,0,%1\n\
9254 bne- 1b"
9255 +
9256 +#ifdef CONFIG_PAX_REFCOUNT
9257 +"\n4:\n"
9258 + _ASM_EXTABLE(2b, 4b)
9259 +#endif
9260 +
9261 : "=&r"(tmp)
9262 : "r"(&rw->lock)
9263 : "cr0", "xer", "memory");
9264 diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
9265 index b034ecd..af7e31f 100644
9266 --- a/arch/powerpc/include/asm/thread_info.h
9267 +++ b/arch/powerpc/include/asm/thread_info.h
9268 @@ -107,6 +107,8 @@ static inline struct thread_info *current_thread_info(void)
9269 #if defined(CONFIG_PPC64)
9270 #define TIF_ELF2ABI 18 /* function descriptors must die! */
9271 #endif
9272 +/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
9273 +#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
9274
9275 /* as above, but as bit values */
9276 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
9277 @@ -125,9 +127,10 @@ static inline struct thread_info *current_thread_info(void)
9278 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
9279 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
9280 #define _TIF_NOHZ (1<<TIF_NOHZ)
9281 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
9282 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
9283 _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
9284 - _TIF_NOHZ)
9285 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
9286
9287 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
9288 _TIF_NOTIFY_RESUME | _TIF_UPROBE | \
9289 diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
9290 index 9485b43..3bd3c16 100644
9291 --- a/arch/powerpc/include/asm/uaccess.h
9292 +++ b/arch/powerpc/include/asm/uaccess.h
9293 @@ -58,6 +58,7 @@
9294
9295 #endif
9296
9297 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
9298 #define access_ok(type, addr, size) \
9299 (__chk_user_ptr(addr), \
9300 __access_ok((__force unsigned long)(addr), (size), get_fs()))
9301 @@ -318,52 +319,6 @@ do { \
9302 extern unsigned long __copy_tofrom_user(void __user *to,
9303 const void __user *from, unsigned long size);
9304
9305 -#ifndef __powerpc64__
9306 -
9307 -static inline unsigned long copy_from_user(void *to,
9308 - const void __user *from, unsigned long n)
9309 -{
9310 - unsigned long over;
9311 -
9312 - if (access_ok(VERIFY_READ, from, n))
9313 - return __copy_tofrom_user((__force void __user *)to, from, n);
9314 - if ((unsigned long)from < TASK_SIZE) {
9315 - over = (unsigned long)from + n - TASK_SIZE;
9316 - return __copy_tofrom_user((__force void __user *)to, from,
9317 - n - over) + over;
9318 - }
9319 - return n;
9320 -}
9321 -
9322 -static inline unsigned long copy_to_user(void __user *to,
9323 - const void *from, unsigned long n)
9324 -{
9325 - unsigned long over;
9326 -
9327 - if (access_ok(VERIFY_WRITE, to, n))
9328 - return __copy_tofrom_user(to, (__force void __user *)from, n);
9329 - if ((unsigned long)to < TASK_SIZE) {
9330 - over = (unsigned long)to + n - TASK_SIZE;
9331 - return __copy_tofrom_user(to, (__force void __user *)from,
9332 - n - over) + over;
9333 - }
9334 - return n;
9335 -}
9336 -
9337 -#else /* __powerpc64__ */
9338 -
9339 -#define __copy_in_user(to, from, size) \
9340 - __copy_tofrom_user((to), (from), (size))
9341 -
9342 -extern unsigned long copy_from_user(void *to, const void __user *from,
9343 - unsigned long n);
9344 -extern unsigned long copy_to_user(void __user *to, const void *from,
9345 - unsigned long n);
9346 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
9347 - unsigned long n);
9348 -
9349 -#endif /* __powerpc64__ */
9350 -
9351 static inline unsigned long __copy_from_user_inatomic(void *to,
9352 const void __user *from, unsigned long n)
9353 {
9354 @@ -387,6 +342,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
9355 if (ret == 0)
9356 return 0;
9357 }
9358 +
9359 + if (!__builtin_constant_p(n))
9360 + check_object_size(to, n, false);
9361 +
9362 return __copy_tofrom_user((__force void __user *)to, from, n);
9363 }
9364
9365 @@ -413,6 +372,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
9366 if (ret == 0)
9367 return 0;
9368 }
9369 +
9370 + if (!__builtin_constant_p(n))
9371 + check_object_size(from, n, true);
9372 +
9373 return __copy_tofrom_user(to, (__force const void __user *)from, n);
9374 }
9375
9376 @@ -430,6 +393,92 @@ static inline unsigned long __copy_to_user(void __user *to,
9377 return __copy_to_user_inatomic(to, from, size);
9378 }
9379
9380 +#ifndef __powerpc64__
9381 +
9382 +static inline unsigned long __must_check copy_from_user(void *to,
9383 + const void __user *from, unsigned long n)
9384 +{
9385 + unsigned long over;
9386 +
9387 + if ((long)n < 0)
9388 + return n;
9389 +
9390 + if (access_ok(VERIFY_READ, from, n)) {
9391 + if (!__builtin_constant_p(n))
9392 + check_object_size(to, n, false);
9393 + return __copy_tofrom_user((__force void __user *)to, from, n);
9394 + }
9395 + if ((unsigned long)from < TASK_SIZE) {
9396 + over = (unsigned long)from + n - TASK_SIZE;
9397 + if (!__builtin_constant_p(n - over))
9398 + check_object_size(to, n - over, false);
9399 + return __copy_tofrom_user((__force void __user *)to, from,
9400 + n - over) + over;
9401 + }
9402 + return n;
9403 +}
9404 +
9405 +static inline unsigned long __must_check copy_to_user(void __user *to,
9406 + const void *from, unsigned long n)
9407 +{
9408 + unsigned long over;
9409 +
9410 + if ((long)n < 0)
9411 + return n;
9412 +
9413 + if (access_ok(VERIFY_WRITE, to, n)) {
9414 + if (!__builtin_constant_p(n))
9415 + check_object_size(from, n, true);
9416 + return __copy_tofrom_user(to, (__force void __user *)from, n);
9417 + }
9418 + if ((unsigned long)to < TASK_SIZE) {
9419 + over = (unsigned long)to + n - TASK_SIZE;
9420 + if (!__builtin_constant_p(n))
9421 + check_object_size(from, n - over, true);
9422 + return __copy_tofrom_user(to, (__force void __user *)from,
9423 + n - over) + over;
9424 + }
9425 + return n;
9426 +}
9427 +
9428 +#else /* __powerpc64__ */
9429 +
9430 +#define __copy_in_user(to, from, size) \
9431 + __copy_tofrom_user((to), (from), (size))
9432 +
9433 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
9434 +{
9435 + if ((long)n < 0 || n > INT_MAX)
9436 + return n;
9437 +
9438 + if (!__builtin_constant_p(n))
9439 + check_object_size(to, n, false);
9440 +
9441 + if (likely(access_ok(VERIFY_READ, from, n)))
9442 + n = __copy_from_user(to, from, n);
9443 + else
9444 + memset(to, 0, n);
9445 + return n;
9446 +}
9447 +
9448 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
9449 +{
9450 + if ((long)n < 0 || n > INT_MAX)
9451 + return n;
9452 +
9453 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
9454 + if (!__builtin_constant_p(n))
9455 + check_object_size(from, n, true);
9456 + n = __copy_to_user(to, from, n);
9457 + }
9458 + return n;
9459 +}
9460 +
9461 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
9462 + unsigned long n);
9463 +
9464 +#endif /* __powerpc64__ */
9465 +
9466 extern unsigned long __clear_user(void __user *addr, unsigned long size);
9467
9468 static inline unsigned long clear_user(void __user *addr, unsigned long size)
9469 diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
9470 index 670c312..60c2b52 100644
9471 --- a/arch/powerpc/kernel/Makefile
9472 +++ b/arch/powerpc/kernel/Makefile
9473 @@ -27,6 +27,8 @@ CFLAGS_REMOVE_ftrace.o = -pg -mno-sched-epilog
9474 CFLAGS_REMOVE_time.o = -pg -mno-sched-epilog
9475 endif
9476
9477 +CFLAGS_REMOVE_prom_init.o += $(LATENT_ENTROPY_PLUGIN_CFLAGS)
9478 +
9479 obj-y := cputable.o ptrace.o syscalls.o \
9480 irq.o align.o signal_32.o pmc.o vdso.o \
9481 process.o systbl.o idle.o \
9482 diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
9483 index bb9cac6..5181202 100644
9484 --- a/arch/powerpc/kernel/exceptions-64e.S
9485 +++ b/arch/powerpc/kernel/exceptions-64e.S
9486 @@ -1010,6 +1010,7 @@ storage_fault_common:
9487 std r14,_DAR(r1)
9488 std r15,_DSISR(r1)
9489 addi r3,r1,STACK_FRAME_OVERHEAD
9490 + bl save_nvgprs
9491 mr r4,r14
9492 mr r5,r15
9493 ld r14,PACA_EXGEN+EX_R14(r13)
9494 @@ -1018,8 +1019,7 @@ storage_fault_common:
9495 cmpdi r3,0
9496 bne- 1f
9497 b ret_from_except_lite
9498 -1: bl save_nvgprs
9499 - mr r5,r3
9500 +1: mr r5,r3
9501 addi r3,r1,STACK_FRAME_OVERHEAD
9502 ld r4,_DAR(r1)
9503 bl bad_page_fault
9504 diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
9505 index 050f79a..f385bfe 100644
9506 --- a/arch/powerpc/kernel/exceptions-64s.S
9507 +++ b/arch/powerpc/kernel/exceptions-64s.S
9508 @@ -1593,10 +1593,10 @@ handle_page_fault:
9509 11: ld r4,_DAR(r1)
9510 ld r5,_DSISR(r1)
9511 addi r3,r1,STACK_FRAME_OVERHEAD
9512 + bl save_nvgprs
9513 bl do_page_fault
9514 cmpdi r3,0
9515 beq+ 12f
9516 - bl save_nvgprs
9517 mr r5,r3
9518 addi r3,r1,STACK_FRAME_OVERHEAD
9519 lwz r4,_DAR(r1)
9520 diff --git a/arch/powerpc/kernel/irq.c b/arch/powerpc/kernel/irq.c
9521 index 4c5891d..a5d88bb 100644
9522 --- a/arch/powerpc/kernel/irq.c
9523 +++ b/arch/powerpc/kernel/irq.c
9524 @@ -461,6 +461,8 @@ void migrate_irqs(void)
9525 }
9526 #endif
9527
9528 +extern void gr_handle_kernel_exploit(void);
9529 +
9530 static inline void check_stack_overflow(void)
9531 {
9532 #ifdef CONFIG_DEBUG_STACKOVERFLOW
9533 @@ -473,6 +475,7 @@ static inline void check_stack_overflow(void)
9534 printk("do_IRQ: stack overflow: %ld\n",
9535 sp - sizeof(struct thread_info));
9536 dump_stack();
9537 + gr_handle_kernel_exploit();
9538 }
9539 #endif
9540 }
9541 diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
9542 index 6cff040..74ac5d1b 100644
9543 --- a/arch/powerpc/kernel/module_32.c
9544 +++ b/arch/powerpc/kernel/module_32.c
9545 @@ -161,7 +161,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
9546 me->arch.core_plt_section = i;
9547 }
9548 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
9549 - printk("Module doesn't contain .plt or .init.plt sections.\n");
9550 + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
9551 return -ENOEXEC;
9552 }
9553
9554 @@ -191,11 +191,16 @@ static uint32_t do_plt_call(void *location,
9555
9556 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
9557 /* Init, or core PLT? */
9558 - if (location >= mod->module_core
9559 - && location < mod->module_core + mod->core_size)
9560 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
9561 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
9562 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
9563 - else
9564 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
9565 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
9566 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
9567 + else {
9568 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
9569 + return ~0UL;
9570 + }
9571
9572 /* Find this entry, or if that fails, the next avail. entry */
9573 while (entry->jump[0]) {
9574 @@ -299,7 +304,7 @@ int apply_relocate_add(Elf32_Shdr *sechdrs,
9575 }
9576 #ifdef CONFIG_DYNAMIC_FTRACE
9577 module->arch.tramp =
9578 - do_plt_call(module->module_core,
9579 + do_plt_call(module->module_core_rx,
9580 (unsigned long)ftrace_caller,
9581 sechdrs, module);
9582 #endif
9583 diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
9584 index bf44ae9..6d2ce71 100644
9585 --- a/arch/powerpc/kernel/process.c
9586 +++ b/arch/powerpc/kernel/process.c
9587 @@ -1039,8 +1039,8 @@ void show_regs(struct pt_regs * regs)
9588 * Lookup NIP late so we have the best change of getting the
9589 * above info out without failing
9590 */
9591 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
9592 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
9593 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
9594 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
9595 #endif
9596 show_stack(current, (unsigned long *) regs->gpr[1]);
9597 if (!user_mode(regs))
9598 @@ -1558,10 +1558,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
9599 newsp = stack[0];
9600 ip = stack[STACK_FRAME_LR_SAVE];
9601 if (!firstframe || ip != lr) {
9602 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
9603 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
9604 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
9605 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
9606 - printk(" (%pS)",
9607 + printk(" (%pA)",
9608 (void *)current->ret_stack[curr_frame].ret);
9609 curr_frame--;
9610 }
9611 @@ -1581,7 +1581,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
9612 struct pt_regs *regs = (struct pt_regs *)
9613 (sp + STACK_FRAME_OVERHEAD);
9614 lr = regs->link;
9615 - printk("--- interrupt: %lx at %pS\n LR = %pS\n",
9616 + printk("--- interrupt: %lx at %pA\n LR = %pA\n",
9617 regs->trap, (void *)regs->nip, (void *)lr);
9618 firstframe = 1;
9619 }
9620 @@ -1617,58 +1617,3 @@ void notrace __ppc64_runlatch_off(void)
9621 mtspr(SPRN_CTRLT, ctrl);
9622 }
9623 #endif /* CONFIG_PPC64 */
9624 -
9625 -unsigned long arch_align_stack(unsigned long sp)
9626 -{
9627 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
9628 - sp -= get_random_int() & ~PAGE_MASK;
9629 - return sp & ~0xf;
9630 -}
9631 -
9632 -static inline unsigned long brk_rnd(void)
9633 -{
9634 - unsigned long rnd = 0;
9635 -
9636 - /* 8MB for 32bit, 1GB for 64bit */
9637 - if (is_32bit_task())
9638 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
9639 - else
9640 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
9641 -
9642 - return rnd << PAGE_SHIFT;
9643 -}
9644 -
9645 -unsigned long arch_randomize_brk(struct mm_struct *mm)
9646 -{
9647 - unsigned long base = mm->brk;
9648 - unsigned long ret;
9649 -
9650 -#ifdef CONFIG_PPC_STD_MMU_64
9651 - /*
9652 - * If we are using 1TB segments and we are allowed to randomise
9653 - * the heap, we can put it above 1TB so it is backed by a 1TB
9654 - * segment. Otherwise the heap will be in the bottom 1TB
9655 - * which always uses 256MB segments and this may result in a
9656 - * performance penalty.
9657 - */
9658 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
9659 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
9660 -#endif
9661 -
9662 - ret = PAGE_ALIGN(base + brk_rnd());
9663 -
9664 - if (ret < mm->brk)
9665 - return mm->brk;
9666 -
9667 - return ret;
9668 -}
9669 -
9670 -unsigned long randomize_et_dyn(unsigned long base)
9671 -{
9672 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
9673 -
9674 - if (ret < base)
9675 - return base;
9676 -
9677 - return ret;
9678 -}
9679 diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
9680 index 2e3d2bf..35df241 100644
9681 --- a/arch/powerpc/kernel/ptrace.c
9682 +++ b/arch/powerpc/kernel/ptrace.c
9683 @@ -1762,6 +1762,10 @@ long arch_ptrace(struct task_struct *child, long request,
9684 return ret;
9685 }
9686
9687 +#ifdef CONFIG_GRKERNSEC_SETXID
9688 +extern void gr_delayed_cred_worker(void);
9689 +#endif
9690 +
9691 /*
9692 * We must return the syscall number to actually look up in the table.
9693 * This can be -1L to skip running any syscall at all.
9694 @@ -1774,6 +1778,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
9695
9696 secure_computing_strict(regs->gpr[0]);
9697
9698 +#ifdef CONFIG_GRKERNSEC_SETXID
9699 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
9700 + gr_delayed_cred_worker();
9701 +#endif
9702 +
9703 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
9704 tracehook_report_syscall_entry(regs))
9705 /*
9706 @@ -1808,6 +1817,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
9707 {
9708 int step;
9709
9710 +#ifdef CONFIG_GRKERNSEC_SETXID
9711 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
9712 + gr_delayed_cred_worker();
9713 +#endif
9714 +
9715 audit_syscall_exit(regs);
9716
9717 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
9718 diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
9719 index b171001..4ac7ac5 100644
9720 --- a/arch/powerpc/kernel/signal_32.c
9721 +++ b/arch/powerpc/kernel/signal_32.c
9722 @@ -1011,7 +1011,7 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset,
9723 /* Save user registers on the stack */
9724 frame = &rt_sf->uc.uc_mcontext;
9725 addr = frame;
9726 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
9727 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
9728 sigret = 0;
9729 tramp = current->mm->context.vdso_base + vdso32_rt_sigtramp;
9730 } else {
9731 diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
9732 index 2cb0c94..c0c0bc9 100644
9733 --- a/arch/powerpc/kernel/signal_64.c
9734 +++ b/arch/powerpc/kernel/signal_64.c
9735 @@ -754,7 +754,7 @@ int handle_rt_signal64(struct ksignal *ksig, sigset_t *set, struct pt_regs *regs
9736 current->thread.fp_state.fpscr = 0;
9737
9738 /* Set up to return from userspace. */
9739 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
9740 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
9741 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
9742 } else {
9743 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
9744 diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
9745 index 0dc43f9..a885d33 100644
9746 --- a/arch/powerpc/kernel/traps.c
9747 +++ b/arch/powerpc/kernel/traps.c
9748 @@ -36,6 +36,7 @@
9749 #include <linux/debugfs.h>
9750 #include <linux/ratelimit.h>
9751 #include <linux/context_tracking.h>
9752 +#include <linux/uaccess.h>
9753
9754 #include <asm/emulated_ops.h>
9755 #include <asm/pgtable.h>
9756 @@ -142,6 +143,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
9757 return flags;
9758 }
9759
9760 +extern void gr_handle_kernel_exploit(void);
9761 +
9762 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
9763 int signr)
9764 {
9765 @@ -191,6 +194,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
9766 panic("Fatal exception in interrupt");
9767 if (panic_on_oops)
9768 panic("Fatal exception");
9769 +
9770 + gr_handle_kernel_exploit();
9771 +
9772 do_exit(signr);
9773 }
9774
9775 @@ -1137,6 +1143,26 @@ void __kprobes program_check_exception(struct pt_regs *regs)
9776 enum ctx_state prev_state = exception_enter();
9777 unsigned int reason = get_reason(regs);
9778
9779 +#ifdef CONFIG_PAX_REFCOUNT
9780 + unsigned int bkpt;
9781 + const struct exception_table_entry *entry;
9782 +
9783 + if (reason & REASON_ILLEGAL) {
9784 + /* Check if PaX bad instruction */
9785 + if (!probe_kernel_address(regs->nip, bkpt) && bkpt == 0xc00b00) {
9786 + current->thread.trap_nr = 0;
9787 + pax_report_refcount_overflow(regs);
9788 + /* fixup_exception() for PowerPC does not exist, simulate its job */
9789 + if ((entry = search_exception_tables(regs->nip)) != NULL) {
9790 + regs->nip = entry->fixup;
9791 + return;
9792 + }
9793 + /* fixup_exception() could not handle */
9794 + goto bail;
9795 + }
9796 + }
9797 +#endif
9798 +
9799 /* We can now get here via a FP Unavailable exception if the core
9800 * has no FPU, in that case the reason flags will be 0 */
9801
9802 diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
9803 index f174351..5722009 100644
9804 --- a/arch/powerpc/kernel/vdso.c
9805 +++ b/arch/powerpc/kernel/vdso.c
9806 @@ -35,6 +35,7 @@
9807 #include <asm/vdso.h>
9808 #include <asm/vdso_datapage.h>
9809 #include <asm/setup.h>
9810 +#include <asm/mman.h>
9811
9812 #undef DEBUG
9813
9814 @@ -221,7 +222,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
9815 vdso_base = VDSO32_MBASE;
9816 #endif
9817
9818 - current->mm->context.vdso_base = 0;
9819 + current->mm->context.vdso_base = ~0UL;
9820
9821 /* vDSO has a problem and was disabled, just don't "enable" it for the
9822 * process
9823 @@ -241,7 +242,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
9824 vdso_base = get_unmapped_area(NULL, vdso_base,
9825 (vdso_pages << PAGE_SHIFT) +
9826 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
9827 - 0, 0);
9828 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
9829 if (IS_ERR_VALUE(vdso_base)) {
9830 rc = vdso_base;
9831 goto fail_mmapsem;
9832 diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
9833 index 4c79284..0e462c3 100644
9834 --- a/arch/powerpc/kvm/powerpc.c
9835 +++ b/arch/powerpc/kvm/powerpc.c
9836 @@ -1338,7 +1338,7 @@ void kvmppc_init_lpid(unsigned long nr_lpids_param)
9837 }
9838 EXPORT_SYMBOL_GPL(kvmppc_init_lpid);
9839
9840 -int kvm_arch_init(void *opaque)
9841 +int kvm_arch_init(const void *opaque)
9842 {
9843 return 0;
9844 }
9845 diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
9846 index 5eea6f3..5d10396 100644
9847 --- a/arch/powerpc/lib/usercopy_64.c
9848 +++ b/arch/powerpc/lib/usercopy_64.c
9849 @@ -9,22 +9,6 @@
9850 #include <linux/module.h>
9851 #include <asm/uaccess.h>
9852
9853 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
9854 -{
9855 - if (likely(access_ok(VERIFY_READ, from, n)))
9856 - n = __copy_from_user(to, from, n);
9857 - else
9858 - memset(to, 0, n);
9859 - return n;
9860 -}
9861 -
9862 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
9863 -{
9864 - if (likely(access_ok(VERIFY_WRITE, to, n)))
9865 - n = __copy_to_user(to, from, n);
9866 - return n;
9867 -}
9868 -
9869 unsigned long copy_in_user(void __user *to, const void __user *from,
9870 unsigned long n)
9871 {
9872 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
9873 return n;
9874 }
9875
9876 -EXPORT_SYMBOL(copy_from_user);
9877 -EXPORT_SYMBOL(copy_to_user);
9878 EXPORT_SYMBOL(copy_in_user);
9879
9880 diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
9881 index 51ab9e7..7d3c78b 100644
9882 --- a/arch/powerpc/mm/fault.c
9883 +++ b/arch/powerpc/mm/fault.c
9884 @@ -33,6 +33,10 @@
9885 #include <linux/magic.h>
9886 #include <linux/ratelimit.h>
9887 #include <linux/context_tracking.h>
9888 +#include <linux/slab.h>
9889 +#include <linux/pagemap.h>
9890 +#include <linux/compiler.h>
9891 +#include <linux/unistd.h>
9892
9893 #include <asm/firmware.h>
9894 #include <asm/page.h>
9895 @@ -69,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
9896 }
9897 #endif
9898
9899 +#ifdef CONFIG_PAX_PAGEEXEC
9900 +/*
9901 + * PaX: decide what to do with offenders (regs->nip = fault address)
9902 + *
9903 + * returns 1 when task should be killed
9904 + */
9905 +static int pax_handle_fetch_fault(struct pt_regs *regs)
9906 +{
9907 + return 1;
9908 +}
9909 +
9910 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
9911 +{
9912 + unsigned long i;
9913 +
9914 + printk(KERN_ERR "PAX: bytes at PC: ");
9915 + for (i = 0; i < 5; i++) {
9916 + unsigned int c;
9917 + if (get_user(c, (unsigned int __user *)pc+i))
9918 + printk(KERN_CONT "???????? ");
9919 + else
9920 + printk(KERN_CONT "%08x ", c);
9921 + }
9922 + printk("\n");
9923 +}
9924 +#endif
9925 +
9926 /*
9927 * Check whether the instruction at regs->nip is a store using
9928 * an update addressing form which will update r1.
9929 @@ -216,7 +247,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
9930 * indicate errors in DSISR but can validly be set in SRR1.
9931 */
9932 if (trap == 0x400)
9933 - error_code &= 0x48200000;
9934 + error_code &= 0x58200000;
9935 else
9936 is_write = error_code & DSISR_ISSTORE;
9937 #else
9938 @@ -378,7 +409,7 @@ good_area:
9939 * "undefined". Of those that can be set, this is the only
9940 * one which seems bad.
9941 */
9942 - if (error_code & 0x10000000)
9943 + if (error_code & DSISR_GUARDED)
9944 /* Guarded storage error. */
9945 goto bad_area;
9946 #endif /* CONFIG_8xx */
9947 @@ -393,7 +424,7 @@ good_area:
9948 * processors use the same I/D cache coherency mechanism
9949 * as embedded.
9950 */
9951 - if (error_code & DSISR_PROTFAULT)
9952 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
9953 goto bad_area;
9954 #endif /* CONFIG_PPC_STD_MMU */
9955
9956 @@ -483,6 +514,23 @@ bad_area:
9957 bad_area_nosemaphore:
9958 /* User mode accesses cause a SIGSEGV */
9959 if (user_mode(regs)) {
9960 +
9961 +#ifdef CONFIG_PAX_PAGEEXEC
9962 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
9963 +#ifdef CONFIG_PPC_STD_MMU
9964 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
9965 +#else
9966 + if (is_exec && regs->nip == address) {
9967 +#endif
9968 + switch (pax_handle_fetch_fault(regs)) {
9969 + }
9970 +
9971 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
9972 + do_group_exit(SIGKILL);
9973 + }
9974 + }
9975 +#endif
9976 +
9977 _exception(SIGSEGV, regs, code, address);
9978 goto bail;
9979 }
9980 diff --git a/arch/powerpc/mm/mmap.c b/arch/powerpc/mm/mmap.c
9981 index cb8bdbe..cde4bc7 100644
9982 --- a/arch/powerpc/mm/mmap.c
9983 +++ b/arch/powerpc/mm/mmap.c
9984 @@ -53,10 +53,14 @@ static inline int mmap_is_legacy(void)
9985 return sysctl_legacy_va_layout;
9986 }
9987
9988 -static unsigned long mmap_rnd(void)
9989 +static unsigned long mmap_rnd(struct mm_struct *mm)
9990 {
9991 unsigned long rnd = 0;
9992
9993 +#ifdef CONFIG_PAX_RANDMMAP
9994 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9995 +#endif
9996 +
9997 if (current->flags & PF_RANDOMIZE) {
9998 /* 8MB for 32bit, 1GB for 64bit */
9999 if (is_32bit_task())
10000 @@ -67,7 +71,7 @@ static unsigned long mmap_rnd(void)
10001 return rnd << PAGE_SHIFT;
10002 }
10003
10004 -static inline unsigned long mmap_base(void)
10005 +static inline unsigned long mmap_base(struct mm_struct *mm)
10006 {
10007 unsigned long gap = rlimit(RLIMIT_STACK);
10008
10009 @@ -76,7 +80,7 @@ static inline unsigned long mmap_base(void)
10010 else if (gap > MAX_GAP)
10011 gap = MAX_GAP;
10012
10013 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
10014 + return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd(mm));
10015 }
10016
10017 /*
10018 @@ -91,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10019 */
10020 if (mmap_is_legacy()) {
10021 mm->mmap_base = TASK_UNMAPPED_BASE;
10022 +
10023 +#ifdef CONFIG_PAX_RANDMMAP
10024 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10025 + mm->mmap_base += mm->delta_mmap;
10026 +#endif
10027 +
10028 mm->get_unmapped_area = arch_get_unmapped_area;
10029 } else {
10030 - mm->mmap_base = mmap_base();
10031 + mm->mmap_base = mmap_base(mm);
10032 +
10033 +#ifdef CONFIG_PAX_RANDMMAP
10034 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10035 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
10036 +#endif
10037 +
10038 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
10039 }
10040 }
10041 diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
10042 index b0c75cc..ef7fb93 100644
10043 --- a/arch/powerpc/mm/slice.c
10044 +++ b/arch/powerpc/mm/slice.c
10045 @@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
10046 if ((mm->task_size - len) < addr)
10047 return 0;
10048 vma = find_vma(mm, addr);
10049 - return (!vma || (addr + len) <= vma->vm_start);
10050 + return check_heap_stack_gap(vma, addr, len, 0);
10051 }
10052
10053 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
10054 @@ -277,6 +277,12 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm,
10055 info.align_offset = 0;
10056
10057 addr = TASK_UNMAPPED_BASE;
10058 +
10059 +#ifdef CONFIG_PAX_RANDMMAP
10060 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10061 + addr += mm->delta_mmap;
10062 +#endif
10063 +
10064 while (addr < TASK_SIZE) {
10065 info.low_limit = addr;
10066 if (!slice_scan_available(addr, available, 1, &addr))
10067 @@ -410,6 +416,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
10068 if (fixed && addr > (mm->task_size - len))
10069 return -ENOMEM;
10070
10071 +#ifdef CONFIG_PAX_RANDMMAP
10072 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
10073 + addr = 0;
10074 +#endif
10075 +
10076 /* If hint, make sure it matches our alignment restrictions */
10077 if (!fixed && addr) {
10078 addr = _ALIGN_UP(addr, 1ul << pshift);
10079 diff --git a/arch/powerpc/net/bpf_jit_comp.c b/arch/powerpc/net/bpf_jit_comp.c
10080 index 3afa6f4..40c53ff 100644
10081 --- a/arch/powerpc/net/bpf_jit_comp.c
10082 +++ b/arch/powerpc/net/bpf_jit_comp.c
10083 @@ -697,5 +697,6 @@ void bpf_jit_free(struct bpf_prog *fp)
10084 {
10085 if (fp->jited)
10086 module_free(NULL, fp->bpf_func);
10087 - kfree(fp);
10088 +
10089 + bpf_prog_unlock_free(fp);
10090 }
10091 diff --git a/arch/powerpc/platforms/cell/celleb_scc_pciex.c b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
10092 index 4278acf..67fd0e6 100644
10093 --- a/arch/powerpc/platforms/cell/celleb_scc_pciex.c
10094 +++ b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
10095 @@ -400,8 +400,8 @@ static int scc_pciex_write_config(struct pci_bus *bus, unsigned int devfn,
10096 }
10097
10098 static struct pci_ops scc_pciex_pci_ops = {
10099 - scc_pciex_read_config,
10100 - scc_pciex_write_config,
10101 + .read = scc_pciex_read_config,
10102 + .write = scc_pciex_write_config,
10103 };
10104
10105 static void pciex_clear_intr_all(unsigned int __iomem *base)
10106 diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
10107 index d966bbe..372124a 100644
10108 --- a/arch/powerpc/platforms/cell/spufs/file.c
10109 +++ b/arch/powerpc/platforms/cell/spufs/file.c
10110 @@ -280,9 +280,9 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
10111 return VM_FAULT_NOPAGE;
10112 }
10113
10114 -static int spufs_mem_mmap_access(struct vm_area_struct *vma,
10115 +static ssize_t spufs_mem_mmap_access(struct vm_area_struct *vma,
10116 unsigned long address,
10117 - void *buf, int len, int write)
10118 + void *buf, size_t len, int write)
10119 {
10120 struct spu_context *ctx = vma->vm_file->private_data;
10121 unsigned long offset = address - vma->vm_start;
10122 diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
10123 index fa934fe..c296056 100644
10124 --- a/arch/s390/include/asm/atomic.h
10125 +++ b/arch/s390/include/asm/atomic.h
10126 @@ -412,4 +412,14 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
10127 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
10128 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
10129
10130 +#define atomic64_read_unchecked(v) atomic64_read(v)
10131 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
10132 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
10133 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
10134 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
10135 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
10136 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
10137 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
10138 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
10139 +
10140 #endif /* __ARCH_S390_ATOMIC__ */
10141 diff --git a/arch/s390/include/asm/barrier.h b/arch/s390/include/asm/barrier.h
10142 index 19ff956..8d39cb1 100644
10143 --- a/arch/s390/include/asm/barrier.h
10144 +++ b/arch/s390/include/asm/barrier.h
10145 @@ -37,7 +37,7 @@
10146 do { \
10147 compiletime_assert_atomic_type(*p); \
10148 barrier(); \
10149 - ACCESS_ONCE(*p) = (v); \
10150 + ACCESS_ONCE_RW(*p) = (v); \
10151 } while (0)
10152
10153 #define smp_load_acquire(p) \
10154 diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
10155 index 4d7ccac..d03d0ad 100644
10156 --- a/arch/s390/include/asm/cache.h
10157 +++ b/arch/s390/include/asm/cache.h
10158 @@ -9,8 +9,10 @@
10159 #ifndef __ARCH_S390_CACHE_H
10160 #define __ARCH_S390_CACHE_H
10161
10162 -#define L1_CACHE_BYTES 256
10163 +#include <linux/const.h>
10164 +
10165 #define L1_CACHE_SHIFT 8
10166 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10167 #define NET_SKB_PAD 32
10168
10169 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
10170 diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
10171 index 78f4f87..598ce39 100644
10172 --- a/arch/s390/include/asm/elf.h
10173 +++ b/arch/s390/include/asm/elf.h
10174 @@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
10175 the loader. We need to make sure that it is out of the way of the program
10176 that it will "exec", and that there is sufficient room for the brk. */
10177
10178 -extern unsigned long randomize_et_dyn(unsigned long base);
10179 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
10180 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
10181 +
10182 +#ifdef CONFIG_PAX_ASLR
10183 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
10184 +
10185 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
10186 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
10187 +#endif
10188
10189 /* This yields a mask that user programs can use to figure out what
10190 instruction set this CPU supports. */
10191 @@ -222,9 +228,6 @@ struct linux_binprm;
10192 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
10193 int arch_setup_additional_pages(struct linux_binprm *, int);
10194
10195 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
10196 -#define arch_randomize_brk arch_randomize_brk
10197 -
10198 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
10199
10200 #endif
10201 diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
10202 index c4a93d6..4d2a9b4 100644
10203 --- a/arch/s390/include/asm/exec.h
10204 +++ b/arch/s390/include/asm/exec.h
10205 @@ -7,6 +7,6 @@
10206 #ifndef __ASM_EXEC_H
10207 #define __ASM_EXEC_H
10208
10209 -extern unsigned long arch_align_stack(unsigned long sp);
10210 +#define arch_align_stack(x) ((x) & ~0xfUL)
10211
10212 #endif /* __ASM_EXEC_H */
10213 diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
10214 index cd4c68e..6764641 100644
10215 --- a/arch/s390/include/asm/uaccess.h
10216 +++ b/arch/s390/include/asm/uaccess.h
10217 @@ -59,6 +59,7 @@ static inline int __range_ok(unsigned long addr, unsigned long size)
10218 __range_ok((unsigned long)(addr), (size)); \
10219 })
10220
10221 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
10222 #define access_ok(type, addr, size) __access_ok(addr, size)
10223
10224 /*
10225 @@ -275,6 +276,10 @@ static inline unsigned long __must_check
10226 copy_to_user(void __user *to, const void *from, unsigned long n)
10227 {
10228 might_fault();
10229 +
10230 + if ((long)n < 0)
10231 + return n;
10232 +
10233 return __copy_to_user(to, from, n);
10234 }
10235
10236 @@ -303,10 +308,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
10237 static inline unsigned long __must_check
10238 copy_from_user(void *to, const void __user *from, unsigned long n)
10239 {
10240 - unsigned int sz = __compiletime_object_size(to);
10241 + size_t sz = __compiletime_object_size(to);
10242
10243 might_fault();
10244 - if (unlikely(sz != -1 && sz < n)) {
10245 +
10246 + if ((long)n < 0)
10247 + return n;
10248 +
10249 + if (unlikely(sz != (size_t)-1 && sz < n)) {
10250 copy_from_user_overflow();
10251 return n;
10252 }
10253 diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
10254 index b89b591..fd9609d 100644
10255 --- a/arch/s390/kernel/module.c
10256 +++ b/arch/s390/kernel/module.c
10257 @@ -169,11 +169,11 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
10258
10259 /* Increase core size by size of got & plt and set start
10260 offsets for got and plt. */
10261 - me->core_size = ALIGN(me->core_size, 4);
10262 - me->arch.got_offset = me->core_size;
10263 - me->core_size += me->arch.got_size;
10264 - me->arch.plt_offset = me->core_size;
10265 - me->core_size += me->arch.plt_size;
10266 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
10267 + me->arch.got_offset = me->core_size_rw;
10268 + me->core_size_rw += me->arch.got_size;
10269 + me->arch.plt_offset = me->core_size_rx;
10270 + me->core_size_rx += me->arch.plt_size;
10271 return 0;
10272 }
10273
10274 @@ -289,7 +289,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
10275 if (info->got_initialized == 0) {
10276 Elf_Addr *gotent;
10277
10278 - gotent = me->module_core + me->arch.got_offset +
10279 + gotent = me->module_core_rw + me->arch.got_offset +
10280 info->got_offset;
10281 *gotent = val;
10282 info->got_initialized = 1;
10283 @@ -312,7 +312,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
10284 rc = apply_rela_bits(loc, val, 0, 64, 0);
10285 else if (r_type == R_390_GOTENT ||
10286 r_type == R_390_GOTPLTENT) {
10287 - val += (Elf_Addr) me->module_core - loc;
10288 + val += (Elf_Addr) me->module_core_rw - loc;
10289 rc = apply_rela_bits(loc, val, 1, 32, 1);
10290 }
10291 break;
10292 @@ -325,7 +325,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
10293 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
10294 if (info->plt_initialized == 0) {
10295 unsigned int *ip;
10296 - ip = me->module_core + me->arch.plt_offset +
10297 + ip = me->module_core_rx + me->arch.plt_offset +
10298 info->plt_offset;
10299 #ifndef CONFIG_64BIT
10300 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
10301 @@ -350,7 +350,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
10302 val - loc + 0xffffUL < 0x1ffffeUL) ||
10303 (r_type == R_390_PLT32DBL &&
10304 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
10305 - val = (Elf_Addr) me->module_core +
10306 + val = (Elf_Addr) me->module_core_rx +
10307 me->arch.plt_offset +
10308 info->plt_offset;
10309 val += rela->r_addend - loc;
10310 @@ -372,7 +372,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
10311 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
10312 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
10313 val = val + rela->r_addend -
10314 - ((Elf_Addr) me->module_core + me->arch.got_offset);
10315 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
10316 if (r_type == R_390_GOTOFF16)
10317 rc = apply_rela_bits(loc, val, 0, 16, 0);
10318 else if (r_type == R_390_GOTOFF32)
10319 @@ -382,7 +382,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
10320 break;
10321 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
10322 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
10323 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
10324 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
10325 rela->r_addend - loc;
10326 if (r_type == R_390_GOTPC)
10327 rc = apply_rela_bits(loc, val, 1, 32, 0);
10328 diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
10329 index 93b9ca4..4ea1454 100644
10330 --- a/arch/s390/kernel/process.c
10331 +++ b/arch/s390/kernel/process.c
10332 @@ -242,37 +242,3 @@ unsigned long get_wchan(struct task_struct *p)
10333 }
10334 return 0;
10335 }
10336 -
10337 -unsigned long arch_align_stack(unsigned long sp)
10338 -{
10339 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
10340 - sp -= get_random_int() & ~PAGE_MASK;
10341 - return sp & ~0xf;
10342 -}
10343 -
10344 -static inline unsigned long brk_rnd(void)
10345 -{
10346 - /* 8MB for 32bit, 1GB for 64bit */
10347 - if (is_32bit_task())
10348 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
10349 - else
10350 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
10351 -}
10352 -
10353 -unsigned long arch_randomize_brk(struct mm_struct *mm)
10354 -{
10355 - unsigned long ret;
10356 -
10357 - ret = PAGE_ALIGN(mm->brk + brk_rnd());
10358 - return (ret > mm->brk) ? ret : mm->brk;
10359 -}
10360 -
10361 -unsigned long randomize_et_dyn(unsigned long base)
10362 -{
10363 - unsigned long ret;
10364 -
10365 - if (!(current->flags & PF_RANDOMIZE))
10366 - return base;
10367 - ret = PAGE_ALIGN(base + brk_rnd());
10368 - return (ret > base) ? ret : base;
10369 -}
10370 diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
10371 index 9b436c2..54fbf0a 100644
10372 --- a/arch/s390/mm/mmap.c
10373 +++ b/arch/s390/mm/mmap.c
10374 @@ -95,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10375 */
10376 if (mmap_is_legacy()) {
10377 mm->mmap_base = mmap_base_legacy();
10378 +
10379 +#ifdef CONFIG_PAX_RANDMMAP
10380 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10381 + mm->mmap_base += mm->delta_mmap;
10382 +#endif
10383 +
10384 mm->get_unmapped_area = arch_get_unmapped_area;
10385 } else {
10386 mm->mmap_base = mmap_base();
10387 +
10388 +#ifdef CONFIG_PAX_RANDMMAP
10389 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10390 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
10391 +#endif
10392 +
10393 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
10394 }
10395 }
10396 @@ -170,9 +182,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10397 */
10398 if (mmap_is_legacy()) {
10399 mm->mmap_base = mmap_base_legacy();
10400 +
10401 +#ifdef CONFIG_PAX_RANDMMAP
10402 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10403 + mm->mmap_base += mm->delta_mmap;
10404 +#endif
10405 +
10406 mm->get_unmapped_area = s390_get_unmapped_area;
10407 } else {
10408 mm->mmap_base = mmap_base();
10409 +
10410 +#ifdef CONFIG_PAX_RANDMMAP
10411 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10412 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
10413 +#endif
10414 +
10415 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
10416 }
10417 }
10418 diff --git a/arch/s390/net/bpf_jit_comp.c b/arch/s390/net/bpf_jit_comp.c
10419 index 61e45b7..f2833c5 100644
10420 --- a/arch/s390/net/bpf_jit_comp.c
10421 +++ b/arch/s390/net/bpf_jit_comp.c
10422 @@ -887,5 +887,5 @@ void bpf_jit_free(struct bpf_prog *fp)
10423 module_free(NULL, header);
10424
10425 free_filter:
10426 - kfree(fp);
10427 + bpf_prog_unlock_free(fp);
10428 }
10429 diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
10430 index ae3d59f..f65f075 100644
10431 --- a/arch/score/include/asm/cache.h
10432 +++ b/arch/score/include/asm/cache.h
10433 @@ -1,7 +1,9 @@
10434 #ifndef _ASM_SCORE_CACHE_H
10435 #define _ASM_SCORE_CACHE_H
10436
10437 +#include <linux/const.h>
10438 +
10439 #define L1_CACHE_SHIFT 4
10440 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10441 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10442
10443 #endif /* _ASM_SCORE_CACHE_H */
10444 diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
10445 index f9f3cd5..58ff438 100644
10446 --- a/arch/score/include/asm/exec.h
10447 +++ b/arch/score/include/asm/exec.h
10448 @@ -1,6 +1,6 @@
10449 #ifndef _ASM_SCORE_EXEC_H
10450 #define _ASM_SCORE_EXEC_H
10451
10452 -extern unsigned long arch_align_stack(unsigned long sp);
10453 +#define arch_align_stack(x) (x)
10454
10455 #endif /* _ASM_SCORE_EXEC_H */
10456 diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
10457 index a1519ad3..e8ac1ff 100644
10458 --- a/arch/score/kernel/process.c
10459 +++ b/arch/score/kernel/process.c
10460 @@ -116,8 +116,3 @@ unsigned long get_wchan(struct task_struct *task)
10461
10462 return task_pt_regs(task)->cp0_epc;
10463 }
10464 -
10465 -unsigned long arch_align_stack(unsigned long sp)
10466 -{
10467 - return sp;
10468 -}
10469 diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
10470 index ef9e555..331bd29 100644
10471 --- a/arch/sh/include/asm/cache.h
10472 +++ b/arch/sh/include/asm/cache.h
10473 @@ -9,10 +9,11 @@
10474 #define __ASM_SH_CACHE_H
10475 #ifdef __KERNEL__
10476
10477 +#include <linux/const.h>
10478 #include <linux/init.h>
10479 #include <cpu/cache.h>
10480
10481 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10482 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10483
10484 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
10485
10486 diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
10487 index 6777177..cb5e44f 100644
10488 --- a/arch/sh/mm/mmap.c
10489 +++ b/arch/sh/mm/mmap.c
10490 @@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
10491 struct mm_struct *mm = current->mm;
10492 struct vm_area_struct *vma;
10493 int do_colour_align;
10494 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10495 struct vm_unmapped_area_info info;
10496
10497 if (flags & MAP_FIXED) {
10498 @@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
10499 if (filp || (flags & MAP_SHARED))
10500 do_colour_align = 1;
10501
10502 +#ifdef CONFIG_PAX_RANDMMAP
10503 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10504 +#endif
10505 +
10506 if (addr) {
10507 if (do_colour_align)
10508 addr = COLOUR_ALIGN(addr, pgoff);
10509 @@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
10510 addr = PAGE_ALIGN(addr);
10511
10512 vma = find_vma(mm, addr);
10513 - if (TASK_SIZE - len >= addr &&
10514 - (!vma || addr + len <= vma->vm_start))
10515 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10516 return addr;
10517 }
10518
10519 info.flags = 0;
10520 info.length = len;
10521 - info.low_limit = TASK_UNMAPPED_BASE;
10522 + info.low_limit = mm->mmap_base;
10523 info.high_limit = TASK_SIZE;
10524 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
10525 info.align_offset = pgoff << PAGE_SHIFT;
10526 @@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10527 struct mm_struct *mm = current->mm;
10528 unsigned long addr = addr0;
10529 int do_colour_align;
10530 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10531 struct vm_unmapped_area_info info;
10532
10533 if (flags & MAP_FIXED) {
10534 @@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10535 if (filp || (flags & MAP_SHARED))
10536 do_colour_align = 1;
10537
10538 +#ifdef CONFIG_PAX_RANDMMAP
10539 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10540 +#endif
10541 +
10542 /* requesting a specific address */
10543 if (addr) {
10544 if (do_colour_align)
10545 @@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10546 addr = PAGE_ALIGN(addr);
10547
10548 vma = find_vma(mm, addr);
10549 - if (TASK_SIZE - len >= addr &&
10550 - (!vma || addr + len <= vma->vm_start))
10551 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10552 return addr;
10553 }
10554
10555 @@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10556 VM_BUG_ON(addr != -ENOMEM);
10557 info.flags = 0;
10558 info.low_limit = TASK_UNMAPPED_BASE;
10559 +
10560 +#ifdef CONFIG_PAX_RANDMMAP
10561 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10562 + info.low_limit += mm->delta_mmap;
10563 +#endif
10564 +
10565 info.high_limit = TASK_SIZE;
10566 addr = vm_unmapped_area(&info);
10567 }
10568 diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
10569 index bb894c8..81b82e9 100644
10570 --- a/arch/sparc/include/asm/atomic_64.h
10571 +++ b/arch/sparc/include/asm/atomic_64.h
10572 @@ -15,18 +15,40 @@
10573 #define ATOMIC64_INIT(i) { (i) }
10574
10575 #define atomic_read(v) (*(volatile int *)&(v)->counter)
10576 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
10577 +{
10578 + return *(const volatile int *)&v->counter;
10579 +}
10580 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
10581 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
10582 +{
10583 + return *(const volatile long *)&v->counter;
10584 +}
10585
10586 #define atomic_set(v, i) (((v)->counter) = i)
10587 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
10588 +{
10589 + v->counter = i;
10590 +}
10591 #define atomic64_set(v, i) (((v)->counter) = i)
10592 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
10593 +{
10594 + v->counter = i;
10595 +}
10596
10597 void atomic_add(int, atomic_t *);
10598 +void atomic_add_unchecked(int, atomic_unchecked_t *);
10599 void atomic64_add(long, atomic64_t *);
10600 +void atomic64_add_unchecked(long, atomic64_unchecked_t *);
10601 void atomic_sub(int, atomic_t *);
10602 +void atomic_sub_unchecked(int, atomic_unchecked_t *);
10603 void atomic64_sub(long, atomic64_t *);
10604 +void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
10605
10606 int atomic_add_ret(int, atomic_t *);
10607 +int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
10608 long atomic64_add_ret(long, atomic64_t *);
10609 +long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
10610 int atomic_sub_ret(int, atomic_t *);
10611 long atomic64_sub_ret(long, atomic64_t *);
10612
10613 @@ -34,13 +56,29 @@ long atomic64_sub_ret(long, atomic64_t *);
10614 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
10615
10616 #define atomic_inc_return(v) atomic_add_ret(1, v)
10617 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
10618 +{
10619 + return atomic_add_ret_unchecked(1, v);
10620 +}
10621 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
10622 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
10623 +{
10624 + return atomic64_add_ret_unchecked(1, v);
10625 +}
10626
10627 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
10628 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
10629
10630 #define atomic_add_return(i, v) atomic_add_ret(i, v)
10631 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
10632 +{
10633 + return atomic_add_ret_unchecked(i, v);
10634 +}
10635 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
10636 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
10637 +{
10638 + return atomic64_add_ret_unchecked(i, v);
10639 +}
10640
10641 /*
10642 * atomic_inc_and_test - increment and test
10643 @@ -51,6 +89,10 @@ long atomic64_sub_ret(long, atomic64_t *);
10644 * other cases.
10645 */
10646 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
10647 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
10648 +{
10649 + return atomic_inc_return_unchecked(v) == 0;
10650 +}
10651 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
10652
10653 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
10654 @@ -60,25 +102,60 @@ long atomic64_sub_ret(long, atomic64_t *);
10655 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
10656
10657 #define atomic_inc(v) atomic_add(1, v)
10658 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
10659 +{
10660 + atomic_add_unchecked(1, v);
10661 +}
10662 #define atomic64_inc(v) atomic64_add(1, v)
10663 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
10664 +{
10665 + atomic64_add_unchecked(1, v);
10666 +}
10667
10668 #define atomic_dec(v) atomic_sub(1, v)
10669 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
10670 +{
10671 + atomic_sub_unchecked(1, v);
10672 +}
10673 #define atomic64_dec(v) atomic64_sub(1, v)
10674 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
10675 +{
10676 + atomic64_sub_unchecked(1, v);
10677 +}
10678
10679 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
10680 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
10681
10682 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
10683 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
10684 +{
10685 + return cmpxchg(&v->counter, old, new);
10686 +}
10687 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
10688 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
10689 +{
10690 + return xchg(&v->counter, new);
10691 +}
10692
10693 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
10694 {
10695 - int c, old;
10696 + int c, old, new;
10697 c = atomic_read(v);
10698 for (;;) {
10699 - if (unlikely(c == (u)))
10700 + if (unlikely(c == u))
10701 break;
10702 - old = atomic_cmpxchg((v), c, c + (a));
10703 +
10704 + asm volatile("addcc %2, %0, %0\n"
10705 +
10706 +#ifdef CONFIG_PAX_REFCOUNT
10707 + "tvs %%icc, 6\n"
10708 +#endif
10709 +
10710 + : "=r" (new)
10711 + : "0" (c), "ir" (a)
10712 + : "cc");
10713 +
10714 + old = atomic_cmpxchg(v, c, new);
10715 if (likely(old == c))
10716 break;
10717 c = old;
10718 @@ -89,20 +166,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
10719 #define atomic64_cmpxchg(v, o, n) \
10720 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
10721 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
10722 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
10723 +{
10724 + return xchg(&v->counter, new);
10725 +}
10726
10727 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
10728 {
10729 - long c, old;
10730 + long c, old, new;
10731 c = atomic64_read(v);
10732 for (;;) {
10733 - if (unlikely(c == (u)))
10734 + if (unlikely(c == u))
10735 break;
10736 - old = atomic64_cmpxchg((v), c, c + (a));
10737 +
10738 + asm volatile("addcc %2, %0, %0\n"
10739 +
10740 +#ifdef CONFIG_PAX_REFCOUNT
10741 + "tvs %%xcc, 6\n"
10742 +#endif
10743 +
10744 + : "=r" (new)
10745 + : "0" (c), "ir" (a)
10746 + : "cc");
10747 +
10748 + old = atomic64_cmpxchg(v, c, new);
10749 if (likely(old == c))
10750 break;
10751 c = old;
10752 }
10753 - return c != (u);
10754 + return c != u;
10755 }
10756
10757 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
10758 diff --git a/arch/sparc/include/asm/barrier_64.h b/arch/sparc/include/asm/barrier_64.h
10759 index 305dcc3..7835030 100644
10760 --- a/arch/sparc/include/asm/barrier_64.h
10761 +++ b/arch/sparc/include/asm/barrier_64.h
10762 @@ -57,7 +57,7 @@ do { __asm__ __volatile__("ba,pt %%xcc, 1f\n\t" \
10763 do { \
10764 compiletime_assert_atomic_type(*p); \
10765 barrier(); \
10766 - ACCESS_ONCE(*p) = (v); \
10767 + ACCESS_ONCE_RW(*p) = (v); \
10768 } while (0)
10769
10770 #define smp_load_acquire(p) \
10771 diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
10772 index 5bb6991..5c2132e 100644
10773 --- a/arch/sparc/include/asm/cache.h
10774 +++ b/arch/sparc/include/asm/cache.h
10775 @@ -7,10 +7,12 @@
10776 #ifndef _SPARC_CACHE_H
10777 #define _SPARC_CACHE_H
10778
10779 +#include <linux/const.h>
10780 +
10781 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
10782
10783 #define L1_CACHE_SHIFT 5
10784 -#define L1_CACHE_BYTES 32
10785 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10786
10787 #ifdef CONFIG_SPARC32
10788 #define SMP_CACHE_BYTES_SHIFT 5
10789 diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
10790 index a24e41f..47677ff 100644
10791 --- a/arch/sparc/include/asm/elf_32.h
10792 +++ b/arch/sparc/include/asm/elf_32.h
10793 @@ -114,6 +114,13 @@ typedef struct {
10794
10795 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
10796
10797 +#ifdef CONFIG_PAX_ASLR
10798 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
10799 +
10800 +#define PAX_DELTA_MMAP_LEN 16
10801 +#define PAX_DELTA_STACK_LEN 16
10802 +#endif
10803 +
10804 /* This yields a mask that user programs can use to figure out what
10805 instruction set this cpu supports. This can NOT be done in userspace
10806 on Sparc. */
10807 diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
10808 index 370ca1e..d4f4a98 100644
10809 --- a/arch/sparc/include/asm/elf_64.h
10810 +++ b/arch/sparc/include/asm/elf_64.h
10811 @@ -189,6 +189,13 @@ typedef struct {
10812 #define ELF_ET_DYN_BASE 0x0000010000000000UL
10813 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
10814
10815 +#ifdef CONFIG_PAX_ASLR
10816 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
10817 +
10818 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
10819 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
10820 +#endif
10821 +
10822 extern unsigned long sparc64_elf_hwcap;
10823 #define ELF_HWCAP sparc64_elf_hwcap
10824
10825 diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
10826 index a3890da..f6a408e 100644
10827 --- a/arch/sparc/include/asm/pgalloc_32.h
10828 +++ b/arch/sparc/include/asm/pgalloc_32.h
10829 @@ -35,6 +35,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
10830 }
10831
10832 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
10833 +#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
10834
10835 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
10836 unsigned long address)
10837 diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
10838 index 5e31871..13469c6 100644
10839 --- a/arch/sparc/include/asm/pgalloc_64.h
10840 +++ b/arch/sparc/include/asm/pgalloc_64.h
10841 @@ -21,6 +21,7 @@ static inline void __pgd_populate(pgd_t *pgd, pud_t *pud)
10842 }
10843
10844 #define pgd_populate(MM, PGD, PUD) __pgd_populate(PGD, PUD)
10845 +#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
10846
10847 static inline pgd_t *pgd_alloc(struct mm_struct *mm)
10848 {
10849 @@ -38,6 +39,7 @@ static inline void __pud_populate(pud_t *pud, pmd_t *pmd)
10850 }
10851
10852 #define pud_populate(MM, PUD, PMD) __pud_populate(PUD, PMD)
10853 +#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
10854
10855 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
10856 {
10857 diff --git a/arch/sparc/include/asm/pgtable.h b/arch/sparc/include/asm/pgtable.h
10858 index 59ba6f6..4518128 100644
10859 --- a/arch/sparc/include/asm/pgtable.h
10860 +++ b/arch/sparc/include/asm/pgtable.h
10861 @@ -5,4 +5,8 @@
10862 #else
10863 #include <asm/pgtable_32.h>
10864 #endif
10865 +
10866 +#define ktla_ktva(addr) (addr)
10867 +#define ktva_ktla(addr) (addr)
10868 +
10869 #endif
10870 diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
10871 index b9b91ae..950b91e 100644
10872 --- a/arch/sparc/include/asm/pgtable_32.h
10873 +++ b/arch/sparc/include/asm/pgtable_32.h
10874 @@ -51,6 +51,9 @@ unsigned long __init bootmem_init(unsigned long *pages_avail);
10875 #define PAGE_SHARED SRMMU_PAGE_SHARED
10876 #define PAGE_COPY SRMMU_PAGE_COPY
10877 #define PAGE_READONLY SRMMU_PAGE_RDONLY
10878 +#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
10879 +#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
10880 +#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
10881 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
10882
10883 /* Top-level page directory - dummy used by init-mm.
10884 @@ -63,18 +66,18 @@ extern unsigned long ptr_in_current_pgd;
10885
10886 /* xwr */
10887 #define __P000 PAGE_NONE
10888 -#define __P001 PAGE_READONLY
10889 -#define __P010 PAGE_COPY
10890 -#define __P011 PAGE_COPY
10891 +#define __P001 PAGE_READONLY_NOEXEC
10892 +#define __P010 PAGE_COPY_NOEXEC
10893 +#define __P011 PAGE_COPY_NOEXEC
10894 #define __P100 PAGE_READONLY
10895 #define __P101 PAGE_READONLY
10896 #define __P110 PAGE_COPY
10897 #define __P111 PAGE_COPY
10898
10899 #define __S000 PAGE_NONE
10900 -#define __S001 PAGE_READONLY
10901 -#define __S010 PAGE_SHARED
10902 -#define __S011 PAGE_SHARED
10903 +#define __S001 PAGE_READONLY_NOEXEC
10904 +#define __S010 PAGE_SHARED_NOEXEC
10905 +#define __S011 PAGE_SHARED_NOEXEC
10906 #define __S100 PAGE_READONLY
10907 #define __S101 PAGE_READONLY
10908 #define __S110 PAGE_SHARED
10909 diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
10910 index 79da178..c2eede8 100644
10911 --- a/arch/sparc/include/asm/pgtsrmmu.h
10912 +++ b/arch/sparc/include/asm/pgtsrmmu.h
10913 @@ -115,6 +115,11 @@
10914 SRMMU_EXEC | SRMMU_REF)
10915 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
10916 SRMMU_EXEC | SRMMU_REF)
10917 +
10918 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
10919 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
10920 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
10921 +
10922 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
10923 SRMMU_DIRTY | SRMMU_REF)
10924
10925 diff --git a/arch/sparc/include/asm/setup.h b/arch/sparc/include/asm/setup.h
10926 index 29d64b1..4272fe8 100644
10927 --- a/arch/sparc/include/asm/setup.h
10928 +++ b/arch/sparc/include/asm/setup.h
10929 @@ -55,8 +55,8 @@ int handle_ldf_stq(u32 insn, struct pt_regs *regs);
10930 void handle_ld_nf(u32 insn, struct pt_regs *regs);
10931
10932 /* init_64.c */
10933 -extern atomic_t dcpage_flushes;
10934 -extern atomic_t dcpage_flushes_xcall;
10935 +extern atomic_unchecked_t dcpage_flushes;
10936 +extern atomic_unchecked_t dcpage_flushes_xcall;
10937
10938 extern int sysctl_tsb_ratio;
10939 #endif
10940 diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
10941 index 9689176..63c18ea 100644
10942 --- a/arch/sparc/include/asm/spinlock_64.h
10943 +++ b/arch/sparc/include/asm/spinlock_64.h
10944 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
10945
10946 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
10947
10948 -static void inline arch_read_lock(arch_rwlock_t *lock)
10949 +static inline void arch_read_lock(arch_rwlock_t *lock)
10950 {
10951 unsigned long tmp1, tmp2;
10952
10953 __asm__ __volatile__ (
10954 "1: ldsw [%2], %0\n"
10955 " brlz,pn %0, 2f\n"
10956 -"4: add %0, 1, %1\n"
10957 +"4: addcc %0, 1, %1\n"
10958 +
10959 +#ifdef CONFIG_PAX_REFCOUNT
10960 +" tvs %%icc, 6\n"
10961 +#endif
10962 +
10963 " cas [%2], %0, %1\n"
10964 " cmp %0, %1\n"
10965 " bne,pn %%icc, 1b\n"
10966 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
10967 " .previous"
10968 : "=&r" (tmp1), "=&r" (tmp2)
10969 : "r" (lock)
10970 - : "memory");
10971 + : "memory", "cc");
10972 }
10973
10974 -static int inline arch_read_trylock(arch_rwlock_t *lock)
10975 +static inline int arch_read_trylock(arch_rwlock_t *lock)
10976 {
10977 int tmp1, tmp2;
10978
10979 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
10980 "1: ldsw [%2], %0\n"
10981 " brlz,a,pn %0, 2f\n"
10982 " mov 0, %0\n"
10983 -" add %0, 1, %1\n"
10984 +" addcc %0, 1, %1\n"
10985 +
10986 +#ifdef CONFIG_PAX_REFCOUNT
10987 +" tvs %%icc, 6\n"
10988 +#endif
10989 +
10990 " cas [%2], %0, %1\n"
10991 " cmp %0, %1\n"
10992 " bne,pn %%icc, 1b\n"
10993 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
10994 return tmp1;
10995 }
10996
10997 -static void inline arch_read_unlock(arch_rwlock_t *lock)
10998 +static inline void arch_read_unlock(arch_rwlock_t *lock)
10999 {
11000 unsigned long tmp1, tmp2;
11001
11002 __asm__ __volatile__(
11003 "1: lduw [%2], %0\n"
11004 -" sub %0, 1, %1\n"
11005 +" subcc %0, 1, %1\n"
11006 +
11007 +#ifdef CONFIG_PAX_REFCOUNT
11008 +" tvs %%icc, 6\n"
11009 +#endif
11010 +
11011 " cas [%2], %0, %1\n"
11012 " cmp %0, %1\n"
11013 " bne,pn %%xcc, 1b\n"
11014 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
11015 : "memory");
11016 }
11017
11018 -static void inline arch_write_lock(arch_rwlock_t *lock)
11019 +static inline void arch_write_lock(arch_rwlock_t *lock)
11020 {
11021 unsigned long mask, tmp1, tmp2;
11022
11023 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
11024 : "memory");
11025 }
11026
11027 -static void inline arch_write_unlock(arch_rwlock_t *lock)
11028 +static inline void arch_write_unlock(arch_rwlock_t *lock)
11029 {
11030 __asm__ __volatile__(
11031 " stw %%g0, [%0]"
11032 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
11033 : "memory");
11034 }
11035
11036 -static int inline arch_write_trylock(arch_rwlock_t *lock)
11037 +static inline int arch_write_trylock(arch_rwlock_t *lock)
11038 {
11039 unsigned long mask, tmp1, tmp2, result;
11040
11041 diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
11042 index 96efa7a..16858bf 100644
11043 --- a/arch/sparc/include/asm/thread_info_32.h
11044 +++ b/arch/sparc/include/asm/thread_info_32.h
11045 @@ -49,6 +49,8 @@ struct thread_info {
11046 unsigned long w_saved;
11047
11048 struct restart_block restart_block;
11049 +
11050 + unsigned long lowest_stack;
11051 };
11052
11053 /*
11054 diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
11055 index cc6275c..7eb8e21 100644
11056 --- a/arch/sparc/include/asm/thread_info_64.h
11057 +++ b/arch/sparc/include/asm/thread_info_64.h
11058 @@ -63,6 +63,8 @@ struct thread_info {
11059 struct pt_regs *kern_una_regs;
11060 unsigned int kern_una_insn;
11061
11062 + unsigned long lowest_stack;
11063 +
11064 unsigned long fpregs[(7 * 256) / sizeof(unsigned long)]
11065 __attribute__ ((aligned(64)));
11066 };
11067 @@ -190,12 +192,13 @@ register struct thread_info *current_thread_info_reg asm("g6");
11068 #define TIF_NEED_RESCHED 3 /* rescheduling necessary */
11069 /* flag bit 4 is available */
11070 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
11071 -/* flag bit 6 is available */
11072 +#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
11073 #define TIF_32BIT 7 /* 32-bit binary */
11074 #define TIF_NOHZ 8 /* in adaptive nohz mode */
11075 #define TIF_SECCOMP 9 /* secure computing */
11076 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
11077 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
11078 +
11079 /* NOTE: Thread flags >= 12 should be ones we have no interest
11080 * in using in assembly, else we can't use the mask as
11081 * an immediate value in instructions such as andcc.
11082 @@ -215,12 +218,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
11083 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
11084 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
11085 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
11086 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
11087
11088 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
11089 _TIF_DO_NOTIFY_RESUME_MASK | \
11090 _TIF_NEED_RESCHED)
11091 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
11092
11093 +#define _TIF_WORK_SYSCALL \
11094 + (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
11095 + _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
11096 +
11097 +
11098 /*
11099 * Thread-synchronous status.
11100 *
11101 diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
11102 index bd56c28..4b63d83 100644
11103 --- a/arch/sparc/include/asm/uaccess.h
11104 +++ b/arch/sparc/include/asm/uaccess.h
11105 @@ -1,5 +1,6 @@
11106 #ifndef ___ASM_SPARC_UACCESS_H
11107 #define ___ASM_SPARC_UACCESS_H
11108 +
11109 #if defined(__sparc__) && defined(__arch64__)
11110 #include <asm/uaccess_64.h>
11111 #else
11112 diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
11113 index 9634d08..f55fe4f 100644
11114 --- a/arch/sparc/include/asm/uaccess_32.h
11115 +++ b/arch/sparc/include/asm/uaccess_32.h
11116 @@ -250,27 +250,46 @@ unsigned long __copy_user(void __user *to, const void __user *from, unsigned lon
11117
11118 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
11119 {
11120 - if (n && __access_ok((unsigned long) to, n))
11121 + if ((long)n < 0)
11122 + return n;
11123 +
11124 + if (n && __access_ok((unsigned long) to, n)) {
11125 + if (!__builtin_constant_p(n))
11126 + check_object_size(from, n, true);
11127 return __copy_user(to, (__force void __user *) from, n);
11128 - else
11129 + } else
11130 return n;
11131 }
11132
11133 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
11134 {
11135 + if ((long)n < 0)
11136 + return n;
11137 +
11138 + if (!__builtin_constant_p(n))
11139 + check_object_size(from, n, true);
11140 +
11141 return __copy_user(to, (__force void __user *) from, n);
11142 }
11143
11144 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
11145 {
11146 - if (n && __access_ok((unsigned long) from, n))
11147 + if ((long)n < 0)
11148 + return n;
11149 +
11150 + if (n && __access_ok((unsigned long) from, n)) {
11151 + if (!__builtin_constant_p(n))
11152 + check_object_size(to, n, false);
11153 return __copy_user((__force void __user *) to, from, n);
11154 - else
11155 + } else
11156 return n;
11157 }
11158
11159 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
11160 {
11161 + if ((long)n < 0)
11162 + return n;
11163 +
11164 return __copy_user((__force void __user *) to, from, n);
11165 }
11166
11167 diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
11168 index c990a5e..f17b9c1 100644
11169 --- a/arch/sparc/include/asm/uaccess_64.h
11170 +++ b/arch/sparc/include/asm/uaccess_64.h
11171 @@ -10,6 +10,7 @@
11172 #include <linux/compiler.h>
11173 #include <linux/string.h>
11174 #include <linux/thread_info.h>
11175 +#include <linux/kernel.h>
11176 #include <asm/asi.h>
11177 #include <asm/spitfire.h>
11178 #include <asm-generic/uaccess-unaligned.h>
11179 @@ -214,8 +215,15 @@ unsigned long copy_from_user_fixup(void *to, const void __user *from,
11180 static inline unsigned long __must_check
11181 copy_from_user(void *to, const void __user *from, unsigned long size)
11182 {
11183 - unsigned long ret = ___copy_from_user(to, from, size);
11184 + unsigned long ret;
11185
11186 + if ((long)size < 0 || size > INT_MAX)
11187 + return size;
11188 +
11189 + if (!__builtin_constant_p(size))
11190 + check_object_size(to, size, false);
11191 +
11192 + ret = ___copy_from_user(to, from, size);
11193 if (unlikely(ret))
11194 ret = copy_from_user_fixup(to, from, size);
11195
11196 @@ -231,8 +239,15 @@ unsigned long copy_to_user_fixup(void __user *to, const void *from,
11197 static inline unsigned long __must_check
11198 copy_to_user(void __user *to, const void *from, unsigned long size)
11199 {
11200 - unsigned long ret = ___copy_to_user(to, from, size);
11201 + unsigned long ret;
11202
11203 + if ((long)size < 0 || size > INT_MAX)
11204 + return size;
11205 +
11206 + if (!__builtin_constant_p(size))
11207 + check_object_size(from, size, true);
11208 +
11209 + ret = ___copy_to_user(to, from, size);
11210 if (unlikely(ret))
11211 ret = copy_to_user_fixup(to, from, size);
11212 return ret;
11213 diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
11214 index 7cf9c6e..6206648 100644
11215 --- a/arch/sparc/kernel/Makefile
11216 +++ b/arch/sparc/kernel/Makefile
11217 @@ -4,7 +4,7 @@
11218 #
11219
11220 asflags-y := -ansi
11221 -ccflags-y := -Werror
11222 +#ccflags-y := -Werror
11223
11224 extra-y := head_$(BITS).o
11225
11226 diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
11227 index 50e7b62..79fae35 100644
11228 --- a/arch/sparc/kernel/process_32.c
11229 +++ b/arch/sparc/kernel/process_32.c
11230 @@ -123,14 +123,14 @@ void show_regs(struct pt_regs *r)
11231
11232 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
11233 r->psr, r->pc, r->npc, r->y, print_tainted());
11234 - printk("PC: <%pS>\n", (void *) r->pc);
11235 + printk("PC: <%pA>\n", (void *) r->pc);
11236 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
11237 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
11238 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
11239 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
11240 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
11241 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
11242 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
11243 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
11244
11245 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
11246 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
11247 @@ -167,7 +167,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
11248 rw = (struct reg_window32 *) fp;
11249 pc = rw->ins[7];
11250 printk("[%08lx : ", pc);
11251 - printk("%pS ] ", (void *) pc);
11252 + printk("%pA ] ", (void *) pc);
11253 fp = rw->ins[6];
11254 } while (++count < 16);
11255 printk("\n");
11256 diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
11257 index 0be7bf9..2b1cba8 100644
11258 --- a/arch/sparc/kernel/process_64.c
11259 +++ b/arch/sparc/kernel/process_64.c
11260 @@ -161,7 +161,7 @@ static void show_regwindow(struct pt_regs *regs)
11261 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
11262 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
11263 if (regs->tstate & TSTATE_PRIV)
11264 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
11265 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
11266 }
11267
11268 void show_regs(struct pt_regs *regs)
11269 @@ -170,7 +170,7 @@ void show_regs(struct pt_regs *regs)
11270
11271 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
11272 regs->tpc, regs->tnpc, regs->y, print_tainted());
11273 - printk("TPC: <%pS>\n", (void *) regs->tpc);
11274 + printk("TPC: <%pA>\n", (void *) regs->tpc);
11275 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
11276 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
11277 regs->u_regs[3]);
11278 @@ -183,7 +183,7 @@ void show_regs(struct pt_regs *regs)
11279 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
11280 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
11281 regs->u_regs[15]);
11282 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
11283 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
11284 show_regwindow(regs);
11285 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
11286 }
11287 @@ -278,7 +278,7 @@ void arch_trigger_all_cpu_backtrace(bool include_self)
11288 ((tp && tp->task) ? tp->task->pid : -1));
11289
11290 if (gp->tstate & TSTATE_PRIV) {
11291 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
11292 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
11293 (void *) gp->tpc,
11294 (void *) gp->o7,
11295 (void *) gp->i7,
11296 diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
11297 index 79cc0d1..ec62734 100644
11298 --- a/arch/sparc/kernel/prom_common.c
11299 +++ b/arch/sparc/kernel/prom_common.c
11300 @@ -144,7 +144,7 @@ static int __init prom_common_nextprop(phandle node, char *prev, char *buf)
11301
11302 unsigned int prom_early_allocated __initdata;
11303
11304 -static struct of_pdt_ops prom_sparc_ops __initdata = {
11305 +static struct of_pdt_ops prom_sparc_ops __initconst = {
11306 .nextprop = prom_common_nextprop,
11307 .getproplen = prom_getproplen,
11308 .getproperty = prom_getproperty,
11309 diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
11310 index c13c9f2..d572c34 100644
11311 --- a/arch/sparc/kernel/ptrace_64.c
11312 +++ b/arch/sparc/kernel/ptrace_64.c
11313 @@ -1060,6 +1060,10 @@ long arch_ptrace(struct task_struct *child, long request,
11314 return ret;
11315 }
11316
11317 +#ifdef CONFIG_GRKERNSEC_SETXID
11318 +extern void gr_delayed_cred_worker(void);
11319 +#endif
11320 +
11321 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
11322 {
11323 int ret = 0;
11324 @@ -1070,6 +1074,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
11325 if (test_thread_flag(TIF_NOHZ))
11326 user_exit();
11327
11328 +#ifdef CONFIG_GRKERNSEC_SETXID
11329 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
11330 + gr_delayed_cred_worker();
11331 +#endif
11332 +
11333 if (test_thread_flag(TIF_SYSCALL_TRACE))
11334 ret = tracehook_report_syscall_entry(regs);
11335
11336 @@ -1093,6 +1102,11 @@ asmlinkage void syscall_trace_leave(struct pt_regs *regs)
11337 if (test_thread_flag(TIF_NOHZ))
11338 user_exit();
11339
11340 +#ifdef CONFIG_GRKERNSEC_SETXID
11341 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
11342 + gr_delayed_cred_worker();
11343 +#endif
11344 +
11345 audit_syscall_exit(regs);
11346
11347 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
11348 diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
11349 index 81954ee..6cfaa98 100644
11350 --- a/arch/sparc/kernel/smp_64.c
11351 +++ b/arch/sparc/kernel/smp_64.c
11352 @@ -887,7 +887,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
11353 return;
11354
11355 #ifdef CONFIG_DEBUG_DCFLUSH
11356 - atomic_inc(&dcpage_flushes);
11357 + atomic_inc_unchecked(&dcpage_flushes);
11358 #endif
11359
11360 this_cpu = get_cpu();
11361 @@ -911,7 +911,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
11362 xcall_deliver(data0, __pa(pg_addr),
11363 (u64) pg_addr, cpumask_of(cpu));
11364 #ifdef CONFIG_DEBUG_DCFLUSH
11365 - atomic_inc(&dcpage_flushes_xcall);
11366 + atomic_inc_unchecked(&dcpage_flushes_xcall);
11367 #endif
11368 }
11369 }
11370 @@ -930,7 +930,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
11371 preempt_disable();
11372
11373 #ifdef CONFIG_DEBUG_DCFLUSH
11374 - atomic_inc(&dcpage_flushes);
11375 + atomic_inc_unchecked(&dcpage_flushes);
11376 #endif
11377 data0 = 0;
11378 pg_addr = page_address(page);
11379 @@ -947,7 +947,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
11380 xcall_deliver(data0, __pa(pg_addr),
11381 (u64) pg_addr, cpu_online_mask);
11382 #ifdef CONFIG_DEBUG_DCFLUSH
11383 - atomic_inc(&dcpage_flushes_xcall);
11384 + atomic_inc_unchecked(&dcpage_flushes_xcall);
11385 #endif
11386 }
11387 __local_flush_dcache_page(page);
11388 diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
11389 index 646988d..b88905f 100644
11390 --- a/arch/sparc/kernel/sys_sparc_32.c
11391 +++ b/arch/sparc/kernel/sys_sparc_32.c
11392 @@ -54,7 +54,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
11393 if (len > TASK_SIZE - PAGE_SIZE)
11394 return -ENOMEM;
11395 if (!addr)
11396 - addr = TASK_UNMAPPED_BASE;
11397 + addr = current->mm->mmap_base;
11398
11399 info.flags = 0;
11400 info.length = len;
11401 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
11402 index c85403d..6af95c9 100644
11403 --- a/arch/sparc/kernel/sys_sparc_64.c
11404 +++ b/arch/sparc/kernel/sys_sparc_64.c
11405 @@ -89,13 +89,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
11406 struct vm_area_struct * vma;
11407 unsigned long task_size = TASK_SIZE;
11408 int do_color_align;
11409 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
11410 struct vm_unmapped_area_info info;
11411
11412 if (flags & MAP_FIXED) {
11413 /* We do not accept a shared mapping if it would violate
11414 * cache aliasing constraints.
11415 */
11416 - if ((flags & MAP_SHARED) &&
11417 + if ((filp || (flags & MAP_SHARED)) &&
11418 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
11419 return -EINVAL;
11420 return addr;
11421 @@ -110,6 +111,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
11422 if (filp || (flags & MAP_SHARED))
11423 do_color_align = 1;
11424
11425 +#ifdef CONFIG_PAX_RANDMMAP
11426 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
11427 +#endif
11428 +
11429 if (addr) {
11430 if (do_color_align)
11431 addr = COLOR_ALIGN(addr, pgoff);
11432 @@ -117,22 +122,28 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
11433 addr = PAGE_ALIGN(addr);
11434
11435 vma = find_vma(mm, addr);
11436 - if (task_size - len >= addr &&
11437 - (!vma || addr + len <= vma->vm_start))
11438 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
11439 return addr;
11440 }
11441
11442 info.flags = 0;
11443 info.length = len;
11444 - info.low_limit = TASK_UNMAPPED_BASE;
11445 + info.low_limit = mm->mmap_base;
11446 info.high_limit = min(task_size, VA_EXCLUDE_START);
11447 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
11448 info.align_offset = pgoff << PAGE_SHIFT;
11449 + info.threadstack_offset = offset;
11450 addr = vm_unmapped_area(&info);
11451
11452 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
11453 VM_BUG_ON(addr != -ENOMEM);
11454 info.low_limit = VA_EXCLUDE_END;
11455 +
11456 +#ifdef CONFIG_PAX_RANDMMAP
11457 + if (mm->pax_flags & MF_PAX_RANDMMAP)
11458 + info.low_limit += mm->delta_mmap;
11459 +#endif
11460 +
11461 info.high_limit = task_size;
11462 addr = vm_unmapped_area(&info);
11463 }
11464 @@ -150,6 +161,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11465 unsigned long task_size = STACK_TOP32;
11466 unsigned long addr = addr0;
11467 int do_color_align;
11468 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
11469 struct vm_unmapped_area_info info;
11470
11471 /* This should only ever run for 32-bit processes. */
11472 @@ -159,7 +171,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11473 /* We do not accept a shared mapping if it would violate
11474 * cache aliasing constraints.
11475 */
11476 - if ((flags & MAP_SHARED) &&
11477 + if ((filp || (flags & MAP_SHARED)) &&
11478 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
11479 return -EINVAL;
11480 return addr;
11481 @@ -172,6 +184,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11482 if (filp || (flags & MAP_SHARED))
11483 do_color_align = 1;
11484
11485 +#ifdef CONFIG_PAX_RANDMMAP
11486 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
11487 +#endif
11488 +
11489 /* requesting a specific address */
11490 if (addr) {
11491 if (do_color_align)
11492 @@ -180,8 +196,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11493 addr = PAGE_ALIGN(addr);
11494
11495 vma = find_vma(mm, addr);
11496 - if (task_size - len >= addr &&
11497 - (!vma || addr + len <= vma->vm_start))
11498 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
11499 return addr;
11500 }
11501
11502 @@ -191,6 +206,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11503 info.high_limit = mm->mmap_base;
11504 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
11505 info.align_offset = pgoff << PAGE_SHIFT;
11506 + info.threadstack_offset = offset;
11507 addr = vm_unmapped_area(&info);
11508
11509 /*
11510 @@ -203,6 +219,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11511 VM_BUG_ON(addr != -ENOMEM);
11512 info.flags = 0;
11513 info.low_limit = TASK_UNMAPPED_BASE;
11514 +
11515 +#ifdef CONFIG_PAX_RANDMMAP
11516 + if (mm->pax_flags & MF_PAX_RANDMMAP)
11517 + info.low_limit += mm->delta_mmap;
11518 +#endif
11519 +
11520 info.high_limit = STACK_TOP32;
11521 addr = vm_unmapped_area(&info);
11522 }
11523 @@ -259,10 +281,14 @@ unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, u
11524 EXPORT_SYMBOL(get_fb_unmapped_area);
11525
11526 /* Essentially the same as PowerPC. */
11527 -static unsigned long mmap_rnd(void)
11528 +static unsigned long mmap_rnd(struct mm_struct *mm)
11529 {
11530 unsigned long rnd = 0UL;
11531
11532 +#ifdef CONFIG_PAX_RANDMMAP
11533 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
11534 +#endif
11535 +
11536 if (current->flags & PF_RANDOMIZE) {
11537 unsigned long val = get_random_int();
11538 if (test_thread_flag(TIF_32BIT))
11539 @@ -275,7 +301,7 @@ static unsigned long mmap_rnd(void)
11540
11541 void arch_pick_mmap_layout(struct mm_struct *mm)
11542 {
11543 - unsigned long random_factor = mmap_rnd();
11544 + unsigned long random_factor = mmap_rnd(mm);
11545 unsigned long gap;
11546
11547 /*
11548 @@ -288,6 +314,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
11549 gap == RLIM_INFINITY ||
11550 sysctl_legacy_va_layout) {
11551 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
11552 +
11553 +#ifdef CONFIG_PAX_RANDMMAP
11554 + if (mm->pax_flags & MF_PAX_RANDMMAP)
11555 + mm->mmap_base += mm->delta_mmap;
11556 +#endif
11557 +
11558 mm->get_unmapped_area = arch_get_unmapped_area;
11559 } else {
11560 /* We know it's 32-bit */
11561 @@ -299,6 +331,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
11562 gap = (task_size / 6 * 5);
11563
11564 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
11565 +
11566 +#ifdef CONFIG_PAX_RANDMMAP
11567 + if (mm->pax_flags & MF_PAX_RANDMMAP)
11568 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
11569 +#endif
11570 +
11571 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
11572 }
11573 }
11574 diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
11575 index 33a17e7..d87fb1f 100644
11576 --- a/arch/sparc/kernel/syscalls.S
11577 +++ b/arch/sparc/kernel/syscalls.S
11578 @@ -52,7 +52,7 @@ sys32_rt_sigreturn:
11579 #endif
11580 .align 32
11581 1: ldx [%g6 + TI_FLAGS], %l5
11582 - andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
11583 + andcc %l5, _TIF_WORK_SYSCALL, %g0
11584 be,pt %icc, rtrap
11585 nop
11586 call syscall_trace_leave
11587 @@ -184,7 +184,7 @@ linux_sparc_syscall32:
11588
11589 srl %i3, 0, %o3 ! IEU0
11590 srl %i2, 0, %o2 ! IEU0 Group
11591 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
11592 + andcc %l0, _TIF_WORK_SYSCALL, %g0
11593 bne,pn %icc, linux_syscall_trace32 ! CTI
11594 mov %i0, %l5 ! IEU1
11595 5: call %l7 ! CTI Group brk forced
11596 @@ -208,7 +208,7 @@ linux_sparc_syscall:
11597
11598 mov %i3, %o3 ! IEU1
11599 mov %i4, %o4 ! IEU0 Group
11600 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
11601 + andcc %l0, _TIF_WORK_SYSCALL, %g0
11602 bne,pn %icc, linux_syscall_trace ! CTI Group
11603 mov %i0, %l5 ! IEU0
11604 2: call %l7 ! CTI Group brk forced
11605 @@ -223,7 +223,7 @@ ret_sys_call:
11606
11607 cmp %o0, -ERESTART_RESTARTBLOCK
11608 bgeu,pn %xcc, 1f
11609 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
11610 + andcc %l0, _TIF_WORK_SYSCALL, %g0
11611 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
11612
11613 2:
11614 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
11615 index 6fd386c5..6907d81 100644
11616 --- a/arch/sparc/kernel/traps_32.c
11617 +++ b/arch/sparc/kernel/traps_32.c
11618 @@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
11619 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
11620 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
11621
11622 +extern void gr_handle_kernel_exploit(void);
11623 +
11624 void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11625 {
11626 static int die_counter;
11627 @@ -76,15 +78,17 @@ void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11628 count++ < 30 &&
11629 (((unsigned long) rw) >= PAGE_OFFSET) &&
11630 !(((unsigned long) rw) & 0x7)) {
11631 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
11632 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
11633 (void *) rw->ins[7]);
11634 rw = (struct reg_window32 *)rw->ins[6];
11635 }
11636 }
11637 printk("Instruction DUMP:");
11638 instruction_dump ((unsigned long *) regs->pc);
11639 - if(regs->psr & PSR_PS)
11640 + if(regs->psr & PSR_PS) {
11641 + gr_handle_kernel_exploit();
11642 do_exit(SIGKILL);
11643 + }
11644 do_exit(SIGSEGV);
11645 }
11646
11647 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
11648 index 981a769..d906eda 100644
11649 --- a/arch/sparc/kernel/traps_64.c
11650 +++ b/arch/sparc/kernel/traps_64.c
11651 @@ -79,7 +79,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
11652 i + 1,
11653 p->trapstack[i].tstate, p->trapstack[i].tpc,
11654 p->trapstack[i].tnpc, p->trapstack[i].tt);
11655 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
11656 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
11657 }
11658 }
11659
11660 @@ -99,6 +99,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
11661
11662 lvl -= 0x100;
11663 if (regs->tstate & TSTATE_PRIV) {
11664 +
11665 +#ifdef CONFIG_PAX_REFCOUNT
11666 + if (lvl == 6)
11667 + pax_report_refcount_overflow(regs);
11668 +#endif
11669 +
11670 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
11671 die_if_kernel(buffer, regs);
11672 }
11673 @@ -117,11 +123,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
11674 void bad_trap_tl1(struct pt_regs *regs, long lvl)
11675 {
11676 char buffer[32];
11677 -
11678 +
11679 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
11680 0, lvl, SIGTRAP) == NOTIFY_STOP)
11681 return;
11682
11683 +#ifdef CONFIG_PAX_REFCOUNT
11684 + if (lvl == 6)
11685 + pax_report_refcount_overflow(regs);
11686 +#endif
11687 +
11688 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
11689
11690 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
11691 @@ -1151,7 +1162,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
11692 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
11693 printk("%s" "ERROR(%d): ",
11694 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
11695 - printk("TPC<%pS>\n", (void *) regs->tpc);
11696 + printk("TPC<%pA>\n", (void *) regs->tpc);
11697 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
11698 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
11699 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
11700 @@ -1758,7 +1769,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
11701 smp_processor_id(),
11702 (type & 0x1) ? 'I' : 'D',
11703 regs->tpc);
11704 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
11705 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
11706 panic("Irrecoverable Cheetah+ parity error.");
11707 }
11708
11709 @@ -1766,7 +1777,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
11710 smp_processor_id(),
11711 (type & 0x1) ? 'I' : 'D',
11712 regs->tpc);
11713 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
11714 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
11715 }
11716
11717 struct sun4v_error_entry {
11718 @@ -1839,8 +1850,8 @@ struct sun4v_error_entry {
11719 /*0x38*/u64 reserved_5;
11720 };
11721
11722 -static atomic_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
11723 -static atomic_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
11724 +static atomic_unchecked_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
11725 +static atomic_unchecked_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
11726
11727 static const char *sun4v_err_type_to_str(u8 type)
11728 {
11729 @@ -1932,7 +1943,7 @@ static void sun4v_report_real_raddr(const char *pfx, struct pt_regs *regs)
11730 }
11731
11732 static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
11733 - int cpu, const char *pfx, atomic_t *ocnt)
11734 + int cpu, const char *pfx, atomic_unchecked_t *ocnt)
11735 {
11736 u64 *raw_ptr = (u64 *) ent;
11737 u32 attrs;
11738 @@ -1990,8 +2001,8 @@ static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
11739
11740 show_regs(regs);
11741
11742 - if ((cnt = atomic_read(ocnt)) != 0) {
11743 - atomic_set(ocnt, 0);
11744 + if ((cnt = atomic_read_unchecked(ocnt)) != 0) {
11745 + atomic_set_unchecked(ocnt, 0);
11746 wmb();
11747 printk("%s: Queue overflowed %d times.\n",
11748 pfx, cnt);
11749 @@ -2048,7 +2059,7 @@ out:
11750 */
11751 void sun4v_resum_overflow(struct pt_regs *regs)
11752 {
11753 - atomic_inc(&sun4v_resum_oflow_cnt);
11754 + atomic_inc_unchecked(&sun4v_resum_oflow_cnt);
11755 }
11756
11757 /* We run with %pil set to PIL_NORMAL_MAX and PSTATE_IE enabled in %pstate.
11758 @@ -2101,7 +2112,7 @@ void sun4v_nonresum_overflow(struct pt_regs *regs)
11759 /* XXX Actually even this can make not that much sense. Perhaps
11760 * XXX we should just pull the plug and panic directly from here?
11761 */
11762 - atomic_inc(&sun4v_nonresum_oflow_cnt);
11763 + atomic_inc_unchecked(&sun4v_nonresum_oflow_cnt);
11764 }
11765
11766 static void sun4v_tlb_error(struct pt_regs *regs)
11767 @@ -2120,9 +2131,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
11768
11769 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
11770 regs->tpc, tl);
11771 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
11772 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
11773 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
11774 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
11775 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
11776 (void *) regs->u_regs[UREG_I7]);
11777 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
11778 "pte[%lx] error[%lx]\n",
11779 @@ -2143,9 +2154,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
11780
11781 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
11782 regs->tpc, tl);
11783 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
11784 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
11785 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
11786 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
11787 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
11788 (void *) regs->u_regs[UREG_I7]);
11789 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
11790 "pte[%lx] error[%lx]\n",
11791 @@ -2362,13 +2373,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
11792 fp = (unsigned long)sf->fp + STACK_BIAS;
11793 }
11794
11795 - printk(" [%016lx] %pS\n", pc, (void *) pc);
11796 + printk(" [%016lx] %pA\n", pc, (void *) pc);
11797 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
11798 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
11799 int index = tsk->curr_ret_stack;
11800 if (tsk->ret_stack && index >= graph) {
11801 pc = tsk->ret_stack[index - graph].ret;
11802 - printk(" [%016lx] %pS\n", pc, (void *) pc);
11803 + printk(" [%016lx] %pA\n", pc, (void *) pc);
11804 graph++;
11805 }
11806 }
11807 @@ -2386,6 +2397,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
11808 return (struct reg_window *) (fp + STACK_BIAS);
11809 }
11810
11811 +extern void gr_handle_kernel_exploit(void);
11812 +
11813 void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11814 {
11815 static int die_counter;
11816 @@ -2414,7 +2427,7 @@ void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11817 while (rw &&
11818 count++ < 30 &&
11819 kstack_valid(tp, (unsigned long) rw)) {
11820 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
11821 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
11822 (void *) rw->ins[7]);
11823
11824 rw = kernel_stack_up(rw);
11825 @@ -2427,8 +2440,10 @@ void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11826 }
11827 user_instruction_dump ((unsigned int __user *) regs->tpc);
11828 }
11829 - if (regs->tstate & TSTATE_PRIV)
11830 + if (regs->tstate & TSTATE_PRIV) {
11831 + gr_handle_kernel_exploit();
11832 do_exit(SIGKILL);
11833 + }
11834 do_exit(SIGSEGV);
11835 }
11836 EXPORT_SYMBOL(die_if_kernel);
11837 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
11838 index 62098a8..547ab2c 100644
11839 --- a/arch/sparc/kernel/unaligned_64.c
11840 +++ b/arch/sparc/kernel/unaligned_64.c
11841 @@ -297,7 +297,7 @@ static void log_unaligned(struct pt_regs *regs)
11842 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
11843
11844 if (__ratelimit(&ratelimit)) {
11845 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
11846 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
11847 regs->tpc, (void *) regs->tpc);
11848 }
11849 }
11850 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
11851 index 3269b02..64f5231 100644
11852 --- a/arch/sparc/lib/Makefile
11853 +++ b/arch/sparc/lib/Makefile
11854 @@ -2,7 +2,7 @@
11855 #
11856
11857 asflags-y := -ansi -DST_DIV0=0x02
11858 -ccflags-y := -Werror
11859 +#ccflags-y := -Werror
11860
11861 lib-$(CONFIG_SPARC32) += ashrdi3.o
11862 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
11863 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
11864 index 85c233d..68500e0 100644
11865 --- a/arch/sparc/lib/atomic_64.S
11866 +++ b/arch/sparc/lib/atomic_64.S
11867 @@ -17,7 +17,12 @@
11868 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
11869 BACKOFF_SETUP(%o2)
11870 1: lduw [%o1], %g1
11871 - add %g1, %o0, %g7
11872 + addcc %g1, %o0, %g7
11873 +
11874 +#ifdef CONFIG_PAX_REFCOUNT
11875 + tvs %icc, 6
11876 +#endif
11877 +
11878 cas [%o1], %g1, %g7
11879 cmp %g1, %g7
11880 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
11881 @@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
11882 2: BACKOFF_SPIN(%o2, %o3, 1b)
11883 ENDPROC(atomic_add)
11884
11885 +ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
11886 + BACKOFF_SETUP(%o2)
11887 +1: lduw [%o1], %g1
11888 + add %g1, %o0, %g7
11889 + cas [%o1], %g1, %g7
11890 + cmp %g1, %g7
11891 + bne,pn %icc, 2f
11892 + nop
11893 + retl
11894 + nop
11895 +2: BACKOFF_SPIN(%o2, %o3, 1b)
11896 +ENDPROC(atomic_add_unchecked)
11897 +
11898 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
11899 BACKOFF_SETUP(%o2)
11900 1: lduw [%o1], %g1
11901 - sub %g1, %o0, %g7
11902 + subcc %g1, %o0, %g7
11903 +
11904 +#ifdef CONFIG_PAX_REFCOUNT
11905 + tvs %icc, 6
11906 +#endif
11907 +
11908 cas [%o1], %g1, %g7
11909 cmp %g1, %g7
11910 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
11911 @@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
11912 2: BACKOFF_SPIN(%o2, %o3, 1b)
11913 ENDPROC(atomic_sub)
11914
11915 +ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
11916 + BACKOFF_SETUP(%o2)
11917 +1: lduw [%o1], %g1
11918 + sub %g1, %o0, %g7
11919 + cas [%o1], %g1, %g7
11920 + cmp %g1, %g7
11921 + bne,pn %icc, 2f
11922 + nop
11923 + retl
11924 + nop
11925 +2: BACKOFF_SPIN(%o2, %o3, 1b)
11926 +ENDPROC(atomic_sub_unchecked)
11927 +
11928 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
11929 BACKOFF_SETUP(%o2)
11930 1: lduw [%o1], %g1
11931 - add %g1, %o0, %g7
11932 + addcc %g1, %o0, %g7
11933 +
11934 +#ifdef CONFIG_PAX_REFCOUNT
11935 + tvs %icc, 6
11936 +#endif
11937 +
11938 cas [%o1], %g1, %g7
11939 cmp %g1, %g7
11940 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
11941 @@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
11942 2: BACKOFF_SPIN(%o2, %o3, 1b)
11943 ENDPROC(atomic_add_ret)
11944
11945 +ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
11946 + BACKOFF_SETUP(%o2)
11947 +1: lduw [%o1], %g1
11948 + addcc %g1, %o0, %g7
11949 + cas [%o1], %g1, %g7
11950 + cmp %g1, %g7
11951 + bne,pn %icc, 2f
11952 + add %g7, %o0, %g7
11953 + sra %g7, 0, %o0
11954 + retl
11955 + nop
11956 +2: BACKOFF_SPIN(%o2, %o3, 1b)
11957 +ENDPROC(atomic_add_ret_unchecked)
11958 +
11959 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
11960 BACKOFF_SETUP(%o2)
11961 1: lduw [%o1], %g1
11962 - sub %g1, %o0, %g7
11963 + subcc %g1, %o0, %g7
11964 +
11965 +#ifdef CONFIG_PAX_REFCOUNT
11966 + tvs %icc, 6
11967 +#endif
11968 +
11969 cas [%o1], %g1, %g7
11970 cmp %g1, %g7
11971 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
11972 @@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
11973 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
11974 BACKOFF_SETUP(%o2)
11975 1: ldx [%o1], %g1
11976 - add %g1, %o0, %g7
11977 + addcc %g1, %o0, %g7
11978 +
11979 +#ifdef CONFIG_PAX_REFCOUNT
11980 + tvs %xcc, 6
11981 +#endif
11982 +
11983 casx [%o1], %g1, %g7
11984 cmp %g1, %g7
11985 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11986 @@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
11987 2: BACKOFF_SPIN(%o2, %o3, 1b)
11988 ENDPROC(atomic64_add)
11989
11990 +ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
11991 + BACKOFF_SETUP(%o2)
11992 +1: ldx [%o1], %g1
11993 + addcc %g1, %o0, %g7
11994 + casx [%o1], %g1, %g7
11995 + cmp %g1, %g7
11996 + bne,pn %xcc, 2f
11997 + nop
11998 + retl
11999 + nop
12000 +2: BACKOFF_SPIN(%o2, %o3, 1b)
12001 +ENDPROC(atomic64_add_unchecked)
12002 +
12003 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
12004 BACKOFF_SETUP(%o2)
12005 1: ldx [%o1], %g1
12006 - sub %g1, %o0, %g7
12007 + subcc %g1, %o0, %g7
12008 +
12009 +#ifdef CONFIG_PAX_REFCOUNT
12010 + tvs %xcc, 6
12011 +#endif
12012 +
12013 casx [%o1], %g1, %g7
12014 cmp %g1, %g7
12015 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
12016 @@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
12017 2: BACKOFF_SPIN(%o2, %o3, 1b)
12018 ENDPROC(atomic64_sub)
12019
12020 +ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
12021 + BACKOFF_SETUP(%o2)
12022 +1: ldx [%o1], %g1
12023 + subcc %g1, %o0, %g7
12024 + casx [%o1], %g1, %g7
12025 + cmp %g1, %g7
12026 + bne,pn %xcc, 2f
12027 + nop
12028 + retl
12029 + nop
12030 +2: BACKOFF_SPIN(%o2, %o3, 1b)
12031 +ENDPROC(atomic64_sub_unchecked)
12032 +
12033 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
12034 BACKOFF_SETUP(%o2)
12035 1: ldx [%o1], %g1
12036 - add %g1, %o0, %g7
12037 + addcc %g1, %o0, %g7
12038 +
12039 +#ifdef CONFIG_PAX_REFCOUNT
12040 + tvs %xcc, 6
12041 +#endif
12042 +
12043 casx [%o1], %g1, %g7
12044 cmp %g1, %g7
12045 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
12046 @@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
12047 2: BACKOFF_SPIN(%o2, %o3, 1b)
12048 ENDPROC(atomic64_add_ret)
12049
12050 +ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
12051 + BACKOFF_SETUP(%o2)
12052 +1: ldx [%o1], %g1
12053 + addcc %g1, %o0, %g7
12054 + casx [%o1], %g1, %g7
12055 + cmp %g1, %g7
12056 + bne,pn %xcc, 2f
12057 + add %g7, %o0, %g7
12058 + mov %g7, %o0
12059 + retl
12060 + nop
12061 +2: BACKOFF_SPIN(%o2, %o3, 1b)
12062 +ENDPROC(atomic64_add_ret_unchecked)
12063 +
12064 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
12065 BACKOFF_SETUP(%o2)
12066 1: ldx [%o1], %g1
12067 - sub %g1, %o0, %g7
12068 + subcc %g1, %o0, %g7
12069 +
12070 +#ifdef CONFIG_PAX_REFCOUNT
12071 + tvs %xcc, 6
12072 +#endif
12073 +
12074 casx [%o1], %g1, %g7
12075 cmp %g1, %g7
12076 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
12077 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
12078 index 323335b..ed85ea2 100644
12079 --- a/arch/sparc/lib/ksyms.c
12080 +++ b/arch/sparc/lib/ksyms.c
12081 @@ -100,12 +100,18 @@ EXPORT_SYMBOL(__clear_user);
12082
12083 /* Atomic counter implementation. */
12084 EXPORT_SYMBOL(atomic_add);
12085 +EXPORT_SYMBOL(atomic_add_unchecked);
12086 EXPORT_SYMBOL(atomic_add_ret);
12087 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
12088 EXPORT_SYMBOL(atomic_sub);
12089 +EXPORT_SYMBOL(atomic_sub_unchecked);
12090 EXPORT_SYMBOL(atomic_sub_ret);
12091 EXPORT_SYMBOL(atomic64_add);
12092 +EXPORT_SYMBOL(atomic64_add_unchecked);
12093 EXPORT_SYMBOL(atomic64_add_ret);
12094 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
12095 EXPORT_SYMBOL(atomic64_sub);
12096 +EXPORT_SYMBOL(atomic64_sub_unchecked);
12097 EXPORT_SYMBOL(atomic64_sub_ret);
12098 EXPORT_SYMBOL(atomic64_dec_if_positive);
12099
12100 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
12101 index 30c3ecc..736f015 100644
12102 --- a/arch/sparc/mm/Makefile
12103 +++ b/arch/sparc/mm/Makefile
12104 @@ -2,7 +2,7 @@
12105 #
12106
12107 asflags-y := -ansi
12108 -ccflags-y := -Werror
12109 +#ccflags-y := -Werror
12110
12111 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
12112 obj-y += fault_$(BITS).o
12113 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
12114 index 908e8c1..1524793 100644
12115 --- a/arch/sparc/mm/fault_32.c
12116 +++ b/arch/sparc/mm/fault_32.c
12117 @@ -21,6 +21,9 @@
12118 #include <linux/perf_event.h>
12119 #include <linux/interrupt.h>
12120 #include <linux/kdebug.h>
12121 +#include <linux/slab.h>
12122 +#include <linux/pagemap.h>
12123 +#include <linux/compiler.h>
12124
12125 #include <asm/page.h>
12126 #include <asm/pgtable.h>
12127 @@ -156,6 +159,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
12128 return safe_compute_effective_address(regs, insn);
12129 }
12130
12131 +#ifdef CONFIG_PAX_PAGEEXEC
12132 +#ifdef CONFIG_PAX_DLRESOLVE
12133 +static void pax_emuplt_close(struct vm_area_struct *vma)
12134 +{
12135 + vma->vm_mm->call_dl_resolve = 0UL;
12136 +}
12137 +
12138 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
12139 +{
12140 + unsigned int *kaddr;
12141 +
12142 + vmf->page = alloc_page(GFP_HIGHUSER);
12143 + if (!vmf->page)
12144 + return VM_FAULT_OOM;
12145 +
12146 + kaddr = kmap(vmf->page);
12147 + memset(kaddr, 0, PAGE_SIZE);
12148 + kaddr[0] = 0x9DE3BFA8U; /* save */
12149 + flush_dcache_page(vmf->page);
12150 + kunmap(vmf->page);
12151 + return VM_FAULT_MAJOR;
12152 +}
12153 +
12154 +static const struct vm_operations_struct pax_vm_ops = {
12155 + .close = pax_emuplt_close,
12156 + .fault = pax_emuplt_fault
12157 +};
12158 +
12159 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
12160 +{
12161 + int ret;
12162 +
12163 + INIT_LIST_HEAD(&vma->anon_vma_chain);
12164 + vma->vm_mm = current->mm;
12165 + vma->vm_start = addr;
12166 + vma->vm_end = addr + PAGE_SIZE;
12167 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
12168 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
12169 + vma->vm_ops = &pax_vm_ops;
12170 +
12171 + ret = insert_vm_struct(current->mm, vma);
12172 + if (ret)
12173 + return ret;
12174 +
12175 + ++current->mm->total_vm;
12176 + return 0;
12177 +}
12178 +#endif
12179 +
12180 +/*
12181 + * PaX: decide what to do with offenders (regs->pc = fault address)
12182 + *
12183 + * returns 1 when task should be killed
12184 + * 2 when patched PLT trampoline was detected
12185 + * 3 when unpatched PLT trampoline was detected
12186 + */
12187 +static int pax_handle_fetch_fault(struct pt_regs *regs)
12188 +{
12189 +
12190 +#ifdef CONFIG_PAX_EMUPLT
12191 + int err;
12192 +
12193 + do { /* PaX: patched PLT emulation #1 */
12194 + unsigned int sethi1, sethi2, jmpl;
12195 +
12196 + err = get_user(sethi1, (unsigned int *)regs->pc);
12197 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
12198 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
12199 +
12200 + if (err)
12201 + break;
12202 +
12203 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
12204 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
12205 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
12206 + {
12207 + unsigned int addr;
12208 +
12209 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
12210 + addr = regs->u_regs[UREG_G1];
12211 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
12212 + regs->pc = addr;
12213 + regs->npc = addr+4;
12214 + return 2;
12215 + }
12216 + } while (0);
12217 +
12218 + do { /* PaX: patched PLT emulation #2 */
12219 + unsigned int ba;
12220 +
12221 + err = get_user(ba, (unsigned int *)regs->pc);
12222 +
12223 + if (err)
12224 + break;
12225 +
12226 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
12227 + unsigned int addr;
12228 +
12229 + if ((ba & 0xFFC00000U) == 0x30800000U)
12230 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
12231 + else
12232 + addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
12233 + regs->pc = addr;
12234 + regs->npc = addr+4;
12235 + return 2;
12236 + }
12237 + } while (0);
12238 +
12239 + do { /* PaX: patched PLT emulation #3 */
12240 + unsigned int sethi, bajmpl, nop;
12241 +
12242 + err = get_user(sethi, (unsigned int *)regs->pc);
12243 + err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
12244 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
12245 +
12246 + if (err)
12247 + break;
12248 +
12249 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
12250 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
12251 + nop == 0x01000000U)
12252 + {
12253 + unsigned int addr;
12254 +
12255 + addr = (sethi & 0x003FFFFFU) << 10;
12256 + regs->u_regs[UREG_G1] = addr;
12257 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
12258 + addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
12259 + else
12260 + addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
12261 + regs->pc = addr;
12262 + regs->npc = addr+4;
12263 + return 2;
12264 + }
12265 + } while (0);
12266 +
12267 + do { /* PaX: unpatched PLT emulation step 1 */
12268 + unsigned int sethi, ba, nop;
12269 +
12270 + err = get_user(sethi, (unsigned int *)regs->pc);
12271 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
12272 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
12273 +
12274 + if (err)
12275 + break;
12276 +
12277 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
12278 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
12279 + nop == 0x01000000U)
12280 + {
12281 + unsigned int addr, save, call;
12282 +
12283 + if ((ba & 0xFFC00000U) == 0x30800000U)
12284 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
12285 + else
12286 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
12287 +
12288 + err = get_user(save, (unsigned int *)addr);
12289 + err |= get_user(call, (unsigned int *)(addr+4));
12290 + err |= get_user(nop, (unsigned int *)(addr+8));
12291 + if (err)
12292 + break;
12293 +
12294 +#ifdef CONFIG_PAX_DLRESOLVE
12295 + if (save == 0x9DE3BFA8U &&
12296 + (call & 0xC0000000U) == 0x40000000U &&
12297 + nop == 0x01000000U)
12298 + {
12299 + struct vm_area_struct *vma;
12300 + unsigned long call_dl_resolve;
12301 +
12302 + down_read(&current->mm->mmap_sem);
12303 + call_dl_resolve = current->mm->call_dl_resolve;
12304 + up_read(&current->mm->mmap_sem);
12305 + if (likely(call_dl_resolve))
12306 + goto emulate;
12307 +
12308 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
12309 +
12310 + down_write(&current->mm->mmap_sem);
12311 + if (current->mm->call_dl_resolve) {
12312 + call_dl_resolve = current->mm->call_dl_resolve;
12313 + up_write(&current->mm->mmap_sem);
12314 + if (vma)
12315 + kmem_cache_free(vm_area_cachep, vma);
12316 + goto emulate;
12317 + }
12318 +
12319 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
12320 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
12321 + up_write(&current->mm->mmap_sem);
12322 + if (vma)
12323 + kmem_cache_free(vm_area_cachep, vma);
12324 + return 1;
12325 + }
12326 +
12327 + if (pax_insert_vma(vma, call_dl_resolve)) {
12328 + up_write(&current->mm->mmap_sem);
12329 + kmem_cache_free(vm_area_cachep, vma);
12330 + return 1;
12331 + }
12332 +
12333 + current->mm->call_dl_resolve = call_dl_resolve;
12334 + up_write(&current->mm->mmap_sem);
12335 +
12336 +emulate:
12337 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
12338 + regs->pc = call_dl_resolve;
12339 + regs->npc = addr+4;
12340 + return 3;
12341 + }
12342 +#endif
12343 +
12344 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
12345 + if ((save & 0xFFC00000U) == 0x05000000U &&
12346 + (call & 0xFFFFE000U) == 0x85C0A000U &&
12347 + nop == 0x01000000U)
12348 + {
12349 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
12350 + regs->u_regs[UREG_G2] = addr + 4;
12351 + addr = (save & 0x003FFFFFU) << 10;
12352 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
12353 + regs->pc = addr;
12354 + regs->npc = addr+4;
12355 + return 3;
12356 + }
12357 + }
12358 + } while (0);
12359 +
12360 + do { /* PaX: unpatched PLT emulation step 2 */
12361 + unsigned int save, call, nop;
12362 +
12363 + err = get_user(save, (unsigned int *)(regs->pc-4));
12364 + err |= get_user(call, (unsigned int *)regs->pc);
12365 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
12366 + if (err)
12367 + break;
12368 +
12369 + if (save == 0x9DE3BFA8U &&
12370 + (call & 0xC0000000U) == 0x40000000U &&
12371 + nop == 0x01000000U)
12372 + {
12373 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
12374 +
12375 + regs->u_regs[UREG_RETPC] = regs->pc;
12376 + regs->pc = dl_resolve;
12377 + regs->npc = dl_resolve+4;
12378 + return 3;
12379 + }
12380 + } while (0);
12381 +#endif
12382 +
12383 + return 1;
12384 +}
12385 +
12386 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
12387 +{
12388 + unsigned long i;
12389 +
12390 + printk(KERN_ERR "PAX: bytes at PC: ");
12391 + for (i = 0; i < 8; i++) {
12392 + unsigned int c;
12393 + if (get_user(c, (unsigned int *)pc+i))
12394 + printk(KERN_CONT "???????? ");
12395 + else
12396 + printk(KERN_CONT "%08x ", c);
12397 + }
12398 + printk("\n");
12399 +}
12400 +#endif
12401 +
12402 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
12403 int text_fault)
12404 {
12405 @@ -226,6 +500,24 @@ good_area:
12406 if (!(vma->vm_flags & VM_WRITE))
12407 goto bad_area;
12408 } else {
12409 +
12410 +#ifdef CONFIG_PAX_PAGEEXEC
12411 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
12412 + up_read(&mm->mmap_sem);
12413 + switch (pax_handle_fetch_fault(regs)) {
12414 +
12415 +#ifdef CONFIG_PAX_EMUPLT
12416 + case 2:
12417 + case 3:
12418 + return;
12419 +#endif
12420 +
12421 + }
12422 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
12423 + do_group_exit(SIGKILL);
12424 + }
12425 +#endif
12426 +
12427 /* Allow reads even for write-only mappings */
12428 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
12429 goto bad_area;
12430 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
12431 index 18fcd71..e4fe821 100644
12432 --- a/arch/sparc/mm/fault_64.c
12433 +++ b/arch/sparc/mm/fault_64.c
12434 @@ -22,6 +22,9 @@
12435 #include <linux/kdebug.h>
12436 #include <linux/percpu.h>
12437 #include <linux/context_tracking.h>
12438 +#include <linux/slab.h>
12439 +#include <linux/pagemap.h>
12440 +#include <linux/compiler.h>
12441
12442 #include <asm/page.h>
12443 #include <asm/pgtable.h>
12444 @@ -76,7 +79,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
12445 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
12446 regs->tpc);
12447 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
12448 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
12449 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
12450 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
12451 dump_stack();
12452 unhandled_fault(regs->tpc, current, regs);
12453 @@ -279,6 +282,466 @@ static void noinline __kprobes bogus_32bit_fault_tpc(struct pt_regs *regs)
12454 show_regs(regs);
12455 }
12456
12457 +#ifdef CONFIG_PAX_PAGEEXEC
12458 +#ifdef CONFIG_PAX_DLRESOLVE
12459 +static void pax_emuplt_close(struct vm_area_struct *vma)
12460 +{
12461 + vma->vm_mm->call_dl_resolve = 0UL;
12462 +}
12463 +
12464 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
12465 +{
12466 + unsigned int *kaddr;
12467 +
12468 + vmf->page = alloc_page(GFP_HIGHUSER);
12469 + if (!vmf->page)
12470 + return VM_FAULT_OOM;
12471 +
12472 + kaddr = kmap(vmf->page);
12473 + memset(kaddr, 0, PAGE_SIZE);
12474 + kaddr[0] = 0x9DE3BFA8U; /* save */
12475 + flush_dcache_page(vmf->page);
12476 + kunmap(vmf->page);
12477 + return VM_FAULT_MAJOR;
12478 +}
12479 +
12480 +static const struct vm_operations_struct pax_vm_ops = {
12481 + .close = pax_emuplt_close,
12482 + .fault = pax_emuplt_fault
12483 +};
12484 +
12485 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
12486 +{
12487 + int ret;
12488 +
12489 + INIT_LIST_HEAD(&vma->anon_vma_chain);
12490 + vma->vm_mm = current->mm;
12491 + vma->vm_start = addr;
12492 + vma->vm_end = addr + PAGE_SIZE;
12493 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
12494 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
12495 + vma->vm_ops = &pax_vm_ops;
12496 +
12497 + ret = insert_vm_struct(current->mm, vma);
12498 + if (ret)
12499 + return ret;
12500 +
12501 + ++current->mm->total_vm;
12502 + return 0;
12503 +}
12504 +#endif
12505 +
12506 +/*
12507 + * PaX: decide what to do with offenders (regs->tpc = fault address)
12508 + *
12509 + * returns 1 when task should be killed
12510 + * 2 when patched PLT trampoline was detected
12511 + * 3 when unpatched PLT trampoline was detected
12512 + */
12513 +static int pax_handle_fetch_fault(struct pt_regs *regs)
12514 +{
12515 +
12516 +#ifdef CONFIG_PAX_EMUPLT
12517 + int err;
12518 +
12519 + do { /* PaX: patched PLT emulation #1 */
12520 + unsigned int sethi1, sethi2, jmpl;
12521 +
12522 + err = get_user(sethi1, (unsigned int *)regs->tpc);
12523 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
12524 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
12525 +
12526 + if (err)
12527 + break;
12528 +
12529 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
12530 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
12531 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
12532 + {
12533 + unsigned long addr;
12534 +
12535 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
12536 + addr = regs->u_regs[UREG_G1];
12537 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
12538 +
12539 + if (test_thread_flag(TIF_32BIT))
12540 + addr &= 0xFFFFFFFFUL;
12541 +
12542 + regs->tpc = addr;
12543 + regs->tnpc = addr+4;
12544 + return 2;
12545 + }
12546 + } while (0);
12547 +
12548 + do { /* PaX: patched PLT emulation #2 */
12549 + unsigned int ba;
12550 +
12551 + err = get_user(ba, (unsigned int *)regs->tpc);
12552 +
12553 + if (err)
12554 + break;
12555 +
12556 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
12557 + unsigned long addr;
12558 +
12559 + if ((ba & 0xFFC00000U) == 0x30800000U)
12560 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
12561 + else
12562 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
12563 +
12564 + if (test_thread_flag(TIF_32BIT))
12565 + addr &= 0xFFFFFFFFUL;
12566 +
12567 + regs->tpc = addr;
12568 + regs->tnpc = addr+4;
12569 + return 2;
12570 + }
12571 + } while (0);
12572 +
12573 + do { /* PaX: patched PLT emulation #3 */
12574 + unsigned int sethi, bajmpl, nop;
12575 +
12576 + err = get_user(sethi, (unsigned int *)regs->tpc);
12577 + err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
12578 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
12579 +
12580 + if (err)
12581 + break;
12582 +
12583 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
12584 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
12585 + nop == 0x01000000U)
12586 + {
12587 + unsigned long addr;
12588 +
12589 + addr = (sethi & 0x003FFFFFU) << 10;
12590 + regs->u_regs[UREG_G1] = addr;
12591 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
12592 + addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
12593 + else
12594 + addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
12595 +
12596 + if (test_thread_flag(TIF_32BIT))
12597 + addr &= 0xFFFFFFFFUL;
12598 +
12599 + regs->tpc = addr;
12600 + regs->tnpc = addr+4;
12601 + return 2;
12602 + }
12603 + } while (0);
12604 +
12605 + do { /* PaX: patched PLT emulation #4 */
12606 + unsigned int sethi, mov1, call, mov2;
12607 +
12608 + err = get_user(sethi, (unsigned int *)regs->tpc);
12609 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
12610 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
12611 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
12612 +
12613 + if (err)
12614 + break;
12615 +
12616 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
12617 + mov1 == 0x8210000FU &&
12618 + (call & 0xC0000000U) == 0x40000000U &&
12619 + mov2 == 0x9E100001U)
12620 + {
12621 + unsigned long addr;
12622 +
12623 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
12624 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
12625 +
12626 + if (test_thread_flag(TIF_32BIT))
12627 + addr &= 0xFFFFFFFFUL;
12628 +
12629 + regs->tpc = addr;
12630 + regs->tnpc = addr+4;
12631 + return 2;
12632 + }
12633 + } while (0);
12634 +
12635 + do { /* PaX: patched PLT emulation #5 */
12636 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
12637 +
12638 + err = get_user(sethi, (unsigned int *)regs->tpc);
12639 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
12640 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
12641 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
12642 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
12643 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
12644 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
12645 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
12646 +
12647 + if (err)
12648 + break;
12649 +
12650 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
12651 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
12652 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
12653 + (or1 & 0xFFFFE000U) == 0x82106000U &&
12654 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
12655 + sllx == 0x83287020U &&
12656 + jmpl == 0x81C04005U &&
12657 + nop == 0x01000000U)
12658 + {
12659 + unsigned long addr;
12660 +
12661 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
12662 + regs->u_regs[UREG_G1] <<= 32;
12663 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
12664 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
12665 + regs->tpc = addr;
12666 + regs->tnpc = addr+4;
12667 + return 2;
12668 + }
12669 + } while (0);
12670 +
12671 + do { /* PaX: patched PLT emulation #6 */
12672 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
12673 +
12674 + err = get_user(sethi, (unsigned int *)regs->tpc);
12675 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
12676 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
12677 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
12678 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
12679 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
12680 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
12681 +
12682 + if (err)
12683 + break;
12684 +
12685 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
12686 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
12687 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
12688 + sllx == 0x83287020U &&
12689 + (or & 0xFFFFE000U) == 0x8A116000U &&
12690 + jmpl == 0x81C04005U &&
12691 + nop == 0x01000000U)
12692 + {
12693 + unsigned long addr;
12694 +
12695 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
12696 + regs->u_regs[UREG_G1] <<= 32;
12697 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
12698 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
12699 + regs->tpc = addr;
12700 + regs->tnpc = addr+4;
12701 + return 2;
12702 + }
12703 + } while (0);
12704 +
12705 + do { /* PaX: unpatched PLT emulation step 1 */
12706 + unsigned int sethi, ba, nop;
12707 +
12708 + err = get_user(sethi, (unsigned int *)regs->tpc);
12709 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
12710 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
12711 +
12712 + if (err)
12713 + break;
12714 +
12715 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
12716 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
12717 + nop == 0x01000000U)
12718 + {
12719 + unsigned long addr;
12720 + unsigned int save, call;
12721 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
12722 +
12723 + if ((ba & 0xFFC00000U) == 0x30800000U)
12724 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
12725 + else
12726 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
12727 +
12728 + if (test_thread_flag(TIF_32BIT))
12729 + addr &= 0xFFFFFFFFUL;
12730 +
12731 + err = get_user(save, (unsigned int *)addr);
12732 + err |= get_user(call, (unsigned int *)(addr+4));
12733 + err |= get_user(nop, (unsigned int *)(addr+8));
12734 + if (err)
12735 + break;
12736 +
12737 +#ifdef CONFIG_PAX_DLRESOLVE
12738 + if (save == 0x9DE3BFA8U &&
12739 + (call & 0xC0000000U) == 0x40000000U &&
12740 + nop == 0x01000000U)
12741 + {
12742 + struct vm_area_struct *vma;
12743 + unsigned long call_dl_resolve;
12744 +
12745 + down_read(&current->mm->mmap_sem);
12746 + call_dl_resolve = current->mm->call_dl_resolve;
12747 + up_read(&current->mm->mmap_sem);
12748 + if (likely(call_dl_resolve))
12749 + goto emulate;
12750 +
12751 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
12752 +
12753 + down_write(&current->mm->mmap_sem);
12754 + if (current->mm->call_dl_resolve) {
12755 + call_dl_resolve = current->mm->call_dl_resolve;
12756 + up_write(&current->mm->mmap_sem);
12757 + if (vma)
12758 + kmem_cache_free(vm_area_cachep, vma);
12759 + goto emulate;
12760 + }
12761 +
12762 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
12763 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
12764 + up_write(&current->mm->mmap_sem);
12765 + if (vma)
12766 + kmem_cache_free(vm_area_cachep, vma);
12767 + return 1;
12768 + }
12769 +
12770 + if (pax_insert_vma(vma, call_dl_resolve)) {
12771 + up_write(&current->mm->mmap_sem);
12772 + kmem_cache_free(vm_area_cachep, vma);
12773 + return 1;
12774 + }
12775 +
12776 + current->mm->call_dl_resolve = call_dl_resolve;
12777 + up_write(&current->mm->mmap_sem);
12778 +
12779 +emulate:
12780 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
12781 + regs->tpc = call_dl_resolve;
12782 + regs->tnpc = addr+4;
12783 + return 3;
12784 + }
12785 +#endif
12786 +
12787 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
12788 + if ((save & 0xFFC00000U) == 0x05000000U &&
12789 + (call & 0xFFFFE000U) == 0x85C0A000U &&
12790 + nop == 0x01000000U)
12791 + {
12792 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
12793 + regs->u_regs[UREG_G2] = addr + 4;
12794 + addr = (save & 0x003FFFFFU) << 10;
12795 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
12796 +
12797 + if (test_thread_flag(TIF_32BIT))
12798 + addr &= 0xFFFFFFFFUL;
12799 +
12800 + regs->tpc = addr;
12801 + regs->tnpc = addr+4;
12802 + return 3;
12803 + }
12804 +
12805 + /* PaX: 64-bit PLT stub */
12806 + err = get_user(sethi1, (unsigned int *)addr);
12807 + err |= get_user(sethi2, (unsigned int *)(addr+4));
12808 + err |= get_user(or1, (unsigned int *)(addr+8));
12809 + err |= get_user(or2, (unsigned int *)(addr+12));
12810 + err |= get_user(sllx, (unsigned int *)(addr+16));
12811 + err |= get_user(add, (unsigned int *)(addr+20));
12812 + err |= get_user(jmpl, (unsigned int *)(addr+24));
12813 + err |= get_user(nop, (unsigned int *)(addr+28));
12814 + if (err)
12815 + break;
12816 +
12817 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
12818 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
12819 + (or1 & 0xFFFFE000U) == 0x88112000U &&
12820 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
12821 + sllx == 0x89293020U &&
12822 + add == 0x8A010005U &&
12823 + jmpl == 0x89C14000U &&
12824 + nop == 0x01000000U)
12825 + {
12826 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
12827 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
12828 + regs->u_regs[UREG_G4] <<= 32;
12829 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
12830 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
12831 + regs->u_regs[UREG_G4] = addr + 24;
12832 + addr = regs->u_regs[UREG_G5];
12833 + regs->tpc = addr;
12834 + regs->tnpc = addr+4;
12835 + return 3;
12836 + }
12837 + }
12838 + } while (0);
12839 +
12840 +#ifdef CONFIG_PAX_DLRESOLVE
12841 + do { /* PaX: unpatched PLT emulation step 2 */
12842 + unsigned int save, call, nop;
12843 +
12844 + err = get_user(save, (unsigned int *)(regs->tpc-4));
12845 + err |= get_user(call, (unsigned int *)regs->tpc);
12846 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
12847 + if (err)
12848 + break;
12849 +
12850 + if (save == 0x9DE3BFA8U &&
12851 + (call & 0xC0000000U) == 0x40000000U &&
12852 + nop == 0x01000000U)
12853 + {
12854 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
12855 +
12856 + if (test_thread_flag(TIF_32BIT))
12857 + dl_resolve &= 0xFFFFFFFFUL;
12858 +
12859 + regs->u_regs[UREG_RETPC] = regs->tpc;
12860 + regs->tpc = dl_resolve;
12861 + regs->tnpc = dl_resolve+4;
12862 + return 3;
12863 + }
12864 + } while (0);
12865 +#endif
12866 +
12867 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
12868 + unsigned int sethi, ba, nop;
12869 +
12870 + err = get_user(sethi, (unsigned int *)regs->tpc);
12871 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
12872 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
12873 +
12874 + if (err)
12875 + break;
12876 +
12877 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
12878 + (ba & 0xFFF00000U) == 0x30600000U &&
12879 + nop == 0x01000000U)
12880 + {
12881 + unsigned long addr;
12882 +
12883 + addr = (sethi & 0x003FFFFFU) << 10;
12884 + regs->u_regs[UREG_G1] = addr;
12885 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
12886 +
12887 + if (test_thread_flag(TIF_32BIT))
12888 + addr &= 0xFFFFFFFFUL;
12889 +
12890 + regs->tpc = addr;
12891 + regs->tnpc = addr+4;
12892 + return 2;
12893 + }
12894 + } while (0);
12895 +
12896 +#endif
12897 +
12898 + return 1;
12899 +}
12900 +
12901 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
12902 +{
12903 + unsigned long i;
12904 +
12905 + printk(KERN_ERR "PAX: bytes at PC: ");
12906 + for (i = 0; i < 8; i++) {
12907 + unsigned int c;
12908 + if (get_user(c, (unsigned int *)pc+i))
12909 + printk(KERN_CONT "???????? ");
12910 + else
12911 + printk(KERN_CONT "%08x ", c);
12912 + }
12913 + printk("\n");
12914 +}
12915 +#endif
12916 +
12917 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
12918 {
12919 enum ctx_state prev_state = exception_enter();
12920 @@ -353,6 +816,29 @@ retry:
12921 if (!vma)
12922 goto bad_area;
12923
12924 +#ifdef CONFIG_PAX_PAGEEXEC
12925 + /* PaX: detect ITLB misses on non-exec pages */
12926 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
12927 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
12928 + {
12929 + if (address != regs->tpc)
12930 + goto good_area;
12931 +
12932 + up_read(&mm->mmap_sem);
12933 + switch (pax_handle_fetch_fault(regs)) {
12934 +
12935 +#ifdef CONFIG_PAX_EMUPLT
12936 + case 2:
12937 + case 3:
12938 + return;
12939 +#endif
12940 +
12941 + }
12942 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
12943 + do_group_exit(SIGKILL);
12944 + }
12945 +#endif
12946 +
12947 /* Pure DTLB misses do not tell us whether the fault causing
12948 * load/store/atomic was a write or not, it only says that there
12949 * was no match. So in such a case we (carefully) read the
12950 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
12951 index d329537..2c3746a 100644
12952 --- a/arch/sparc/mm/hugetlbpage.c
12953 +++ b/arch/sparc/mm/hugetlbpage.c
12954 @@ -25,8 +25,10 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
12955 unsigned long addr,
12956 unsigned long len,
12957 unsigned long pgoff,
12958 - unsigned long flags)
12959 + unsigned long flags,
12960 + unsigned long offset)
12961 {
12962 + struct mm_struct *mm = current->mm;
12963 unsigned long task_size = TASK_SIZE;
12964 struct vm_unmapped_area_info info;
12965
12966 @@ -35,15 +37,22 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
12967
12968 info.flags = 0;
12969 info.length = len;
12970 - info.low_limit = TASK_UNMAPPED_BASE;
12971 + info.low_limit = mm->mmap_base;
12972 info.high_limit = min(task_size, VA_EXCLUDE_START);
12973 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
12974 info.align_offset = 0;
12975 + info.threadstack_offset = offset;
12976 addr = vm_unmapped_area(&info);
12977
12978 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
12979 VM_BUG_ON(addr != -ENOMEM);
12980 info.low_limit = VA_EXCLUDE_END;
12981 +
12982 +#ifdef CONFIG_PAX_RANDMMAP
12983 + if (mm->pax_flags & MF_PAX_RANDMMAP)
12984 + info.low_limit += mm->delta_mmap;
12985 +#endif
12986 +
12987 info.high_limit = task_size;
12988 addr = vm_unmapped_area(&info);
12989 }
12990 @@ -55,7 +64,8 @@ static unsigned long
12991 hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12992 const unsigned long len,
12993 const unsigned long pgoff,
12994 - const unsigned long flags)
12995 + const unsigned long flags,
12996 + const unsigned long offset)
12997 {
12998 struct mm_struct *mm = current->mm;
12999 unsigned long addr = addr0;
13000 @@ -70,6 +80,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
13001 info.high_limit = mm->mmap_base;
13002 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
13003 info.align_offset = 0;
13004 + info.threadstack_offset = offset;
13005 addr = vm_unmapped_area(&info);
13006
13007 /*
13008 @@ -82,6 +93,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
13009 VM_BUG_ON(addr != -ENOMEM);
13010 info.flags = 0;
13011 info.low_limit = TASK_UNMAPPED_BASE;
13012 +
13013 +#ifdef CONFIG_PAX_RANDMMAP
13014 + if (mm->pax_flags & MF_PAX_RANDMMAP)
13015 + info.low_limit += mm->delta_mmap;
13016 +#endif
13017 +
13018 info.high_limit = STACK_TOP32;
13019 addr = vm_unmapped_area(&info);
13020 }
13021 @@ -96,6 +113,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
13022 struct mm_struct *mm = current->mm;
13023 struct vm_area_struct *vma;
13024 unsigned long task_size = TASK_SIZE;
13025 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
13026
13027 if (test_thread_flag(TIF_32BIT))
13028 task_size = STACK_TOP32;
13029 @@ -111,19 +129,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
13030 return addr;
13031 }
13032
13033 +#ifdef CONFIG_PAX_RANDMMAP
13034 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
13035 +#endif
13036 +
13037 if (addr) {
13038 addr = ALIGN(addr, HPAGE_SIZE);
13039 vma = find_vma(mm, addr);
13040 - if (task_size - len >= addr &&
13041 - (!vma || addr + len <= vma->vm_start))
13042 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
13043 return addr;
13044 }
13045 if (mm->get_unmapped_area == arch_get_unmapped_area)
13046 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
13047 - pgoff, flags);
13048 + pgoff, flags, offset);
13049 else
13050 return hugetlb_get_unmapped_area_topdown(file, addr, len,
13051 - pgoff, flags);
13052 + pgoff, flags, offset);
13053 }
13054
13055 pte_t *huge_pte_alloc(struct mm_struct *mm,
13056 diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c
13057 index 04bc826..0fefab9 100644
13058 --- a/arch/sparc/mm/init_64.c
13059 +++ b/arch/sparc/mm/init_64.c
13060 @@ -186,9 +186,9 @@ unsigned long sparc64_kern_sec_context __read_mostly;
13061 int num_kernel_image_mappings;
13062
13063 #ifdef CONFIG_DEBUG_DCFLUSH
13064 -atomic_t dcpage_flushes = ATOMIC_INIT(0);
13065 +atomic_unchecked_t dcpage_flushes = ATOMIC_INIT(0);
13066 #ifdef CONFIG_SMP
13067 -atomic_t dcpage_flushes_xcall = ATOMIC_INIT(0);
13068 +atomic_unchecked_t dcpage_flushes_xcall = ATOMIC_INIT(0);
13069 #endif
13070 #endif
13071
13072 @@ -196,7 +196,7 @@ inline void flush_dcache_page_impl(struct page *page)
13073 {
13074 BUG_ON(tlb_type == hypervisor);
13075 #ifdef CONFIG_DEBUG_DCFLUSH
13076 - atomic_inc(&dcpage_flushes);
13077 + atomic_inc_unchecked(&dcpage_flushes);
13078 #endif
13079
13080 #ifdef DCACHE_ALIASING_POSSIBLE
13081 @@ -468,10 +468,10 @@ void mmu_info(struct seq_file *m)
13082
13083 #ifdef CONFIG_DEBUG_DCFLUSH
13084 seq_printf(m, "DCPageFlushes\t: %d\n",
13085 - atomic_read(&dcpage_flushes));
13086 + atomic_read_unchecked(&dcpage_flushes));
13087 #ifdef CONFIG_SMP
13088 seq_printf(m, "DCPageFlushesXC\t: %d\n",
13089 - atomic_read(&dcpage_flushes_xcall));
13090 + atomic_read_unchecked(&dcpage_flushes_xcall));
13091 #endif /* CONFIG_SMP */
13092 #endif /* CONFIG_DEBUG_DCFLUSH */
13093 }
13094 diff --git a/arch/sparc/net/bpf_jit_comp.c b/arch/sparc/net/bpf_jit_comp.c
13095 index ece4af0..f04b862 100644
13096 --- a/arch/sparc/net/bpf_jit_comp.c
13097 +++ b/arch/sparc/net/bpf_jit_comp.c
13098 @@ -823,5 +823,6 @@ void bpf_jit_free(struct bpf_prog *fp)
13099 {
13100 if (fp->jited)
13101 module_free(NULL, fp->bpf_func);
13102 - kfree(fp);
13103 +
13104 + bpf_prog_unlock_free(fp);
13105 }
13106 diff --git a/arch/tile/Kconfig b/arch/tile/Kconfig
13107 index 7fcd492..1311074 100644
13108 --- a/arch/tile/Kconfig
13109 +++ b/arch/tile/Kconfig
13110 @@ -191,6 +191,7 @@ source "kernel/Kconfig.hz"
13111
13112 config KEXEC
13113 bool "kexec system call"
13114 + depends on !GRKERNSEC_KMEM
13115 ---help---
13116 kexec is a system call that implements the ability to shutdown your
13117 current kernel, and to start another kernel. It is like a reboot
13118 diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
13119 index 7b11c5f..755a026 100644
13120 --- a/arch/tile/include/asm/atomic_64.h
13121 +++ b/arch/tile/include/asm/atomic_64.h
13122 @@ -105,6 +105,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
13123
13124 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
13125
13126 +#define atomic64_read_unchecked(v) atomic64_read(v)
13127 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
13128 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
13129 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
13130 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
13131 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
13132 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
13133 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
13134 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
13135 +
13136 /* Define this to indicate that cmpxchg is an efficient operation. */
13137 #define __HAVE_ARCH_CMPXCHG
13138
13139 diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
13140 index 6160761..00cac88 100644
13141 --- a/arch/tile/include/asm/cache.h
13142 +++ b/arch/tile/include/asm/cache.h
13143 @@ -15,11 +15,12 @@
13144 #ifndef _ASM_TILE_CACHE_H
13145 #define _ASM_TILE_CACHE_H
13146
13147 +#include <linux/const.h>
13148 #include <arch/chip.h>
13149
13150 /* bytes per L1 data cache line */
13151 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
13152 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
13153 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
13154
13155 /* bytes per L2 cache line */
13156 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
13157 diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
13158 index b6cde32..c0cb736 100644
13159 --- a/arch/tile/include/asm/uaccess.h
13160 +++ b/arch/tile/include/asm/uaccess.h
13161 @@ -414,9 +414,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
13162 const void __user *from,
13163 unsigned long n)
13164 {
13165 - int sz = __compiletime_object_size(to);
13166 + size_t sz = __compiletime_object_size(to);
13167
13168 - if (likely(sz == -1 || sz >= n))
13169 + if (likely(sz == (size_t)-1 || sz >= n))
13170 n = _copy_from_user(to, from, n);
13171 else
13172 copy_from_user_overflow();
13173 diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
13174 index e514899..f8743c4 100644
13175 --- a/arch/tile/mm/hugetlbpage.c
13176 +++ b/arch/tile/mm/hugetlbpage.c
13177 @@ -207,6 +207,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
13178 info.high_limit = TASK_SIZE;
13179 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
13180 info.align_offset = 0;
13181 + info.threadstack_offset = 0;
13182 return vm_unmapped_area(&info);
13183 }
13184
13185 @@ -224,6 +225,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
13186 info.high_limit = current->mm->mmap_base;
13187 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
13188 info.align_offset = 0;
13189 + info.threadstack_offset = 0;
13190 addr = vm_unmapped_area(&info);
13191
13192 /*
13193 diff --git a/arch/um/Makefile b/arch/um/Makefile
13194 index e4b1a96..16162f8 100644
13195 --- a/arch/um/Makefile
13196 +++ b/arch/um/Makefile
13197 @@ -72,6 +72,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
13198 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
13199 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
13200
13201 +ifdef CONSTIFY_PLUGIN
13202 +USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
13203 +endif
13204 +
13205 #This will adjust *FLAGS accordingly to the platform.
13206 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
13207
13208 diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
13209 index 19e1bdd..3665b77 100644
13210 --- a/arch/um/include/asm/cache.h
13211 +++ b/arch/um/include/asm/cache.h
13212 @@ -1,6 +1,7 @@
13213 #ifndef __UM_CACHE_H
13214 #define __UM_CACHE_H
13215
13216 +#include <linux/const.h>
13217
13218 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
13219 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
13220 @@ -12,6 +13,6 @@
13221 # define L1_CACHE_SHIFT 5
13222 #endif
13223
13224 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
13225 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
13226
13227 #endif
13228 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
13229 index 2e0a6b1..a64d0f5 100644
13230 --- a/arch/um/include/asm/kmap_types.h
13231 +++ b/arch/um/include/asm/kmap_types.h
13232 @@ -8,6 +8,6 @@
13233
13234 /* No more #include "asm/arch/kmap_types.h" ! */
13235
13236 -#define KM_TYPE_NR 14
13237 +#define KM_TYPE_NR 15
13238
13239 #endif
13240 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
13241 index 71c5d13..4c7b9f1 100644
13242 --- a/arch/um/include/asm/page.h
13243 +++ b/arch/um/include/asm/page.h
13244 @@ -14,6 +14,9 @@
13245 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
13246 #define PAGE_MASK (~(PAGE_SIZE-1))
13247
13248 +#define ktla_ktva(addr) (addr)
13249 +#define ktva_ktla(addr) (addr)
13250 +
13251 #ifndef __ASSEMBLY__
13252
13253 struct page;
13254 diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
13255 index 0032f92..cd151e0 100644
13256 --- a/arch/um/include/asm/pgtable-3level.h
13257 +++ b/arch/um/include/asm/pgtable-3level.h
13258 @@ -58,6 +58,7 @@
13259 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
13260 #define pud_populate(mm, pud, pmd) \
13261 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
13262 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
13263
13264 #ifdef CONFIG_64BIT
13265 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
13266 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
13267 index f17bca8..48adb87 100644
13268 --- a/arch/um/kernel/process.c
13269 +++ b/arch/um/kernel/process.c
13270 @@ -356,22 +356,6 @@ int singlestepping(void * t)
13271 return 2;
13272 }
13273
13274 -/*
13275 - * Only x86 and x86_64 have an arch_align_stack().
13276 - * All other arches have "#define arch_align_stack(x) (x)"
13277 - * in their asm/exec.h
13278 - * As this is included in UML from asm-um/system-generic.h,
13279 - * we can use it to behave as the subarch does.
13280 - */
13281 -#ifndef arch_align_stack
13282 -unsigned long arch_align_stack(unsigned long sp)
13283 -{
13284 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
13285 - sp -= get_random_int() % 8192;
13286 - return sp & ~0xf;
13287 -}
13288 -#endif
13289 -
13290 unsigned long get_wchan(struct task_struct *p)
13291 {
13292 unsigned long stack_page, sp, ip;
13293 diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
13294 index ad8f795..2c7eec6 100644
13295 --- a/arch/unicore32/include/asm/cache.h
13296 +++ b/arch/unicore32/include/asm/cache.h
13297 @@ -12,8 +12,10 @@
13298 #ifndef __UNICORE_CACHE_H__
13299 #define __UNICORE_CACHE_H__
13300
13301 -#define L1_CACHE_SHIFT (5)
13302 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
13303 +#include <linux/const.h>
13304 +
13305 +#define L1_CACHE_SHIFT 5
13306 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
13307
13308 /*
13309 * Memory returned by kmalloc() may be used for DMA, so we must make
13310 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
13311 index 3632743..5cf7bff 100644
13312 --- a/arch/x86/Kconfig
13313 +++ b/arch/x86/Kconfig
13314 @@ -130,7 +130,7 @@ config X86
13315 select RTC_LIB
13316 select HAVE_DEBUG_STACKOVERFLOW
13317 select HAVE_IRQ_EXIT_ON_IRQ_STACK if X86_64
13318 - select HAVE_CC_STACKPROTECTOR
13319 + select HAVE_CC_STACKPROTECTOR if X86_64 || !PAX_MEMORY_UDEREF
13320 select GENERIC_CPU_AUTOPROBE
13321 select HAVE_ARCH_AUDITSYSCALL
13322 select ARCH_SUPPORTS_ATOMIC_RMW
13323 @@ -258,7 +258,7 @@ config X86_HT
13324
13325 config X86_32_LAZY_GS
13326 def_bool y
13327 - depends on X86_32 && !CC_STACKPROTECTOR
13328 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
13329
13330 config ARCH_HWEIGHT_CFLAGS
13331 string
13332 @@ -555,6 +555,7 @@ config SCHED_OMIT_FRAME_POINTER
13333
13334 menuconfig HYPERVISOR_GUEST
13335 bool "Linux guest support"
13336 + depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_GUEST || (GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_XEN)
13337 ---help---
13338 Say Y here to enable options for running Linux under various hyper-
13339 visors. This option enables basic hypervisor detection and platform
13340 @@ -928,6 +929,7 @@ config VM86
13341
13342 config X86_16BIT
13343 bool "Enable support for 16-bit segments" if EXPERT
13344 + depends on !GRKERNSEC
13345 default y
13346 ---help---
13347 This option is required by programs like Wine to run 16-bit
13348 @@ -1083,6 +1085,7 @@ choice
13349
13350 config NOHIGHMEM
13351 bool "off"
13352 + depends on !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
13353 ---help---
13354 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
13355 However, the address space of 32-bit x86 processors is only 4
13356 @@ -1119,6 +1122,7 @@ config NOHIGHMEM
13357
13358 config HIGHMEM4G
13359 bool "4GB"
13360 + depends on !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
13361 ---help---
13362 Select this if you have a 32-bit processor and between 1 and 4
13363 gigabytes of physical RAM.
13364 @@ -1171,7 +1175,7 @@ config PAGE_OFFSET
13365 hex
13366 default 0xB0000000 if VMSPLIT_3G_OPT
13367 default 0x80000000 if VMSPLIT_2G
13368 - default 0x78000000 if VMSPLIT_2G_OPT
13369 + default 0x70000000 if VMSPLIT_2G_OPT
13370 default 0x40000000 if VMSPLIT_1G
13371 default 0xC0000000
13372 depends on X86_32
13373 @@ -1586,6 +1590,7 @@ source kernel/Kconfig.hz
13374
13375 config KEXEC
13376 bool "kexec system call"
13377 + depends on !GRKERNSEC_KMEM
13378 ---help---
13379 kexec is a system call that implements the ability to shutdown your
13380 current kernel, and to start another kernel. It is like a reboot
13381 @@ -1771,7 +1776,9 @@ config X86_NEED_RELOCS
13382
13383 config PHYSICAL_ALIGN
13384 hex "Alignment value to which kernel should be aligned"
13385 - default "0x200000"
13386 + default "0x1000000"
13387 + range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
13388 + range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
13389 range 0x2000 0x1000000 if X86_32
13390 range 0x200000 0x1000000 if X86_64
13391 ---help---
13392 @@ -1854,6 +1861,7 @@ config COMPAT_VDSO
13393 def_bool n
13394 prompt "Disable the 32-bit vDSO (needed for glibc 2.3.3)"
13395 depends on X86_32 || IA32_EMULATION
13396 + depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
13397 ---help---
13398 Certain buggy versions of glibc will crash if they are
13399 presented with a 32-bit vDSO that is not mapped at the address
13400 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
13401 index 6983314..54ad7e8 100644
13402 --- a/arch/x86/Kconfig.cpu
13403 +++ b/arch/x86/Kconfig.cpu
13404 @@ -319,7 +319,7 @@ config X86_PPRO_FENCE
13405
13406 config X86_F00F_BUG
13407 def_bool y
13408 - depends on M586MMX || M586TSC || M586 || M486
13409 + depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
13410
13411 config X86_INVD_BUG
13412 def_bool y
13413 @@ -327,7 +327,7 @@ config X86_INVD_BUG
13414
13415 config X86_ALIGNMENT_16
13416 def_bool y
13417 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
13418 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
13419
13420 config X86_INTEL_USERCOPY
13421 def_bool y
13422 @@ -369,7 +369,7 @@ config X86_CMPXCHG64
13423 # generates cmov.
13424 config X86_CMOV
13425 def_bool y
13426 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
13427 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
13428
13429 config X86_MINIMUM_CPU_FAMILY
13430 int
13431 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
13432 index 61bd2ad..50b625d 100644
13433 --- a/arch/x86/Kconfig.debug
13434 +++ b/arch/x86/Kconfig.debug
13435 @@ -93,7 +93,7 @@ config EFI_PGT_DUMP
13436 config DEBUG_RODATA
13437 bool "Write protect kernel read-only data structures"
13438 default y
13439 - depends on DEBUG_KERNEL
13440 + depends on DEBUG_KERNEL && BROKEN
13441 ---help---
13442 Mark the kernel read-only data as write-protected in the pagetables,
13443 in order to catch accidental (and incorrect) writes to such const
13444 @@ -111,7 +111,7 @@ config DEBUG_RODATA_TEST
13445
13446 config DEBUG_SET_MODULE_RONX
13447 bool "Set loadable kernel module data as NX and text as RO"
13448 - depends on MODULES
13449 + depends on MODULES && BROKEN
13450 ---help---
13451 This option helps catch unintended modifications to loadable
13452 kernel module's text and read-only data. It also prevents execution
13453 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
13454 index 60087ca..9d9500e 100644
13455 --- a/arch/x86/Makefile
13456 +++ b/arch/x86/Makefile
13457 @@ -68,9 +68,6 @@ ifeq ($(CONFIG_X86_32),y)
13458 # CPU-specific tuning. Anything which can be shared with UML should go here.
13459 include $(srctree)/arch/x86/Makefile_32.cpu
13460 KBUILD_CFLAGS += $(cflags-y)
13461 -
13462 - # temporary until string.h is fixed
13463 - KBUILD_CFLAGS += -ffreestanding
13464 else
13465 BITS := 64
13466 UTS_MACHINE := x86_64
13467 @@ -111,6 +108,9 @@ else
13468 KBUILD_CFLAGS += $(call cc-option,-maccumulate-outgoing-args)
13469 endif
13470
13471 +# temporary until string.h is fixed
13472 +KBUILD_CFLAGS += -ffreestanding
13473 +
13474 # Make sure compiler does not have buggy stack-protector support.
13475 ifdef CONFIG_CC_STACKPROTECTOR
13476 cc_has_sp := $(srctree)/scripts/gcc-x86_$(BITS)-has-stack-protector.sh
13477 @@ -184,6 +184,7 @@ archheaders:
13478 $(Q)$(MAKE) $(build)=arch/x86/syscalls all
13479
13480 archprepare:
13481 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
13482 ifeq ($(CONFIG_KEXEC_FILE),y)
13483 $(Q)$(MAKE) $(build)=arch/x86/purgatory arch/x86/purgatory/kexec-purgatory.c
13484 endif
13485 @@ -274,3 +275,9 @@ define archhelp
13486 echo ' FDINITRD=file initrd for the booted kernel'
13487 echo ' kvmconfig - Enable additional options for guest kernel support'
13488 endef
13489 +
13490 +define OLD_LD
13491 +
13492 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
13493 +*** Please upgrade your binutils to 2.18 or newer
13494 +endef
13495 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
13496 index dbe8dd2..2f0a98f 100644
13497 --- a/arch/x86/boot/Makefile
13498 +++ b/arch/x86/boot/Makefile
13499 @@ -52,6 +52,9 @@ $(obj)/cpustr.h: $(obj)/mkcpustr FORCE
13500 # ---------------------------------------------------------------------------
13501
13502 KBUILD_CFLAGS := $(USERINCLUDE) $(REALMODE_CFLAGS) -D_SETUP
13503 +ifdef CONSTIFY_PLUGIN
13504 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
13505 +endif
13506 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
13507 GCOV_PROFILE := n
13508
13509 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
13510 index 878e4b9..20537ab 100644
13511 --- a/arch/x86/boot/bitops.h
13512 +++ b/arch/x86/boot/bitops.h
13513 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
13514 u8 v;
13515 const u32 *p = (const u32 *)addr;
13516
13517 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
13518 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
13519 return v;
13520 }
13521
13522 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
13523
13524 static inline void set_bit(int nr, void *addr)
13525 {
13526 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
13527 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
13528 }
13529
13530 #endif /* BOOT_BITOPS_H */
13531 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
13532 index bd49ec6..94c7f58 100644
13533 --- a/arch/x86/boot/boot.h
13534 +++ b/arch/x86/boot/boot.h
13535 @@ -84,7 +84,7 @@ static inline void io_delay(void)
13536 static inline u16 ds(void)
13537 {
13538 u16 seg;
13539 - asm("movw %%ds,%0" : "=rm" (seg));
13540 + asm volatile("movw %%ds,%0" : "=rm" (seg));
13541 return seg;
13542 }
13543
13544 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
13545 index b5bb498..74110e8 100644
13546 --- a/arch/x86/boot/compressed/Makefile
13547 +++ b/arch/x86/boot/compressed/Makefile
13548 @@ -16,6 +16,9 @@ KBUILD_CFLAGS += $(cflags-y)
13549 KBUILD_CFLAGS += -mno-mmx -mno-sse
13550 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
13551 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
13552 +ifdef CONSTIFY_PLUGIN
13553 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
13554 +endif
13555
13556 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
13557 GCOV_PROFILE := n
13558 diff --git a/arch/x86/boot/compressed/efi_stub_32.S b/arch/x86/boot/compressed/efi_stub_32.S
13559 index a53440e..c3dbf1e 100644
13560 --- a/arch/x86/boot/compressed/efi_stub_32.S
13561 +++ b/arch/x86/boot/compressed/efi_stub_32.S
13562 @@ -46,16 +46,13 @@ ENTRY(efi_call_phys)
13563 * parameter 2, ..., param n. To make things easy, we save the return
13564 * address of efi_call_phys in a global variable.
13565 */
13566 - popl %ecx
13567 - movl %ecx, saved_return_addr(%edx)
13568 - /* get the function pointer into ECX*/
13569 - popl %ecx
13570 - movl %ecx, efi_rt_function_ptr(%edx)
13571 + popl saved_return_addr(%edx)
13572 + popl efi_rt_function_ptr(%edx)
13573
13574 /*
13575 * 3. Call the physical function.
13576 */
13577 - call *%ecx
13578 + call *efi_rt_function_ptr(%edx)
13579
13580 /*
13581 * 4. Balance the stack. And because EAX contain the return value,
13582 @@ -67,15 +64,12 @@ ENTRY(efi_call_phys)
13583 1: popl %edx
13584 subl $1b, %edx
13585
13586 - movl efi_rt_function_ptr(%edx), %ecx
13587 - pushl %ecx
13588 + pushl efi_rt_function_ptr(%edx)
13589
13590 /*
13591 * 10. Push the saved return address onto the stack and return.
13592 */
13593 - movl saved_return_addr(%edx), %ecx
13594 - pushl %ecx
13595 - ret
13596 + jmpl *saved_return_addr(%edx)
13597 ENDPROC(efi_call_phys)
13598 .previous
13599
13600 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
13601 index 1d7fbbc..36ecd58 100644
13602 --- a/arch/x86/boot/compressed/head_32.S
13603 +++ b/arch/x86/boot/compressed/head_32.S
13604 @@ -140,10 +140,10 @@ preferred_addr:
13605 addl %eax, %ebx
13606 notl %eax
13607 andl %eax, %ebx
13608 - cmpl $LOAD_PHYSICAL_ADDR, %ebx
13609 + cmpl $____LOAD_PHYSICAL_ADDR, %ebx
13610 jge 1f
13611 #endif
13612 - movl $LOAD_PHYSICAL_ADDR, %ebx
13613 + movl $____LOAD_PHYSICAL_ADDR, %ebx
13614 1:
13615
13616 /* Target address to relocate to for decompression */
13617 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
13618 index 6b1766c..ad465c9 100644
13619 --- a/arch/x86/boot/compressed/head_64.S
13620 +++ b/arch/x86/boot/compressed/head_64.S
13621 @@ -94,10 +94,10 @@ ENTRY(startup_32)
13622 addl %eax, %ebx
13623 notl %eax
13624 andl %eax, %ebx
13625 - cmpl $LOAD_PHYSICAL_ADDR, %ebx
13626 + cmpl $____LOAD_PHYSICAL_ADDR, %ebx
13627 jge 1f
13628 #endif
13629 - movl $LOAD_PHYSICAL_ADDR, %ebx
13630 + movl $____LOAD_PHYSICAL_ADDR, %ebx
13631 1:
13632
13633 /* Target address to relocate to for decompression */
13634 @@ -322,10 +322,10 @@ preferred_addr:
13635 addq %rax, %rbp
13636 notq %rax
13637 andq %rax, %rbp
13638 - cmpq $LOAD_PHYSICAL_ADDR, %rbp
13639 + cmpq $____LOAD_PHYSICAL_ADDR, %rbp
13640 jge 1f
13641 #endif
13642 - movq $LOAD_PHYSICAL_ADDR, %rbp
13643 + movq $____LOAD_PHYSICAL_ADDR, %rbp
13644 1:
13645
13646 /* Target address to relocate to for decompression */
13647 @@ -434,8 +434,8 @@ gdt:
13648 .long gdt
13649 .word 0
13650 .quad 0x0000000000000000 /* NULL descriptor */
13651 - .quad 0x00af9a000000ffff /* __KERNEL_CS */
13652 - .quad 0x00cf92000000ffff /* __KERNEL_DS */
13653 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
13654 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
13655 .quad 0x0080890000000000 /* TS descriptor */
13656 .quad 0x0000000000000000 /* TS continued */
13657 gdt_end:
13658 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
13659 index 30dd59a..cd9edc3 100644
13660 --- a/arch/x86/boot/compressed/misc.c
13661 +++ b/arch/x86/boot/compressed/misc.c
13662 @@ -242,7 +242,7 @@ static void handle_relocations(void *output, unsigned long output_len)
13663 * Calculate the delta between where vmlinux was linked to load
13664 * and where it was actually loaded.
13665 */
13666 - delta = min_addr - LOAD_PHYSICAL_ADDR;
13667 + delta = min_addr - ____LOAD_PHYSICAL_ADDR;
13668 if (!delta) {
13669 debug_putstr("No relocation needed... ");
13670 return;
13671 @@ -312,7 +312,7 @@ static void parse_elf(void *output)
13672 Elf32_Ehdr ehdr;
13673 Elf32_Phdr *phdrs, *phdr;
13674 #endif
13675 - void *dest;
13676 + void *dest, *prev;
13677 int i;
13678
13679 memcpy(&ehdr, output, sizeof(ehdr));
13680 @@ -339,13 +339,16 @@ static void parse_elf(void *output)
13681 case PT_LOAD:
13682 #ifdef CONFIG_RELOCATABLE
13683 dest = output;
13684 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
13685 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
13686 #else
13687 dest = (void *)(phdr->p_paddr);
13688 #endif
13689 memcpy(dest,
13690 output + phdr->p_offset,
13691 phdr->p_filesz);
13692 + if (i)
13693 + memset(prev, 0xff, dest - prev);
13694 + prev = dest + phdr->p_filesz;
13695 break;
13696 default: /* Ignore other PT_* */ break;
13697 }
13698 @@ -402,7 +405,7 @@ asmlinkage __visible void *decompress_kernel(void *rmode, memptr heap,
13699 error("Destination address too large");
13700 #endif
13701 #ifndef CONFIG_RELOCATABLE
13702 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
13703 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
13704 error("Wrong destination address");
13705 #endif
13706
13707 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
13708 index 1fd7d57..0f7d096 100644
13709 --- a/arch/x86/boot/cpucheck.c
13710 +++ b/arch/x86/boot/cpucheck.c
13711 @@ -125,9 +125,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
13712 u32 ecx = MSR_K7_HWCR;
13713 u32 eax, edx;
13714
13715 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13716 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13717 eax &= ~(1 << 15);
13718 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13719 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13720
13721 get_cpuflags(); /* Make sure it really did something */
13722 err = check_cpuflags();
13723 @@ -140,9 +140,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
13724 u32 ecx = MSR_VIA_FCR;
13725 u32 eax, edx;
13726
13727 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13728 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13729 eax |= (1<<1)|(1<<7);
13730 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13731 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13732
13733 set_bit(X86_FEATURE_CX8, cpu.flags);
13734 err = check_cpuflags();
13735 @@ -153,12 +153,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
13736 u32 eax, edx;
13737 u32 level = 1;
13738
13739 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13740 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
13741 - asm("cpuid"
13742 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13743 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
13744 + asm volatile("cpuid"
13745 : "+a" (level), "=d" (cpu.flags[0])
13746 : : "ecx", "ebx");
13747 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13748 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13749
13750 err = check_cpuflags();
13751 } else if (err == 0x01 &&
13752 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
13753 index 16ef025..91e033b 100644
13754 --- a/arch/x86/boot/header.S
13755 +++ b/arch/x86/boot/header.S
13756 @@ -438,10 +438,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
13757 # single linked list of
13758 # struct setup_data
13759
13760 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
13761 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
13762
13763 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
13764 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13765 +#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
13766 +#else
13767 #define VO_INIT_SIZE (VO__end - VO__text)
13768 +#endif
13769 #if ZO_INIT_SIZE > VO_INIT_SIZE
13770 #define INIT_SIZE ZO_INIT_SIZE
13771 #else
13772 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
13773 index db75d07..8e6d0af 100644
13774 --- a/arch/x86/boot/memory.c
13775 +++ b/arch/x86/boot/memory.c
13776 @@ -19,7 +19,7 @@
13777
13778 static int detect_memory_e820(void)
13779 {
13780 - int count = 0;
13781 + unsigned int count = 0;
13782 struct biosregs ireg, oreg;
13783 struct e820entry *desc = boot_params.e820_map;
13784 static struct e820entry buf; /* static so it is zeroed */
13785 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
13786 index ba3e100..6501b8f 100644
13787 --- a/arch/x86/boot/video-vesa.c
13788 +++ b/arch/x86/boot/video-vesa.c
13789 @@ -201,6 +201,7 @@ static void vesa_store_pm_info(void)
13790
13791 boot_params.screen_info.vesapm_seg = oreg.es;
13792 boot_params.screen_info.vesapm_off = oreg.di;
13793 + boot_params.screen_info.vesapm_size = oreg.cx;
13794 }
13795
13796 /*
13797 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
13798 index 43eda28..5ab5fdb 100644
13799 --- a/arch/x86/boot/video.c
13800 +++ b/arch/x86/boot/video.c
13801 @@ -96,7 +96,7 @@ static void store_mode_params(void)
13802 static unsigned int get_entry(void)
13803 {
13804 char entry_buf[4];
13805 - int i, len = 0;
13806 + unsigned int i, len = 0;
13807 int key;
13808 unsigned int v;
13809
13810 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
13811 index 9105655..41779c1 100644
13812 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
13813 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
13814 @@ -8,6 +8,8 @@
13815 * including this sentence is retained in full.
13816 */
13817
13818 +#include <asm/alternative-asm.h>
13819 +
13820 .extern crypto_ft_tab
13821 .extern crypto_it_tab
13822 .extern crypto_fl_tab
13823 @@ -70,6 +72,8 @@
13824 je B192; \
13825 leaq 32(r9),r9;
13826
13827 +#define ret pax_force_retaddr; ret
13828 +
13829 #define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
13830 movq r1,r2; \
13831 movq r3,r4; \
13832 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
13833 index 477e9d7..c92c7d8 100644
13834 --- a/arch/x86/crypto/aesni-intel_asm.S
13835 +++ b/arch/x86/crypto/aesni-intel_asm.S
13836 @@ -31,6 +31,7 @@
13837
13838 #include <linux/linkage.h>
13839 #include <asm/inst.h>
13840 +#include <asm/alternative-asm.h>
13841
13842 #ifdef __x86_64__
13843 .data
13844 @@ -205,7 +206,7 @@ enc: .octa 0x2
13845 * num_initial_blocks = b mod 4
13846 * encrypt the initial num_initial_blocks blocks and apply ghash on
13847 * the ciphertext
13848 -* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13849 +* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13850 * are clobbered
13851 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
13852 */
13853 @@ -214,8 +215,8 @@ enc: .octa 0x2
13854 .macro INITIAL_BLOCKS_DEC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
13855 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
13856 mov arg7, %r10 # %r10 = AAD
13857 - mov arg8, %r12 # %r12 = aadLen
13858 - mov %r12, %r11
13859 + mov arg8, %r15 # %r15 = aadLen
13860 + mov %r15, %r11
13861 pxor %xmm\i, %xmm\i
13862 _get_AAD_loop\num_initial_blocks\operation:
13863 movd (%r10), \TMP1
13864 @@ -223,15 +224,15 @@ _get_AAD_loop\num_initial_blocks\operation:
13865 psrldq $4, %xmm\i
13866 pxor \TMP1, %xmm\i
13867 add $4, %r10
13868 - sub $4, %r12
13869 + sub $4, %r15
13870 jne _get_AAD_loop\num_initial_blocks\operation
13871 cmp $16, %r11
13872 je _get_AAD_loop2_done\num_initial_blocks\operation
13873 - mov $16, %r12
13874 + mov $16, %r15
13875 _get_AAD_loop2\num_initial_blocks\operation:
13876 psrldq $4, %xmm\i
13877 - sub $4, %r12
13878 - cmp %r11, %r12
13879 + sub $4, %r15
13880 + cmp %r11, %r15
13881 jne _get_AAD_loop2\num_initial_blocks\operation
13882 _get_AAD_loop2_done\num_initial_blocks\operation:
13883 movdqa SHUF_MASK(%rip), %xmm14
13884 @@ -443,7 +444,7 @@ _initial_blocks_done\num_initial_blocks\operation:
13885 * num_initial_blocks = b mod 4
13886 * encrypt the initial num_initial_blocks blocks and apply ghash on
13887 * the ciphertext
13888 -* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13889 +* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13890 * are clobbered
13891 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
13892 */
13893 @@ -452,8 +453,8 @@ _initial_blocks_done\num_initial_blocks\operation:
13894 .macro INITIAL_BLOCKS_ENC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
13895 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
13896 mov arg7, %r10 # %r10 = AAD
13897 - mov arg8, %r12 # %r12 = aadLen
13898 - mov %r12, %r11
13899 + mov arg8, %r15 # %r15 = aadLen
13900 + mov %r15, %r11
13901 pxor %xmm\i, %xmm\i
13902 _get_AAD_loop\num_initial_blocks\operation:
13903 movd (%r10), \TMP1
13904 @@ -461,15 +462,15 @@ _get_AAD_loop\num_initial_blocks\operation:
13905 psrldq $4, %xmm\i
13906 pxor \TMP1, %xmm\i
13907 add $4, %r10
13908 - sub $4, %r12
13909 + sub $4, %r15
13910 jne _get_AAD_loop\num_initial_blocks\operation
13911 cmp $16, %r11
13912 je _get_AAD_loop2_done\num_initial_blocks\operation
13913 - mov $16, %r12
13914 + mov $16, %r15
13915 _get_AAD_loop2\num_initial_blocks\operation:
13916 psrldq $4, %xmm\i
13917 - sub $4, %r12
13918 - cmp %r11, %r12
13919 + sub $4, %r15
13920 + cmp %r11, %r15
13921 jne _get_AAD_loop2\num_initial_blocks\operation
13922 _get_AAD_loop2_done\num_initial_blocks\operation:
13923 movdqa SHUF_MASK(%rip), %xmm14
13924 @@ -1269,7 +1270,7 @@ TMP7 XMM1 XMM2 XMM3 XMM4 XMMDst
13925 *
13926 *****************************************************************************/
13927 ENTRY(aesni_gcm_dec)
13928 - push %r12
13929 + push %r15
13930 push %r13
13931 push %r14
13932 mov %rsp, %r14
13933 @@ -1279,8 +1280,8 @@ ENTRY(aesni_gcm_dec)
13934 */
13935 sub $VARIABLE_OFFSET, %rsp
13936 and $~63, %rsp # align rsp to 64 bytes
13937 - mov %arg6, %r12
13938 - movdqu (%r12), %xmm13 # %xmm13 = HashKey
13939 + mov %arg6, %r15
13940 + movdqu (%r15), %xmm13 # %xmm13 = HashKey
13941 movdqa SHUF_MASK(%rip), %xmm2
13942 PSHUFB_XMM %xmm2, %xmm13
13943
13944 @@ -1308,10 +1309,10 @@ ENTRY(aesni_gcm_dec)
13945 movdqa %xmm13, HashKey(%rsp) # store HashKey<<1 (mod poly)
13946 mov %arg4, %r13 # save the number of bytes of plaintext/ciphertext
13947 and $-16, %r13 # %r13 = %r13 - (%r13 mod 16)
13948 - mov %r13, %r12
13949 - and $(3<<4), %r12
13950 + mov %r13, %r15
13951 + and $(3<<4), %r15
13952 jz _initial_num_blocks_is_0_decrypt
13953 - cmp $(2<<4), %r12
13954 + cmp $(2<<4), %r15
13955 jb _initial_num_blocks_is_1_decrypt
13956 je _initial_num_blocks_is_2_decrypt
13957 _initial_num_blocks_is_3_decrypt:
13958 @@ -1361,16 +1362,16 @@ _zero_cipher_left_decrypt:
13959 sub $16, %r11
13960 add %r13, %r11
13961 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte block
13962 - lea SHIFT_MASK+16(%rip), %r12
13963 - sub %r13, %r12
13964 + lea SHIFT_MASK+16(%rip), %r15
13965 + sub %r13, %r15
13966 # adjust the shuffle mask pointer to be able to shift 16-%r13 bytes
13967 # (%r13 is the number of bytes in plaintext mod 16)
13968 - movdqu (%r12), %xmm2 # get the appropriate shuffle mask
13969 + movdqu (%r15), %xmm2 # get the appropriate shuffle mask
13970 PSHUFB_XMM %xmm2, %xmm1 # right shift 16-%r13 butes
13971
13972 movdqa %xmm1, %xmm2
13973 pxor %xmm1, %xmm0 # Ciphertext XOR E(K, Yn)
13974 - movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
13975 + movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
13976 # get the appropriate mask to mask out top 16-%r13 bytes of %xmm0
13977 pand %xmm1, %xmm0 # mask out top 16-%r13 bytes of %xmm0
13978 pand %xmm1, %xmm2
13979 @@ -1399,9 +1400,9 @@ _less_than_8_bytes_left_decrypt:
13980 sub $1, %r13
13981 jne _less_than_8_bytes_left_decrypt
13982 _multiple_of_16_bytes_decrypt:
13983 - mov arg8, %r12 # %r13 = aadLen (number of bytes)
13984 - shl $3, %r12 # convert into number of bits
13985 - movd %r12d, %xmm15 # len(A) in %xmm15
13986 + mov arg8, %r15 # %r13 = aadLen (number of bytes)
13987 + shl $3, %r15 # convert into number of bits
13988 + movd %r15d, %xmm15 # len(A) in %xmm15
13989 shl $3, %arg4 # len(C) in bits (*128)
13990 MOVQ_R64_XMM %arg4, %xmm1
13991 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
13992 @@ -1440,7 +1441,8 @@ _return_T_done_decrypt:
13993 mov %r14, %rsp
13994 pop %r14
13995 pop %r13
13996 - pop %r12
13997 + pop %r15
13998 + pax_force_retaddr
13999 ret
14000 ENDPROC(aesni_gcm_dec)
14001
14002 @@ -1529,7 +1531,7 @@ ENDPROC(aesni_gcm_dec)
14003 * poly = x^128 + x^127 + x^126 + x^121 + 1
14004 ***************************************************************************/
14005 ENTRY(aesni_gcm_enc)
14006 - push %r12
14007 + push %r15
14008 push %r13
14009 push %r14
14010 mov %rsp, %r14
14011 @@ -1539,8 +1541,8 @@ ENTRY(aesni_gcm_enc)
14012 #
14013 sub $VARIABLE_OFFSET, %rsp
14014 and $~63, %rsp
14015 - mov %arg6, %r12
14016 - movdqu (%r12), %xmm13
14017 + mov %arg6, %r15
14018 + movdqu (%r15), %xmm13
14019 movdqa SHUF_MASK(%rip), %xmm2
14020 PSHUFB_XMM %xmm2, %xmm13
14021
14022 @@ -1564,13 +1566,13 @@ ENTRY(aesni_gcm_enc)
14023 movdqa %xmm13, HashKey(%rsp)
14024 mov %arg4, %r13 # %xmm13 holds HashKey<<1 (mod poly)
14025 and $-16, %r13
14026 - mov %r13, %r12
14027 + mov %r13, %r15
14028
14029 # Encrypt first few blocks
14030
14031 - and $(3<<4), %r12
14032 + and $(3<<4), %r15
14033 jz _initial_num_blocks_is_0_encrypt
14034 - cmp $(2<<4), %r12
14035 + cmp $(2<<4), %r15
14036 jb _initial_num_blocks_is_1_encrypt
14037 je _initial_num_blocks_is_2_encrypt
14038 _initial_num_blocks_is_3_encrypt:
14039 @@ -1623,14 +1625,14 @@ _zero_cipher_left_encrypt:
14040 sub $16, %r11
14041 add %r13, %r11
14042 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte blocks
14043 - lea SHIFT_MASK+16(%rip), %r12
14044 - sub %r13, %r12
14045 + lea SHIFT_MASK+16(%rip), %r15
14046 + sub %r13, %r15
14047 # adjust the shuffle mask pointer to be able to shift 16-r13 bytes
14048 # (%r13 is the number of bytes in plaintext mod 16)
14049 - movdqu (%r12), %xmm2 # get the appropriate shuffle mask
14050 + movdqu (%r15), %xmm2 # get the appropriate shuffle mask
14051 PSHUFB_XMM %xmm2, %xmm1 # shift right 16-r13 byte
14052 pxor %xmm1, %xmm0 # Plaintext XOR Encrypt(K, Yn)
14053 - movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
14054 + movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
14055 # get the appropriate mask to mask out top 16-r13 bytes of xmm0
14056 pand %xmm1, %xmm0 # mask out top 16-r13 bytes of xmm0
14057 movdqa SHUF_MASK(%rip), %xmm10
14058 @@ -1663,9 +1665,9 @@ _less_than_8_bytes_left_encrypt:
14059 sub $1, %r13
14060 jne _less_than_8_bytes_left_encrypt
14061 _multiple_of_16_bytes_encrypt:
14062 - mov arg8, %r12 # %r12 = addLen (number of bytes)
14063 - shl $3, %r12
14064 - movd %r12d, %xmm15 # len(A) in %xmm15
14065 + mov arg8, %r15 # %r15 = addLen (number of bytes)
14066 + shl $3, %r15
14067 + movd %r15d, %xmm15 # len(A) in %xmm15
14068 shl $3, %arg4 # len(C) in bits (*128)
14069 MOVQ_R64_XMM %arg4, %xmm1
14070 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
14071 @@ -1704,7 +1706,8 @@ _return_T_done_encrypt:
14072 mov %r14, %rsp
14073 pop %r14
14074 pop %r13
14075 - pop %r12
14076 + pop %r15
14077 + pax_force_retaddr
14078 ret
14079 ENDPROC(aesni_gcm_enc)
14080
14081 @@ -1722,6 +1725,7 @@ _key_expansion_256a:
14082 pxor %xmm1, %xmm0
14083 movaps %xmm0, (TKEYP)
14084 add $0x10, TKEYP
14085 + pax_force_retaddr
14086 ret
14087 ENDPROC(_key_expansion_128)
14088 ENDPROC(_key_expansion_256a)
14089 @@ -1748,6 +1752,7 @@ _key_expansion_192a:
14090 shufps $0b01001110, %xmm2, %xmm1
14091 movaps %xmm1, 0x10(TKEYP)
14092 add $0x20, TKEYP
14093 + pax_force_retaddr
14094 ret
14095 ENDPROC(_key_expansion_192a)
14096
14097 @@ -1768,6 +1773,7 @@ _key_expansion_192b:
14098
14099 movaps %xmm0, (TKEYP)
14100 add $0x10, TKEYP
14101 + pax_force_retaddr
14102 ret
14103 ENDPROC(_key_expansion_192b)
14104
14105 @@ -1781,6 +1787,7 @@ _key_expansion_256b:
14106 pxor %xmm1, %xmm2
14107 movaps %xmm2, (TKEYP)
14108 add $0x10, TKEYP
14109 + pax_force_retaddr
14110 ret
14111 ENDPROC(_key_expansion_256b)
14112
14113 @@ -1894,6 +1901,7 @@ ENTRY(aesni_set_key)
14114 #ifndef __x86_64__
14115 popl KEYP
14116 #endif
14117 + pax_force_retaddr
14118 ret
14119 ENDPROC(aesni_set_key)
14120
14121 @@ -1916,6 +1924,7 @@ ENTRY(aesni_enc)
14122 popl KLEN
14123 popl KEYP
14124 #endif
14125 + pax_force_retaddr
14126 ret
14127 ENDPROC(aesni_enc)
14128
14129 @@ -1974,6 +1983,7 @@ _aesni_enc1:
14130 AESENC KEY STATE
14131 movaps 0x70(TKEYP), KEY
14132 AESENCLAST KEY STATE
14133 + pax_force_retaddr
14134 ret
14135 ENDPROC(_aesni_enc1)
14136
14137 @@ -2083,6 +2093,7 @@ _aesni_enc4:
14138 AESENCLAST KEY STATE2
14139 AESENCLAST KEY STATE3
14140 AESENCLAST KEY STATE4
14141 + pax_force_retaddr
14142 ret
14143 ENDPROC(_aesni_enc4)
14144
14145 @@ -2106,6 +2117,7 @@ ENTRY(aesni_dec)
14146 popl KLEN
14147 popl KEYP
14148 #endif
14149 + pax_force_retaddr
14150 ret
14151 ENDPROC(aesni_dec)
14152
14153 @@ -2164,6 +2176,7 @@ _aesni_dec1:
14154 AESDEC KEY STATE
14155 movaps 0x70(TKEYP), KEY
14156 AESDECLAST KEY STATE
14157 + pax_force_retaddr
14158 ret
14159 ENDPROC(_aesni_dec1)
14160
14161 @@ -2273,6 +2286,7 @@ _aesni_dec4:
14162 AESDECLAST KEY STATE2
14163 AESDECLAST KEY STATE3
14164 AESDECLAST KEY STATE4
14165 + pax_force_retaddr
14166 ret
14167 ENDPROC(_aesni_dec4)
14168
14169 @@ -2331,6 +2345,7 @@ ENTRY(aesni_ecb_enc)
14170 popl KEYP
14171 popl LEN
14172 #endif
14173 + pax_force_retaddr
14174 ret
14175 ENDPROC(aesni_ecb_enc)
14176
14177 @@ -2390,6 +2405,7 @@ ENTRY(aesni_ecb_dec)
14178 popl KEYP
14179 popl LEN
14180 #endif
14181 + pax_force_retaddr
14182 ret
14183 ENDPROC(aesni_ecb_dec)
14184
14185 @@ -2432,6 +2448,7 @@ ENTRY(aesni_cbc_enc)
14186 popl LEN
14187 popl IVP
14188 #endif
14189 + pax_force_retaddr
14190 ret
14191 ENDPROC(aesni_cbc_enc)
14192
14193 @@ -2523,6 +2540,7 @@ ENTRY(aesni_cbc_dec)
14194 popl LEN
14195 popl IVP
14196 #endif
14197 + pax_force_retaddr
14198 ret
14199 ENDPROC(aesni_cbc_dec)
14200
14201 @@ -2550,6 +2568,7 @@ _aesni_inc_init:
14202 mov $1, TCTR_LOW
14203 MOVQ_R64_XMM TCTR_LOW INC
14204 MOVQ_R64_XMM CTR TCTR_LOW
14205 + pax_force_retaddr
14206 ret
14207 ENDPROC(_aesni_inc_init)
14208
14209 @@ -2579,6 +2598,7 @@ _aesni_inc:
14210 .Linc_low:
14211 movaps CTR, IV
14212 PSHUFB_XMM BSWAP_MASK IV
14213 + pax_force_retaddr
14214 ret
14215 ENDPROC(_aesni_inc)
14216
14217 @@ -2640,6 +2660,7 @@ ENTRY(aesni_ctr_enc)
14218 .Lctr_enc_ret:
14219 movups IV, (IVP)
14220 .Lctr_enc_just_ret:
14221 + pax_force_retaddr
14222 ret
14223 ENDPROC(aesni_ctr_enc)
14224
14225 @@ -2766,6 +2787,7 @@ ENTRY(aesni_xts_crypt8)
14226 pxor INC, STATE4
14227 movdqu STATE4, 0x70(OUTP)
14228
14229 + pax_force_retaddr
14230 ret
14231 ENDPROC(aesni_xts_crypt8)
14232
14233 diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
14234 index 246c670..466e2d6 100644
14235 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
14236 +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
14237 @@ -21,6 +21,7 @@
14238 */
14239
14240 #include <linux/linkage.h>
14241 +#include <asm/alternative-asm.h>
14242
14243 .file "blowfish-x86_64-asm.S"
14244 .text
14245 @@ -149,9 +150,11 @@ ENTRY(__blowfish_enc_blk)
14246 jnz .L__enc_xor;
14247
14248 write_block();
14249 + pax_force_retaddr
14250 ret;
14251 .L__enc_xor:
14252 xor_block();
14253 + pax_force_retaddr
14254 ret;
14255 ENDPROC(__blowfish_enc_blk)
14256
14257 @@ -183,6 +186,7 @@ ENTRY(blowfish_dec_blk)
14258
14259 movq %r11, %rbp;
14260
14261 + pax_force_retaddr
14262 ret;
14263 ENDPROC(blowfish_dec_blk)
14264
14265 @@ -334,6 +338,7 @@ ENTRY(__blowfish_enc_blk_4way)
14266
14267 popq %rbx;
14268 popq %rbp;
14269 + pax_force_retaddr
14270 ret;
14271
14272 .L__enc_xor4:
14273 @@ -341,6 +346,7 @@ ENTRY(__blowfish_enc_blk_4way)
14274
14275 popq %rbx;
14276 popq %rbp;
14277 + pax_force_retaddr
14278 ret;
14279 ENDPROC(__blowfish_enc_blk_4way)
14280
14281 @@ -375,5 +381,6 @@ ENTRY(blowfish_dec_blk_4way)
14282 popq %rbx;
14283 popq %rbp;
14284
14285 + pax_force_retaddr
14286 ret;
14287 ENDPROC(blowfish_dec_blk_4way)
14288 diff --git a/arch/x86/crypto/camellia-aesni-avx-asm_64.S b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
14289 index ce71f92..1dce7ec 100644
14290 --- a/arch/x86/crypto/camellia-aesni-avx-asm_64.S
14291 +++ b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
14292 @@ -16,6 +16,7 @@
14293 */
14294
14295 #include <linux/linkage.h>
14296 +#include <asm/alternative-asm.h>
14297
14298 #define CAMELLIA_TABLE_BYTE_LEN 272
14299
14300 @@ -191,6 +192,7 @@ roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
14301 roundsm16(%xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7,
14302 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14, %xmm15,
14303 %rcx, (%r9));
14304 + pax_force_retaddr
14305 ret;
14306 ENDPROC(roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
14307
14308 @@ -199,6 +201,7 @@ roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
14309 roundsm16(%xmm4, %xmm5, %xmm6, %xmm7, %xmm0, %xmm1, %xmm2, %xmm3,
14310 %xmm12, %xmm13, %xmm14, %xmm15, %xmm8, %xmm9, %xmm10, %xmm11,
14311 %rax, (%r9));
14312 + pax_force_retaddr
14313 ret;
14314 ENDPROC(roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
14315
14316 @@ -780,6 +783,7 @@ __camellia_enc_blk16:
14317 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
14318 %xmm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 16(%rax));
14319
14320 + pax_force_retaddr
14321 ret;
14322
14323 .align 8
14324 @@ -865,6 +869,7 @@ __camellia_dec_blk16:
14325 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
14326 %xmm15, (key_table)(CTX), (%rax), 1 * 16(%rax));
14327
14328 + pax_force_retaddr
14329 ret;
14330
14331 .align 8
14332 @@ -904,6 +909,7 @@ ENTRY(camellia_ecb_enc_16way)
14333 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
14334 %xmm8, %rsi);
14335
14336 + pax_force_retaddr
14337 ret;
14338 ENDPROC(camellia_ecb_enc_16way)
14339
14340 @@ -932,6 +938,7 @@ ENTRY(camellia_ecb_dec_16way)
14341 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
14342 %xmm8, %rsi);
14343
14344 + pax_force_retaddr
14345 ret;
14346 ENDPROC(camellia_ecb_dec_16way)
14347
14348 @@ -981,6 +988,7 @@ ENTRY(camellia_cbc_dec_16way)
14349 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
14350 %xmm8, %rsi);
14351
14352 + pax_force_retaddr
14353 ret;
14354 ENDPROC(camellia_cbc_dec_16way)
14355
14356 @@ -1092,6 +1100,7 @@ ENTRY(camellia_ctr_16way)
14357 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
14358 %xmm8, %rsi);
14359
14360 + pax_force_retaddr
14361 ret;
14362 ENDPROC(camellia_ctr_16way)
14363
14364 @@ -1234,6 +1243,7 @@ camellia_xts_crypt_16way:
14365 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
14366 %xmm8, %rsi);
14367
14368 + pax_force_retaddr
14369 ret;
14370 ENDPROC(camellia_xts_crypt_16way)
14371
14372 diff --git a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
14373 index 0e0b886..5a3123c 100644
14374 --- a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
14375 +++ b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
14376 @@ -11,6 +11,7 @@
14377 */
14378
14379 #include <linux/linkage.h>
14380 +#include <asm/alternative-asm.h>
14381
14382 #define CAMELLIA_TABLE_BYTE_LEN 272
14383
14384 @@ -230,6 +231,7 @@ roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
14385 roundsm32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
14386 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14, %ymm15,
14387 %rcx, (%r9));
14388 + pax_force_retaddr
14389 ret;
14390 ENDPROC(roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
14391
14392 @@ -238,6 +240,7 @@ roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
14393 roundsm32(%ymm4, %ymm5, %ymm6, %ymm7, %ymm0, %ymm1, %ymm2, %ymm3,
14394 %ymm12, %ymm13, %ymm14, %ymm15, %ymm8, %ymm9, %ymm10, %ymm11,
14395 %rax, (%r9));
14396 + pax_force_retaddr
14397 ret;
14398 ENDPROC(roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
14399
14400 @@ -820,6 +823,7 @@ __camellia_enc_blk32:
14401 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
14402 %ymm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 32(%rax));
14403
14404 + pax_force_retaddr
14405 ret;
14406
14407 .align 8
14408 @@ -905,6 +909,7 @@ __camellia_dec_blk32:
14409 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
14410 %ymm15, (key_table)(CTX), (%rax), 1 * 32(%rax));
14411
14412 + pax_force_retaddr
14413 ret;
14414
14415 .align 8
14416 @@ -948,6 +953,7 @@ ENTRY(camellia_ecb_enc_32way)
14417
14418 vzeroupper;
14419
14420 + pax_force_retaddr
14421 ret;
14422 ENDPROC(camellia_ecb_enc_32way)
14423
14424 @@ -980,6 +986,7 @@ ENTRY(camellia_ecb_dec_32way)
14425
14426 vzeroupper;
14427
14428 + pax_force_retaddr
14429 ret;
14430 ENDPROC(camellia_ecb_dec_32way)
14431
14432 @@ -1046,6 +1053,7 @@ ENTRY(camellia_cbc_dec_32way)
14433
14434 vzeroupper;
14435
14436 + pax_force_retaddr
14437 ret;
14438 ENDPROC(camellia_cbc_dec_32way)
14439
14440 @@ -1184,6 +1192,7 @@ ENTRY(camellia_ctr_32way)
14441
14442 vzeroupper;
14443
14444 + pax_force_retaddr
14445 ret;
14446 ENDPROC(camellia_ctr_32way)
14447
14448 @@ -1349,6 +1358,7 @@ camellia_xts_crypt_32way:
14449
14450 vzeroupper;
14451
14452 + pax_force_retaddr
14453 ret;
14454 ENDPROC(camellia_xts_crypt_32way)
14455
14456 diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
14457 index 310319c..db3d7b5 100644
14458 --- a/arch/x86/crypto/camellia-x86_64-asm_64.S
14459 +++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
14460 @@ -21,6 +21,7 @@
14461 */
14462
14463 #include <linux/linkage.h>
14464 +#include <asm/alternative-asm.h>
14465
14466 .file "camellia-x86_64-asm_64.S"
14467 .text
14468 @@ -228,12 +229,14 @@ ENTRY(__camellia_enc_blk)
14469 enc_outunpack(mov, RT1);
14470
14471 movq RRBP, %rbp;
14472 + pax_force_retaddr
14473 ret;
14474
14475 .L__enc_xor:
14476 enc_outunpack(xor, RT1);
14477
14478 movq RRBP, %rbp;
14479 + pax_force_retaddr
14480 ret;
14481 ENDPROC(__camellia_enc_blk)
14482
14483 @@ -272,6 +275,7 @@ ENTRY(camellia_dec_blk)
14484 dec_outunpack();
14485
14486 movq RRBP, %rbp;
14487 + pax_force_retaddr
14488 ret;
14489 ENDPROC(camellia_dec_blk)
14490
14491 @@ -463,6 +467,7 @@ ENTRY(__camellia_enc_blk_2way)
14492
14493 movq RRBP, %rbp;
14494 popq %rbx;
14495 + pax_force_retaddr
14496 ret;
14497
14498 .L__enc2_xor:
14499 @@ -470,6 +475,7 @@ ENTRY(__camellia_enc_blk_2way)
14500
14501 movq RRBP, %rbp;
14502 popq %rbx;
14503 + pax_force_retaddr
14504 ret;
14505 ENDPROC(__camellia_enc_blk_2way)
14506
14507 @@ -510,5 +516,6 @@ ENTRY(camellia_dec_blk_2way)
14508
14509 movq RRBP, %rbp;
14510 movq RXOR, %rbx;
14511 + pax_force_retaddr
14512 ret;
14513 ENDPROC(camellia_dec_blk_2way)
14514 diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
14515 index c35fd5d..2d8c7db 100644
14516 --- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
14517 +++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
14518 @@ -24,6 +24,7 @@
14519 */
14520
14521 #include <linux/linkage.h>
14522 +#include <asm/alternative-asm.h>
14523
14524 .file "cast5-avx-x86_64-asm_64.S"
14525
14526 @@ -281,6 +282,7 @@ __cast5_enc_blk16:
14527 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
14528 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
14529
14530 + pax_force_retaddr
14531 ret;
14532 ENDPROC(__cast5_enc_blk16)
14533
14534 @@ -352,6 +354,7 @@ __cast5_dec_blk16:
14535 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
14536 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
14537
14538 + pax_force_retaddr
14539 ret;
14540
14541 .L__skip_dec:
14542 @@ -388,6 +391,7 @@ ENTRY(cast5_ecb_enc_16way)
14543 vmovdqu RR4, (6*4*4)(%r11);
14544 vmovdqu RL4, (7*4*4)(%r11);
14545
14546 + pax_force_retaddr
14547 ret;
14548 ENDPROC(cast5_ecb_enc_16way)
14549
14550 @@ -420,6 +424,7 @@ ENTRY(cast5_ecb_dec_16way)
14551 vmovdqu RR4, (6*4*4)(%r11);
14552 vmovdqu RL4, (7*4*4)(%r11);
14553
14554 + pax_force_retaddr
14555 ret;
14556 ENDPROC(cast5_ecb_dec_16way)
14557
14558 @@ -430,10 +435,10 @@ ENTRY(cast5_cbc_dec_16way)
14559 * %rdx: src
14560 */
14561
14562 - pushq %r12;
14563 + pushq %r14;
14564
14565 movq %rsi, %r11;
14566 - movq %rdx, %r12;
14567 + movq %rdx, %r14;
14568
14569 vmovdqu (0*16)(%rdx), RL1;
14570 vmovdqu (1*16)(%rdx), RR1;
14571 @@ -447,16 +452,16 @@ ENTRY(cast5_cbc_dec_16way)
14572 call __cast5_dec_blk16;
14573
14574 /* xor with src */
14575 - vmovq (%r12), RX;
14576 + vmovq (%r14), RX;
14577 vpshufd $0x4f, RX, RX;
14578 vpxor RX, RR1, RR1;
14579 - vpxor 0*16+8(%r12), RL1, RL1;
14580 - vpxor 1*16+8(%r12), RR2, RR2;
14581 - vpxor 2*16+8(%r12), RL2, RL2;
14582 - vpxor 3*16+8(%r12), RR3, RR3;
14583 - vpxor 4*16+8(%r12), RL3, RL3;
14584 - vpxor 5*16+8(%r12), RR4, RR4;
14585 - vpxor 6*16+8(%r12), RL4, RL4;
14586 + vpxor 0*16+8(%r14), RL1, RL1;
14587 + vpxor 1*16+8(%r14), RR2, RR2;
14588 + vpxor 2*16+8(%r14), RL2, RL2;
14589 + vpxor 3*16+8(%r14), RR3, RR3;
14590 + vpxor 4*16+8(%r14), RL3, RL3;
14591 + vpxor 5*16+8(%r14), RR4, RR4;
14592 + vpxor 6*16+8(%r14), RL4, RL4;
14593
14594 vmovdqu RR1, (0*16)(%r11);
14595 vmovdqu RL1, (1*16)(%r11);
14596 @@ -467,8 +472,9 @@ ENTRY(cast5_cbc_dec_16way)
14597 vmovdqu RR4, (6*16)(%r11);
14598 vmovdqu RL4, (7*16)(%r11);
14599
14600 - popq %r12;
14601 + popq %r14;
14602
14603 + pax_force_retaddr
14604 ret;
14605 ENDPROC(cast5_cbc_dec_16way)
14606
14607 @@ -480,10 +486,10 @@ ENTRY(cast5_ctr_16way)
14608 * %rcx: iv (big endian, 64bit)
14609 */
14610
14611 - pushq %r12;
14612 + pushq %r14;
14613
14614 movq %rsi, %r11;
14615 - movq %rdx, %r12;
14616 + movq %rdx, %r14;
14617
14618 vpcmpeqd RTMP, RTMP, RTMP;
14619 vpsrldq $8, RTMP, RTMP; /* low: -1, high: 0 */
14620 @@ -523,14 +529,14 @@ ENTRY(cast5_ctr_16way)
14621 call __cast5_enc_blk16;
14622
14623 /* dst = src ^ iv */
14624 - vpxor (0*16)(%r12), RR1, RR1;
14625 - vpxor (1*16)(%r12), RL1, RL1;
14626 - vpxor (2*16)(%r12), RR2, RR2;
14627 - vpxor (3*16)(%r12), RL2, RL2;
14628 - vpxor (4*16)(%r12), RR3, RR3;
14629 - vpxor (5*16)(%r12), RL3, RL3;
14630 - vpxor (6*16)(%r12), RR4, RR4;
14631 - vpxor (7*16)(%r12), RL4, RL4;
14632 + vpxor (0*16)(%r14), RR1, RR1;
14633 + vpxor (1*16)(%r14), RL1, RL1;
14634 + vpxor (2*16)(%r14), RR2, RR2;
14635 + vpxor (3*16)(%r14), RL2, RL2;
14636 + vpxor (4*16)(%r14), RR3, RR3;
14637 + vpxor (5*16)(%r14), RL3, RL3;
14638 + vpxor (6*16)(%r14), RR4, RR4;
14639 + vpxor (7*16)(%r14), RL4, RL4;
14640 vmovdqu RR1, (0*16)(%r11);
14641 vmovdqu RL1, (1*16)(%r11);
14642 vmovdqu RR2, (2*16)(%r11);
14643 @@ -540,7 +546,8 @@ ENTRY(cast5_ctr_16way)
14644 vmovdqu RR4, (6*16)(%r11);
14645 vmovdqu RL4, (7*16)(%r11);
14646
14647 - popq %r12;
14648 + popq %r14;
14649
14650 + pax_force_retaddr
14651 ret;
14652 ENDPROC(cast5_ctr_16way)
14653 diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
14654 index e3531f8..e123f35 100644
14655 --- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
14656 +++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
14657 @@ -24,6 +24,7 @@
14658 */
14659
14660 #include <linux/linkage.h>
14661 +#include <asm/alternative-asm.h>
14662 #include "glue_helper-asm-avx.S"
14663
14664 .file "cast6-avx-x86_64-asm_64.S"
14665 @@ -295,6 +296,7 @@ __cast6_enc_blk8:
14666 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
14667 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
14668
14669 + pax_force_retaddr
14670 ret;
14671 ENDPROC(__cast6_enc_blk8)
14672
14673 @@ -340,6 +342,7 @@ __cast6_dec_blk8:
14674 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
14675 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
14676
14677 + pax_force_retaddr
14678 ret;
14679 ENDPROC(__cast6_dec_blk8)
14680
14681 @@ -358,6 +361,7 @@ ENTRY(cast6_ecb_enc_8way)
14682
14683 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14684
14685 + pax_force_retaddr
14686 ret;
14687 ENDPROC(cast6_ecb_enc_8way)
14688
14689 @@ -376,6 +380,7 @@ ENTRY(cast6_ecb_dec_8way)
14690
14691 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14692
14693 + pax_force_retaddr
14694 ret;
14695 ENDPROC(cast6_ecb_dec_8way)
14696
14697 @@ -386,19 +391,20 @@ ENTRY(cast6_cbc_dec_8way)
14698 * %rdx: src
14699 */
14700
14701 - pushq %r12;
14702 + pushq %r14;
14703
14704 movq %rsi, %r11;
14705 - movq %rdx, %r12;
14706 + movq %rdx, %r14;
14707
14708 load_8way(%rdx, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14709
14710 call __cast6_dec_blk8;
14711
14712 - store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14713 + store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14714
14715 - popq %r12;
14716 + popq %r14;
14717
14718 + pax_force_retaddr
14719 ret;
14720 ENDPROC(cast6_cbc_dec_8way)
14721
14722 @@ -410,20 +416,21 @@ ENTRY(cast6_ctr_8way)
14723 * %rcx: iv (little endian, 128bit)
14724 */
14725
14726 - pushq %r12;
14727 + pushq %r14;
14728
14729 movq %rsi, %r11;
14730 - movq %rdx, %r12;
14731 + movq %rdx, %r14;
14732
14733 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
14734 RD2, RX, RKR, RKM);
14735
14736 call __cast6_enc_blk8;
14737
14738 - store_ctr_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14739 + store_ctr_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14740
14741 - popq %r12;
14742 + popq %r14;
14743
14744 + pax_force_retaddr
14745 ret;
14746 ENDPROC(cast6_ctr_8way)
14747
14748 @@ -446,6 +453,7 @@ ENTRY(cast6_xts_enc_8way)
14749 /* dst <= regs xor IVs(in dst) */
14750 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14751
14752 + pax_force_retaddr
14753 ret;
14754 ENDPROC(cast6_xts_enc_8way)
14755
14756 @@ -468,5 +476,6 @@ ENTRY(cast6_xts_dec_8way)
14757 /* dst <= regs xor IVs(in dst) */
14758 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14759
14760 + pax_force_retaddr
14761 ret;
14762 ENDPROC(cast6_xts_dec_8way)
14763 diff --git a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
14764 index 26d49eb..c0a8c84 100644
14765 --- a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
14766 +++ b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
14767 @@ -45,6 +45,7 @@
14768
14769 #include <asm/inst.h>
14770 #include <linux/linkage.h>
14771 +#include <asm/alternative-asm.h>
14772
14773 ## ISCSI CRC 32 Implementation with crc32 and pclmulqdq Instruction
14774
14775 @@ -309,6 +310,7 @@ do_return:
14776 popq %rsi
14777 popq %rdi
14778 popq %rbx
14779 + pax_force_retaddr
14780 ret
14781
14782 ################################################################
14783 diff --git a/arch/x86/crypto/ghash-clmulni-intel_asm.S b/arch/x86/crypto/ghash-clmulni-intel_asm.S
14784 index 5d1e007..098cb4f 100644
14785 --- a/arch/x86/crypto/ghash-clmulni-intel_asm.S
14786 +++ b/arch/x86/crypto/ghash-clmulni-intel_asm.S
14787 @@ -18,6 +18,7 @@
14788
14789 #include <linux/linkage.h>
14790 #include <asm/inst.h>
14791 +#include <asm/alternative-asm.h>
14792
14793 .data
14794
14795 @@ -89,6 +90,7 @@ __clmul_gf128mul_ble:
14796 psrlq $1, T2
14797 pxor T2, T1
14798 pxor T1, DATA
14799 + pax_force_retaddr
14800 ret
14801 ENDPROC(__clmul_gf128mul_ble)
14802
14803 @@ -101,6 +103,7 @@ ENTRY(clmul_ghash_mul)
14804 call __clmul_gf128mul_ble
14805 PSHUFB_XMM BSWAP DATA
14806 movups DATA, (%rdi)
14807 + pax_force_retaddr
14808 ret
14809 ENDPROC(clmul_ghash_mul)
14810
14811 @@ -128,5 +131,6 @@ ENTRY(clmul_ghash_update)
14812 PSHUFB_XMM BSWAP DATA
14813 movups DATA, (%rdi)
14814 .Lupdate_just_ret:
14815 + pax_force_retaddr
14816 ret
14817 ENDPROC(clmul_ghash_update)
14818 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
14819 index 9279e0b..c4b3d2c 100644
14820 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
14821 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
14822 @@ -1,4 +1,5 @@
14823 #include <linux/linkage.h>
14824 +#include <asm/alternative-asm.h>
14825
14826 # enter salsa20_encrypt_bytes
14827 ENTRY(salsa20_encrypt_bytes)
14828 @@ -789,6 +790,7 @@ ENTRY(salsa20_encrypt_bytes)
14829 add %r11,%rsp
14830 mov %rdi,%rax
14831 mov %rsi,%rdx
14832 + pax_force_retaddr
14833 ret
14834 # bytesatleast65:
14835 ._bytesatleast65:
14836 @@ -889,6 +891,7 @@ ENTRY(salsa20_keysetup)
14837 add %r11,%rsp
14838 mov %rdi,%rax
14839 mov %rsi,%rdx
14840 + pax_force_retaddr
14841 ret
14842 ENDPROC(salsa20_keysetup)
14843
14844 @@ -914,5 +917,6 @@ ENTRY(salsa20_ivsetup)
14845 add %r11,%rsp
14846 mov %rdi,%rax
14847 mov %rsi,%rdx
14848 + pax_force_retaddr
14849 ret
14850 ENDPROC(salsa20_ivsetup)
14851 diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14852 index 2f202f4..d9164d6 100644
14853 --- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14854 +++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14855 @@ -24,6 +24,7 @@
14856 */
14857
14858 #include <linux/linkage.h>
14859 +#include <asm/alternative-asm.h>
14860 #include "glue_helper-asm-avx.S"
14861
14862 .file "serpent-avx-x86_64-asm_64.S"
14863 @@ -618,6 +619,7 @@ __serpent_enc_blk8_avx:
14864 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14865 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14866
14867 + pax_force_retaddr
14868 ret;
14869 ENDPROC(__serpent_enc_blk8_avx)
14870
14871 @@ -672,6 +674,7 @@ __serpent_dec_blk8_avx:
14872 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14873 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14874
14875 + pax_force_retaddr
14876 ret;
14877 ENDPROC(__serpent_dec_blk8_avx)
14878
14879 @@ -688,6 +691,7 @@ ENTRY(serpent_ecb_enc_8way_avx)
14880
14881 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14882
14883 + pax_force_retaddr
14884 ret;
14885 ENDPROC(serpent_ecb_enc_8way_avx)
14886
14887 @@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_8way_avx)
14888
14889 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14890
14891 + pax_force_retaddr
14892 ret;
14893 ENDPROC(serpent_ecb_dec_8way_avx)
14894
14895 @@ -720,6 +725,7 @@ ENTRY(serpent_cbc_dec_8way_avx)
14896
14897 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14898
14899 + pax_force_retaddr
14900 ret;
14901 ENDPROC(serpent_cbc_dec_8way_avx)
14902
14903 @@ -738,6 +744,7 @@ ENTRY(serpent_ctr_8way_avx)
14904
14905 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14906
14907 + pax_force_retaddr
14908 ret;
14909 ENDPROC(serpent_ctr_8way_avx)
14910
14911 @@ -758,6 +765,7 @@ ENTRY(serpent_xts_enc_8way_avx)
14912 /* dst <= regs xor IVs(in dst) */
14913 store_xts_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14914
14915 + pax_force_retaddr
14916 ret;
14917 ENDPROC(serpent_xts_enc_8way_avx)
14918
14919 @@ -778,5 +786,6 @@ ENTRY(serpent_xts_dec_8way_avx)
14920 /* dst <= regs xor IVs(in dst) */
14921 store_xts_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14922
14923 + pax_force_retaddr
14924 ret;
14925 ENDPROC(serpent_xts_dec_8way_avx)
14926 diff --git a/arch/x86/crypto/serpent-avx2-asm_64.S b/arch/x86/crypto/serpent-avx2-asm_64.S
14927 index b222085..abd483c 100644
14928 --- a/arch/x86/crypto/serpent-avx2-asm_64.S
14929 +++ b/arch/x86/crypto/serpent-avx2-asm_64.S
14930 @@ -15,6 +15,7 @@
14931 */
14932
14933 #include <linux/linkage.h>
14934 +#include <asm/alternative-asm.h>
14935 #include "glue_helper-asm-avx2.S"
14936
14937 .file "serpent-avx2-asm_64.S"
14938 @@ -610,6 +611,7 @@ __serpent_enc_blk16:
14939 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14940 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14941
14942 + pax_force_retaddr
14943 ret;
14944 ENDPROC(__serpent_enc_blk16)
14945
14946 @@ -664,6 +666,7 @@ __serpent_dec_blk16:
14947 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14948 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14949
14950 + pax_force_retaddr
14951 ret;
14952 ENDPROC(__serpent_dec_blk16)
14953
14954 @@ -684,6 +687,7 @@ ENTRY(serpent_ecb_enc_16way)
14955
14956 vzeroupper;
14957
14958 + pax_force_retaddr
14959 ret;
14960 ENDPROC(serpent_ecb_enc_16way)
14961
14962 @@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_16way)
14963
14964 vzeroupper;
14965
14966 + pax_force_retaddr
14967 ret;
14968 ENDPROC(serpent_ecb_dec_16way)
14969
14970 @@ -725,6 +730,7 @@ ENTRY(serpent_cbc_dec_16way)
14971
14972 vzeroupper;
14973
14974 + pax_force_retaddr
14975 ret;
14976 ENDPROC(serpent_cbc_dec_16way)
14977
14978 @@ -748,6 +754,7 @@ ENTRY(serpent_ctr_16way)
14979
14980 vzeroupper;
14981
14982 + pax_force_retaddr
14983 ret;
14984 ENDPROC(serpent_ctr_16way)
14985
14986 @@ -772,6 +779,7 @@ ENTRY(serpent_xts_enc_16way)
14987
14988 vzeroupper;
14989
14990 + pax_force_retaddr
14991 ret;
14992 ENDPROC(serpent_xts_enc_16way)
14993
14994 @@ -796,5 +804,6 @@ ENTRY(serpent_xts_dec_16way)
14995
14996 vzeroupper;
14997
14998 + pax_force_retaddr
14999 ret;
15000 ENDPROC(serpent_xts_dec_16way)
15001 diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
15002 index acc066c..1559cc4 100644
15003 --- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
15004 +++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
15005 @@ -25,6 +25,7 @@
15006 */
15007
15008 #include <linux/linkage.h>
15009 +#include <asm/alternative-asm.h>
15010
15011 .file "serpent-sse2-x86_64-asm_64.S"
15012 .text
15013 @@ -690,12 +691,14 @@ ENTRY(__serpent_enc_blk_8way)
15014 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
15015 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
15016
15017 + pax_force_retaddr
15018 ret;
15019
15020 .L__enc_xor8:
15021 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
15022 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
15023
15024 + pax_force_retaddr
15025 ret;
15026 ENDPROC(__serpent_enc_blk_8way)
15027
15028 @@ -750,5 +753,6 @@ ENTRY(serpent_dec_blk_8way)
15029 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
15030 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
15031
15032 + pax_force_retaddr
15033 ret;
15034 ENDPROC(serpent_dec_blk_8way)
15035 diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
15036 index a410950..9dfe7ad 100644
15037 --- a/arch/x86/crypto/sha1_ssse3_asm.S
15038 +++ b/arch/x86/crypto/sha1_ssse3_asm.S
15039 @@ -29,6 +29,7 @@
15040 */
15041
15042 #include <linux/linkage.h>
15043 +#include <asm/alternative-asm.h>
15044
15045 #define CTX %rdi // arg1
15046 #define BUF %rsi // arg2
15047 @@ -75,9 +76,9 @@
15048
15049 push %rbx
15050 push %rbp
15051 - push %r12
15052 + push %r14
15053
15054 - mov %rsp, %r12
15055 + mov %rsp, %r14
15056 sub $64, %rsp # allocate workspace
15057 and $~15, %rsp # align stack
15058
15059 @@ -99,11 +100,12 @@
15060 xor %rax, %rax
15061 rep stosq
15062
15063 - mov %r12, %rsp # deallocate workspace
15064 + mov %r14, %rsp # deallocate workspace
15065
15066 - pop %r12
15067 + pop %r14
15068 pop %rbp
15069 pop %rbx
15070 + pax_force_retaddr
15071 ret
15072
15073 ENDPROC(\name)
15074 diff --git a/arch/x86/crypto/sha256-avx-asm.S b/arch/x86/crypto/sha256-avx-asm.S
15075 index 642f156..51a513c 100644
15076 --- a/arch/x86/crypto/sha256-avx-asm.S
15077 +++ b/arch/x86/crypto/sha256-avx-asm.S
15078 @@ -49,6 +49,7 @@
15079
15080 #ifdef CONFIG_AS_AVX
15081 #include <linux/linkage.h>
15082 +#include <asm/alternative-asm.h>
15083
15084 ## assume buffers not aligned
15085 #define VMOVDQ vmovdqu
15086 @@ -460,6 +461,7 @@ done_hash:
15087 popq %r13
15088 popq %rbp
15089 popq %rbx
15090 + pax_force_retaddr
15091 ret
15092 ENDPROC(sha256_transform_avx)
15093
15094 diff --git a/arch/x86/crypto/sha256-avx2-asm.S b/arch/x86/crypto/sha256-avx2-asm.S
15095 index 9e86944..3795e6a 100644
15096 --- a/arch/x86/crypto/sha256-avx2-asm.S
15097 +++ b/arch/x86/crypto/sha256-avx2-asm.S
15098 @@ -50,6 +50,7 @@
15099
15100 #ifdef CONFIG_AS_AVX2
15101 #include <linux/linkage.h>
15102 +#include <asm/alternative-asm.h>
15103
15104 ## assume buffers not aligned
15105 #define VMOVDQ vmovdqu
15106 @@ -720,6 +721,7 @@ done_hash:
15107 popq %r12
15108 popq %rbp
15109 popq %rbx
15110 + pax_force_retaddr
15111 ret
15112 ENDPROC(sha256_transform_rorx)
15113
15114 diff --git a/arch/x86/crypto/sha256-ssse3-asm.S b/arch/x86/crypto/sha256-ssse3-asm.S
15115 index f833b74..8c62a9e 100644
15116 --- a/arch/x86/crypto/sha256-ssse3-asm.S
15117 +++ b/arch/x86/crypto/sha256-ssse3-asm.S
15118 @@ -47,6 +47,7 @@
15119 ########################################################################
15120
15121 #include <linux/linkage.h>
15122 +#include <asm/alternative-asm.h>
15123
15124 ## assume buffers not aligned
15125 #define MOVDQ movdqu
15126 @@ -471,6 +472,7 @@ done_hash:
15127 popq %rbp
15128 popq %rbx
15129
15130 + pax_force_retaddr
15131 ret
15132 ENDPROC(sha256_transform_ssse3)
15133
15134 diff --git a/arch/x86/crypto/sha512-avx-asm.S b/arch/x86/crypto/sha512-avx-asm.S
15135 index 974dde9..a823ff9 100644
15136 --- a/arch/x86/crypto/sha512-avx-asm.S
15137 +++ b/arch/x86/crypto/sha512-avx-asm.S
15138 @@ -49,6 +49,7 @@
15139
15140 #ifdef CONFIG_AS_AVX
15141 #include <linux/linkage.h>
15142 +#include <asm/alternative-asm.h>
15143
15144 .text
15145
15146 @@ -364,6 +365,7 @@ updateblock:
15147 mov frame_RSPSAVE(%rsp), %rsp
15148
15149 nowork:
15150 + pax_force_retaddr
15151 ret
15152 ENDPROC(sha512_transform_avx)
15153
15154 diff --git a/arch/x86/crypto/sha512-avx2-asm.S b/arch/x86/crypto/sha512-avx2-asm.S
15155 index 568b961..ed20c37 100644
15156 --- a/arch/x86/crypto/sha512-avx2-asm.S
15157 +++ b/arch/x86/crypto/sha512-avx2-asm.S
15158 @@ -51,6 +51,7 @@
15159
15160 #ifdef CONFIG_AS_AVX2
15161 #include <linux/linkage.h>
15162 +#include <asm/alternative-asm.h>
15163
15164 .text
15165
15166 @@ -678,6 +679,7 @@ done_hash:
15167
15168 # Restore Stack Pointer
15169 mov frame_RSPSAVE(%rsp), %rsp
15170 + pax_force_retaddr
15171 ret
15172 ENDPROC(sha512_transform_rorx)
15173
15174 diff --git a/arch/x86/crypto/sha512-ssse3-asm.S b/arch/x86/crypto/sha512-ssse3-asm.S
15175 index fb56855..6edd768 100644
15176 --- a/arch/x86/crypto/sha512-ssse3-asm.S
15177 +++ b/arch/x86/crypto/sha512-ssse3-asm.S
15178 @@ -48,6 +48,7 @@
15179 ########################################################################
15180
15181 #include <linux/linkage.h>
15182 +#include <asm/alternative-asm.h>
15183
15184 .text
15185
15186 @@ -363,6 +364,7 @@ updateblock:
15187 mov frame_RSPSAVE(%rsp), %rsp
15188
15189 nowork:
15190 + pax_force_retaddr
15191 ret
15192 ENDPROC(sha512_transform_ssse3)
15193
15194 diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
15195 index 0505813..b067311 100644
15196 --- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
15197 +++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
15198 @@ -24,6 +24,7 @@
15199 */
15200
15201 #include <linux/linkage.h>
15202 +#include <asm/alternative-asm.h>
15203 #include "glue_helper-asm-avx.S"
15204
15205 .file "twofish-avx-x86_64-asm_64.S"
15206 @@ -284,6 +285,7 @@ __twofish_enc_blk8:
15207 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
15208 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
15209
15210 + pax_force_retaddr
15211 ret;
15212 ENDPROC(__twofish_enc_blk8)
15213
15214 @@ -324,6 +326,7 @@ __twofish_dec_blk8:
15215 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
15216 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
15217
15218 + pax_force_retaddr
15219 ret;
15220 ENDPROC(__twofish_dec_blk8)
15221
15222 @@ -342,6 +345,7 @@ ENTRY(twofish_ecb_enc_8way)
15223
15224 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
15225
15226 + pax_force_retaddr
15227 ret;
15228 ENDPROC(twofish_ecb_enc_8way)
15229
15230 @@ -360,6 +364,7 @@ ENTRY(twofish_ecb_dec_8way)
15231
15232 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
15233
15234 + pax_force_retaddr
15235 ret;
15236 ENDPROC(twofish_ecb_dec_8way)
15237
15238 @@ -370,19 +375,20 @@ ENTRY(twofish_cbc_dec_8way)
15239 * %rdx: src
15240 */
15241
15242 - pushq %r12;
15243 + pushq %r14;
15244
15245 movq %rsi, %r11;
15246 - movq %rdx, %r12;
15247 + movq %rdx, %r14;
15248
15249 load_8way(%rdx, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
15250
15251 call __twofish_dec_blk8;
15252
15253 - store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
15254 + store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
15255
15256 - popq %r12;
15257 + popq %r14;
15258
15259 + pax_force_retaddr
15260 ret;
15261 ENDPROC(twofish_cbc_dec_8way)
15262
15263 @@ -394,20 +400,21 @@ ENTRY(twofish_ctr_8way)
15264 * %rcx: iv (little endian, 128bit)
15265 */
15266
15267 - pushq %r12;
15268 + pushq %r14;
15269
15270 movq %rsi, %r11;
15271 - movq %rdx, %r12;
15272 + movq %rdx, %r14;
15273
15274 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
15275 RD2, RX0, RX1, RY0);
15276
15277 call __twofish_enc_blk8;
15278
15279 - store_ctr_8way(%r12, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
15280 + store_ctr_8way(%r14, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
15281
15282 - popq %r12;
15283 + popq %r14;
15284
15285 + pax_force_retaddr
15286 ret;
15287 ENDPROC(twofish_ctr_8way)
15288
15289 @@ -430,6 +437,7 @@ ENTRY(twofish_xts_enc_8way)
15290 /* dst <= regs xor IVs(in dst) */
15291 store_xts_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
15292
15293 + pax_force_retaddr
15294 ret;
15295 ENDPROC(twofish_xts_enc_8way)
15296
15297 @@ -452,5 +460,6 @@ ENTRY(twofish_xts_dec_8way)
15298 /* dst <= regs xor IVs(in dst) */
15299 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
15300
15301 + pax_force_retaddr
15302 ret;
15303 ENDPROC(twofish_xts_dec_8way)
15304 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
15305 index 1c3b7ce..02f578d 100644
15306 --- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
15307 +++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
15308 @@ -21,6 +21,7 @@
15309 */
15310
15311 #include <linux/linkage.h>
15312 +#include <asm/alternative-asm.h>
15313
15314 .file "twofish-x86_64-asm-3way.S"
15315 .text
15316 @@ -258,6 +259,7 @@ ENTRY(__twofish_enc_blk_3way)
15317 popq %r13;
15318 popq %r14;
15319 popq %r15;
15320 + pax_force_retaddr
15321 ret;
15322
15323 .L__enc_xor3:
15324 @@ -269,6 +271,7 @@ ENTRY(__twofish_enc_blk_3way)
15325 popq %r13;
15326 popq %r14;
15327 popq %r15;
15328 + pax_force_retaddr
15329 ret;
15330 ENDPROC(__twofish_enc_blk_3way)
15331
15332 @@ -308,5 +311,6 @@ ENTRY(twofish_dec_blk_3way)
15333 popq %r13;
15334 popq %r14;
15335 popq %r15;
15336 + pax_force_retaddr
15337 ret;
15338 ENDPROC(twofish_dec_blk_3way)
15339 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
15340 index a039d21..524b8b2 100644
15341 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
15342 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
15343 @@ -22,6 +22,7 @@
15344
15345 #include <linux/linkage.h>
15346 #include <asm/asm-offsets.h>
15347 +#include <asm/alternative-asm.h>
15348
15349 #define a_offset 0
15350 #define b_offset 4
15351 @@ -265,6 +266,7 @@ ENTRY(twofish_enc_blk)
15352
15353 popq R1
15354 movq $1,%rax
15355 + pax_force_retaddr
15356 ret
15357 ENDPROC(twofish_enc_blk)
15358
15359 @@ -317,5 +319,6 @@ ENTRY(twofish_dec_blk)
15360
15361 popq R1
15362 movq $1,%rax
15363 + pax_force_retaddr
15364 ret
15365 ENDPROC(twofish_dec_blk)
15366 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
15367 index d21ff89..6da8e6e 100644
15368 --- a/arch/x86/ia32/ia32_aout.c
15369 +++ b/arch/x86/ia32/ia32_aout.c
15370 @@ -153,6 +153,8 @@ static int aout_core_dump(struct coredump_params *cprm)
15371 unsigned long dump_start, dump_size;
15372 struct user32 dump;
15373
15374 + memset(&dump, 0, sizeof(dump));
15375 +
15376 fs = get_fs();
15377 set_fs(KERNEL_DS);
15378 has_dumped = 1;
15379 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
15380 index f9e181a..300544c 100644
15381 --- a/arch/x86/ia32/ia32_signal.c
15382 +++ b/arch/x86/ia32/ia32_signal.c
15383 @@ -218,7 +218,7 @@ asmlinkage long sys32_sigreturn(void)
15384 if (__get_user(set.sig[0], &frame->sc.oldmask)
15385 || (_COMPAT_NSIG_WORDS > 1
15386 && __copy_from_user((((char *) &set.sig) + 4),
15387 - &frame->extramask,
15388 + frame->extramask,
15389 sizeof(frame->extramask))))
15390 goto badframe;
15391
15392 @@ -338,7 +338,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
15393 sp -= frame_size;
15394 /* Align the stack pointer according to the i386 ABI,
15395 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
15396 - sp = ((sp + 4) & -16ul) - 4;
15397 + sp = ((sp - 12) & -16ul) - 4;
15398 return (void __user *) sp;
15399 }
15400
15401 @@ -383,10 +383,10 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
15402 } else {
15403 /* Return stub is in 32bit vsyscall page */
15404 if (current->mm->context.vdso)
15405 - restorer = current->mm->context.vdso +
15406 - selected_vdso32->sym___kernel_sigreturn;
15407 + restorer = (void __force_user *)(current->mm->context.vdso +
15408 + selected_vdso32->sym___kernel_sigreturn);
15409 else
15410 - restorer = &frame->retcode;
15411 + restorer = frame->retcode;
15412 }
15413
15414 put_user_try {
15415 @@ -396,7 +396,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
15416 * These are actually not used anymore, but left because some
15417 * gdb versions depend on them as a marker.
15418 */
15419 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
15420 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
15421 } put_user_catch(err);
15422
15423 if (err)
15424 @@ -438,7 +438,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
15425 0xb8,
15426 __NR_ia32_rt_sigreturn,
15427 0x80cd,
15428 - 0,
15429 + 0
15430 };
15431
15432 frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
15433 @@ -461,16 +461,19 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
15434
15435 if (ksig->ka.sa.sa_flags & SA_RESTORER)
15436 restorer = ksig->ka.sa.sa_restorer;
15437 + else if (current->mm->context.vdso)
15438 + /* Return stub is in 32bit vsyscall page */
15439 + restorer = (void __force_user *)(current->mm->context.vdso +
15440 + selected_vdso32->sym___kernel_rt_sigreturn);
15441 else
15442 - restorer = current->mm->context.vdso +
15443 - selected_vdso32->sym___kernel_rt_sigreturn;
15444 + restorer = frame->retcode;
15445 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
15446
15447 /*
15448 * Not actually used anymore, but left because some gdb
15449 * versions need it.
15450 */
15451 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
15452 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
15453 } put_user_catch(err);
15454
15455 err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
15456 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
15457 index 92a2e93..cd4d95f 100644
15458 --- a/arch/x86/ia32/ia32entry.S
15459 +++ b/arch/x86/ia32/ia32entry.S
15460 @@ -15,8 +15,10 @@
15461 #include <asm/irqflags.h>
15462 #include <asm/asm.h>
15463 #include <asm/smap.h>
15464 +#include <asm/pgtable.h>
15465 #include <linux/linkage.h>
15466 #include <linux/err.h>
15467 +#include <asm/alternative-asm.h>
15468
15469 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
15470 #include <linux/elf-em.h>
15471 @@ -62,12 +64,12 @@
15472 */
15473 .macro LOAD_ARGS32 offset, _r9=0
15474 .if \_r9
15475 - movl \offset+16(%rsp),%r9d
15476 + movl \offset+R9(%rsp),%r9d
15477 .endif
15478 - movl \offset+40(%rsp),%ecx
15479 - movl \offset+48(%rsp),%edx
15480 - movl \offset+56(%rsp),%esi
15481 - movl \offset+64(%rsp),%edi
15482 + movl \offset+RCX(%rsp),%ecx
15483 + movl \offset+RDX(%rsp),%edx
15484 + movl \offset+RSI(%rsp),%esi
15485 + movl \offset+RDI(%rsp),%edi
15486 movl %eax,%eax /* zero extension */
15487 .endm
15488
15489 @@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
15490 ENDPROC(native_irq_enable_sysexit)
15491 #endif
15492
15493 + .macro pax_enter_kernel_user
15494 + pax_set_fptr_mask
15495 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15496 + call pax_enter_kernel_user
15497 +#endif
15498 + .endm
15499 +
15500 + .macro pax_exit_kernel_user
15501 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15502 + call pax_exit_kernel_user
15503 +#endif
15504 +#ifdef CONFIG_PAX_RANDKSTACK
15505 + pushq %rax
15506 + pushq %r11
15507 + call pax_randomize_kstack
15508 + popq %r11
15509 + popq %rax
15510 +#endif
15511 + .endm
15512 +
15513 + .macro pax_erase_kstack
15514 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15515 + call pax_erase_kstack
15516 +#endif
15517 + .endm
15518 +
15519 /*
15520 * 32bit SYSENTER instruction entry.
15521 *
15522 @@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
15523 CFI_REGISTER rsp,rbp
15524 SWAPGS_UNSAFE_STACK
15525 movq PER_CPU_VAR(kernel_stack), %rsp
15526 - addq $(KERNEL_STACK_OFFSET),%rsp
15527 - /*
15528 - * No need to follow this irqs on/off section: the syscall
15529 - * disabled irqs, here we enable it straight after entry:
15530 - */
15531 - ENABLE_INTERRUPTS(CLBR_NONE)
15532 movl %ebp,%ebp /* zero extension */
15533 pushq_cfi $__USER32_DS
15534 /*CFI_REL_OFFSET ss,0*/
15535 @@ -135,23 +157,46 @@ ENTRY(ia32_sysenter_target)
15536 CFI_REL_OFFSET rsp,0
15537 pushfq_cfi
15538 /*CFI_REL_OFFSET rflags,0*/
15539 - movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
15540 - CFI_REGISTER rip,r10
15541 + orl $X86_EFLAGS_IF,(%rsp)
15542 + GET_THREAD_INFO(%r11)
15543 + movl TI_sysenter_return(%r11), %r11d
15544 + CFI_REGISTER rip,r11
15545 pushq_cfi $__USER32_CS
15546 /*CFI_REL_OFFSET cs,0*/
15547 movl %eax, %eax
15548 - pushq_cfi %r10
15549 + pushq_cfi %r11
15550 CFI_REL_OFFSET rip,0
15551 pushq_cfi %rax
15552 cld
15553 SAVE_ARGS 0,1,0
15554 + pax_enter_kernel_user
15555 +
15556 +#ifdef CONFIG_PAX_RANDKSTACK
15557 + pax_erase_kstack
15558 +#endif
15559 +
15560 + /*
15561 + * No need to follow this irqs on/off section: the syscall
15562 + * disabled irqs, here we enable it straight after entry:
15563 + */
15564 + ENABLE_INTERRUPTS(CLBR_NONE)
15565 /* no need to do an access_ok check here because rbp has been
15566 32bit zero extended */
15567 +
15568 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15569 + addq pax_user_shadow_base,%rbp
15570 + ASM_PAX_OPEN_USERLAND
15571 +#endif
15572 +
15573 ASM_STAC
15574 1: movl (%rbp),%ebp
15575 _ASM_EXTABLE(1b,ia32_badarg)
15576 ASM_CLAC
15577
15578 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15579 + ASM_PAX_CLOSE_USERLAND
15580 +#endif
15581 +
15582 /*
15583 * Sysenter doesn't filter flags, so we need to clear NT
15584 * ourselves. To save a few cycles, we can check whether
15585 @@ -161,8 +206,9 @@ ENTRY(ia32_sysenter_target)
15586 jnz sysenter_fix_flags
15587 sysenter_flags_fixed:
15588
15589 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15590 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15591 + GET_THREAD_INFO(%r11)
15592 + orl $TS_COMPAT,TI_status(%r11)
15593 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
15594 CFI_REMEMBER_STATE
15595 jnz sysenter_tracesys
15596 cmpq $(IA32_NR_syscalls-1),%rax
15597 @@ -172,15 +218,18 @@ sysenter_do_call:
15598 sysenter_dispatch:
15599 call *ia32_sys_call_table(,%rax,8)
15600 movq %rax,RAX-ARGOFFSET(%rsp)
15601 + GET_THREAD_INFO(%r11)
15602 DISABLE_INTERRUPTS(CLBR_NONE)
15603 TRACE_IRQS_OFF
15604 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15605 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
15606 jnz sysexit_audit
15607 sysexit_from_sys_call:
15608 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15609 + pax_exit_kernel_user
15610 + pax_erase_kstack
15611 + andl $~TS_COMPAT,TI_status(%r11)
15612 /* clear IF, that popfq doesn't enable interrupts early */
15613 - andl $~0x200,EFLAGS-R11(%rsp)
15614 - movl RIP-R11(%rsp),%edx /* User %eip */
15615 + andl $~X86_EFLAGS_IF,EFLAGS(%rsp)
15616 + movl RIP(%rsp),%edx /* User %eip */
15617 CFI_REGISTER rip,rdx
15618 RESTORE_ARGS 0,24,0,0,0,0
15619 xorq %r8,%r8
15620 @@ -205,6 +254,9 @@ sysexit_from_sys_call:
15621 movl %eax,%esi /* 2nd arg: syscall number */
15622 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
15623 call __audit_syscall_entry
15624 +
15625 + pax_erase_kstack
15626 +
15627 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
15628 cmpq $(IA32_NR_syscalls-1),%rax
15629 ja ia32_badsys
15630 @@ -216,7 +268,7 @@ sysexit_from_sys_call:
15631 .endm
15632
15633 .macro auditsys_exit exit
15634 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15635 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
15636 jnz ia32_ret_from_sys_call
15637 TRACE_IRQS_ON
15638 ENABLE_INTERRUPTS(CLBR_NONE)
15639 @@ -227,11 +279,12 @@ sysexit_from_sys_call:
15640 1: setbe %al /* 1 if error, 0 if not */
15641 movzbl %al,%edi /* zero-extend that into %edi */
15642 call __audit_syscall_exit
15643 + GET_THREAD_INFO(%r11)
15644 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
15645 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
15646 DISABLE_INTERRUPTS(CLBR_NONE)
15647 TRACE_IRQS_OFF
15648 - testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15649 + testl %edi,TI_flags(%r11)
15650 jz \exit
15651 CLEAR_RREGS -ARGOFFSET
15652 jmp int_with_check
15653 @@ -253,7 +306,7 @@ sysenter_fix_flags:
15654
15655 sysenter_tracesys:
15656 #ifdef CONFIG_AUDITSYSCALL
15657 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15658 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
15659 jz sysenter_auditsys
15660 #endif
15661 SAVE_REST
15662 @@ -265,6 +318,9 @@ sysenter_tracesys:
15663 RESTORE_REST
15664 cmpq $(IA32_NR_syscalls-1),%rax
15665 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
15666 +
15667 + pax_erase_kstack
15668 +
15669 jmp sysenter_do_call
15670 CFI_ENDPROC
15671 ENDPROC(ia32_sysenter_target)
15672 @@ -292,19 +348,25 @@ ENDPROC(ia32_sysenter_target)
15673 ENTRY(ia32_cstar_target)
15674 CFI_STARTPROC32 simple
15675 CFI_SIGNAL_FRAME
15676 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
15677 + CFI_DEF_CFA rsp,0
15678 CFI_REGISTER rip,rcx
15679 /*CFI_REGISTER rflags,r11*/
15680 SWAPGS_UNSAFE_STACK
15681 movl %esp,%r8d
15682 CFI_REGISTER rsp,r8
15683 movq PER_CPU_VAR(kernel_stack),%rsp
15684 + SAVE_ARGS 8*6,0,0
15685 + pax_enter_kernel_user
15686 +
15687 +#ifdef CONFIG_PAX_RANDKSTACK
15688 + pax_erase_kstack
15689 +#endif
15690 +
15691 /*
15692 * No need to follow this irqs on/off section: the syscall
15693 * disabled irqs and here we enable it straight after entry:
15694 */
15695 ENABLE_INTERRUPTS(CLBR_NONE)
15696 - SAVE_ARGS 8,0,0
15697 movl %eax,%eax /* zero extension */
15698 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
15699 movq %rcx,RIP-ARGOFFSET(%rsp)
15700 @@ -320,12 +382,25 @@ ENTRY(ia32_cstar_target)
15701 /* no need to do an access_ok check here because r8 has been
15702 32bit zero extended */
15703 /* hardware stack frame is complete now */
15704 +
15705 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15706 + ASM_PAX_OPEN_USERLAND
15707 + movq pax_user_shadow_base,%r8
15708 + addq RSP-ARGOFFSET(%rsp),%r8
15709 +#endif
15710 +
15711 ASM_STAC
15712 1: movl (%r8),%r9d
15713 _ASM_EXTABLE(1b,ia32_badarg)
15714 ASM_CLAC
15715 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15716 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15717 +
15718 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15719 + ASM_PAX_CLOSE_USERLAND
15720 +#endif
15721 +
15722 + GET_THREAD_INFO(%r11)
15723 + orl $TS_COMPAT,TI_status(%r11)
15724 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
15725 CFI_REMEMBER_STATE
15726 jnz cstar_tracesys
15727 cmpq $IA32_NR_syscalls-1,%rax
15728 @@ -335,13 +410,16 @@ cstar_do_call:
15729 cstar_dispatch:
15730 call *ia32_sys_call_table(,%rax,8)
15731 movq %rax,RAX-ARGOFFSET(%rsp)
15732 + GET_THREAD_INFO(%r11)
15733 DISABLE_INTERRUPTS(CLBR_NONE)
15734 TRACE_IRQS_OFF
15735 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15736 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
15737 jnz sysretl_audit
15738 sysretl_from_sys_call:
15739 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15740 - RESTORE_ARGS 0,-ARG_SKIP,0,0,0
15741 + pax_exit_kernel_user
15742 + pax_erase_kstack
15743 + andl $~TS_COMPAT,TI_status(%r11)
15744 + RESTORE_ARGS 0,-ORIG_RAX,0,0,0
15745 movl RIP-ARGOFFSET(%rsp),%ecx
15746 CFI_REGISTER rip,rcx
15747 movl EFLAGS-ARGOFFSET(%rsp),%r11d
15748 @@ -368,7 +446,7 @@ sysretl_audit:
15749
15750 cstar_tracesys:
15751 #ifdef CONFIG_AUDITSYSCALL
15752 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15753 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
15754 jz cstar_auditsys
15755 #endif
15756 xchgl %r9d,%ebp
15757 @@ -382,11 +460,19 @@ cstar_tracesys:
15758 xchgl %ebp,%r9d
15759 cmpq $(IA32_NR_syscalls-1),%rax
15760 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
15761 +
15762 + pax_erase_kstack
15763 +
15764 jmp cstar_do_call
15765 END(ia32_cstar_target)
15766
15767 ia32_badarg:
15768 ASM_CLAC
15769 +
15770 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15771 + ASM_PAX_CLOSE_USERLAND
15772 +#endif
15773 +
15774 movq $-EFAULT,%rax
15775 jmp ia32_sysret
15776 CFI_ENDPROC
15777 @@ -423,19 +509,26 @@ ENTRY(ia32_syscall)
15778 CFI_REL_OFFSET rip,RIP-RIP
15779 PARAVIRT_ADJUST_EXCEPTION_FRAME
15780 SWAPGS
15781 - /*
15782 - * No need to follow this irqs on/off section: the syscall
15783 - * disabled irqs and here we enable it straight after entry:
15784 - */
15785 - ENABLE_INTERRUPTS(CLBR_NONE)
15786 movl %eax,%eax
15787 pushq_cfi %rax
15788 cld
15789 /* note the registers are not zero extended to the sf.
15790 this could be a problem. */
15791 SAVE_ARGS 0,1,0
15792 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15793 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15794 + pax_enter_kernel_user
15795 +
15796 +#ifdef CONFIG_PAX_RANDKSTACK
15797 + pax_erase_kstack
15798 +#endif
15799 +
15800 + /*
15801 + * No need to follow this irqs on/off section: the syscall
15802 + * disabled irqs and here we enable it straight after entry:
15803 + */
15804 + ENABLE_INTERRUPTS(CLBR_NONE)
15805 + GET_THREAD_INFO(%r11)
15806 + orl $TS_COMPAT,TI_status(%r11)
15807 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
15808 jnz ia32_tracesys
15809 cmpq $(IA32_NR_syscalls-1),%rax
15810 ja ia32_badsys
15811 @@ -458,6 +551,9 @@ ia32_tracesys:
15812 RESTORE_REST
15813 cmpq $(IA32_NR_syscalls-1),%rax
15814 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
15815 +
15816 + pax_erase_kstack
15817 +
15818 jmp ia32_do_call
15819 END(ia32_syscall)
15820
15821 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
15822 index 8e0ceec..af13504 100644
15823 --- a/arch/x86/ia32/sys_ia32.c
15824 +++ b/arch/x86/ia32/sys_ia32.c
15825 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
15826 */
15827 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
15828 {
15829 - typeof(ubuf->st_uid) uid = 0;
15830 - typeof(ubuf->st_gid) gid = 0;
15831 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
15832 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
15833 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
15834 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
15835 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
15836 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
15837 index 372231c..51b537d 100644
15838 --- a/arch/x86/include/asm/alternative-asm.h
15839 +++ b/arch/x86/include/asm/alternative-asm.h
15840 @@ -18,6 +18,45 @@
15841 .endm
15842 #endif
15843
15844 +#ifdef KERNEXEC_PLUGIN
15845 + .macro pax_force_retaddr_bts rip=0
15846 + btsq $63,\rip(%rsp)
15847 + .endm
15848 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
15849 + .macro pax_force_retaddr rip=0, reload=0
15850 + btsq $63,\rip(%rsp)
15851 + .endm
15852 + .macro pax_force_fptr ptr
15853 + btsq $63,\ptr
15854 + .endm
15855 + .macro pax_set_fptr_mask
15856 + .endm
15857 +#endif
15858 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15859 + .macro pax_force_retaddr rip=0, reload=0
15860 + .if \reload
15861 + pax_set_fptr_mask
15862 + .endif
15863 + orq %r12,\rip(%rsp)
15864 + .endm
15865 + .macro pax_force_fptr ptr
15866 + orq %r12,\ptr
15867 + .endm
15868 + .macro pax_set_fptr_mask
15869 + movabs $0x8000000000000000,%r12
15870 + .endm
15871 +#endif
15872 +#else
15873 + .macro pax_force_retaddr rip=0, reload=0
15874 + .endm
15875 + .macro pax_force_fptr ptr
15876 + .endm
15877 + .macro pax_force_retaddr_bts rip=0
15878 + .endm
15879 + .macro pax_set_fptr_mask
15880 + .endm
15881 +#endif
15882 +
15883 .macro altinstruction_entry orig alt feature orig_len alt_len
15884 .long \orig - .
15885 .long \alt - .
15886 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
15887 index 473bdbe..b1e3377 100644
15888 --- a/arch/x86/include/asm/alternative.h
15889 +++ b/arch/x86/include/asm/alternative.h
15890 @@ -106,7 +106,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
15891 ".pushsection .discard,\"aw\",@progbits\n" \
15892 DISCARD_ENTRY(1) \
15893 ".popsection\n" \
15894 - ".pushsection .altinstr_replacement, \"ax\"\n" \
15895 + ".pushsection .altinstr_replacement, \"a\"\n" \
15896 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
15897 ".popsection"
15898
15899 @@ -120,7 +120,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
15900 DISCARD_ENTRY(1) \
15901 DISCARD_ENTRY(2) \
15902 ".popsection\n" \
15903 - ".pushsection .altinstr_replacement, \"ax\"\n" \
15904 + ".pushsection .altinstr_replacement, \"a\"\n" \
15905 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
15906 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
15907 ".popsection"
15908 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
15909 index 465b309..ab7e51f 100644
15910 --- a/arch/x86/include/asm/apic.h
15911 +++ b/arch/x86/include/asm/apic.h
15912 @@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
15913
15914 #ifdef CONFIG_X86_LOCAL_APIC
15915
15916 -extern unsigned int apic_verbosity;
15917 +extern int apic_verbosity;
15918 extern int local_apic_timer_c2_ok;
15919
15920 extern int disable_apic;
15921 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
15922 index 20370c6..a2eb9b0 100644
15923 --- a/arch/x86/include/asm/apm.h
15924 +++ b/arch/x86/include/asm/apm.h
15925 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
15926 __asm__ __volatile__(APM_DO_ZERO_SEGS
15927 "pushl %%edi\n\t"
15928 "pushl %%ebp\n\t"
15929 - "lcall *%%cs:apm_bios_entry\n\t"
15930 + "lcall *%%ss:apm_bios_entry\n\t"
15931 "setc %%al\n\t"
15932 "popl %%ebp\n\t"
15933 "popl %%edi\n\t"
15934 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
15935 __asm__ __volatile__(APM_DO_ZERO_SEGS
15936 "pushl %%edi\n\t"
15937 "pushl %%ebp\n\t"
15938 - "lcall *%%cs:apm_bios_entry\n\t"
15939 + "lcall *%%ss:apm_bios_entry\n\t"
15940 "setc %%bl\n\t"
15941 "popl %%ebp\n\t"
15942 "popl %%edi\n\t"
15943 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
15944 index 6dd1c7dd..5a85bf2 100644
15945 --- a/arch/x86/include/asm/atomic.h
15946 +++ b/arch/x86/include/asm/atomic.h
15947 @@ -24,7 +24,18 @@
15948 */
15949 static inline int atomic_read(const atomic_t *v)
15950 {
15951 - return (*(volatile int *)&(v)->counter);
15952 + return (*(volatile const int *)&(v)->counter);
15953 +}
15954 +
15955 +/**
15956 + * atomic_read_unchecked - read atomic variable
15957 + * @v: pointer of type atomic_unchecked_t
15958 + *
15959 + * Atomically reads the value of @v.
15960 + */
15961 +static inline int __intentional_overflow(-1) atomic_read_unchecked(const atomic_unchecked_t *v)
15962 +{
15963 + return (*(volatile const int *)&(v)->counter);
15964 }
15965
15966 /**
15967 @@ -40,6 +51,18 @@ static inline void atomic_set(atomic_t *v, int i)
15968 }
15969
15970 /**
15971 + * atomic_set_unchecked - set atomic variable
15972 + * @v: pointer of type atomic_unchecked_t
15973 + * @i: required value
15974 + *
15975 + * Atomically sets the value of @v to @i.
15976 + */
15977 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
15978 +{
15979 + v->counter = i;
15980 +}
15981 +
15982 +/**
15983 * atomic_add - add integer to atomic variable
15984 * @i: integer value to add
15985 * @v: pointer of type atomic_t
15986 @@ -48,7 +71,29 @@ static inline void atomic_set(atomic_t *v, int i)
15987 */
15988 static inline void atomic_add(int i, atomic_t *v)
15989 {
15990 - asm volatile(LOCK_PREFIX "addl %1,%0"
15991 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
15992 +
15993 +#ifdef CONFIG_PAX_REFCOUNT
15994 + "jno 0f\n"
15995 + LOCK_PREFIX "subl %1,%0\n"
15996 + "int $4\n0:\n"
15997 + _ASM_EXTABLE(0b, 0b)
15998 +#endif
15999 +
16000 + : "+m" (v->counter)
16001 + : "ir" (i));
16002 +}
16003 +
16004 +/**
16005 + * atomic_add_unchecked - add integer to atomic variable
16006 + * @i: integer value to add
16007 + * @v: pointer of type atomic_unchecked_t
16008 + *
16009 + * Atomically adds @i to @v.
16010 + */
16011 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
16012 +{
16013 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
16014 : "+m" (v->counter)
16015 : "ir" (i));
16016 }
16017 @@ -62,7 +107,29 @@ static inline void atomic_add(int i, atomic_t *v)
16018 */
16019 static inline void atomic_sub(int i, atomic_t *v)
16020 {
16021 - asm volatile(LOCK_PREFIX "subl %1,%0"
16022 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
16023 +
16024 +#ifdef CONFIG_PAX_REFCOUNT
16025 + "jno 0f\n"
16026 + LOCK_PREFIX "addl %1,%0\n"
16027 + "int $4\n0:\n"
16028 + _ASM_EXTABLE(0b, 0b)
16029 +#endif
16030 +
16031 + : "+m" (v->counter)
16032 + : "ir" (i));
16033 +}
16034 +
16035 +/**
16036 + * atomic_sub_unchecked - subtract integer from atomic variable
16037 + * @i: integer value to subtract
16038 + * @v: pointer of type atomic_unchecked_t
16039 + *
16040 + * Atomically subtracts @i from @v.
16041 + */
16042 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
16043 +{
16044 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
16045 : "+m" (v->counter)
16046 : "ir" (i));
16047 }
16048 @@ -78,7 +145,7 @@ static inline void atomic_sub(int i, atomic_t *v)
16049 */
16050 static inline int atomic_sub_and_test(int i, atomic_t *v)
16051 {
16052 - GEN_BINARY_RMWcc(LOCK_PREFIX "subl", v->counter, "er", i, "%0", "e");
16053 + GEN_BINARY_RMWcc(LOCK_PREFIX "subl", LOCK_PREFIX "addl", v->counter, "er", i, "%0", "e");
16054 }
16055
16056 /**
16057 @@ -89,7 +156,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
16058 */
16059 static inline void atomic_inc(atomic_t *v)
16060 {
16061 - asm volatile(LOCK_PREFIX "incl %0"
16062 + asm volatile(LOCK_PREFIX "incl %0\n"
16063 +
16064 +#ifdef CONFIG_PAX_REFCOUNT
16065 + "jno 0f\n"
16066 + LOCK_PREFIX "decl %0\n"
16067 + "int $4\n0:\n"
16068 + _ASM_EXTABLE(0b, 0b)
16069 +#endif
16070 +
16071 + : "+m" (v->counter));
16072 +}
16073 +
16074 +/**
16075 + * atomic_inc_unchecked - increment atomic variable
16076 + * @v: pointer of type atomic_unchecked_t
16077 + *
16078 + * Atomically increments @v by 1.
16079 + */
16080 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
16081 +{
16082 + asm volatile(LOCK_PREFIX "incl %0\n"
16083 : "+m" (v->counter));
16084 }
16085
16086 @@ -101,7 +188,27 @@ static inline void atomic_inc(atomic_t *v)
16087 */
16088 static inline void atomic_dec(atomic_t *v)
16089 {
16090 - asm volatile(LOCK_PREFIX "decl %0"
16091 + asm volatile(LOCK_PREFIX "decl %0\n"
16092 +
16093 +#ifdef CONFIG_PAX_REFCOUNT
16094 + "jno 0f\n"
16095 + LOCK_PREFIX "incl %0\n"
16096 + "int $4\n0:\n"
16097 + _ASM_EXTABLE(0b, 0b)
16098 +#endif
16099 +
16100 + : "+m" (v->counter));
16101 +}
16102 +
16103 +/**
16104 + * atomic_dec_unchecked - decrement atomic variable
16105 + * @v: pointer of type atomic_unchecked_t
16106 + *
16107 + * Atomically decrements @v by 1.
16108 + */
16109 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
16110 +{
16111 + asm volatile(LOCK_PREFIX "decl %0\n"
16112 : "+m" (v->counter));
16113 }
16114
16115 @@ -115,7 +222,7 @@ static inline void atomic_dec(atomic_t *v)
16116 */
16117 static inline int atomic_dec_and_test(atomic_t *v)
16118 {
16119 - GEN_UNARY_RMWcc(LOCK_PREFIX "decl", v->counter, "%0", "e");
16120 + GEN_UNARY_RMWcc(LOCK_PREFIX "decl", LOCK_PREFIX "incl", v->counter, "%0", "e");
16121 }
16122
16123 /**
16124 @@ -128,7 +235,20 @@ static inline int atomic_dec_and_test(atomic_t *v)
16125 */
16126 static inline int atomic_inc_and_test(atomic_t *v)
16127 {
16128 - GEN_UNARY_RMWcc(LOCK_PREFIX "incl", v->counter, "%0", "e");
16129 + GEN_UNARY_RMWcc(LOCK_PREFIX "incl", LOCK_PREFIX "decl", v->counter, "%0", "e");
16130 +}
16131 +
16132 +/**
16133 + * atomic_inc_and_test_unchecked - increment and test
16134 + * @v: pointer of type atomic_unchecked_t
16135 + *
16136 + * Atomically increments @v by 1
16137 + * and returns true if the result is zero, or false for all
16138 + * other cases.
16139 + */
16140 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
16141 +{
16142 + GEN_UNARY_RMWcc_unchecked(LOCK_PREFIX "incl", v->counter, "%0", "e");
16143 }
16144
16145 /**
16146 @@ -142,7 +262,7 @@ static inline int atomic_inc_and_test(atomic_t *v)
16147 */
16148 static inline int atomic_add_negative(int i, atomic_t *v)
16149 {
16150 - GEN_BINARY_RMWcc(LOCK_PREFIX "addl", v->counter, "er", i, "%0", "s");
16151 + GEN_BINARY_RMWcc(LOCK_PREFIX "addl", LOCK_PREFIX "subl", v->counter, "er", i, "%0", "s");
16152 }
16153
16154 /**
16155 @@ -152,7 +272,19 @@ static inline int atomic_add_negative(int i, atomic_t *v)
16156 *
16157 * Atomically adds @i to @v and returns @i + @v
16158 */
16159 -static inline int atomic_add_return(int i, atomic_t *v)
16160 +static inline int __intentional_overflow(-1) atomic_add_return(int i, atomic_t *v)
16161 +{
16162 + return i + xadd_check_overflow(&v->counter, i);
16163 +}
16164 +
16165 +/**
16166 + * atomic_add_return_unchecked - add integer and return
16167 + * @i: integer value to add
16168 + * @v: pointer of type atomic_unchecked_t
16169 + *
16170 + * Atomically adds @i to @v and returns @i + @v
16171 + */
16172 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
16173 {
16174 return i + xadd(&v->counter, i);
16175 }
16176 @@ -164,15 +296,24 @@ static inline int atomic_add_return(int i, atomic_t *v)
16177 *
16178 * Atomically subtracts @i from @v and returns @v - @i
16179 */
16180 -static inline int atomic_sub_return(int i, atomic_t *v)
16181 +static inline int __intentional_overflow(-1) atomic_sub_return(int i, atomic_t *v)
16182 {
16183 return atomic_add_return(-i, v);
16184 }
16185
16186 #define atomic_inc_return(v) (atomic_add_return(1, v))
16187 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
16188 +{
16189 + return atomic_add_return_unchecked(1, v);
16190 +}
16191 #define atomic_dec_return(v) (atomic_sub_return(1, v))
16192
16193 -static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
16194 +static inline int __intentional_overflow(-1) atomic_cmpxchg(atomic_t *v, int old, int new)
16195 +{
16196 + return cmpxchg(&v->counter, old, new);
16197 +}
16198 +
16199 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
16200 {
16201 return cmpxchg(&v->counter, old, new);
16202 }
16203 @@ -182,6 +323,11 @@ static inline int atomic_xchg(atomic_t *v, int new)
16204 return xchg(&v->counter, new);
16205 }
16206
16207 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
16208 +{
16209 + return xchg(&v->counter, new);
16210 +}
16211 +
16212 /**
16213 * __atomic_add_unless - add unless the number is already a given value
16214 * @v: pointer of type atomic_t
16215 @@ -191,14 +337,27 @@ static inline int atomic_xchg(atomic_t *v, int new)
16216 * Atomically adds @a to @v, so long as @v was not already @u.
16217 * Returns the old value of @v.
16218 */
16219 -static inline int __atomic_add_unless(atomic_t *v, int a, int u)
16220 +static inline int __intentional_overflow(-1) __atomic_add_unless(atomic_t *v, int a, int u)
16221 {
16222 - int c, old;
16223 + int c, old, new;
16224 c = atomic_read(v);
16225 for (;;) {
16226 - if (unlikely(c == (u)))
16227 + if (unlikely(c == u))
16228 break;
16229 - old = atomic_cmpxchg((v), c, c + (a));
16230 +
16231 + asm volatile("addl %2,%0\n"
16232 +
16233 +#ifdef CONFIG_PAX_REFCOUNT
16234 + "jno 0f\n"
16235 + "subl %2,%0\n"
16236 + "int $4\n0:\n"
16237 + _ASM_EXTABLE(0b, 0b)
16238 +#endif
16239 +
16240 + : "=r" (new)
16241 + : "0" (c), "ir" (a));
16242 +
16243 + old = atomic_cmpxchg(v, c, new);
16244 if (likely(old == c))
16245 break;
16246 c = old;
16247 @@ -207,6 +366,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
16248 }
16249
16250 /**
16251 + * atomic_inc_not_zero_hint - increment if not null
16252 + * @v: pointer of type atomic_t
16253 + * @hint: probable value of the atomic before the increment
16254 + *
16255 + * This version of atomic_inc_not_zero() gives a hint of probable
16256 + * value of the atomic. This helps processor to not read the memory
16257 + * before doing the atomic read/modify/write cycle, lowering
16258 + * number of bus transactions on some arches.
16259 + *
16260 + * Returns: 0 if increment was not done, 1 otherwise.
16261 + */
16262 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
16263 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
16264 +{
16265 + int val, c = hint, new;
16266 +
16267 + /* sanity test, should be removed by compiler if hint is a constant */
16268 + if (!hint)
16269 + return __atomic_add_unless(v, 1, 0);
16270 +
16271 + do {
16272 + asm volatile("incl %0\n"
16273 +
16274 +#ifdef CONFIG_PAX_REFCOUNT
16275 + "jno 0f\n"
16276 + "decl %0\n"
16277 + "int $4\n0:\n"
16278 + _ASM_EXTABLE(0b, 0b)
16279 +#endif
16280 +
16281 + : "=r" (new)
16282 + : "0" (c));
16283 +
16284 + val = atomic_cmpxchg(v, c, new);
16285 + if (val == c)
16286 + return 1;
16287 + c = val;
16288 + } while (c);
16289 +
16290 + return 0;
16291 +}
16292 +
16293 +/**
16294 * atomic_inc_short - increment of a short integer
16295 * @v: pointer to type int
16296 *
16297 @@ -235,14 +437,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
16298 #endif
16299
16300 /* These are x86-specific, used by some header files */
16301 -#define atomic_clear_mask(mask, addr) \
16302 - asm volatile(LOCK_PREFIX "andl %0,%1" \
16303 - : : "r" (~(mask)), "m" (*(addr)) : "memory")
16304 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
16305 +{
16306 + asm volatile(LOCK_PREFIX "andl %1,%0"
16307 + : "+m" (v->counter)
16308 + : "r" (~(mask))
16309 + : "memory");
16310 +}
16311
16312 -#define atomic_set_mask(mask, addr) \
16313 - asm volatile(LOCK_PREFIX "orl %0,%1" \
16314 - : : "r" ((unsigned)(mask)), "m" (*(addr)) \
16315 - : "memory")
16316 +static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
16317 +{
16318 + asm volatile(LOCK_PREFIX "andl %1,%0"
16319 + : "+m" (v->counter)
16320 + : "r" (~(mask))
16321 + : "memory");
16322 +}
16323 +
16324 +static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
16325 +{
16326 + asm volatile(LOCK_PREFIX "orl %1,%0"
16327 + : "+m" (v->counter)
16328 + : "r" (mask)
16329 + : "memory");
16330 +}
16331 +
16332 +static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
16333 +{
16334 + asm volatile(LOCK_PREFIX "orl %1,%0"
16335 + : "+m" (v->counter)
16336 + : "r" (mask)
16337 + : "memory");
16338 +}
16339
16340 #ifdef CONFIG_X86_32
16341 # include <asm/atomic64_32.h>
16342 diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
16343 index b154de7..bf18a5a 100644
16344 --- a/arch/x86/include/asm/atomic64_32.h
16345 +++ b/arch/x86/include/asm/atomic64_32.h
16346 @@ -12,6 +12,14 @@ typedef struct {
16347 u64 __aligned(8) counter;
16348 } atomic64_t;
16349
16350 +#ifdef CONFIG_PAX_REFCOUNT
16351 +typedef struct {
16352 + u64 __aligned(8) counter;
16353 +} atomic64_unchecked_t;
16354 +#else
16355 +typedef atomic64_t atomic64_unchecked_t;
16356 +#endif
16357 +
16358 #define ATOMIC64_INIT(val) { (val) }
16359
16360 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
16361 @@ -37,21 +45,31 @@ typedef struct {
16362 ATOMIC64_DECL_ONE(sym##_386)
16363
16364 ATOMIC64_DECL_ONE(add_386);
16365 +ATOMIC64_DECL_ONE(add_unchecked_386);
16366 ATOMIC64_DECL_ONE(sub_386);
16367 +ATOMIC64_DECL_ONE(sub_unchecked_386);
16368 ATOMIC64_DECL_ONE(inc_386);
16369 +ATOMIC64_DECL_ONE(inc_unchecked_386);
16370 ATOMIC64_DECL_ONE(dec_386);
16371 +ATOMIC64_DECL_ONE(dec_unchecked_386);
16372 #endif
16373
16374 #define alternative_atomic64(f, out, in...) \
16375 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
16376
16377 ATOMIC64_DECL(read);
16378 +ATOMIC64_DECL(read_unchecked);
16379 ATOMIC64_DECL(set);
16380 +ATOMIC64_DECL(set_unchecked);
16381 ATOMIC64_DECL(xchg);
16382 ATOMIC64_DECL(add_return);
16383 +ATOMIC64_DECL(add_return_unchecked);
16384 ATOMIC64_DECL(sub_return);
16385 +ATOMIC64_DECL(sub_return_unchecked);
16386 ATOMIC64_DECL(inc_return);
16387 +ATOMIC64_DECL(inc_return_unchecked);
16388 ATOMIC64_DECL(dec_return);
16389 +ATOMIC64_DECL(dec_return_unchecked);
16390 ATOMIC64_DECL(dec_if_positive);
16391 ATOMIC64_DECL(inc_not_zero);
16392 ATOMIC64_DECL(add_unless);
16393 @@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
16394 }
16395
16396 /**
16397 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
16398 + * @p: pointer to type atomic64_unchecked_t
16399 + * @o: expected value
16400 + * @n: new value
16401 + *
16402 + * Atomically sets @v to @n if it was equal to @o and returns
16403 + * the old value.
16404 + */
16405 +
16406 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
16407 +{
16408 + return cmpxchg64(&v->counter, o, n);
16409 +}
16410 +
16411 +/**
16412 * atomic64_xchg - xchg atomic64 variable
16413 * @v: pointer to type atomic64_t
16414 * @n: value to assign
16415 @@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
16416 }
16417
16418 /**
16419 + * atomic64_set_unchecked - set atomic64 variable
16420 + * @v: pointer to type atomic64_unchecked_t
16421 + * @n: value to assign
16422 + *
16423 + * Atomically sets the value of @v to @n.
16424 + */
16425 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
16426 +{
16427 + unsigned high = (unsigned)(i >> 32);
16428 + unsigned low = (unsigned)i;
16429 + alternative_atomic64(set, /* no output */,
16430 + "S" (v), "b" (low), "c" (high)
16431 + : "eax", "edx", "memory");
16432 +}
16433 +
16434 +/**
16435 * atomic64_read - read atomic64 variable
16436 * @v: pointer to type atomic64_t
16437 *
16438 @@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
16439 }
16440
16441 /**
16442 + * atomic64_read_unchecked - read atomic64 variable
16443 + * @v: pointer to type atomic64_unchecked_t
16444 + *
16445 + * Atomically reads the value of @v and returns it.
16446 + */
16447 +static inline long long __intentional_overflow(-1) atomic64_read_unchecked(atomic64_unchecked_t *v)
16448 +{
16449 + long long r;
16450 + alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
16451 + return r;
16452 + }
16453 +
16454 +/**
16455 * atomic64_add_return - add and return
16456 * @i: integer value to add
16457 * @v: pointer to type atomic64_t
16458 @@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
16459 return i;
16460 }
16461
16462 +/**
16463 + * atomic64_add_return_unchecked - add and return
16464 + * @i: integer value to add
16465 + * @v: pointer to type atomic64_unchecked_t
16466 + *
16467 + * Atomically adds @i to @v and returns @i + *@v
16468 + */
16469 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
16470 +{
16471 + alternative_atomic64(add_return_unchecked,
16472 + ASM_OUTPUT2("+A" (i), "+c" (v)),
16473 + ASM_NO_INPUT_CLOBBER("memory"));
16474 + return i;
16475 +}
16476 +
16477 /*
16478 * Other variants with different arithmetic operators:
16479 */
16480 @@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
16481 return a;
16482 }
16483
16484 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
16485 +{
16486 + long long a;
16487 + alternative_atomic64(inc_return_unchecked, "=&A" (a),
16488 + "S" (v) : "memory", "ecx");
16489 + return a;
16490 +}
16491 +
16492 static inline long long atomic64_dec_return(atomic64_t *v)
16493 {
16494 long long a;
16495 @@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
16496 }
16497
16498 /**
16499 + * atomic64_add_unchecked - add integer to atomic64 variable
16500 + * @i: integer value to add
16501 + * @v: pointer to type atomic64_unchecked_t
16502 + *
16503 + * Atomically adds @i to @v.
16504 + */
16505 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
16506 +{
16507 + __alternative_atomic64(add_unchecked, add_return_unchecked,
16508 + ASM_OUTPUT2("+A" (i), "+c" (v)),
16509 + ASM_NO_INPUT_CLOBBER("memory"));
16510 + return i;
16511 +}
16512 +
16513 +/**
16514 * atomic64_sub - subtract the atomic64 variable
16515 * @i: integer value to subtract
16516 * @v: pointer to type atomic64_t
16517 diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
16518 index 46e9052..ae45136 100644
16519 --- a/arch/x86/include/asm/atomic64_64.h
16520 +++ b/arch/x86/include/asm/atomic64_64.h
16521 @@ -18,7 +18,19 @@
16522 */
16523 static inline long atomic64_read(const atomic64_t *v)
16524 {
16525 - return (*(volatile long *)&(v)->counter);
16526 + return (*(volatile const long *)&(v)->counter);
16527 +}
16528 +
16529 +/**
16530 + * atomic64_read_unchecked - read atomic64 variable
16531 + * @v: pointer of type atomic64_unchecked_t
16532 + *
16533 + * Atomically reads the value of @v.
16534 + * Doesn't imply a read memory barrier.
16535 + */
16536 +static inline long __intentional_overflow(-1) atomic64_read_unchecked(const atomic64_unchecked_t *v)
16537 +{
16538 + return (*(volatile const long *)&(v)->counter);
16539 }
16540
16541 /**
16542 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
16543 }
16544
16545 /**
16546 + * atomic64_set_unchecked - set atomic64 variable
16547 + * @v: pointer to type atomic64_unchecked_t
16548 + * @i: required value
16549 + *
16550 + * Atomically sets the value of @v to @i.
16551 + */
16552 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
16553 +{
16554 + v->counter = i;
16555 +}
16556 +
16557 +/**
16558 * atomic64_add - add integer to atomic64 variable
16559 * @i: integer value to add
16560 * @v: pointer to type atomic64_t
16561 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
16562 */
16563 static inline void atomic64_add(long i, atomic64_t *v)
16564 {
16565 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
16566 +
16567 +#ifdef CONFIG_PAX_REFCOUNT
16568 + "jno 0f\n"
16569 + LOCK_PREFIX "subq %1,%0\n"
16570 + "int $4\n0:\n"
16571 + _ASM_EXTABLE(0b, 0b)
16572 +#endif
16573 +
16574 + : "=m" (v->counter)
16575 + : "er" (i), "m" (v->counter));
16576 +}
16577 +
16578 +/**
16579 + * atomic64_add_unchecked - add integer to atomic64 variable
16580 + * @i: integer value to add
16581 + * @v: pointer to type atomic64_unchecked_t
16582 + *
16583 + * Atomically adds @i to @v.
16584 + */
16585 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
16586 +{
16587 asm volatile(LOCK_PREFIX "addq %1,%0"
16588 : "=m" (v->counter)
16589 : "er" (i), "m" (v->counter));
16590 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
16591 */
16592 static inline void atomic64_sub(long i, atomic64_t *v)
16593 {
16594 - asm volatile(LOCK_PREFIX "subq %1,%0"
16595 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
16596 +
16597 +#ifdef CONFIG_PAX_REFCOUNT
16598 + "jno 0f\n"
16599 + LOCK_PREFIX "addq %1,%0\n"
16600 + "int $4\n0:\n"
16601 + _ASM_EXTABLE(0b, 0b)
16602 +#endif
16603 +
16604 + : "=m" (v->counter)
16605 + : "er" (i), "m" (v->counter));
16606 +}
16607 +
16608 +/**
16609 + * atomic64_sub_unchecked - subtract the atomic64 variable
16610 + * @i: integer value to subtract
16611 + * @v: pointer to type atomic64_unchecked_t
16612 + *
16613 + * Atomically subtracts @i from @v.
16614 + */
16615 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
16616 +{
16617 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
16618 : "=m" (v->counter)
16619 : "er" (i), "m" (v->counter));
16620 }
16621 @@ -72,7 +140,7 @@ static inline void atomic64_sub(long i, atomic64_t *v)
16622 */
16623 static inline int atomic64_sub_and_test(long i, atomic64_t *v)
16624 {
16625 - GEN_BINARY_RMWcc(LOCK_PREFIX "subq", v->counter, "er", i, "%0", "e");
16626 + GEN_BINARY_RMWcc(LOCK_PREFIX "subq", LOCK_PREFIX "addq", v->counter, "er", i, "%0", "e");
16627 }
16628
16629 /**
16630 @@ -83,6 +151,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
16631 */
16632 static inline void atomic64_inc(atomic64_t *v)
16633 {
16634 + asm volatile(LOCK_PREFIX "incq %0\n"
16635 +
16636 +#ifdef CONFIG_PAX_REFCOUNT
16637 + "jno 0f\n"
16638 + LOCK_PREFIX "decq %0\n"
16639 + "int $4\n0:\n"
16640 + _ASM_EXTABLE(0b, 0b)
16641 +#endif
16642 +
16643 + : "=m" (v->counter)
16644 + : "m" (v->counter));
16645 +}
16646 +
16647 +/**
16648 + * atomic64_inc_unchecked - increment atomic64 variable
16649 + * @v: pointer to type atomic64_unchecked_t
16650 + *
16651 + * Atomically increments @v by 1.
16652 + */
16653 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
16654 +{
16655 asm volatile(LOCK_PREFIX "incq %0"
16656 : "=m" (v->counter)
16657 : "m" (v->counter));
16658 @@ -96,7 +185,28 @@ static inline void atomic64_inc(atomic64_t *v)
16659 */
16660 static inline void atomic64_dec(atomic64_t *v)
16661 {
16662 - asm volatile(LOCK_PREFIX "decq %0"
16663 + asm volatile(LOCK_PREFIX "decq %0\n"
16664 +
16665 +#ifdef CONFIG_PAX_REFCOUNT
16666 + "jno 0f\n"
16667 + LOCK_PREFIX "incq %0\n"
16668 + "int $4\n0:\n"
16669 + _ASM_EXTABLE(0b, 0b)
16670 +#endif
16671 +
16672 + : "=m" (v->counter)
16673 + : "m" (v->counter));
16674 +}
16675 +
16676 +/**
16677 + * atomic64_dec_unchecked - decrement atomic64 variable
16678 + * @v: pointer to type atomic64_t
16679 + *
16680 + * Atomically decrements @v by 1.
16681 + */
16682 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
16683 +{
16684 + asm volatile(LOCK_PREFIX "decq %0\n"
16685 : "=m" (v->counter)
16686 : "m" (v->counter));
16687 }
16688 @@ -111,7 +221,7 @@ static inline void atomic64_dec(atomic64_t *v)
16689 */
16690 static inline int atomic64_dec_and_test(atomic64_t *v)
16691 {
16692 - GEN_UNARY_RMWcc(LOCK_PREFIX "decq", v->counter, "%0", "e");
16693 + GEN_UNARY_RMWcc(LOCK_PREFIX "decq", LOCK_PREFIX "incq", v->counter, "%0", "e");
16694 }
16695
16696 /**
16697 @@ -124,7 +234,7 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
16698 */
16699 static inline int atomic64_inc_and_test(atomic64_t *v)
16700 {
16701 - GEN_UNARY_RMWcc(LOCK_PREFIX "incq", v->counter, "%0", "e");
16702 + GEN_UNARY_RMWcc(LOCK_PREFIX "incq", LOCK_PREFIX "decq", v->counter, "%0", "e");
16703 }
16704
16705 /**
16706 @@ -138,7 +248,7 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
16707 */
16708 static inline int atomic64_add_negative(long i, atomic64_t *v)
16709 {
16710 - GEN_BINARY_RMWcc(LOCK_PREFIX "addq", v->counter, "er", i, "%0", "s");
16711 + GEN_BINARY_RMWcc(LOCK_PREFIX "addq", LOCK_PREFIX "subq", v->counter, "er", i, "%0", "s");
16712 }
16713
16714 /**
16715 @@ -150,6 +260,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
16716 */
16717 static inline long atomic64_add_return(long i, atomic64_t *v)
16718 {
16719 + return i + xadd_check_overflow(&v->counter, i);
16720 +}
16721 +
16722 +/**
16723 + * atomic64_add_return_unchecked - add and return
16724 + * @i: integer value to add
16725 + * @v: pointer to type atomic64_unchecked_t
16726 + *
16727 + * Atomically adds @i to @v and returns @i + @v
16728 + */
16729 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
16730 +{
16731 return i + xadd(&v->counter, i);
16732 }
16733
16734 @@ -159,6 +281,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
16735 }
16736
16737 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
16738 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
16739 +{
16740 + return atomic64_add_return_unchecked(1, v);
16741 +}
16742 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
16743
16744 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
16745 @@ -166,6 +292,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
16746 return cmpxchg(&v->counter, old, new);
16747 }
16748
16749 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
16750 +{
16751 + return cmpxchg(&v->counter, old, new);
16752 +}
16753 +
16754 static inline long atomic64_xchg(atomic64_t *v, long new)
16755 {
16756 return xchg(&v->counter, new);
16757 @@ -182,17 +313,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
16758 */
16759 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
16760 {
16761 - long c, old;
16762 + long c, old, new;
16763 c = atomic64_read(v);
16764 for (;;) {
16765 - if (unlikely(c == (u)))
16766 + if (unlikely(c == u))
16767 break;
16768 - old = atomic64_cmpxchg((v), c, c + (a));
16769 +
16770 + asm volatile("add %2,%0\n"
16771 +
16772 +#ifdef CONFIG_PAX_REFCOUNT
16773 + "jno 0f\n"
16774 + "sub %2,%0\n"
16775 + "int $4\n0:\n"
16776 + _ASM_EXTABLE(0b, 0b)
16777 +#endif
16778 +
16779 + : "=r" (new)
16780 + : "0" (c), "ir" (a));
16781 +
16782 + old = atomic64_cmpxchg(v, c, new);
16783 if (likely(old == c))
16784 break;
16785 c = old;
16786 }
16787 - return c != (u);
16788 + return c != u;
16789 }
16790
16791 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
16792 diff --git a/arch/x86/include/asm/barrier.h b/arch/x86/include/asm/barrier.h
16793 index 0f4460b..fa1ee19 100644
16794 --- a/arch/x86/include/asm/barrier.h
16795 +++ b/arch/x86/include/asm/barrier.h
16796 @@ -107,7 +107,7 @@
16797 do { \
16798 compiletime_assert_atomic_type(*p); \
16799 smp_mb(); \
16800 - ACCESS_ONCE(*p) = (v); \
16801 + ACCESS_ONCE_RW(*p) = (v); \
16802 } while (0)
16803
16804 #define smp_load_acquire(p) \
16805 @@ -124,7 +124,7 @@ do { \
16806 do { \
16807 compiletime_assert_atomic_type(*p); \
16808 barrier(); \
16809 - ACCESS_ONCE(*p) = (v); \
16810 + ACCESS_ONCE_RW(*p) = (v); \
16811 } while (0)
16812
16813 #define smp_load_acquire(p) \
16814 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
16815 index cfe3b95..d01b118 100644
16816 --- a/arch/x86/include/asm/bitops.h
16817 +++ b/arch/x86/include/asm/bitops.h
16818 @@ -50,7 +50,7 @@
16819 * a mask operation on a byte.
16820 */
16821 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
16822 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
16823 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
16824 #define CONST_MASK(nr) (1 << ((nr) & 7))
16825
16826 /**
16827 @@ -203,7 +203,7 @@ static inline void change_bit(long nr, volatile unsigned long *addr)
16828 */
16829 static inline int test_and_set_bit(long nr, volatile unsigned long *addr)
16830 {
16831 - GEN_BINARY_RMWcc(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
16832 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
16833 }
16834
16835 /**
16836 @@ -249,7 +249,7 @@ static inline int __test_and_set_bit(long nr, volatile unsigned long *addr)
16837 */
16838 static inline int test_and_clear_bit(long nr, volatile unsigned long *addr)
16839 {
16840 - GEN_BINARY_RMWcc(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
16841 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
16842 }
16843
16844 /**
16845 @@ -302,7 +302,7 @@ static inline int __test_and_change_bit(long nr, volatile unsigned long *addr)
16846 */
16847 static inline int test_and_change_bit(long nr, volatile unsigned long *addr)
16848 {
16849 - GEN_BINARY_RMWcc(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
16850 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
16851 }
16852
16853 static __always_inline int constant_test_bit(long nr, const volatile unsigned long *addr)
16854 @@ -343,7 +343,7 @@ static int test_bit(int nr, const volatile unsigned long *addr);
16855 *
16856 * Undefined if no bit exists, so code should check against 0 first.
16857 */
16858 -static inline unsigned long __ffs(unsigned long word)
16859 +static inline unsigned long __intentional_overflow(-1) __ffs(unsigned long word)
16860 {
16861 asm("rep; bsf %1,%0"
16862 : "=r" (word)
16863 @@ -357,7 +357,7 @@ static inline unsigned long __ffs(unsigned long word)
16864 *
16865 * Undefined if no zero exists, so code should check against ~0UL first.
16866 */
16867 -static inline unsigned long ffz(unsigned long word)
16868 +static inline unsigned long __intentional_overflow(-1) ffz(unsigned long word)
16869 {
16870 asm("rep; bsf %1,%0"
16871 : "=r" (word)
16872 @@ -371,7 +371,7 @@ static inline unsigned long ffz(unsigned long word)
16873 *
16874 * Undefined if no set bit exists, so code should check against 0 first.
16875 */
16876 -static inline unsigned long __fls(unsigned long word)
16877 +static inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
16878 {
16879 asm("bsr %1,%0"
16880 : "=r" (word)
16881 @@ -434,7 +434,7 @@ static inline int ffs(int x)
16882 * set bit if value is nonzero. The last (most significant) bit is
16883 * at position 32.
16884 */
16885 -static inline int fls(int x)
16886 +static inline int __intentional_overflow(-1) fls(int x)
16887 {
16888 int r;
16889
16890 @@ -476,7 +476,7 @@ static inline int fls(int x)
16891 * at position 64.
16892 */
16893 #ifdef CONFIG_X86_64
16894 -static __always_inline int fls64(__u64 x)
16895 +static __always_inline __intentional_overflow(-1) int fls64(__u64 x)
16896 {
16897 int bitpos = -1;
16898 /*
16899 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
16900 index 4fa687a..60f2d39 100644
16901 --- a/arch/x86/include/asm/boot.h
16902 +++ b/arch/x86/include/asm/boot.h
16903 @@ -6,10 +6,15 @@
16904 #include <uapi/asm/boot.h>
16905
16906 /* Physical address where kernel should be loaded. */
16907 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
16908 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
16909 + (CONFIG_PHYSICAL_ALIGN - 1)) \
16910 & ~(CONFIG_PHYSICAL_ALIGN - 1))
16911
16912 +#ifndef __ASSEMBLY__
16913 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
16914 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
16915 +#endif
16916 +
16917 /* Minimum kernel alignment, as a power of two */
16918 #ifdef CONFIG_X86_64
16919 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
16920 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
16921 index 48f99f1..d78ebf9 100644
16922 --- a/arch/x86/include/asm/cache.h
16923 +++ b/arch/x86/include/asm/cache.h
16924 @@ -5,12 +5,13 @@
16925
16926 /* L1 cache line size */
16927 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
16928 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
16929 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
16930
16931 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
16932 +#define __read_only __attribute__((__section__(".data..read_only")))
16933
16934 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
16935 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
16936 +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
16937
16938 #ifdef CONFIG_X86_VSMP
16939 #ifdef CONFIG_SMP
16940 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
16941 index 9863ee3..4a1f8e1 100644
16942 --- a/arch/x86/include/asm/cacheflush.h
16943 +++ b/arch/x86/include/asm/cacheflush.h
16944 @@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
16945 unsigned long pg_flags = pg->flags & _PGMT_MASK;
16946
16947 if (pg_flags == _PGMT_DEFAULT)
16948 - return -1;
16949 + return ~0UL;
16950 else if (pg_flags == _PGMT_WC)
16951 return _PAGE_CACHE_WC;
16952 else if (pg_flags == _PGMT_UC_MINUS)
16953 diff --git a/arch/x86/include/asm/calling.h b/arch/x86/include/asm/calling.h
16954 index cb4c73b..c473c29 100644
16955 --- a/arch/x86/include/asm/calling.h
16956 +++ b/arch/x86/include/asm/calling.h
16957 @@ -82,103 +82,113 @@ For 32-bit we have the following conventions - kernel is built with
16958 #define RSP 152
16959 #define SS 160
16960
16961 -#define ARGOFFSET R11
16962 -#define SWFRAME ORIG_RAX
16963 +#define ARGOFFSET R15
16964
16965 .macro SAVE_ARGS addskip=0, save_rcx=1, save_r891011=1
16966 - subq $9*8+\addskip, %rsp
16967 - CFI_ADJUST_CFA_OFFSET 9*8+\addskip
16968 - movq_cfi rdi, 8*8
16969 - movq_cfi rsi, 7*8
16970 - movq_cfi rdx, 6*8
16971 + subq $ORIG_RAX-ARGOFFSET+\addskip, %rsp
16972 + CFI_ADJUST_CFA_OFFSET ORIG_RAX-ARGOFFSET+\addskip
16973 + movq_cfi rdi, RDI
16974 + movq_cfi rsi, RSI
16975 + movq_cfi rdx, RDX
16976
16977 .if \save_rcx
16978 - movq_cfi rcx, 5*8
16979 + movq_cfi rcx, RCX
16980 .endif
16981
16982 - movq_cfi rax, 4*8
16983 + movq_cfi rax, RAX
16984
16985 .if \save_r891011
16986 - movq_cfi r8, 3*8
16987 - movq_cfi r9, 2*8
16988 - movq_cfi r10, 1*8
16989 - movq_cfi r11, 0*8
16990 + movq_cfi r8, R8
16991 + movq_cfi r9, R9
16992 + movq_cfi r10, R10
16993 + movq_cfi r11, R11
16994 .endif
16995
16996 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16997 + movq_cfi r12, R12
16998 +#endif
16999 +
17000 .endm
17001
17002 -#define ARG_SKIP (9*8)
17003 +#define ARG_SKIP ORIG_RAX
17004
17005 .macro RESTORE_ARGS rstor_rax=1, addskip=0, rstor_rcx=1, rstor_r11=1, \
17006 rstor_r8910=1, rstor_rdx=1
17007 +
17008 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
17009 + movq_cfi_restore R12, r12
17010 +#endif
17011 +
17012 .if \rstor_r11
17013 - movq_cfi_restore 0*8, r11
17014 + movq_cfi_restore R11, r11
17015 .endif
17016
17017 .if \rstor_r8910
17018 - movq_cfi_restore 1*8, r10
17019 - movq_cfi_restore 2*8, r9
17020 - movq_cfi_restore 3*8, r8
17021 + movq_cfi_restore R10, r10
17022 + movq_cfi_restore R9, r9
17023 + movq_cfi_restore R8, r8
17024 .endif
17025
17026 .if \rstor_rax
17027 - movq_cfi_restore 4*8, rax
17028 + movq_cfi_restore RAX, rax
17029 .endif
17030
17031 .if \rstor_rcx
17032 - movq_cfi_restore 5*8, rcx
17033 + movq_cfi_restore RCX, rcx
17034 .endif
17035
17036 .if \rstor_rdx
17037 - movq_cfi_restore 6*8, rdx
17038 + movq_cfi_restore RDX, rdx
17039 .endif
17040
17041 - movq_cfi_restore 7*8, rsi
17042 - movq_cfi_restore 8*8, rdi
17043 + movq_cfi_restore RSI, rsi
17044 + movq_cfi_restore RDI, rdi
17045
17046 - .if ARG_SKIP+\addskip > 0
17047 - addq $ARG_SKIP+\addskip, %rsp
17048 - CFI_ADJUST_CFA_OFFSET -(ARG_SKIP+\addskip)
17049 + .if ORIG_RAX+\addskip > 0
17050 + addq $ORIG_RAX+\addskip, %rsp
17051 + CFI_ADJUST_CFA_OFFSET -(ORIG_RAX+\addskip)
17052 .endif
17053 .endm
17054
17055 - .macro LOAD_ARGS offset, skiprax=0
17056 - movq \offset(%rsp), %r11
17057 - movq \offset+8(%rsp), %r10
17058 - movq \offset+16(%rsp), %r9
17059 - movq \offset+24(%rsp), %r8
17060 - movq \offset+40(%rsp), %rcx
17061 - movq \offset+48(%rsp), %rdx
17062 - movq \offset+56(%rsp), %rsi
17063 - movq \offset+64(%rsp), %rdi
17064 + .macro LOAD_ARGS skiprax=0
17065 + movq R11(%rsp), %r11
17066 + movq R10(%rsp), %r10
17067 + movq R9(%rsp), %r9
17068 + movq R8(%rsp), %r8
17069 + movq RCX(%rsp), %rcx
17070 + movq RDX(%rsp), %rdx
17071 + movq RSI(%rsp), %rsi
17072 + movq RDI(%rsp), %rdi
17073 .if \skiprax
17074 .else
17075 - movq \offset+72(%rsp), %rax
17076 + movq RAX(%rsp), %rax
17077 .endif
17078 .endm
17079
17080 -#define REST_SKIP (6*8)
17081 -
17082 .macro SAVE_REST
17083 - subq $REST_SKIP, %rsp
17084 - CFI_ADJUST_CFA_OFFSET REST_SKIP
17085 - movq_cfi rbx, 5*8
17086 - movq_cfi rbp, 4*8
17087 - movq_cfi r12, 3*8
17088 - movq_cfi r13, 2*8
17089 - movq_cfi r14, 1*8
17090 - movq_cfi r15, 0*8
17091 + movq_cfi rbx, RBX
17092 + movq_cfi rbp, RBP
17093 +
17094 +#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
17095 + movq_cfi r12, R12
17096 +#endif
17097 +
17098 + movq_cfi r13, R13
17099 + movq_cfi r14, R14
17100 + movq_cfi r15, R15
17101 .endm
17102
17103 .macro RESTORE_REST
17104 - movq_cfi_restore 0*8, r15
17105 - movq_cfi_restore 1*8, r14
17106 - movq_cfi_restore 2*8, r13
17107 - movq_cfi_restore 3*8, r12
17108 - movq_cfi_restore 4*8, rbp
17109 - movq_cfi_restore 5*8, rbx
17110 - addq $REST_SKIP, %rsp
17111 - CFI_ADJUST_CFA_OFFSET -(REST_SKIP)
17112 + movq_cfi_restore R15, r15
17113 + movq_cfi_restore R14, r14
17114 + movq_cfi_restore R13, r13
17115 +
17116 +#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
17117 + movq_cfi_restore R12, r12
17118 +#endif
17119 +
17120 + movq_cfi_restore RBP, rbp
17121 + movq_cfi_restore RBX, rbx
17122 .endm
17123
17124 .macro SAVE_ALL
17125 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
17126 index f50de69..2b0a458 100644
17127 --- a/arch/x86/include/asm/checksum_32.h
17128 +++ b/arch/x86/include/asm/checksum_32.h
17129 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
17130 int len, __wsum sum,
17131 int *src_err_ptr, int *dst_err_ptr);
17132
17133 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
17134 + int len, __wsum sum,
17135 + int *src_err_ptr, int *dst_err_ptr);
17136 +
17137 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
17138 + int len, __wsum sum,
17139 + int *src_err_ptr, int *dst_err_ptr);
17140 +
17141 /*
17142 * Note: when you get a NULL pointer exception here this means someone
17143 * passed in an incorrect kernel address to one of these functions.
17144 @@ -53,7 +61,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
17145
17146 might_sleep();
17147 stac();
17148 - ret = csum_partial_copy_generic((__force void *)src, dst,
17149 + ret = csum_partial_copy_generic_from_user((__force void *)src, dst,
17150 len, sum, err_ptr, NULL);
17151 clac();
17152
17153 @@ -187,7 +195,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
17154 might_sleep();
17155 if (access_ok(VERIFY_WRITE, dst, len)) {
17156 stac();
17157 - ret = csum_partial_copy_generic(src, (__force void *)dst,
17158 + ret = csum_partial_copy_generic_to_user(src, (__force void *)dst,
17159 len, sum, NULL, err_ptr);
17160 clac();
17161 return ret;
17162 diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
17163 index 99c105d7..2f667ac 100644
17164 --- a/arch/x86/include/asm/cmpxchg.h
17165 +++ b/arch/x86/include/asm/cmpxchg.h
17166 @@ -16,8 +16,12 @@ extern void __cmpxchg_wrong_size(void)
17167 __compiletime_error("Bad argument size for cmpxchg");
17168 extern void __xadd_wrong_size(void)
17169 __compiletime_error("Bad argument size for xadd");
17170 +extern void __xadd_check_overflow_wrong_size(void)
17171 + __compiletime_error("Bad argument size for xadd_check_overflow");
17172 extern void __add_wrong_size(void)
17173 __compiletime_error("Bad argument size for add");
17174 +extern void __add_check_overflow_wrong_size(void)
17175 + __compiletime_error("Bad argument size for add_check_overflow");
17176
17177 /*
17178 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
17179 @@ -69,6 +73,38 @@ extern void __add_wrong_size(void)
17180 __ret; \
17181 })
17182
17183 +#ifdef CONFIG_PAX_REFCOUNT
17184 +#define __xchg_op_check_overflow(ptr, arg, op, lock) \
17185 + ({ \
17186 + __typeof__ (*(ptr)) __ret = (arg); \
17187 + switch (sizeof(*(ptr))) { \
17188 + case __X86_CASE_L: \
17189 + asm volatile (lock #op "l %0, %1\n" \
17190 + "jno 0f\n" \
17191 + "mov %0,%1\n" \
17192 + "int $4\n0:\n" \
17193 + _ASM_EXTABLE(0b, 0b) \
17194 + : "+r" (__ret), "+m" (*(ptr)) \
17195 + : : "memory", "cc"); \
17196 + break; \
17197 + case __X86_CASE_Q: \
17198 + asm volatile (lock #op "q %q0, %1\n" \
17199 + "jno 0f\n" \
17200 + "mov %0,%1\n" \
17201 + "int $4\n0:\n" \
17202 + _ASM_EXTABLE(0b, 0b) \
17203 + : "+r" (__ret), "+m" (*(ptr)) \
17204 + : : "memory", "cc"); \
17205 + break; \
17206 + default: \
17207 + __ ## op ## _check_overflow_wrong_size(); \
17208 + } \
17209 + __ret; \
17210 + })
17211 +#else
17212 +#define __xchg_op_check_overflow(ptr, arg, op, lock) __xchg_op(ptr, arg, op, lock)
17213 +#endif
17214 +
17215 /*
17216 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
17217 * Since this is generally used to protect other memory information, we
17218 @@ -167,6 +203,9 @@ extern void __add_wrong_size(void)
17219 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
17220 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
17221
17222 +#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
17223 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
17224 +
17225 #define __add(ptr, inc, lock) \
17226 ({ \
17227 __typeof__ (*(ptr)) __ret = (inc); \
17228 diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
17229 index 59c6c40..5e0b22c 100644
17230 --- a/arch/x86/include/asm/compat.h
17231 +++ b/arch/x86/include/asm/compat.h
17232 @@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
17233 typedef u32 compat_uint_t;
17234 typedef u32 compat_ulong_t;
17235 typedef u64 __attribute__((aligned(4))) compat_u64;
17236 -typedef u32 compat_uptr_t;
17237 +typedef u32 __user compat_uptr_t;
17238
17239 struct compat_timespec {
17240 compat_time_t tv_sec;
17241 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
17242 index 2075e6c..4d368b4 100644
17243 --- a/arch/x86/include/asm/cpufeature.h
17244 +++ b/arch/x86/include/asm/cpufeature.h
17245 @@ -203,7 +203,7 @@
17246 #define X86_FEATURE_PAUSEFILTER ( 8*32+13) /* AMD filtered pause intercept */
17247 #define X86_FEATURE_PFTHRESHOLD ( 8*32+14) /* AMD pause filter threshold */
17248 #define X86_FEATURE_VMMCALL ( 8*32+15) /* Prefer vmmcall to vmcall */
17249 -
17250 +#define X86_FEATURE_STRONGUDEREF (8*32+31) /* PaX PCID based strong UDEREF */
17251
17252 /* Intel-defined CPU features, CPUID level 0x00000007:0 (ebx), word 9 */
17253 #define X86_FEATURE_FSGSBASE ( 9*32+ 0) /* {RD/WR}{FS/GS}BASE instructions*/
17254 @@ -211,7 +211,7 @@
17255 #define X86_FEATURE_BMI1 ( 9*32+ 3) /* 1st group bit manipulation extensions */
17256 #define X86_FEATURE_HLE ( 9*32+ 4) /* Hardware Lock Elision */
17257 #define X86_FEATURE_AVX2 ( 9*32+ 5) /* AVX2 instructions */
17258 -#define X86_FEATURE_SMEP ( 9*32+ 7) /* Supervisor Mode Execution Protection */
17259 +#define X86_FEATURE_SMEP ( 9*32+ 7) /* Supervisor Mode Execution Prevention */
17260 #define X86_FEATURE_BMI2 ( 9*32+ 8) /* 2nd group bit manipulation extensions */
17261 #define X86_FEATURE_ERMS ( 9*32+ 9) /* Enhanced REP MOVSB/STOSB */
17262 #define X86_FEATURE_INVPCID ( 9*32+10) /* Invalidate Processor Context ID */
17263 @@ -371,6 +371,7 @@ extern const char * const x86_bug_flags[NBUGINTS*32];
17264 #undef cpu_has_centaur_mcr
17265 #define cpu_has_centaur_mcr 0
17266
17267 +#define cpu_has_pcid boot_cpu_has(X86_FEATURE_PCID)
17268 #endif /* CONFIG_X86_64 */
17269
17270 #if __GNUC__ >= 4
17271 @@ -423,7 +424,8 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
17272
17273 #ifdef CONFIG_X86_DEBUG_STATIC_CPU_HAS
17274 t_warn:
17275 - warn_pre_alternatives();
17276 + if (bit != X86_FEATURE_PCID && bit != X86_FEATURE_INVPCID)
17277 + warn_pre_alternatives();
17278 return false;
17279 #endif
17280
17281 @@ -443,7 +445,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
17282 ".section .discard,\"aw\",@progbits\n"
17283 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
17284 ".previous\n"
17285 - ".section .altinstr_replacement,\"ax\"\n"
17286 + ".section .altinstr_replacement,\"a\"\n"
17287 "3: movb $1,%0\n"
17288 "4:\n"
17289 ".previous\n"
17290 @@ -480,7 +482,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
17291 " .byte 2b - 1b\n" /* src len */
17292 " .byte 4f - 3f\n" /* repl len */
17293 ".previous\n"
17294 - ".section .altinstr_replacement,\"ax\"\n"
17295 + ".section .altinstr_replacement,\"a\"\n"
17296 "3: .byte 0xe9\n .long %l[t_no] - 2b\n"
17297 "4:\n"
17298 ".previous\n"
17299 @@ -513,7 +515,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
17300 ".section .discard,\"aw\",@progbits\n"
17301 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
17302 ".previous\n"
17303 - ".section .altinstr_replacement,\"ax\"\n"
17304 + ".section .altinstr_replacement,\"a\"\n"
17305 "3: movb $0,%0\n"
17306 "4:\n"
17307 ".previous\n"
17308 @@ -527,7 +529,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
17309 ".section .discard,\"aw\",@progbits\n"
17310 " .byte 0xff + (6f-5f) - (4b-3b)\n" /* size check */
17311 ".previous\n"
17312 - ".section .altinstr_replacement,\"ax\"\n"
17313 + ".section .altinstr_replacement,\"a\"\n"
17314 "5: movb $1,%0\n"
17315 "6:\n"
17316 ".previous\n"
17317 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
17318 index 50d033a..37deb26 100644
17319 --- a/arch/x86/include/asm/desc.h
17320 +++ b/arch/x86/include/asm/desc.h
17321 @@ -4,6 +4,7 @@
17322 #include <asm/desc_defs.h>
17323 #include <asm/ldt.h>
17324 #include <asm/mmu.h>
17325 +#include <asm/pgtable.h>
17326
17327 #include <linux/smp.h>
17328 #include <linux/percpu.h>
17329 @@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
17330
17331 desc->type = (info->read_exec_only ^ 1) << 1;
17332 desc->type |= info->contents << 2;
17333 + desc->type |= info->seg_not_present ^ 1;
17334
17335 desc->s = 1;
17336 desc->dpl = 0x3;
17337 @@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
17338 }
17339
17340 extern struct desc_ptr idt_descr;
17341 -extern gate_desc idt_table[];
17342 -extern struct desc_ptr debug_idt_descr;
17343 -extern gate_desc debug_idt_table[];
17344 -
17345 -struct gdt_page {
17346 - struct desc_struct gdt[GDT_ENTRIES];
17347 -} __attribute__((aligned(PAGE_SIZE)));
17348 -
17349 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
17350 +extern gate_desc idt_table[IDT_ENTRIES];
17351 +extern const struct desc_ptr debug_idt_descr;
17352 +extern gate_desc debug_idt_table[IDT_ENTRIES];
17353
17354 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
17355 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
17356 {
17357 - return per_cpu(gdt_page, cpu).gdt;
17358 + return cpu_gdt_table[cpu];
17359 }
17360
17361 #ifdef CONFIG_X86_64
17362 @@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
17363 unsigned long base, unsigned dpl, unsigned flags,
17364 unsigned short seg)
17365 {
17366 - gate->a = (seg << 16) | (base & 0xffff);
17367 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
17368 + gate->gate.offset_low = base;
17369 + gate->gate.seg = seg;
17370 + gate->gate.reserved = 0;
17371 + gate->gate.type = type;
17372 + gate->gate.s = 0;
17373 + gate->gate.dpl = dpl;
17374 + gate->gate.p = 1;
17375 + gate->gate.offset_high = base >> 16;
17376 }
17377
17378 #endif
17379 @@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
17380
17381 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
17382 {
17383 + pax_open_kernel();
17384 memcpy(&idt[entry], gate, sizeof(*gate));
17385 + pax_close_kernel();
17386 }
17387
17388 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
17389 {
17390 + pax_open_kernel();
17391 memcpy(&ldt[entry], desc, 8);
17392 + pax_close_kernel();
17393 }
17394
17395 static inline void
17396 @@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
17397 default: size = sizeof(*gdt); break;
17398 }
17399
17400 + pax_open_kernel();
17401 memcpy(&gdt[entry], desc, size);
17402 + pax_close_kernel();
17403 }
17404
17405 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
17406 @@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
17407
17408 static inline void native_load_tr_desc(void)
17409 {
17410 + pax_open_kernel();
17411 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
17412 + pax_close_kernel();
17413 }
17414
17415 static inline void native_load_gdt(const struct desc_ptr *dtr)
17416 @@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
17417 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
17418 unsigned int i;
17419
17420 + pax_open_kernel();
17421 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
17422 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
17423 + pax_close_kernel();
17424 }
17425
17426 #define _LDT_empty(info) \
17427 @@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
17428 preempt_enable();
17429 }
17430
17431 -static inline unsigned long get_desc_base(const struct desc_struct *desc)
17432 +static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
17433 {
17434 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
17435 }
17436 @@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
17437 }
17438
17439 #ifdef CONFIG_X86_64
17440 -static inline void set_nmi_gate(int gate, void *addr)
17441 +static inline void set_nmi_gate(int gate, const void *addr)
17442 {
17443 gate_desc s;
17444
17445 @@ -321,14 +334,14 @@ static inline void set_nmi_gate(int gate, void *addr)
17446 #endif
17447
17448 #ifdef CONFIG_TRACING
17449 -extern struct desc_ptr trace_idt_descr;
17450 -extern gate_desc trace_idt_table[];
17451 +extern const struct desc_ptr trace_idt_descr;
17452 +extern gate_desc trace_idt_table[IDT_ENTRIES];
17453 static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
17454 {
17455 write_idt_entry(trace_idt_table, entry, gate);
17456 }
17457
17458 -static inline void _trace_set_gate(int gate, unsigned type, void *addr,
17459 +static inline void _trace_set_gate(int gate, unsigned type, const void *addr,
17460 unsigned dpl, unsigned ist, unsigned seg)
17461 {
17462 gate_desc s;
17463 @@ -348,7 +361,7 @@ static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
17464 #define _trace_set_gate(gate, type, addr, dpl, ist, seg)
17465 #endif
17466
17467 -static inline void _set_gate(int gate, unsigned type, void *addr,
17468 +static inline void _set_gate(int gate, unsigned type, const void *addr,
17469 unsigned dpl, unsigned ist, unsigned seg)
17470 {
17471 gate_desc s;
17472 @@ -371,9 +384,9 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
17473 #define set_intr_gate(n, addr) \
17474 do { \
17475 BUG_ON((unsigned)n > 0xFF); \
17476 - _set_gate(n, GATE_INTERRUPT, (void *)addr, 0, 0, \
17477 + _set_gate(n, GATE_INTERRUPT, (const void *)addr, 0, 0, \
17478 __KERNEL_CS); \
17479 - _trace_set_gate(n, GATE_INTERRUPT, (void *)trace_##addr,\
17480 + _trace_set_gate(n, GATE_INTERRUPT, (const void *)trace_##addr,\
17481 0, 0, __KERNEL_CS); \
17482 } while (0)
17483
17484 @@ -401,19 +414,19 @@ static inline void alloc_system_vector(int vector)
17485 /*
17486 * This routine sets up an interrupt gate at directory privilege level 3.
17487 */
17488 -static inline void set_system_intr_gate(unsigned int n, void *addr)
17489 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
17490 {
17491 BUG_ON((unsigned)n > 0xFF);
17492 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
17493 }
17494
17495 -static inline void set_system_trap_gate(unsigned int n, void *addr)
17496 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
17497 {
17498 BUG_ON((unsigned)n > 0xFF);
17499 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
17500 }
17501
17502 -static inline void set_trap_gate(unsigned int n, void *addr)
17503 +static inline void set_trap_gate(unsigned int n, const void *addr)
17504 {
17505 BUG_ON((unsigned)n > 0xFF);
17506 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
17507 @@ -422,16 +435,16 @@ static inline void set_trap_gate(unsigned int n, void *addr)
17508 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
17509 {
17510 BUG_ON((unsigned)n > 0xFF);
17511 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
17512 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
17513 }
17514
17515 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
17516 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
17517 {
17518 BUG_ON((unsigned)n > 0xFF);
17519 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
17520 }
17521
17522 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
17523 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
17524 {
17525 BUG_ON((unsigned)n > 0xFF);
17526 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
17527 @@ -503,4 +516,17 @@ static inline void load_current_idt(void)
17528 else
17529 load_idt((const struct desc_ptr *)&idt_descr);
17530 }
17531 +
17532 +#ifdef CONFIG_X86_32
17533 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
17534 +{
17535 + struct desc_struct d;
17536 +
17537 + if (likely(limit))
17538 + limit = (limit - 1UL) >> PAGE_SHIFT;
17539 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
17540 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
17541 +}
17542 +#endif
17543 +
17544 #endif /* _ASM_X86_DESC_H */
17545 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
17546 index 278441f..b95a174 100644
17547 --- a/arch/x86/include/asm/desc_defs.h
17548 +++ b/arch/x86/include/asm/desc_defs.h
17549 @@ -31,6 +31,12 @@ struct desc_struct {
17550 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
17551 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
17552 };
17553 + struct {
17554 + u16 offset_low;
17555 + u16 seg;
17556 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
17557 + unsigned offset_high: 16;
17558 + } gate;
17559 };
17560 } __attribute__((packed));
17561
17562 diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
17563 index ced283a..ffe04cc 100644
17564 --- a/arch/x86/include/asm/div64.h
17565 +++ b/arch/x86/include/asm/div64.h
17566 @@ -39,7 +39,7 @@
17567 __mod; \
17568 })
17569
17570 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
17571 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
17572 {
17573 union {
17574 u64 v64;
17575 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
17576 index ca3347a..1a5082a 100644
17577 --- a/arch/x86/include/asm/elf.h
17578 +++ b/arch/x86/include/asm/elf.h
17579 @@ -75,9 +75,6 @@ typedef struct user_fxsr_struct elf_fpxregset_t;
17580
17581 #include <asm/vdso.h>
17582
17583 -#ifdef CONFIG_X86_64
17584 -extern unsigned int vdso64_enabled;
17585 -#endif
17586 #if defined(CONFIG_X86_32) || defined(CONFIG_COMPAT)
17587 extern unsigned int vdso32_enabled;
17588 #endif
17589 @@ -249,7 +246,25 @@ extern int force_personality32;
17590 the loader. We need to make sure that it is out of the way of the program
17591 that it will "exec", and that there is sufficient room for the brk. */
17592
17593 +#ifdef CONFIG_PAX_SEGMEXEC
17594 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
17595 +#else
17596 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
17597 +#endif
17598 +
17599 +#ifdef CONFIG_PAX_ASLR
17600 +#ifdef CONFIG_X86_32
17601 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
17602 +
17603 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
17604 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
17605 +#else
17606 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
17607 +
17608 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
17609 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
17610 +#endif
17611 +#endif
17612
17613 /* This yields a mask that user programs can use to figure out what
17614 instruction set this CPU supports. This could be done in user space,
17615 @@ -298,17 +313,13 @@ do { \
17616
17617 #define ARCH_DLINFO \
17618 do { \
17619 - if (vdso64_enabled) \
17620 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
17621 - (unsigned long __force)current->mm->context.vdso); \
17622 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
17623 } while (0)
17624
17625 /* As a historical oddity, the x32 and x86_64 vDSOs are controlled together. */
17626 #define ARCH_DLINFO_X32 \
17627 do { \
17628 - if (vdso64_enabled) \
17629 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
17630 - (unsigned long __force)current->mm->context.vdso); \
17631 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
17632 } while (0)
17633
17634 #define AT_SYSINFO 32
17635 @@ -323,10 +334,10 @@ else \
17636
17637 #endif /* !CONFIG_X86_32 */
17638
17639 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
17640 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
17641
17642 #define VDSO_ENTRY \
17643 - ((unsigned long)current->mm->context.vdso + \
17644 + (current->mm->context.vdso + \
17645 selected_vdso32->sym___kernel_vsyscall)
17646
17647 struct linux_binprm;
17648 @@ -338,9 +349,6 @@ extern int compat_arch_setup_additional_pages(struct linux_binprm *bprm,
17649 int uses_interp);
17650 #define compat_arch_setup_additional_pages compat_arch_setup_additional_pages
17651
17652 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
17653 -#define arch_randomize_brk arch_randomize_brk
17654 -
17655 /*
17656 * True on X86_32 or when emulating IA32 on X86_64
17657 */
17658 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
17659 index 77a99ac..39ff7f5 100644
17660 --- a/arch/x86/include/asm/emergency-restart.h
17661 +++ b/arch/x86/include/asm/emergency-restart.h
17662 @@ -1,6 +1,6 @@
17663 #ifndef _ASM_X86_EMERGENCY_RESTART_H
17664 #define _ASM_X86_EMERGENCY_RESTART_H
17665
17666 -extern void machine_emergency_restart(void);
17667 +extern void machine_emergency_restart(void) __noreturn;
17668
17669 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
17670 diff --git a/arch/x86/include/asm/floppy.h b/arch/x86/include/asm/floppy.h
17671 index 1c7eefe..d0e4702 100644
17672 --- a/arch/x86/include/asm/floppy.h
17673 +++ b/arch/x86/include/asm/floppy.h
17674 @@ -229,18 +229,18 @@ static struct fd_routine_l {
17675 int (*_dma_setup)(char *addr, unsigned long size, int mode, int io);
17676 } fd_routine[] = {
17677 {
17678 - request_dma,
17679 - free_dma,
17680 - get_dma_residue,
17681 - dma_mem_alloc,
17682 - hard_dma_setup
17683 + ._request_dma = request_dma,
17684 + ._free_dma = free_dma,
17685 + ._get_dma_residue = get_dma_residue,
17686 + ._dma_mem_alloc = dma_mem_alloc,
17687 + ._dma_setup = hard_dma_setup
17688 },
17689 {
17690 - vdma_request_dma,
17691 - vdma_nop,
17692 - vdma_get_dma_residue,
17693 - vdma_mem_alloc,
17694 - vdma_dma_setup
17695 + ._request_dma = vdma_request_dma,
17696 + ._free_dma = vdma_nop,
17697 + ._get_dma_residue = vdma_get_dma_residue,
17698 + ._dma_mem_alloc = vdma_mem_alloc,
17699 + ._dma_setup = vdma_dma_setup
17700 }
17701 };
17702
17703 diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
17704 index 412ecec..c1ea43a 100644
17705 --- a/arch/x86/include/asm/fpu-internal.h
17706 +++ b/arch/x86/include/asm/fpu-internal.h
17707 @@ -124,8 +124,11 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
17708 #define user_insn(insn, output, input...) \
17709 ({ \
17710 int err; \
17711 + pax_open_userland(); \
17712 asm volatile(ASM_STAC "\n" \
17713 - "1:" #insn "\n\t" \
17714 + "1:" \
17715 + __copyuser_seg \
17716 + #insn "\n\t" \
17717 "2: " ASM_CLAC "\n" \
17718 ".section .fixup,\"ax\"\n" \
17719 "3: movl $-1,%[err]\n" \
17720 @@ -134,6 +137,7 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
17721 _ASM_EXTABLE(1b, 3b) \
17722 : [err] "=r" (err), output \
17723 : "0"(0), input); \
17724 + pax_close_userland(); \
17725 err; \
17726 })
17727
17728 @@ -298,7 +302,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
17729 "fnclex\n\t"
17730 "emms\n\t"
17731 "fildl %P[addr]" /* set F?P to defined value */
17732 - : : [addr] "m" (tsk->thread.fpu.has_fpu));
17733 + : : [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
17734 }
17735
17736 return fpu_restore_checking(&tsk->thread.fpu);
17737 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
17738 index b4c1f54..e290c08 100644
17739 --- a/arch/x86/include/asm/futex.h
17740 +++ b/arch/x86/include/asm/futex.h
17741 @@ -12,6 +12,7 @@
17742 #include <asm/smap.h>
17743
17744 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
17745 + typecheck(u32 __user *, uaddr); \
17746 asm volatile("\t" ASM_STAC "\n" \
17747 "1:\t" insn "\n" \
17748 "2:\t" ASM_CLAC "\n" \
17749 @@ -20,15 +21,16 @@
17750 "\tjmp\t2b\n" \
17751 "\t.previous\n" \
17752 _ASM_EXTABLE(1b, 3b) \
17753 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
17754 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
17755 : "i" (-EFAULT), "0" (oparg), "1" (0))
17756
17757 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
17758 + typecheck(u32 __user *, uaddr); \
17759 asm volatile("\t" ASM_STAC "\n" \
17760 "1:\tmovl %2, %0\n" \
17761 "\tmovl\t%0, %3\n" \
17762 "\t" insn "\n" \
17763 - "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
17764 + "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
17765 "\tjnz\t1b\n" \
17766 "3:\t" ASM_CLAC "\n" \
17767 "\t.section .fixup,\"ax\"\n" \
17768 @@ -38,7 +40,7 @@
17769 _ASM_EXTABLE(1b, 4b) \
17770 _ASM_EXTABLE(2b, 4b) \
17771 : "=&a" (oldval), "=&r" (ret), \
17772 - "+m" (*uaddr), "=&r" (tem) \
17773 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
17774 : "r" (oparg), "i" (-EFAULT), "1" (0))
17775
17776 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
17777 @@ -57,12 +59,13 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
17778
17779 pagefault_disable();
17780
17781 + pax_open_userland();
17782 switch (op) {
17783 case FUTEX_OP_SET:
17784 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
17785 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
17786 break;
17787 case FUTEX_OP_ADD:
17788 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
17789 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
17790 uaddr, oparg);
17791 break;
17792 case FUTEX_OP_OR:
17793 @@ -77,6 +80,7 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
17794 default:
17795 ret = -ENOSYS;
17796 }
17797 + pax_close_userland();
17798
17799 pagefault_enable();
17800
17801 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
17802 index 4615906..788c817 100644
17803 --- a/arch/x86/include/asm/hw_irq.h
17804 +++ b/arch/x86/include/asm/hw_irq.h
17805 @@ -164,8 +164,8 @@ extern void setup_ioapic_dest(void);
17806 extern void enable_IO_APIC(void);
17807
17808 /* Statistics */
17809 -extern atomic_t irq_err_count;
17810 -extern atomic_t irq_mis_count;
17811 +extern atomic_unchecked_t irq_err_count;
17812 +extern atomic_unchecked_t irq_mis_count;
17813
17814 /* EISA */
17815 extern void eisa_set_level_irq(unsigned int irq);
17816 diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
17817 index ccffa53..3c90c87 100644
17818 --- a/arch/x86/include/asm/i8259.h
17819 +++ b/arch/x86/include/asm/i8259.h
17820 @@ -62,7 +62,7 @@ struct legacy_pic {
17821 void (*init)(int auto_eoi);
17822 int (*irq_pending)(unsigned int irq);
17823 void (*make_irq)(unsigned int irq);
17824 -};
17825 +} __do_const;
17826
17827 extern struct legacy_pic *legacy_pic;
17828 extern struct legacy_pic null_legacy_pic;
17829 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
17830 index b8237d8..3e8864e 100644
17831 --- a/arch/x86/include/asm/io.h
17832 +++ b/arch/x86/include/asm/io.h
17833 @@ -52,12 +52,12 @@ static inline void name(type val, volatile void __iomem *addr) \
17834 "m" (*(volatile type __force *)addr) barrier); }
17835
17836 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
17837 -build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
17838 -build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
17839 +build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
17840 +build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
17841
17842 build_mmio_read(__readb, "b", unsigned char, "=q", )
17843 -build_mmio_read(__readw, "w", unsigned short, "=r", )
17844 -build_mmio_read(__readl, "l", unsigned int, "=r", )
17845 +build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
17846 +build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
17847
17848 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
17849 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
17850 @@ -109,7 +109,7 @@ build_mmio_write(writeq, "q", unsigned long, "r", :"memory")
17851 * this function
17852 */
17853
17854 -static inline phys_addr_t virt_to_phys(volatile void *address)
17855 +static inline phys_addr_t __intentional_overflow(-1) virt_to_phys(volatile void *address)
17856 {
17857 return __pa(address);
17858 }
17859 @@ -185,7 +185,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
17860 return ioremap_nocache(offset, size);
17861 }
17862
17863 -extern void iounmap(volatile void __iomem *addr);
17864 +extern void iounmap(const volatile void __iomem *addr);
17865
17866 extern void set_iounmap_nonlazy(void);
17867
17868 @@ -195,6 +195,17 @@ extern void set_iounmap_nonlazy(void);
17869
17870 #include <linux/vmalloc.h>
17871
17872 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
17873 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
17874 +{
17875 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
17876 +}
17877 +
17878 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
17879 +{
17880 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
17881 +}
17882 +
17883 /*
17884 * Convert a virtual cached pointer to an uncached pointer
17885 */
17886 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
17887 index 0a8b519..80e7d5b 100644
17888 --- a/arch/x86/include/asm/irqflags.h
17889 +++ b/arch/x86/include/asm/irqflags.h
17890 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
17891 sti; \
17892 sysexit
17893
17894 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
17895 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
17896 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
17897 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
17898 +
17899 #else
17900 #define INTERRUPT_RETURN iret
17901 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
17902 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
17903 index 53cdfb2..d1369e6 100644
17904 --- a/arch/x86/include/asm/kprobes.h
17905 +++ b/arch/x86/include/asm/kprobes.h
17906 @@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
17907 #define RELATIVEJUMP_SIZE 5
17908 #define RELATIVECALL_OPCODE 0xe8
17909 #define RELATIVE_ADDR_SIZE 4
17910 -#define MAX_STACK_SIZE 64
17911 -#define MIN_STACK_SIZE(ADDR) \
17912 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
17913 - THREAD_SIZE - (unsigned long)(ADDR))) \
17914 - ? (MAX_STACK_SIZE) \
17915 - : (((unsigned long)current_thread_info()) + \
17916 - THREAD_SIZE - (unsigned long)(ADDR)))
17917 +#define MAX_STACK_SIZE 64UL
17918 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
17919
17920 #define flush_insn_slot(p) do { } while (0)
17921
17922 diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
17923 index 0d47ae1..b0e3ee1 100644
17924 --- a/arch/x86/include/asm/kvm_host.h
17925 +++ b/arch/x86/include/asm/kvm_host.h
17926 @@ -51,6 +51,7 @@
17927 | X86_CR0_NW | X86_CR0_CD | X86_CR0_PG))
17928
17929 #define CR3_L_MODE_RESERVED_BITS 0xFFFFFF0000000000ULL
17930 +#define CR3_PCID_INVD (1UL << 63)
17931 #define CR4_RESERVED_BITS \
17932 (~(unsigned long)(X86_CR4_VME | X86_CR4_PVI | X86_CR4_TSD | X86_CR4_DE\
17933 | X86_CR4_PSE | X86_CR4_PAE | X86_CR4_MCE \
17934 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
17935 index 4ad6560..75c7bdd 100644
17936 --- a/arch/x86/include/asm/local.h
17937 +++ b/arch/x86/include/asm/local.h
17938 @@ -10,33 +10,97 @@ typedef struct {
17939 atomic_long_t a;
17940 } local_t;
17941
17942 +typedef struct {
17943 + atomic_long_unchecked_t a;
17944 +} local_unchecked_t;
17945 +
17946 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
17947
17948 #define local_read(l) atomic_long_read(&(l)->a)
17949 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
17950 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
17951 +#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
17952
17953 static inline void local_inc(local_t *l)
17954 {
17955 - asm volatile(_ASM_INC "%0"
17956 + asm volatile(_ASM_INC "%0\n"
17957 +
17958 +#ifdef CONFIG_PAX_REFCOUNT
17959 + "jno 0f\n"
17960 + _ASM_DEC "%0\n"
17961 + "int $4\n0:\n"
17962 + _ASM_EXTABLE(0b, 0b)
17963 +#endif
17964 +
17965 + : "+m" (l->a.counter));
17966 +}
17967 +
17968 +static inline void local_inc_unchecked(local_unchecked_t *l)
17969 +{
17970 + asm volatile(_ASM_INC "%0\n"
17971 : "+m" (l->a.counter));
17972 }
17973
17974 static inline void local_dec(local_t *l)
17975 {
17976 - asm volatile(_ASM_DEC "%0"
17977 + asm volatile(_ASM_DEC "%0\n"
17978 +
17979 +#ifdef CONFIG_PAX_REFCOUNT
17980 + "jno 0f\n"
17981 + _ASM_INC "%0\n"
17982 + "int $4\n0:\n"
17983 + _ASM_EXTABLE(0b, 0b)
17984 +#endif
17985 +
17986 + : "+m" (l->a.counter));
17987 +}
17988 +
17989 +static inline void local_dec_unchecked(local_unchecked_t *l)
17990 +{
17991 + asm volatile(_ASM_DEC "%0\n"
17992 : "+m" (l->a.counter));
17993 }
17994
17995 static inline void local_add(long i, local_t *l)
17996 {
17997 - asm volatile(_ASM_ADD "%1,%0"
17998 + asm volatile(_ASM_ADD "%1,%0\n"
17999 +
18000 +#ifdef CONFIG_PAX_REFCOUNT
18001 + "jno 0f\n"
18002 + _ASM_SUB "%1,%0\n"
18003 + "int $4\n0:\n"
18004 + _ASM_EXTABLE(0b, 0b)
18005 +#endif
18006 +
18007 + : "+m" (l->a.counter)
18008 + : "ir" (i));
18009 +}
18010 +
18011 +static inline void local_add_unchecked(long i, local_unchecked_t *l)
18012 +{
18013 + asm volatile(_ASM_ADD "%1,%0\n"
18014 : "+m" (l->a.counter)
18015 : "ir" (i));
18016 }
18017
18018 static inline void local_sub(long i, local_t *l)
18019 {
18020 - asm volatile(_ASM_SUB "%1,%0"
18021 + asm volatile(_ASM_SUB "%1,%0\n"
18022 +
18023 +#ifdef CONFIG_PAX_REFCOUNT
18024 + "jno 0f\n"
18025 + _ASM_ADD "%1,%0\n"
18026 + "int $4\n0:\n"
18027 + _ASM_EXTABLE(0b, 0b)
18028 +#endif
18029 +
18030 + : "+m" (l->a.counter)
18031 + : "ir" (i));
18032 +}
18033 +
18034 +static inline void local_sub_unchecked(long i, local_unchecked_t *l)
18035 +{
18036 + asm volatile(_ASM_SUB "%1,%0\n"
18037 : "+m" (l->a.counter)
18038 : "ir" (i));
18039 }
18040 @@ -52,7 +116,7 @@ static inline void local_sub(long i, local_t *l)
18041 */
18042 static inline int local_sub_and_test(long i, local_t *l)
18043 {
18044 - GEN_BINARY_RMWcc(_ASM_SUB, l->a.counter, "er", i, "%0", "e");
18045 + GEN_BINARY_RMWcc(_ASM_SUB, _ASM_ADD, l->a.counter, "er", i, "%0", "e");
18046 }
18047
18048 /**
18049 @@ -65,7 +129,7 @@ static inline int local_sub_and_test(long i, local_t *l)
18050 */
18051 static inline int local_dec_and_test(local_t *l)
18052 {
18053 - GEN_UNARY_RMWcc(_ASM_DEC, l->a.counter, "%0", "e");
18054 + GEN_UNARY_RMWcc(_ASM_DEC, _ASM_INC, l->a.counter, "%0", "e");
18055 }
18056
18057 /**
18058 @@ -78,7 +142,7 @@ static inline int local_dec_and_test(local_t *l)
18059 */
18060 static inline int local_inc_and_test(local_t *l)
18061 {
18062 - GEN_UNARY_RMWcc(_ASM_INC, l->a.counter, "%0", "e");
18063 + GEN_UNARY_RMWcc(_ASM_INC, _ASM_DEC, l->a.counter, "%0", "e");
18064 }
18065
18066 /**
18067 @@ -92,7 +156,7 @@ static inline int local_inc_and_test(local_t *l)
18068 */
18069 static inline int local_add_negative(long i, local_t *l)
18070 {
18071 - GEN_BINARY_RMWcc(_ASM_ADD, l->a.counter, "er", i, "%0", "s");
18072 + GEN_BINARY_RMWcc(_ASM_ADD, _ASM_SUB, l->a.counter, "er", i, "%0", "s");
18073 }
18074
18075 /**
18076 @@ -105,6 +169,30 @@ static inline int local_add_negative(long i, local_t *l)
18077 static inline long local_add_return(long i, local_t *l)
18078 {
18079 long __i = i;
18080 + asm volatile(_ASM_XADD "%0, %1\n"
18081 +
18082 +#ifdef CONFIG_PAX_REFCOUNT
18083 + "jno 0f\n"
18084 + _ASM_MOV "%0,%1\n"
18085 + "int $4\n0:\n"
18086 + _ASM_EXTABLE(0b, 0b)
18087 +#endif
18088 +
18089 + : "+r" (i), "+m" (l->a.counter)
18090 + : : "memory");
18091 + return i + __i;
18092 +}
18093 +
18094 +/**
18095 + * local_add_return_unchecked - add and return
18096 + * @i: integer value to add
18097 + * @l: pointer to type local_unchecked_t
18098 + *
18099 + * Atomically adds @i to @l and returns @i + @l
18100 + */
18101 +static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
18102 +{
18103 + long __i = i;
18104 asm volatile(_ASM_XADD "%0, %1;"
18105 : "+r" (i), "+m" (l->a.counter)
18106 : : "memory");
18107 @@ -121,6 +209,8 @@ static inline long local_sub_return(long i, local_t *l)
18108
18109 #define local_cmpxchg(l, o, n) \
18110 (cmpxchg_local(&((l)->a.counter), (o), (n)))
18111 +#define local_cmpxchg_unchecked(l, o, n) \
18112 + (cmpxchg_local(&((l)->a.counter), (o), (n)))
18113 /* Always has a lock prefix */
18114 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
18115
18116 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
18117 new file mode 100644
18118 index 0000000..2bfd3ba
18119 --- /dev/null
18120 +++ b/arch/x86/include/asm/mman.h
18121 @@ -0,0 +1,15 @@
18122 +#ifndef _X86_MMAN_H
18123 +#define _X86_MMAN_H
18124 +
18125 +#include <uapi/asm/mman.h>
18126 +
18127 +#ifdef __KERNEL__
18128 +#ifndef __ASSEMBLY__
18129 +#ifdef CONFIG_X86_32
18130 +#define arch_mmap_check i386_mmap_check
18131 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
18132 +#endif
18133 +#endif
18134 +#endif
18135 +
18136 +#endif /* X86_MMAN_H */
18137 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
18138 index 876e74e..e20bfb1 100644
18139 --- a/arch/x86/include/asm/mmu.h
18140 +++ b/arch/x86/include/asm/mmu.h
18141 @@ -9,7 +9,7 @@
18142 * we put the segment information here.
18143 */
18144 typedef struct {
18145 - void *ldt;
18146 + struct desc_struct *ldt;
18147 int size;
18148
18149 #ifdef CONFIG_X86_64
18150 @@ -18,7 +18,19 @@ typedef struct {
18151 #endif
18152
18153 struct mutex lock;
18154 - void __user *vdso;
18155 + unsigned long vdso;
18156 +
18157 +#ifdef CONFIG_X86_32
18158 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
18159 + unsigned long user_cs_base;
18160 + unsigned long user_cs_limit;
18161 +
18162 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
18163 + cpumask_t cpu_user_cs_mask;
18164 +#endif
18165 +
18166 +#endif
18167 +#endif
18168 } mm_context_t;
18169
18170 #ifdef CONFIG_SMP
18171 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
18172 index 166af2a..648c200 100644
18173 --- a/arch/x86/include/asm/mmu_context.h
18174 +++ b/arch/x86/include/asm/mmu_context.h
18175 @@ -28,6 +28,20 @@ void destroy_context(struct mm_struct *mm);
18176
18177 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
18178 {
18179 +
18180 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18181 + if (!(static_cpu_has(X86_FEATURE_PCID))) {
18182 + unsigned int i;
18183 + pgd_t *pgd;
18184 +
18185 + pax_open_kernel();
18186 + pgd = get_cpu_pgd(smp_processor_id(), kernel);
18187 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
18188 + set_pgd_batched(pgd+i, native_make_pgd(0));
18189 + pax_close_kernel();
18190 + }
18191 +#endif
18192 +
18193 #ifdef CONFIG_SMP
18194 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
18195 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
18196 @@ -38,16 +52,59 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
18197 struct task_struct *tsk)
18198 {
18199 unsigned cpu = smp_processor_id();
18200 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
18201 + int tlbstate = TLBSTATE_OK;
18202 +#endif
18203
18204 if (likely(prev != next)) {
18205 #ifdef CONFIG_SMP
18206 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
18207 + tlbstate = this_cpu_read(cpu_tlbstate.state);
18208 +#endif
18209 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
18210 this_cpu_write(cpu_tlbstate.active_mm, next);
18211 #endif
18212 cpumask_set_cpu(cpu, mm_cpumask(next));
18213
18214 /* Re-load page tables */
18215 +#ifdef CONFIG_PAX_PER_CPU_PGD
18216 + pax_open_kernel();
18217 +
18218 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18219 + if (static_cpu_has(X86_FEATURE_PCID))
18220 + __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
18221 + else
18222 +#endif
18223 +
18224 + __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
18225 + __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
18226 + pax_close_kernel();
18227 + 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));
18228 +
18229 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18230 + if (static_cpu_has(X86_FEATURE_PCID)) {
18231 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
18232 + u64 descriptor[2];
18233 + descriptor[0] = PCID_USER;
18234 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
18235 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
18236 + descriptor[0] = PCID_KERNEL;
18237 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
18238 + }
18239 + } else {
18240 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
18241 + if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
18242 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
18243 + else
18244 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
18245 + }
18246 + } else
18247 +#endif
18248 +
18249 + load_cr3(get_cpu_pgd(cpu, kernel));
18250 +#else
18251 load_cr3(next->pgd);
18252 +#endif
18253 trace_tlb_flush(TLB_FLUSH_ON_TASK_SWITCH, TLB_FLUSH_ALL);
18254
18255 /* Stop flush ipis for the previous mm */
18256 @@ -56,9 +113,67 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
18257 /* Load the LDT, if the LDT is different: */
18258 if (unlikely(prev->context.ldt != next->context.ldt))
18259 load_LDT_nolock(&next->context);
18260 +
18261 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
18262 + if (!(__supported_pte_mask & _PAGE_NX)) {
18263 + smp_mb__before_atomic();
18264 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
18265 + smp_mb__after_atomic();
18266 + cpu_set(cpu, next->context.cpu_user_cs_mask);
18267 + }
18268 +#endif
18269 +
18270 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
18271 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
18272 + prev->context.user_cs_limit != next->context.user_cs_limit))
18273 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
18274 +#ifdef CONFIG_SMP
18275 + else if (unlikely(tlbstate != TLBSTATE_OK))
18276 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
18277 +#endif
18278 +#endif
18279 +
18280 }
18281 + else {
18282 +
18283 +#ifdef CONFIG_PAX_PER_CPU_PGD
18284 + pax_open_kernel();
18285 +
18286 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18287 + if (static_cpu_has(X86_FEATURE_PCID))
18288 + __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
18289 + else
18290 +#endif
18291 +
18292 + __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
18293 + __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
18294 + pax_close_kernel();
18295 + 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));
18296 +
18297 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18298 + if (static_cpu_has(X86_FEATURE_PCID)) {
18299 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
18300 + u64 descriptor[2];
18301 + descriptor[0] = PCID_USER;
18302 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
18303 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
18304 + descriptor[0] = PCID_KERNEL;
18305 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
18306 + }
18307 + } else {
18308 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
18309 + if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
18310 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
18311 + else
18312 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
18313 + }
18314 + } else
18315 +#endif
18316 +
18317 + load_cr3(get_cpu_pgd(cpu, kernel));
18318 +#endif
18319 +
18320 #ifdef CONFIG_SMP
18321 - else {
18322 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
18323 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
18324
18325 @@ -75,12 +190,29 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
18326 * tlb flush IPI delivery. We must reload CR3
18327 * to make sure to use no freed page tables.
18328 */
18329 +
18330 +#ifndef CONFIG_PAX_PER_CPU_PGD
18331 load_cr3(next->pgd);
18332 trace_tlb_flush(TLB_FLUSH_ON_TASK_SWITCH, TLB_FLUSH_ALL);
18333 +#endif
18334 +
18335 load_LDT_nolock(&next->context);
18336 +
18337 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
18338 + if (!(__supported_pte_mask & _PAGE_NX))
18339 + cpu_set(cpu, next->context.cpu_user_cs_mask);
18340 +#endif
18341 +
18342 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
18343 +#ifdef CONFIG_PAX_PAGEEXEC
18344 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
18345 +#endif
18346 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
18347 +#endif
18348 +
18349 }
18350 +#endif
18351 }
18352 -#endif
18353 }
18354
18355 #define activate_mm(prev, next) \
18356 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
18357 index e3b7819..b257c64 100644
18358 --- a/arch/x86/include/asm/module.h
18359 +++ b/arch/x86/include/asm/module.h
18360 @@ -5,6 +5,7 @@
18361
18362 #ifdef CONFIG_X86_64
18363 /* X86_64 does not define MODULE_PROC_FAMILY */
18364 +#define MODULE_PROC_FAMILY ""
18365 #elif defined CONFIG_M486
18366 #define MODULE_PROC_FAMILY "486 "
18367 #elif defined CONFIG_M586
18368 @@ -57,8 +58,20 @@
18369 #error unknown processor family
18370 #endif
18371
18372 -#ifdef CONFIG_X86_32
18373 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
18374 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
18375 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
18376 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
18377 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
18378 +#else
18379 +#define MODULE_PAX_KERNEXEC ""
18380 #endif
18381
18382 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18383 +#define MODULE_PAX_UDEREF "UDEREF "
18384 +#else
18385 +#define MODULE_PAX_UDEREF ""
18386 +#endif
18387 +
18388 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
18389 +
18390 #endif /* _ASM_X86_MODULE_H */
18391 diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
18392 index 5f2fc44..106caa6 100644
18393 --- a/arch/x86/include/asm/nmi.h
18394 +++ b/arch/x86/include/asm/nmi.h
18395 @@ -36,26 +36,35 @@ enum {
18396
18397 typedef int (*nmi_handler_t)(unsigned int, struct pt_regs *);
18398
18399 +struct nmiaction;
18400 +
18401 +struct nmiwork {
18402 + const struct nmiaction *action;
18403 + u64 max_duration;
18404 + struct irq_work irq_work;
18405 +};
18406 +
18407 struct nmiaction {
18408 struct list_head list;
18409 nmi_handler_t handler;
18410 - u64 max_duration;
18411 - struct irq_work irq_work;
18412 unsigned long flags;
18413 const char *name;
18414 -};
18415 + struct nmiwork *work;
18416 +} __do_const;
18417
18418 #define register_nmi_handler(t, fn, fg, n, init...) \
18419 ({ \
18420 - static struct nmiaction init fn##_na = { \
18421 + static struct nmiwork fn##_nw; \
18422 + static const struct nmiaction init fn##_na = { \
18423 .handler = (fn), \
18424 .name = (n), \
18425 .flags = (fg), \
18426 + .work = &fn##_nw, \
18427 }; \
18428 __register_nmi_handler((t), &fn##_na); \
18429 })
18430
18431 -int __register_nmi_handler(unsigned int, struct nmiaction *);
18432 +int __register_nmi_handler(unsigned int, const struct nmiaction *);
18433
18434 void unregister_nmi_handler(unsigned int, const char *);
18435
18436 diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
18437 index 802dde3..9183e68 100644
18438 --- a/arch/x86/include/asm/page.h
18439 +++ b/arch/x86/include/asm/page.h
18440 @@ -52,6 +52,7 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
18441 __phys_addr_symbol(__phys_reloc_hide((unsigned long)(x)))
18442
18443 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
18444 +#define __early_va(x) ((void *)((unsigned long)(x)+__START_KERNEL_map - phys_base))
18445
18446 #define __boot_va(x) __va(x)
18447 #define __boot_pa(x) __pa(x)
18448 @@ -60,11 +61,21 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
18449 * virt_to_page(kaddr) returns a valid pointer if and only if
18450 * virt_addr_valid(kaddr) returns true.
18451 */
18452 -#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
18453 #define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT)
18454 extern bool __virt_addr_valid(unsigned long kaddr);
18455 #define virt_addr_valid(kaddr) __virt_addr_valid((unsigned long) (kaddr))
18456
18457 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
18458 +#define virt_to_page(kaddr) \
18459 + ({ \
18460 + const void *__kaddr = (const void *)(kaddr); \
18461 + BUG_ON(!virt_addr_valid(__kaddr)); \
18462 + pfn_to_page(__pa(__kaddr) >> PAGE_SHIFT); \
18463 + })
18464 +#else
18465 +#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
18466 +#endif
18467 +
18468 #endif /* __ASSEMBLY__ */
18469
18470 #include <asm-generic/memory_model.h>
18471 diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
18472 index f408caf..4a0455e 100644
18473 --- a/arch/x86/include/asm/page_64.h
18474 +++ b/arch/x86/include/asm/page_64.h
18475 @@ -7,9 +7,9 @@
18476
18477 /* duplicated to the one in bootmem.h */
18478 extern unsigned long max_pfn;
18479 -extern unsigned long phys_base;
18480 +extern const unsigned long phys_base;
18481
18482 -static inline unsigned long __phys_addr_nodebug(unsigned long x)
18483 +static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
18484 {
18485 unsigned long y = x - __START_KERNEL_map;
18486
18487 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
18488 index cd6e1610..70f4418 100644
18489 --- a/arch/x86/include/asm/paravirt.h
18490 +++ b/arch/x86/include/asm/paravirt.h
18491 @@ -560,7 +560,7 @@ static inline pmd_t __pmd(pmdval_t val)
18492 return (pmd_t) { ret };
18493 }
18494
18495 -static inline pmdval_t pmd_val(pmd_t pmd)
18496 +static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
18497 {
18498 pmdval_t ret;
18499
18500 @@ -626,6 +626,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
18501 val);
18502 }
18503
18504 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
18505 +{
18506 + pgdval_t val = native_pgd_val(pgd);
18507 +
18508 + if (sizeof(pgdval_t) > sizeof(long))
18509 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
18510 + val, (u64)val >> 32);
18511 + else
18512 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
18513 + val);
18514 +}
18515 +
18516 static inline void pgd_clear(pgd_t *pgdp)
18517 {
18518 set_pgd(pgdp, __pgd(0));
18519 @@ -710,6 +722,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
18520 pv_mmu_ops.set_fixmap(idx, phys, flags);
18521 }
18522
18523 +#ifdef CONFIG_PAX_KERNEXEC
18524 +static inline unsigned long pax_open_kernel(void)
18525 +{
18526 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
18527 +}
18528 +
18529 +static inline unsigned long pax_close_kernel(void)
18530 +{
18531 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
18532 +}
18533 +#else
18534 +static inline unsigned long pax_open_kernel(void) { return 0; }
18535 +static inline unsigned long pax_close_kernel(void) { return 0; }
18536 +#endif
18537 +
18538 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
18539
18540 static __always_inline void __ticket_lock_spinning(struct arch_spinlock *lock,
18541 @@ -906,7 +933,7 @@ extern void default_banner(void);
18542
18543 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
18544 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
18545 -#define PARA_INDIRECT(addr) *%cs:addr
18546 +#define PARA_INDIRECT(addr) *%ss:addr
18547 #endif
18548
18549 #define INTERRUPT_RETURN \
18550 @@ -981,6 +1008,21 @@ extern void default_banner(void);
18551 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
18552 CLBR_NONE, \
18553 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
18554 +
18555 +#define GET_CR0_INTO_RDI \
18556 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
18557 + mov %rax,%rdi
18558 +
18559 +#define SET_RDI_INTO_CR0 \
18560 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
18561 +
18562 +#define GET_CR3_INTO_RDI \
18563 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
18564 + mov %rax,%rdi
18565 +
18566 +#define SET_RDI_INTO_CR3 \
18567 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
18568 +
18569 #endif /* CONFIG_X86_32 */
18570
18571 #endif /* __ASSEMBLY__ */
18572 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
18573 index 7549b8b..f0edfda 100644
18574 --- a/arch/x86/include/asm/paravirt_types.h
18575 +++ b/arch/x86/include/asm/paravirt_types.h
18576 @@ -84,7 +84,7 @@ struct pv_init_ops {
18577 */
18578 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
18579 unsigned long addr, unsigned len);
18580 -};
18581 +} __no_const __no_randomize_layout;
18582
18583
18584 struct pv_lazy_ops {
18585 @@ -92,13 +92,13 @@ struct pv_lazy_ops {
18586 void (*enter)(void);
18587 void (*leave)(void);
18588 void (*flush)(void);
18589 -};
18590 +} __no_randomize_layout;
18591
18592 struct pv_time_ops {
18593 unsigned long long (*sched_clock)(void);
18594 unsigned long long (*steal_clock)(int cpu);
18595 unsigned long (*get_tsc_khz)(void);
18596 -};
18597 +} __no_const __no_randomize_layout;
18598
18599 struct pv_cpu_ops {
18600 /* hooks for various privileged instructions */
18601 @@ -192,7 +192,7 @@ struct pv_cpu_ops {
18602
18603 void (*start_context_switch)(struct task_struct *prev);
18604 void (*end_context_switch)(struct task_struct *next);
18605 -};
18606 +} __no_const __no_randomize_layout;
18607
18608 struct pv_irq_ops {
18609 /*
18610 @@ -215,7 +215,7 @@ struct pv_irq_ops {
18611 #ifdef CONFIG_X86_64
18612 void (*adjust_exception_frame)(void);
18613 #endif
18614 -};
18615 +} __no_randomize_layout;
18616
18617 struct pv_apic_ops {
18618 #ifdef CONFIG_X86_LOCAL_APIC
18619 @@ -223,7 +223,7 @@ struct pv_apic_ops {
18620 unsigned long start_eip,
18621 unsigned long start_esp);
18622 #endif
18623 -};
18624 +} __no_const __no_randomize_layout;
18625
18626 struct pv_mmu_ops {
18627 unsigned long (*read_cr2)(void);
18628 @@ -313,6 +313,7 @@ struct pv_mmu_ops {
18629 struct paravirt_callee_save make_pud;
18630
18631 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
18632 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
18633 #endif /* PAGETABLE_LEVELS == 4 */
18634 #endif /* PAGETABLE_LEVELS >= 3 */
18635
18636 @@ -324,7 +325,13 @@ struct pv_mmu_ops {
18637 an mfn. We can tell which is which from the index. */
18638 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
18639 phys_addr_t phys, pgprot_t flags);
18640 -};
18641 +
18642 +#ifdef CONFIG_PAX_KERNEXEC
18643 + unsigned long (*pax_open_kernel)(void);
18644 + unsigned long (*pax_close_kernel)(void);
18645 +#endif
18646 +
18647 +} __no_randomize_layout;
18648
18649 struct arch_spinlock;
18650 #ifdef CONFIG_SMP
18651 @@ -336,11 +343,14 @@ typedef u16 __ticket_t;
18652 struct pv_lock_ops {
18653 struct paravirt_callee_save lock_spinning;
18654 void (*unlock_kick)(struct arch_spinlock *lock, __ticket_t ticket);
18655 -};
18656 +} __no_randomize_layout;
18657
18658 /* This contains all the paravirt structures: we get a convenient
18659 * number for each function using the offset which we use to indicate
18660 - * what to patch. */
18661 + * what to patch.
18662 + * shouldn't be randomized due to the "NEAT TRICK" in paravirt.c
18663 + */
18664 +
18665 struct paravirt_patch_template {
18666 struct pv_init_ops pv_init_ops;
18667 struct pv_time_ops pv_time_ops;
18668 @@ -349,7 +359,7 @@ struct paravirt_patch_template {
18669 struct pv_apic_ops pv_apic_ops;
18670 struct pv_mmu_ops pv_mmu_ops;
18671 struct pv_lock_ops pv_lock_ops;
18672 -};
18673 +} __no_randomize_layout;
18674
18675 extern struct pv_info pv_info;
18676 extern struct pv_init_ops pv_init_ops;
18677 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
18678 index c4412e9..90e88c5 100644
18679 --- a/arch/x86/include/asm/pgalloc.h
18680 +++ b/arch/x86/include/asm/pgalloc.h
18681 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
18682 pmd_t *pmd, pte_t *pte)
18683 {
18684 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
18685 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
18686 +}
18687 +
18688 +static inline void pmd_populate_user(struct mm_struct *mm,
18689 + pmd_t *pmd, pte_t *pte)
18690 +{
18691 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
18692 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
18693 }
18694
18695 @@ -108,12 +115,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
18696
18697 #ifdef CONFIG_X86_PAE
18698 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
18699 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
18700 +{
18701 + pud_populate(mm, pudp, pmd);
18702 +}
18703 #else /* !CONFIG_X86_PAE */
18704 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
18705 {
18706 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
18707 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
18708 }
18709 +
18710 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
18711 +{
18712 + paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
18713 + set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
18714 +}
18715 #endif /* CONFIG_X86_PAE */
18716
18717 #if PAGETABLE_LEVELS > 3
18718 @@ -123,6 +140,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
18719 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
18720 }
18721
18722 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
18723 +{
18724 + paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
18725 + set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
18726 +}
18727 +
18728 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
18729 {
18730 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
18731 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
18732 index 206a87f..1623b06 100644
18733 --- a/arch/x86/include/asm/pgtable-2level.h
18734 +++ b/arch/x86/include/asm/pgtable-2level.h
18735 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
18736
18737 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
18738 {
18739 + pax_open_kernel();
18740 *pmdp = pmd;
18741 + pax_close_kernel();
18742 }
18743
18744 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
18745 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
18746 index 81bb91b..9392125 100644
18747 --- a/arch/x86/include/asm/pgtable-3level.h
18748 +++ b/arch/x86/include/asm/pgtable-3level.h
18749 @@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
18750
18751 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
18752 {
18753 + pax_open_kernel();
18754 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
18755 + pax_close_kernel();
18756 }
18757
18758 static inline void native_set_pud(pud_t *pudp, pud_t pud)
18759 {
18760 + pax_open_kernel();
18761 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
18762 + pax_close_kernel();
18763 }
18764
18765 /*
18766 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
18767 index aa97a07..5c53c32 100644
18768 --- a/arch/x86/include/asm/pgtable.h
18769 +++ b/arch/x86/include/asm/pgtable.h
18770 @@ -46,6 +46,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
18771
18772 #ifndef __PAGETABLE_PUD_FOLDED
18773 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
18774 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
18775 #define pgd_clear(pgd) native_pgd_clear(pgd)
18776 #endif
18777
18778 @@ -83,12 +84,53 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
18779
18780 #define arch_end_context_switch(prev) do {} while(0)
18781
18782 +#define pax_open_kernel() native_pax_open_kernel()
18783 +#define pax_close_kernel() native_pax_close_kernel()
18784 #endif /* CONFIG_PARAVIRT */
18785
18786 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
18787 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
18788 +
18789 +#ifdef CONFIG_PAX_KERNEXEC
18790 +static inline unsigned long native_pax_open_kernel(void)
18791 +{
18792 + unsigned long cr0;
18793 +
18794 + preempt_disable();
18795 + barrier();
18796 + cr0 = read_cr0() ^ X86_CR0_WP;
18797 + BUG_ON(cr0 & X86_CR0_WP);
18798 + write_cr0(cr0);
18799 + barrier();
18800 + return cr0 ^ X86_CR0_WP;
18801 +}
18802 +
18803 +static inline unsigned long native_pax_close_kernel(void)
18804 +{
18805 + unsigned long cr0;
18806 +
18807 + barrier();
18808 + cr0 = read_cr0() ^ X86_CR0_WP;
18809 + BUG_ON(!(cr0 & X86_CR0_WP));
18810 + write_cr0(cr0);
18811 + barrier();
18812 + preempt_enable_no_resched();
18813 + return cr0 ^ X86_CR0_WP;
18814 +}
18815 +#else
18816 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
18817 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
18818 +#endif
18819 +
18820 /*
18821 * The following only work if pte_present() is true.
18822 * Undefined behaviour if not..
18823 */
18824 +static inline int pte_user(pte_t pte)
18825 +{
18826 + return pte_val(pte) & _PAGE_USER;
18827 +}
18828 +
18829 static inline int pte_dirty(pte_t pte)
18830 {
18831 return pte_flags(pte) & _PAGE_DIRTY;
18832 @@ -155,6 +197,11 @@ static inline unsigned long pud_pfn(pud_t pud)
18833 return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
18834 }
18835
18836 +static inline unsigned long pgd_pfn(pgd_t pgd)
18837 +{
18838 + return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
18839 +}
18840 +
18841 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
18842
18843 static inline int pmd_large(pmd_t pte)
18844 @@ -208,9 +255,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
18845 return pte_clear_flags(pte, _PAGE_RW);
18846 }
18847
18848 +static inline pte_t pte_mkread(pte_t pte)
18849 +{
18850 + return __pte(pte_val(pte) | _PAGE_USER);
18851 +}
18852 +
18853 static inline pte_t pte_mkexec(pte_t pte)
18854 {
18855 - return pte_clear_flags(pte, _PAGE_NX);
18856 +#ifdef CONFIG_X86_PAE
18857 + if (__supported_pte_mask & _PAGE_NX)
18858 + return pte_clear_flags(pte, _PAGE_NX);
18859 + else
18860 +#endif
18861 + return pte_set_flags(pte, _PAGE_USER);
18862 +}
18863 +
18864 +static inline pte_t pte_exprotect(pte_t pte)
18865 +{
18866 +#ifdef CONFIG_X86_PAE
18867 + if (__supported_pte_mask & _PAGE_NX)
18868 + return pte_set_flags(pte, _PAGE_NX);
18869 + else
18870 +#endif
18871 + return pte_clear_flags(pte, _PAGE_USER);
18872 }
18873
18874 static inline pte_t pte_mkdirty(pte_t pte)
18875 @@ -440,6 +507,16 @@ pte_t *populate_extra_pte(unsigned long vaddr);
18876 #endif
18877
18878 #ifndef __ASSEMBLY__
18879 +
18880 +#ifdef CONFIG_PAX_PER_CPU_PGD
18881 +extern pgd_t cpu_pgd[NR_CPUS][2][PTRS_PER_PGD];
18882 +enum cpu_pgd_type {kernel = 0, user = 1};
18883 +static inline pgd_t *get_cpu_pgd(unsigned int cpu, enum cpu_pgd_type type)
18884 +{
18885 + return cpu_pgd[cpu][type];
18886 +}
18887 +#endif
18888 +
18889 #include <linux/mm_types.h>
18890 #include <linux/mmdebug.h>
18891 #include <linux/log2.h>
18892 @@ -586,7 +663,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
18893 * Currently stuck as a macro due to indirect forward reference to
18894 * linux/mmzone.h's __section_mem_map_addr() definition:
18895 */
18896 -#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
18897 +#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
18898
18899 /* Find an entry in the second-level page table.. */
18900 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
18901 @@ -626,7 +703,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
18902 * Currently stuck as a macro due to indirect forward reference to
18903 * linux/mmzone.h's __section_mem_map_addr() definition:
18904 */
18905 -#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
18906 +#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
18907
18908 /* to find an entry in a page-table-directory. */
18909 static inline unsigned long pud_index(unsigned long address)
18910 @@ -641,7 +718,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
18911
18912 static inline int pgd_bad(pgd_t pgd)
18913 {
18914 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
18915 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
18916 }
18917
18918 static inline int pgd_none(pgd_t pgd)
18919 @@ -664,7 +741,12 @@ static inline int pgd_none(pgd_t pgd)
18920 * pgd_offset() returns a (pgd_t *)
18921 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
18922 */
18923 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
18924 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
18925 +
18926 +#ifdef CONFIG_PAX_PER_CPU_PGD
18927 +#define pgd_offset_cpu(cpu, type, address) (get_cpu_pgd(cpu, type) + pgd_index(address))
18928 +#endif
18929 +
18930 /*
18931 * a shortcut which implies the use of the kernel's pgd, instead
18932 * of a process's
18933 @@ -675,6 +757,23 @@ static inline int pgd_none(pgd_t pgd)
18934 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
18935 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
18936
18937 +#ifdef CONFIG_X86_32
18938 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
18939 +#else
18940 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
18941 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
18942 +
18943 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18944 +#ifdef __ASSEMBLY__
18945 +#define pax_user_shadow_base pax_user_shadow_base(%rip)
18946 +#else
18947 +extern unsigned long pax_user_shadow_base;
18948 +extern pgdval_t clone_pgd_mask;
18949 +#endif
18950 +#endif
18951 +
18952 +#endif
18953 +
18954 #ifndef __ASSEMBLY__
18955
18956 extern int direct_gbpages;
18957 @@ -841,11 +940,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
18958 * dst and src can be on the same page, but the range must not overlap,
18959 * and must not cross a page boundary.
18960 */
18961 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
18962 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
18963 {
18964 - memcpy(dst, src, count * sizeof(pgd_t));
18965 + pax_open_kernel();
18966 + while (count--)
18967 + *dst++ = *src++;
18968 + pax_close_kernel();
18969 }
18970
18971 +#ifdef CONFIG_PAX_PER_CPU_PGD
18972 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
18973 +#endif
18974 +
18975 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18976 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
18977 +#else
18978 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
18979 +#endif
18980 +
18981 #define PTE_SHIFT ilog2(PTRS_PER_PTE)
18982 static inline int page_level_shift(enum pg_level level)
18983 {
18984 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
18985 index 9ee3221..b979c6b 100644
18986 --- a/arch/x86/include/asm/pgtable_32.h
18987 +++ b/arch/x86/include/asm/pgtable_32.h
18988 @@ -25,9 +25,6 @@
18989 struct mm_struct;
18990 struct vm_area_struct;
18991
18992 -extern pgd_t swapper_pg_dir[1024];
18993 -extern pgd_t initial_page_table[1024];
18994 -
18995 static inline void pgtable_cache_init(void) { }
18996 static inline void check_pgt_cache(void) { }
18997 void paging_init(void);
18998 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
18999 # include <asm/pgtable-2level.h>
19000 #endif
19001
19002 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
19003 +extern pgd_t initial_page_table[PTRS_PER_PGD];
19004 +#ifdef CONFIG_X86_PAE
19005 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
19006 +#endif
19007 +
19008 #if defined(CONFIG_HIGHPTE)
19009 #define pte_offset_map(dir, address) \
19010 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
19011 @@ -62,12 +65,17 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
19012 /* Clear a kernel PTE and flush it from the TLB */
19013 #define kpte_clear_flush(ptep, vaddr) \
19014 do { \
19015 + pax_open_kernel(); \
19016 pte_clear(&init_mm, (vaddr), (ptep)); \
19017 + pax_close_kernel(); \
19018 __flush_tlb_one((vaddr)); \
19019 } while (0)
19020
19021 #endif /* !__ASSEMBLY__ */
19022
19023 +#define HAVE_ARCH_UNMAPPED_AREA
19024 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
19025 +
19026 /*
19027 * kern_addr_valid() is (1) for FLATMEM and (0) for
19028 * SPARSEMEM and DISCONTIGMEM
19029 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
19030 index ed5903b..c7fe163 100644
19031 --- a/arch/x86/include/asm/pgtable_32_types.h
19032 +++ b/arch/x86/include/asm/pgtable_32_types.h
19033 @@ -8,7 +8,7 @@
19034 */
19035 #ifdef CONFIG_X86_PAE
19036 # include <asm/pgtable-3level_types.h>
19037 -# define PMD_SIZE (1UL << PMD_SHIFT)
19038 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
19039 # define PMD_MASK (~(PMD_SIZE - 1))
19040 #else
19041 # include <asm/pgtable-2level_types.h>
19042 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
19043 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
19044 #endif
19045
19046 +#ifdef CONFIG_PAX_KERNEXEC
19047 +#ifndef __ASSEMBLY__
19048 +extern unsigned char MODULES_EXEC_VADDR[];
19049 +extern unsigned char MODULES_EXEC_END[];
19050 +#endif
19051 +#include <asm/boot.h>
19052 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
19053 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
19054 +#else
19055 +#define ktla_ktva(addr) (addr)
19056 +#define ktva_ktla(addr) (addr)
19057 +#endif
19058 +
19059 #define MODULES_VADDR VMALLOC_START
19060 #define MODULES_END VMALLOC_END
19061 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
19062 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
19063 index 3874693..d7906ac 100644
19064 --- a/arch/x86/include/asm/pgtable_64.h
19065 +++ b/arch/x86/include/asm/pgtable_64.h
19066 @@ -16,11 +16,16 @@
19067
19068 extern pud_t level3_kernel_pgt[512];
19069 extern pud_t level3_ident_pgt[512];
19070 +extern pud_t level3_vmalloc_start_pgt[512];
19071 +extern pud_t level3_vmalloc_end_pgt[512];
19072 +extern pud_t level3_vmemmap_pgt[512];
19073 +extern pud_t level2_vmemmap_pgt[512];
19074 extern pmd_t level2_kernel_pgt[512];
19075 extern pmd_t level2_fixmap_pgt[512];
19076 -extern pmd_t level2_ident_pgt[512];
19077 +extern pmd_t level2_ident_pgt[512*2];
19078 extern pte_t level1_fixmap_pgt[512];
19079 -extern pgd_t init_level4_pgt[];
19080 +extern pte_t level1_vsyscall_pgt[512];
19081 +extern pgd_t init_level4_pgt[512];
19082
19083 #define swapper_pg_dir init_level4_pgt
19084
19085 @@ -62,7 +67,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
19086
19087 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
19088 {
19089 + pax_open_kernel();
19090 *pmdp = pmd;
19091 + pax_close_kernel();
19092 }
19093
19094 static inline void native_pmd_clear(pmd_t *pmd)
19095 @@ -98,7 +105,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
19096
19097 static inline void native_set_pud(pud_t *pudp, pud_t pud)
19098 {
19099 + pax_open_kernel();
19100 *pudp = pud;
19101 + pax_close_kernel();
19102 }
19103
19104 static inline void native_pud_clear(pud_t *pud)
19105 @@ -108,6 +117,13 @@ static inline void native_pud_clear(pud_t *pud)
19106
19107 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
19108 {
19109 + pax_open_kernel();
19110 + *pgdp = pgd;
19111 + pax_close_kernel();
19112 +}
19113 +
19114 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
19115 +{
19116 *pgdp = pgd;
19117 }
19118
19119 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
19120 index 7166e25..baaa6fe 100644
19121 --- a/arch/x86/include/asm/pgtable_64_types.h
19122 +++ b/arch/x86/include/asm/pgtable_64_types.h
19123 @@ -61,9 +61,14 @@ typedef struct { pteval_t pte; } pte_t;
19124 #define MODULES_VADDR (__START_KERNEL_map + KERNEL_IMAGE_SIZE)
19125 #define MODULES_END _AC(0xffffffffff000000, UL)
19126 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
19127 +#define MODULES_EXEC_VADDR MODULES_VADDR
19128 +#define MODULES_EXEC_END MODULES_END
19129 #define ESPFIX_PGD_ENTRY _AC(-2, UL)
19130 #define ESPFIX_BASE_ADDR (ESPFIX_PGD_ENTRY << PGDIR_SHIFT)
19131
19132 +#define ktla_ktva(addr) (addr)
19133 +#define ktva_ktla(addr) (addr)
19134 +
19135 #define EARLY_DYNAMIC_PAGE_TABLES 64
19136
19137 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
19138 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
19139 index f216963..6bd7c21 100644
19140 --- a/arch/x86/include/asm/pgtable_types.h
19141 +++ b/arch/x86/include/asm/pgtable_types.h
19142 @@ -111,8 +111,10 @@
19143
19144 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
19145 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
19146 -#else
19147 +#elif defined(CONFIG_KMEMCHECK) || defined(CONFIG_MEM_SOFT_DIRTY)
19148 #define _PAGE_NX (_AT(pteval_t, 0))
19149 +#else
19150 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
19151 #endif
19152
19153 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
19154 @@ -151,6 +153,9 @@
19155 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
19156 _PAGE_ACCESSED)
19157
19158 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
19159 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
19160 +
19161 #define __PAGE_KERNEL_EXEC \
19162 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
19163 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
19164 @@ -161,7 +166,7 @@
19165 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
19166 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
19167 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
19168 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
19169 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
19170 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
19171 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
19172 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
19173 @@ -218,7 +223,7 @@
19174 #ifdef CONFIG_X86_64
19175 #define __PAGE_KERNEL_IDENT_LARGE_EXEC __PAGE_KERNEL_LARGE_EXEC
19176 #else
19177 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
19178 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
19179 #define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
19180 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
19181 #endif
19182 @@ -257,7 +262,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
19183 {
19184 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
19185 }
19186 +#endif
19187
19188 +#if PAGETABLE_LEVELS == 3
19189 +#include <asm-generic/pgtable-nopud.h>
19190 +#endif
19191 +
19192 +#if PAGETABLE_LEVELS == 2
19193 +#include <asm-generic/pgtable-nopmd.h>
19194 +#endif
19195 +
19196 +#ifndef __ASSEMBLY__
19197 #if PAGETABLE_LEVELS > 3
19198 typedef struct { pudval_t pud; } pud_t;
19199
19200 @@ -271,8 +286,6 @@ static inline pudval_t native_pud_val(pud_t pud)
19201 return pud.pud;
19202 }
19203 #else
19204 -#include <asm-generic/pgtable-nopud.h>
19205 -
19206 static inline pudval_t native_pud_val(pud_t pud)
19207 {
19208 return native_pgd_val(pud.pgd);
19209 @@ -292,8 +305,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
19210 return pmd.pmd;
19211 }
19212 #else
19213 -#include <asm-generic/pgtable-nopmd.h>
19214 -
19215 static inline pmdval_t native_pmd_val(pmd_t pmd)
19216 {
19217 return native_pgd_val(pmd.pud.pgd);
19218 @@ -333,7 +344,6 @@ typedef struct page *pgtable_t;
19219
19220 extern pteval_t __supported_pte_mask;
19221 extern void set_nx(void);
19222 -extern int nx_enabled;
19223
19224 #define pgprot_writecombine pgprot_writecombine
19225 extern pgprot_t pgprot_writecombine(pgprot_t prot);
19226 diff --git a/arch/x86/include/asm/preempt.h b/arch/x86/include/asm/preempt.h
19227 index 7024c12..71c46b9 100644
19228 --- a/arch/x86/include/asm/preempt.h
19229 +++ b/arch/x86/include/asm/preempt.h
19230 @@ -87,7 +87,7 @@ static __always_inline void __preempt_count_sub(int val)
19231 */
19232 static __always_inline bool __preempt_count_dec_and_test(void)
19233 {
19234 - GEN_UNARY_RMWcc("decl", __preempt_count, __percpu_arg(0), "e");
19235 + GEN_UNARY_RMWcc("decl", "incl", __preempt_count, __percpu_arg(0), "e");
19236 }
19237
19238 /*
19239 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
19240 index eb71ec7..f06532a 100644
19241 --- a/arch/x86/include/asm/processor.h
19242 +++ b/arch/x86/include/asm/processor.h
19243 @@ -127,7 +127,7 @@ struct cpuinfo_x86 {
19244 /* Index into per_cpu list: */
19245 u16 cpu_index;
19246 u32 microcode;
19247 -} __attribute__((__aligned__(SMP_CACHE_BYTES)));
19248 +} __attribute__((__aligned__(SMP_CACHE_BYTES))) __randomize_layout;
19249
19250 #define X86_VENDOR_INTEL 0
19251 #define X86_VENDOR_CYRIX 1
19252 @@ -198,9 +198,21 @@ static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
19253 : "memory");
19254 }
19255
19256 +/* invpcid (%rdx),%rax */
19257 +#define __ASM_INVPCID ".byte 0x66,0x0f,0x38,0x82,0x02"
19258 +
19259 +#define INVPCID_SINGLE_ADDRESS 0UL
19260 +#define INVPCID_SINGLE_CONTEXT 1UL
19261 +#define INVPCID_ALL_GLOBAL 2UL
19262 +#define INVPCID_ALL_NONGLOBAL 3UL
19263 +
19264 +#define PCID_KERNEL 0UL
19265 +#define PCID_USER 1UL
19266 +#define PCID_NOFLUSH (1UL << 63)
19267 +
19268 static inline void load_cr3(pgd_t *pgdir)
19269 {
19270 - write_cr3(__pa(pgdir));
19271 + write_cr3(__pa(pgdir) | PCID_KERNEL);
19272 }
19273
19274 #ifdef CONFIG_X86_32
19275 @@ -282,7 +294,7 @@ struct tss_struct {
19276
19277 } ____cacheline_aligned;
19278
19279 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
19280 +extern struct tss_struct init_tss[NR_CPUS];
19281
19282 /*
19283 * Save the original ist values for checking stack pointers during debugging
19284 @@ -478,6 +490,7 @@ struct thread_struct {
19285 unsigned short ds;
19286 unsigned short fsindex;
19287 unsigned short gsindex;
19288 + unsigned short ss;
19289 #endif
19290 #ifdef CONFIG_X86_32
19291 unsigned long ip;
19292 @@ -587,29 +600,8 @@ static inline void load_sp0(struct tss_struct *tss,
19293 extern unsigned long mmu_cr4_features;
19294 extern u32 *trampoline_cr4_features;
19295
19296 -static inline void set_in_cr4(unsigned long mask)
19297 -{
19298 - unsigned long cr4;
19299 -
19300 - mmu_cr4_features |= mask;
19301 - if (trampoline_cr4_features)
19302 - *trampoline_cr4_features = mmu_cr4_features;
19303 - cr4 = read_cr4();
19304 - cr4 |= mask;
19305 - write_cr4(cr4);
19306 -}
19307 -
19308 -static inline void clear_in_cr4(unsigned long mask)
19309 -{
19310 - unsigned long cr4;
19311 -
19312 - mmu_cr4_features &= ~mask;
19313 - if (trampoline_cr4_features)
19314 - *trampoline_cr4_features = mmu_cr4_features;
19315 - cr4 = read_cr4();
19316 - cr4 &= ~mask;
19317 - write_cr4(cr4);
19318 -}
19319 +extern void set_in_cr4(unsigned long mask);
19320 +extern void clear_in_cr4(unsigned long mask);
19321
19322 typedef struct {
19323 unsigned long seg;
19324 @@ -837,11 +829,18 @@ static inline void spin_lock_prefetch(const void *x)
19325 */
19326 #define TASK_SIZE PAGE_OFFSET
19327 #define TASK_SIZE_MAX TASK_SIZE
19328 +
19329 +#ifdef CONFIG_PAX_SEGMEXEC
19330 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
19331 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
19332 +#else
19333 #define STACK_TOP TASK_SIZE
19334 -#define STACK_TOP_MAX STACK_TOP
19335 +#endif
19336 +
19337 +#define STACK_TOP_MAX TASK_SIZE
19338
19339 #define INIT_THREAD { \
19340 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
19341 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
19342 .vm86_info = NULL, \
19343 .sysenter_cs = __KERNEL_CS, \
19344 .io_bitmap_ptr = NULL, \
19345 @@ -855,7 +854,7 @@ static inline void spin_lock_prefetch(const void *x)
19346 */
19347 #define INIT_TSS { \
19348 .x86_tss = { \
19349 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
19350 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
19351 .ss0 = __KERNEL_DS, \
19352 .ss1 = __KERNEL_CS, \
19353 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
19354 @@ -866,11 +865,7 @@ static inline void spin_lock_prefetch(const void *x)
19355 extern unsigned long thread_saved_pc(struct task_struct *tsk);
19356
19357 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
19358 -#define KSTK_TOP(info) \
19359 -({ \
19360 - unsigned long *__ptr = (unsigned long *)(info); \
19361 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
19362 -})
19363 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
19364
19365 /*
19366 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
19367 @@ -885,7 +880,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
19368 #define task_pt_regs(task) \
19369 ({ \
19370 struct pt_regs *__regs__; \
19371 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
19372 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
19373 __regs__ - 1; \
19374 })
19375
19376 @@ -895,13 +890,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
19377 /*
19378 * User space process size. 47bits minus one guard page.
19379 */
19380 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
19381 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
19382
19383 /* This decides where the kernel will search for a free chunk of vm
19384 * space during mmap's.
19385 */
19386 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
19387 - 0xc0000000 : 0xFFFFe000)
19388 + 0xc0000000 : 0xFFFFf000)
19389
19390 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
19391 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
19392 @@ -912,11 +907,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
19393 #define STACK_TOP_MAX TASK_SIZE_MAX
19394
19395 #define INIT_THREAD { \
19396 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
19397 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
19398 }
19399
19400 #define INIT_TSS { \
19401 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
19402 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
19403 }
19404
19405 /*
19406 @@ -944,6 +939,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
19407 */
19408 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
19409
19410 +#ifdef CONFIG_PAX_SEGMEXEC
19411 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
19412 +#endif
19413 +
19414 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
19415
19416 /* Get/set a process' ability to use the timestamp counter instruction */
19417 @@ -970,7 +969,7 @@ static inline uint32_t hypervisor_cpuid_base(const char *sig, uint32_t leaves)
19418 return 0;
19419 }
19420
19421 -extern unsigned long arch_align_stack(unsigned long sp);
19422 +#define arch_align_stack(x) ((x) & ~0xfUL)
19423 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
19424
19425 void default_idle(void);
19426 @@ -980,6 +979,6 @@ bool xen_set_default_idle(void);
19427 #define xen_set_default_idle 0
19428 #endif
19429
19430 -void stop_this_cpu(void *dummy);
19431 +void stop_this_cpu(void *dummy) __noreturn;
19432 void df_debug(struct pt_regs *regs, long error_code);
19433 #endif /* _ASM_X86_PROCESSOR_H */
19434 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
19435 index 6205f0c..688a3a9 100644
19436 --- a/arch/x86/include/asm/ptrace.h
19437 +++ b/arch/x86/include/asm/ptrace.h
19438 @@ -84,28 +84,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
19439 }
19440
19441 /*
19442 - * user_mode_vm(regs) determines whether a register set came from user mode.
19443 + * user_mode(regs) determines whether a register set came from user mode.
19444 * This is true if V8086 mode was enabled OR if the register set was from
19445 * protected mode with RPL-3 CS value. This tricky test checks that with
19446 * one comparison. Many places in the kernel can bypass this full check
19447 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
19448 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
19449 + * be used.
19450 */
19451 -static inline int user_mode(struct pt_regs *regs)
19452 +static inline int user_mode_novm(struct pt_regs *regs)
19453 {
19454 #ifdef CONFIG_X86_32
19455 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
19456 #else
19457 - return !!(regs->cs & 3);
19458 + return !!(regs->cs & SEGMENT_RPL_MASK);
19459 #endif
19460 }
19461
19462 -static inline int user_mode_vm(struct pt_regs *regs)
19463 +static inline int user_mode(struct pt_regs *regs)
19464 {
19465 #ifdef CONFIG_X86_32
19466 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
19467 USER_RPL;
19468 #else
19469 - return user_mode(regs);
19470 + return user_mode_novm(regs);
19471 #endif
19472 }
19473
19474 @@ -121,15 +122,16 @@ static inline int v8086_mode(struct pt_regs *regs)
19475 #ifdef CONFIG_X86_64
19476 static inline bool user_64bit_mode(struct pt_regs *regs)
19477 {
19478 + unsigned long cs = regs->cs & 0xffff;
19479 #ifndef CONFIG_PARAVIRT
19480 /*
19481 * On non-paravirt systems, this is the only long mode CPL 3
19482 * selector. We do not allow long mode selectors in the LDT.
19483 */
19484 - return regs->cs == __USER_CS;
19485 + return cs == __USER_CS;
19486 #else
19487 /* Headers are too twisted for this to go in paravirt.h. */
19488 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
19489 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
19490 #endif
19491 }
19492
19493 @@ -180,9 +182,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
19494 * Traps from the kernel do not save sp and ss.
19495 * Use the helper function to retrieve sp.
19496 */
19497 - if (offset == offsetof(struct pt_regs, sp) &&
19498 - regs->cs == __KERNEL_CS)
19499 - return kernel_stack_pointer(regs);
19500 + if (offset == offsetof(struct pt_regs, sp)) {
19501 + unsigned long cs = regs->cs & 0xffff;
19502 + if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
19503 + return kernel_stack_pointer(regs);
19504 + }
19505 #endif
19506 return *(unsigned long *)((unsigned long)regs + offset);
19507 }
19508 diff --git a/arch/x86/include/asm/qrwlock.h b/arch/x86/include/asm/qrwlock.h
19509 index ae0e241..e80b10b 100644
19510 --- a/arch/x86/include/asm/qrwlock.h
19511 +++ b/arch/x86/include/asm/qrwlock.h
19512 @@ -7,8 +7,8 @@
19513 #define queue_write_unlock queue_write_unlock
19514 static inline void queue_write_unlock(struct qrwlock *lock)
19515 {
19516 - barrier();
19517 - ACCESS_ONCE(*(u8 *)&lock->cnts) = 0;
19518 + barrier();
19519 + ACCESS_ONCE_RW(*(u8 *)&lock->cnts) = 0;
19520 }
19521 #endif
19522
19523 diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
19524 index 9c6b890..5305f53 100644
19525 --- a/arch/x86/include/asm/realmode.h
19526 +++ b/arch/x86/include/asm/realmode.h
19527 @@ -22,16 +22,14 @@ struct real_mode_header {
19528 #endif
19529 /* APM/BIOS reboot */
19530 u32 machine_real_restart_asm;
19531 -#ifdef CONFIG_X86_64
19532 u32 machine_real_restart_seg;
19533 -#endif
19534 };
19535
19536 /* This must match data at trampoline_32/64.S */
19537 struct trampoline_header {
19538 #ifdef CONFIG_X86_32
19539 u32 start;
19540 - u16 gdt_pad;
19541 + u16 boot_cs;
19542 u16 gdt_limit;
19543 u32 gdt_base;
19544 #else
19545 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
19546 index a82c4f1..ac45053 100644
19547 --- a/arch/x86/include/asm/reboot.h
19548 +++ b/arch/x86/include/asm/reboot.h
19549 @@ -6,13 +6,13 @@
19550 struct pt_regs;
19551
19552 struct machine_ops {
19553 - void (*restart)(char *cmd);
19554 - void (*halt)(void);
19555 - void (*power_off)(void);
19556 + void (* __noreturn restart)(char *cmd);
19557 + void (* __noreturn halt)(void);
19558 + void (* __noreturn power_off)(void);
19559 void (*shutdown)(void);
19560 void (*crash_shutdown)(struct pt_regs *);
19561 - void (*emergency_restart)(void);
19562 -};
19563 + void (* __noreturn emergency_restart)(void);
19564 +} __no_const;
19565
19566 extern struct machine_ops machine_ops;
19567
19568 diff --git a/arch/x86/include/asm/rmwcc.h b/arch/x86/include/asm/rmwcc.h
19569 index 8f7866a..e442f20 100644
19570 --- a/arch/x86/include/asm/rmwcc.h
19571 +++ b/arch/x86/include/asm/rmwcc.h
19572 @@ -3,7 +3,34 @@
19573
19574 #ifdef CC_HAVE_ASM_GOTO
19575
19576 -#define __GEN_RMWcc(fullop, var, cc, ...) \
19577 +#ifdef CONFIG_PAX_REFCOUNT
19578 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
19579 +do { \
19580 + asm_volatile_goto (fullop \
19581 + ";jno 0f\n" \
19582 + fullantiop \
19583 + ";int $4\n0:\n" \
19584 + _ASM_EXTABLE(0b, 0b) \
19585 + ";j" cc " %l[cc_label]" \
19586 + : : "m" (var), ## __VA_ARGS__ \
19587 + : "memory" : cc_label); \
19588 + return 0; \
19589 +cc_label: \
19590 + return 1; \
19591 +} while (0)
19592 +#else
19593 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
19594 +do { \
19595 + asm_volatile_goto (fullop ";j" cc " %l[cc_label]" \
19596 + : : "m" (var), ## __VA_ARGS__ \
19597 + : "memory" : cc_label); \
19598 + return 0; \
19599 +cc_label: \
19600 + return 1; \
19601 +} while (0)
19602 +#endif
19603 +
19604 +#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
19605 do { \
19606 asm_volatile_goto (fullop "; j" cc " %l[cc_label]" \
19607 : : "m" (var), ## __VA_ARGS__ \
19608 @@ -13,15 +40,46 @@ cc_label: \
19609 return 1; \
19610 } while (0)
19611
19612 -#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
19613 - __GEN_RMWcc(op " " arg0, var, cc)
19614 +#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
19615 + __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
19616
19617 -#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
19618 - __GEN_RMWcc(op " %1, " arg0, var, cc, vcon (val))
19619 +#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
19620 + __GEN_RMWcc_unchecked(op " " arg0, var, cc)
19621 +
19622 +#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
19623 + __GEN_RMWcc(op " %1, " arg0, antiop " %1, " arg0, var, cc, vcon (val))
19624 +
19625 +#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
19626 + __GEN_RMWcc_unchecked(op " %1, " arg0, var, cc, vcon (val))
19627
19628 #else /* !CC_HAVE_ASM_GOTO */
19629
19630 -#define __GEN_RMWcc(fullop, var, cc, ...) \
19631 +#ifdef CONFIG_PAX_REFCOUNT
19632 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
19633 +do { \
19634 + char c; \
19635 + asm volatile (fullop \
19636 + ";jno 0f\n" \
19637 + fullantiop \
19638 + ";int $4\n0:\n" \
19639 + _ASM_EXTABLE(0b, 0b) \
19640 + "; set" cc " %1" \
19641 + : "+m" (var), "=qm" (c) \
19642 + : __VA_ARGS__ : "memory"); \
19643 + return c != 0; \
19644 +} while (0)
19645 +#else
19646 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
19647 +do { \
19648 + char c; \
19649 + asm volatile (fullop "; set" cc " %1" \
19650 + : "+m" (var), "=qm" (c) \
19651 + : __VA_ARGS__ : "memory"); \
19652 + return c != 0; \
19653 +} while (0)
19654 +#endif
19655 +
19656 +#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
19657 do { \
19658 char c; \
19659 asm volatile (fullop "; set" cc " %1" \
19660 @@ -30,11 +88,17 @@ do { \
19661 return c != 0; \
19662 } while (0)
19663
19664 -#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
19665 - __GEN_RMWcc(op " " arg0, var, cc)
19666 +#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
19667 + __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
19668 +
19669 +#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
19670 + __GEN_RMWcc_unchecked(op " " arg0, var, cc)
19671 +
19672 +#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
19673 + __GEN_RMWcc(op " %2, " arg0, antiop " %2, " arg0, var, cc, vcon (val))
19674
19675 -#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
19676 - __GEN_RMWcc(op " %2, " arg0, var, cc, vcon (val))
19677 +#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
19678 + __GEN_RMWcc_unchecked(op " %2, " arg0, var, cc, vcon (val))
19679
19680 #endif /* CC_HAVE_ASM_GOTO */
19681
19682 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
19683 index cad82c9..2e5c5c1 100644
19684 --- a/arch/x86/include/asm/rwsem.h
19685 +++ b/arch/x86/include/asm/rwsem.h
19686 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
19687 {
19688 asm volatile("# beginning down_read\n\t"
19689 LOCK_PREFIX _ASM_INC "(%1)\n\t"
19690 +
19691 +#ifdef CONFIG_PAX_REFCOUNT
19692 + "jno 0f\n"
19693 + LOCK_PREFIX _ASM_DEC "(%1)\n"
19694 + "int $4\n0:\n"
19695 + _ASM_EXTABLE(0b, 0b)
19696 +#endif
19697 +
19698 /* adds 0x00000001 */
19699 " jns 1f\n"
19700 " call call_rwsem_down_read_failed\n"
19701 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
19702 "1:\n\t"
19703 " mov %1,%2\n\t"
19704 " add %3,%2\n\t"
19705 +
19706 +#ifdef CONFIG_PAX_REFCOUNT
19707 + "jno 0f\n"
19708 + "sub %3,%2\n"
19709 + "int $4\n0:\n"
19710 + _ASM_EXTABLE(0b, 0b)
19711 +#endif
19712 +
19713 " jle 2f\n\t"
19714 LOCK_PREFIX " cmpxchg %2,%0\n\t"
19715 " jnz 1b\n\t"
19716 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
19717 long tmp;
19718 asm volatile("# beginning down_write\n\t"
19719 LOCK_PREFIX " xadd %1,(%2)\n\t"
19720 +
19721 +#ifdef CONFIG_PAX_REFCOUNT
19722 + "jno 0f\n"
19723 + "mov %1,(%2)\n"
19724 + "int $4\n0:\n"
19725 + _ASM_EXTABLE(0b, 0b)
19726 +#endif
19727 +
19728 /* adds 0xffff0001, returns the old value */
19729 " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
19730 /* was the active mask 0 before? */
19731 @@ -155,6 +179,14 @@ static inline void __up_read(struct rw_semaphore *sem)
19732 long tmp;
19733 asm volatile("# beginning __up_read\n\t"
19734 LOCK_PREFIX " xadd %1,(%2)\n\t"
19735 +
19736 +#ifdef CONFIG_PAX_REFCOUNT
19737 + "jno 0f\n"
19738 + "mov %1,(%2)\n"
19739 + "int $4\n0:\n"
19740 + _ASM_EXTABLE(0b, 0b)
19741 +#endif
19742 +
19743 /* subtracts 1, returns the old value */
19744 " jns 1f\n\t"
19745 " call call_rwsem_wake\n" /* expects old value in %edx */
19746 @@ -173,6 +205,14 @@ static inline void __up_write(struct rw_semaphore *sem)
19747 long tmp;
19748 asm volatile("# beginning __up_write\n\t"
19749 LOCK_PREFIX " xadd %1,(%2)\n\t"
19750 +
19751 +#ifdef CONFIG_PAX_REFCOUNT
19752 + "jno 0f\n"
19753 + "mov %1,(%2)\n"
19754 + "int $4\n0:\n"
19755 + _ASM_EXTABLE(0b, 0b)
19756 +#endif
19757 +
19758 /* subtracts 0xffff0001, returns the old value */
19759 " jns 1f\n\t"
19760 " call call_rwsem_wake\n" /* expects old value in %edx */
19761 @@ -190,6 +230,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
19762 {
19763 asm volatile("# beginning __downgrade_write\n\t"
19764 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
19765 +
19766 +#ifdef CONFIG_PAX_REFCOUNT
19767 + "jno 0f\n"
19768 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
19769 + "int $4\n0:\n"
19770 + _ASM_EXTABLE(0b, 0b)
19771 +#endif
19772 +
19773 /*
19774 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
19775 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
19776 @@ -208,7 +256,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
19777 */
19778 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
19779 {
19780 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
19781 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
19782 +
19783 +#ifdef CONFIG_PAX_REFCOUNT
19784 + "jno 0f\n"
19785 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
19786 + "int $4\n0:\n"
19787 + _ASM_EXTABLE(0b, 0b)
19788 +#endif
19789 +
19790 : "+m" (sem->count)
19791 : "er" (delta));
19792 }
19793 @@ -218,7 +274,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
19794 */
19795 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
19796 {
19797 - return delta + xadd(&sem->count, delta);
19798 + return delta + xadd_check_overflow(&sem->count, delta);
19799 }
19800
19801 #endif /* __KERNEL__ */
19802 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
19803 index 6f1c3a8..7744f19 100644
19804 --- a/arch/x86/include/asm/segment.h
19805 +++ b/arch/x86/include/asm/segment.h
19806 @@ -64,10 +64,15 @@
19807 * 26 - ESPFIX small SS
19808 * 27 - per-cpu [ offset to per-cpu data area ]
19809 * 28 - stack_canary-20 [ for stack protector ]
19810 - * 29 - unused
19811 - * 30 - unused
19812 + * 29 - PCI BIOS CS
19813 + * 30 - PCI BIOS DS
19814 * 31 - TSS for double fault handler
19815 */
19816 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
19817 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
19818 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
19819 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
19820 +
19821 #define GDT_ENTRY_TLS_MIN 6
19822 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
19823
19824 @@ -79,6 +84,8 @@
19825
19826 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
19827
19828 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
19829 +
19830 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
19831
19832 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
19833 @@ -104,6 +111,12 @@
19834 #define __KERNEL_STACK_CANARY 0
19835 #endif
19836
19837 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
19838 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
19839 +
19840 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
19841 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
19842 +
19843 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
19844
19845 /*
19846 @@ -141,7 +154,7 @@
19847 */
19848
19849 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
19850 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
19851 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
19852
19853
19854 #else
19855 @@ -165,6 +178,8 @@
19856 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
19857 #define __USER32_DS __USER_DS
19858
19859 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
19860 +
19861 #define GDT_ENTRY_TSS 8 /* needs two entries */
19862 #define GDT_ENTRY_LDT 10 /* needs two entries */
19863 #define GDT_ENTRY_TLS_MIN 12
19864 @@ -173,6 +188,8 @@
19865 #define GDT_ENTRY_PER_CPU 15 /* Abused to load per CPU data from limit */
19866 #define __PER_CPU_SEG (GDT_ENTRY_PER_CPU * 8 + 3)
19867
19868 +#define GDT_ENTRY_UDEREF_KERNEL_DS 16
19869 +
19870 /* TLS indexes for 64bit - hardcoded in arch_prctl */
19871 #define FS_TLS 0
19872 #define GS_TLS 1
19873 @@ -180,12 +197,14 @@
19874 #define GS_TLS_SEL ((GDT_ENTRY_TLS_MIN+GS_TLS)*8 + 3)
19875 #define FS_TLS_SEL ((GDT_ENTRY_TLS_MIN+FS_TLS)*8 + 3)
19876
19877 -#define GDT_ENTRIES 16
19878 +#define GDT_ENTRIES 17
19879
19880 #endif
19881
19882 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
19883 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
19884 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
19885 +#define __UDEREF_KERNEL_DS (GDT_ENTRY_UDEREF_KERNEL_DS*8)
19886 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
19887 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
19888 #ifndef CONFIG_PARAVIRT
19889 @@ -268,7 +287,7 @@ static inline unsigned long get_limit(unsigned long segment)
19890 {
19891 unsigned long __limit;
19892 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
19893 - return __limit + 1;
19894 + return __limit;
19895 }
19896
19897 #endif /* !__ASSEMBLY__ */
19898 diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h
19899 index 8d3120f..352b440 100644
19900 --- a/arch/x86/include/asm/smap.h
19901 +++ b/arch/x86/include/asm/smap.h
19902 @@ -25,11 +25,40 @@
19903
19904 #include <asm/alternative-asm.h>
19905
19906 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19907 +#define ASM_PAX_OPEN_USERLAND \
19908 + 661: jmp 663f; \
19909 + .pushsection .altinstr_replacement, "a" ; \
19910 + 662: pushq %rax; nop; \
19911 + .popsection ; \
19912 + .pushsection .altinstructions, "a" ; \
19913 + altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
19914 + .popsection ; \
19915 + call __pax_open_userland; \
19916 + popq %rax; \
19917 + 663:
19918 +
19919 +#define ASM_PAX_CLOSE_USERLAND \
19920 + 661: jmp 663f; \
19921 + .pushsection .altinstr_replacement, "a" ; \
19922 + 662: pushq %rax; nop; \
19923 + .popsection; \
19924 + .pushsection .altinstructions, "a" ; \
19925 + altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
19926 + .popsection; \
19927 + call __pax_close_userland; \
19928 + popq %rax; \
19929 + 663:
19930 +#else
19931 +#define ASM_PAX_OPEN_USERLAND
19932 +#define ASM_PAX_CLOSE_USERLAND
19933 +#endif
19934 +
19935 #ifdef CONFIG_X86_SMAP
19936
19937 #define ASM_CLAC \
19938 661: ASM_NOP3 ; \
19939 - .pushsection .altinstr_replacement, "ax" ; \
19940 + .pushsection .altinstr_replacement, "a" ; \
19941 662: __ASM_CLAC ; \
19942 .popsection ; \
19943 .pushsection .altinstructions, "a" ; \
19944 @@ -38,7 +67,7 @@
19945
19946 #define ASM_STAC \
19947 661: ASM_NOP3 ; \
19948 - .pushsection .altinstr_replacement, "ax" ; \
19949 + .pushsection .altinstr_replacement, "a" ; \
19950 662: __ASM_STAC ; \
19951 .popsection ; \
19952 .pushsection .altinstructions, "a" ; \
19953 @@ -56,6 +85,37 @@
19954
19955 #include <asm/alternative.h>
19956
19957 +#define __HAVE_ARCH_PAX_OPEN_USERLAND
19958 +#define __HAVE_ARCH_PAX_CLOSE_USERLAND
19959 +
19960 +extern void __pax_open_userland(void);
19961 +static __always_inline unsigned long pax_open_userland(void)
19962 +{
19963 +
19964 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19965 + asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[open]", X86_FEATURE_STRONGUDEREF)
19966 + :
19967 + : [open] "i" (__pax_open_userland)
19968 + : "memory", "rax");
19969 +#endif
19970 +
19971 + return 0;
19972 +}
19973 +
19974 +extern void __pax_close_userland(void);
19975 +static __always_inline unsigned long pax_close_userland(void)
19976 +{
19977 +
19978 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19979 + asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[close]", X86_FEATURE_STRONGUDEREF)
19980 + :
19981 + : [close] "i" (__pax_close_userland)
19982 + : "memory", "rax");
19983 +#endif
19984 +
19985 + return 0;
19986 +}
19987 +
19988 #ifdef CONFIG_X86_SMAP
19989
19990 static __always_inline void clac(void)
19991 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
19992 index 8cd27e0..7f05ec8 100644
19993 --- a/arch/x86/include/asm/smp.h
19994 +++ b/arch/x86/include/asm/smp.h
19995 @@ -35,7 +35,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
19996 /* cpus sharing the last level cache: */
19997 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
19998 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
19999 -DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
20000 +DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
20001
20002 static inline struct cpumask *cpu_sibling_mask(int cpu)
20003 {
20004 @@ -78,7 +78,7 @@ struct smp_ops {
20005
20006 void (*send_call_func_ipi)(const struct cpumask *mask);
20007 void (*send_call_func_single_ipi)(int cpu);
20008 -};
20009 +} __no_const;
20010
20011 /* Globals due to paravirt */
20012 extern void set_cpu_sibling_map(int cpu);
20013 @@ -190,14 +190,8 @@ extern unsigned disabled_cpus;
20014 extern int safe_smp_processor_id(void);
20015
20016 #elif defined(CONFIG_X86_64_SMP)
20017 -#define raw_smp_processor_id() (this_cpu_read(cpu_number))
20018 -
20019 -#define stack_smp_processor_id() \
20020 -({ \
20021 - struct thread_info *ti; \
20022 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
20023 - ti->cpu; \
20024 -})
20025 +#define raw_smp_processor_id() (this_cpu_read(cpu_number))
20026 +#define stack_smp_processor_id() raw_smp_processor_id()
20027 #define safe_smp_processor_id() smp_processor_id()
20028
20029 #endif
20030 diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
20031 index 54f1c80..39362a5 100644
20032 --- a/arch/x86/include/asm/spinlock.h
20033 +++ b/arch/x86/include/asm/spinlock.h
20034 @@ -223,6 +223,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
20035 static inline void arch_read_lock(arch_rwlock_t *rw)
20036 {
20037 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
20038 +
20039 +#ifdef CONFIG_PAX_REFCOUNT
20040 + "jno 0f\n"
20041 + LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
20042 + "int $4\n0:\n"
20043 + _ASM_EXTABLE(0b, 0b)
20044 +#endif
20045 +
20046 "jns 1f\n"
20047 "call __read_lock_failed\n\t"
20048 "1:\n"
20049 @@ -232,6 +240,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
20050 static inline void arch_write_lock(arch_rwlock_t *rw)
20051 {
20052 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
20053 +
20054 +#ifdef CONFIG_PAX_REFCOUNT
20055 + "jno 0f\n"
20056 + LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
20057 + "int $4\n0:\n"
20058 + _ASM_EXTABLE(0b, 0b)
20059 +#endif
20060 +
20061 "jz 1f\n"
20062 "call __write_lock_failed\n\t"
20063 "1:\n"
20064 @@ -261,13 +277,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
20065
20066 static inline void arch_read_unlock(arch_rwlock_t *rw)
20067 {
20068 - asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
20069 + asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
20070 +
20071 +#ifdef CONFIG_PAX_REFCOUNT
20072 + "jno 0f\n"
20073 + LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
20074 + "int $4\n0:\n"
20075 + _ASM_EXTABLE(0b, 0b)
20076 +#endif
20077 +
20078 :"+m" (rw->lock) : : "memory");
20079 }
20080
20081 static inline void arch_write_unlock(arch_rwlock_t *rw)
20082 {
20083 - asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
20084 + asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
20085 +
20086 +#ifdef CONFIG_PAX_REFCOUNT
20087 + "jno 0f\n"
20088 + LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
20089 + "int $4\n0:\n"
20090 + _ASM_EXTABLE(0b, 0b)
20091 +#endif
20092 +
20093 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
20094 }
20095 #else
20096 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
20097 index 6a99859..03cb807 100644
20098 --- a/arch/x86/include/asm/stackprotector.h
20099 +++ b/arch/x86/include/asm/stackprotector.h
20100 @@ -47,7 +47,7 @@
20101 * head_32 for boot CPU and setup_per_cpu_areas() for others.
20102 */
20103 #define GDT_STACK_CANARY_INIT \
20104 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
20105 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
20106
20107 /*
20108 * Initialize the stackprotector canary value.
20109 @@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
20110
20111 static inline void load_stack_canary_segment(void)
20112 {
20113 -#ifdef CONFIG_X86_32
20114 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
20115 asm volatile ("mov %0, %%gs" : : "r" (0));
20116 #endif
20117 }
20118 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
20119 index 70bbe39..4ae2bd4 100644
20120 --- a/arch/x86/include/asm/stacktrace.h
20121 +++ b/arch/x86/include/asm/stacktrace.h
20122 @@ -11,28 +11,20 @@
20123
20124 extern int kstack_depth_to_print;
20125
20126 -struct thread_info;
20127 +struct task_struct;
20128 struct stacktrace_ops;
20129
20130 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
20131 - unsigned long *stack,
20132 - unsigned long bp,
20133 - const struct stacktrace_ops *ops,
20134 - void *data,
20135 - unsigned long *end,
20136 - int *graph);
20137 +typedef unsigned long walk_stack_t(struct task_struct *task,
20138 + void *stack_start,
20139 + unsigned long *stack,
20140 + unsigned long bp,
20141 + const struct stacktrace_ops *ops,
20142 + void *data,
20143 + unsigned long *end,
20144 + int *graph);
20145
20146 -extern unsigned long
20147 -print_context_stack(struct thread_info *tinfo,
20148 - unsigned long *stack, unsigned long bp,
20149 - const struct stacktrace_ops *ops, void *data,
20150 - unsigned long *end, int *graph);
20151 -
20152 -extern unsigned long
20153 -print_context_stack_bp(struct thread_info *tinfo,
20154 - unsigned long *stack, unsigned long bp,
20155 - const struct stacktrace_ops *ops, void *data,
20156 - unsigned long *end, int *graph);
20157 +extern walk_stack_t print_context_stack;
20158 +extern walk_stack_t print_context_stack_bp;
20159
20160 /* Generic stack tracer with callbacks */
20161
20162 @@ -40,7 +32,7 @@ struct stacktrace_ops {
20163 void (*address)(void *data, unsigned long address, int reliable);
20164 /* On negative return stop dumping */
20165 int (*stack)(void *data, char *name);
20166 - walk_stack_t walk_stack;
20167 + walk_stack_t *walk_stack;
20168 };
20169
20170 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
20171 diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
20172 index d7f3b3b..3cc39f1 100644
20173 --- a/arch/x86/include/asm/switch_to.h
20174 +++ b/arch/x86/include/asm/switch_to.h
20175 @@ -108,7 +108,7 @@ do { \
20176 "call __switch_to\n\t" \
20177 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
20178 __switch_canary \
20179 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
20180 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
20181 "movq %%rax,%%rdi\n\t" \
20182 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
20183 "jnz ret_from_fork\n\t" \
20184 @@ -119,7 +119,7 @@ do { \
20185 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
20186 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
20187 [_tif_fork] "i" (_TIF_FORK), \
20188 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
20189 + [thread_info] "m" (current_tinfo), \
20190 [current_task] "m" (current_task) \
20191 __switch_canary_iparam \
20192 : "memory", "cc" __EXTRA_CLOBBER)
20193 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
20194 index 547e344..6be1175 100644
20195 --- a/arch/x86/include/asm/thread_info.h
20196 +++ b/arch/x86/include/asm/thread_info.h
20197 @@ -24,7 +24,6 @@ struct exec_domain;
20198 #include <linux/atomic.h>
20199
20200 struct thread_info {
20201 - struct task_struct *task; /* main task structure */
20202 struct exec_domain *exec_domain; /* execution domain */
20203 __u32 flags; /* low level flags */
20204 __u32 status; /* thread synchronous flags */
20205 @@ -33,13 +32,13 @@ struct thread_info {
20206 mm_segment_t addr_limit;
20207 struct restart_block restart_block;
20208 void __user *sysenter_return;
20209 + unsigned long lowest_stack;
20210 unsigned int sig_on_uaccess_error:1;
20211 unsigned int uaccess_err:1; /* uaccess failed */
20212 };
20213
20214 -#define INIT_THREAD_INFO(tsk) \
20215 +#define INIT_THREAD_INFO \
20216 { \
20217 - .task = &tsk, \
20218 .exec_domain = &default_exec_domain, \
20219 .flags = 0, \
20220 .cpu = 0, \
20221 @@ -50,7 +49,7 @@ struct thread_info {
20222 }, \
20223 }
20224
20225 -#define init_thread_info (init_thread_union.thread_info)
20226 +#define init_thread_info (init_thread_union.stack)
20227 #define init_stack (init_thread_union.stack)
20228
20229 #else /* !__ASSEMBLY__ */
20230 @@ -91,6 +90,7 @@ struct thread_info {
20231 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
20232 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
20233 #define TIF_X32 30 /* 32-bit native x86-64 binary */
20234 +#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
20235
20236 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
20237 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
20238 @@ -115,17 +115,18 @@ struct thread_info {
20239 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
20240 #define _TIF_ADDR32 (1 << TIF_ADDR32)
20241 #define _TIF_X32 (1 << TIF_X32)
20242 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
20243
20244 /* work to do in syscall_trace_enter() */
20245 #define _TIF_WORK_SYSCALL_ENTRY \
20246 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
20247 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
20248 - _TIF_NOHZ)
20249 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
20250
20251 /* work to do in syscall_trace_leave() */
20252 #define _TIF_WORK_SYSCALL_EXIT \
20253 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
20254 - _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
20255 + _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
20256
20257 /* work to do on interrupt/exception return */
20258 #define _TIF_WORK_MASK \
20259 @@ -136,7 +137,7 @@ struct thread_info {
20260 /* work to do on any return to user space */
20261 #define _TIF_ALLWORK_MASK \
20262 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
20263 - _TIF_NOHZ)
20264 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
20265
20266 /* Only used for 64 bit */
20267 #define _TIF_DO_NOTIFY_MASK \
20268 @@ -151,7 +152,6 @@ struct thread_info {
20269 #define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW)
20270
20271 #define STACK_WARN (THREAD_SIZE/8)
20272 -#define KERNEL_STACK_OFFSET (5*(BITS_PER_LONG/8))
20273
20274 /*
20275 * macros/functions for gaining access to the thread information structure
20276 @@ -162,26 +162,18 @@ struct thread_info {
20277
20278 DECLARE_PER_CPU(unsigned long, kernel_stack);
20279
20280 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
20281 +
20282 static inline struct thread_info *current_thread_info(void)
20283 {
20284 - struct thread_info *ti;
20285 - ti = (void *)(this_cpu_read_stable(kernel_stack) +
20286 - KERNEL_STACK_OFFSET - THREAD_SIZE);
20287 - return ti;
20288 + return this_cpu_read_stable(current_tinfo);
20289 }
20290
20291 #else /* !__ASSEMBLY__ */
20292
20293 /* how to get the thread information struct from ASM */
20294 #define GET_THREAD_INFO(reg) \
20295 - _ASM_MOV PER_CPU_VAR(kernel_stack),reg ; \
20296 - _ASM_SUB $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg ;
20297 -
20298 -/*
20299 - * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
20300 - * a certain register (to be used in assembler memory operands).
20301 - */
20302 -#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
20303 + _ASM_MOV PER_CPU_VAR(current_tinfo),reg ;
20304
20305 #endif
20306
20307 @@ -237,5 +229,12 @@ static inline bool is_ia32_task(void)
20308 extern void arch_task_cache_init(void);
20309 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
20310 extern void arch_release_task_struct(struct task_struct *tsk);
20311 +
20312 +#define __HAVE_THREAD_FUNCTIONS
20313 +#define task_thread_info(task) (&(task)->tinfo)
20314 +#define task_stack_page(task) ((task)->stack)
20315 +#define setup_thread_stack(p, org) do {} while (0)
20316 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
20317 +
20318 #endif
20319 #endif /* _ASM_X86_THREAD_INFO_H */
20320 diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
20321 index 04905bf..1178cdf 100644
20322 --- a/arch/x86/include/asm/tlbflush.h
20323 +++ b/arch/x86/include/asm/tlbflush.h
20324 @@ -17,18 +17,44 @@
20325
20326 static inline void __native_flush_tlb(void)
20327 {
20328 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
20329 + u64 descriptor[2];
20330 +
20331 + descriptor[0] = PCID_KERNEL;
20332 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_NONGLOBAL) : "memory");
20333 + return;
20334 + }
20335 +
20336 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20337 + if (static_cpu_has(X86_FEATURE_PCID)) {
20338 + unsigned int cpu = raw_get_cpu();
20339 +
20340 + native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
20341 + native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
20342 + raw_put_cpu_no_resched();
20343 + return;
20344 + }
20345 +#endif
20346 +
20347 native_write_cr3(native_read_cr3());
20348 }
20349
20350 static inline void __native_flush_tlb_global_irq_disabled(void)
20351 {
20352 - unsigned long cr4;
20353 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
20354 + u64 descriptor[2];
20355
20356 - cr4 = native_read_cr4();
20357 - /* clear PGE */
20358 - native_write_cr4(cr4 & ~X86_CR4_PGE);
20359 - /* write old PGE again and flush TLBs */
20360 - native_write_cr4(cr4);
20361 + descriptor[0] = PCID_KERNEL;
20362 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_GLOBAL) : "memory");
20363 + } else {
20364 + unsigned long cr4;
20365 +
20366 + cr4 = native_read_cr4();
20367 + /* clear PGE */
20368 + native_write_cr4(cr4 & ~X86_CR4_PGE);
20369 + /* write old PGE again and flush TLBs */
20370 + native_write_cr4(cr4);
20371 + }
20372 }
20373
20374 static inline void __native_flush_tlb_global(void)
20375 @@ -49,6 +75,41 @@ static inline void __native_flush_tlb_global(void)
20376
20377 static inline void __native_flush_tlb_single(unsigned long addr)
20378 {
20379 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
20380 + u64 descriptor[2];
20381 +
20382 + descriptor[0] = PCID_KERNEL;
20383 + descriptor[1] = addr;
20384 +
20385 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20386 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) || addr >= TASK_SIZE_MAX) {
20387 + if (addr < TASK_SIZE_MAX)
20388 + descriptor[1] += pax_user_shadow_base;
20389 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
20390 + }
20391 +
20392 + descriptor[0] = PCID_USER;
20393 + descriptor[1] = addr;
20394 +#endif
20395 +
20396 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
20397 + return;
20398 + }
20399 +
20400 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20401 + if (static_cpu_has(X86_FEATURE_PCID)) {
20402 + unsigned int cpu = raw_get_cpu();
20403 +
20404 + native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
20405 + asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
20406 + native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
20407 + raw_put_cpu_no_resched();
20408 +
20409 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) && addr < TASK_SIZE_MAX)
20410 + addr += pax_user_shadow_base;
20411 + }
20412 +#endif
20413 +
20414 asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
20415 }
20416
20417 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
20418 index 0d592e0..526f797 100644
20419 --- a/arch/x86/include/asm/uaccess.h
20420 +++ b/arch/x86/include/asm/uaccess.h
20421 @@ -7,6 +7,7 @@
20422 #include <linux/compiler.h>
20423 #include <linux/thread_info.h>
20424 #include <linux/string.h>
20425 +#include <linux/spinlock.h>
20426 #include <asm/asm.h>
20427 #include <asm/page.h>
20428 #include <asm/smap.h>
20429 @@ -29,7 +30,12 @@
20430
20431 #define get_ds() (KERNEL_DS)
20432 #define get_fs() (current_thread_info()->addr_limit)
20433 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20434 +void __set_fs(mm_segment_t x);
20435 +void set_fs(mm_segment_t x);
20436 +#else
20437 #define set_fs(x) (current_thread_info()->addr_limit = (x))
20438 +#endif
20439
20440 #define segment_eq(a, b) ((a).seg == (b).seg)
20441
20442 @@ -85,8 +91,36 @@ static inline bool __chk_range_not_ok(unsigned long addr, unsigned long size, un
20443 * checks that the pointer is in the user space range - after calling
20444 * this function, memory access functions may still return -EFAULT.
20445 */
20446 -#define access_ok(type, addr, size) \
20447 - likely(!__range_not_ok(addr, size, user_addr_max()))
20448 +extern int _cond_resched(void);
20449 +#define access_ok_noprefault(type, addr, size) (likely(!__range_not_ok(addr, size, user_addr_max())))
20450 +#define access_ok(type, addr, size) \
20451 +({ \
20452 + unsigned long __size = size; \
20453 + unsigned long __addr = (unsigned long)addr; \
20454 + bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
20455 + if (__ret_ao && __size) { \
20456 + unsigned long __addr_ao = __addr & PAGE_MASK; \
20457 + unsigned long __end_ao = __addr + __size - 1; \
20458 + if (unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
20459 + while (__addr_ao <= __end_ao) { \
20460 + char __c_ao; \
20461 + __addr_ao += PAGE_SIZE; \
20462 + if (__size > PAGE_SIZE) \
20463 + _cond_resched(); \
20464 + if (__get_user(__c_ao, (char __user *)__addr)) \
20465 + break; \
20466 + if (type != VERIFY_WRITE) { \
20467 + __addr = __addr_ao; \
20468 + continue; \
20469 + } \
20470 + if (__put_user(__c_ao, (char __user *)__addr)) \
20471 + break; \
20472 + __addr = __addr_ao; \
20473 + } \
20474 + } \
20475 + } \
20476 + __ret_ao; \
20477 +})
20478
20479 /*
20480 * The exception table consists of pairs of addresses relative to the
20481 @@ -176,10 +210,12 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
20482 register __inttype(*(ptr)) __val_gu asm("%"_ASM_DX); \
20483 __chk_user_ptr(ptr); \
20484 might_fault(); \
20485 + pax_open_userland(); \
20486 asm volatile("call __get_user_%P3" \
20487 : "=a" (__ret_gu), "=r" (__val_gu) \
20488 : "0" (ptr), "i" (sizeof(*(ptr)))); \
20489 (x) = (__typeof__(*(ptr))) __val_gu; \
20490 + pax_close_userland(); \
20491 __ret_gu; \
20492 })
20493
20494 @@ -187,13 +223,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
20495 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
20496 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
20497
20498 -
20499 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20500 +#define __copyuser_seg "gs;"
20501 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
20502 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
20503 +#else
20504 +#define __copyuser_seg
20505 +#define __COPYUSER_SET_ES
20506 +#define __COPYUSER_RESTORE_ES
20507 +#endif
20508
20509 #ifdef CONFIG_X86_32
20510 #define __put_user_asm_u64(x, addr, err, errret) \
20511 asm volatile(ASM_STAC "\n" \
20512 - "1: movl %%eax,0(%2)\n" \
20513 - "2: movl %%edx,4(%2)\n" \
20514 + "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
20515 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
20516 "3: " ASM_CLAC "\n" \
20517 ".section .fixup,\"ax\"\n" \
20518 "4: movl %3,%0\n" \
20519 @@ -206,8 +250,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
20520
20521 #define __put_user_asm_ex_u64(x, addr) \
20522 asm volatile(ASM_STAC "\n" \
20523 - "1: movl %%eax,0(%1)\n" \
20524 - "2: movl %%edx,4(%1)\n" \
20525 + "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
20526 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
20527 "3: " ASM_CLAC "\n" \
20528 _ASM_EXTABLE_EX(1b, 2b) \
20529 _ASM_EXTABLE_EX(2b, 3b) \
20530 @@ -257,7 +301,8 @@ extern void __put_user_8(void);
20531 __typeof__(*(ptr)) __pu_val; \
20532 __chk_user_ptr(ptr); \
20533 might_fault(); \
20534 - __pu_val = x; \
20535 + __pu_val = (x); \
20536 + pax_open_userland(); \
20537 switch (sizeof(*(ptr))) { \
20538 case 1: \
20539 __put_user_x(1, __pu_val, ptr, __ret_pu); \
20540 @@ -275,6 +320,7 @@ extern void __put_user_8(void);
20541 __put_user_x(X, __pu_val, ptr, __ret_pu); \
20542 break; \
20543 } \
20544 + pax_close_userland(); \
20545 __ret_pu; \
20546 })
20547
20548 @@ -355,8 +401,10 @@ do { \
20549 } while (0)
20550
20551 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
20552 +do { \
20553 + pax_open_userland(); \
20554 asm volatile(ASM_STAC "\n" \
20555 - "1: mov"itype" %2,%"rtype"1\n" \
20556 + "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
20557 "2: " ASM_CLAC "\n" \
20558 ".section .fixup,\"ax\"\n" \
20559 "3: mov %3,%0\n" \
20560 @@ -364,8 +412,10 @@ do { \
20561 " jmp 2b\n" \
20562 ".previous\n" \
20563 _ASM_EXTABLE(1b, 3b) \
20564 - : "=r" (err), ltype(x) \
20565 - : "m" (__m(addr)), "i" (errret), "0" (err))
20566 + : "=r" (err), ltype (x) \
20567 + : "m" (__m(addr)), "i" (errret), "0" (err)); \
20568 + pax_close_userland(); \
20569 +} while (0)
20570
20571 #define __get_user_size_ex(x, ptr, size) \
20572 do { \
20573 @@ -389,7 +439,7 @@ do { \
20574 } while (0)
20575
20576 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
20577 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
20578 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
20579 "2:\n" \
20580 _ASM_EXTABLE_EX(1b, 2b) \
20581 : ltype(x) : "m" (__m(addr)))
20582 @@ -406,13 +456,24 @@ do { \
20583 int __gu_err; \
20584 unsigned long __gu_val; \
20585 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
20586 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
20587 + (x) = (__typeof__(*(ptr)))__gu_val; \
20588 __gu_err; \
20589 })
20590
20591 /* FIXME: this hack is definitely wrong -AK */
20592 struct __large_struct { unsigned long buf[100]; };
20593 -#define __m(x) (*(struct __large_struct __user *)(x))
20594 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20595 +#define ____m(x) \
20596 +({ \
20597 + unsigned long ____x = (unsigned long)(x); \
20598 + if (____x < pax_user_shadow_base) \
20599 + ____x += pax_user_shadow_base; \
20600 + (typeof(x))____x; \
20601 +})
20602 +#else
20603 +#define ____m(x) (x)
20604 +#endif
20605 +#define __m(x) (*(struct __large_struct __user *)____m(x))
20606
20607 /*
20608 * Tell gcc we read from memory instead of writing: this is because
20609 @@ -420,8 +481,10 @@ struct __large_struct { unsigned long buf[100]; };
20610 * aliasing issues.
20611 */
20612 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
20613 +do { \
20614 + pax_open_userland(); \
20615 asm volatile(ASM_STAC "\n" \
20616 - "1: mov"itype" %"rtype"1,%2\n" \
20617 + "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
20618 "2: " ASM_CLAC "\n" \
20619 ".section .fixup,\"ax\"\n" \
20620 "3: mov %3,%0\n" \
20621 @@ -429,10 +492,12 @@ struct __large_struct { unsigned long buf[100]; };
20622 ".previous\n" \
20623 _ASM_EXTABLE(1b, 3b) \
20624 : "=r"(err) \
20625 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
20626 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err));\
20627 + pax_close_userland(); \
20628 +} while (0)
20629
20630 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
20631 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
20632 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
20633 "2:\n" \
20634 _ASM_EXTABLE_EX(1b, 2b) \
20635 : : ltype(x), "m" (__m(addr)))
20636 @@ -442,11 +507,13 @@ struct __large_struct { unsigned long buf[100]; };
20637 */
20638 #define uaccess_try do { \
20639 current_thread_info()->uaccess_err = 0; \
20640 + pax_open_userland(); \
20641 stac(); \
20642 barrier();
20643
20644 #define uaccess_catch(err) \
20645 clac(); \
20646 + pax_close_userland(); \
20647 (err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0); \
20648 } while (0)
20649
20650 @@ -471,8 +538,12 @@ struct __large_struct { unsigned long buf[100]; };
20651 * On error, the variable @x is set to zero.
20652 */
20653
20654 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20655 +#define __get_user(x, ptr) get_user((x), (ptr))
20656 +#else
20657 #define __get_user(x, ptr) \
20658 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
20659 +#endif
20660
20661 /**
20662 * __put_user: - Write a simple value into user space, with less checking.
20663 @@ -494,8 +565,12 @@ struct __large_struct { unsigned long buf[100]; };
20664 * Returns zero on success, or -EFAULT on error.
20665 */
20666
20667 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20668 +#define __put_user(x, ptr) put_user((x), (ptr))
20669 +#else
20670 #define __put_user(x, ptr) \
20671 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
20672 +#endif
20673
20674 #define __get_user_unaligned __get_user
20675 #define __put_user_unaligned __put_user
20676 @@ -513,7 +588,7 @@ struct __large_struct { unsigned long buf[100]; };
20677 #define get_user_ex(x, ptr) do { \
20678 unsigned long __gue_val; \
20679 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
20680 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
20681 + (x) = (__typeof__(*(ptr)))__gue_val; \
20682 } while (0)
20683
20684 #define put_user_try uaccess_try
20685 @@ -542,18 +617,19 @@ extern void __cmpxchg_wrong_size(void)
20686 __typeof__(ptr) __uval = (uval); \
20687 __typeof__(*(ptr)) __old = (old); \
20688 __typeof__(*(ptr)) __new = (new); \
20689 + pax_open_userland(); \
20690 switch (size) { \
20691 case 1: \
20692 { \
20693 asm volatile("\t" ASM_STAC "\n" \
20694 - "1:\t" LOCK_PREFIX "cmpxchgb %4, %2\n" \
20695 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgb %4, %2\n"\
20696 "2:\t" ASM_CLAC "\n" \
20697 "\t.section .fixup, \"ax\"\n" \
20698 "3:\tmov %3, %0\n" \
20699 "\tjmp 2b\n" \
20700 "\t.previous\n" \
20701 _ASM_EXTABLE(1b, 3b) \
20702 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
20703 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
20704 : "i" (-EFAULT), "q" (__new), "1" (__old) \
20705 : "memory" \
20706 ); \
20707 @@ -562,14 +638,14 @@ extern void __cmpxchg_wrong_size(void)
20708 case 2: \
20709 { \
20710 asm volatile("\t" ASM_STAC "\n" \
20711 - "1:\t" LOCK_PREFIX "cmpxchgw %4, %2\n" \
20712 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgw %4, %2\n"\
20713 "2:\t" ASM_CLAC "\n" \
20714 "\t.section .fixup, \"ax\"\n" \
20715 "3:\tmov %3, %0\n" \
20716 "\tjmp 2b\n" \
20717 "\t.previous\n" \
20718 _ASM_EXTABLE(1b, 3b) \
20719 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
20720 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
20721 : "i" (-EFAULT), "r" (__new), "1" (__old) \
20722 : "memory" \
20723 ); \
20724 @@ -578,14 +654,14 @@ extern void __cmpxchg_wrong_size(void)
20725 case 4: \
20726 { \
20727 asm volatile("\t" ASM_STAC "\n" \
20728 - "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n" \
20729 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"\
20730 "2:\t" ASM_CLAC "\n" \
20731 "\t.section .fixup, \"ax\"\n" \
20732 "3:\tmov %3, %0\n" \
20733 "\tjmp 2b\n" \
20734 "\t.previous\n" \
20735 _ASM_EXTABLE(1b, 3b) \
20736 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
20737 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
20738 : "i" (-EFAULT), "r" (__new), "1" (__old) \
20739 : "memory" \
20740 ); \
20741 @@ -597,14 +673,14 @@ extern void __cmpxchg_wrong_size(void)
20742 __cmpxchg_wrong_size(); \
20743 \
20744 asm volatile("\t" ASM_STAC "\n" \
20745 - "1:\t" LOCK_PREFIX "cmpxchgq %4, %2\n" \
20746 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgq %4, %2\n"\
20747 "2:\t" ASM_CLAC "\n" \
20748 "\t.section .fixup, \"ax\"\n" \
20749 "3:\tmov %3, %0\n" \
20750 "\tjmp 2b\n" \
20751 "\t.previous\n" \
20752 _ASM_EXTABLE(1b, 3b) \
20753 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
20754 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
20755 : "i" (-EFAULT), "r" (__new), "1" (__old) \
20756 : "memory" \
20757 ); \
20758 @@ -613,6 +689,7 @@ extern void __cmpxchg_wrong_size(void)
20759 default: \
20760 __cmpxchg_wrong_size(); \
20761 } \
20762 + pax_close_userland(); \
20763 *__uval = __old; \
20764 __ret; \
20765 })
20766 @@ -636,17 +713,6 @@ extern struct movsl_mask {
20767
20768 #define ARCH_HAS_NOCACHE_UACCESS 1
20769
20770 -#ifdef CONFIG_X86_32
20771 -# include <asm/uaccess_32.h>
20772 -#else
20773 -# include <asm/uaccess_64.h>
20774 -#endif
20775 -
20776 -unsigned long __must_check _copy_from_user(void *to, const void __user *from,
20777 - unsigned n);
20778 -unsigned long __must_check _copy_to_user(void __user *to, const void *from,
20779 - unsigned n);
20780 -
20781 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
20782 # define copy_user_diag __compiletime_error
20783 #else
20784 @@ -656,7 +722,7 @@ unsigned long __must_check _copy_to_user(void __user *to, const void *from,
20785 extern void copy_user_diag("copy_from_user() buffer size is too small")
20786 copy_from_user_overflow(void);
20787 extern void copy_user_diag("copy_to_user() buffer size is too small")
20788 -copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
20789 +copy_to_user_overflow(void);
20790
20791 #undef copy_user_diag
20792
20793 @@ -669,7 +735,7 @@ __copy_from_user_overflow(void) __asm__("copy_from_user_overflow");
20794
20795 extern void
20796 __compiletime_warning("copy_to_user() buffer size is not provably correct")
20797 -__copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
20798 +__copy_to_user_overflow(void) __asm__("copy_to_user_overflow");
20799 #define __copy_to_user_overflow(size, count) __copy_to_user_overflow()
20800
20801 #else
20802 @@ -684,10 +750,16 @@ __copy_from_user_overflow(int size, unsigned long count)
20803
20804 #endif
20805
20806 +#ifdef CONFIG_X86_32
20807 +# include <asm/uaccess_32.h>
20808 +#else
20809 +# include <asm/uaccess_64.h>
20810 +#endif
20811 +
20812 static inline unsigned long __must_check
20813 copy_from_user(void *to, const void __user *from, unsigned long n)
20814 {
20815 - int sz = __compiletime_object_size(to);
20816 + size_t sz = __compiletime_object_size(to);
20817
20818 might_fault();
20819
20820 @@ -709,12 +781,15 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
20821 * case, and do only runtime checking for non-constant sizes.
20822 */
20823
20824 - if (likely(sz < 0 || sz >= n))
20825 - n = _copy_from_user(to, from, n);
20826 - else if(__builtin_constant_p(n))
20827 - copy_from_user_overflow();
20828 - else
20829 - __copy_from_user_overflow(sz, n);
20830 + if (likely(sz != (size_t)-1 && sz < n)) {
20831 + if(__builtin_constant_p(n))
20832 + copy_from_user_overflow();
20833 + else
20834 + __copy_from_user_overflow(sz, n);
20835 + } else if (access_ok(VERIFY_READ, from, n))
20836 + n = __copy_from_user(to, from, n);
20837 + else if ((long)n > 0)
20838 + memset(to, 0, n);
20839
20840 return n;
20841 }
20842 @@ -722,17 +797,18 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
20843 static inline unsigned long __must_check
20844 copy_to_user(void __user *to, const void *from, unsigned long n)
20845 {
20846 - int sz = __compiletime_object_size(from);
20847 + size_t sz = __compiletime_object_size(from);
20848
20849 might_fault();
20850
20851 /* See the comment in copy_from_user() above. */
20852 - if (likely(sz < 0 || sz >= n))
20853 - n = _copy_to_user(to, from, n);
20854 - else if(__builtin_constant_p(n))
20855 - copy_to_user_overflow();
20856 - else
20857 - __copy_to_user_overflow(sz, n);
20858 + if (likely(sz != (size_t)-1 && sz < n)) {
20859 + if(__builtin_constant_p(n))
20860 + copy_to_user_overflow();
20861 + else
20862 + __copy_to_user_overflow(sz, n);
20863 + } else if (access_ok(VERIFY_WRITE, to, n))
20864 + n = __copy_to_user(to, from, n);
20865
20866 return n;
20867 }
20868 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
20869 index 3c03a5d..1071638 100644
20870 --- a/arch/x86/include/asm/uaccess_32.h
20871 +++ b/arch/x86/include/asm/uaccess_32.h
20872 @@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
20873 static __always_inline unsigned long __must_check
20874 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
20875 {
20876 + if ((long)n < 0)
20877 + return n;
20878 +
20879 + check_object_size(from, n, true);
20880 +
20881 if (__builtin_constant_p(n)) {
20882 unsigned long ret;
20883
20884 @@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
20885 __copy_to_user(void __user *to, const void *from, unsigned long n)
20886 {
20887 might_fault();
20888 +
20889 return __copy_to_user_inatomic(to, from, n);
20890 }
20891
20892 static __always_inline unsigned long
20893 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
20894 {
20895 + if ((long)n < 0)
20896 + return n;
20897 +
20898 /* Avoid zeroing the tail if the copy fails..
20899 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
20900 * but as the zeroing behaviour is only significant when n is not
20901 @@ -137,6 +146,12 @@ static __always_inline unsigned long
20902 __copy_from_user(void *to, const void __user *from, unsigned long n)
20903 {
20904 might_fault();
20905 +
20906 + if ((long)n < 0)
20907 + return n;
20908 +
20909 + check_object_size(to, n, false);
20910 +
20911 if (__builtin_constant_p(n)) {
20912 unsigned long ret;
20913
20914 @@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
20915 const void __user *from, unsigned long n)
20916 {
20917 might_fault();
20918 +
20919 + if ((long)n < 0)
20920 + return n;
20921 +
20922 if (__builtin_constant_p(n)) {
20923 unsigned long ret;
20924
20925 @@ -181,7 +200,10 @@ static __always_inline unsigned long
20926 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
20927 unsigned long n)
20928 {
20929 - return __copy_from_user_ll_nocache_nozero(to, from, n);
20930 + if ((long)n < 0)
20931 + return n;
20932 +
20933 + return __copy_from_user_ll_nocache_nozero(to, from, n);
20934 }
20935
20936 #endif /* _ASM_X86_UACCESS_32_H */
20937 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
20938 index 12a26b9..206c200 100644
20939 --- a/arch/x86/include/asm/uaccess_64.h
20940 +++ b/arch/x86/include/asm/uaccess_64.h
20941 @@ -10,6 +10,9 @@
20942 #include <asm/alternative.h>
20943 #include <asm/cpufeature.h>
20944 #include <asm/page.h>
20945 +#include <asm/pgtable.h>
20946 +
20947 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
20948
20949 /*
20950 * Copy To/From Userspace
20951 @@ -17,14 +20,14 @@
20952
20953 /* Handles exceptions in both to and from, but doesn't do access_ok */
20954 __must_check unsigned long
20955 -copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
20956 +copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
20957 __must_check unsigned long
20958 -copy_user_generic_string(void *to, const void *from, unsigned len);
20959 +copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
20960 __must_check unsigned long
20961 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
20962 +copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
20963
20964 static __always_inline __must_check unsigned long
20965 -copy_user_generic(void *to, const void *from, unsigned len)
20966 +copy_user_generic(void *to, const void *from, unsigned long len)
20967 {
20968 unsigned ret;
20969
20970 @@ -46,121 +49,170 @@ copy_user_generic(void *to, const void *from, unsigned len)
20971 }
20972
20973 __must_check unsigned long
20974 -copy_in_user(void __user *to, const void __user *from, unsigned len);
20975 +copy_in_user(void __user *to, const void __user *from, unsigned long len);
20976
20977 static __always_inline __must_check
20978 -int __copy_from_user_nocheck(void *dst, const void __user *src, unsigned size)
20979 +unsigned long __copy_from_user_nocheck(void *dst, const void __user *src, unsigned long size)
20980 {
20981 - int ret = 0;
20982 + size_t sz = __compiletime_object_size(dst);
20983 + unsigned ret = 0;
20984 +
20985 + if (size > INT_MAX)
20986 + return size;
20987 +
20988 + check_object_size(dst, size, false);
20989 +
20990 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20991 + if (!access_ok_noprefault(VERIFY_READ, src, size))
20992 + return size;
20993 +#endif
20994 +
20995 + if (unlikely(sz != (size_t)-1 && sz < size)) {
20996 + if(__builtin_constant_p(size))
20997 + copy_from_user_overflow();
20998 + else
20999 + __copy_from_user_overflow(sz, size);
21000 + return size;
21001 + }
21002
21003 if (!__builtin_constant_p(size))
21004 - return copy_user_generic(dst, (__force void *)src, size);
21005 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
21006 switch (size) {
21007 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
21008 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
21009 ret, "b", "b", "=q", 1);
21010 return ret;
21011 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
21012 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
21013 ret, "w", "w", "=r", 2);
21014 return ret;
21015 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
21016 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
21017 ret, "l", "k", "=r", 4);
21018 return ret;
21019 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
21020 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
21021 ret, "q", "", "=r", 8);
21022 return ret;
21023 case 10:
21024 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
21025 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
21026 ret, "q", "", "=r", 10);
21027 if (unlikely(ret))
21028 return ret;
21029 __get_user_asm(*(u16 *)(8 + (char *)dst),
21030 - (u16 __user *)(8 + (char __user *)src),
21031 + (const u16 __user *)(8 + (const char __user *)src),
21032 ret, "w", "w", "=r", 2);
21033 return ret;
21034 case 16:
21035 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
21036 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
21037 ret, "q", "", "=r", 16);
21038 if (unlikely(ret))
21039 return ret;
21040 __get_user_asm(*(u64 *)(8 + (char *)dst),
21041 - (u64 __user *)(8 + (char __user *)src),
21042 + (const u64 __user *)(8 + (const char __user *)src),
21043 ret, "q", "", "=r", 8);
21044 return ret;
21045 default:
21046 - return copy_user_generic(dst, (__force void *)src, size);
21047 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
21048 }
21049 }
21050
21051 static __always_inline __must_check
21052 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
21053 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
21054 {
21055 might_fault();
21056 return __copy_from_user_nocheck(dst, src, size);
21057 }
21058
21059 static __always_inline __must_check
21060 -int __copy_to_user_nocheck(void __user *dst, const void *src, unsigned size)
21061 +unsigned long __copy_to_user_nocheck(void __user *dst, const void *src, unsigned long size)
21062 {
21063 - int ret = 0;
21064 + size_t sz = __compiletime_object_size(src);
21065 + unsigned ret = 0;
21066 +
21067 + if (size > INT_MAX)
21068 + return size;
21069 +
21070 + check_object_size(src, size, true);
21071 +
21072 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21073 + if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
21074 + return size;
21075 +#endif
21076 +
21077 + if (unlikely(sz != (size_t)-1 && sz < size)) {
21078 + if(__builtin_constant_p(size))
21079 + copy_to_user_overflow();
21080 + else
21081 + __copy_to_user_overflow(sz, size);
21082 + return size;
21083 + }
21084
21085 if (!__builtin_constant_p(size))
21086 - return copy_user_generic((__force void *)dst, src, size);
21087 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
21088 switch (size) {
21089 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
21090 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
21091 ret, "b", "b", "iq", 1);
21092 return ret;
21093 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
21094 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
21095 ret, "w", "w", "ir", 2);
21096 return ret;
21097 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
21098 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
21099 ret, "l", "k", "ir", 4);
21100 return ret;
21101 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
21102 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
21103 ret, "q", "", "er", 8);
21104 return ret;
21105 case 10:
21106 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
21107 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
21108 ret, "q", "", "er", 10);
21109 if (unlikely(ret))
21110 return ret;
21111 asm("":::"memory");
21112 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
21113 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
21114 ret, "w", "w", "ir", 2);
21115 return ret;
21116 case 16:
21117 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
21118 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
21119 ret, "q", "", "er", 16);
21120 if (unlikely(ret))
21121 return ret;
21122 asm("":::"memory");
21123 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
21124 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
21125 ret, "q", "", "er", 8);
21126 return ret;
21127 default:
21128 - return copy_user_generic((__force void *)dst, src, size);
21129 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
21130 }
21131 }
21132
21133 static __always_inline __must_check
21134 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
21135 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
21136 {
21137 might_fault();
21138 return __copy_to_user_nocheck(dst, src, size);
21139 }
21140
21141 static __always_inline __must_check
21142 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
21143 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned size)
21144 {
21145 - int ret = 0;
21146 + unsigned ret = 0;
21147
21148 might_fault();
21149 +
21150 + if (size > INT_MAX)
21151 + return size;
21152 +
21153 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21154 + if (!access_ok_noprefault(VERIFY_READ, src, size))
21155 + return size;
21156 + if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
21157 + return size;
21158 +#endif
21159 +
21160 if (!__builtin_constant_p(size))
21161 - return copy_user_generic((__force void *)dst,
21162 - (__force void *)src, size);
21163 + return copy_user_generic((__force_kernel void *)____m(dst),
21164 + (__force_kernel const void *)____m(src), size);
21165 switch (size) {
21166 case 1: {
21167 u8 tmp;
21168 - __get_user_asm(tmp, (u8 __user *)src,
21169 + __get_user_asm(tmp, (const u8 __user *)src,
21170 ret, "b", "b", "=q", 1);
21171 if (likely(!ret))
21172 __put_user_asm(tmp, (u8 __user *)dst,
21173 @@ -169,7 +221,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
21174 }
21175 case 2: {
21176 u16 tmp;
21177 - __get_user_asm(tmp, (u16 __user *)src,
21178 + __get_user_asm(tmp, (const u16 __user *)src,
21179 ret, "w", "w", "=r", 2);
21180 if (likely(!ret))
21181 __put_user_asm(tmp, (u16 __user *)dst,
21182 @@ -179,7 +231,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
21183
21184 case 4: {
21185 u32 tmp;
21186 - __get_user_asm(tmp, (u32 __user *)src,
21187 + __get_user_asm(tmp, (const u32 __user *)src,
21188 ret, "l", "k", "=r", 4);
21189 if (likely(!ret))
21190 __put_user_asm(tmp, (u32 __user *)dst,
21191 @@ -188,7 +240,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
21192 }
21193 case 8: {
21194 u64 tmp;
21195 - __get_user_asm(tmp, (u64 __user *)src,
21196 + __get_user_asm(tmp, (const u64 __user *)src,
21197 ret, "q", "", "=r", 8);
21198 if (likely(!ret))
21199 __put_user_asm(tmp, (u64 __user *)dst,
21200 @@ -196,41 +248,58 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
21201 return ret;
21202 }
21203 default:
21204 - return copy_user_generic((__force void *)dst,
21205 - (__force void *)src, size);
21206 + return copy_user_generic((__force_kernel void *)____m(dst),
21207 + (__force_kernel const void *)____m(src), size);
21208 }
21209 }
21210
21211 -static __must_check __always_inline int
21212 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
21213 +static __must_check __always_inline unsigned long
21214 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
21215 {
21216 return __copy_from_user_nocheck(dst, src, size);
21217 }
21218
21219 -static __must_check __always_inline int
21220 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
21221 +static __must_check __always_inline unsigned long
21222 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
21223 {
21224 return __copy_to_user_nocheck(dst, src, size);
21225 }
21226
21227 -extern long __copy_user_nocache(void *dst, const void __user *src,
21228 - unsigned size, int zerorest);
21229 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
21230 + unsigned long size, int zerorest);
21231
21232 -static inline int
21233 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
21234 +static inline unsigned long
21235 +__copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
21236 {
21237 might_fault();
21238 +
21239 + if (size > INT_MAX)
21240 + return size;
21241 +
21242 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21243 + if (!access_ok_noprefault(VERIFY_READ, src, size))
21244 + return size;
21245 +#endif
21246 +
21247 return __copy_user_nocache(dst, src, size, 1);
21248 }
21249
21250 -static inline int
21251 +static inline unsigned long
21252 __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
21253 - unsigned size)
21254 + unsigned long size)
21255 {
21256 + if (size > INT_MAX)
21257 + return size;
21258 +
21259 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21260 + if (!access_ok_noprefault(VERIFY_READ, src, size))
21261 + return size;
21262 +#endif
21263 +
21264 return __copy_user_nocache(dst, src, size, 0);
21265 }
21266
21267 unsigned long
21268 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
21269 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
21270
21271 #endif /* _ASM_X86_UACCESS_64_H */
21272 diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
21273 index 5b238981..77fdd78 100644
21274 --- a/arch/x86/include/asm/word-at-a-time.h
21275 +++ b/arch/x86/include/asm/word-at-a-time.h
21276 @@ -11,7 +11,7 @@
21277 * and shift, for example.
21278 */
21279 struct word_at_a_time {
21280 - const unsigned long one_bits, high_bits;
21281 + unsigned long one_bits, high_bits;
21282 };
21283
21284 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
21285 diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
21286 index e45e4da..44e8572 100644
21287 --- a/arch/x86/include/asm/x86_init.h
21288 +++ b/arch/x86/include/asm/x86_init.h
21289 @@ -129,7 +129,7 @@ struct x86_init_ops {
21290 struct x86_init_timers timers;
21291 struct x86_init_iommu iommu;
21292 struct x86_init_pci pci;
21293 -};
21294 +} __no_const;
21295
21296 /**
21297 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
21298 @@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
21299 void (*setup_percpu_clockev)(void);
21300 void (*early_percpu_clock_init)(void);
21301 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
21302 -};
21303 +} __no_const;
21304
21305 struct timespec;
21306
21307 @@ -168,7 +168,7 @@ struct x86_platform_ops {
21308 void (*save_sched_clock_state)(void);
21309 void (*restore_sched_clock_state)(void);
21310 void (*apic_post_init)(void);
21311 -};
21312 +} __no_const;
21313
21314 struct pci_dev;
21315 struct msi_msg;
21316 @@ -185,7 +185,7 @@ struct x86_msi_ops {
21317 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
21318 u32 (*msi_mask_irq)(struct msi_desc *desc, u32 mask, u32 flag);
21319 u32 (*msix_mask_irq)(struct msi_desc *desc, u32 flag);
21320 -};
21321 +} __no_const;
21322
21323 struct IO_APIC_route_entry;
21324 struct io_apic_irq_attr;
21325 @@ -206,7 +206,7 @@ struct x86_io_apic_ops {
21326 unsigned int destination, int vector,
21327 struct io_apic_irq_attr *attr);
21328 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
21329 -};
21330 +} __no_const;
21331
21332 extern struct x86_init_ops x86_init;
21333 extern struct x86_cpuinit_ops x86_cpuinit;
21334 diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
21335 index c949923..c22bfa4 100644
21336 --- a/arch/x86/include/asm/xen/page.h
21337 +++ b/arch/x86/include/asm/xen/page.h
21338 @@ -63,7 +63,7 @@ extern int m2p_remove_override(struct page *page,
21339 extern struct page *m2p_find_override(unsigned long mfn);
21340 extern unsigned long m2p_find_override_pfn(unsigned long mfn, unsigned long pfn);
21341
21342 -static inline unsigned long pfn_to_mfn(unsigned long pfn)
21343 +static inline unsigned long __intentional_overflow(-1) pfn_to_mfn(unsigned long pfn)
21344 {
21345 unsigned long mfn;
21346
21347 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
21348 index 7e7a79a..0824666 100644
21349 --- a/arch/x86/include/asm/xsave.h
21350 +++ b/arch/x86/include/asm/xsave.h
21351 @@ -228,12 +228,16 @@ static inline int xsave_user(struct xsave_struct __user *buf)
21352 if (unlikely(err))
21353 return -EFAULT;
21354
21355 + pax_open_userland();
21356 __asm__ __volatile__(ASM_STAC "\n"
21357 - "1:"XSAVE"\n"
21358 + "1:"
21359 + __copyuser_seg
21360 + XSAVE"\n"
21361 "2: " ASM_CLAC "\n"
21362 xstate_fault
21363 : "D" (buf), "a" (-1), "d" (-1), "0" (0)
21364 : "memory");
21365 + pax_close_userland();
21366 return err;
21367 }
21368
21369 @@ -243,16 +247,20 @@ static inline int xsave_user(struct xsave_struct __user *buf)
21370 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
21371 {
21372 int err = 0;
21373 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
21374 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
21375 u32 lmask = mask;
21376 u32 hmask = mask >> 32;
21377
21378 + pax_open_userland();
21379 __asm__ __volatile__(ASM_STAC "\n"
21380 - "1:"XRSTOR"\n"
21381 + "1:"
21382 + __copyuser_seg
21383 + XRSTOR"\n"
21384 "2: " ASM_CLAC "\n"
21385 xstate_fault
21386 : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
21387 : "memory"); /* memory required? */
21388 + pax_close_userland();
21389 return err;
21390 }
21391
21392 diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
21393 index bbae024..e1528f9 100644
21394 --- a/arch/x86/include/uapi/asm/e820.h
21395 +++ b/arch/x86/include/uapi/asm/e820.h
21396 @@ -63,7 +63,7 @@ struct e820map {
21397 #define ISA_START_ADDRESS 0xa0000
21398 #define ISA_END_ADDRESS 0x100000
21399
21400 -#define BIOS_BEGIN 0x000a0000
21401 +#define BIOS_BEGIN 0x000c0000
21402 #define BIOS_END 0x00100000
21403
21404 #define BIOS_ROM_BASE 0xffe00000
21405 diff --git a/arch/x86/include/uapi/asm/ldt.h b/arch/x86/include/uapi/asm/ldt.h
21406 index 46727eb..6e1aaf7 100644
21407 --- a/arch/x86/include/uapi/asm/ldt.h
21408 +++ b/arch/x86/include/uapi/asm/ldt.h
21409 @@ -28,6 +28,13 @@ struct user_desc {
21410 unsigned int seg_not_present:1;
21411 unsigned int useable:1;
21412 #ifdef __x86_64__
21413 + /*
21414 + * Because this bit is not present in 32-bit user code, user
21415 + * programs can pass uninitialized values here. Therefore, in
21416 + * any context in which a user_desc comes from a 32-bit program,
21417 + * the kernel must act as though lm == 0, regardless of the
21418 + * actual value.
21419 + */
21420 unsigned int lm:1;
21421 #endif
21422 };
21423 diff --git a/arch/x86/include/uapi/asm/ptrace-abi.h b/arch/x86/include/uapi/asm/ptrace-abi.h
21424 index 7b0a55a..ad115bf 100644
21425 --- a/arch/x86/include/uapi/asm/ptrace-abi.h
21426 +++ b/arch/x86/include/uapi/asm/ptrace-abi.h
21427 @@ -49,7 +49,6 @@
21428 #define EFLAGS 144
21429 #define RSP 152
21430 #define SS 160
21431 -#define ARGOFFSET R11
21432 #endif /* __ASSEMBLY__ */
21433
21434 /* top of stack page */
21435 diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
21436 index ada2e2d..ca69e16 100644
21437 --- a/arch/x86/kernel/Makefile
21438 +++ b/arch/x86/kernel/Makefile
21439 @@ -24,7 +24,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
21440 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
21441 obj-$(CONFIG_IRQ_WORK) += irq_work.o
21442 obj-y += probe_roms.o
21443 -obj-$(CONFIG_X86_32) += i386_ksyms_32.o
21444 +obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
21445 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
21446 obj-$(CONFIG_X86_64) += mcount_64.o
21447 obj-y += syscall_$(BITS).o vsyscall_gtod.o
21448 diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
21449 index a142e77..6222cdd 100644
21450 --- a/arch/x86/kernel/acpi/boot.c
21451 +++ b/arch/x86/kernel/acpi/boot.c
21452 @@ -1276,7 +1276,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
21453 * If your system is blacklisted here, but you find that acpi=force
21454 * works for you, please contact linux-acpi@vger.kernel.org
21455 */
21456 -static struct dmi_system_id __initdata acpi_dmi_table[] = {
21457 +static const struct dmi_system_id __initconst acpi_dmi_table[] = {
21458 /*
21459 * Boxes that need ACPI disabled
21460 */
21461 @@ -1351,7 +1351,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
21462 };
21463
21464 /* second table for DMI checks that should run after early-quirks */
21465 -static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
21466 +static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
21467 /*
21468 * HP laptops which use a DSDT reporting as HP/SB400/10000,
21469 * which includes some code which overrides all temperature
21470 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
21471 index 3136820..e2c6577 100644
21472 --- a/arch/x86/kernel/acpi/sleep.c
21473 +++ b/arch/x86/kernel/acpi/sleep.c
21474 @@ -99,8 +99,12 @@ int x86_acpi_suspend_lowlevel(void)
21475 #else /* CONFIG_64BIT */
21476 #ifdef CONFIG_SMP
21477 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
21478 +
21479 + pax_open_kernel();
21480 early_gdt_descr.address =
21481 (unsigned long)get_cpu_gdt_table(smp_processor_id());
21482 + pax_close_kernel();
21483 +
21484 initial_gs = per_cpu_offset(smp_processor_id());
21485 #endif
21486 initial_code = (unsigned long)wakeup_long64;
21487 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
21488 index 665c6b7..eae4d56 100644
21489 --- a/arch/x86/kernel/acpi/wakeup_32.S
21490 +++ b/arch/x86/kernel/acpi/wakeup_32.S
21491 @@ -29,13 +29,11 @@ wakeup_pmode_return:
21492 # and restore the stack ... but you need gdt for this to work
21493 movl saved_context_esp, %esp
21494
21495 - movl %cs:saved_magic, %eax
21496 - cmpl $0x12345678, %eax
21497 + cmpl $0x12345678, saved_magic
21498 jne bogus_magic
21499
21500 # jump to place where we left off
21501 - movl saved_eip, %eax
21502 - jmp *%eax
21503 + jmp *(saved_eip)
21504
21505 bogus_magic:
21506 jmp bogus_magic
21507 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
21508 index 703130f..27a155d 100644
21509 --- a/arch/x86/kernel/alternative.c
21510 +++ b/arch/x86/kernel/alternative.c
21511 @@ -268,6 +268,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
21512 */
21513 for (a = start; a < end; a++) {
21514 instr = (u8 *)&a->instr_offset + a->instr_offset;
21515 +
21516 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21517 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
21518 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
21519 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
21520 +#endif
21521 +
21522 replacement = (u8 *)&a->repl_offset + a->repl_offset;
21523 BUG_ON(a->replacementlen > a->instrlen);
21524 BUG_ON(a->instrlen > sizeof(insnbuf));
21525 @@ -284,6 +291,11 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
21526 add_nops(insnbuf + a->replacementlen,
21527 a->instrlen - a->replacementlen);
21528
21529 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21530 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
21531 + instr = ktva_ktla(instr);
21532 +#endif
21533 +
21534 text_poke_early(instr, insnbuf, a->instrlen);
21535 }
21536 }
21537 @@ -299,10 +311,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
21538 for (poff = start; poff < end; poff++) {
21539 u8 *ptr = (u8 *)poff + *poff;
21540
21541 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21542 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
21543 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
21544 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
21545 +#endif
21546 +
21547 if (!*poff || ptr < text || ptr >= text_end)
21548 continue;
21549 /* turn DS segment override prefix into lock prefix */
21550 - if (*ptr == 0x3e)
21551 + if (*ktla_ktva(ptr) == 0x3e)
21552 text_poke(ptr, ((unsigned char []){0xf0}), 1);
21553 }
21554 mutex_unlock(&text_mutex);
21555 @@ -317,10 +335,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
21556 for (poff = start; poff < end; poff++) {
21557 u8 *ptr = (u8 *)poff + *poff;
21558
21559 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21560 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
21561 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
21562 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
21563 +#endif
21564 +
21565 if (!*poff || ptr < text || ptr >= text_end)
21566 continue;
21567 /* turn lock prefix into DS segment override prefix */
21568 - if (*ptr == 0xf0)
21569 + if (*ktla_ktva(ptr) == 0xf0)
21570 text_poke(ptr, ((unsigned char []){0x3E}), 1);
21571 }
21572 mutex_unlock(&text_mutex);
21573 @@ -457,7 +481,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
21574
21575 BUG_ON(p->len > MAX_PATCH_LEN);
21576 /* prep the buffer with the original instructions */
21577 - memcpy(insnbuf, p->instr, p->len);
21578 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
21579 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
21580 (unsigned long)p->instr, p->len);
21581
21582 @@ -504,7 +528,7 @@ void __init alternative_instructions(void)
21583 if (!uniproc_patched || num_possible_cpus() == 1)
21584 free_init_pages("SMP alternatives",
21585 (unsigned long)__smp_locks,
21586 - (unsigned long)__smp_locks_end);
21587 + PAGE_ALIGN((unsigned long)__smp_locks_end));
21588 #endif
21589
21590 apply_paravirt(__parainstructions, __parainstructions_end);
21591 @@ -524,13 +548,17 @@ void __init alternative_instructions(void)
21592 * instructions. And on the local CPU you need to be protected again NMI or MCE
21593 * handlers seeing an inconsistent instruction while you patch.
21594 */
21595 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
21596 +void *__kprobes text_poke_early(void *addr, const void *opcode,
21597 size_t len)
21598 {
21599 unsigned long flags;
21600 local_irq_save(flags);
21601 - memcpy(addr, opcode, len);
21602 +
21603 + pax_open_kernel();
21604 + memcpy(ktla_ktva(addr), opcode, len);
21605 sync_core();
21606 + pax_close_kernel();
21607 +
21608 local_irq_restore(flags);
21609 /* Could also do a CLFLUSH here to speed up CPU recovery; but
21610 that causes hangs on some VIA CPUs. */
21611 @@ -552,36 +580,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
21612 */
21613 void *text_poke(void *addr, const void *opcode, size_t len)
21614 {
21615 - unsigned long flags;
21616 - char *vaddr;
21617 + unsigned char *vaddr = ktla_ktva(addr);
21618 struct page *pages[2];
21619 - int i;
21620 + size_t i;
21621
21622 if (!core_kernel_text((unsigned long)addr)) {
21623 - pages[0] = vmalloc_to_page(addr);
21624 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
21625 + pages[0] = vmalloc_to_page(vaddr);
21626 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
21627 } else {
21628 - pages[0] = virt_to_page(addr);
21629 + pages[0] = virt_to_page(vaddr);
21630 WARN_ON(!PageReserved(pages[0]));
21631 - pages[1] = virt_to_page(addr + PAGE_SIZE);
21632 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
21633 }
21634 BUG_ON(!pages[0]);
21635 - local_irq_save(flags);
21636 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
21637 - if (pages[1])
21638 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
21639 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
21640 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
21641 - clear_fixmap(FIX_TEXT_POKE0);
21642 - if (pages[1])
21643 - clear_fixmap(FIX_TEXT_POKE1);
21644 - local_flush_tlb();
21645 - sync_core();
21646 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
21647 - that causes hangs on some VIA CPUs. */
21648 + text_poke_early(addr, opcode, len);
21649 for (i = 0; i < len; i++)
21650 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
21651 - local_irq_restore(flags);
21652 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
21653 return addr;
21654 }
21655
21656 @@ -601,7 +615,7 @@ int poke_int3_handler(struct pt_regs *regs)
21657 if (likely(!bp_patching_in_progress))
21658 return 0;
21659
21660 - if (user_mode_vm(regs) || regs->ip != (unsigned long)bp_int3_addr)
21661 + if (user_mode(regs) || regs->ip != (unsigned long)bp_int3_addr)
21662 return 0;
21663
21664 /* set up the specified breakpoint handler */
21665 @@ -635,7 +649,7 @@ int poke_int3_handler(struct pt_regs *regs)
21666 */
21667 void *text_poke_bp(void *addr, const void *opcode, size_t len, void *handler)
21668 {
21669 - unsigned char int3 = 0xcc;
21670 + const unsigned char int3 = 0xcc;
21671
21672 bp_int3_handler = handler;
21673 bp_int3_addr = (u8 *)addr + sizeof(int3);
21674 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
21675 index 24b5894..6d9701b 100644
21676 --- a/arch/x86/kernel/apic/apic.c
21677 +++ b/arch/x86/kernel/apic/apic.c
21678 @@ -201,7 +201,7 @@ int first_system_vector = 0xfe;
21679 /*
21680 * Debug level, exported for io_apic.c
21681 */
21682 -unsigned int apic_verbosity;
21683 +int apic_verbosity;
21684
21685 int pic_mode;
21686
21687 @@ -1989,7 +1989,7 @@ static inline void __smp_error_interrupt(struct pt_regs *regs)
21688 apic_write(APIC_ESR, 0);
21689 v = apic_read(APIC_ESR);
21690 ack_APIC_irq();
21691 - atomic_inc(&irq_err_count);
21692 + atomic_inc_unchecked(&irq_err_count);
21693
21694 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x",
21695 smp_processor_id(), v);
21696 diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
21697 index de918c4..32eed23 100644
21698 --- a/arch/x86/kernel/apic/apic_flat_64.c
21699 +++ b/arch/x86/kernel/apic/apic_flat_64.c
21700 @@ -154,7 +154,7 @@ static int flat_probe(void)
21701 return 1;
21702 }
21703
21704 -static struct apic apic_flat = {
21705 +static struct apic apic_flat __read_only = {
21706 .name = "flat",
21707 .probe = flat_probe,
21708 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
21709 @@ -260,7 +260,7 @@ static int physflat_probe(void)
21710 return 0;
21711 }
21712
21713 -static struct apic apic_physflat = {
21714 +static struct apic apic_physflat __read_only = {
21715
21716 .name = "physical flat",
21717 .probe = physflat_probe,
21718 diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
21719 index b205cdb..d8503ff 100644
21720 --- a/arch/x86/kernel/apic/apic_noop.c
21721 +++ b/arch/x86/kernel/apic/apic_noop.c
21722 @@ -108,7 +108,7 @@ static void noop_apic_write(u32 reg, u32 v)
21723 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
21724 }
21725
21726 -struct apic apic_noop = {
21727 +struct apic apic_noop __read_only = {
21728 .name = "noop",
21729 .probe = noop_probe,
21730 .acpi_madt_oem_check = NULL,
21731 diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
21732 index c4a8d63..fe893ac 100644
21733 --- a/arch/x86/kernel/apic/bigsmp_32.c
21734 +++ b/arch/x86/kernel/apic/bigsmp_32.c
21735 @@ -147,7 +147,7 @@ static int probe_bigsmp(void)
21736 return dmi_bigsmp;
21737 }
21738
21739 -static struct apic apic_bigsmp = {
21740 +static struct apic apic_bigsmp __read_only = {
21741
21742 .name = "bigsmp",
21743 .probe = probe_bigsmp,
21744 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
21745 index 337ce5a..c8d98b4 100644
21746 --- a/arch/x86/kernel/apic/io_apic.c
21747 +++ b/arch/x86/kernel/apic/io_apic.c
21748 @@ -1230,7 +1230,7 @@ out:
21749 }
21750 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
21751
21752 -void lock_vector_lock(void)
21753 +void lock_vector_lock(void) __acquires(vector_lock)
21754 {
21755 /* Used to the online set of cpus does not change
21756 * during assign_irq_vector.
21757 @@ -1238,7 +1238,7 @@ void lock_vector_lock(void)
21758 raw_spin_lock(&vector_lock);
21759 }
21760
21761 -void unlock_vector_lock(void)
21762 +void unlock_vector_lock(void) __releases(vector_lock)
21763 {
21764 raw_spin_unlock(&vector_lock);
21765 }
21766 @@ -2465,7 +2465,7 @@ static void ack_apic_edge(struct irq_data *data)
21767 ack_APIC_irq();
21768 }
21769
21770 -atomic_t irq_mis_count;
21771 +atomic_unchecked_t irq_mis_count;
21772
21773 #ifdef CONFIG_GENERIC_PENDING_IRQ
21774 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
21775 @@ -2606,7 +2606,7 @@ static void ack_apic_level(struct irq_data *data)
21776 * at the cpu.
21777 */
21778 if (!(v & (1 << (i & 0x1f)))) {
21779 - atomic_inc(&irq_mis_count);
21780 + atomic_inc_unchecked(&irq_mis_count);
21781
21782 eoi_ioapic_irq(irq, cfg);
21783 }
21784 diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
21785 index bda4886..f9c7195 100644
21786 --- a/arch/x86/kernel/apic/probe_32.c
21787 +++ b/arch/x86/kernel/apic/probe_32.c
21788 @@ -72,7 +72,7 @@ static int probe_default(void)
21789 return 1;
21790 }
21791
21792 -static struct apic apic_default = {
21793 +static struct apic apic_default __read_only = {
21794
21795 .name = "default",
21796 .probe = probe_default,
21797 diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
21798 index 6ce600f..cb44af8 100644
21799 --- a/arch/x86/kernel/apic/x2apic_cluster.c
21800 +++ b/arch/x86/kernel/apic/x2apic_cluster.c
21801 @@ -182,7 +182,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
21802 return notifier_from_errno(err);
21803 }
21804
21805 -static struct notifier_block __refdata x2apic_cpu_notifier = {
21806 +static struct notifier_block x2apic_cpu_notifier = {
21807 .notifier_call = update_clusterinfo,
21808 };
21809
21810 @@ -234,7 +234,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
21811 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
21812 }
21813
21814 -static struct apic apic_x2apic_cluster = {
21815 +static struct apic apic_x2apic_cluster __read_only = {
21816
21817 .name = "cluster x2apic",
21818 .probe = x2apic_cluster_probe,
21819 diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
21820 index 6fae733..5ca17af 100644
21821 --- a/arch/x86/kernel/apic/x2apic_phys.c
21822 +++ b/arch/x86/kernel/apic/x2apic_phys.c
21823 @@ -88,7 +88,7 @@ static int x2apic_phys_probe(void)
21824 return apic == &apic_x2apic_phys;
21825 }
21826
21827 -static struct apic apic_x2apic_phys = {
21828 +static struct apic apic_x2apic_phys __read_only = {
21829
21830 .name = "physical x2apic",
21831 .probe = x2apic_phys_probe,
21832 diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
21833 index 004f017..8fbc8b5 100644
21834 --- a/arch/x86/kernel/apic/x2apic_uv_x.c
21835 +++ b/arch/x86/kernel/apic/x2apic_uv_x.c
21836 @@ -350,7 +350,7 @@ static int uv_probe(void)
21837 return apic == &apic_x2apic_uv_x;
21838 }
21839
21840 -static struct apic __refdata apic_x2apic_uv_x = {
21841 +static struct apic apic_x2apic_uv_x __read_only = {
21842
21843 .name = "UV large system",
21844 .probe = uv_probe,
21845 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
21846 index 5848744..56cb598 100644
21847 --- a/arch/x86/kernel/apm_32.c
21848 +++ b/arch/x86/kernel/apm_32.c
21849 @@ -433,7 +433,7 @@ static DEFINE_MUTEX(apm_mutex);
21850 * This is for buggy BIOS's that refer to (real mode) segment 0x40
21851 * even though they are called in protected mode.
21852 */
21853 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
21854 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
21855 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
21856
21857 static const char driver_version[] = "1.16ac"; /* no spaces */
21858 @@ -611,7 +611,10 @@ static long __apm_bios_call(void *_call)
21859 BUG_ON(cpu != 0);
21860 gdt = get_cpu_gdt_table(cpu);
21861 save_desc_40 = gdt[0x40 / 8];
21862 +
21863 + pax_open_kernel();
21864 gdt[0x40 / 8] = bad_bios_desc;
21865 + pax_close_kernel();
21866
21867 apm_irq_save(flags);
21868 APM_DO_SAVE_SEGS;
21869 @@ -620,7 +623,11 @@ static long __apm_bios_call(void *_call)
21870 &call->esi);
21871 APM_DO_RESTORE_SEGS;
21872 apm_irq_restore(flags);
21873 +
21874 + pax_open_kernel();
21875 gdt[0x40 / 8] = save_desc_40;
21876 + pax_close_kernel();
21877 +
21878 put_cpu();
21879
21880 return call->eax & 0xff;
21881 @@ -687,7 +694,10 @@ static long __apm_bios_call_simple(void *_call)
21882 BUG_ON(cpu != 0);
21883 gdt = get_cpu_gdt_table(cpu);
21884 save_desc_40 = gdt[0x40 / 8];
21885 +
21886 + pax_open_kernel();
21887 gdt[0x40 / 8] = bad_bios_desc;
21888 + pax_close_kernel();
21889
21890 apm_irq_save(flags);
21891 APM_DO_SAVE_SEGS;
21892 @@ -695,7 +705,11 @@ static long __apm_bios_call_simple(void *_call)
21893 &call->eax);
21894 APM_DO_RESTORE_SEGS;
21895 apm_irq_restore(flags);
21896 +
21897 + pax_open_kernel();
21898 gdt[0x40 / 8] = save_desc_40;
21899 + pax_close_kernel();
21900 +
21901 put_cpu();
21902 return error;
21903 }
21904 @@ -2350,12 +2364,15 @@ static int __init apm_init(void)
21905 * code to that CPU.
21906 */
21907 gdt = get_cpu_gdt_table(0);
21908 +
21909 + pax_open_kernel();
21910 set_desc_base(&gdt[APM_CS >> 3],
21911 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
21912 set_desc_base(&gdt[APM_CS_16 >> 3],
21913 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
21914 set_desc_base(&gdt[APM_DS >> 3],
21915 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
21916 + pax_close_kernel();
21917
21918 proc_create("apm", 0, NULL, &apm_file_ops);
21919
21920 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
21921 index 9f6b934..cf5ffb3 100644
21922 --- a/arch/x86/kernel/asm-offsets.c
21923 +++ b/arch/x86/kernel/asm-offsets.c
21924 @@ -32,6 +32,8 @@ void common(void) {
21925 OFFSET(TI_flags, thread_info, flags);
21926 OFFSET(TI_status, thread_info, status);
21927 OFFSET(TI_addr_limit, thread_info, addr_limit);
21928 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
21929 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
21930
21931 BLANK();
21932 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
21933 @@ -52,8 +54,26 @@ void common(void) {
21934 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
21935 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
21936 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
21937 +
21938 +#ifdef CONFIG_PAX_KERNEXEC
21939 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
21940 #endif
21941
21942 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21943 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
21944 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
21945 +#ifdef CONFIG_X86_64
21946 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
21947 +#endif
21948 +#endif
21949 +
21950 +#endif
21951 +
21952 + BLANK();
21953 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
21954 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
21955 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
21956 +
21957 #ifdef CONFIG_XEN
21958 BLANK();
21959 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
21960 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
21961 index e7c798b..2b2019b 100644
21962 --- a/arch/x86/kernel/asm-offsets_64.c
21963 +++ b/arch/x86/kernel/asm-offsets_64.c
21964 @@ -77,6 +77,7 @@ int main(void)
21965 BLANK();
21966 #undef ENTRY
21967
21968 + DEFINE(TSS_size, sizeof(struct tss_struct));
21969 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
21970 BLANK();
21971
21972 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
21973 index 7fd54f0..0691410 100644
21974 --- a/arch/x86/kernel/cpu/Makefile
21975 +++ b/arch/x86/kernel/cpu/Makefile
21976 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
21977 CFLAGS_REMOVE_perf_event.o = -pg
21978 endif
21979
21980 -# Make sure load_percpu_segment has no stackprotector
21981 -nostackp := $(call cc-option, -fno-stack-protector)
21982 -CFLAGS_common.o := $(nostackp)
21983 -
21984 obj-y := intel_cacheinfo.o scattered.o topology.o
21985 obj-y += proc.o capflags.o powerflags.o common.o
21986 obj-y += rdrand.o
21987 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
21988 index 813d29d..6e542d4 100644
21989 --- a/arch/x86/kernel/cpu/amd.c
21990 +++ b/arch/x86/kernel/cpu/amd.c
21991 @@ -718,7 +718,7 @@ static void init_amd(struct cpuinfo_x86 *c)
21992 static unsigned int amd_size_cache(struct cpuinfo_x86 *c, unsigned int size)
21993 {
21994 /* AMD errata T13 (order #21922) */
21995 - if ((c->x86 == 6)) {
21996 + if (c->x86 == 6) {
21997 /* Duron Rev A0 */
21998 if (c->x86_model == 3 && c->x86_mask == 0)
21999 size = 64;
22000 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
22001 index 35db56b..256e87c 100644
22002 --- a/arch/x86/kernel/cpu/common.c
22003 +++ b/arch/x86/kernel/cpu/common.c
22004 @@ -90,60 +90,6 @@ static const struct cpu_dev default_cpu = {
22005
22006 static const struct cpu_dev *this_cpu = &default_cpu;
22007
22008 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
22009 -#ifdef CONFIG_X86_64
22010 - /*
22011 - * We need valid kernel segments for data and code in long mode too
22012 - * IRET will check the segment types kkeil 2000/10/28
22013 - * Also sysret mandates a special GDT layout
22014 - *
22015 - * TLS descriptors are currently at a different place compared to i386.
22016 - * Hopefully nobody expects them at a fixed place (Wine?)
22017 - */
22018 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
22019 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
22020 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
22021 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
22022 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
22023 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
22024 -#else
22025 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
22026 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
22027 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
22028 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
22029 - /*
22030 - * Segments used for calling PnP BIOS have byte granularity.
22031 - * They code segments and data segments have fixed 64k limits,
22032 - * the transfer segment sizes are set at run time.
22033 - */
22034 - /* 32-bit code */
22035 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
22036 - /* 16-bit code */
22037 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
22038 - /* 16-bit data */
22039 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
22040 - /* 16-bit data */
22041 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
22042 - /* 16-bit data */
22043 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
22044 - /*
22045 - * The APM segments have byte granularity and their bases
22046 - * are set at run time. All have 64k limits.
22047 - */
22048 - /* 32-bit code */
22049 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
22050 - /* 16-bit code */
22051 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
22052 - /* data */
22053 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
22054 -
22055 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
22056 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
22057 - GDT_STACK_CANARY_INIT
22058 -#endif
22059 -} };
22060 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
22061 -
22062 static int __init x86_xsave_setup(char *s)
22063 {
22064 if (strlen(s))
22065 @@ -305,6 +251,59 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c)
22066 }
22067 }
22068
22069 +#ifdef CONFIG_X86_64
22070 +static __init int setup_disable_pcid(char *arg)
22071 +{
22072 + setup_clear_cpu_cap(X86_FEATURE_PCID);
22073 + setup_clear_cpu_cap(X86_FEATURE_INVPCID);
22074 +
22075 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22076 + if (clone_pgd_mask != ~(pgdval_t)0UL)
22077 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
22078 +#endif
22079 +
22080 + return 1;
22081 +}
22082 +__setup("nopcid", setup_disable_pcid);
22083 +
22084 +static void setup_pcid(struct cpuinfo_x86 *c)
22085 +{
22086 + if (!cpu_has(c, X86_FEATURE_PCID)) {
22087 + clear_cpu_cap(c, X86_FEATURE_INVPCID);
22088 +
22089 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22090 + if (clone_pgd_mask != ~(pgdval_t)0UL) {
22091 + pax_open_kernel();
22092 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
22093 + pax_close_kernel();
22094 + printk("PAX: slow and weak UDEREF enabled\n");
22095 + } else
22096 + printk("PAX: UDEREF disabled\n");
22097 +#endif
22098 +
22099 + return;
22100 + }
22101 +
22102 + printk("PAX: PCID detected\n");
22103 + set_in_cr4(X86_CR4_PCIDE);
22104 +
22105 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22106 + pax_open_kernel();
22107 + clone_pgd_mask = ~(pgdval_t)0UL;
22108 + pax_close_kernel();
22109 + if (pax_user_shadow_base)
22110 + printk("PAX: weak UDEREF enabled\n");
22111 + else {
22112 + set_cpu_cap(c, X86_FEATURE_STRONGUDEREF);
22113 + printk("PAX: strong UDEREF enabled\n");
22114 + }
22115 +#endif
22116 +
22117 + if (cpu_has(c, X86_FEATURE_INVPCID))
22118 + printk("PAX: INVPCID detected\n");
22119 +}
22120 +#endif
22121 +
22122 /*
22123 * Some CPU features depend on higher CPUID levels, which may not always
22124 * be available due to CPUID level capping or broken virtualization
22125 @@ -405,7 +404,7 @@ void switch_to_new_gdt(int cpu)
22126 {
22127 struct desc_ptr gdt_descr;
22128
22129 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
22130 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
22131 gdt_descr.size = GDT_SIZE - 1;
22132 load_gdt(&gdt_descr);
22133 /* Reload the per-cpu base */
22134 @@ -895,6 +894,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
22135 setup_smep(c);
22136 setup_smap(c);
22137
22138 +#ifdef CONFIG_X86_64
22139 + setup_pcid(c);
22140 +#endif
22141 +
22142 /*
22143 * The vendor-specific functions might have changed features.
22144 * Now we do "generic changes."
22145 @@ -903,6 +906,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
22146 /* Filter out anything that depends on CPUID levels we don't have */
22147 filter_cpuid_features(c, true);
22148
22149 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
22150 + setup_clear_cpu_cap(X86_FEATURE_SEP);
22151 +#endif
22152 +
22153 /* If the model name is still unset, do table lookup. */
22154 if (!c->x86_model_id[0]) {
22155 const char *p;
22156 @@ -983,7 +990,7 @@ static void syscall32_cpu_init(void)
22157 void enable_sep_cpu(void)
22158 {
22159 int cpu = get_cpu();
22160 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
22161 + struct tss_struct *tss = init_tss + cpu;
22162
22163 if (!boot_cpu_has(X86_FEATURE_SEP)) {
22164 put_cpu();
22165 @@ -1123,14 +1130,16 @@ static __init int setup_disablecpuid(char *arg)
22166 }
22167 __setup("clearcpuid=", setup_disablecpuid);
22168
22169 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
22170 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
22171 +
22172 DEFINE_PER_CPU(unsigned long, kernel_stack) =
22173 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
22174 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
22175 EXPORT_PER_CPU_SYMBOL(kernel_stack);
22176
22177 #ifdef CONFIG_X86_64
22178 -struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
22179 -struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1,
22180 - (unsigned long) debug_idt_table };
22181 +struct desc_ptr idt_descr __read_only = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
22182 +const struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) debug_idt_table };
22183
22184 DEFINE_PER_CPU_FIRST(union irq_stack_union,
22185 irq_stack_union) __aligned(PAGE_SIZE) __visible;
22186 @@ -1293,7 +1302,7 @@ void cpu_init(void)
22187 load_ucode_ap();
22188
22189 cpu = stack_smp_processor_id();
22190 - t = &per_cpu(init_tss, cpu);
22191 + t = init_tss + cpu;
22192 oist = &per_cpu(orig_ist, cpu);
22193
22194 #ifdef CONFIG_NUMA
22195 @@ -1328,7 +1337,6 @@ void cpu_init(void)
22196 wrmsrl(MSR_KERNEL_GS_BASE, 0);
22197 barrier();
22198
22199 - x86_configure_nx();
22200 enable_x2apic();
22201
22202 /*
22203 @@ -1380,7 +1388,7 @@ void cpu_init(void)
22204 {
22205 int cpu = smp_processor_id();
22206 struct task_struct *curr = current;
22207 - struct tss_struct *t = &per_cpu(init_tss, cpu);
22208 + struct tss_struct *t = init_tss + cpu;
22209 struct thread_struct *thread = &curr->thread;
22210
22211 show_ucode_info_early();
22212 diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
22213 index c703507..28535e3 100644
22214 --- a/arch/x86/kernel/cpu/intel_cacheinfo.c
22215 +++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
22216 @@ -1026,6 +1026,22 @@ static struct attribute *default_attrs[] = {
22217 };
22218
22219 #ifdef CONFIG_AMD_NB
22220 +static struct attribute *default_attrs_amd_nb[] = {
22221 + &type.attr,
22222 + &level.attr,
22223 + &coherency_line_size.attr,
22224 + &physical_line_partition.attr,
22225 + &ways_of_associativity.attr,
22226 + &number_of_sets.attr,
22227 + &size.attr,
22228 + &shared_cpu_map.attr,
22229 + &shared_cpu_list.attr,
22230 + NULL,
22231 + NULL,
22232 + NULL,
22233 + NULL
22234 +};
22235 +
22236 static struct attribute **amd_l3_attrs(void)
22237 {
22238 static struct attribute **attrs;
22239 @@ -1036,18 +1052,7 @@ static struct attribute **amd_l3_attrs(void)
22240
22241 n = ARRAY_SIZE(default_attrs);
22242
22243 - if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
22244 - n += 2;
22245 -
22246 - if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
22247 - n += 1;
22248 -
22249 - attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
22250 - if (attrs == NULL)
22251 - return attrs = default_attrs;
22252 -
22253 - for (n = 0; default_attrs[n]; n++)
22254 - attrs[n] = default_attrs[n];
22255 + attrs = default_attrs_amd_nb;
22256
22257 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
22258 attrs[n++] = &cache_disable_0.attr;
22259 @@ -1098,6 +1103,13 @@ static struct kobj_type ktype_cache = {
22260 .default_attrs = default_attrs,
22261 };
22262
22263 +#ifdef CONFIG_AMD_NB
22264 +static struct kobj_type ktype_cache_amd_nb = {
22265 + .sysfs_ops = &sysfs_ops,
22266 + .default_attrs = default_attrs_amd_nb,
22267 +};
22268 +#endif
22269 +
22270 static struct kobj_type ktype_percpu_entry = {
22271 .sysfs_ops = &sysfs_ops,
22272 };
22273 @@ -1163,20 +1175,26 @@ static int cache_add_dev(struct device *dev)
22274 return retval;
22275 }
22276
22277 +#ifdef CONFIG_AMD_NB
22278 + amd_l3_attrs();
22279 +#endif
22280 +
22281 for (i = 0; i < num_cache_leaves; i++) {
22282 + struct kobj_type *ktype;
22283 +
22284 this_object = INDEX_KOBJECT_PTR(cpu, i);
22285 this_object->cpu = cpu;
22286 this_object->index = i;
22287
22288 this_leaf = CPUID4_INFO_IDX(cpu, i);
22289
22290 - ktype_cache.default_attrs = default_attrs;
22291 + ktype = &ktype_cache;
22292 #ifdef CONFIG_AMD_NB
22293 if (this_leaf->base.nb)
22294 - ktype_cache.default_attrs = amd_l3_attrs();
22295 + ktype = &ktype_cache_amd_nb;
22296 #endif
22297 retval = kobject_init_and_add(&(this_object->kobj),
22298 - &ktype_cache,
22299 + ktype,
22300 per_cpu(ici_cache_kobject, cpu),
22301 "index%1lu", i);
22302 if (unlikely(retval)) {
22303 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
22304 index bd9ccda..38314e7 100644
22305 --- a/arch/x86/kernel/cpu/mcheck/mce.c
22306 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
22307 @@ -45,6 +45,7 @@
22308 #include <asm/processor.h>
22309 #include <asm/mce.h>
22310 #include <asm/msr.h>
22311 +#include <asm/local.h>
22312
22313 #include "mce-internal.h"
22314
22315 @@ -259,7 +260,7 @@ static void print_mce(struct mce *m)
22316 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
22317 m->cs, m->ip);
22318
22319 - if (m->cs == __KERNEL_CS)
22320 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
22321 print_symbol("{%s}", m->ip);
22322 pr_cont("\n");
22323 }
22324 @@ -292,10 +293,10 @@ static void print_mce(struct mce *m)
22325
22326 #define PANIC_TIMEOUT 5 /* 5 seconds */
22327
22328 -static atomic_t mce_paniced;
22329 +static atomic_unchecked_t mce_paniced;
22330
22331 static int fake_panic;
22332 -static atomic_t mce_fake_paniced;
22333 +static atomic_unchecked_t mce_fake_paniced;
22334
22335 /* Panic in progress. Enable interrupts and wait for final IPI */
22336 static void wait_for_panic(void)
22337 @@ -319,7 +320,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
22338 /*
22339 * Make sure only one CPU runs in machine check panic
22340 */
22341 - if (atomic_inc_return(&mce_paniced) > 1)
22342 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
22343 wait_for_panic();
22344 barrier();
22345
22346 @@ -327,7 +328,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
22347 console_verbose();
22348 } else {
22349 /* Don't log too much for fake panic */
22350 - if (atomic_inc_return(&mce_fake_paniced) > 1)
22351 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
22352 return;
22353 }
22354 /* First print corrected ones that are still unlogged */
22355 @@ -366,7 +367,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
22356 if (!fake_panic) {
22357 if (panic_timeout == 0)
22358 panic_timeout = mca_cfg.panic_timeout;
22359 - panic(msg);
22360 + panic("%s", msg);
22361 } else
22362 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
22363 }
22364 @@ -697,7 +698,7 @@ static int mce_timed_out(u64 *t)
22365 * might have been modified by someone else.
22366 */
22367 rmb();
22368 - if (atomic_read(&mce_paniced))
22369 + if (atomic_read_unchecked(&mce_paniced))
22370 wait_for_panic();
22371 if (!mca_cfg.monarch_timeout)
22372 goto out;
22373 @@ -1674,7 +1675,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
22374 }
22375
22376 /* Call the installed machine check handler for this CPU setup. */
22377 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
22378 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
22379 unexpected_machine_check;
22380
22381 /*
22382 @@ -1697,7 +1698,9 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
22383 return;
22384 }
22385
22386 + pax_open_kernel();
22387 machine_check_vector = do_machine_check;
22388 + pax_close_kernel();
22389
22390 __mcheck_cpu_init_generic();
22391 __mcheck_cpu_init_vendor(c);
22392 @@ -1711,7 +1714,7 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
22393 */
22394
22395 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
22396 -static int mce_chrdev_open_count; /* #times opened */
22397 +static local_t mce_chrdev_open_count; /* #times opened */
22398 static int mce_chrdev_open_exclu; /* already open exclusive? */
22399
22400 static int mce_chrdev_open(struct inode *inode, struct file *file)
22401 @@ -1719,7 +1722,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
22402 spin_lock(&mce_chrdev_state_lock);
22403
22404 if (mce_chrdev_open_exclu ||
22405 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
22406 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
22407 spin_unlock(&mce_chrdev_state_lock);
22408
22409 return -EBUSY;
22410 @@ -1727,7 +1730,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
22411
22412 if (file->f_flags & O_EXCL)
22413 mce_chrdev_open_exclu = 1;
22414 - mce_chrdev_open_count++;
22415 + local_inc(&mce_chrdev_open_count);
22416
22417 spin_unlock(&mce_chrdev_state_lock);
22418
22419 @@ -1738,7 +1741,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
22420 {
22421 spin_lock(&mce_chrdev_state_lock);
22422
22423 - mce_chrdev_open_count--;
22424 + local_dec(&mce_chrdev_open_count);
22425 mce_chrdev_open_exclu = 0;
22426
22427 spin_unlock(&mce_chrdev_state_lock);
22428 @@ -2413,7 +2416,7 @@ static __init void mce_init_banks(void)
22429
22430 for (i = 0; i < mca_cfg.banks; i++) {
22431 struct mce_bank *b = &mce_banks[i];
22432 - struct device_attribute *a = &b->attr;
22433 + device_attribute_no_const *a = &b->attr;
22434
22435 sysfs_attr_init(&a->attr);
22436 a->attr.name = b->attrname;
22437 @@ -2520,7 +2523,7 @@ struct dentry *mce_get_debugfs_dir(void)
22438 static void mce_reset(void)
22439 {
22440 cpu_missing = 0;
22441 - atomic_set(&mce_fake_paniced, 0);
22442 + atomic_set_unchecked(&mce_fake_paniced, 0);
22443 atomic_set(&mce_executing, 0);
22444 atomic_set(&mce_callin, 0);
22445 atomic_set(&global_nwo, 0);
22446 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
22447 index a304298..49b6d06 100644
22448 --- a/arch/x86/kernel/cpu/mcheck/p5.c
22449 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
22450 @@ -10,6 +10,7 @@
22451 #include <asm/processor.h>
22452 #include <asm/mce.h>
22453 #include <asm/msr.h>
22454 +#include <asm/pgtable.h>
22455
22456 /* By default disabled */
22457 int mce_p5_enabled __read_mostly;
22458 @@ -48,7 +49,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
22459 if (!cpu_has(c, X86_FEATURE_MCE))
22460 return;
22461
22462 + pax_open_kernel();
22463 machine_check_vector = pentium_machine_check;
22464 + pax_close_kernel();
22465 /* Make sure the vector pointer is visible before we enable MCEs: */
22466 wmb();
22467
22468 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
22469 index 7dc5564..1273569 100644
22470 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
22471 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
22472 @@ -9,6 +9,7 @@
22473 #include <asm/processor.h>
22474 #include <asm/mce.h>
22475 #include <asm/msr.h>
22476 +#include <asm/pgtable.h>
22477
22478 /* Machine check handler for WinChip C6: */
22479 static void winchip_machine_check(struct pt_regs *regs, long error_code)
22480 @@ -22,7 +23,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
22481 {
22482 u32 lo, hi;
22483
22484 + pax_open_kernel();
22485 machine_check_vector = winchip_machine_check;
22486 + pax_close_kernel();
22487 /* Make sure the vector pointer is visible before we enable MCEs: */
22488 wmb();
22489
22490 diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c
22491 index dd9d619..86e1d81 100644
22492 --- a/arch/x86/kernel/cpu/microcode/core.c
22493 +++ b/arch/x86/kernel/cpu/microcode/core.c
22494 @@ -516,7 +516,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
22495 return NOTIFY_OK;
22496 }
22497
22498 -static struct notifier_block __refdata mc_cpu_notifier = {
22499 +static struct notifier_block mc_cpu_notifier = {
22500 .notifier_call = mc_cpu_callback,
22501 };
22502
22503 diff --git a/arch/x86/kernel/cpu/microcode/intel.c b/arch/x86/kernel/cpu/microcode/intel.c
22504 index a276fa7..e66810f 100644
22505 --- a/arch/x86/kernel/cpu/microcode/intel.c
22506 +++ b/arch/x86/kernel/cpu/microcode/intel.c
22507 @@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
22508
22509 static int get_ucode_user(void *to, const void *from, size_t n)
22510 {
22511 - return copy_from_user(to, from, n);
22512 + return copy_from_user(to, (const void __force_user *)from, n);
22513 }
22514
22515 static enum ucode_state
22516 request_microcode_user(int cpu, const void __user *buf, size_t size)
22517 {
22518 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
22519 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
22520 }
22521
22522 static void microcode_fini_cpu(int cpu)
22523 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
22524 index f961de9..8a9d332 100644
22525 --- a/arch/x86/kernel/cpu/mtrr/main.c
22526 +++ b/arch/x86/kernel/cpu/mtrr/main.c
22527 @@ -66,7 +66,7 @@ static DEFINE_MUTEX(mtrr_mutex);
22528 u64 size_or_mask, size_and_mask;
22529 static bool mtrr_aps_delayed_init;
22530
22531 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
22532 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
22533
22534 const struct mtrr_ops *mtrr_if;
22535
22536 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
22537 index df5e41f..816c719 100644
22538 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
22539 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
22540 @@ -25,7 +25,7 @@ struct mtrr_ops {
22541 int (*validate_add_page)(unsigned long base, unsigned long size,
22542 unsigned int type);
22543 int (*have_wrcomb)(void);
22544 -};
22545 +} __do_const;
22546
22547 extern int generic_get_free_region(unsigned long base, unsigned long size,
22548 int replace_reg);
22549 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
22550 index 2879ecd..bb8c80b 100644
22551 --- a/arch/x86/kernel/cpu/perf_event.c
22552 +++ b/arch/x86/kernel/cpu/perf_event.c
22553 @@ -1372,7 +1372,7 @@ static void __init pmu_check_apic(void)
22554
22555 }
22556
22557 -static struct attribute_group x86_pmu_format_group = {
22558 +static attribute_group_no_const x86_pmu_format_group = {
22559 .name = "format",
22560 .attrs = NULL,
22561 };
22562 @@ -1471,7 +1471,7 @@ static struct attribute *events_attr[] = {
22563 NULL,
22564 };
22565
22566 -static struct attribute_group x86_pmu_events_group = {
22567 +static attribute_group_no_const x86_pmu_events_group = {
22568 .name = "events",
22569 .attrs = events_attr,
22570 };
22571 @@ -1995,7 +1995,7 @@ static unsigned long get_segment_base(unsigned int segment)
22572 if (idx > GDT_ENTRIES)
22573 return 0;
22574
22575 - desc = __this_cpu_ptr(&gdt_page.gdt[0]);
22576 + desc = get_cpu_gdt_table(smp_processor_id());
22577 }
22578
22579 return get_desc_base(desc + idx);
22580 @@ -2085,7 +2085,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
22581 break;
22582
22583 perf_callchain_store(entry, frame.return_address);
22584 - fp = frame.next_frame;
22585 + fp = (const void __force_user *)frame.next_frame;
22586 }
22587 }
22588
22589 diff --git a/arch/x86/kernel/cpu/perf_event_amd_iommu.c b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
22590 index 639d128..e92d7e5 100644
22591 --- a/arch/x86/kernel/cpu/perf_event_amd_iommu.c
22592 +++ b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
22593 @@ -405,7 +405,7 @@ static void perf_iommu_del(struct perf_event *event, int flags)
22594 static __init int _init_events_attrs(struct perf_amd_iommu *perf_iommu)
22595 {
22596 struct attribute **attrs;
22597 - struct attribute_group *attr_group;
22598 + attribute_group_no_const *attr_group;
22599 int i = 0, j;
22600
22601 while (amd_iommu_v2_event_descs[i].attr.attr.name)
22602 diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
22603 index 2502d0d..e5cc05c 100644
22604 --- a/arch/x86/kernel/cpu/perf_event_intel.c
22605 +++ b/arch/x86/kernel/cpu/perf_event_intel.c
22606 @@ -2353,10 +2353,10 @@ __init int intel_pmu_init(void)
22607 x86_pmu.num_counters_fixed = max((int)edx.split.num_counters_fixed, 3);
22608
22609 if (boot_cpu_has(X86_FEATURE_PDCM)) {
22610 - u64 capabilities;
22611 + u64 capabilities = x86_pmu.intel_cap.capabilities;
22612
22613 - rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
22614 - x86_pmu.intel_cap.capabilities = capabilities;
22615 + if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
22616 + x86_pmu.intel_cap.capabilities = capabilities;
22617 }
22618
22619 intel_ds_init();
22620 diff --git a/arch/x86/kernel/cpu/perf_event_intel_rapl.c b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
22621 index 619f769..d510008 100644
22622 --- a/arch/x86/kernel/cpu/perf_event_intel_rapl.c
22623 +++ b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
22624 @@ -449,7 +449,7 @@ static struct attribute *rapl_events_hsw_attr[] = {
22625 NULL,
22626 };
22627
22628 -static struct attribute_group rapl_pmu_events_group = {
22629 +static attribute_group_no_const rapl_pmu_events_group __read_only = {
22630 .name = "events",
22631 .attrs = NULL, /* patched at runtime */
22632 };
22633 diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
22634 index 0939f86..69730af 100644
22635 --- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
22636 +++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
22637 @@ -3691,7 +3691,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
22638 static int __init uncore_type_init(struct intel_uncore_type *type)
22639 {
22640 struct intel_uncore_pmu *pmus;
22641 - struct attribute_group *attr_group;
22642 + attribute_group_no_const *attr_group;
22643 struct attribute **attrs;
22644 int i, j;
22645
22646 diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
22647 index 90236f0..54cb20d 100644
22648 --- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
22649 +++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
22650 @@ -503,7 +503,7 @@ struct intel_uncore_box {
22651 struct uncore_event_desc {
22652 struct kobj_attribute attr;
22653 const char *config;
22654 -};
22655 +} __do_const;
22656
22657 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
22658 { \
22659 diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
22660 index 3225ae6c..ee3c6db 100644
22661 --- a/arch/x86/kernel/cpuid.c
22662 +++ b/arch/x86/kernel/cpuid.c
22663 @@ -170,7 +170,7 @@ static int cpuid_class_cpu_callback(struct notifier_block *nfb,
22664 return notifier_from_errno(err);
22665 }
22666
22667 -static struct notifier_block __refdata cpuid_class_cpu_notifier =
22668 +static struct notifier_block cpuid_class_cpu_notifier =
22669 {
22670 .notifier_call = cpuid_class_cpu_callback,
22671 };
22672 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
22673 index a618fcd..200e95b 100644
22674 --- a/arch/x86/kernel/crash.c
22675 +++ b/arch/x86/kernel/crash.c
22676 @@ -104,7 +104,7 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
22677 #ifdef CONFIG_X86_32
22678 struct pt_regs fixed_regs;
22679
22680 - if (!user_mode_vm(regs)) {
22681 + if (!user_mode(regs)) {
22682 crash_fixup_ss_esp(&fixed_regs, regs);
22683 regs = &fixed_regs;
22684 }
22685 diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
22686 index afa64ad..dce67dd 100644
22687 --- a/arch/x86/kernel/crash_dump_64.c
22688 +++ b/arch/x86/kernel/crash_dump_64.c
22689 @@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
22690 return -ENOMEM;
22691
22692 if (userbuf) {
22693 - if (copy_to_user(buf, vaddr + offset, csize)) {
22694 + if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
22695 iounmap(vaddr);
22696 return -EFAULT;
22697 }
22698 diff --git a/arch/x86/kernel/doublefault.c b/arch/x86/kernel/doublefault.c
22699 index f6dfd93..892ade4 100644
22700 --- a/arch/x86/kernel/doublefault.c
22701 +++ b/arch/x86/kernel/doublefault.c
22702 @@ -12,7 +12,7 @@
22703
22704 #define DOUBLEFAULT_STACKSIZE (1024)
22705 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
22706 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
22707 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
22708
22709 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
22710
22711 @@ -22,7 +22,7 @@ static void doublefault_fn(void)
22712 unsigned long gdt, tss;
22713
22714 native_store_gdt(&gdt_desc);
22715 - gdt = gdt_desc.address;
22716 + gdt = (unsigned long)gdt_desc.address;
22717
22718 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
22719
22720 @@ -59,10 +59,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
22721 /* 0x2 bit is always set */
22722 .flags = X86_EFLAGS_SF | 0x2,
22723 .sp = STACK_START,
22724 - .es = __USER_DS,
22725 + .es = __KERNEL_DS,
22726 .cs = __KERNEL_CS,
22727 .ss = __KERNEL_DS,
22728 - .ds = __USER_DS,
22729 + .ds = __KERNEL_DS,
22730 .fs = __KERNEL_PERCPU,
22731
22732 .__cr3 = __pa_nodebug(swapper_pg_dir),
22733 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
22734 index b74ebc7..2c95874 100644
22735 --- a/arch/x86/kernel/dumpstack.c
22736 +++ b/arch/x86/kernel/dumpstack.c
22737 @@ -2,6 +2,9 @@
22738 * Copyright (C) 1991, 1992 Linus Torvalds
22739 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
22740 */
22741 +#ifdef CONFIG_GRKERNSEC_HIDESYM
22742 +#define __INCLUDED_BY_HIDESYM 1
22743 +#endif
22744 #include <linux/kallsyms.h>
22745 #include <linux/kprobes.h>
22746 #include <linux/uaccess.h>
22747 @@ -33,23 +36,21 @@ static void printk_stack_address(unsigned long address, int reliable)
22748
22749 void printk_address(unsigned long address)
22750 {
22751 - pr_cont(" [<%p>] %pS\n", (void *)address, (void *)address);
22752 + pr_cont(" [<%p>] %pA\n", (void *)address, (void *)address);
22753 }
22754
22755 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
22756 static void
22757 print_ftrace_graph_addr(unsigned long addr, void *data,
22758 const struct stacktrace_ops *ops,
22759 - struct thread_info *tinfo, int *graph)
22760 + struct task_struct *task, int *graph)
22761 {
22762 - struct task_struct *task;
22763 unsigned long ret_addr;
22764 int index;
22765
22766 if (addr != (unsigned long)return_to_handler)
22767 return;
22768
22769 - task = tinfo->task;
22770 index = task->curr_ret_stack;
22771
22772 if (!task->ret_stack || index < *graph)
22773 @@ -66,7 +67,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
22774 static inline void
22775 print_ftrace_graph_addr(unsigned long addr, void *data,
22776 const struct stacktrace_ops *ops,
22777 - struct thread_info *tinfo, int *graph)
22778 + struct task_struct *task, int *graph)
22779 { }
22780 #endif
22781
22782 @@ -77,10 +78,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
22783 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
22784 */
22785
22786 -static inline int valid_stack_ptr(struct thread_info *tinfo,
22787 - void *p, unsigned int size, void *end)
22788 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
22789 {
22790 - void *t = tinfo;
22791 if (end) {
22792 if (p < end && p >= (end-THREAD_SIZE))
22793 return 1;
22794 @@ -91,14 +90,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
22795 }
22796
22797 unsigned long
22798 -print_context_stack(struct thread_info *tinfo,
22799 +print_context_stack(struct task_struct *task, void *stack_start,
22800 unsigned long *stack, unsigned long bp,
22801 const struct stacktrace_ops *ops, void *data,
22802 unsigned long *end, int *graph)
22803 {
22804 struct stack_frame *frame = (struct stack_frame *)bp;
22805
22806 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
22807 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
22808 unsigned long addr;
22809
22810 addr = *stack;
22811 @@ -110,7 +109,7 @@ print_context_stack(struct thread_info *tinfo,
22812 } else {
22813 ops->address(data, addr, 0);
22814 }
22815 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
22816 + print_ftrace_graph_addr(addr, data, ops, task, graph);
22817 }
22818 stack++;
22819 }
22820 @@ -119,7 +118,7 @@ print_context_stack(struct thread_info *tinfo,
22821 EXPORT_SYMBOL_GPL(print_context_stack);
22822
22823 unsigned long
22824 -print_context_stack_bp(struct thread_info *tinfo,
22825 +print_context_stack_bp(struct task_struct *task, void *stack_start,
22826 unsigned long *stack, unsigned long bp,
22827 const struct stacktrace_ops *ops, void *data,
22828 unsigned long *end, int *graph)
22829 @@ -127,7 +126,7 @@ print_context_stack_bp(struct thread_info *tinfo,
22830 struct stack_frame *frame = (struct stack_frame *)bp;
22831 unsigned long *ret_addr = &frame->return_address;
22832
22833 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
22834 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
22835 unsigned long addr = *ret_addr;
22836
22837 if (!__kernel_text_address(addr))
22838 @@ -136,7 +135,7 @@ print_context_stack_bp(struct thread_info *tinfo,
22839 ops->address(data, addr, 1);
22840 frame = frame->next_frame;
22841 ret_addr = &frame->return_address;
22842 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
22843 + print_ftrace_graph_addr(addr, data, ops, task, graph);
22844 }
22845
22846 return (unsigned long)frame;
22847 @@ -155,7 +154,7 @@ static int print_trace_stack(void *data, char *name)
22848 static void print_trace_address(void *data, unsigned long addr, int reliable)
22849 {
22850 touch_nmi_watchdog();
22851 - printk(data);
22852 + printk("%s", (char *)data);
22853 printk_stack_address(addr, reliable);
22854 }
22855
22856 @@ -225,6 +224,8 @@ unsigned long oops_begin(void)
22857 EXPORT_SYMBOL_GPL(oops_begin);
22858 NOKPROBE_SYMBOL(oops_begin);
22859
22860 +extern void gr_handle_kernel_exploit(void);
22861 +
22862 void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
22863 {
22864 if (regs && kexec_should_crash(current))
22865 @@ -246,7 +247,10 @@ void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
22866 panic("Fatal exception in interrupt");
22867 if (panic_on_oops)
22868 panic("Fatal exception");
22869 - do_exit(signr);
22870 +
22871 + gr_handle_kernel_exploit();
22872 +
22873 + do_group_exit(signr);
22874 }
22875 NOKPROBE_SYMBOL(oops_end);
22876
22877 @@ -275,7 +279,7 @@ int __die(const char *str, struct pt_regs *regs, long err)
22878 print_modules();
22879 show_regs(regs);
22880 #ifdef CONFIG_X86_32
22881 - if (user_mode_vm(regs)) {
22882 + if (user_mode(regs)) {
22883 sp = regs->sp;
22884 ss = regs->ss & 0xffff;
22885 } else {
22886 @@ -304,7 +308,7 @@ void die(const char *str, struct pt_regs *regs, long err)
22887 unsigned long flags = oops_begin();
22888 int sig = SIGSEGV;
22889
22890 - if (!user_mode_vm(regs))
22891 + if (!user_mode(regs))
22892 report_bug(regs->ip, regs);
22893
22894 if (__die(str, regs, err))
22895 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
22896 index 5abd4cd..c65733b 100644
22897 --- a/arch/x86/kernel/dumpstack_32.c
22898 +++ b/arch/x86/kernel/dumpstack_32.c
22899 @@ -61,15 +61,14 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22900 bp = stack_frame(task, regs);
22901
22902 for (;;) {
22903 - struct thread_info *context;
22904 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
22905 void *end_stack;
22906
22907 end_stack = is_hardirq_stack(stack, cpu);
22908 if (!end_stack)
22909 end_stack = is_softirq_stack(stack, cpu);
22910
22911 - context = task_thread_info(task);
22912 - bp = ops->walk_stack(context, stack, bp, ops, data,
22913 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data,
22914 end_stack, &graph);
22915
22916 /* Stop if not on irq stack */
22917 @@ -123,27 +122,28 @@ void show_regs(struct pt_regs *regs)
22918 int i;
22919
22920 show_regs_print_info(KERN_EMERG);
22921 - __show_regs(regs, !user_mode_vm(regs));
22922 + __show_regs(regs, !user_mode(regs));
22923
22924 /*
22925 * When in-kernel, we also print out the stack and code at the
22926 * time of the fault..
22927 */
22928 - if (!user_mode_vm(regs)) {
22929 + if (!user_mode(regs)) {
22930 unsigned int code_prologue = code_bytes * 43 / 64;
22931 unsigned int code_len = code_bytes;
22932 unsigned char c;
22933 u8 *ip;
22934 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
22935
22936 pr_emerg("Stack:\n");
22937 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
22938
22939 pr_emerg("Code:");
22940
22941 - ip = (u8 *)regs->ip - code_prologue;
22942 + ip = (u8 *)regs->ip - code_prologue + cs_base;
22943 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
22944 /* try starting at IP */
22945 - ip = (u8 *)regs->ip;
22946 + ip = (u8 *)regs->ip + cs_base;
22947 code_len = code_len - code_prologue + 1;
22948 }
22949 for (i = 0; i < code_len; i++, ip++) {
22950 @@ -152,7 +152,7 @@ void show_regs(struct pt_regs *regs)
22951 pr_cont(" Bad EIP value.");
22952 break;
22953 }
22954 - if (ip == (u8 *)regs->ip)
22955 + if (ip == (u8 *)regs->ip + cs_base)
22956 pr_cont(" <%02x>", c);
22957 else
22958 pr_cont(" %02x", c);
22959 @@ -165,6 +165,7 @@ int is_valid_bugaddr(unsigned long ip)
22960 {
22961 unsigned short ud2;
22962
22963 + ip = ktla_ktva(ip);
22964 if (ip < PAGE_OFFSET)
22965 return 0;
22966 if (probe_kernel_address((unsigned short *)ip, ud2))
22967 @@ -172,3 +173,15 @@ int is_valid_bugaddr(unsigned long ip)
22968
22969 return ud2 == 0x0b0f;
22970 }
22971 +
22972 +#if defined(CONFIG_PAX_MEMORY_STACKLEAK) || defined(CONFIG_PAX_USERCOPY)
22973 +void pax_check_alloca(unsigned long size)
22974 +{
22975 + unsigned long sp = (unsigned long)&sp, stack_left;
22976 +
22977 + /* all kernel stacks are of the same size */
22978 + stack_left = sp & (THREAD_SIZE - 1);
22979 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
22980 +}
22981 +EXPORT_SYMBOL(pax_check_alloca);
22982 +#endif
22983 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
22984 index ff86f19..a20c62c 100644
22985 --- a/arch/x86/kernel/dumpstack_64.c
22986 +++ b/arch/x86/kernel/dumpstack_64.c
22987 @@ -153,12 +153,12 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22988 const struct stacktrace_ops *ops, void *data)
22989 {
22990 const unsigned cpu = get_cpu();
22991 - struct thread_info *tinfo;
22992 unsigned long *irq_stack = (unsigned long *)per_cpu(irq_stack_ptr, cpu);
22993 unsigned long dummy;
22994 unsigned used = 0;
22995 int graph = 0;
22996 int done = 0;
22997 + void *stack_start;
22998
22999 if (!task)
23000 task = current;
23001 @@ -179,7 +179,6 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
23002 * current stack address. If the stacks consist of nested
23003 * exceptions
23004 */
23005 - tinfo = task_thread_info(task);
23006 while (!done) {
23007 unsigned long *stack_end;
23008 enum stack_type stype;
23009 @@ -202,7 +201,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
23010 if (ops->stack(data, id) < 0)
23011 break;
23012
23013 - bp = ops->walk_stack(tinfo, stack, bp, ops,
23014 + bp = ops->walk_stack(task, stack_end - EXCEPTION_STKSZ, stack, bp, ops,
23015 data, stack_end, &graph);
23016 ops->stack(data, "<EOE>");
23017 /*
23018 @@ -210,6 +209,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
23019 * second-to-last pointer (index -2 to end) in the
23020 * exception stack:
23021 */
23022 + if ((u16)stack_end[-1] != __KERNEL_DS)
23023 + goto out;
23024 stack = (unsigned long *) stack_end[-2];
23025 done = 0;
23026 break;
23027 @@ -218,7 +219,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
23028
23029 if (ops->stack(data, "IRQ") < 0)
23030 break;
23031 - bp = ops->walk_stack(tinfo, stack, bp,
23032 + bp = ops->walk_stack(task, irq_stack, stack, bp,
23033 ops, data, stack_end, &graph);
23034 /*
23035 * We link to the next stack (which would be
23036 @@ -240,7 +241,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
23037 /*
23038 * This handles the process stack:
23039 */
23040 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
23041 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
23042 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
23043 +out:
23044 put_cpu();
23045 }
23046 EXPORT_SYMBOL(dump_trace);
23047 @@ -349,3 +352,50 @@ int is_valid_bugaddr(unsigned long ip)
23048
23049 return ud2 == 0x0b0f;
23050 }
23051 +
23052 +#if defined(CONFIG_PAX_MEMORY_STACKLEAK) || defined(CONFIG_PAX_USERCOPY)
23053 +void pax_check_alloca(unsigned long size)
23054 +{
23055 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
23056 + unsigned cpu, used;
23057 + char *id;
23058 +
23059 + /* check the process stack first */
23060 + stack_start = (unsigned long)task_stack_page(current);
23061 + stack_end = stack_start + THREAD_SIZE;
23062 + if (likely(stack_start <= sp && sp < stack_end)) {
23063 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
23064 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
23065 + return;
23066 + }
23067 +
23068 + cpu = get_cpu();
23069 +
23070 + /* check the irq stacks */
23071 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
23072 + stack_start = stack_end - IRQ_STACK_SIZE;
23073 + if (stack_start <= sp && sp < stack_end) {
23074 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
23075 + put_cpu();
23076 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
23077 + return;
23078 + }
23079 +
23080 + /* check the exception stacks */
23081 + used = 0;
23082 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
23083 + stack_start = stack_end - EXCEPTION_STKSZ;
23084 + if (stack_end && stack_start <= sp && sp < stack_end) {
23085 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
23086 + put_cpu();
23087 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
23088 + return;
23089 + }
23090 +
23091 + put_cpu();
23092 +
23093 + /* unknown stack */
23094 + BUG();
23095 +}
23096 +EXPORT_SYMBOL(pax_check_alloca);
23097 +#endif
23098 diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
23099 index 988c00a..4f673b6 100644
23100 --- a/arch/x86/kernel/e820.c
23101 +++ b/arch/x86/kernel/e820.c
23102 @@ -803,8 +803,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
23103
23104 static void early_panic(char *msg)
23105 {
23106 - early_printk(msg);
23107 - panic(msg);
23108 + early_printk("%s", msg);
23109 + panic("%s", msg);
23110 }
23111
23112 static int userdef __initdata;
23113 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
23114 index 01d1c18..8073693 100644
23115 --- a/arch/x86/kernel/early_printk.c
23116 +++ b/arch/x86/kernel/early_printk.c
23117 @@ -7,6 +7,7 @@
23118 #include <linux/pci_regs.h>
23119 #include <linux/pci_ids.h>
23120 #include <linux/errno.h>
23121 +#include <linux/sched.h>
23122 #include <asm/io.h>
23123 #include <asm/processor.h>
23124 #include <asm/fcntl.h>
23125 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
23126 index 4b0e1df..884b67e 100644
23127 --- a/arch/x86/kernel/entry_32.S
23128 +++ b/arch/x86/kernel/entry_32.S
23129 @@ -177,13 +177,153 @@
23130 /*CFI_REL_OFFSET gs, PT_GS*/
23131 .endm
23132 .macro SET_KERNEL_GS reg
23133 +
23134 +#ifdef CONFIG_CC_STACKPROTECTOR
23135 movl $(__KERNEL_STACK_CANARY), \reg
23136 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
23137 + movl $(__USER_DS), \reg
23138 +#else
23139 + xorl \reg, \reg
23140 +#endif
23141 +
23142 movl \reg, %gs
23143 .endm
23144
23145 #endif /* CONFIG_X86_32_LAZY_GS */
23146
23147 -.macro SAVE_ALL
23148 +.macro pax_enter_kernel
23149 +#ifdef CONFIG_PAX_KERNEXEC
23150 + call pax_enter_kernel
23151 +#endif
23152 +.endm
23153 +
23154 +.macro pax_exit_kernel
23155 +#ifdef CONFIG_PAX_KERNEXEC
23156 + call pax_exit_kernel
23157 +#endif
23158 +.endm
23159 +
23160 +#ifdef CONFIG_PAX_KERNEXEC
23161 +ENTRY(pax_enter_kernel)
23162 +#ifdef CONFIG_PARAVIRT
23163 + pushl %eax
23164 + pushl %ecx
23165 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
23166 + mov %eax, %esi
23167 +#else
23168 + mov %cr0, %esi
23169 +#endif
23170 + bts $16, %esi
23171 + jnc 1f
23172 + mov %cs, %esi
23173 + cmp $__KERNEL_CS, %esi
23174 + jz 3f
23175 + ljmp $__KERNEL_CS, $3f
23176 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
23177 +2:
23178 +#ifdef CONFIG_PARAVIRT
23179 + mov %esi, %eax
23180 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
23181 +#else
23182 + mov %esi, %cr0
23183 +#endif
23184 +3:
23185 +#ifdef CONFIG_PARAVIRT
23186 + popl %ecx
23187 + popl %eax
23188 +#endif
23189 + ret
23190 +ENDPROC(pax_enter_kernel)
23191 +
23192 +ENTRY(pax_exit_kernel)
23193 +#ifdef CONFIG_PARAVIRT
23194 + pushl %eax
23195 + pushl %ecx
23196 +#endif
23197 + mov %cs, %esi
23198 + cmp $__KERNEXEC_KERNEL_CS, %esi
23199 + jnz 2f
23200 +#ifdef CONFIG_PARAVIRT
23201 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
23202 + mov %eax, %esi
23203 +#else
23204 + mov %cr0, %esi
23205 +#endif
23206 + btr $16, %esi
23207 + ljmp $__KERNEL_CS, $1f
23208 +1:
23209 +#ifdef CONFIG_PARAVIRT
23210 + mov %esi, %eax
23211 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
23212 +#else
23213 + mov %esi, %cr0
23214 +#endif
23215 +2:
23216 +#ifdef CONFIG_PARAVIRT
23217 + popl %ecx
23218 + popl %eax
23219 +#endif
23220 + ret
23221 +ENDPROC(pax_exit_kernel)
23222 +#endif
23223 +
23224 + .macro pax_erase_kstack
23225 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23226 + call pax_erase_kstack
23227 +#endif
23228 + .endm
23229 +
23230 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23231 +/*
23232 + * ebp: thread_info
23233 + */
23234 +ENTRY(pax_erase_kstack)
23235 + pushl %edi
23236 + pushl %ecx
23237 + pushl %eax
23238 +
23239 + mov TI_lowest_stack(%ebp), %edi
23240 + mov $-0xBEEF, %eax
23241 + std
23242 +
23243 +1: mov %edi, %ecx
23244 + and $THREAD_SIZE_asm - 1, %ecx
23245 + shr $2, %ecx
23246 + repne scasl
23247 + jecxz 2f
23248 +
23249 + cmp $2*16, %ecx
23250 + jc 2f
23251 +
23252 + mov $2*16, %ecx
23253 + repe scasl
23254 + jecxz 2f
23255 + jne 1b
23256 +
23257 +2: cld
23258 + mov %esp, %ecx
23259 + sub %edi, %ecx
23260 +
23261 + cmp $THREAD_SIZE_asm, %ecx
23262 + jb 3f
23263 + ud2
23264 +3:
23265 +
23266 + shr $2, %ecx
23267 + rep stosl
23268 +
23269 + mov TI_task_thread_sp0(%ebp), %edi
23270 + sub $128, %edi
23271 + mov %edi, TI_lowest_stack(%ebp)
23272 +
23273 + popl %eax
23274 + popl %ecx
23275 + popl %edi
23276 + ret
23277 +ENDPROC(pax_erase_kstack)
23278 +#endif
23279 +
23280 +.macro __SAVE_ALL _DS
23281 cld
23282 PUSH_GS
23283 pushl_cfi %fs
23284 @@ -206,7 +346,7 @@
23285 CFI_REL_OFFSET ecx, 0
23286 pushl_cfi %ebx
23287 CFI_REL_OFFSET ebx, 0
23288 - movl $(__USER_DS), %edx
23289 + movl $\_DS, %edx
23290 movl %edx, %ds
23291 movl %edx, %es
23292 movl $(__KERNEL_PERCPU), %edx
23293 @@ -214,6 +354,15 @@
23294 SET_KERNEL_GS %edx
23295 .endm
23296
23297 +.macro SAVE_ALL
23298 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23299 + __SAVE_ALL __KERNEL_DS
23300 + pax_enter_kernel
23301 +#else
23302 + __SAVE_ALL __USER_DS
23303 +#endif
23304 +.endm
23305 +
23306 .macro RESTORE_INT_REGS
23307 popl_cfi %ebx
23308 CFI_RESTORE ebx
23309 @@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
23310 popfl_cfi
23311 jmp syscall_exit
23312 CFI_ENDPROC
23313 -END(ret_from_fork)
23314 +ENDPROC(ret_from_fork)
23315
23316 ENTRY(ret_from_kernel_thread)
23317 CFI_STARTPROC
23318 @@ -340,7 +489,15 @@ ret_from_intr:
23319 andl $SEGMENT_RPL_MASK, %eax
23320 #endif
23321 cmpl $USER_RPL, %eax
23322 +
23323 +#ifdef CONFIG_PAX_KERNEXEC
23324 + jae resume_userspace
23325 +
23326 + pax_exit_kernel
23327 + jmp resume_kernel
23328 +#else
23329 jb resume_kernel # not returning to v8086 or userspace
23330 +#endif
23331
23332 ENTRY(resume_userspace)
23333 LOCKDEP_SYS_EXIT
23334 @@ -352,8 +509,8 @@ ENTRY(resume_userspace)
23335 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
23336 # int/exception return?
23337 jne work_pending
23338 - jmp restore_all
23339 -END(ret_from_exception)
23340 + jmp restore_all_pax
23341 +ENDPROC(ret_from_exception)
23342
23343 #ifdef CONFIG_PREEMPT
23344 ENTRY(resume_kernel)
23345 @@ -365,7 +522,7 @@ need_resched:
23346 jz restore_all
23347 call preempt_schedule_irq
23348 jmp need_resched
23349 -END(resume_kernel)
23350 +ENDPROC(resume_kernel)
23351 #endif
23352 CFI_ENDPROC
23353
23354 @@ -395,30 +552,45 @@ sysenter_past_esp:
23355 /*CFI_REL_OFFSET cs, 0*/
23356 /*
23357 * Push current_thread_info()->sysenter_return to the stack.
23358 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
23359 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
23360 */
23361 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
23362 + pushl_cfi $0
23363 CFI_REL_OFFSET eip, 0
23364
23365 pushl_cfi %eax
23366 SAVE_ALL
23367 + GET_THREAD_INFO(%ebp)
23368 + movl TI_sysenter_return(%ebp),%ebp
23369 + movl %ebp,PT_EIP(%esp)
23370 ENABLE_INTERRUPTS(CLBR_NONE)
23371
23372 /*
23373 * Load the potential sixth argument from user stack.
23374 * Careful about security.
23375 */
23376 + movl PT_OLDESP(%esp),%ebp
23377 +
23378 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23379 + mov PT_OLDSS(%esp),%ds
23380 +1: movl %ds:(%ebp),%ebp
23381 + push %ss
23382 + pop %ds
23383 +#else
23384 cmpl $__PAGE_OFFSET-3,%ebp
23385 jae syscall_fault
23386 ASM_STAC
23387 1: movl (%ebp),%ebp
23388 ASM_CLAC
23389 +#endif
23390 +
23391 movl %ebp,PT_EBP(%esp)
23392 _ASM_EXTABLE(1b,syscall_fault)
23393
23394 GET_THREAD_INFO(%ebp)
23395
23396 +#ifdef CONFIG_PAX_RANDKSTACK
23397 + pax_erase_kstack
23398 +#endif
23399 +
23400 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
23401 jnz sysenter_audit
23402 sysenter_do_call:
23403 @@ -434,12 +606,24 @@ sysenter_after_call:
23404 testl $_TIF_ALLWORK_MASK, %ecx
23405 jne sysexit_audit
23406 sysenter_exit:
23407 +
23408 +#ifdef CONFIG_PAX_RANDKSTACK
23409 + pushl_cfi %eax
23410 + movl %esp, %eax
23411 + call pax_randomize_kstack
23412 + popl_cfi %eax
23413 +#endif
23414 +
23415 + pax_erase_kstack
23416 +
23417 /* if something modifies registers it must also disable sysexit */
23418 movl PT_EIP(%esp), %edx
23419 movl PT_OLDESP(%esp), %ecx
23420 xorl %ebp,%ebp
23421 TRACE_IRQS_ON
23422 1: mov PT_FS(%esp), %fs
23423 +2: mov PT_DS(%esp), %ds
23424 +3: mov PT_ES(%esp), %es
23425 PTGS_TO_GS
23426 ENABLE_INTERRUPTS_SYSEXIT
23427
23428 @@ -456,6 +640,9 @@ sysenter_audit:
23429 movl %eax,%edx /* 2nd arg: syscall number */
23430 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
23431 call __audit_syscall_entry
23432 +
23433 + pax_erase_kstack
23434 +
23435 pushl_cfi %ebx
23436 movl PT_EAX(%esp),%eax /* reload syscall number */
23437 jmp sysenter_do_call
23438 @@ -481,10 +668,16 @@ sysexit_audit:
23439
23440 CFI_ENDPROC
23441 .pushsection .fixup,"ax"
23442 -2: movl $0,PT_FS(%esp)
23443 +4: movl $0,PT_FS(%esp)
23444 + jmp 1b
23445 +5: movl $0,PT_DS(%esp)
23446 + jmp 1b
23447 +6: movl $0,PT_ES(%esp)
23448 jmp 1b
23449 .popsection
23450 - _ASM_EXTABLE(1b,2b)
23451 + _ASM_EXTABLE(1b,4b)
23452 + _ASM_EXTABLE(2b,5b)
23453 + _ASM_EXTABLE(3b,6b)
23454 PTGS_TO_GS_EX
23455 ENDPROC(ia32_sysenter_target)
23456
23457 @@ -495,6 +688,11 @@ ENTRY(system_call)
23458 pushl_cfi %eax # save orig_eax
23459 SAVE_ALL
23460 GET_THREAD_INFO(%ebp)
23461 +
23462 +#ifdef CONFIG_PAX_RANDKSTACK
23463 + pax_erase_kstack
23464 +#endif
23465 +
23466 # system call tracing in operation / emulation
23467 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
23468 jnz syscall_trace_entry
23469 @@ -514,6 +712,15 @@ syscall_exit:
23470 testl $_TIF_ALLWORK_MASK, %ecx # current->work
23471 jne syscall_exit_work
23472
23473 +restore_all_pax:
23474 +
23475 +#ifdef CONFIG_PAX_RANDKSTACK
23476 + movl %esp, %eax
23477 + call pax_randomize_kstack
23478 +#endif
23479 +
23480 + pax_erase_kstack
23481 +
23482 restore_all:
23483 TRACE_IRQS_IRET
23484 restore_all_notrace:
23485 @@ -568,14 +775,34 @@ ldt_ss:
23486 * compensating for the offset by changing to the ESPFIX segment with
23487 * a base address that matches for the difference.
23488 */
23489 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
23490 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
23491 mov %esp, %edx /* load kernel esp */
23492 mov PT_OLDESP(%esp), %eax /* load userspace esp */
23493 mov %dx, %ax /* eax: new kernel esp */
23494 sub %eax, %edx /* offset (low word is 0) */
23495 +#ifdef CONFIG_SMP
23496 + movl PER_CPU_VAR(cpu_number), %ebx
23497 + shll $PAGE_SHIFT_asm, %ebx
23498 + addl $cpu_gdt_table, %ebx
23499 +#else
23500 + movl $cpu_gdt_table, %ebx
23501 +#endif
23502 shr $16, %edx
23503 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
23504 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
23505 +
23506 +#ifdef CONFIG_PAX_KERNEXEC
23507 + mov %cr0, %esi
23508 + btr $16, %esi
23509 + mov %esi, %cr0
23510 +#endif
23511 +
23512 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
23513 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
23514 +
23515 +#ifdef CONFIG_PAX_KERNEXEC
23516 + bts $16, %esi
23517 + mov %esi, %cr0
23518 +#endif
23519 +
23520 pushl_cfi $__ESPFIX_SS
23521 pushl_cfi %eax /* new kernel esp */
23522 /* Disable interrupts, but do not irqtrace this section: we
23523 @@ -605,20 +832,18 @@ work_resched:
23524 movl TI_flags(%ebp), %ecx
23525 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
23526 # than syscall tracing?
23527 - jz restore_all
23528 + jz restore_all_pax
23529 testb $_TIF_NEED_RESCHED, %cl
23530 jnz work_resched
23531
23532 work_notifysig: # deal with pending signals and
23533 # notify-resume requests
23534 + movl %esp, %eax
23535 #ifdef CONFIG_VM86
23536 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
23537 - movl %esp, %eax
23538 jne work_notifysig_v86 # returning to kernel-space or
23539 # vm86-space
23540 1:
23541 -#else
23542 - movl %esp, %eax
23543 #endif
23544 TRACE_IRQS_ON
23545 ENABLE_INTERRUPTS(CLBR_NONE)
23546 @@ -639,7 +864,7 @@ work_notifysig_v86:
23547 movl %eax, %esp
23548 jmp 1b
23549 #endif
23550 -END(work_pending)
23551 +ENDPROC(work_pending)
23552
23553 # perform syscall exit tracing
23554 ALIGN
23555 @@ -647,11 +872,14 @@ syscall_trace_entry:
23556 movl $-ENOSYS,PT_EAX(%esp)
23557 movl %esp, %eax
23558 call syscall_trace_enter
23559 +
23560 + pax_erase_kstack
23561 +
23562 /* What it returned is what we'll actually use. */
23563 cmpl $(NR_syscalls), %eax
23564 jnae syscall_call
23565 jmp syscall_exit
23566 -END(syscall_trace_entry)
23567 +ENDPROC(syscall_trace_entry)
23568
23569 # perform syscall exit tracing
23570 ALIGN
23571 @@ -664,26 +892,30 @@ syscall_exit_work:
23572 movl %esp, %eax
23573 call syscall_trace_leave
23574 jmp resume_userspace
23575 -END(syscall_exit_work)
23576 +ENDPROC(syscall_exit_work)
23577 CFI_ENDPROC
23578
23579 RING0_INT_FRAME # can't unwind into user space anyway
23580 syscall_fault:
23581 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23582 + push %ss
23583 + pop %ds
23584 +#endif
23585 ASM_CLAC
23586 GET_THREAD_INFO(%ebp)
23587 movl $-EFAULT,PT_EAX(%esp)
23588 jmp resume_userspace
23589 -END(syscall_fault)
23590 +ENDPROC(syscall_fault)
23591
23592 syscall_badsys:
23593 movl $-ENOSYS,%eax
23594 jmp syscall_after_call
23595 -END(syscall_badsys)
23596 +ENDPROC(syscall_badsys)
23597
23598 sysenter_badsys:
23599 movl $-ENOSYS,%eax
23600 jmp sysenter_after_call
23601 -END(sysenter_badsys)
23602 +ENDPROC(sysenter_badsys)
23603 CFI_ENDPROC
23604
23605 .macro FIXUP_ESPFIX_STACK
23606 @@ -696,8 +928,15 @@ END(sysenter_badsys)
23607 */
23608 #ifdef CONFIG_X86_ESPFIX32
23609 /* fixup the stack */
23610 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
23611 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
23612 +#ifdef CONFIG_SMP
23613 + movl PER_CPU_VAR(cpu_number), %ebx
23614 + shll $PAGE_SHIFT_asm, %ebx
23615 + addl $cpu_gdt_table, %ebx
23616 +#else
23617 + movl $cpu_gdt_table, %ebx
23618 +#endif
23619 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
23620 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
23621 shl $16, %eax
23622 addl %esp, %eax /* the adjusted stack pointer */
23623 pushl_cfi $__KERNEL_DS
23624 @@ -753,7 +992,7 @@ vector=vector+1
23625 .endr
23626 2: jmp common_interrupt
23627 .endr
23628 -END(irq_entries_start)
23629 +ENDPROC(irq_entries_start)
23630
23631 .previous
23632 END(interrupt)
23633 @@ -810,7 +1049,7 @@ ENTRY(coprocessor_error)
23634 pushl_cfi $do_coprocessor_error
23635 jmp error_code
23636 CFI_ENDPROC
23637 -END(coprocessor_error)
23638 +ENDPROC(coprocessor_error)
23639
23640 ENTRY(simd_coprocessor_error)
23641 RING0_INT_FRAME
23642 @@ -823,7 +1062,7 @@ ENTRY(simd_coprocessor_error)
23643 .section .altinstructions,"a"
23644 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
23645 .previous
23646 -.section .altinstr_replacement,"ax"
23647 +.section .altinstr_replacement,"a"
23648 663: pushl $do_simd_coprocessor_error
23649 664:
23650 .previous
23651 @@ -832,7 +1071,7 @@ ENTRY(simd_coprocessor_error)
23652 #endif
23653 jmp error_code
23654 CFI_ENDPROC
23655 -END(simd_coprocessor_error)
23656 +ENDPROC(simd_coprocessor_error)
23657
23658 ENTRY(device_not_available)
23659 RING0_INT_FRAME
23660 @@ -841,18 +1080,18 @@ ENTRY(device_not_available)
23661 pushl_cfi $do_device_not_available
23662 jmp error_code
23663 CFI_ENDPROC
23664 -END(device_not_available)
23665 +ENDPROC(device_not_available)
23666
23667 #ifdef CONFIG_PARAVIRT
23668 ENTRY(native_iret)
23669 iret
23670 _ASM_EXTABLE(native_iret, iret_exc)
23671 -END(native_iret)
23672 +ENDPROC(native_iret)
23673
23674 ENTRY(native_irq_enable_sysexit)
23675 sti
23676 sysexit
23677 -END(native_irq_enable_sysexit)
23678 +ENDPROC(native_irq_enable_sysexit)
23679 #endif
23680
23681 ENTRY(overflow)
23682 @@ -862,7 +1101,7 @@ ENTRY(overflow)
23683 pushl_cfi $do_overflow
23684 jmp error_code
23685 CFI_ENDPROC
23686 -END(overflow)
23687 +ENDPROC(overflow)
23688
23689 ENTRY(bounds)
23690 RING0_INT_FRAME
23691 @@ -871,7 +1110,7 @@ ENTRY(bounds)
23692 pushl_cfi $do_bounds
23693 jmp error_code
23694 CFI_ENDPROC
23695 -END(bounds)
23696 +ENDPROC(bounds)
23697
23698 ENTRY(invalid_op)
23699 RING0_INT_FRAME
23700 @@ -880,7 +1119,7 @@ ENTRY(invalid_op)
23701 pushl_cfi $do_invalid_op
23702 jmp error_code
23703 CFI_ENDPROC
23704 -END(invalid_op)
23705 +ENDPROC(invalid_op)
23706
23707 ENTRY(coprocessor_segment_overrun)
23708 RING0_INT_FRAME
23709 @@ -889,7 +1128,7 @@ ENTRY(coprocessor_segment_overrun)
23710 pushl_cfi $do_coprocessor_segment_overrun
23711 jmp error_code
23712 CFI_ENDPROC
23713 -END(coprocessor_segment_overrun)
23714 +ENDPROC(coprocessor_segment_overrun)
23715
23716 ENTRY(invalid_TSS)
23717 RING0_EC_FRAME
23718 @@ -897,7 +1136,7 @@ ENTRY(invalid_TSS)
23719 pushl_cfi $do_invalid_TSS
23720 jmp error_code
23721 CFI_ENDPROC
23722 -END(invalid_TSS)
23723 +ENDPROC(invalid_TSS)
23724
23725 ENTRY(segment_not_present)
23726 RING0_EC_FRAME
23727 @@ -905,7 +1144,7 @@ ENTRY(segment_not_present)
23728 pushl_cfi $do_segment_not_present
23729 jmp error_code
23730 CFI_ENDPROC
23731 -END(segment_not_present)
23732 +ENDPROC(segment_not_present)
23733
23734 ENTRY(stack_segment)
23735 RING0_EC_FRAME
23736 @@ -913,7 +1152,7 @@ ENTRY(stack_segment)
23737 pushl_cfi $do_stack_segment
23738 jmp error_code
23739 CFI_ENDPROC
23740 -END(stack_segment)
23741 +ENDPROC(stack_segment)
23742
23743 ENTRY(alignment_check)
23744 RING0_EC_FRAME
23745 @@ -921,7 +1160,7 @@ ENTRY(alignment_check)
23746 pushl_cfi $do_alignment_check
23747 jmp error_code
23748 CFI_ENDPROC
23749 -END(alignment_check)
23750 +ENDPROC(alignment_check)
23751
23752 ENTRY(divide_error)
23753 RING0_INT_FRAME
23754 @@ -930,7 +1169,7 @@ ENTRY(divide_error)
23755 pushl_cfi $do_divide_error
23756 jmp error_code
23757 CFI_ENDPROC
23758 -END(divide_error)
23759 +ENDPROC(divide_error)
23760
23761 #ifdef CONFIG_X86_MCE
23762 ENTRY(machine_check)
23763 @@ -940,7 +1179,7 @@ ENTRY(machine_check)
23764 pushl_cfi machine_check_vector
23765 jmp error_code
23766 CFI_ENDPROC
23767 -END(machine_check)
23768 +ENDPROC(machine_check)
23769 #endif
23770
23771 ENTRY(spurious_interrupt_bug)
23772 @@ -950,7 +1189,7 @@ ENTRY(spurious_interrupt_bug)
23773 pushl_cfi $do_spurious_interrupt_bug
23774 jmp error_code
23775 CFI_ENDPROC
23776 -END(spurious_interrupt_bug)
23777 +ENDPROC(spurious_interrupt_bug)
23778
23779 #ifdef CONFIG_XEN
23780 /* Xen doesn't set %esp to be precisely what the normal sysenter
23781 @@ -1056,7 +1295,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
23782
23783 ENTRY(mcount)
23784 ret
23785 -END(mcount)
23786 +ENDPROC(mcount)
23787
23788 ENTRY(ftrace_caller)
23789 pushl %eax
23790 @@ -1086,7 +1325,7 @@ ftrace_graph_call:
23791 .globl ftrace_stub
23792 ftrace_stub:
23793 ret
23794 -END(ftrace_caller)
23795 +ENDPROC(ftrace_caller)
23796
23797 ENTRY(ftrace_regs_caller)
23798 pushf /* push flags before compare (in cs location) */
23799 @@ -1184,7 +1423,7 @@ trace:
23800 popl %ecx
23801 popl %eax
23802 jmp ftrace_stub
23803 -END(mcount)
23804 +ENDPROC(mcount)
23805 #endif /* CONFIG_DYNAMIC_FTRACE */
23806 #endif /* CONFIG_FUNCTION_TRACER */
23807
23808 @@ -1202,7 +1441,7 @@ ENTRY(ftrace_graph_caller)
23809 popl %ecx
23810 popl %eax
23811 ret
23812 -END(ftrace_graph_caller)
23813 +ENDPROC(ftrace_graph_caller)
23814
23815 .globl return_to_handler
23816 return_to_handler:
23817 @@ -1263,15 +1502,18 @@ error_code:
23818 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
23819 REG_TO_PTGS %ecx
23820 SET_KERNEL_GS %ecx
23821 - movl $(__USER_DS), %ecx
23822 + movl $(__KERNEL_DS), %ecx
23823 movl %ecx, %ds
23824 movl %ecx, %es
23825 +
23826 + pax_enter_kernel
23827 +
23828 TRACE_IRQS_OFF
23829 movl %esp,%eax # pt_regs pointer
23830 call *%edi
23831 jmp ret_from_exception
23832 CFI_ENDPROC
23833 -END(page_fault)
23834 +ENDPROC(page_fault)
23835
23836 /*
23837 * Debug traps and NMI can happen at the one SYSENTER instruction
23838 @@ -1314,7 +1556,7 @@ debug_stack_correct:
23839 call do_debug
23840 jmp ret_from_exception
23841 CFI_ENDPROC
23842 -END(debug)
23843 +ENDPROC(debug)
23844
23845 /*
23846 * NMI is doubly nasty. It can happen _while_ we're handling
23847 @@ -1354,6 +1596,9 @@ nmi_stack_correct:
23848 xorl %edx,%edx # zero error code
23849 movl %esp,%eax # pt_regs pointer
23850 call do_nmi
23851 +
23852 + pax_exit_kernel
23853 +
23854 jmp restore_all_notrace
23855 CFI_ENDPROC
23856
23857 @@ -1391,13 +1636,16 @@ nmi_espfix_stack:
23858 FIXUP_ESPFIX_STACK # %eax == %esp
23859 xorl %edx,%edx # zero error code
23860 call do_nmi
23861 +
23862 + pax_exit_kernel
23863 +
23864 RESTORE_REGS
23865 lss 12+4(%esp), %esp # back to espfix stack
23866 CFI_ADJUST_CFA_OFFSET -24
23867 jmp irq_return
23868 #endif
23869 CFI_ENDPROC
23870 -END(nmi)
23871 +ENDPROC(nmi)
23872
23873 ENTRY(int3)
23874 RING0_INT_FRAME
23875 @@ -1410,14 +1658,14 @@ ENTRY(int3)
23876 call do_int3
23877 jmp ret_from_exception
23878 CFI_ENDPROC
23879 -END(int3)
23880 +ENDPROC(int3)
23881
23882 ENTRY(general_protection)
23883 RING0_EC_FRAME
23884 pushl_cfi $do_general_protection
23885 jmp error_code
23886 CFI_ENDPROC
23887 -END(general_protection)
23888 +ENDPROC(general_protection)
23889
23890 #ifdef CONFIG_KVM_GUEST
23891 ENTRY(async_page_fault)
23892 @@ -1426,6 +1674,6 @@ ENTRY(async_page_fault)
23893 pushl_cfi $do_async_page_fault
23894 jmp error_code
23895 CFI_ENDPROC
23896 -END(async_page_fault)
23897 +ENDPROC(async_page_fault)
23898 #endif
23899
23900 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
23901 index b9dde27..6e9dc4e 100644
23902 --- a/arch/x86/kernel/entry_64.S
23903 +++ b/arch/x86/kernel/entry_64.S
23904 @@ -59,6 +59,8 @@
23905 #include <asm/smap.h>
23906 #include <asm/pgtable_types.h>
23907 #include <linux/err.h>
23908 +#include <asm/pgtable.h>
23909 +#include <asm/alternative-asm.h>
23910
23911 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
23912 #include <linux/elf-em.h>
23913 @@ -81,6 +83,430 @@ ENTRY(native_usergs_sysret64)
23914 ENDPROC(native_usergs_sysret64)
23915 #endif /* CONFIG_PARAVIRT */
23916
23917 + .macro ljmpq sel, off
23918 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
23919 + .byte 0x48; ljmp *1234f(%rip)
23920 + .pushsection .rodata
23921 + .align 16
23922 + 1234: .quad \off; .word \sel
23923 + .popsection
23924 +#else
23925 + pushq $\sel
23926 + pushq $\off
23927 + lretq
23928 +#endif
23929 + .endm
23930 +
23931 + .macro pax_enter_kernel
23932 + pax_set_fptr_mask
23933 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23934 + call pax_enter_kernel
23935 +#endif
23936 + .endm
23937 +
23938 + .macro pax_exit_kernel
23939 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23940 + call pax_exit_kernel
23941 +#endif
23942 +
23943 + .endm
23944 +
23945 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23946 +ENTRY(pax_enter_kernel)
23947 + pushq %rdi
23948 +
23949 +#ifdef CONFIG_PARAVIRT
23950 + PV_SAVE_REGS(CLBR_RDI)
23951 +#endif
23952 +
23953 +#ifdef CONFIG_PAX_KERNEXEC
23954 + GET_CR0_INTO_RDI
23955 + bts $16,%rdi
23956 + jnc 3f
23957 + mov %cs,%edi
23958 + cmp $__KERNEL_CS,%edi
23959 + jnz 2f
23960 +1:
23961 +#endif
23962 +
23963 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23964 + 661: jmp 111f
23965 + .pushsection .altinstr_replacement, "a"
23966 + 662: ASM_NOP2
23967 + .popsection
23968 + .pushsection .altinstructions, "a"
23969 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23970 + .popsection
23971 + GET_CR3_INTO_RDI
23972 + cmp $0,%dil
23973 + jnz 112f
23974 + mov $__KERNEL_DS,%edi
23975 + mov %edi,%ss
23976 + jmp 111f
23977 +112: cmp $1,%dil
23978 + jz 113f
23979 + ud2
23980 +113: sub $4097,%rdi
23981 + bts $63,%rdi
23982 + SET_RDI_INTO_CR3
23983 + mov $__UDEREF_KERNEL_DS,%edi
23984 + mov %edi,%ss
23985 +111:
23986 +#endif
23987 +
23988 +#ifdef CONFIG_PARAVIRT
23989 + PV_RESTORE_REGS(CLBR_RDI)
23990 +#endif
23991 +
23992 + popq %rdi
23993 + pax_force_retaddr
23994 + retq
23995 +
23996 +#ifdef CONFIG_PAX_KERNEXEC
23997 +2: ljmpq __KERNEL_CS,1b
23998 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
23999 +4: SET_RDI_INTO_CR0
24000 + jmp 1b
24001 +#endif
24002 +ENDPROC(pax_enter_kernel)
24003 +
24004 +ENTRY(pax_exit_kernel)
24005 + pushq %rdi
24006 +
24007 +#ifdef CONFIG_PARAVIRT
24008 + PV_SAVE_REGS(CLBR_RDI)
24009 +#endif
24010 +
24011 +#ifdef CONFIG_PAX_KERNEXEC
24012 + mov %cs,%rdi
24013 + cmp $__KERNEXEC_KERNEL_CS,%edi
24014 + jz 2f
24015 + GET_CR0_INTO_RDI
24016 + bts $16,%rdi
24017 + jnc 4f
24018 +1:
24019 +#endif
24020 +
24021 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24022 + 661: jmp 111f
24023 + .pushsection .altinstr_replacement, "a"
24024 + 662: ASM_NOP2
24025 + .popsection
24026 + .pushsection .altinstructions, "a"
24027 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
24028 + .popsection
24029 + mov %ss,%edi
24030 + cmp $__UDEREF_KERNEL_DS,%edi
24031 + jnz 111f
24032 + GET_CR3_INTO_RDI
24033 + cmp $0,%dil
24034 + jz 112f
24035 + ud2
24036 +112: add $4097,%rdi
24037 + bts $63,%rdi
24038 + SET_RDI_INTO_CR3
24039 + mov $__KERNEL_DS,%edi
24040 + mov %edi,%ss
24041 +111:
24042 +#endif
24043 +
24044 +#ifdef CONFIG_PARAVIRT
24045 + PV_RESTORE_REGS(CLBR_RDI);
24046 +#endif
24047 +
24048 + popq %rdi
24049 + pax_force_retaddr
24050 + retq
24051 +
24052 +#ifdef CONFIG_PAX_KERNEXEC
24053 +2: GET_CR0_INTO_RDI
24054 + btr $16,%rdi
24055 + jnc 4f
24056 + ljmpq __KERNEL_CS,3f
24057 +3: SET_RDI_INTO_CR0
24058 + jmp 1b
24059 +4: ud2
24060 + jmp 4b
24061 +#endif
24062 +ENDPROC(pax_exit_kernel)
24063 +#endif
24064 +
24065 + .macro pax_enter_kernel_user
24066 + pax_set_fptr_mask
24067 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24068 + call pax_enter_kernel_user
24069 +#endif
24070 + .endm
24071 +
24072 + .macro pax_exit_kernel_user
24073 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24074 + call pax_exit_kernel_user
24075 +#endif
24076 +#ifdef CONFIG_PAX_RANDKSTACK
24077 + pushq %rax
24078 + pushq %r11
24079 + call pax_randomize_kstack
24080 + popq %r11
24081 + popq %rax
24082 +#endif
24083 + .endm
24084 +
24085 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24086 +ENTRY(pax_enter_kernel_user)
24087 + pushq %rdi
24088 + pushq %rbx
24089 +
24090 +#ifdef CONFIG_PARAVIRT
24091 + PV_SAVE_REGS(CLBR_RDI)
24092 +#endif
24093 +
24094 + 661: jmp 111f
24095 + .pushsection .altinstr_replacement, "a"
24096 + 662: ASM_NOP2
24097 + .popsection
24098 + .pushsection .altinstructions, "a"
24099 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
24100 + .popsection
24101 + GET_CR3_INTO_RDI
24102 + cmp $1,%dil
24103 + jnz 4f
24104 + sub $4097,%rdi
24105 + bts $63,%rdi
24106 + SET_RDI_INTO_CR3
24107 + jmp 3f
24108 +111:
24109 +
24110 + GET_CR3_INTO_RDI
24111 + mov %rdi,%rbx
24112 + add $__START_KERNEL_map,%rbx
24113 + sub phys_base(%rip),%rbx
24114 +
24115 +#ifdef CONFIG_PARAVIRT
24116 + cmpl $0, pv_info+PARAVIRT_enabled
24117 + jz 1f
24118 + pushq %rdi
24119 + i = 0
24120 + .rept USER_PGD_PTRS
24121 + mov i*8(%rbx),%rsi
24122 + mov $0,%sil
24123 + lea i*8(%rbx),%rdi
24124 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
24125 + i = i + 1
24126 + .endr
24127 + popq %rdi
24128 + jmp 2f
24129 +1:
24130 +#endif
24131 +
24132 + i = 0
24133 + .rept USER_PGD_PTRS
24134 + movb $0,i*8(%rbx)
24135 + i = i + 1
24136 + .endr
24137 +
24138 +2: SET_RDI_INTO_CR3
24139 +
24140 +#ifdef CONFIG_PAX_KERNEXEC
24141 + GET_CR0_INTO_RDI
24142 + bts $16,%rdi
24143 + SET_RDI_INTO_CR0
24144 +#endif
24145 +
24146 +3:
24147 +
24148 +#ifdef CONFIG_PARAVIRT
24149 + PV_RESTORE_REGS(CLBR_RDI)
24150 +#endif
24151 +
24152 + popq %rbx
24153 + popq %rdi
24154 + pax_force_retaddr
24155 + retq
24156 +4: ud2
24157 +ENDPROC(pax_enter_kernel_user)
24158 +
24159 +ENTRY(pax_exit_kernel_user)
24160 + pushq %rdi
24161 + pushq %rbx
24162 +
24163 +#ifdef CONFIG_PARAVIRT
24164 + PV_SAVE_REGS(CLBR_RDI)
24165 +#endif
24166 +
24167 + GET_CR3_INTO_RDI
24168 + 661: jmp 1f
24169 + .pushsection .altinstr_replacement, "a"
24170 + 662: ASM_NOP2
24171 + .popsection
24172 + .pushsection .altinstructions, "a"
24173 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
24174 + .popsection
24175 + cmp $0,%dil
24176 + jnz 3f
24177 + add $4097,%rdi
24178 + bts $63,%rdi
24179 + SET_RDI_INTO_CR3
24180 + jmp 2f
24181 +1:
24182 +
24183 + mov %rdi,%rbx
24184 +
24185 +#ifdef CONFIG_PAX_KERNEXEC
24186 + GET_CR0_INTO_RDI
24187 + btr $16,%rdi
24188 + jnc 3f
24189 + SET_RDI_INTO_CR0
24190 +#endif
24191 +
24192 + add $__START_KERNEL_map,%rbx
24193 + sub phys_base(%rip),%rbx
24194 +
24195 +#ifdef CONFIG_PARAVIRT
24196 + cmpl $0, pv_info+PARAVIRT_enabled
24197 + jz 1f
24198 + i = 0
24199 + .rept USER_PGD_PTRS
24200 + mov i*8(%rbx),%rsi
24201 + mov $0x67,%sil
24202 + lea i*8(%rbx),%rdi
24203 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
24204 + i = i + 1
24205 + .endr
24206 + jmp 2f
24207 +1:
24208 +#endif
24209 +
24210 + i = 0
24211 + .rept USER_PGD_PTRS
24212 + movb $0x67,i*8(%rbx)
24213 + i = i + 1
24214 + .endr
24215 +2:
24216 +
24217 +#ifdef CONFIG_PARAVIRT
24218 + PV_RESTORE_REGS(CLBR_RDI)
24219 +#endif
24220 +
24221 + popq %rbx
24222 + popq %rdi
24223 + pax_force_retaddr
24224 + retq
24225 +3: ud2
24226 +ENDPROC(pax_exit_kernel_user)
24227 +#endif
24228 +
24229 + .macro pax_enter_kernel_nmi
24230 + pax_set_fptr_mask
24231 +
24232 +#ifdef CONFIG_PAX_KERNEXEC
24233 + GET_CR0_INTO_RDI
24234 + bts $16,%rdi
24235 + jc 110f
24236 + SET_RDI_INTO_CR0
24237 + or $2,%ebx
24238 +110:
24239 +#endif
24240 +
24241 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24242 + 661: jmp 111f
24243 + .pushsection .altinstr_replacement, "a"
24244 + 662: ASM_NOP2
24245 + .popsection
24246 + .pushsection .altinstructions, "a"
24247 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
24248 + .popsection
24249 + GET_CR3_INTO_RDI
24250 + cmp $0,%dil
24251 + jz 111f
24252 + sub $4097,%rdi
24253 + or $4,%ebx
24254 + bts $63,%rdi
24255 + SET_RDI_INTO_CR3
24256 + mov $__UDEREF_KERNEL_DS,%edi
24257 + mov %edi,%ss
24258 +111:
24259 +#endif
24260 + .endm
24261 +
24262 + .macro pax_exit_kernel_nmi
24263 +#ifdef CONFIG_PAX_KERNEXEC
24264 + btr $1,%ebx
24265 + jnc 110f
24266 + GET_CR0_INTO_RDI
24267 + btr $16,%rdi
24268 + SET_RDI_INTO_CR0
24269 +110:
24270 +#endif
24271 +
24272 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24273 + btr $2,%ebx
24274 + jnc 111f
24275 + GET_CR3_INTO_RDI
24276 + add $4097,%rdi
24277 + bts $63,%rdi
24278 + SET_RDI_INTO_CR3
24279 + mov $__KERNEL_DS,%edi
24280 + mov %edi,%ss
24281 +111:
24282 +#endif
24283 + .endm
24284 +
24285 + .macro pax_erase_kstack
24286 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
24287 + call pax_erase_kstack
24288 +#endif
24289 + .endm
24290 +
24291 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
24292 +ENTRY(pax_erase_kstack)
24293 + pushq %rdi
24294 + pushq %rcx
24295 + pushq %rax
24296 + pushq %r11
24297 +
24298 + GET_THREAD_INFO(%r11)
24299 + mov TI_lowest_stack(%r11), %rdi
24300 + mov $-0xBEEF, %rax
24301 + std
24302 +
24303 +1: mov %edi, %ecx
24304 + and $THREAD_SIZE_asm - 1, %ecx
24305 + shr $3, %ecx
24306 + repne scasq
24307 + jecxz 2f
24308 +
24309 + cmp $2*8, %ecx
24310 + jc 2f
24311 +
24312 + mov $2*8, %ecx
24313 + repe scasq
24314 + jecxz 2f
24315 + jne 1b
24316 +
24317 +2: cld
24318 + mov %esp, %ecx
24319 + sub %edi, %ecx
24320 +
24321 + cmp $THREAD_SIZE_asm, %rcx
24322 + jb 3f
24323 + ud2
24324 +3:
24325 +
24326 + shr $3, %ecx
24327 + rep stosq
24328 +
24329 + mov TI_task_thread_sp0(%r11), %rdi
24330 + sub $256, %rdi
24331 + mov %rdi, TI_lowest_stack(%r11)
24332 +
24333 + popq %r11
24334 + popq %rax
24335 + popq %rcx
24336 + popq %rdi
24337 + pax_force_retaddr
24338 + ret
24339 +ENDPROC(pax_erase_kstack)
24340 +#endif
24341
24342 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
24343 #ifdef CONFIG_TRACE_IRQFLAGS
24344 @@ -117,7 +543,7 @@ ENDPROC(native_usergs_sysret64)
24345 .endm
24346
24347 .macro TRACE_IRQS_IRETQ_DEBUG offset=ARGOFFSET
24348 - bt $9,EFLAGS-\offset(%rsp) /* interrupts off? */
24349 + bt $X86_EFLAGS_IF_BIT,EFLAGS-\offset(%rsp) /* interrupts off? */
24350 jnc 1f
24351 TRACE_IRQS_ON_DEBUG
24352 1:
24353 @@ -155,27 +581,6 @@ ENDPROC(native_usergs_sysret64)
24354 movq \tmp,R11+\offset(%rsp)
24355 .endm
24356
24357 - .macro FAKE_STACK_FRAME child_rip
24358 - /* push in order ss, rsp, eflags, cs, rip */
24359 - xorl %eax, %eax
24360 - pushq_cfi $__KERNEL_DS /* ss */
24361 - /*CFI_REL_OFFSET ss,0*/
24362 - pushq_cfi %rax /* rsp */
24363 - CFI_REL_OFFSET rsp,0
24364 - pushq_cfi $(X86_EFLAGS_IF|X86_EFLAGS_FIXED) /* eflags - interrupts on */
24365 - /*CFI_REL_OFFSET rflags,0*/
24366 - pushq_cfi $__KERNEL_CS /* cs */
24367 - /*CFI_REL_OFFSET cs,0*/
24368 - pushq_cfi \child_rip /* rip */
24369 - CFI_REL_OFFSET rip,0
24370 - pushq_cfi %rax /* orig rax */
24371 - .endm
24372 -
24373 - .macro UNFAKE_STACK_FRAME
24374 - addq $8*6, %rsp
24375 - CFI_ADJUST_CFA_OFFSET -(6*8)
24376 - .endm
24377 -
24378 /*
24379 * initial frame state for interrupts (and exceptions without error code)
24380 */
24381 @@ -241,25 +646,26 @@ ENDPROC(native_usergs_sysret64)
24382 /* save partial stack frame */
24383 .macro SAVE_ARGS_IRQ
24384 cld
24385 - /* start from rbp in pt_regs and jump over */
24386 - movq_cfi rdi, (RDI-RBP)
24387 - movq_cfi rsi, (RSI-RBP)
24388 - movq_cfi rdx, (RDX-RBP)
24389 - movq_cfi rcx, (RCX-RBP)
24390 - movq_cfi rax, (RAX-RBP)
24391 - movq_cfi r8, (R8-RBP)
24392 - movq_cfi r9, (R9-RBP)
24393 - movq_cfi r10, (R10-RBP)
24394 - movq_cfi r11, (R11-RBP)
24395 + /* start from r15 in pt_regs and jump over */
24396 + movq_cfi rdi, RDI
24397 + movq_cfi rsi, RSI
24398 + movq_cfi rdx, RDX
24399 + movq_cfi rcx, RCX
24400 + movq_cfi rax, RAX
24401 + movq_cfi r8, R8
24402 + movq_cfi r9, R9
24403 + movq_cfi r10, R10
24404 + movq_cfi r11, R11
24405 + movq_cfi r12, R12
24406
24407 /* Save rbp so that we can unwind from get_irq_regs() */
24408 - movq_cfi rbp, 0
24409 + movq_cfi rbp, RBP
24410
24411 /* Save previous stack value */
24412 movq %rsp, %rsi
24413
24414 - leaq -RBP(%rsp),%rdi /* arg1 for handler */
24415 - testl $3, CS-RBP(%rsi)
24416 + movq %rsp,%rdi /* arg1 for handler */
24417 + testb $3, CS(%rsi)
24418 je 1f
24419 SWAPGS
24420 /*
24421 @@ -279,6 +685,18 @@ ENDPROC(native_usergs_sysret64)
24422 0x06 /* DW_OP_deref */, \
24423 0x08 /* DW_OP_const1u */, SS+8-RBP, \
24424 0x22 /* DW_OP_plus */
24425 +
24426 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24427 + testb $3, CS(%rdi)
24428 + jnz 1f
24429 + pax_enter_kernel
24430 + jmp 2f
24431 +1: pax_enter_kernel_user
24432 +2:
24433 +#else
24434 + pax_enter_kernel
24435 +#endif
24436 +
24437 /* We entered an interrupt context - irqs are off: */
24438 TRACE_IRQS_OFF
24439 .endm
24440 @@ -308,9 +726,52 @@ ENTRY(save_paranoid)
24441 js 1f /* negative -> in kernel */
24442 SWAPGS
24443 xorl %ebx,%ebx
24444 -1: ret
24445 +1:
24446 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24447 + testb $3, CS+8(%rsp)
24448 + jnz 1f
24449 + pax_enter_kernel
24450 + jmp 2f
24451 +1: pax_enter_kernel_user
24452 +2:
24453 +#else
24454 + pax_enter_kernel
24455 +#endif
24456 + pax_force_retaddr
24457 + ret
24458 CFI_ENDPROC
24459 -END(save_paranoid)
24460 +ENDPROC(save_paranoid)
24461 +
24462 +ENTRY(save_paranoid_nmi)
24463 + XCPT_FRAME 1 RDI+8
24464 + cld
24465 + movq_cfi rdi, RDI+8
24466 + movq_cfi rsi, RSI+8
24467 + movq_cfi rdx, RDX+8
24468 + movq_cfi rcx, RCX+8
24469 + movq_cfi rax, RAX+8
24470 + movq_cfi r8, R8+8
24471 + movq_cfi r9, R9+8
24472 + movq_cfi r10, R10+8
24473 + movq_cfi r11, R11+8
24474 + movq_cfi rbx, RBX+8
24475 + movq_cfi rbp, RBP+8
24476 + movq_cfi r12, R12+8
24477 + movq_cfi r13, R13+8
24478 + movq_cfi r14, R14+8
24479 + movq_cfi r15, R15+8
24480 + movl $1,%ebx
24481 + movl $MSR_GS_BASE,%ecx
24482 + rdmsr
24483 + testl %edx,%edx
24484 + js 1f /* negative -> in kernel */
24485 + SWAPGS
24486 + xorl %ebx,%ebx
24487 +1: pax_enter_kernel_nmi
24488 + pax_force_retaddr
24489 + ret
24490 + CFI_ENDPROC
24491 +ENDPROC(save_paranoid_nmi)
24492
24493 /*
24494 * A newly forked process directly context switches into this address.
24495 @@ -331,7 +792,7 @@ ENTRY(ret_from_fork)
24496
24497 RESTORE_REST
24498
24499 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
24500 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
24501 jz 1f
24502
24503 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
24504 @@ -341,15 +802,13 @@ ENTRY(ret_from_fork)
24505 jmp ret_from_sys_call # go to the SYSRET fastpath
24506
24507 1:
24508 - subq $REST_SKIP, %rsp # leave space for volatiles
24509 - CFI_ADJUST_CFA_OFFSET REST_SKIP
24510 movq %rbp, %rdi
24511 call *%rbx
24512 movl $0, RAX(%rsp)
24513 RESTORE_REST
24514 jmp int_ret_from_sys_call
24515 CFI_ENDPROC
24516 -END(ret_from_fork)
24517 +ENDPROC(ret_from_fork)
24518
24519 /*
24520 * System call entry. Up to 6 arguments in registers are supported.
24521 @@ -386,7 +845,7 @@ END(ret_from_fork)
24522 ENTRY(system_call)
24523 CFI_STARTPROC simple
24524 CFI_SIGNAL_FRAME
24525 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
24526 + CFI_DEF_CFA rsp,0
24527 CFI_REGISTER rip,rcx
24528 /*CFI_REGISTER rflags,r11*/
24529 SWAPGS_UNSAFE_STACK
24530 @@ -399,16 +858,23 @@ GLOBAL(system_call_after_swapgs)
24531
24532 movq %rsp,PER_CPU_VAR(old_rsp)
24533 movq PER_CPU_VAR(kernel_stack),%rsp
24534 + SAVE_ARGS 8*6,0
24535 + pax_enter_kernel_user
24536 +
24537 +#ifdef CONFIG_PAX_RANDKSTACK
24538 + pax_erase_kstack
24539 +#endif
24540 +
24541 /*
24542 * No need to follow this irqs off/on section - it's straight
24543 * and short:
24544 */
24545 ENABLE_INTERRUPTS(CLBR_NONE)
24546 - SAVE_ARGS 8,0
24547 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
24548 movq %rcx,RIP-ARGOFFSET(%rsp)
24549 CFI_REL_OFFSET rip,RIP-ARGOFFSET
24550 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
24551 + GET_THREAD_INFO(%rcx)
24552 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
24553 jnz tracesys
24554 system_call_fastpath:
24555 #if __SYSCALL_MASK == ~0
24556 @@ -432,10 +898,13 @@ sysret_check:
24557 LOCKDEP_SYS_EXIT
24558 DISABLE_INTERRUPTS(CLBR_NONE)
24559 TRACE_IRQS_OFF
24560 - movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
24561 + GET_THREAD_INFO(%rcx)
24562 + movl TI_flags(%rcx),%edx
24563 andl %edi,%edx
24564 jnz sysret_careful
24565 CFI_REMEMBER_STATE
24566 + pax_exit_kernel_user
24567 + pax_erase_kstack
24568 /*
24569 * sysretq will re-enable interrupts:
24570 */
24571 @@ -494,6 +963,9 @@ auditsys:
24572 movq %rax,%rsi /* 2nd arg: syscall number */
24573 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
24574 call __audit_syscall_entry
24575 +
24576 + pax_erase_kstack
24577 +
24578 LOAD_ARGS 0 /* reload call-clobbered registers */
24579 jmp system_call_fastpath
24580
24581 @@ -515,7 +987,7 @@ sysret_audit:
24582 /* Do syscall tracing */
24583 tracesys:
24584 #ifdef CONFIG_AUDITSYSCALL
24585 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
24586 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
24587 jz auditsys
24588 #endif
24589 SAVE_REST
24590 @@ -523,12 +995,15 @@ tracesys:
24591 FIXUP_TOP_OF_STACK %rdi
24592 movq %rsp,%rdi
24593 call syscall_trace_enter
24594 +
24595 + pax_erase_kstack
24596 +
24597 /*
24598 * Reload arg registers from stack in case ptrace changed them.
24599 * We don't reload %rax because syscall_trace_enter() returned
24600 * the value it wants us to use in the table lookup.
24601 */
24602 - LOAD_ARGS ARGOFFSET, 1
24603 + LOAD_ARGS 1
24604 RESTORE_REST
24605 #if __SYSCALL_MASK == ~0
24606 cmpq $__NR_syscall_max,%rax
24607 @@ -558,7 +1033,9 @@ GLOBAL(int_with_check)
24608 andl %edi,%edx
24609 jnz int_careful
24610 andl $~TS_COMPAT,TI_status(%rcx)
24611 - jmp retint_swapgs
24612 + pax_exit_kernel_user
24613 + pax_erase_kstack
24614 + jmp retint_swapgs_pax
24615
24616 /* Either reschedule or signal or syscall exit tracking needed. */
24617 /* First do a reschedule test. */
24618 @@ -604,7 +1081,7 @@ int_restore_rest:
24619 TRACE_IRQS_OFF
24620 jmp int_with_check
24621 CFI_ENDPROC
24622 -END(system_call)
24623 +ENDPROC(system_call)
24624
24625 .macro FORK_LIKE func
24626 ENTRY(stub_\func)
24627 @@ -617,9 +1094,10 @@ ENTRY(stub_\func)
24628 DEFAULT_FRAME 0 8 /* offset 8: return address */
24629 call sys_\func
24630 RESTORE_TOP_OF_STACK %r11, 8
24631 - ret $REST_SKIP /* pop extended registers */
24632 + pax_force_retaddr
24633 + ret
24634 CFI_ENDPROC
24635 -END(stub_\func)
24636 +ENDPROC(stub_\func)
24637 .endm
24638
24639 .macro FIXED_FRAME label,func
24640 @@ -629,9 +1107,10 @@ ENTRY(\label)
24641 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
24642 call \func
24643 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
24644 + pax_force_retaddr
24645 ret
24646 CFI_ENDPROC
24647 -END(\label)
24648 +ENDPROC(\label)
24649 .endm
24650
24651 FORK_LIKE clone
24652 @@ -639,19 +1118,6 @@ END(\label)
24653 FORK_LIKE vfork
24654 FIXED_FRAME stub_iopl, sys_iopl
24655
24656 -ENTRY(ptregscall_common)
24657 - DEFAULT_FRAME 1 8 /* offset 8: return address */
24658 - RESTORE_TOP_OF_STACK %r11, 8
24659 - movq_cfi_restore R15+8, r15
24660 - movq_cfi_restore R14+8, r14
24661 - movq_cfi_restore R13+8, r13
24662 - movq_cfi_restore R12+8, r12
24663 - movq_cfi_restore RBP+8, rbp
24664 - movq_cfi_restore RBX+8, rbx
24665 - ret $REST_SKIP /* pop extended registers */
24666 - CFI_ENDPROC
24667 -END(ptregscall_common)
24668 -
24669 ENTRY(stub_execve)
24670 CFI_STARTPROC
24671 addq $8, %rsp
24672 @@ -663,7 +1129,7 @@ ENTRY(stub_execve)
24673 RESTORE_REST
24674 jmp int_ret_from_sys_call
24675 CFI_ENDPROC
24676 -END(stub_execve)
24677 +ENDPROC(stub_execve)
24678
24679 /*
24680 * sigreturn is special because it needs to restore all registers on return.
24681 @@ -680,7 +1146,7 @@ ENTRY(stub_rt_sigreturn)
24682 RESTORE_REST
24683 jmp int_ret_from_sys_call
24684 CFI_ENDPROC
24685 -END(stub_rt_sigreturn)
24686 +ENDPROC(stub_rt_sigreturn)
24687
24688 #ifdef CONFIG_X86_X32_ABI
24689 ENTRY(stub_x32_rt_sigreturn)
24690 @@ -694,7 +1160,7 @@ ENTRY(stub_x32_rt_sigreturn)
24691 RESTORE_REST
24692 jmp int_ret_from_sys_call
24693 CFI_ENDPROC
24694 -END(stub_x32_rt_sigreturn)
24695 +ENDPROC(stub_x32_rt_sigreturn)
24696
24697 ENTRY(stub_x32_execve)
24698 CFI_STARTPROC
24699 @@ -708,7 +1174,7 @@ ENTRY(stub_x32_execve)
24700 RESTORE_REST
24701 jmp int_ret_from_sys_call
24702 CFI_ENDPROC
24703 -END(stub_x32_execve)
24704 +ENDPROC(stub_x32_execve)
24705
24706 #endif
24707
24708 @@ -745,7 +1211,7 @@ vector=vector+1
24709 2: jmp common_interrupt
24710 .endr
24711 CFI_ENDPROC
24712 -END(irq_entries_start)
24713 +ENDPROC(irq_entries_start)
24714
24715 .previous
24716 END(interrupt)
24717 @@ -762,8 +1228,8 @@ END(interrupt)
24718 /* 0(%rsp): ~(interrupt number) */
24719 .macro interrupt func
24720 /* reserve pt_regs for scratch regs and rbp */
24721 - subq $ORIG_RAX-RBP, %rsp
24722 - CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
24723 + subq $ORIG_RAX, %rsp
24724 + CFI_ADJUST_CFA_OFFSET ORIG_RAX
24725 SAVE_ARGS_IRQ
24726 call \func
24727 .endm
24728 @@ -786,14 +1252,14 @@ ret_from_intr:
24729
24730 /* Restore saved previous stack */
24731 popq %rsi
24732 - CFI_DEF_CFA rsi,SS+8-RBP /* reg/off reset after def_cfa_expr */
24733 - leaq ARGOFFSET-RBP(%rsi), %rsp
24734 + CFI_DEF_CFA rsi,SS+8 /* reg/off reset after def_cfa_expr */
24735 + movq %rsi, %rsp
24736 CFI_DEF_CFA_REGISTER rsp
24737 - CFI_ADJUST_CFA_OFFSET RBP-ARGOFFSET
24738 + CFI_ADJUST_CFA_OFFSET -ARGOFFSET
24739
24740 exit_intr:
24741 GET_THREAD_INFO(%rcx)
24742 - testl $3,CS-ARGOFFSET(%rsp)
24743 + testb $3,CS-ARGOFFSET(%rsp)
24744 je retint_kernel
24745
24746 /* Interrupt came from user space */
24747 @@ -815,12 +1281,35 @@ retint_swapgs: /* return to user-space */
24748 * The iretq could re-enable interrupts:
24749 */
24750 DISABLE_INTERRUPTS(CLBR_ANY)
24751 + pax_exit_kernel_user
24752 +retint_swapgs_pax:
24753 TRACE_IRQS_IRETQ
24754 SWAPGS
24755 jmp restore_args
24756
24757 retint_restore_args: /* return to kernel space */
24758 DISABLE_INTERRUPTS(CLBR_ANY)
24759 + pax_exit_kernel
24760 +
24761 +#if defined(CONFIG_EFI) && defined(CONFIG_PAX_KERNEXEC)
24762 + /* This is a quirk to allow IRQs/NMIs/MCEs during early EFI setup,
24763 + * namely calling EFI runtime services with a phys mapping. We're
24764 + * starting off with NOPs and patch in the real instrumentation
24765 + * (BTS/OR) before starting any userland process; even before starting
24766 + * up the APs.
24767 + */
24768 + .pushsection .altinstr_replacement, "a"
24769 + 601: pax_force_retaddr (RIP-ARGOFFSET)
24770 + 602:
24771 + .popsection
24772 + 603: .fill 602b-601b, 1, 0x90
24773 + .pushsection .altinstructions, "a"
24774 + altinstruction_entry 603b, 601b, X86_FEATURE_ALWAYS, 602b-601b, 602b-601b
24775 + .popsection
24776 +#else
24777 + pax_force_retaddr (RIP-ARGOFFSET)
24778 +#endif
24779 +
24780 /*
24781 * The iretq could re-enable interrupts:
24782 */
24783 @@ -920,7 +1409,7 @@ ENTRY(retint_kernel)
24784 jmp exit_intr
24785 #endif
24786 CFI_ENDPROC
24787 -END(common_interrupt)
24788 +ENDPROC(common_interrupt)
24789
24790 /*
24791 * APIC interrupts.
24792 @@ -934,7 +1423,7 @@ ENTRY(\sym)
24793 interrupt \do_sym
24794 jmp ret_from_intr
24795 CFI_ENDPROC
24796 -END(\sym)
24797 +ENDPROC(\sym)
24798 .endm
24799
24800 #ifdef CONFIG_TRACING
24801 @@ -1007,7 +1496,7 @@ apicinterrupt IRQ_WORK_VECTOR \
24802 /*
24803 * Exception entry points.
24804 */
24805 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
24806 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r13)
24807
24808 .macro idtentry sym do_sym has_error_code:req paranoid=0 shift_ist=-1
24809 ENTRY(\sym)
24810 @@ -1058,6 +1547,12 @@ ENTRY(\sym)
24811 .endif
24812
24813 .if \shift_ist != -1
24814 +#ifdef CONFIG_SMP
24815 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r13d
24816 + lea init_tss(%r13), %r13
24817 +#else
24818 + lea init_tss(%rip), %r13
24819 +#endif
24820 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\shift_ist)
24821 .endif
24822
24823 @@ -1074,7 +1569,7 @@ ENTRY(\sym)
24824 .endif
24825
24826 CFI_ENDPROC
24827 -END(\sym)
24828 +ENDPROC(\sym)
24829 .endm
24830
24831 #ifdef CONFIG_TRACING
24832 @@ -1115,9 +1610,10 @@ gs_change:
24833 2: mfence /* workaround */
24834 SWAPGS
24835 popfq_cfi
24836 + pax_force_retaddr
24837 ret
24838 CFI_ENDPROC
24839 -END(native_load_gs_index)
24840 +ENDPROC(native_load_gs_index)
24841
24842 _ASM_EXTABLE(gs_change,bad_gs)
24843 .section .fixup,"ax"
24844 @@ -1145,9 +1641,10 @@ ENTRY(do_softirq_own_stack)
24845 CFI_DEF_CFA_REGISTER rsp
24846 CFI_ADJUST_CFA_OFFSET -8
24847 decl PER_CPU_VAR(irq_count)
24848 + pax_force_retaddr
24849 ret
24850 CFI_ENDPROC
24851 -END(do_softirq_own_stack)
24852 +ENDPROC(do_softirq_own_stack)
24853
24854 #ifdef CONFIG_XEN
24855 idtentry xen_hypervisor_callback xen_do_hypervisor_callback has_error_code=0
24856 @@ -1185,7 +1682,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
24857 decl PER_CPU_VAR(irq_count)
24858 jmp error_exit
24859 CFI_ENDPROC
24860 -END(xen_do_hypervisor_callback)
24861 +ENDPROC(xen_do_hypervisor_callback)
24862
24863 /*
24864 * Hypervisor uses this for application faults while it executes.
24865 @@ -1244,7 +1741,7 @@ ENTRY(xen_failsafe_callback)
24866 SAVE_ALL
24867 jmp error_exit
24868 CFI_ENDPROC
24869 -END(xen_failsafe_callback)
24870 +ENDPROC(xen_failsafe_callback)
24871
24872 apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
24873 xen_hvm_callback_vector xen_evtchn_do_upcall
24874 @@ -1291,18 +1788,33 @@ ENTRY(paranoid_exit)
24875 DEFAULT_FRAME
24876 DISABLE_INTERRUPTS(CLBR_NONE)
24877 TRACE_IRQS_OFF_DEBUG
24878 - testl %ebx,%ebx /* swapgs needed? */
24879 + testl $1,%ebx /* swapgs needed? */
24880 jnz paranoid_restore
24881 - testl $3,CS(%rsp)
24882 + testb $3,CS(%rsp)
24883 jnz paranoid_userspace
24884 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24885 + pax_exit_kernel
24886 + TRACE_IRQS_IRETQ 0
24887 + SWAPGS_UNSAFE_STACK
24888 + RESTORE_ALL 8
24889 + pax_force_retaddr_bts
24890 + jmp irq_return
24891 +#endif
24892 paranoid_swapgs:
24893 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24894 + pax_exit_kernel_user
24895 +#else
24896 + pax_exit_kernel
24897 +#endif
24898 TRACE_IRQS_IRETQ 0
24899 SWAPGS_UNSAFE_STACK
24900 RESTORE_ALL 8
24901 jmp irq_return
24902 paranoid_restore:
24903 + pax_exit_kernel
24904 TRACE_IRQS_IRETQ_DEBUG 0
24905 RESTORE_ALL 8
24906 + pax_force_retaddr_bts
24907 jmp irq_return
24908 paranoid_userspace:
24909 GET_THREAD_INFO(%rcx)
24910 @@ -1331,7 +1843,7 @@ paranoid_schedule:
24911 TRACE_IRQS_OFF
24912 jmp paranoid_userspace
24913 CFI_ENDPROC
24914 -END(paranoid_exit)
24915 +ENDPROC(paranoid_exit)
24916
24917 /*
24918 * Exception entry point. This expects an error code/orig_rax on the stack.
24919 @@ -1358,12 +1870,23 @@ ENTRY(error_entry)
24920 movq %r14, R14+8(%rsp)
24921 movq %r15, R15+8(%rsp)
24922 xorl %ebx,%ebx
24923 - testl $3,CS+8(%rsp)
24924 + testb $3,CS+8(%rsp)
24925 je error_kernelspace
24926 error_swapgs:
24927 SWAPGS
24928 error_sti:
24929 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24930 + testb $3, CS+8(%rsp)
24931 + jnz 1f
24932 + pax_enter_kernel
24933 + jmp 2f
24934 +1: pax_enter_kernel_user
24935 +2:
24936 +#else
24937 + pax_enter_kernel
24938 +#endif
24939 TRACE_IRQS_OFF
24940 + pax_force_retaddr
24941 ret
24942
24943 /*
24944 @@ -1398,7 +1921,7 @@ error_bad_iret:
24945 decl %ebx /* Return to usergs */
24946 jmp error_sti
24947 CFI_ENDPROC
24948 -END(error_entry)
24949 +ENDPROC(error_entry)
24950
24951
24952 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
24953 @@ -1409,7 +1932,7 @@ ENTRY(error_exit)
24954 DISABLE_INTERRUPTS(CLBR_NONE)
24955 TRACE_IRQS_OFF
24956 GET_THREAD_INFO(%rcx)
24957 - testl %eax,%eax
24958 + testl $1,%eax
24959 jne retint_kernel
24960 LOCKDEP_SYS_EXIT_IRQ
24961 movl TI_flags(%rcx),%edx
24962 @@ -1418,7 +1941,7 @@ ENTRY(error_exit)
24963 jnz retint_careful
24964 jmp retint_swapgs
24965 CFI_ENDPROC
24966 -END(error_exit)
24967 +ENDPROC(error_exit)
24968
24969 /*
24970 * Test if a given stack is an NMI stack or not.
24971 @@ -1476,9 +1999,11 @@ ENTRY(nmi)
24972 * If %cs was not the kernel segment, then the NMI triggered in user
24973 * space, which means it is definitely not nested.
24974 */
24975 + cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
24976 + je 1f
24977 cmpl $__KERNEL_CS, 16(%rsp)
24978 jne first_nmi
24979 -
24980 +1:
24981 /*
24982 * Check the special variable on the stack to see if NMIs are
24983 * executing.
24984 @@ -1512,8 +2037,7 @@ nested_nmi:
24985
24986 1:
24987 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
24988 - leaq -1*8(%rsp), %rdx
24989 - movq %rdx, %rsp
24990 + subq $8, %rsp
24991 CFI_ADJUST_CFA_OFFSET 1*8
24992 leaq -10*8(%rsp), %rdx
24993 pushq_cfi $__KERNEL_DS
24994 @@ -1531,6 +2055,7 @@ nested_nmi_out:
24995 CFI_RESTORE rdx
24996
24997 /* No need to check faults here */
24998 +# pax_force_retaddr_bts
24999 INTERRUPT_RETURN
25000
25001 CFI_RESTORE_STATE
25002 @@ -1627,13 +2152,13 @@ end_repeat_nmi:
25003 subq $ORIG_RAX-R15, %rsp
25004 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
25005 /*
25006 - * Use save_paranoid to handle SWAPGS, but no need to use paranoid_exit
25007 + * Use save_paranoid_nmi to handle SWAPGS, but no need to use paranoid_exit
25008 * as we should not be calling schedule in NMI context.
25009 * Even with normal interrupts enabled. An NMI should not be
25010 * setting NEED_RESCHED or anything that normal interrupts and
25011 * exceptions might do.
25012 */
25013 - call save_paranoid
25014 + call save_paranoid_nmi
25015 DEFAULT_FRAME 0
25016
25017 /*
25018 @@ -1643,9 +2168,9 @@ end_repeat_nmi:
25019 * NMI itself takes a page fault, the page fault that was preempted
25020 * will read the information from the NMI page fault and not the
25021 * origin fault. Save it off and restore it if it changes.
25022 - * Use the r12 callee-saved register.
25023 + * Use the r13 callee-saved register.
25024 */
25025 - movq %cr2, %r12
25026 + movq %cr2, %r13
25027
25028 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
25029 movq %rsp,%rdi
25030 @@ -1654,29 +2179,34 @@ end_repeat_nmi:
25031
25032 /* Did the NMI take a page fault? Restore cr2 if it did */
25033 movq %cr2, %rcx
25034 - cmpq %rcx, %r12
25035 + cmpq %rcx, %r13
25036 je 1f
25037 - movq %r12, %cr2
25038 + movq %r13, %cr2
25039 1:
25040
25041 - testl %ebx,%ebx /* swapgs needed? */
25042 + testl $1,%ebx /* swapgs needed? */
25043 jnz nmi_restore
25044 nmi_swapgs:
25045 SWAPGS_UNSAFE_STACK
25046 nmi_restore:
25047 + pax_exit_kernel_nmi
25048 /* Pop the extra iret frame at once */
25049 RESTORE_ALL 6*8
25050 + testb $3, 8(%rsp)
25051 + jnz 1f
25052 + pax_force_retaddr_bts
25053 +1:
25054
25055 /* Clear the NMI executing stack variable */
25056 movq $0, 5*8(%rsp)
25057 jmp irq_return
25058 CFI_ENDPROC
25059 -END(nmi)
25060 +ENDPROC(nmi)
25061
25062 ENTRY(ignore_sysret)
25063 CFI_STARTPROC
25064 mov $-ENOSYS,%eax
25065 sysret
25066 CFI_ENDPROC
25067 -END(ignore_sysret)
25068 +ENDPROC(ignore_sysret)
25069
25070 diff --git a/arch/x86/kernel/espfix_64.c b/arch/x86/kernel/espfix_64.c
25071 index 94d857f..5bce89c 100644
25072 --- a/arch/x86/kernel/espfix_64.c
25073 +++ b/arch/x86/kernel/espfix_64.c
25074 @@ -70,8 +70,7 @@ static DEFINE_MUTEX(espfix_init_mutex);
25075 #define ESPFIX_MAX_PAGES DIV_ROUND_UP(CONFIG_NR_CPUS, ESPFIX_STACKS_PER_PAGE)
25076 static void *espfix_pages[ESPFIX_MAX_PAGES];
25077
25078 -static __page_aligned_bss pud_t espfix_pud_page[PTRS_PER_PUD]
25079 - __aligned(PAGE_SIZE);
25080 +static pud_t espfix_pud_page[PTRS_PER_PUD] __page_aligned_rodata;
25081
25082 static unsigned int page_random, slot_random;
25083
25084 @@ -122,14 +121,17 @@ static void init_espfix_random(void)
25085 void __init init_espfix_bsp(void)
25086 {
25087 pgd_t *pgd_p;
25088 - pteval_t ptemask;
25089 -
25090 - ptemask = __supported_pte_mask;
25091 + unsigned long index = pgd_index(ESPFIX_BASE_ADDR);
25092
25093 /* Install the espfix pud into the kernel page directory */
25094 - pgd_p = &init_level4_pgt[pgd_index(ESPFIX_BASE_ADDR)];
25095 + pgd_p = &init_level4_pgt[index];
25096 pgd_populate(&init_mm, pgd_p, (pud_t *)espfix_pud_page);
25097
25098 +#ifdef CONFIG_PAX_PER_CPU_PGD
25099 + clone_pgd_range(get_cpu_pgd(0, kernel) + index, swapper_pg_dir + index, 1);
25100 + clone_pgd_range(get_cpu_pgd(0, user) + index, swapper_pg_dir + index, 1);
25101 +#endif
25102 +
25103 /* Randomize the locations */
25104 init_espfix_random();
25105
25106 @@ -197,7 +199,7 @@ void init_espfix_ap(void)
25107 set_pte(&pte_p[n*PTE_STRIDE], pte);
25108
25109 /* Job is done for this CPU and any CPU which shares this page */
25110 - ACCESS_ONCE(espfix_pages[page]) = stack_page;
25111 + ACCESS_ONCE_RW(espfix_pages[page]) = stack_page;
25112
25113 unlock_done:
25114 mutex_unlock(&espfix_init_mutex);
25115 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
25116 index 3386dc9..28bdf81 100644
25117 --- a/arch/x86/kernel/ftrace.c
25118 +++ b/arch/x86/kernel/ftrace.c
25119 @@ -88,7 +88,7 @@ static unsigned long text_ip_addr(unsigned long ip)
25120 * kernel identity mapping to modify code.
25121 */
25122 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
25123 - ip = (unsigned long)__va(__pa_symbol(ip));
25124 + ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
25125
25126 return ip;
25127 }
25128 @@ -104,6 +104,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
25129 {
25130 unsigned char replaced[MCOUNT_INSN_SIZE];
25131
25132 + ip = ktla_ktva(ip);
25133 +
25134 /*
25135 * Note: Due to modules and __init, code can
25136 * disappear and change, we need to protect against faulting
25137 @@ -229,7 +231,7 @@ static int update_ftrace_func(unsigned long ip, void *new)
25138 unsigned char old[MCOUNT_INSN_SIZE];
25139 int ret;
25140
25141 - memcpy(old, (void *)ip, MCOUNT_INSN_SIZE);
25142 + memcpy(old, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE);
25143
25144 ftrace_update_func = ip;
25145 /* Make sure the breakpoints see the ftrace_update_func update */
25146 @@ -310,7 +312,7 @@ static int add_break(unsigned long ip, const char *old)
25147 unsigned char replaced[MCOUNT_INSN_SIZE];
25148 unsigned char brk = BREAKPOINT_INSTRUCTION;
25149
25150 - if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
25151 + if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
25152 return -EFAULT;
25153
25154 /* Make sure it is what we expect it to be */
25155 diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
25156 index eda1a86..8f6df48 100644
25157 --- a/arch/x86/kernel/head64.c
25158 +++ b/arch/x86/kernel/head64.c
25159 @@ -67,12 +67,12 @@ again:
25160 pgd = *pgd_p;
25161
25162 /*
25163 - * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
25164 - * critical -- __PAGE_OFFSET would point us back into the dynamic
25165 + * The use of __early_va rather than __va here is critical:
25166 + * __va would point us back into the dynamic
25167 * range and we might end up looping forever...
25168 */
25169 if (pgd)
25170 - pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
25171 + pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
25172 else {
25173 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
25174 reset_early_page_tables();
25175 @@ -82,13 +82,13 @@ again:
25176 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
25177 for (i = 0; i < PTRS_PER_PUD; i++)
25178 pud_p[i] = 0;
25179 - *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
25180 + *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
25181 }
25182 pud_p += pud_index(address);
25183 pud = *pud_p;
25184
25185 if (pud)
25186 - pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
25187 + pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
25188 else {
25189 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
25190 reset_early_page_tables();
25191 @@ -98,7 +98,7 @@ again:
25192 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
25193 for (i = 0; i < PTRS_PER_PMD; i++)
25194 pmd_p[i] = 0;
25195 - *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
25196 + *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
25197 }
25198 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
25199 pmd_p[pmd_index(address)] = pmd;
25200 @@ -175,7 +175,6 @@ asmlinkage __visible void __init x86_64_start_kernel(char * real_mode_data)
25201 if (console_loglevel >= CONSOLE_LOGLEVEL_DEBUG)
25202 early_printk("Kernel alive\n");
25203
25204 - clear_page(init_level4_pgt);
25205 /* set init_level4_pgt kernel high mapping*/
25206 init_level4_pgt[511] = early_level4_pgt[511];
25207
25208 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
25209 index f36bd42..0ab4474 100644
25210 --- a/arch/x86/kernel/head_32.S
25211 +++ b/arch/x86/kernel/head_32.S
25212 @@ -26,6 +26,12 @@
25213 /* Physical address */
25214 #define pa(X) ((X) - __PAGE_OFFSET)
25215
25216 +#ifdef CONFIG_PAX_KERNEXEC
25217 +#define ta(X) (X)
25218 +#else
25219 +#define ta(X) ((X) - __PAGE_OFFSET)
25220 +#endif
25221 +
25222 /*
25223 * References to members of the new_cpu_data structure.
25224 */
25225 @@ -55,11 +61,7 @@
25226 * and small than max_low_pfn, otherwise will waste some page table entries
25227 */
25228
25229 -#if PTRS_PER_PMD > 1
25230 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
25231 -#else
25232 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
25233 -#endif
25234 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
25235
25236 /* Number of possible pages in the lowmem region */
25237 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
25238 @@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
25239 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
25240
25241 /*
25242 + * Real beginning of normal "text" segment
25243 + */
25244 +ENTRY(stext)
25245 +ENTRY(_stext)
25246 +
25247 +/*
25248 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
25249 * %esi points to the real-mode code as a 32-bit pointer.
25250 * CS and DS must be 4 GB flat segments, but we don't depend on
25251 @@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
25252 * can.
25253 */
25254 __HEAD
25255 +
25256 +#ifdef CONFIG_PAX_KERNEXEC
25257 + jmp startup_32
25258 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
25259 +.fill PAGE_SIZE-5,1,0xcc
25260 +#endif
25261 +
25262 ENTRY(startup_32)
25263 movl pa(stack_start),%ecx
25264
25265 @@ -106,6 +121,59 @@ ENTRY(startup_32)
25266 2:
25267 leal -__PAGE_OFFSET(%ecx),%esp
25268
25269 +#ifdef CONFIG_SMP
25270 + movl $pa(cpu_gdt_table),%edi
25271 + movl $__per_cpu_load,%eax
25272 + movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
25273 + rorl $16,%eax
25274 + movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
25275 + movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
25276 + movl $__per_cpu_end - 1,%eax
25277 + subl $__per_cpu_start,%eax
25278 + movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
25279 +#endif
25280 +
25281 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25282 + movl $NR_CPUS,%ecx
25283 + movl $pa(cpu_gdt_table),%edi
25284 +1:
25285 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
25286 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
25287 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
25288 + addl $PAGE_SIZE_asm,%edi
25289 + loop 1b
25290 +#endif
25291 +
25292 +#ifdef CONFIG_PAX_KERNEXEC
25293 + movl $pa(boot_gdt),%edi
25294 + movl $__LOAD_PHYSICAL_ADDR,%eax
25295 + movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
25296 + rorl $16,%eax
25297 + movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
25298 + movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
25299 + rorl $16,%eax
25300 +
25301 + ljmp $(__BOOT_CS),$1f
25302 +1:
25303 +
25304 + movl $NR_CPUS,%ecx
25305 + movl $pa(cpu_gdt_table),%edi
25306 + addl $__PAGE_OFFSET,%eax
25307 +1:
25308 + movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
25309 + movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
25310 + movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
25311 + movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
25312 + rorl $16,%eax
25313 + movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
25314 + movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
25315 + movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
25316 + movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
25317 + rorl $16,%eax
25318 + addl $PAGE_SIZE_asm,%edi
25319 + loop 1b
25320 +#endif
25321 +
25322 /*
25323 * Clear BSS first so that there are no surprises...
25324 */
25325 @@ -201,8 +269,11 @@ ENTRY(startup_32)
25326 movl %eax, pa(max_pfn_mapped)
25327
25328 /* Do early initialization of the fixmap area */
25329 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
25330 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
25331 +#ifdef CONFIG_COMPAT_VDSO
25332 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
25333 +#else
25334 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
25335 +#endif
25336 #else /* Not PAE */
25337
25338 page_pde_offset = (__PAGE_OFFSET >> 20);
25339 @@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
25340 movl %eax, pa(max_pfn_mapped)
25341
25342 /* Do early initialization of the fixmap area */
25343 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
25344 - movl %eax,pa(initial_page_table+0xffc)
25345 +#ifdef CONFIG_COMPAT_VDSO
25346 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
25347 +#else
25348 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
25349 +#endif
25350 #endif
25351
25352 #ifdef CONFIG_PARAVIRT
25353 @@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
25354 cmpl $num_subarch_entries, %eax
25355 jae bad_subarch
25356
25357 - movl pa(subarch_entries)(,%eax,4), %eax
25358 - subl $__PAGE_OFFSET, %eax
25359 - jmp *%eax
25360 + jmp *pa(subarch_entries)(,%eax,4)
25361
25362 bad_subarch:
25363 WEAK(lguest_entry)
25364 @@ -261,10 +333,10 @@ WEAK(xen_entry)
25365 __INITDATA
25366
25367 subarch_entries:
25368 - .long default_entry /* normal x86/PC */
25369 - .long lguest_entry /* lguest hypervisor */
25370 - .long xen_entry /* Xen hypervisor */
25371 - .long default_entry /* Moorestown MID */
25372 + .long ta(default_entry) /* normal x86/PC */
25373 + .long ta(lguest_entry) /* lguest hypervisor */
25374 + .long ta(xen_entry) /* Xen hypervisor */
25375 + .long ta(default_entry) /* Moorestown MID */
25376 num_subarch_entries = (. - subarch_entries) / 4
25377 .previous
25378 #else
25379 @@ -354,6 +426,7 @@ default_entry:
25380 movl pa(mmu_cr4_features),%eax
25381 movl %eax,%cr4
25382
25383 +#ifdef CONFIG_X86_PAE
25384 testb $X86_CR4_PAE, %al # check if PAE is enabled
25385 jz enable_paging
25386
25387 @@ -382,6 +455,9 @@ default_entry:
25388 /* Make changes effective */
25389 wrmsr
25390
25391 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
25392 +#endif
25393 +
25394 enable_paging:
25395
25396 /*
25397 @@ -449,14 +525,20 @@ is486:
25398 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
25399 movl %eax,%ss # after changing gdt.
25400
25401 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
25402 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
25403 movl %eax,%ds
25404 movl %eax,%es
25405
25406 movl $(__KERNEL_PERCPU), %eax
25407 movl %eax,%fs # set this cpu's percpu
25408
25409 +#ifdef CONFIG_CC_STACKPROTECTOR
25410 movl $(__KERNEL_STACK_CANARY),%eax
25411 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
25412 + movl $(__USER_DS),%eax
25413 +#else
25414 + xorl %eax,%eax
25415 +#endif
25416 movl %eax,%gs
25417
25418 xorl %eax,%eax # Clear LDT
25419 @@ -512,8 +594,11 @@ setup_once:
25420 * relocation. Manually set base address in stack canary
25421 * segment descriptor.
25422 */
25423 - movl $gdt_page,%eax
25424 + movl $cpu_gdt_table,%eax
25425 movl $stack_canary,%ecx
25426 +#ifdef CONFIG_SMP
25427 + addl $__per_cpu_load,%ecx
25428 +#endif
25429 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
25430 shrl $16, %ecx
25431 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
25432 @@ -548,7 +633,7 @@ ENTRY(early_idt_handler)
25433 cmpl $2,(%esp) # X86_TRAP_NMI
25434 je is_nmi # Ignore NMI
25435
25436 - cmpl $2,%ss:early_recursion_flag
25437 + cmpl $1,%ss:early_recursion_flag
25438 je hlt_loop
25439 incl %ss:early_recursion_flag
25440
25441 @@ -586,8 +671,8 @@ ENTRY(early_idt_handler)
25442 pushl (20+6*4)(%esp) /* trapno */
25443 pushl $fault_msg
25444 call printk
25445 -#endif
25446 call dump_stack
25447 +#endif
25448 hlt_loop:
25449 hlt
25450 jmp hlt_loop
25451 @@ -607,8 +692,11 @@ ENDPROC(early_idt_handler)
25452 /* This is the default interrupt "handler" :-) */
25453 ALIGN
25454 ignore_int:
25455 - cld
25456 #ifdef CONFIG_PRINTK
25457 + cmpl $2,%ss:early_recursion_flag
25458 + je hlt_loop
25459 + incl %ss:early_recursion_flag
25460 + cld
25461 pushl %eax
25462 pushl %ecx
25463 pushl %edx
25464 @@ -617,9 +705,6 @@ ignore_int:
25465 movl $(__KERNEL_DS),%eax
25466 movl %eax,%ds
25467 movl %eax,%es
25468 - cmpl $2,early_recursion_flag
25469 - je hlt_loop
25470 - incl early_recursion_flag
25471 pushl 16(%esp)
25472 pushl 24(%esp)
25473 pushl 32(%esp)
25474 @@ -653,29 +738,34 @@ ENTRY(setup_once_ref)
25475 /*
25476 * BSS section
25477 */
25478 -__PAGE_ALIGNED_BSS
25479 - .align PAGE_SIZE
25480 #ifdef CONFIG_X86_PAE
25481 +.section .initial_pg_pmd,"a",@progbits
25482 initial_pg_pmd:
25483 .fill 1024*KPMDS,4,0
25484 #else
25485 +.section .initial_page_table,"a",@progbits
25486 ENTRY(initial_page_table)
25487 .fill 1024,4,0
25488 #endif
25489 +.section .initial_pg_fixmap,"a",@progbits
25490 initial_pg_fixmap:
25491 .fill 1024,4,0
25492 +.section .empty_zero_page,"a",@progbits
25493 ENTRY(empty_zero_page)
25494 .fill 4096,1,0
25495 +.section .swapper_pg_dir,"a",@progbits
25496 ENTRY(swapper_pg_dir)
25497 +#ifdef CONFIG_X86_PAE
25498 + .fill 4,8,0
25499 +#else
25500 .fill 1024,4,0
25501 +#endif
25502
25503 /*
25504 * This starts the data section.
25505 */
25506 #ifdef CONFIG_X86_PAE
25507 -__PAGE_ALIGNED_DATA
25508 - /* Page-aligned for the benefit of paravirt? */
25509 - .align PAGE_SIZE
25510 +.section .initial_page_table,"a",@progbits
25511 ENTRY(initial_page_table)
25512 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
25513 # if KPMDS == 3
25514 @@ -694,12 +784,20 @@ ENTRY(initial_page_table)
25515 # error "Kernel PMDs should be 1, 2 or 3"
25516 # endif
25517 .align PAGE_SIZE /* needs to be page-sized too */
25518 +
25519 +#ifdef CONFIG_PAX_PER_CPU_PGD
25520 +ENTRY(cpu_pgd)
25521 + .rept 2*NR_CPUS
25522 + .fill 4,8,0
25523 + .endr
25524 +#endif
25525 +
25526 #endif
25527
25528 .data
25529 .balign 4
25530 ENTRY(stack_start)
25531 - .long init_thread_union+THREAD_SIZE
25532 + .long init_thread_union+THREAD_SIZE-8
25533
25534 __INITRODATA
25535 int_msg:
25536 @@ -727,7 +825,7 @@ fault_msg:
25537 * segment size, and 32-bit linear address value:
25538 */
25539
25540 - .data
25541 +.section .rodata,"a",@progbits
25542 .globl boot_gdt_descr
25543 .globl idt_descr
25544
25545 @@ -736,7 +834,7 @@ fault_msg:
25546 .word 0 # 32 bit align gdt_desc.address
25547 boot_gdt_descr:
25548 .word __BOOT_DS+7
25549 - .long boot_gdt - __PAGE_OFFSET
25550 + .long pa(boot_gdt)
25551
25552 .word 0 # 32-bit align idt_desc.address
25553 idt_descr:
25554 @@ -747,7 +845,7 @@ idt_descr:
25555 .word 0 # 32 bit align gdt_desc.address
25556 ENTRY(early_gdt_descr)
25557 .word GDT_ENTRIES*8-1
25558 - .long gdt_page /* Overwritten for secondary CPUs */
25559 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
25560
25561 /*
25562 * The boot_gdt must mirror the equivalent in setup.S and is
25563 @@ -756,5 +854,65 @@ ENTRY(early_gdt_descr)
25564 .align L1_CACHE_BYTES
25565 ENTRY(boot_gdt)
25566 .fill GDT_ENTRY_BOOT_CS,8,0
25567 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
25568 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
25569 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
25570 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
25571 +
25572 + .align PAGE_SIZE_asm
25573 +ENTRY(cpu_gdt_table)
25574 + .rept NR_CPUS
25575 + .quad 0x0000000000000000 /* NULL descriptor */
25576 + .quad 0x0000000000000000 /* 0x0b reserved */
25577 + .quad 0x0000000000000000 /* 0x13 reserved */
25578 + .quad 0x0000000000000000 /* 0x1b reserved */
25579 +
25580 +#ifdef CONFIG_PAX_KERNEXEC
25581 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
25582 +#else
25583 + .quad 0x0000000000000000 /* 0x20 unused */
25584 +#endif
25585 +
25586 + .quad 0x0000000000000000 /* 0x28 unused */
25587 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
25588 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
25589 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
25590 + .quad 0x0000000000000000 /* 0x4b reserved */
25591 + .quad 0x0000000000000000 /* 0x53 reserved */
25592 + .quad 0x0000000000000000 /* 0x5b reserved */
25593 +
25594 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
25595 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
25596 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
25597 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
25598 +
25599 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
25600 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
25601 +
25602 + /*
25603 + * Segments used for calling PnP BIOS have byte granularity.
25604 + * The code segments and data segments have fixed 64k limits,
25605 + * the transfer segment sizes are set at run time.
25606 + */
25607 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
25608 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
25609 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
25610 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
25611 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
25612 +
25613 + /*
25614 + * The APM segments have byte granularity and their bases
25615 + * are set at run time. All have 64k limits.
25616 + */
25617 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
25618 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
25619 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
25620 +
25621 + .quad 0x00c093000000ffff /* 0xd0 - ESPFIX SS */
25622 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
25623 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
25624 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
25625 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
25626 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
25627 +
25628 + /* Be sure this is zeroed to avoid false validations in Xen */
25629 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
25630 + .endr
25631 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
25632 index a468c0a..8b5a879 100644
25633 --- a/arch/x86/kernel/head_64.S
25634 +++ b/arch/x86/kernel/head_64.S
25635 @@ -20,6 +20,8 @@
25636 #include <asm/processor-flags.h>
25637 #include <asm/percpu.h>
25638 #include <asm/nops.h>
25639 +#include <asm/cpufeature.h>
25640 +#include <asm/alternative-asm.h>
25641
25642 #ifdef CONFIG_PARAVIRT
25643 #include <asm/asm-offsets.h>
25644 @@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
25645 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
25646 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
25647 L3_START_KERNEL = pud_index(__START_KERNEL_map)
25648 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
25649 +L3_VMALLOC_START = pud_index(VMALLOC_START)
25650 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
25651 +L3_VMALLOC_END = pud_index(VMALLOC_END)
25652 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
25653 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
25654
25655 .text
25656 __HEAD
25657 @@ -89,11 +97,24 @@ startup_64:
25658 * Fixup the physical addresses in the page table
25659 */
25660 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
25661 + addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
25662 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
25663 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
25664 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
25665 + addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
25666
25667 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
25668 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
25669 + addq %rbp, level3_ident_pgt + (0*8)(%rip)
25670 +#ifndef CONFIG_XEN
25671 + addq %rbp, level3_ident_pgt + (1*8)(%rip)
25672 +#endif
25673 +
25674 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
25675 +
25676 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
25677 + addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
25678
25679 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
25680 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
25681
25682 /*
25683 * Set up the identity mapping for the switchover. These
25684 @@ -174,11 +195,12 @@ ENTRY(secondary_startup_64)
25685 * after the boot processor executes this code.
25686 */
25687
25688 + orq $-1, %rbp
25689 movq $(init_level4_pgt - __START_KERNEL_map), %rax
25690 1:
25691
25692 - /* Enable PAE mode and PGE */
25693 - movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
25694 + /* Enable PAE mode and PSE/PGE */
25695 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
25696 movq %rcx, %cr4
25697
25698 /* Setup early boot stage 4 level pagetables. */
25699 @@ -199,10 +221,19 @@ ENTRY(secondary_startup_64)
25700 movl $MSR_EFER, %ecx
25701 rdmsr
25702 btsl $_EFER_SCE, %eax /* Enable System Call */
25703 - btl $20,%edi /* No Execute supported? */
25704 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
25705 jnc 1f
25706 btsl $_EFER_NX, %eax
25707 + cmpq $-1, %rbp
25708 + je 1f
25709 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
25710 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_PAGE_OFFSET(%rip)
25711 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_START(%rip)
25712 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_END(%rip)
25713 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMEMMAP_START(%rip)
25714 + btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*506(%rip)
25715 + btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*507(%rip)
25716 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
25717 1: wrmsr /* Make changes effective */
25718
25719 /* Setup cr0 */
25720 @@ -282,6 +313,7 @@ ENTRY(secondary_startup_64)
25721 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
25722 * address given in m16:64.
25723 */
25724 + pax_set_fptr_mask
25725 movq initial_code(%rip),%rax
25726 pushq $0 # fake return address to stop unwinder
25727 pushq $__KERNEL_CS # set correct cs
25728 @@ -313,7 +345,7 @@ ENDPROC(start_cpu0)
25729 .quad INIT_PER_CPU_VAR(irq_stack_union)
25730
25731 GLOBAL(stack_start)
25732 - .quad init_thread_union+THREAD_SIZE-8
25733 + .quad init_thread_union+THREAD_SIZE-16
25734 .word 0
25735 __FINITDATA
25736
25737 @@ -391,7 +423,7 @@ ENTRY(early_idt_handler)
25738 call dump_stack
25739 #ifdef CONFIG_KALLSYMS
25740 leaq early_idt_ripmsg(%rip),%rdi
25741 - movq 40(%rsp),%rsi # %rip again
25742 + movq 88(%rsp),%rsi # %rip again
25743 call __print_symbol
25744 #endif
25745 #endif /* EARLY_PRINTK */
25746 @@ -420,6 +452,7 @@ ENDPROC(early_idt_handler)
25747 early_recursion_flag:
25748 .long 0
25749
25750 + .section .rodata,"a",@progbits
25751 #ifdef CONFIG_EARLY_PRINTK
25752 early_idt_msg:
25753 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
25754 @@ -447,29 +480,52 @@ NEXT_PAGE(early_level4_pgt)
25755 NEXT_PAGE(early_dynamic_pgts)
25756 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
25757
25758 - .data
25759 + .section .rodata,"a",@progbits
25760
25761 -#ifndef CONFIG_XEN
25762 NEXT_PAGE(init_level4_pgt)
25763 - .fill 512,8,0
25764 -#else
25765 -NEXT_PAGE(init_level4_pgt)
25766 - .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
25767 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
25768 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
25769 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
25770 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
25771 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
25772 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
25773 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
25774 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
25775 .org init_level4_pgt + L4_START_KERNEL*8, 0
25776 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
25777 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
25778
25779 +#ifdef CONFIG_PAX_PER_CPU_PGD
25780 +NEXT_PAGE(cpu_pgd)
25781 + .rept 2*NR_CPUS
25782 + .fill 512,8,0
25783 + .endr
25784 +#endif
25785 +
25786 NEXT_PAGE(level3_ident_pgt)
25787 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
25788 +#ifdef CONFIG_XEN
25789 .fill 511, 8, 0
25790 +#else
25791 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
25792 + .fill 510,8,0
25793 +#endif
25794 +
25795 +NEXT_PAGE(level3_vmalloc_start_pgt)
25796 + .fill 512,8,0
25797 +
25798 +NEXT_PAGE(level3_vmalloc_end_pgt)
25799 + .fill 512,8,0
25800 +
25801 +NEXT_PAGE(level3_vmemmap_pgt)
25802 + .fill L3_VMEMMAP_START,8,0
25803 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
25804 +
25805 NEXT_PAGE(level2_ident_pgt)
25806 - /* Since I easily can, map the first 1G.
25807 + /* Since I easily can, map the first 2G.
25808 * Don't set NX because code runs from these pages.
25809 */
25810 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
25811 -#endif
25812 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
25813
25814 NEXT_PAGE(level3_kernel_pgt)
25815 .fill L3_START_KERNEL,8,0
25816 @@ -477,6 +533,9 @@ NEXT_PAGE(level3_kernel_pgt)
25817 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
25818 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
25819
25820 +NEXT_PAGE(level2_vmemmap_pgt)
25821 + .fill 512,8,0
25822 +
25823 NEXT_PAGE(level2_kernel_pgt)
25824 /*
25825 * 512 MB kernel mapping. We spend a full page on this pagetable
25826 @@ -494,28 +553,64 @@ NEXT_PAGE(level2_kernel_pgt)
25827 NEXT_PAGE(level2_fixmap_pgt)
25828 .fill 506,8,0
25829 .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
25830 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
25831 - .fill 5,8,0
25832 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
25833 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
25834 + .fill 4,8,0
25835
25836 NEXT_PAGE(level1_fixmap_pgt)
25837 .fill 512,8,0
25838
25839 +NEXT_PAGE(level1_vsyscall_pgt)
25840 + .fill 512,8,0
25841 +
25842 #undef PMDS
25843
25844 - .data
25845 + .align PAGE_SIZE
25846 +ENTRY(cpu_gdt_table)
25847 + .rept NR_CPUS
25848 + .quad 0x0000000000000000 /* NULL descriptor */
25849 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
25850 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
25851 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
25852 + .quad 0x00cffb000000ffff /* __USER32_CS */
25853 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
25854 + .quad 0x00affb000000ffff /* __USER_CS */
25855 +
25856 +#ifdef CONFIG_PAX_KERNEXEC
25857 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
25858 +#else
25859 + .quad 0x0 /* unused */
25860 +#endif
25861 +
25862 + .quad 0,0 /* TSS */
25863 + .quad 0,0 /* LDT */
25864 + .quad 0,0,0 /* three TLS descriptors */
25865 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
25866 + /* asm/segment.h:GDT_ENTRIES must match this */
25867 +
25868 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25869 + .quad 0x00cf93000000ffff /* __UDEREF_KERNEL_DS */
25870 +#else
25871 + .quad 0x0 /* unused */
25872 +#endif
25873 +
25874 + /* zero the remaining page */
25875 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
25876 + .endr
25877 +
25878 .align 16
25879 .globl early_gdt_descr
25880 early_gdt_descr:
25881 .word GDT_ENTRIES*8-1
25882 early_gdt_descr_base:
25883 - .quad INIT_PER_CPU_VAR(gdt_page)
25884 + .quad cpu_gdt_table
25885
25886 ENTRY(phys_base)
25887 /* This must match the first entry in level2_kernel_pgt */
25888 .quad 0x0000000000000000
25889
25890 #include "../../x86/xen/xen-head.S"
25891 -
25892 - __PAGE_ALIGNED_BSS
25893 +
25894 + .section .rodata,"a",@progbits
25895 NEXT_PAGE(empty_zero_page)
25896 .skip PAGE_SIZE
25897 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
25898 index 05fd74f..c3548b1 100644
25899 --- a/arch/x86/kernel/i386_ksyms_32.c
25900 +++ b/arch/x86/kernel/i386_ksyms_32.c
25901 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
25902 EXPORT_SYMBOL(cmpxchg8b_emu);
25903 #endif
25904
25905 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
25906 +
25907 /* Networking helper routines. */
25908 EXPORT_SYMBOL(csum_partial_copy_generic);
25909 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
25910 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
25911
25912 EXPORT_SYMBOL(__get_user_1);
25913 EXPORT_SYMBOL(__get_user_2);
25914 @@ -44,3 +48,11 @@ EXPORT_SYMBOL(___preempt_schedule);
25915 EXPORT_SYMBOL(___preempt_schedule_context);
25916 #endif
25917 #endif
25918 +
25919 +#ifdef CONFIG_PAX_KERNEXEC
25920 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
25921 +#endif
25922 +
25923 +#ifdef CONFIG_PAX_PER_CPU_PGD
25924 +EXPORT_SYMBOL(cpu_pgd);
25925 +#endif
25926 diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
25927 index a9a4229..6f4d476 100644
25928 --- a/arch/x86/kernel/i387.c
25929 +++ b/arch/x86/kernel/i387.c
25930 @@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
25931 static inline bool interrupted_user_mode(void)
25932 {
25933 struct pt_regs *regs = get_irq_regs();
25934 - return regs && user_mode_vm(regs);
25935 + return regs && user_mode(regs);
25936 }
25937
25938 /*
25939 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
25940 index 8af8171..f8c1169 100644
25941 --- a/arch/x86/kernel/i8259.c
25942 +++ b/arch/x86/kernel/i8259.c
25943 @@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
25944 static void make_8259A_irq(unsigned int irq)
25945 {
25946 disable_irq_nosync(irq);
25947 - io_apic_irqs &= ~(1<<irq);
25948 + io_apic_irqs &= ~(1UL<<irq);
25949 irq_set_chip_and_handler_name(irq, &i8259A_chip, handle_level_irq,
25950 i8259A_chip.name);
25951 enable_irq(irq);
25952 @@ -209,7 +209,7 @@ spurious_8259A_irq:
25953 "spurious 8259A interrupt: IRQ%d.\n", irq);
25954 spurious_irq_mask |= irqmask;
25955 }
25956 - atomic_inc(&irq_err_count);
25957 + atomic_inc_unchecked(&irq_err_count);
25958 /*
25959 * Theoretically we do not have to handle this IRQ,
25960 * but in Linux this does not cause problems and is
25961 @@ -350,14 +350,16 @@ static void init_8259A(int auto_eoi)
25962 /* (slave's support for AEOI in flat mode is to be investigated) */
25963 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
25964
25965 + pax_open_kernel();
25966 if (auto_eoi)
25967 /*
25968 * In AEOI mode we just have to mask the interrupt
25969 * when acking.
25970 */
25971 - i8259A_chip.irq_mask_ack = disable_8259A_irq;
25972 + *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
25973 else
25974 - i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
25975 + *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
25976 + pax_close_kernel();
25977
25978 udelay(100); /* wait for 8259A to initialize */
25979
25980 diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
25981 index a979b5b..1d6db75 100644
25982 --- a/arch/x86/kernel/io_delay.c
25983 +++ b/arch/x86/kernel/io_delay.c
25984 @@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
25985 * Quirk table for systems that misbehave (lock up, etc.) if port
25986 * 0x80 is used:
25987 */
25988 -static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
25989 +static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
25990 {
25991 .callback = dmi_io_delay_0xed_port,
25992 .ident = "Compaq Presario V6000",
25993 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
25994 index 4ddaf66..49d5c18 100644
25995 --- a/arch/x86/kernel/ioport.c
25996 +++ b/arch/x86/kernel/ioport.c
25997 @@ -6,6 +6,7 @@
25998 #include <linux/sched.h>
25999 #include <linux/kernel.h>
26000 #include <linux/capability.h>
26001 +#include <linux/security.h>
26002 #include <linux/errno.h>
26003 #include <linux/types.h>
26004 #include <linux/ioport.h>
26005 @@ -30,6 +31,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
26006 return -EINVAL;
26007 if (turn_on && !capable(CAP_SYS_RAWIO))
26008 return -EPERM;
26009 +#ifdef CONFIG_GRKERNSEC_IO
26010 + if (turn_on && grsec_disable_privio) {
26011 + gr_handle_ioperm();
26012 + return -ENODEV;
26013 + }
26014 +#endif
26015
26016 /*
26017 * If it's the first ioperm() call in this thread's lifetime, set the
26018 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
26019 * because the ->io_bitmap_max value must match the bitmap
26020 * contents:
26021 */
26022 - tss = &per_cpu(init_tss, get_cpu());
26023 + tss = init_tss + get_cpu();
26024
26025 if (turn_on)
26026 bitmap_clear(t->io_bitmap_ptr, from, num);
26027 @@ -105,6 +112,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
26028 if (level > old) {
26029 if (!capable(CAP_SYS_RAWIO))
26030 return -EPERM;
26031 +#ifdef CONFIG_GRKERNSEC_IO
26032 + if (grsec_disable_privio) {
26033 + gr_handle_iopl();
26034 + return -ENODEV;
26035 + }
26036 +#endif
26037 }
26038 regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12);
26039 t->iopl = level << 12;
26040 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
26041 index 922d285..6d20692 100644
26042 --- a/arch/x86/kernel/irq.c
26043 +++ b/arch/x86/kernel/irq.c
26044 @@ -22,7 +22,7 @@
26045 #define CREATE_TRACE_POINTS
26046 #include <asm/trace/irq_vectors.h>
26047
26048 -atomic_t irq_err_count;
26049 +atomic_unchecked_t irq_err_count;
26050
26051 /* Function pointer for generic interrupt vector handling */
26052 void (*x86_platform_ipi_callback)(void) = NULL;
26053 @@ -132,9 +132,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
26054 seq_printf(p, "%10u ", irq_stats(j)->irq_hv_callback_count);
26055 seq_printf(p, " Hypervisor callback interrupts\n");
26056 #endif
26057 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
26058 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
26059 #if defined(CONFIG_X86_IO_APIC)
26060 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
26061 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
26062 #endif
26063 return 0;
26064 }
26065 @@ -174,7 +174,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
26066
26067 u64 arch_irq_stat(void)
26068 {
26069 - u64 sum = atomic_read(&irq_err_count);
26070 + u64 sum = atomic_read_unchecked(&irq_err_count);
26071 return sum;
26072 }
26073
26074 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
26075 index 63ce838..2ea3e06 100644
26076 --- a/arch/x86/kernel/irq_32.c
26077 +++ b/arch/x86/kernel/irq_32.c
26078 @@ -29,6 +29,8 @@ EXPORT_PER_CPU_SYMBOL(irq_regs);
26079
26080 #ifdef CONFIG_DEBUG_STACKOVERFLOW
26081
26082 +extern void gr_handle_kernel_exploit(void);
26083 +
26084 int sysctl_panic_on_stackoverflow __read_mostly;
26085
26086 /* Debugging check for stack overflow: is there less than 1KB free? */
26087 @@ -39,13 +41,14 @@ static int check_stack_overflow(void)
26088 __asm__ __volatile__("andl %%esp,%0" :
26089 "=r" (sp) : "0" (THREAD_SIZE - 1));
26090
26091 - return sp < (sizeof(struct thread_info) + STACK_WARN);
26092 + return sp < STACK_WARN;
26093 }
26094
26095 static void print_stack_overflow(void)
26096 {
26097 printk(KERN_WARNING "low stack detected by irq handler\n");
26098 dump_stack();
26099 + gr_handle_kernel_exploit();
26100 if (sysctl_panic_on_stackoverflow)
26101 panic("low stack detected by irq handler - check messages\n");
26102 }
26103 @@ -84,10 +87,9 @@ static inline void *current_stack(void)
26104 static inline int
26105 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
26106 {
26107 - struct irq_stack *curstk, *irqstk;
26108 + struct irq_stack *irqstk;
26109 u32 *isp, *prev_esp, arg1, arg2;
26110
26111 - curstk = (struct irq_stack *) current_stack();
26112 irqstk = __this_cpu_read(hardirq_stack);
26113
26114 /*
26115 @@ -96,15 +98,19 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
26116 * handler) we can't do that and just have to keep using the
26117 * current stack (which is the irq stack already after all)
26118 */
26119 - if (unlikely(curstk == irqstk))
26120 + if (unlikely((void *)current_stack_pointer - (void *)irqstk < THREAD_SIZE))
26121 return 0;
26122
26123 - isp = (u32 *) ((char *)irqstk + sizeof(*irqstk));
26124 + isp = (u32 *) ((char *)irqstk + sizeof(*irqstk) - 8);
26125
26126 /* Save the next esp at the bottom of the stack */
26127 prev_esp = (u32 *)irqstk;
26128 *prev_esp = current_stack_pointer;
26129
26130 +#ifdef CONFIG_PAX_MEMORY_UDEREF
26131 + __set_fs(MAKE_MM_SEG(0));
26132 +#endif
26133 +
26134 if (unlikely(overflow))
26135 call_on_stack(print_stack_overflow, isp);
26136
26137 @@ -115,6 +121,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
26138 : "0" (irq), "1" (desc), "2" (isp),
26139 "D" (desc->handle_irq)
26140 : "memory", "cc", "ecx");
26141 +
26142 +#ifdef CONFIG_PAX_MEMORY_UDEREF
26143 + __set_fs(current_thread_info()->addr_limit);
26144 +#endif
26145 +
26146 return 1;
26147 }
26148
26149 @@ -123,32 +134,18 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
26150 */
26151 void irq_ctx_init(int cpu)
26152 {
26153 - struct irq_stack *irqstk;
26154 -
26155 if (per_cpu(hardirq_stack, cpu))
26156 return;
26157
26158 - irqstk = page_address(alloc_pages_node(cpu_to_node(cpu),
26159 - THREADINFO_GFP,
26160 - THREAD_SIZE_ORDER));
26161 - per_cpu(hardirq_stack, cpu) = irqstk;
26162 -
26163 - irqstk = page_address(alloc_pages_node(cpu_to_node(cpu),
26164 - THREADINFO_GFP,
26165 - THREAD_SIZE_ORDER));
26166 - per_cpu(softirq_stack, cpu) = irqstk;
26167 -
26168 - printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
26169 - cpu, per_cpu(hardirq_stack, cpu), per_cpu(softirq_stack, cpu));
26170 + per_cpu(hardirq_stack, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
26171 + per_cpu(softirq_stack, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
26172 }
26173
26174 void do_softirq_own_stack(void)
26175 {
26176 - struct thread_info *curstk;
26177 struct irq_stack *irqstk;
26178 u32 *isp, *prev_esp;
26179
26180 - curstk = current_stack();
26181 irqstk = __this_cpu_read(softirq_stack);
26182
26183 /* build the stack frame on the softirq stack */
26184 @@ -158,7 +155,16 @@ void do_softirq_own_stack(void)
26185 prev_esp = (u32 *)irqstk;
26186 *prev_esp = current_stack_pointer;
26187
26188 +#ifdef CONFIG_PAX_MEMORY_UDEREF
26189 + __set_fs(MAKE_MM_SEG(0));
26190 +#endif
26191 +
26192 call_on_stack(__do_softirq, isp);
26193 +
26194 +#ifdef CONFIG_PAX_MEMORY_UDEREF
26195 + __set_fs(current_thread_info()->addr_limit);
26196 +#endif
26197 +
26198 }
26199
26200 bool handle_irq(unsigned irq, struct pt_regs *regs)
26201 @@ -172,7 +178,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
26202 if (unlikely(!desc))
26203 return false;
26204
26205 - if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
26206 + if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
26207 if (unlikely(overflow))
26208 print_stack_overflow();
26209 desc->handle_irq(irq, desc);
26210 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
26211 index 4d1c746..55a22d6 100644
26212 --- a/arch/x86/kernel/irq_64.c
26213 +++ b/arch/x86/kernel/irq_64.c
26214 @@ -26,6 +26,8 @@ EXPORT_PER_CPU_SYMBOL(irq_stat);
26215 DEFINE_PER_CPU(struct pt_regs *, irq_regs);
26216 EXPORT_PER_CPU_SYMBOL(irq_regs);
26217
26218 +extern void gr_handle_kernel_exploit(void);
26219 +
26220 int sysctl_panic_on_stackoverflow;
26221
26222 /*
26223 @@ -44,7 +46,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
26224 u64 estack_top, estack_bottom;
26225 u64 curbase = (u64)task_stack_page(current);
26226
26227 - if (user_mode_vm(regs))
26228 + if (user_mode(regs))
26229 return;
26230
26231 if (regs->sp >= curbase + sizeof(struct thread_info) +
26232 @@ -69,6 +71,8 @@ static inline void stack_overflow_check(struct pt_regs *regs)
26233 irq_stack_top, irq_stack_bottom,
26234 estack_top, estack_bottom);
26235
26236 + gr_handle_kernel_exploit();
26237 +
26238 if (sysctl_panic_on_stackoverflow)
26239 panic("low stack detected by irq handler - check messages\n");
26240 #endif
26241 diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
26242 index 26d5a55..a01160a 100644
26243 --- a/arch/x86/kernel/jump_label.c
26244 +++ b/arch/x86/kernel/jump_label.c
26245 @@ -51,7 +51,7 @@ static void __jump_label_transform(struct jump_entry *entry,
26246 * Jump label is enabled for the first time.
26247 * So we expect a default_nop...
26248 */
26249 - if (unlikely(memcmp((void *)entry->code, default_nop, 5)
26250 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5)
26251 != 0))
26252 bug_at((void *)entry->code, __LINE__);
26253 } else {
26254 @@ -59,7 +59,7 @@ static void __jump_label_transform(struct jump_entry *entry,
26255 * ...otherwise expect an ideal_nop. Otherwise
26256 * something went horribly wrong.
26257 */
26258 - if (unlikely(memcmp((void *)entry->code, ideal_nop, 5)
26259 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), ideal_nop, 5)
26260 != 0))
26261 bug_at((void *)entry->code, __LINE__);
26262 }
26263 @@ -75,13 +75,13 @@ static void __jump_label_transform(struct jump_entry *entry,
26264 * are converting the default nop to the ideal nop.
26265 */
26266 if (init) {
26267 - if (unlikely(memcmp((void *)entry->code, default_nop, 5) != 0))
26268 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5) != 0))
26269 bug_at((void *)entry->code, __LINE__);
26270 } else {
26271 code.jump = 0xe9;
26272 code.offset = entry->target -
26273 (entry->code + JUMP_LABEL_NOP_SIZE);
26274 - if (unlikely(memcmp((void *)entry->code, &code, 5) != 0))
26275 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), &code, 5) != 0))
26276 bug_at((void *)entry->code, __LINE__);
26277 }
26278 memcpy(&code, ideal_nops[NOP_ATOMIC5], JUMP_LABEL_NOP_SIZE);
26279 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
26280 index 7ec1d5f..5a7d130 100644
26281 --- a/arch/x86/kernel/kgdb.c
26282 +++ b/arch/x86/kernel/kgdb.c
26283 @@ -126,11 +126,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
26284 #ifdef CONFIG_X86_32
26285 switch (regno) {
26286 case GDB_SS:
26287 - if (!user_mode_vm(regs))
26288 + if (!user_mode(regs))
26289 *(unsigned long *)mem = __KERNEL_DS;
26290 break;
26291 case GDB_SP:
26292 - if (!user_mode_vm(regs))
26293 + if (!user_mode(regs))
26294 *(unsigned long *)mem = kernel_stack_pointer(regs);
26295 break;
26296 case GDB_GS:
26297 @@ -228,7 +228,10 @@ static void kgdb_correct_hw_break(void)
26298 bp->attr.bp_addr = breakinfo[breakno].addr;
26299 bp->attr.bp_len = breakinfo[breakno].len;
26300 bp->attr.bp_type = breakinfo[breakno].type;
26301 - info->address = breakinfo[breakno].addr;
26302 + if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
26303 + info->address = ktla_ktva(breakinfo[breakno].addr);
26304 + else
26305 + info->address = breakinfo[breakno].addr;
26306 info->len = breakinfo[breakno].len;
26307 info->type = breakinfo[breakno].type;
26308 val = arch_install_hw_breakpoint(bp);
26309 @@ -475,12 +478,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
26310 case 'k':
26311 /* clear the trace bit */
26312 linux_regs->flags &= ~X86_EFLAGS_TF;
26313 - atomic_set(&kgdb_cpu_doing_single_step, -1);
26314 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
26315
26316 /* set the trace bit if we're stepping */
26317 if (remcomInBuffer[0] == 's') {
26318 linux_regs->flags |= X86_EFLAGS_TF;
26319 - atomic_set(&kgdb_cpu_doing_single_step,
26320 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
26321 raw_smp_processor_id());
26322 }
26323
26324 @@ -545,7 +548,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
26325
26326 switch (cmd) {
26327 case DIE_DEBUG:
26328 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
26329 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
26330 if (user_mode(regs))
26331 return single_step_cont(regs, args);
26332 break;
26333 @@ -750,11 +753,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
26334 #endif /* CONFIG_DEBUG_RODATA */
26335
26336 bpt->type = BP_BREAKPOINT;
26337 - err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
26338 + err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
26339 BREAK_INSTR_SIZE);
26340 if (err)
26341 return err;
26342 - err = probe_kernel_write((char *)bpt->bpt_addr,
26343 + err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
26344 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
26345 #ifdef CONFIG_DEBUG_RODATA
26346 if (!err)
26347 @@ -767,7 +770,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
26348 return -EBUSY;
26349 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
26350 BREAK_INSTR_SIZE);
26351 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
26352 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
26353 if (err)
26354 return err;
26355 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
26356 @@ -792,13 +795,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
26357 if (mutex_is_locked(&text_mutex))
26358 goto knl_write;
26359 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
26360 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
26361 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
26362 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
26363 goto knl_write;
26364 return err;
26365 knl_write:
26366 #endif /* CONFIG_DEBUG_RODATA */
26367 - return probe_kernel_write((char *)bpt->bpt_addr,
26368 + return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
26369 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
26370 }
26371
26372 diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
26373 index 67e6d19..731ed28 100644
26374 --- a/arch/x86/kernel/kprobes/core.c
26375 +++ b/arch/x86/kernel/kprobes/core.c
26376 @@ -120,9 +120,12 @@ __synthesize_relative_insn(void *from, void *to, u8 op)
26377 s32 raddr;
26378 } __packed *insn;
26379
26380 - insn = (struct __arch_relative_insn *)from;
26381 + insn = (struct __arch_relative_insn *)ktla_ktva(from);
26382 +
26383 + pax_open_kernel();
26384 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
26385 insn->op = op;
26386 + pax_close_kernel();
26387 }
26388
26389 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
26390 @@ -168,7 +171,7 @@ int can_boost(kprobe_opcode_t *opcodes)
26391 kprobe_opcode_t opcode;
26392 kprobe_opcode_t *orig_opcodes = opcodes;
26393
26394 - if (search_exception_tables((unsigned long)opcodes))
26395 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
26396 return 0; /* Page fault may occur on this address. */
26397
26398 retry:
26399 @@ -242,9 +245,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
26400 * for the first byte, we can recover the original instruction
26401 * from it and kp->opcode.
26402 */
26403 - memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
26404 + memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
26405 buf[0] = kp->opcode;
26406 - return (unsigned long)buf;
26407 + return ktva_ktla((unsigned long)buf);
26408 }
26409
26410 /*
26411 @@ -336,7 +339,9 @@ int __copy_instruction(u8 *dest, u8 *src)
26412 /* Another subsystem puts a breakpoint, failed to recover */
26413 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
26414 return 0;
26415 + pax_open_kernel();
26416 memcpy(dest, insn.kaddr, insn.length);
26417 + pax_close_kernel();
26418
26419 #ifdef CONFIG_X86_64
26420 if (insn_rip_relative(&insn)) {
26421 @@ -363,7 +368,9 @@ int __copy_instruction(u8 *dest, u8 *src)
26422 return 0;
26423 }
26424 disp = (u8 *) dest + insn_offset_displacement(&insn);
26425 + pax_open_kernel();
26426 *(s32 *) disp = (s32) newdisp;
26427 + pax_close_kernel();
26428 }
26429 #endif
26430 return insn.length;
26431 @@ -505,7 +512,7 @@ static void setup_singlestep(struct kprobe *p, struct pt_regs *regs,
26432 * nor set current_kprobe, because it doesn't use single
26433 * stepping.
26434 */
26435 - regs->ip = (unsigned long)p->ainsn.insn;
26436 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
26437 preempt_enable_no_resched();
26438 return;
26439 }
26440 @@ -522,9 +529,9 @@ static void setup_singlestep(struct kprobe *p, struct pt_regs *regs,
26441 regs->flags &= ~X86_EFLAGS_IF;
26442 /* single step inline if the instruction is an int3 */
26443 if (p->opcode == BREAKPOINT_INSTRUCTION)
26444 - regs->ip = (unsigned long)p->addr;
26445 + regs->ip = ktla_ktva((unsigned long)p->addr);
26446 else
26447 - regs->ip = (unsigned long)p->ainsn.insn;
26448 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
26449 }
26450 NOKPROBE_SYMBOL(setup_singlestep);
26451
26452 @@ -574,7 +581,7 @@ int kprobe_int3_handler(struct pt_regs *regs)
26453 struct kprobe *p;
26454 struct kprobe_ctlblk *kcb;
26455
26456 - if (user_mode_vm(regs))
26457 + if (user_mode(regs))
26458 return 0;
26459
26460 addr = (kprobe_opcode_t *)(regs->ip - sizeof(kprobe_opcode_t));
26461 @@ -609,7 +616,7 @@ int kprobe_int3_handler(struct pt_regs *regs)
26462 setup_singlestep(p, regs, kcb, 0);
26463 return 1;
26464 }
26465 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
26466 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
26467 /*
26468 * The breakpoint instruction was removed right
26469 * after we hit it. Another cpu has removed
26470 @@ -656,6 +663,9 @@ static void __used kretprobe_trampoline_holder(void)
26471 " movq %rax, 152(%rsp)\n"
26472 RESTORE_REGS_STRING
26473 " popfq\n"
26474 +#ifdef KERNEXEC_PLUGIN
26475 + " btsq $63,(%rsp)\n"
26476 +#endif
26477 #else
26478 " pushf\n"
26479 SAVE_REGS_STRING
26480 @@ -796,7 +806,7 @@ static void resume_execution(struct kprobe *p, struct pt_regs *regs,
26481 struct kprobe_ctlblk *kcb)
26482 {
26483 unsigned long *tos = stack_addr(regs);
26484 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
26485 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
26486 unsigned long orig_ip = (unsigned long)p->addr;
26487 kprobe_opcode_t *insn = p->ainsn.insn;
26488
26489 @@ -979,7 +989,7 @@ int kprobe_exceptions_notify(struct notifier_block *self, unsigned long val,
26490 struct die_args *args = data;
26491 int ret = NOTIFY_DONE;
26492
26493 - if (args->regs && user_mode_vm(args->regs))
26494 + if (args->regs && user_mode(args->regs))
26495 return ret;
26496
26497 if (val == DIE_GPF) {
26498 diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
26499 index f1314d0..15f3154 100644
26500 --- a/arch/x86/kernel/kprobes/opt.c
26501 +++ b/arch/x86/kernel/kprobes/opt.c
26502 @@ -79,6 +79,7 @@ found:
26503 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
26504 static void synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
26505 {
26506 + pax_open_kernel();
26507 #ifdef CONFIG_X86_64
26508 *addr++ = 0x48;
26509 *addr++ = 0xbf;
26510 @@ -86,6 +87,7 @@ static void synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
26511 *addr++ = 0xb8;
26512 #endif
26513 *(unsigned long *)addr = val;
26514 + pax_close_kernel();
26515 }
26516
26517 asm (
26518 @@ -337,7 +339,7 @@ int arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
26519 * Verify if the address gap is in 2GB range, because this uses
26520 * a relative jump.
26521 */
26522 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
26523 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
26524 if (abs(rel) > 0x7fffffff) {
26525 __arch_remove_optimized_kprobe(op, 0);
26526 return -ERANGE;
26527 @@ -354,16 +356,18 @@ int arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
26528 op->optinsn.size = ret;
26529
26530 /* Copy arch-dep-instance from template */
26531 - memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
26532 + pax_open_kernel();
26533 + memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
26534 + pax_close_kernel();
26535
26536 /* Set probe information */
26537 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
26538
26539 /* Set probe function call */
26540 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
26541 + synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
26542
26543 /* Set returning jmp instruction at the tail of out-of-line buffer */
26544 - synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
26545 + synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
26546 (u8 *)op->kp.addr + op->optinsn.size);
26547
26548 flush_icache_range((unsigned long) buf,
26549 @@ -388,7 +392,7 @@ void arch_optimize_kprobes(struct list_head *oplist)
26550 WARN_ON(kprobe_disabled(&op->kp));
26551
26552 /* Backup instructions which will be replaced by jump address */
26553 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
26554 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
26555 RELATIVE_ADDR_SIZE);
26556
26557 insn_buf[0] = RELATIVEJUMP_OPCODE;
26558 @@ -436,7 +440,7 @@ int setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
26559 /* This kprobe is really able to run optimized path. */
26560 op = container_of(p, struct optimized_kprobe, kp);
26561 /* Detour through copied instructions */
26562 - regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
26563 + regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
26564 if (!reenter)
26565 reset_current_kprobe();
26566 preempt_enable_no_resched();
26567 diff --git a/arch/x86/kernel/ksysfs.c b/arch/x86/kernel/ksysfs.c
26568 index c2bedae..25e7ab60 100644
26569 --- a/arch/x86/kernel/ksysfs.c
26570 +++ b/arch/x86/kernel/ksysfs.c
26571 @@ -184,7 +184,7 @@ out:
26572
26573 static struct kobj_attribute type_attr = __ATTR_RO(type);
26574
26575 -static struct bin_attribute data_attr = {
26576 +static bin_attribute_no_const data_attr __read_only = {
26577 .attr = {
26578 .name = "data",
26579 .mode = S_IRUGO,
26580 diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
26581 index 3dd8e2c..07de51f 100644
26582 --- a/arch/x86/kernel/kvm.c
26583 +++ b/arch/x86/kernel/kvm.c
26584 @@ -282,7 +282,14 @@ NOKPROBE_SYMBOL(do_async_page_fault);
26585 static void __init paravirt_ops_setup(void)
26586 {
26587 pv_info.name = "KVM";
26588 - pv_info.paravirt_enabled = 1;
26589 +
26590 + /*
26591 + * KVM isn't paravirt in the sense of paravirt_enabled. A KVM
26592 + * guest kernel works like a bare metal kernel with additional
26593 + * features, and paravirt_enabled is about features that are
26594 + * missing.
26595 + */
26596 + pv_info.paravirt_enabled = 0;
26597
26598 if (kvm_para_has_feature(KVM_FEATURE_NOP_IO_DELAY))
26599 pv_cpu_ops.io_delay = kvm_io_delay;
26600 diff --git a/arch/x86/kernel/kvmclock.c b/arch/x86/kernel/kvmclock.c
26601 index d9156ce..a2de9bc 100644
26602 --- a/arch/x86/kernel/kvmclock.c
26603 +++ b/arch/x86/kernel/kvmclock.c
26604 @@ -263,7 +263,6 @@ void __init kvmclock_init(void)
26605 #endif
26606 kvm_get_preset_lpj();
26607 clocksource_register_hz(&kvm_clock, NSEC_PER_SEC);
26608 - pv_info.paravirt_enabled = 1;
26609 pv_info.name = "KVM";
26610
26611 if (kvm_para_has_feature(KVM_FEATURE_CLOCKSOURCE_STABLE_BIT))
26612 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
26613 index c37886d..d851d32 100644
26614 --- a/arch/x86/kernel/ldt.c
26615 +++ b/arch/x86/kernel/ldt.c
26616 @@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
26617 if (reload) {
26618 #ifdef CONFIG_SMP
26619 preempt_disable();
26620 - load_LDT(pc);
26621 + load_LDT_nolock(pc);
26622 if (!cpumask_equal(mm_cpumask(current->mm),
26623 cpumask_of(smp_processor_id())))
26624 smp_call_function(flush_ldt, current->mm, 1);
26625 preempt_enable();
26626 #else
26627 - load_LDT(pc);
26628 + load_LDT_nolock(pc);
26629 #endif
26630 }
26631 if (oldsize) {
26632 @@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
26633 return err;
26634
26635 for (i = 0; i < old->size; i++)
26636 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
26637 + write_ldt_entry(new->ldt, i, old->ldt + i);
26638 return 0;
26639 }
26640
26641 @@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
26642 retval = copy_ldt(&mm->context, &old_mm->context);
26643 mutex_unlock(&old_mm->context.lock);
26644 }
26645 +
26646 + if (tsk == current) {
26647 + mm->context.vdso = 0;
26648 +
26649 +#ifdef CONFIG_X86_32
26650 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
26651 + mm->context.user_cs_base = 0UL;
26652 + mm->context.user_cs_limit = ~0UL;
26653 +
26654 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
26655 + cpus_clear(mm->context.cpu_user_cs_mask);
26656 +#endif
26657 +
26658 +#endif
26659 +#endif
26660 +
26661 + }
26662 +
26663 return retval;
26664 }
26665
26666 @@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
26667 }
26668 }
26669
26670 +#ifdef CONFIG_PAX_SEGMEXEC
26671 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
26672 + error = -EINVAL;
26673 + goto out_unlock;
26674 + }
26675 +#endif
26676 +
26677 if (!IS_ENABLED(CONFIG_X86_16BIT) && !ldt_info.seg_32bit) {
26678 error = -EINVAL;
26679 goto out_unlock;
26680 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
26681 index 1667b1d..16492c5 100644
26682 --- a/arch/x86/kernel/machine_kexec_32.c
26683 +++ b/arch/x86/kernel/machine_kexec_32.c
26684 @@ -25,7 +25,7 @@
26685 #include <asm/cacheflush.h>
26686 #include <asm/debugreg.h>
26687
26688 -static void set_idt(void *newidt, __u16 limit)
26689 +static void set_idt(struct desc_struct *newidt, __u16 limit)
26690 {
26691 struct desc_ptr curidt;
26692
26693 @@ -37,7 +37,7 @@ static void set_idt(void *newidt, __u16 limit)
26694 }
26695
26696
26697 -static void set_gdt(void *newgdt, __u16 limit)
26698 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
26699 {
26700 struct desc_ptr curgdt;
26701
26702 @@ -215,7 +215,7 @@ void machine_kexec(struct kimage *image)
26703 }
26704
26705 control_page = page_address(image->control_code_page);
26706 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
26707 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
26708
26709 relocate_kernel_ptr = control_page;
26710 page_list[PA_CONTROL_PAGE] = __pa(control_page);
26711 diff --git a/arch/x86/kernel/mcount_64.S b/arch/x86/kernel/mcount_64.S
26712 index c73aecf..4c63630 100644
26713 --- a/arch/x86/kernel/mcount_64.S
26714 +++ b/arch/x86/kernel/mcount_64.S
26715 @@ -7,7 +7,7 @@
26716 #include <linux/linkage.h>
26717 #include <asm/ptrace.h>
26718 #include <asm/ftrace.h>
26719 -
26720 +#include <asm/alternative-asm.h>
26721
26722 .code64
26723 .section .entry.text, "ax"
26724 @@ -24,8 +24,9 @@
26725 #ifdef CONFIG_DYNAMIC_FTRACE
26726
26727 ENTRY(function_hook)
26728 + pax_force_retaddr
26729 retq
26730 -END(function_hook)
26731 +ENDPROC(function_hook)
26732
26733 /* skip is set if stack has been adjusted */
26734 .macro ftrace_caller_setup skip=0
26735 @@ -62,8 +63,9 @@ GLOBAL(ftrace_graph_call)
26736 #endif
26737
26738 GLOBAL(ftrace_stub)
26739 + pax_force_retaddr
26740 retq
26741 -END(ftrace_caller)
26742 +ENDPROC(ftrace_caller)
26743
26744 ENTRY(ftrace_regs_caller)
26745 /* Save the current flags before compare (in SS location)*/
26746 @@ -127,7 +129,7 @@ GLOBAL(ftrace_regs_call)
26747 popfq
26748 jmp ftrace_stub
26749
26750 -END(ftrace_regs_caller)
26751 +ENDPROC(ftrace_regs_caller)
26752
26753
26754 #else /* ! CONFIG_DYNAMIC_FTRACE */
26755 @@ -145,6 +147,7 @@ ENTRY(function_hook)
26756 #endif
26757
26758 GLOBAL(ftrace_stub)
26759 + pax_force_retaddr
26760 retq
26761
26762 trace:
26763 @@ -158,12 +161,13 @@ trace:
26764 #endif
26765 subq $MCOUNT_INSN_SIZE, %rdi
26766
26767 + pax_force_fptr ftrace_trace_function
26768 call *ftrace_trace_function
26769
26770 MCOUNT_RESTORE_FRAME
26771
26772 jmp ftrace_stub
26773 -END(function_hook)
26774 +ENDPROC(function_hook)
26775 #endif /* CONFIG_DYNAMIC_FTRACE */
26776 #endif /* CONFIG_FUNCTION_TRACER */
26777
26778 @@ -185,8 +189,9 @@ ENTRY(ftrace_graph_caller)
26779
26780 MCOUNT_RESTORE_FRAME
26781
26782 + pax_force_retaddr
26783 retq
26784 -END(ftrace_graph_caller)
26785 +ENDPROC(ftrace_graph_caller)
26786
26787 GLOBAL(return_to_handler)
26788 subq $24, %rsp
26789 @@ -202,5 +207,7 @@ GLOBAL(return_to_handler)
26790 movq 8(%rsp), %rdx
26791 movq (%rsp), %rax
26792 addq $24, %rsp
26793 + pax_force_fptr %rdi
26794 jmp *%rdi
26795 +ENDPROC(return_to_handler)
26796 #endif
26797 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
26798 index e69f988..da078ea 100644
26799 --- a/arch/x86/kernel/module.c
26800 +++ b/arch/x86/kernel/module.c
26801 @@ -81,17 +81,62 @@ static unsigned long int get_module_load_offset(void)
26802 }
26803 #endif
26804
26805 -void *module_alloc(unsigned long size)
26806 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
26807 {
26808 - if (PAGE_ALIGN(size) > MODULES_LEN)
26809 + if (!size || PAGE_ALIGN(size) > MODULES_LEN)
26810 return NULL;
26811 return __vmalloc_node_range(size, 1,
26812 MODULES_VADDR + get_module_load_offset(),
26813 - MODULES_END, GFP_KERNEL | __GFP_HIGHMEM,
26814 - PAGE_KERNEL_EXEC, NUMA_NO_NODE,
26815 + MODULES_END, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO,
26816 + prot, NUMA_NO_NODE,
26817 __builtin_return_address(0));
26818 }
26819
26820 +void *module_alloc(unsigned long size)
26821 +{
26822 +
26823 +#ifdef CONFIG_PAX_KERNEXEC
26824 + return __module_alloc(size, PAGE_KERNEL);
26825 +#else
26826 + return __module_alloc(size, PAGE_KERNEL_EXEC);
26827 +#endif
26828 +
26829 +}
26830 +
26831 +#ifdef CONFIG_PAX_KERNEXEC
26832 +#ifdef CONFIG_X86_32
26833 +void *module_alloc_exec(unsigned long size)
26834 +{
26835 + struct vm_struct *area;
26836 +
26837 + if (size == 0)
26838 + return NULL;
26839 +
26840 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
26841 +return area ? area->addr : NULL;
26842 +}
26843 +EXPORT_SYMBOL(module_alloc_exec);
26844 +
26845 +void module_free_exec(struct module *mod, void *module_region)
26846 +{
26847 + vunmap(module_region);
26848 +}
26849 +EXPORT_SYMBOL(module_free_exec);
26850 +#else
26851 +void module_free_exec(struct module *mod, void *module_region)
26852 +{
26853 + module_free(mod, module_region);
26854 +}
26855 +EXPORT_SYMBOL(module_free_exec);
26856 +
26857 +void *module_alloc_exec(unsigned long size)
26858 +{
26859 + return __module_alloc(size, PAGE_KERNEL_RX);
26860 +}
26861 +EXPORT_SYMBOL(module_alloc_exec);
26862 +#endif
26863 +#endif
26864 +
26865 #ifdef CONFIG_X86_32
26866 int apply_relocate(Elf32_Shdr *sechdrs,
26867 const char *strtab,
26868 @@ -102,14 +147,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
26869 unsigned int i;
26870 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
26871 Elf32_Sym *sym;
26872 - uint32_t *location;
26873 + uint32_t *plocation, location;
26874
26875 DEBUGP("Applying relocate section %u to %u\n",
26876 relsec, sechdrs[relsec].sh_info);
26877 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
26878 /* This is where to make the change */
26879 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
26880 - + rel[i].r_offset;
26881 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
26882 + location = (uint32_t)plocation;
26883 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
26884 + plocation = ktla_ktva((void *)plocation);
26885 /* This is the symbol it is referring to. Note that all
26886 undefined symbols have been resolved. */
26887 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
26888 @@ -118,11 +165,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
26889 switch (ELF32_R_TYPE(rel[i].r_info)) {
26890 case R_386_32:
26891 /* We add the value into the location given */
26892 - *location += sym->st_value;
26893 + pax_open_kernel();
26894 + *plocation += sym->st_value;
26895 + pax_close_kernel();
26896 break;
26897 case R_386_PC32:
26898 /* Add the value, subtract its position */
26899 - *location += sym->st_value - (uint32_t)location;
26900 + pax_open_kernel();
26901 + *plocation += sym->st_value - location;
26902 + pax_close_kernel();
26903 break;
26904 default:
26905 pr_err("%s: Unknown relocation: %u\n",
26906 @@ -167,21 +218,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
26907 case R_X86_64_NONE:
26908 break;
26909 case R_X86_64_64:
26910 + pax_open_kernel();
26911 *(u64 *)loc = val;
26912 + pax_close_kernel();
26913 break;
26914 case R_X86_64_32:
26915 + pax_open_kernel();
26916 *(u32 *)loc = val;
26917 + pax_close_kernel();
26918 if (val != *(u32 *)loc)
26919 goto overflow;
26920 break;
26921 case R_X86_64_32S:
26922 + pax_open_kernel();
26923 *(s32 *)loc = val;
26924 + pax_close_kernel();
26925 if ((s64)val != *(s32 *)loc)
26926 goto overflow;
26927 break;
26928 case R_X86_64_PC32:
26929 val -= (u64)loc;
26930 + pax_open_kernel();
26931 *(u32 *)loc = val;
26932 + pax_close_kernel();
26933 +
26934 #if 0
26935 if ((s64)val != *(s32 *)loc)
26936 goto overflow;
26937 diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
26938 index c9603ac..9f88728 100644
26939 --- a/arch/x86/kernel/msr.c
26940 +++ b/arch/x86/kernel/msr.c
26941 @@ -37,6 +37,7 @@
26942 #include <linux/notifier.h>
26943 #include <linux/uaccess.h>
26944 #include <linux/gfp.h>
26945 +#include <linux/grsecurity.h>
26946
26947 #include <asm/processor.h>
26948 #include <asm/msr.h>
26949 @@ -103,6 +104,11 @@ static ssize_t msr_write(struct file *file, const char __user *buf,
26950 int err = 0;
26951 ssize_t bytes = 0;
26952
26953 +#ifdef CONFIG_GRKERNSEC_KMEM
26954 + gr_handle_msr_write();
26955 + return -EPERM;
26956 +#endif
26957 +
26958 if (count % 8)
26959 return -EINVAL; /* Invalid chunk size */
26960
26961 @@ -150,6 +156,10 @@ static long msr_ioctl(struct file *file, unsigned int ioc, unsigned long arg)
26962 err = -EBADF;
26963 break;
26964 }
26965 +#ifdef CONFIG_GRKERNSEC_KMEM
26966 + gr_handle_msr_write();
26967 + return -EPERM;
26968 +#endif
26969 if (copy_from_user(&regs, uregs, sizeof regs)) {
26970 err = -EFAULT;
26971 break;
26972 @@ -233,7 +243,7 @@ static int msr_class_cpu_callback(struct notifier_block *nfb,
26973 return notifier_from_errno(err);
26974 }
26975
26976 -static struct notifier_block __refdata msr_class_cpu_notifier = {
26977 +static struct notifier_block msr_class_cpu_notifier = {
26978 .notifier_call = msr_class_cpu_callback,
26979 };
26980
26981 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
26982 index c3e985d..110a36a 100644
26983 --- a/arch/x86/kernel/nmi.c
26984 +++ b/arch/x86/kernel/nmi.c
26985 @@ -98,16 +98,16 @@ fs_initcall(nmi_warning_debugfs);
26986
26987 static void nmi_max_handler(struct irq_work *w)
26988 {
26989 - struct nmiaction *a = container_of(w, struct nmiaction, irq_work);
26990 + struct nmiwork *n = container_of(w, struct nmiwork, irq_work);
26991 int remainder_ns, decimal_msecs;
26992 - u64 whole_msecs = ACCESS_ONCE(a->max_duration);
26993 + u64 whole_msecs = ACCESS_ONCE(n->max_duration);
26994
26995 remainder_ns = do_div(whole_msecs, (1000 * 1000));
26996 decimal_msecs = remainder_ns / 1000;
26997
26998 printk_ratelimited(KERN_INFO
26999 "INFO: NMI handler (%ps) took too long to run: %lld.%03d msecs\n",
27000 - a->handler, whole_msecs, decimal_msecs);
27001 + n->action->handler, whole_msecs, decimal_msecs);
27002 }
27003
27004 static int nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
27005 @@ -134,11 +134,11 @@ static int nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
27006 delta = sched_clock() - delta;
27007 trace_nmi_handler(a->handler, (int)delta, thishandled);
27008
27009 - if (delta < nmi_longest_ns || delta < a->max_duration)
27010 + if (delta < nmi_longest_ns || delta < a->work->max_duration)
27011 continue;
27012
27013 - a->max_duration = delta;
27014 - irq_work_queue(&a->irq_work);
27015 + a->work->max_duration = delta;
27016 + irq_work_queue(&a->work->irq_work);
27017 }
27018
27019 rcu_read_unlock();
27020 @@ -148,7 +148,7 @@ static int nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
27021 }
27022 NOKPROBE_SYMBOL(nmi_handle);
27023
27024 -int __register_nmi_handler(unsigned int type, struct nmiaction *action)
27025 +int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
27026 {
27027 struct nmi_desc *desc = nmi_to_desc(type);
27028 unsigned long flags;
27029 @@ -156,7 +156,8 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
27030 if (!action->handler)
27031 return -EINVAL;
27032
27033 - init_irq_work(&action->irq_work, nmi_max_handler);
27034 + action->work->action = action;
27035 + init_irq_work(&action->work->irq_work, nmi_max_handler);
27036
27037 spin_lock_irqsave(&desc->lock, flags);
27038
27039 @@ -174,9 +175,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
27040 * event confuses some handlers (kdump uses this flag)
27041 */
27042 if (action->flags & NMI_FLAG_FIRST)
27043 - list_add_rcu(&action->list, &desc->head);
27044 + pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
27045 else
27046 - list_add_tail_rcu(&action->list, &desc->head);
27047 + pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
27048
27049 spin_unlock_irqrestore(&desc->lock, flags);
27050 return 0;
27051 @@ -199,7 +200,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
27052 if (!strcmp(n->name, name)) {
27053 WARN(in_nmi(),
27054 "Trying to free NMI (%s) from NMI context!\n", n->name);
27055 - list_del_rcu(&n->list);
27056 + pax_list_del_rcu((struct list_head *)&n->list);
27057 break;
27058 }
27059 }
27060 @@ -528,6 +529,17 @@ static inline void nmi_nesting_postprocess(void)
27061 dotraplinkage notrace void
27062 do_nmi(struct pt_regs *regs, long error_code)
27063 {
27064 +
27065 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27066 + if (!user_mode(regs)) {
27067 + unsigned long cs = regs->cs & 0xFFFF;
27068 + unsigned long ip = ktva_ktla(regs->ip);
27069 +
27070 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
27071 + regs->ip = ip;
27072 + }
27073 +#endif
27074 +
27075 nmi_nesting_preprocess(regs);
27076
27077 nmi_enter();
27078 diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
27079 index 6d9582e..f746287 100644
27080 --- a/arch/x86/kernel/nmi_selftest.c
27081 +++ b/arch/x86/kernel/nmi_selftest.c
27082 @@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
27083 {
27084 /* trap all the unknown NMIs we may generate */
27085 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
27086 - __initdata);
27087 + __initconst);
27088 }
27089
27090 static void __init cleanup_nmi_testsuite(void)
27091 @@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
27092 unsigned long timeout;
27093
27094 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
27095 - NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
27096 + NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
27097 nmi_fail = FAILURE;
27098 return;
27099 }
27100 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
27101 index bbb6c73..24a58ef 100644
27102 --- a/arch/x86/kernel/paravirt-spinlocks.c
27103 +++ b/arch/x86/kernel/paravirt-spinlocks.c
27104 @@ -8,7 +8,7 @@
27105
27106 #include <asm/paravirt.h>
27107
27108 -struct pv_lock_ops pv_lock_ops = {
27109 +struct pv_lock_ops pv_lock_ops __read_only = {
27110 #ifdef CONFIG_SMP
27111 .lock_spinning = __PV_IS_CALLEE_SAVE(paravirt_nop),
27112 .unlock_kick = paravirt_nop,
27113 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
27114 index 548d25f..f8fb99c 100644
27115 --- a/arch/x86/kernel/paravirt.c
27116 +++ b/arch/x86/kernel/paravirt.c
27117 @@ -56,6 +56,9 @@ u64 _paravirt_ident_64(u64 x)
27118 {
27119 return x;
27120 }
27121 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
27122 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
27123 +#endif
27124
27125 void __init default_banner(void)
27126 {
27127 @@ -142,16 +145,20 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
27128
27129 if (opfunc == NULL)
27130 /* If there's no function, patch it with a ud2a (BUG) */
27131 - ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
27132 - else if (opfunc == _paravirt_nop)
27133 + ret = paravirt_patch_insns(insnbuf, len, ktva_ktla(ud2a), ud2a+sizeof(ud2a));
27134 + else if (opfunc == (void *)_paravirt_nop)
27135 /* If the operation is a nop, then nop the callsite */
27136 ret = paravirt_patch_nop();
27137
27138 /* identity functions just return their single argument */
27139 - else if (opfunc == _paravirt_ident_32)
27140 + else if (opfunc == (void *)_paravirt_ident_32)
27141 ret = paravirt_patch_ident_32(insnbuf, len);
27142 - else if (opfunc == _paravirt_ident_64)
27143 + else if (opfunc == (void *)_paravirt_ident_64)
27144 ret = paravirt_patch_ident_64(insnbuf, len);
27145 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
27146 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
27147 + ret = paravirt_patch_ident_64(insnbuf, len);
27148 +#endif
27149
27150 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
27151 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
27152 @@ -176,7 +183,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
27153 if (insn_len > len || start == NULL)
27154 insn_len = len;
27155 else
27156 - memcpy(insnbuf, start, insn_len);
27157 + memcpy(insnbuf, ktla_ktva(start), insn_len);
27158
27159 return insn_len;
27160 }
27161 @@ -300,7 +307,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
27162 return this_cpu_read(paravirt_lazy_mode);
27163 }
27164
27165 -struct pv_info pv_info = {
27166 +struct pv_info pv_info __read_only = {
27167 .name = "bare hardware",
27168 .paravirt_enabled = 0,
27169 .kernel_rpl = 0,
27170 @@ -311,16 +318,16 @@ struct pv_info pv_info = {
27171 #endif
27172 };
27173
27174 -struct pv_init_ops pv_init_ops = {
27175 +struct pv_init_ops pv_init_ops __read_only = {
27176 .patch = native_patch,
27177 };
27178
27179 -struct pv_time_ops pv_time_ops = {
27180 +struct pv_time_ops pv_time_ops __read_only = {
27181 .sched_clock = native_sched_clock,
27182 .steal_clock = native_steal_clock,
27183 };
27184
27185 -__visible struct pv_irq_ops pv_irq_ops = {
27186 +__visible struct pv_irq_ops pv_irq_ops __read_only = {
27187 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
27188 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
27189 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
27190 @@ -332,7 +339,7 @@ __visible struct pv_irq_ops pv_irq_ops = {
27191 #endif
27192 };
27193
27194 -__visible struct pv_cpu_ops pv_cpu_ops = {
27195 +__visible struct pv_cpu_ops pv_cpu_ops __read_only = {
27196 .cpuid = native_cpuid,
27197 .get_debugreg = native_get_debugreg,
27198 .set_debugreg = native_set_debugreg,
27199 @@ -395,21 +402,26 @@ NOKPROBE_SYMBOL(native_get_debugreg);
27200 NOKPROBE_SYMBOL(native_set_debugreg);
27201 NOKPROBE_SYMBOL(native_load_idt);
27202
27203 -struct pv_apic_ops pv_apic_ops = {
27204 +struct pv_apic_ops pv_apic_ops __read_only= {
27205 #ifdef CONFIG_X86_LOCAL_APIC
27206 .startup_ipi_hook = paravirt_nop,
27207 #endif
27208 };
27209
27210 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
27211 +#ifdef CONFIG_X86_32
27212 +#ifdef CONFIG_X86_PAE
27213 +/* 64-bit pagetable entries */
27214 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
27215 +#else
27216 /* 32-bit pagetable entries */
27217 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
27218 +#endif
27219 #else
27220 /* 64-bit pagetable entries */
27221 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
27222 #endif
27223
27224 -struct pv_mmu_ops pv_mmu_ops = {
27225 +struct pv_mmu_ops pv_mmu_ops __read_only = {
27226
27227 .read_cr2 = native_read_cr2,
27228 .write_cr2 = native_write_cr2,
27229 @@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
27230 .make_pud = PTE_IDENT,
27231
27232 .set_pgd = native_set_pgd,
27233 + .set_pgd_batched = native_set_pgd_batched,
27234 #endif
27235 #endif /* PAGETABLE_LEVELS >= 3 */
27236
27237 @@ -479,6 +492,12 @@ struct pv_mmu_ops pv_mmu_ops = {
27238 },
27239
27240 .set_fixmap = native_set_fixmap,
27241 +
27242 +#ifdef CONFIG_PAX_KERNEXEC
27243 + .pax_open_kernel = native_pax_open_kernel,
27244 + .pax_close_kernel = native_pax_close_kernel,
27245 +#endif
27246 +
27247 };
27248
27249 EXPORT_SYMBOL_GPL(pv_time_ops);
27250 diff --git a/arch/x86/kernel/paravirt_patch_64.c b/arch/x86/kernel/paravirt_patch_64.c
27251 index a1da673..2c72d5b 100644
27252 --- a/arch/x86/kernel/paravirt_patch_64.c
27253 +++ b/arch/x86/kernel/paravirt_patch_64.c
27254 @@ -9,7 +9,9 @@ DEF_NATIVE(pv_irq_ops, save_fl, "pushfq; popq %rax");
27255 DEF_NATIVE(pv_mmu_ops, read_cr2, "movq %cr2, %rax");
27256 DEF_NATIVE(pv_mmu_ops, read_cr3, "movq %cr3, %rax");
27257 DEF_NATIVE(pv_mmu_ops, write_cr3, "movq %rdi, %cr3");
27258 +#ifndef CONFIG_PAX_MEMORY_UDEREF
27259 DEF_NATIVE(pv_mmu_ops, flush_tlb_single, "invlpg (%rdi)");
27260 +#endif
27261 DEF_NATIVE(pv_cpu_ops, clts, "clts");
27262 DEF_NATIVE(pv_cpu_ops, wbinvd, "wbinvd");
27263
27264 @@ -57,7 +59,9 @@ unsigned native_patch(u8 type, u16 clobbers, void *ibuf,
27265 PATCH_SITE(pv_mmu_ops, read_cr3);
27266 PATCH_SITE(pv_mmu_ops, write_cr3);
27267 PATCH_SITE(pv_cpu_ops, clts);
27268 +#ifndef CONFIG_PAX_MEMORY_UDEREF
27269 PATCH_SITE(pv_mmu_ops, flush_tlb_single);
27270 +#endif
27271 PATCH_SITE(pv_cpu_ops, wbinvd);
27272
27273 patch_site:
27274 diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
27275 index 0497f71..7186c0d 100644
27276 --- a/arch/x86/kernel/pci-calgary_64.c
27277 +++ b/arch/x86/kernel/pci-calgary_64.c
27278 @@ -1347,7 +1347,7 @@ static void __init get_tce_space_from_tar(void)
27279 tce_space = be64_to_cpu(readq(target));
27280 tce_space = tce_space & TAR_SW_BITS;
27281
27282 - tce_space = tce_space & (~specified_table_size);
27283 + tce_space = tce_space & (~(unsigned long)specified_table_size);
27284 info->tce_space = (u64 *)__va(tce_space);
27285 }
27286 }
27287 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
27288 index 35ccf75..7a15747 100644
27289 --- a/arch/x86/kernel/pci-iommu_table.c
27290 +++ b/arch/x86/kernel/pci-iommu_table.c
27291 @@ -2,7 +2,7 @@
27292 #include <asm/iommu_table.h>
27293 #include <linux/string.h>
27294 #include <linux/kallsyms.h>
27295 -
27296 +#include <linux/sched.h>
27297
27298 #define DEBUG 1
27299
27300 diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
27301 index 77dd0ad..9ec4723 100644
27302 --- a/arch/x86/kernel/pci-swiotlb.c
27303 +++ b/arch/x86/kernel/pci-swiotlb.c
27304 @@ -33,7 +33,7 @@ void x86_swiotlb_free_coherent(struct device *dev, size_t size,
27305 struct dma_attrs *attrs)
27306 {
27307 if (is_swiotlb_buffer(dma_to_phys(dev, dma_addr)))
27308 - swiotlb_free_coherent(dev, size, vaddr, dma_addr);
27309 + swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
27310 else
27311 dma_generic_free_coherent(dev, size, vaddr, dma_addr, attrs);
27312 }
27313 diff --git a/arch/x86/kernel/preempt.S b/arch/x86/kernel/preempt.S
27314 index ca7f0d5..8996469 100644
27315 --- a/arch/x86/kernel/preempt.S
27316 +++ b/arch/x86/kernel/preempt.S
27317 @@ -3,12 +3,14 @@
27318 #include <asm/dwarf2.h>
27319 #include <asm/asm.h>
27320 #include <asm/calling.h>
27321 +#include <asm/alternative-asm.h>
27322
27323 ENTRY(___preempt_schedule)
27324 CFI_STARTPROC
27325 SAVE_ALL
27326 call preempt_schedule
27327 RESTORE_ALL
27328 + pax_force_retaddr
27329 ret
27330 CFI_ENDPROC
27331
27332 @@ -19,6 +21,7 @@ ENTRY(___preempt_schedule_context)
27333 SAVE_ALL
27334 call preempt_schedule_context
27335 RESTORE_ALL
27336 + pax_force_retaddr
27337 ret
27338 CFI_ENDPROC
27339
27340 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
27341 index f804dc9..7c62095 100644
27342 --- a/arch/x86/kernel/process.c
27343 +++ b/arch/x86/kernel/process.c
27344 @@ -36,7 +36,8 @@
27345 * section. Since TSS's are completely CPU-local, we want them
27346 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
27347 */
27348 -__visible DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
27349 +struct tss_struct init_tss[NR_CPUS] __visible ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
27350 +EXPORT_SYMBOL(init_tss);
27351
27352 #ifdef CONFIG_X86_64
27353 static DEFINE_PER_CPU(unsigned char, is_idle);
27354 @@ -92,7 +93,7 @@ void arch_task_cache_init(void)
27355 task_xstate_cachep =
27356 kmem_cache_create("task_xstate", xstate_size,
27357 __alignof__(union thread_xstate),
27358 - SLAB_PANIC | SLAB_NOTRACK, NULL);
27359 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
27360 setup_xstate_comp();
27361 }
27362
27363 @@ -106,7 +107,7 @@ void exit_thread(void)
27364 unsigned long *bp = t->io_bitmap_ptr;
27365
27366 if (bp) {
27367 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
27368 + struct tss_struct *tss = init_tss + get_cpu();
27369
27370 t->io_bitmap_ptr = NULL;
27371 clear_thread_flag(TIF_IO_BITMAP);
27372 @@ -126,6 +127,9 @@ void flush_thread(void)
27373 {
27374 struct task_struct *tsk = current;
27375
27376 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
27377 + loadsegment(gs, 0);
27378 +#endif
27379 flush_ptrace_hw_breakpoint(tsk);
27380 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
27381 drop_init_fpu(tsk);
27382 @@ -272,7 +276,7 @@ static void __exit_idle(void)
27383 void exit_idle(void)
27384 {
27385 /* idle loop has pid 0 */
27386 - if (current->pid)
27387 + if (task_pid_nr(current))
27388 return;
27389 __exit_idle();
27390 }
27391 @@ -325,7 +329,7 @@ bool xen_set_default_idle(void)
27392 return ret;
27393 }
27394 #endif
27395 -void stop_this_cpu(void *dummy)
27396 +__noreturn void stop_this_cpu(void *dummy)
27397 {
27398 local_irq_disable();
27399 /*
27400 @@ -454,16 +458,37 @@ static int __init idle_setup(char *str)
27401 }
27402 early_param("idle", idle_setup);
27403
27404 -unsigned long arch_align_stack(unsigned long sp)
27405 +#ifdef CONFIG_PAX_RANDKSTACK
27406 +void pax_randomize_kstack(struct pt_regs *regs)
27407 {
27408 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
27409 - sp -= get_random_int() % 8192;
27410 - return sp & ~0xf;
27411 -}
27412 + struct thread_struct *thread = &current->thread;
27413 + unsigned long time;
27414
27415 -unsigned long arch_randomize_brk(struct mm_struct *mm)
27416 -{
27417 - unsigned long range_end = mm->brk + 0x02000000;
27418 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
27419 -}
27420 + if (!randomize_va_space)
27421 + return;
27422 +
27423 + if (v8086_mode(regs))
27424 + return;
27425
27426 + rdtscl(time);
27427 +
27428 + /* P4 seems to return a 0 LSB, ignore it */
27429 +#ifdef CONFIG_MPENTIUM4
27430 + time &= 0x3EUL;
27431 + time <<= 2;
27432 +#elif defined(CONFIG_X86_64)
27433 + time &= 0xFUL;
27434 + time <<= 4;
27435 +#else
27436 + time &= 0x1FUL;
27437 + time <<= 3;
27438 +#endif
27439 +
27440 + thread->sp0 ^= time;
27441 + load_sp0(init_tss + smp_processor_id(), thread);
27442 +
27443 +#ifdef CONFIG_X86_64
27444 + this_cpu_write(kernel_stack, thread->sp0);
27445 +#endif
27446 +}
27447 +#endif
27448 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
27449 index 7bc86bb..0ea06e8 100644
27450 --- a/arch/x86/kernel/process_32.c
27451 +++ b/arch/x86/kernel/process_32.c
27452 @@ -64,6 +64,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
27453 unsigned long thread_saved_pc(struct task_struct *tsk)
27454 {
27455 return ((unsigned long *)tsk->thread.sp)[3];
27456 +//XXX return tsk->thread.eip;
27457 }
27458
27459 void __show_regs(struct pt_regs *regs, int all)
27460 @@ -73,19 +74,18 @@ void __show_regs(struct pt_regs *regs, int all)
27461 unsigned long sp;
27462 unsigned short ss, gs;
27463
27464 - if (user_mode_vm(regs)) {
27465 + if (user_mode(regs)) {
27466 sp = regs->sp;
27467 ss = regs->ss & 0xffff;
27468 - gs = get_user_gs(regs);
27469 } else {
27470 sp = kernel_stack_pointer(regs);
27471 savesegment(ss, ss);
27472 - savesegment(gs, gs);
27473 }
27474 + gs = get_user_gs(regs);
27475
27476 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
27477 (u16)regs->cs, regs->ip, regs->flags,
27478 - smp_processor_id());
27479 + raw_smp_processor_id());
27480 print_symbol("EIP is at %s\n", regs->ip);
27481
27482 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
27483 @@ -132,20 +132,21 @@ void release_thread(struct task_struct *dead_task)
27484 int copy_thread(unsigned long clone_flags, unsigned long sp,
27485 unsigned long arg, struct task_struct *p)
27486 {
27487 - struct pt_regs *childregs = task_pt_regs(p);
27488 + struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
27489 struct task_struct *tsk;
27490 int err;
27491
27492 p->thread.sp = (unsigned long) childregs;
27493 p->thread.sp0 = (unsigned long) (childregs+1);
27494 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
27495
27496 if (unlikely(p->flags & PF_KTHREAD)) {
27497 /* kernel thread */
27498 memset(childregs, 0, sizeof(struct pt_regs));
27499 p->thread.ip = (unsigned long) ret_from_kernel_thread;
27500 - task_user_gs(p) = __KERNEL_STACK_CANARY;
27501 - childregs->ds = __USER_DS;
27502 - childregs->es = __USER_DS;
27503 + savesegment(gs, childregs->gs);
27504 + childregs->ds = __KERNEL_DS;
27505 + childregs->es = __KERNEL_DS;
27506 childregs->fs = __KERNEL_PERCPU;
27507 childregs->bx = sp; /* function */
27508 childregs->bp = arg;
27509 @@ -252,7 +253,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
27510 struct thread_struct *prev = &prev_p->thread,
27511 *next = &next_p->thread;
27512 int cpu = smp_processor_id();
27513 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
27514 + struct tss_struct *tss = init_tss + cpu;
27515 fpu_switch_t fpu;
27516
27517 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
27518 @@ -276,6 +277,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
27519 */
27520 lazy_save_gs(prev->gs);
27521
27522 +#ifdef CONFIG_PAX_MEMORY_UDEREF
27523 + __set_fs(task_thread_info(next_p)->addr_limit);
27524 +#endif
27525 +
27526 /*
27527 * Load the per-thread Thread-Local Storage descriptor.
27528 */
27529 @@ -314,9 +319,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
27530 */
27531 arch_end_context_switch(next_p);
27532
27533 - this_cpu_write(kernel_stack,
27534 - (unsigned long)task_stack_page(next_p) +
27535 - THREAD_SIZE - KERNEL_STACK_OFFSET);
27536 + this_cpu_write(current_task, next_p);
27537 + this_cpu_write(current_tinfo, &next_p->tinfo);
27538 + this_cpu_write(kernel_stack, next->sp0);
27539
27540 /*
27541 * Restore %gs if needed (which is common)
27542 @@ -326,8 +331,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
27543
27544 switch_fpu_finish(next_p, fpu);
27545
27546 - this_cpu_write(current_task, next_p);
27547 -
27548 return prev_p;
27549 }
27550
27551 @@ -357,4 +360,3 @@ unsigned long get_wchan(struct task_struct *p)
27552 } while (count++ < 16);
27553 return 0;
27554 }
27555 -
27556 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
27557 index ca5b02d..c0b2f6a 100644
27558 --- a/arch/x86/kernel/process_64.c
27559 +++ b/arch/x86/kernel/process_64.c
27560 @@ -158,10 +158,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
27561 struct pt_regs *childregs;
27562 struct task_struct *me = current;
27563
27564 - p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
27565 + p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
27566 childregs = task_pt_regs(p);
27567 p->thread.sp = (unsigned long) childregs;
27568 p->thread.usersp = me->thread.usersp;
27569 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
27570 set_tsk_thread_flag(p, TIF_FORK);
27571 p->thread.fpu_counter = 0;
27572 p->thread.io_bitmap_ptr = NULL;
27573 @@ -172,6 +173,8 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
27574 p->thread.fs = p->thread.fsindex ? 0 : me->thread.fs;
27575 savesegment(es, p->thread.es);
27576 savesegment(ds, p->thread.ds);
27577 + savesegment(ss, p->thread.ss);
27578 + BUG_ON(p->thread.ss == __UDEREF_KERNEL_DS);
27579 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
27580
27581 if (unlikely(p->flags & PF_KTHREAD)) {
27582 @@ -280,7 +283,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
27583 struct thread_struct *prev = &prev_p->thread;
27584 struct thread_struct *next = &next_p->thread;
27585 int cpu = smp_processor_id();
27586 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
27587 + struct tss_struct *tss = init_tss + cpu;
27588 unsigned fsindex, gsindex;
27589 fpu_switch_t fpu;
27590
27591 @@ -303,6 +306,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
27592 if (unlikely(next->ds | prev->ds))
27593 loadsegment(ds, next->ds);
27594
27595 + savesegment(ss, prev->ss);
27596 + if (unlikely(next->ss != prev->ss))
27597 + loadsegment(ss, next->ss);
27598
27599 /* We must save %fs and %gs before load_TLS() because
27600 * %fs and %gs may be cleared by load_TLS().
27601 @@ -362,6 +368,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
27602 prev->usersp = this_cpu_read(old_rsp);
27603 this_cpu_write(old_rsp, next->usersp);
27604 this_cpu_write(current_task, next_p);
27605 + this_cpu_write(current_tinfo, &next_p->tinfo);
27606
27607 /*
27608 * If it were not for PREEMPT_ACTIVE we could guarantee that the
27609 @@ -371,9 +378,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
27610 task_thread_info(prev_p)->saved_preempt_count = this_cpu_read(__preempt_count);
27611 this_cpu_write(__preempt_count, task_thread_info(next_p)->saved_preempt_count);
27612
27613 - this_cpu_write(kernel_stack,
27614 - (unsigned long)task_stack_page(next_p) +
27615 - THREAD_SIZE - KERNEL_STACK_OFFSET);
27616 + this_cpu_write(kernel_stack, next->sp0);
27617
27618 /*
27619 * Now maybe reload the debug registers and handle I/O bitmaps
27620 @@ -443,12 +448,11 @@ unsigned long get_wchan(struct task_struct *p)
27621 if (!p || p == current || p->state == TASK_RUNNING)
27622 return 0;
27623 stack = (unsigned long)task_stack_page(p);
27624 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
27625 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
27626 return 0;
27627 fp = *(u64 *)(p->thread.sp);
27628 do {
27629 - if (fp < (unsigned long)stack ||
27630 - fp >= (unsigned long)stack+THREAD_SIZE)
27631 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
27632 return 0;
27633 ip = *(u64 *)(fp+8);
27634 if (!in_sched_functions(ip))
27635 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
27636 index b1a5dfa..ed94526 100644
27637 --- a/arch/x86/kernel/ptrace.c
27638 +++ b/arch/x86/kernel/ptrace.c
27639 @@ -186,10 +186,10 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
27640 unsigned long sp = (unsigned long)&regs->sp;
27641 u32 *prev_esp;
27642
27643 - if (context == (sp & ~(THREAD_SIZE - 1)))
27644 + if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
27645 return sp;
27646
27647 - prev_esp = (u32 *)(context);
27648 + prev_esp = *(u32 **)(context);
27649 if (prev_esp)
27650 return (unsigned long)prev_esp;
27651
27652 @@ -452,6 +452,20 @@ static int putreg(struct task_struct *child,
27653 if (child->thread.gs != value)
27654 return do_arch_prctl(child, ARCH_SET_GS, value);
27655 return 0;
27656 +
27657 + case offsetof(struct user_regs_struct,ip):
27658 + /*
27659 + * Protect against any attempt to set ip to an
27660 + * impossible address. There are dragons lurking if the
27661 + * address is noncanonical. (This explicitly allows
27662 + * setting ip to TASK_SIZE_MAX, because user code can do
27663 + * that all by itself by running off the end of its
27664 + * address space.
27665 + */
27666 + if (value > TASK_SIZE_MAX)
27667 + return -EIO;
27668 + break;
27669 +
27670 #endif
27671 }
27672
27673 @@ -588,7 +602,7 @@ static void ptrace_triggered(struct perf_event *bp,
27674 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
27675 {
27676 int i;
27677 - int dr7 = 0;
27678 + unsigned long dr7 = 0;
27679 struct arch_hw_breakpoint *info;
27680
27681 for (i = 0; i < HBP_NUM; i++) {
27682 @@ -822,7 +836,7 @@ long arch_ptrace(struct task_struct *child, long request,
27683 unsigned long addr, unsigned long data)
27684 {
27685 int ret;
27686 - unsigned long __user *datap = (unsigned long __user *)data;
27687 + unsigned long __user *datap = (__force unsigned long __user *)data;
27688
27689 switch (request) {
27690 /* read the word at location addr in the USER area. */
27691 @@ -907,14 +921,14 @@ long arch_ptrace(struct task_struct *child, long request,
27692 if ((int) addr < 0)
27693 return -EIO;
27694 ret = do_get_thread_area(child, addr,
27695 - (struct user_desc __user *)data);
27696 + (__force struct user_desc __user *) data);
27697 break;
27698
27699 case PTRACE_SET_THREAD_AREA:
27700 if ((int) addr < 0)
27701 return -EIO;
27702 ret = do_set_thread_area(child, addr,
27703 - (struct user_desc __user *)data, 0);
27704 + (__force struct user_desc __user *) data, 0);
27705 break;
27706 #endif
27707
27708 @@ -1292,7 +1306,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
27709
27710 #ifdef CONFIG_X86_64
27711
27712 -static struct user_regset x86_64_regsets[] __read_mostly = {
27713 +static user_regset_no_const x86_64_regsets[] __read_only = {
27714 [REGSET_GENERAL] = {
27715 .core_note_type = NT_PRSTATUS,
27716 .n = sizeof(struct user_regs_struct) / sizeof(long),
27717 @@ -1333,7 +1347,7 @@ static const struct user_regset_view user_x86_64_view = {
27718 #endif /* CONFIG_X86_64 */
27719
27720 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
27721 -static struct user_regset x86_32_regsets[] __read_mostly = {
27722 +static user_regset_no_const x86_32_regsets[] __read_only = {
27723 [REGSET_GENERAL] = {
27724 .core_note_type = NT_PRSTATUS,
27725 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
27726 @@ -1386,7 +1400,7 @@ static const struct user_regset_view user_x86_32_view = {
27727 */
27728 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
27729
27730 -void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
27731 +void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
27732 {
27733 #ifdef CONFIG_X86_64
27734 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
27735 @@ -1421,7 +1435,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
27736 memset(info, 0, sizeof(*info));
27737 info->si_signo = SIGTRAP;
27738 info->si_code = si_code;
27739 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
27740 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
27741 }
27742
27743 void user_single_step_siginfo(struct task_struct *tsk,
27744 @@ -1441,6 +1455,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
27745 force_sig_info(SIGTRAP, &info, tsk);
27746 }
27747
27748 +#ifdef CONFIG_GRKERNSEC_SETXID
27749 +extern void gr_delayed_cred_worker(void);
27750 +#endif
27751 +
27752 /*
27753 * We must return the syscall number to actually look up in the table.
27754 * This can be -1L to skip running any syscall at all.
27755 @@ -1451,6 +1469,11 @@ long syscall_trace_enter(struct pt_regs *regs)
27756
27757 user_exit();
27758
27759 +#ifdef CONFIG_GRKERNSEC_SETXID
27760 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
27761 + gr_delayed_cred_worker();
27762 +#endif
27763 +
27764 /*
27765 * If we stepped into a sysenter/syscall insn, it trapped in
27766 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
27767 @@ -1506,6 +1529,11 @@ void syscall_trace_leave(struct pt_regs *regs)
27768 */
27769 user_exit();
27770
27771 +#ifdef CONFIG_GRKERNSEC_SETXID
27772 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
27773 + gr_delayed_cred_worker();
27774 +#endif
27775 +
27776 audit_syscall_exit(regs);
27777
27778 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
27779 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
27780 index 2f355d2..e75ed0a 100644
27781 --- a/arch/x86/kernel/pvclock.c
27782 +++ b/arch/x86/kernel/pvclock.c
27783 @@ -51,11 +51,11 @@ void pvclock_touch_watchdogs(void)
27784 reset_hung_task_detector();
27785 }
27786
27787 -static atomic64_t last_value = ATOMIC64_INIT(0);
27788 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
27789
27790 void pvclock_resume(void)
27791 {
27792 - atomic64_set(&last_value, 0);
27793 + atomic64_set_unchecked(&last_value, 0);
27794 }
27795
27796 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
27797 @@ -105,11 +105,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
27798 * updating at the same time, and one of them could be slightly behind,
27799 * making the assumption that last_value always go forward fail to hold.
27800 */
27801 - last = atomic64_read(&last_value);
27802 + last = atomic64_read_unchecked(&last_value);
27803 do {
27804 if (ret < last)
27805 return last;
27806 - last = atomic64_cmpxchg(&last_value, last, ret);
27807 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
27808 } while (unlikely(last != ret));
27809
27810 return ret;
27811 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
27812 index 17962e6..47f55db 100644
27813 --- a/arch/x86/kernel/reboot.c
27814 +++ b/arch/x86/kernel/reboot.c
27815 @@ -69,6 +69,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
27816
27817 void __noreturn machine_real_restart(unsigned int type)
27818 {
27819 +
27820 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
27821 + struct desc_struct *gdt;
27822 +#endif
27823 +
27824 local_irq_disable();
27825
27826 /*
27827 @@ -96,7 +101,29 @@ void __noreturn machine_real_restart(unsigned int type)
27828
27829 /* Jump to the identity-mapped low memory code */
27830 #ifdef CONFIG_X86_32
27831 - asm volatile("jmpl *%0" : :
27832 +
27833 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
27834 + gdt = get_cpu_gdt_table(smp_processor_id());
27835 + pax_open_kernel();
27836 +#ifdef CONFIG_PAX_MEMORY_UDEREF
27837 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
27838 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
27839 + loadsegment(ds, __KERNEL_DS);
27840 + loadsegment(es, __KERNEL_DS);
27841 + loadsegment(ss, __KERNEL_DS);
27842 +#endif
27843 +#ifdef CONFIG_PAX_KERNEXEC
27844 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
27845 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
27846 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
27847 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
27848 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
27849 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
27850 +#endif
27851 + pax_close_kernel();
27852 +#endif
27853 +
27854 + asm volatile("ljmpl *%0" : :
27855 "rm" (real_mode_header->machine_real_restart_asm),
27856 "a" (type));
27857 #else
27858 @@ -500,7 +527,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
27859 * This means that this function can never return, it can misbehave
27860 * by not rebooting properly and hanging.
27861 */
27862 -static void native_machine_emergency_restart(void)
27863 +static void __noreturn native_machine_emergency_restart(void)
27864 {
27865 int i;
27866 int attempt = 0;
27867 @@ -620,13 +647,13 @@ void native_machine_shutdown(void)
27868 #endif
27869 }
27870
27871 -static void __machine_emergency_restart(int emergency)
27872 +static void __noreturn __machine_emergency_restart(int emergency)
27873 {
27874 reboot_emergency = emergency;
27875 machine_ops.emergency_restart();
27876 }
27877
27878 -static void native_machine_restart(char *__unused)
27879 +static void __noreturn native_machine_restart(char *__unused)
27880 {
27881 pr_notice("machine restart\n");
27882
27883 @@ -635,7 +662,7 @@ static void native_machine_restart(char *__unused)
27884 __machine_emergency_restart(0);
27885 }
27886
27887 -static void native_machine_halt(void)
27888 +static void __noreturn native_machine_halt(void)
27889 {
27890 /* Stop other cpus and apics */
27891 machine_shutdown();
27892 @@ -645,7 +672,7 @@ static void native_machine_halt(void)
27893 stop_this_cpu(NULL);
27894 }
27895
27896 -static void native_machine_power_off(void)
27897 +static void __noreturn native_machine_power_off(void)
27898 {
27899 if (pm_power_off) {
27900 if (!reboot_force)
27901 @@ -654,9 +681,10 @@ static void native_machine_power_off(void)
27902 }
27903 /* A fallback in case there is no PM info available */
27904 tboot_shutdown(TB_SHUTDOWN_HALT);
27905 + unreachable();
27906 }
27907
27908 -struct machine_ops machine_ops = {
27909 +struct machine_ops machine_ops __read_only = {
27910 .power_off = native_machine_power_off,
27911 .shutdown = native_machine_shutdown,
27912 .emergency_restart = native_machine_emergency_restart,
27913 diff --git a/arch/x86/kernel/reboot_fixups_32.c b/arch/x86/kernel/reboot_fixups_32.c
27914 index c8e41e9..64049ef 100644
27915 --- a/arch/x86/kernel/reboot_fixups_32.c
27916 +++ b/arch/x86/kernel/reboot_fixups_32.c
27917 @@ -57,7 +57,7 @@ struct device_fixup {
27918 unsigned int vendor;
27919 unsigned int device;
27920 void (*reboot_fixup)(struct pci_dev *);
27921 -};
27922 +} __do_const;
27923
27924 /*
27925 * PCI ids solely used for fixups_table go here
27926 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
27927 index 3fd2c69..a444264 100644
27928 --- a/arch/x86/kernel/relocate_kernel_64.S
27929 +++ b/arch/x86/kernel/relocate_kernel_64.S
27930 @@ -96,8 +96,7 @@ relocate_kernel:
27931
27932 /* jump to identity mapped page */
27933 addq $(identity_mapped - relocate_kernel), %r8
27934 - pushq %r8
27935 - ret
27936 + jmp *%r8
27937
27938 identity_mapped:
27939 /* set return address to 0 if not preserving context */
27940 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
27941 index 41ead8d..7ccde23 100644
27942 --- a/arch/x86/kernel/setup.c
27943 +++ b/arch/x86/kernel/setup.c
27944 @@ -110,6 +110,7 @@
27945 #include <asm/mce.h>
27946 #include <asm/alternative.h>
27947 #include <asm/prom.h>
27948 +#include <asm/boot.h>
27949
27950 /*
27951 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
27952 @@ -205,12 +206,50 @@ EXPORT_SYMBOL(boot_cpu_data);
27953 #endif
27954
27955
27956 -#if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
27957 -__visible unsigned long mmu_cr4_features;
27958 +#ifdef CONFIG_X86_64
27959 +__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE;
27960 +#elif defined(CONFIG_X86_PAE)
27961 +__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PAE;
27962 #else
27963 -__visible unsigned long mmu_cr4_features = X86_CR4_PAE;
27964 +__visible unsigned long mmu_cr4_features __read_only;
27965 #endif
27966
27967 +void set_in_cr4(unsigned long mask)
27968 +{
27969 + unsigned long cr4 = read_cr4();
27970 +
27971 + if ((cr4 & mask) == mask && cr4 == mmu_cr4_features)
27972 + return;
27973 +
27974 + pax_open_kernel();
27975 + mmu_cr4_features |= mask;
27976 + pax_close_kernel();
27977 +
27978 + if (trampoline_cr4_features)
27979 + *trampoline_cr4_features = mmu_cr4_features;
27980 + cr4 |= mask;
27981 + write_cr4(cr4);
27982 +}
27983 +EXPORT_SYMBOL(set_in_cr4);
27984 +
27985 +void clear_in_cr4(unsigned long mask)
27986 +{
27987 + unsigned long cr4 = read_cr4();
27988 +
27989 + if (!(cr4 & mask) && cr4 == mmu_cr4_features)
27990 + return;
27991 +
27992 + pax_open_kernel();
27993 + mmu_cr4_features &= ~mask;
27994 + pax_close_kernel();
27995 +
27996 + if (trampoline_cr4_features)
27997 + *trampoline_cr4_features = mmu_cr4_features;
27998 + cr4 &= ~mask;
27999 + write_cr4(cr4);
28000 +}
28001 +EXPORT_SYMBOL(clear_in_cr4);
28002 +
28003 /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
28004 int bootloader_type, bootloader_version;
28005
28006 @@ -772,7 +811,7 @@ static void __init trim_bios_range(void)
28007 * area (640->1Mb) as ram even though it is not.
28008 * take them out.
28009 */
28010 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
28011 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
28012
28013 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
28014 }
28015 @@ -780,7 +819,7 @@ static void __init trim_bios_range(void)
28016 /* called before trim_bios_range() to spare extra sanitize */
28017 static void __init e820_add_kernel_range(void)
28018 {
28019 - u64 start = __pa_symbol(_text);
28020 + u64 start = __pa_symbol(ktla_ktva(_text));
28021 u64 size = __pa_symbol(_end) - start;
28022
28023 /*
28024 @@ -856,8 +895,12 @@ dump_kernel_offset(struct notifier_block *self, unsigned long v, void *p)
28025
28026 void __init setup_arch(char **cmdline_p)
28027 {
28028 +#ifdef CONFIG_X86_32
28029 + memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
28030 +#else
28031 memblock_reserve(__pa_symbol(_text),
28032 (unsigned long)__bss_stop - (unsigned long)_text);
28033 +#endif
28034
28035 early_reserve_initrd();
28036
28037 @@ -946,14 +989,14 @@ void __init setup_arch(char **cmdline_p)
28038
28039 if (!boot_params.hdr.root_flags)
28040 root_mountflags &= ~MS_RDONLY;
28041 - init_mm.start_code = (unsigned long) _text;
28042 - init_mm.end_code = (unsigned long) _etext;
28043 + init_mm.start_code = ktla_ktva((unsigned long) _text);
28044 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
28045 init_mm.end_data = (unsigned long) _edata;
28046 init_mm.brk = _brk_end;
28047
28048 - code_resource.start = __pa_symbol(_text);
28049 - code_resource.end = __pa_symbol(_etext)-1;
28050 - data_resource.start = __pa_symbol(_etext);
28051 + code_resource.start = __pa_symbol(ktla_ktva(_text));
28052 + code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
28053 + data_resource.start = __pa_symbol(_sdata);
28054 data_resource.end = __pa_symbol(_edata)-1;
28055 bss_resource.start = __pa_symbol(__bss_start);
28056 bss_resource.end = __pa_symbol(__bss_stop)-1;
28057 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
28058 index 5cdff03..80fa283 100644
28059 --- a/arch/x86/kernel/setup_percpu.c
28060 +++ b/arch/x86/kernel/setup_percpu.c
28061 @@ -21,19 +21,17 @@
28062 #include <asm/cpu.h>
28063 #include <asm/stackprotector.h>
28064
28065 -DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
28066 +#ifdef CONFIG_SMP
28067 +DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
28068 EXPORT_PER_CPU_SYMBOL(cpu_number);
28069 +#endif
28070
28071 -#ifdef CONFIG_X86_64
28072 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
28073 -#else
28074 -#define BOOT_PERCPU_OFFSET 0
28075 -#endif
28076
28077 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
28078 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
28079
28080 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
28081 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
28082 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
28083 };
28084 EXPORT_SYMBOL(__per_cpu_offset);
28085 @@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
28086 {
28087 #ifdef CONFIG_NEED_MULTIPLE_NODES
28088 pg_data_t *last = NULL;
28089 - unsigned int cpu;
28090 + int cpu;
28091
28092 for_each_possible_cpu(cpu) {
28093 int node = early_cpu_to_node(cpu);
28094 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
28095 {
28096 #ifdef CONFIG_X86_32
28097 struct desc_struct gdt;
28098 + unsigned long base = per_cpu_offset(cpu);
28099
28100 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
28101 - 0x2 | DESCTYPE_S, 0x8);
28102 - gdt.s = 1;
28103 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
28104 + 0x83 | DESCTYPE_S, 0xC);
28105 write_gdt_entry(get_cpu_gdt_table(cpu),
28106 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
28107 #endif
28108 @@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
28109 /* alrighty, percpu areas up and running */
28110 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
28111 for_each_possible_cpu(cpu) {
28112 +#ifdef CONFIG_CC_STACKPROTECTOR
28113 +#ifdef CONFIG_X86_32
28114 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
28115 +#endif
28116 +#endif
28117 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
28118 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
28119 per_cpu(cpu_number, cpu) = cpu;
28120 @@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
28121 */
28122 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
28123 #endif
28124 +#ifdef CONFIG_CC_STACKPROTECTOR
28125 +#ifdef CONFIG_X86_32
28126 + if (!cpu)
28127 + per_cpu(stack_canary.canary, cpu) = canary;
28128 +#endif
28129 +#endif
28130 /*
28131 * Up to this point, the boot CPU has been using .init.data
28132 * area. Reload any changed state for the boot CPU.
28133 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
28134 index ed37a76..39f936e 100644
28135 --- a/arch/x86/kernel/signal.c
28136 +++ b/arch/x86/kernel/signal.c
28137 @@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
28138 * Align the stack pointer according to the i386 ABI,
28139 * i.e. so that on function entry ((sp + 4) & 15) == 0.
28140 */
28141 - sp = ((sp + 4) & -16ul) - 4;
28142 + sp = ((sp - 12) & -16ul) - 4;
28143 #else /* !CONFIG_X86_32 */
28144 sp = round_down(sp, 16) - 8;
28145 #endif
28146 @@ -298,10 +298,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
28147 }
28148
28149 if (current->mm->context.vdso)
28150 - restorer = current->mm->context.vdso +
28151 - selected_vdso32->sym___kernel_sigreturn;
28152 + restorer = (void __force_user *)(current->mm->context.vdso + selected_vdso32->sym___kernel_sigreturn);
28153 else
28154 - restorer = &frame->retcode;
28155 + restorer = (void __user *)&frame->retcode;
28156 if (ksig->ka.sa.sa_flags & SA_RESTORER)
28157 restorer = ksig->ka.sa.sa_restorer;
28158
28159 @@ -315,7 +314,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
28160 * reasons and because gdb uses it as a signature to notice
28161 * signal handler stack frames.
28162 */
28163 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
28164 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
28165
28166 if (err)
28167 return -EFAULT;
28168 @@ -362,8 +361,10 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
28169 save_altstack_ex(&frame->uc.uc_stack, regs->sp);
28170
28171 /* Set up to return from userspace. */
28172 - restorer = current->mm->context.vdso +
28173 - selected_vdso32->sym___kernel_rt_sigreturn;
28174 + if (current->mm->context.vdso)
28175 + restorer = (void __force_user *)(current->mm->context.vdso + selected_vdso32->sym___kernel_rt_sigreturn);
28176 + else
28177 + restorer = (void __user *)&frame->retcode;
28178 if (ksig->ka.sa.sa_flags & SA_RESTORER)
28179 restorer = ksig->ka.sa.sa_restorer;
28180 put_user_ex(restorer, &frame->pretcode);
28181 @@ -375,7 +376,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
28182 * reasons and because gdb uses it as a signature to notice
28183 * signal handler stack frames.
28184 */
28185 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
28186 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
28187 } put_user_catch(err);
28188
28189 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
28190 @@ -611,7 +612,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
28191 {
28192 int usig = signr_convert(ksig->sig);
28193 sigset_t *set = sigmask_to_save();
28194 - compat_sigset_t *cset = (compat_sigset_t *) set;
28195 + sigset_t sigcopy;
28196 + compat_sigset_t *cset;
28197 +
28198 + sigcopy = *set;
28199 +
28200 + cset = (compat_sigset_t *) &sigcopy;
28201
28202 /* Set up the stack frame */
28203 if (is_ia32_frame()) {
28204 @@ -622,7 +628,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
28205 } else if (is_x32_frame()) {
28206 return x32_setup_rt_frame(ksig, cset, regs);
28207 } else {
28208 - return __setup_rt_frame(ksig->sig, ksig, set, regs);
28209 + return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
28210 }
28211 }
28212
28213 diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
28214 index be8e1bd..a3d93fa 100644
28215 --- a/arch/x86/kernel/smp.c
28216 +++ b/arch/x86/kernel/smp.c
28217 @@ -341,7 +341,7 @@ static int __init nonmi_ipi_setup(char *str)
28218
28219 __setup("nonmi_ipi", nonmi_ipi_setup);
28220
28221 -struct smp_ops smp_ops = {
28222 +struct smp_ops smp_ops __read_only = {
28223 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
28224 .smp_prepare_cpus = native_smp_prepare_cpus,
28225 .smp_cpus_done = native_smp_cpus_done,
28226 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
28227 index 42a2dca..35a07aa 100644
28228 --- a/arch/x86/kernel/smpboot.c
28229 +++ b/arch/x86/kernel/smpboot.c
28230 @@ -226,14 +226,17 @@ static void notrace start_secondary(void *unused)
28231
28232 enable_start_cpu0 = 0;
28233
28234 -#ifdef CONFIG_X86_32
28235 + /* otherwise gcc will move up smp_processor_id before the cpu_init */
28236 + barrier();
28237 +
28238 /* switch away from the initial page table */
28239 +#ifdef CONFIG_PAX_PER_CPU_PGD
28240 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
28241 +#else
28242 load_cr3(swapper_pg_dir);
28243 +#endif
28244 __flush_tlb_all();
28245 -#endif
28246
28247 - /* otherwise gcc will move up smp_processor_id before the cpu_init */
28248 - barrier();
28249 /*
28250 * Check TSC synchronization with the BP:
28251 */
28252 @@ -760,8 +763,9 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
28253 alternatives_enable_smp();
28254
28255 idle->thread.sp = (unsigned long) (((struct pt_regs *)
28256 - (THREAD_SIZE + task_stack_page(idle))) - 1);
28257 + (THREAD_SIZE - 16 + task_stack_page(idle))) - 1);
28258 per_cpu(current_task, cpu) = idle;
28259 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
28260
28261 #ifdef CONFIG_X86_32
28262 /* Stack for startup_32 can be just as for start_secondary onwards */
28263 @@ -770,10 +774,10 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
28264 clear_tsk_thread_flag(idle, TIF_FORK);
28265 initial_gs = per_cpu_offset(cpu);
28266 #endif
28267 - per_cpu(kernel_stack, cpu) =
28268 - (unsigned long)task_stack_page(idle) -
28269 - KERNEL_STACK_OFFSET + THREAD_SIZE;
28270 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
28271 + pax_open_kernel();
28272 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
28273 + pax_close_kernel();
28274 initial_code = (unsigned long)start_secondary;
28275 stack_start = idle->thread.sp;
28276
28277 @@ -919,6 +923,15 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
28278 /* the FPU context is blank, nobody can own it */
28279 __cpu_disable_lazy_restore(cpu);
28280
28281 +#ifdef CONFIG_PAX_PER_CPU_PGD
28282 + clone_pgd_range(get_cpu_pgd(cpu, kernel) + KERNEL_PGD_BOUNDARY,
28283 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
28284 + KERNEL_PGD_PTRS);
28285 + clone_pgd_range(get_cpu_pgd(cpu, user) + KERNEL_PGD_BOUNDARY,
28286 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
28287 + KERNEL_PGD_PTRS);
28288 +#endif
28289 +
28290 err = do_boot_cpu(apicid, cpu, tidle);
28291 if (err) {
28292 pr_err("do_boot_cpu failed(%d) to wakeup CPU#%u\n", err, cpu);
28293 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
28294 index 9b4d51d..5d28b58 100644
28295 --- a/arch/x86/kernel/step.c
28296 +++ b/arch/x86/kernel/step.c
28297 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
28298 struct desc_struct *desc;
28299 unsigned long base;
28300
28301 - seg &= ~7UL;
28302 + seg >>= 3;
28303
28304 mutex_lock(&child->mm->context.lock);
28305 - if (unlikely((seg >> 3) >= child->mm->context.size))
28306 + if (unlikely(seg >= child->mm->context.size))
28307 addr = -1L; /* bogus selector, access would fault */
28308 else {
28309 desc = child->mm->context.ldt + seg;
28310 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
28311 addr += base;
28312 }
28313 mutex_unlock(&child->mm->context.lock);
28314 - }
28315 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
28316 + addr = ktla_ktva(addr);
28317
28318 return addr;
28319 }
28320 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
28321 unsigned char opcode[15];
28322 unsigned long addr = convert_ip_to_linear(child, regs);
28323
28324 + if (addr == -EINVAL)
28325 + return 0;
28326 +
28327 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
28328 for (i = 0; i < copied; i++) {
28329 switch (opcode[i]) {
28330 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
28331 new file mode 100644
28332 index 0000000..5877189
28333 --- /dev/null
28334 +++ b/arch/x86/kernel/sys_i386_32.c
28335 @@ -0,0 +1,189 @@
28336 +/*
28337 + * This file contains various random system calls that
28338 + * have a non-standard calling sequence on the Linux/i386
28339 + * platform.
28340 + */
28341 +
28342 +#include <linux/errno.h>
28343 +#include <linux/sched.h>
28344 +#include <linux/mm.h>
28345 +#include <linux/fs.h>
28346 +#include <linux/smp.h>
28347 +#include <linux/sem.h>
28348 +#include <linux/msg.h>
28349 +#include <linux/shm.h>
28350 +#include <linux/stat.h>
28351 +#include <linux/syscalls.h>
28352 +#include <linux/mman.h>
28353 +#include <linux/file.h>
28354 +#include <linux/utsname.h>
28355 +#include <linux/ipc.h>
28356 +#include <linux/elf.h>
28357 +
28358 +#include <linux/uaccess.h>
28359 +#include <linux/unistd.h>
28360 +
28361 +#include <asm/syscalls.h>
28362 +
28363 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
28364 +{
28365 + unsigned long pax_task_size = TASK_SIZE;
28366 +
28367 +#ifdef CONFIG_PAX_SEGMEXEC
28368 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
28369 + pax_task_size = SEGMEXEC_TASK_SIZE;
28370 +#endif
28371 +
28372 + if (flags & MAP_FIXED)
28373 + if (len > pax_task_size || addr > pax_task_size - len)
28374 + return -EINVAL;
28375 +
28376 + return 0;
28377 +}
28378 +
28379 +/*
28380 + * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
28381 + */
28382 +static unsigned long get_align_mask(void)
28383 +{
28384 + if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
28385 + return 0;
28386 +
28387 + if (!(current->flags & PF_RANDOMIZE))
28388 + return 0;
28389 +
28390 + return va_align.mask;
28391 +}
28392 +
28393 +unsigned long
28394 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
28395 + unsigned long len, unsigned long pgoff, unsigned long flags)
28396 +{
28397 + struct mm_struct *mm = current->mm;
28398 + struct vm_area_struct *vma;
28399 + unsigned long pax_task_size = TASK_SIZE;
28400 + struct vm_unmapped_area_info info;
28401 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
28402 +
28403 +#ifdef CONFIG_PAX_SEGMEXEC
28404 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
28405 + pax_task_size = SEGMEXEC_TASK_SIZE;
28406 +#endif
28407 +
28408 + pax_task_size -= PAGE_SIZE;
28409 +
28410 + if (len > pax_task_size)
28411 + return -ENOMEM;
28412 +
28413 + if (flags & MAP_FIXED)
28414 + return addr;
28415 +
28416 +#ifdef CONFIG_PAX_RANDMMAP
28417 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
28418 +#endif
28419 +
28420 + if (addr) {
28421 + addr = PAGE_ALIGN(addr);
28422 + if (pax_task_size - len >= addr) {
28423 + vma = find_vma(mm, addr);
28424 + if (check_heap_stack_gap(vma, addr, len, offset))
28425 + return addr;
28426 + }
28427 + }
28428 +
28429 + info.flags = 0;
28430 + info.length = len;
28431 + info.align_mask = filp ? get_align_mask() : 0;
28432 + info.align_offset = pgoff << PAGE_SHIFT;
28433 + info.threadstack_offset = offset;
28434 +
28435 +#ifdef CONFIG_PAX_PAGEEXEC
28436 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
28437 + info.low_limit = 0x00110000UL;
28438 + info.high_limit = mm->start_code;
28439 +
28440 +#ifdef CONFIG_PAX_RANDMMAP
28441 + if (mm->pax_flags & MF_PAX_RANDMMAP)
28442 + info.low_limit += mm->delta_mmap & 0x03FFF000UL;
28443 +#endif
28444 +
28445 + if (info.low_limit < info.high_limit) {
28446 + addr = vm_unmapped_area(&info);
28447 + if (!IS_ERR_VALUE(addr))
28448 + return addr;
28449 + }
28450 + } else
28451 +#endif
28452 +
28453 + info.low_limit = mm->mmap_base;
28454 + info.high_limit = pax_task_size;
28455 +
28456 + return vm_unmapped_area(&info);
28457 +}
28458 +
28459 +unsigned long
28460 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
28461 + const unsigned long len, const unsigned long pgoff,
28462 + const unsigned long flags)
28463 +{
28464 + struct vm_area_struct *vma;
28465 + struct mm_struct *mm = current->mm;
28466 + unsigned long addr = addr0, pax_task_size = TASK_SIZE;
28467 + struct vm_unmapped_area_info info;
28468 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
28469 +
28470 +#ifdef CONFIG_PAX_SEGMEXEC
28471 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
28472 + pax_task_size = SEGMEXEC_TASK_SIZE;
28473 +#endif
28474 +
28475 + pax_task_size -= PAGE_SIZE;
28476 +
28477 + /* requested length too big for entire address space */
28478 + if (len > pax_task_size)
28479 + return -ENOMEM;
28480 +
28481 + if (flags & MAP_FIXED)
28482 + return addr;
28483 +
28484 +#ifdef CONFIG_PAX_PAGEEXEC
28485 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
28486 + goto bottomup;
28487 +#endif
28488 +
28489 +#ifdef CONFIG_PAX_RANDMMAP
28490 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
28491 +#endif
28492 +
28493 + /* requesting a specific address */
28494 + if (addr) {
28495 + addr = PAGE_ALIGN(addr);
28496 + if (pax_task_size - len >= addr) {
28497 + vma = find_vma(mm, addr);
28498 + if (check_heap_stack_gap(vma, addr, len, offset))
28499 + return addr;
28500 + }
28501 + }
28502 +
28503 + info.flags = VM_UNMAPPED_AREA_TOPDOWN;
28504 + info.length = len;
28505 + info.low_limit = PAGE_SIZE;
28506 + info.high_limit = mm->mmap_base;
28507 + info.align_mask = filp ? get_align_mask() : 0;
28508 + info.align_offset = pgoff << PAGE_SHIFT;
28509 + info.threadstack_offset = offset;
28510 +
28511 + addr = vm_unmapped_area(&info);
28512 + if (!(addr & ~PAGE_MASK))
28513 + return addr;
28514 + VM_BUG_ON(addr != -ENOMEM);
28515 +
28516 +bottomup:
28517 + /*
28518 + * A failed mmap() very likely causes application failure,
28519 + * so fall back to the bottom-up function here. This scenario
28520 + * can happen with large stack limits and large mmap()
28521 + * allocations.
28522 + */
28523 + return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
28524 +}
28525 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
28526 index 30277e2..5664a29 100644
28527 --- a/arch/x86/kernel/sys_x86_64.c
28528 +++ b/arch/x86/kernel/sys_x86_64.c
28529 @@ -81,8 +81,8 @@ out:
28530 return error;
28531 }
28532
28533 -static void find_start_end(unsigned long flags, unsigned long *begin,
28534 - unsigned long *end)
28535 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
28536 + unsigned long *begin, unsigned long *end)
28537 {
28538 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
28539 unsigned long new_begin;
28540 @@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
28541 *begin = new_begin;
28542 }
28543 } else {
28544 - *begin = current->mm->mmap_legacy_base;
28545 + *begin = mm->mmap_legacy_base;
28546 *end = TASK_SIZE;
28547 }
28548 }
28549 @@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
28550 struct vm_area_struct *vma;
28551 struct vm_unmapped_area_info info;
28552 unsigned long begin, end;
28553 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
28554
28555 if (flags & MAP_FIXED)
28556 return addr;
28557
28558 - find_start_end(flags, &begin, &end);
28559 + find_start_end(mm, flags, &begin, &end);
28560
28561 if (len > end)
28562 return -ENOMEM;
28563
28564 +#ifdef CONFIG_PAX_RANDMMAP
28565 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
28566 +#endif
28567 +
28568 if (addr) {
28569 addr = PAGE_ALIGN(addr);
28570 vma = find_vma(mm, addr);
28571 - if (end - len >= addr &&
28572 - (!vma || addr + len <= vma->vm_start))
28573 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
28574 return addr;
28575 }
28576
28577 @@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
28578 info.high_limit = end;
28579 info.align_mask = filp ? get_align_mask() : 0;
28580 info.align_offset = pgoff << PAGE_SHIFT;
28581 + info.threadstack_offset = offset;
28582 return vm_unmapped_area(&info);
28583 }
28584
28585 @@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
28586 struct mm_struct *mm = current->mm;
28587 unsigned long addr = addr0;
28588 struct vm_unmapped_area_info info;
28589 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
28590
28591 /* requested length too big for entire address space */
28592 if (len > TASK_SIZE)
28593 @@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
28594 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
28595 goto bottomup;
28596
28597 +#ifdef CONFIG_PAX_RANDMMAP
28598 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
28599 +#endif
28600 +
28601 /* requesting a specific address */
28602 if (addr) {
28603 addr = PAGE_ALIGN(addr);
28604 vma = find_vma(mm, addr);
28605 - if (TASK_SIZE - len >= addr &&
28606 - (!vma || addr + len <= vma->vm_start))
28607 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
28608 return addr;
28609 }
28610
28611 @@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
28612 info.high_limit = mm->mmap_base;
28613 info.align_mask = filp ? get_align_mask() : 0;
28614 info.align_offset = pgoff << PAGE_SHIFT;
28615 + info.threadstack_offset = offset;
28616 addr = vm_unmapped_area(&info);
28617 if (!(addr & ~PAGE_MASK))
28618 return addr;
28619 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
28620 index 91a4496..bb87552 100644
28621 --- a/arch/x86/kernel/tboot.c
28622 +++ b/arch/x86/kernel/tboot.c
28623 @@ -221,7 +221,7 @@ static int tboot_setup_sleep(void)
28624
28625 void tboot_shutdown(u32 shutdown_type)
28626 {
28627 - void (*shutdown)(void);
28628 + void (* __noreturn shutdown)(void);
28629
28630 if (!tboot_enabled())
28631 return;
28632 @@ -243,7 +243,7 @@ void tboot_shutdown(u32 shutdown_type)
28633
28634 switch_to_tboot_pt();
28635
28636 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
28637 + shutdown = (void *)(unsigned long)tboot->shutdown_entry;
28638 shutdown();
28639
28640 /* should not reach here */
28641 @@ -310,7 +310,7 @@ static int tboot_extended_sleep(u8 sleep_state, u32 val_a, u32 val_b)
28642 return -ENODEV;
28643 }
28644
28645 -static atomic_t ap_wfs_count;
28646 +static atomic_unchecked_t ap_wfs_count;
28647
28648 static int tboot_wait_for_aps(int num_aps)
28649 {
28650 @@ -334,9 +334,9 @@ static int tboot_cpu_callback(struct notifier_block *nfb, unsigned long action,
28651 {
28652 switch (action) {
28653 case CPU_DYING:
28654 - atomic_inc(&ap_wfs_count);
28655 + atomic_inc_unchecked(&ap_wfs_count);
28656 if (num_online_cpus() == 1)
28657 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
28658 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
28659 return NOTIFY_BAD;
28660 break;
28661 }
28662 @@ -422,7 +422,7 @@ static __init int tboot_late_init(void)
28663
28664 tboot_create_trampoline();
28665
28666 - atomic_set(&ap_wfs_count, 0);
28667 + atomic_set_unchecked(&ap_wfs_count, 0);
28668 register_hotcpu_notifier(&tboot_cpu_notifier);
28669
28670 #ifdef CONFIG_DEBUG_FS
28671 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
28672 index 0fa2960..91eabbe 100644
28673 --- a/arch/x86/kernel/time.c
28674 +++ b/arch/x86/kernel/time.c
28675 @@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
28676 {
28677 unsigned long pc = instruction_pointer(regs);
28678
28679 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
28680 + if (!user_mode(regs) && in_lock_functions(pc)) {
28681 #ifdef CONFIG_FRAME_POINTER
28682 - return *(unsigned long *)(regs->bp + sizeof(long));
28683 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
28684 #else
28685 unsigned long *sp =
28686 (unsigned long *)kernel_stack_pointer(regs);
28687 @@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
28688 * or above a saved flags. Eflags has bits 22-31 zero,
28689 * kernel addresses don't.
28690 */
28691 +
28692 +#ifdef CONFIG_PAX_KERNEXEC
28693 + return ktla_ktva(sp[0]);
28694 +#else
28695 if (sp[0] >> 22)
28696 return sp[0];
28697 if (sp[1] >> 22)
28698 return sp[1];
28699 #endif
28700 +
28701 +#endif
28702 }
28703 return pc;
28704 }
28705 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
28706 index f7fec09..d0f623f 100644
28707 --- a/arch/x86/kernel/tls.c
28708 +++ b/arch/x86/kernel/tls.c
28709 @@ -27,6 +27,37 @@ static int get_free_idx(void)
28710 return -ESRCH;
28711 }
28712
28713 +static bool tls_desc_okay(const struct user_desc *info)
28714 +{
28715 + if (LDT_empty(info))
28716 + return true;
28717 +
28718 + /*
28719 + * espfix is required for 16-bit data segments, but espfix
28720 + * only works for LDT segments.
28721 + */
28722 + if (!info->seg_32bit)
28723 + return false;
28724 +
28725 + /* Only allow data segments in the TLS array. */
28726 + if (info->contents > 1)
28727 + return false;
28728 +
28729 + /*
28730 + * Non-present segments with DPL 3 present an interesting attack
28731 + * surface. The kernel should handle such segments correctly,
28732 + * but TLS is very difficult to protect in a sandbox, so prevent
28733 + * such segments from being created.
28734 + *
28735 + * If userspace needs to remove a TLS entry, it can still delete
28736 + * it outright.
28737 + */
28738 + if (info->seg_not_present)
28739 + return false;
28740 +
28741 + return true;
28742 +}
28743 +
28744 static void set_tls_desc(struct task_struct *p, int idx,
28745 const struct user_desc *info, int n)
28746 {
28747 @@ -66,6 +97,9 @@ int do_set_thread_area(struct task_struct *p, int idx,
28748 if (copy_from_user(&info, u_info, sizeof(info)))
28749 return -EFAULT;
28750
28751 + if (!tls_desc_okay(&info))
28752 + return -EINVAL;
28753 +
28754 if (idx == -1)
28755 idx = info.entry_number;
28756
28757 @@ -84,6 +118,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
28758 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
28759 return -EINVAL;
28760
28761 +#ifdef CONFIG_PAX_SEGMEXEC
28762 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
28763 + return -EINVAL;
28764 +#endif
28765 +
28766 set_tls_desc(p, idx, &info, 1);
28767
28768 return 0;
28769 @@ -192,6 +231,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
28770 {
28771 struct user_desc infobuf[GDT_ENTRY_TLS_ENTRIES];
28772 const struct user_desc *info;
28773 + int i;
28774
28775 if (pos >= GDT_ENTRY_TLS_ENTRIES * sizeof(struct user_desc) ||
28776 (pos % sizeof(struct user_desc)) != 0 ||
28777 @@ -200,11 +240,15 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
28778
28779 if (kbuf)
28780 info = kbuf;
28781 - else if (__copy_from_user(infobuf, ubuf, count))
28782 + else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
28783 return -EFAULT;
28784 else
28785 info = infobuf;
28786
28787 + for (i = 0; i < count / sizeof(struct user_desc); i++)
28788 + if (!tls_desc_okay(info + i))
28789 + return -EINVAL;
28790 +
28791 set_tls_desc(target,
28792 GDT_ENTRY_TLS_MIN + (pos / sizeof(struct user_desc)),
28793 info, count / sizeof(struct user_desc));
28794 diff --git a/arch/x86/kernel/tracepoint.c b/arch/x86/kernel/tracepoint.c
28795 index 1c113db..287b42e 100644
28796 --- a/arch/x86/kernel/tracepoint.c
28797 +++ b/arch/x86/kernel/tracepoint.c
28798 @@ -9,11 +9,11 @@
28799 #include <linux/atomic.h>
28800
28801 atomic_t trace_idt_ctr = ATOMIC_INIT(0);
28802 -struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
28803 +const struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
28804 (unsigned long) trace_idt_table };
28805
28806 /* No need to be aligned, but done to keep all IDTs defined the same way. */
28807 -gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
28808 +gate_desc trace_idt_table[NR_VECTORS] __page_aligned_rodata;
28809
28810 static int trace_irq_vector_refcount;
28811 static DEFINE_MUTEX(irq_vector_mutex);
28812 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
28813 index de801f2..f189dcf 100644
28814 --- a/arch/x86/kernel/traps.c
28815 +++ b/arch/x86/kernel/traps.c
28816 @@ -67,7 +67,7 @@
28817 #include <asm/proto.h>
28818
28819 /* No need to be aligned, but done to keep all IDTs defined the same way. */
28820 -gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;
28821 +gate_desc debug_idt_table[NR_VECTORS] __page_aligned_rodata;
28822 #else
28823 #include <asm/processor-flags.h>
28824 #include <asm/setup.h>
28825 @@ -76,7 +76,7 @@ asmlinkage int system_call(void);
28826 #endif
28827
28828 /* Must be page-aligned because the real IDT is used in a fixmap. */
28829 -gate_desc idt_table[NR_VECTORS] __page_aligned_bss;
28830 +gate_desc idt_table[NR_VECTORS] __page_aligned_rodata;
28831
28832 DECLARE_BITMAP(used_vectors, NR_VECTORS);
28833 EXPORT_SYMBOL_GPL(used_vectors);
28834 @@ -108,11 +108,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
28835 }
28836
28837 static nokprobe_inline int
28838 -do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
28839 +do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
28840 struct pt_regs *regs, long error_code)
28841 {
28842 #ifdef CONFIG_X86_32
28843 - if (regs->flags & X86_VM_MASK) {
28844 + if (v8086_mode(regs)) {
28845 /*
28846 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
28847 * On nmi (interrupt 2), do_trap should not be called.
28848 @@ -125,12 +125,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
28849 return -1;
28850 }
28851 #endif
28852 - if (!user_mode(regs)) {
28853 + if (!user_mode_novm(regs)) {
28854 if (!fixup_exception(regs)) {
28855 tsk->thread.error_code = error_code;
28856 tsk->thread.trap_nr = trapnr;
28857 +
28858 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28859 + if (trapnr == X86_TRAP_SS && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
28860 + str = "PAX: suspicious stack segment fault";
28861 +#endif
28862 +
28863 die(str, regs, error_code);
28864 }
28865 +
28866 +#ifdef CONFIG_PAX_REFCOUNT
28867 + if (trapnr == X86_TRAP_OF)
28868 + pax_report_refcount_overflow(regs);
28869 +#endif
28870 +
28871 return 0;
28872 }
28873
28874 @@ -169,7 +181,7 @@ static siginfo_t *fill_trap_info(struct pt_regs *regs, int signr, int trapnr,
28875 }
28876
28877 static void
28878 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
28879 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
28880 long error_code, siginfo_t *info)
28881 {
28882 struct task_struct *tsk = current;
28883 @@ -193,7 +205,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
28884 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
28885 printk_ratelimit()) {
28886 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
28887 - tsk->comm, tsk->pid, str,
28888 + tsk->comm, task_pid_nr(tsk), str,
28889 regs->ip, regs->sp, error_code);
28890 print_vma_addr(" in ", regs->ip);
28891 pr_cont("\n");
28892 @@ -274,6 +286,11 @@ dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code)
28893 tsk->thread.error_code = error_code;
28894 tsk->thread.trap_nr = X86_TRAP_DF;
28895
28896 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
28897 + if ((unsigned long)tsk->stack - regs->sp <= PAGE_SIZE)
28898 + die("grsec: kernel stack overflow detected", regs, error_code);
28899 +#endif
28900 +
28901 #ifdef CONFIG_DOUBLEFAULT
28902 df_debug(regs, error_code);
28903 #endif
28904 @@ -296,7 +313,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
28905 conditional_sti(regs);
28906
28907 #ifdef CONFIG_X86_32
28908 - if (regs->flags & X86_VM_MASK) {
28909 + if (v8086_mode(regs)) {
28910 local_irq_enable();
28911 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
28912 goto exit;
28913 @@ -304,18 +321,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
28914 #endif
28915
28916 tsk = current;
28917 - if (!user_mode(regs)) {
28918 + if (!user_mode_novm(regs)) {
28919 if (fixup_exception(regs))
28920 goto exit;
28921
28922 tsk->thread.error_code = error_code;
28923 tsk->thread.trap_nr = X86_TRAP_GP;
28924 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
28925 - X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
28926 + X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
28927 +
28928 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28929 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
28930 + die("PAX: suspicious general protection fault", regs, error_code);
28931 + else
28932 +#endif
28933 +
28934 die("general protection fault", regs, error_code);
28935 + }
28936 goto exit;
28937 }
28938
28939 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
28940 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
28941 + struct mm_struct *mm = tsk->mm;
28942 + unsigned long limit;
28943 +
28944 + down_write(&mm->mmap_sem);
28945 + limit = mm->context.user_cs_limit;
28946 + if (limit < TASK_SIZE) {
28947 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
28948 + up_write(&mm->mmap_sem);
28949 + return;
28950 + }
28951 + up_write(&mm->mmap_sem);
28952 + }
28953 +#endif
28954 +
28955 tsk->thread.error_code = error_code;
28956 tsk->thread.trap_nr = X86_TRAP_GP;
28957
28958 @@ -433,7 +474,7 @@ struct bad_iret_stack *fixup_bad_iret(struct bad_iret_stack *s)
28959 /* Copy the remainder of the stack from the current stack. */
28960 memmove(new_stack, s, offsetof(struct bad_iret_stack, regs.ip));
28961
28962 - BUG_ON(!user_mode_vm(&new_stack->regs));
28963 + BUG_ON(!user_mode(&new_stack->regs));
28964 return new_stack;
28965 }
28966 #endif
28967 @@ -518,7 +559,7 @@ dotraplinkage void do_debug(struct pt_regs *regs, long error_code)
28968 /* It's safe to allow irq's after DR6 has been saved */
28969 preempt_conditional_sti(regs);
28970
28971 - if (regs->flags & X86_VM_MASK) {
28972 + if (v8086_mode(regs)) {
28973 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
28974 X86_TRAP_DB);
28975 preempt_conditional_cli(regs);
28976 @@ -533,7 +574,7 @@ dotraplinkage void do_debug(struct pt_regs *regs, long error_code)
28977 * We already checked v86 mode above, so we can check for kernel mode
28978 * by just checking the CPL of CS.
28979 */
28980 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
28981 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
28982 tsk->thread.debugreg6 &= ~DR_STEP;
28983 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
28984 regs->flags &= ~X86_EFLAGS_TF;
28985 @@ -566,7 +607,7 @@ static void math_error(struct pt_regs *regs, int error_code, int trapnr)
28986 return;
28987 conditional_sti(regs);
28988
28989 - if (!user_mode_vm(regs))
28990 + if (!user_mode(regs))
28991 {
28992 if (!fixup_exception(regs)) {
28993 task->thread.error_code = error_code;
28994 diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
28995 index b7e50bb..f4a93ae 100644
28996 --- a/arch/x86/kernel/tsc.c
28997 +++ b/arch/x86/kernel/tsc.c
28998 @@ -150,7 +150,7 @@ static void cyc2ns_write_end(int cpu, struct cyc2ns_data *data)
28999 */
29000 smp_wmb();
29001
29002 - ACCESS_ONCE(c2n->head) = data;
29003 + ACCESS_ONCE_RW(c2n->head) = data;
29004 }
29005
29006 /*
29007 diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
29008 index 5d1cbfe..2a21feb 100644
29009 --- a/arch/x86/kernel/uprobes.c
29010 +++ b/arch/x86/kernel/uprobes.c
29011 @@ -845,7 +845,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
29012 int ret = NOTIFY_DONE;
29013
29014 /* We are only interested in userspace traps */
29015 - if (regs && !user_mode_vm(regs))
29016 + if (regs && !user_mode(regs))
29017 return NOTIFY_DONE;
29018
29019 switch (val) {
29020 @@ -919,7 +919,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
29021
29022 if (nleft != rasize) {
29023 pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
29024 - "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
29025 + "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
29026
29027 force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
29028 }
29029 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
29030 index b9242ba..50c5edd 100644
29031 --- a/arch/x86/kernel/verify_cpu.S
29032 +++ b/arch/x86/kernel/verify_cpu.S
29033 @@ -20,6 +20,7 @@
29034 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
29035 * arch/x86/kernel/trampoline_64.S: secondary processor verification
29036 * arch/x86/kernel/head_32.S: processor startup
29037 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
29038 *
29039 * verify_cpu, returns the status of longmode and SSE in register %eax.
29040 * 0: Success 1: Failure
29041 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
29042 index e8edcf5..27f9344 100644
29043 --- a/arch/x86/kernel/vm86_32.c
29044 +++ b/arch/x86/kernel/vm86_32.c
29045 @@ -44,6 +44,7 @@
29046 #include <linux/ptrace.h>
29047 #include <linux/audit.h>
29048 #include <linux/stddef.h>
29049 +#include <linux/grsecurity.h>
29050
29051 #include <asm/uaccess.h>
29052 #include <asm/io.h>
29053 @@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
29054 do_exit(SIGSEGV);
29055 }
29056
29057 - tss = &per_cpu(init_tss, get_cpu());
29058 + tss = init_tss + get_cpu();
29059 current->thread.sp0 = current->thread.saved_sp0;
29060 current->thread.sysenter_cs = __KERNEL_CS;
29061 load_sp0(tss, &current->thread);
29062 @@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
29063
29064 if (tsk->thread.saved_sp0)
29065 return -EPERM;
29066 +
29067 +#ifdef CONFIG_GRKERNSEC_VM86
29068 + if (!capable(CAP_SYS_RAWIO)) {
29069 + gr_handle_vm86();
29070 + return -EPERM;
29071 + }
29072 +#endif
29073 +
29074 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
29075 offsetof(struct kernel_vm86_struct, vm86plus) -
29076 sizeof(info.regs));
29077 @@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
29078 int tmp;
29079 struct vm86plus_struct __user *v86;
29080
29081 +#ifdef CONFIG_GRKERNSEC_VM86
29082 + if (!capable(CAP_SYS_RAWIO)) {
29083 + gr_handle_vm86();
29084 + return -EPERM;
29085 + }
29086 +#endif
29087 +
29088 tsk = current;
29089 switch (cmd) {
29090 case VM86_REQUEST_IRQ:
29091 @@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
29092 tsk->thread.saved_fs = info->regs32->fs;
29093 tsk->thread.saved_gs = get_user_gs(info->regs32);
29094
29095 - tss = &per_cpu(init_tss, get_cpu());
29096 + tss = init_tss + get_cpu();
29097 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
29098 if (cpu_has_sep)
29099 tsk->thread.sysenter_cs = 0;
29100 @@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
29101 goto cannot_handle;
29102 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
29103 goto cannot_handle;
29104 - intr_ptr = (unsigned long __user *) (i << 2);
29105 + intr_ptr = (__force unsigned long __user *) (i << 2);
29106 if (get_user(segoffs, intr_ptr))
29107 goto cannot_handle;
29108 if ((segoffs >> 16) == BIOSSEG)
29109 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
29110 index 49edf2d..c0d1362 100644
29111 --- a/arch/x86/kernel/vmlinux.lds.S
29112 +++ b/arch/x86/kernel/vmlinux.lds.S
29113 @@ -26,6 +26,13 @@
29114 #include <asm/page_types.h>
29115 #include <asm/cache.h>
29116 #include <asm/boot.h>
29117 +#include <asm/segment.h>
29118 +
29119 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
29120 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
29121 +#else
29122 +#define __KERNEL_TEXT_OFFSET 0
29123 +#endif
29124
29125 #undef i386 /* in case the preprocessor is a 32bit one */
29126
29127 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
29128
29129 PHDRS {
29130 text PT_LOAD FLAGS(5); /* R_E */
29131 +#ifdef CONFIG_X86_32
29132 + module PT_LOAD FLAGS(5); /* R_E */
29133 +#endif
29134 +#ifdef CONFIG_XEN
29135 + rodata PT_LOAD FLAGS(5); /* R_E */
29136 +#else
29137 + rodata PT_LOAD FLAGS(4); /* R__ */
29138 +#endif
29139 data PT_LOAD FLAGS(6); /* RW_ */
29140 -#ifdef CONFIG_X86_64
29141 + init.begin PT_LOAD FLAGS(6); /* RW_ */
29142 #ifdef CONFIG_SMP
29143 percpu PT_LOAD FLAGS(6); /* RW_ */
29144 #endif
29145 + text.init PT_LOAD FLAGS(5); /* R_E */
29146 + text.exit PT_LOAD FLAGS(5); /* R_E */
29147 init PT_LOAD FLAGS(7); /* RWE */
29148 -#endif
29149 note PT_NOTE FLAGS(0); /* ___ */
29150 }
29151
29152 SECTIONS
29153 {
29154 #ifdef CONFIG_X86_32
29155 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
29156 - phys_startup_32 = startup_32 - LOAD_OFFSET;
29157 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
29158 #else
29159 - . = __START_KERNEL;
29160 - phys_startup_64 = startup_64 - LOAD_OFFSET;
29161 + . = __START_KERNEL;
29162 #endif
29163
29164 /* Text and read-only data */
29165 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
29166 - _text = .;
29167 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
29168 /* bootstrapping code */
29169 +#ifdef CONFIG_X86_32
29170 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
29171 +#else
29172 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
29173 +#endif
29174 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
29175 + _text = .;
29176 HEAD_TEXT
29177 . = ALIGN(8);
29178 _stext = .;
29179 @@ -104,13 +124,47 @@ SECTIONS
29180 IRQENTRY_TEXT
29181 *(.fixup)
29182 *(.gnu.warning)
29183 - /* End of text section */
29184 - _etext = .;
29185 } :text = 0x9090
29186
29187 - NOTES :text :note
29188 + . += __KERNEL_TEXT_OFFSET;
29189
29190 - EXCEPTION_TABLE(16) :text = 0x9090
29191 +#ifdef CONFIG_X86_32
29192 + . = ALIGN(PAGE_SIZE);
29193 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
29194 +
29195 +#ifdef CONFIG_PAX_KERNEXEC
29196 + MODULES_EXEC_VADDR = .;
29197 + BYTE(0)
29198 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
29199 + . = ALIGN(HPAGE_SIZE) - 1;
29200 + MODULES_EXEC_END = .;
29201 +#endif
29202 +
29203 + } :module
29204 +#endif
29205 +
29206 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
29207 + /* End of text section */
29208 + BYTE(0)
29209 + _etext = . - __KERNEL_TEXT_OFFSET;
29210 + }
29211 +
29212 +#ifdef CONFIG_X86_32
29213 + . = ALIGN(PAGE_SIZE);
29214 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
29215 + . = ALIGN(PAGE_SIZE);
29216 + *(.empty_zero_page)
29217 + *(.initial_pg_fixmap)
29218 + *(.initial_pg_pmd)
29219 + *(.initial_page_table)
29220 + *(.swapper_pg_dir)
29221 + } :rodata
29222 +#endif
29223 +
29224 + . = ALIGN(PAGE_SIZE);
29225 + NOTES :rodata :note
29226 +
29227 + EXCEPTION_TABLE(16) :rodata
29228
29229 #if defined(CONFIG_DEBUG_RODATA)
29230 /* .text should occupy whole number of pages */
29231 @@ -122,16 +176,20 @@ SECTIONS
29232
29233 /* Data */
29234 .data : AT(ADDR(.data) - LOAD_OFFSET) {
29235 +
29236 +#ifdef CONFIG_PAX_KERNEXEC
29237 + . = ALIGN(HPAGE_SIZE);
29238 +#else
29239 + . = ALIGN(PAGE_SIZE);
29240 +#endif
29241 +
29242 /* Start of data section */
29243 _sdata = .;
29244
29245 /* init_task */
29246 INIT_TASK_DATA(THREAD_SIZE)
29247
29248 -#ifdef CONFIG_X86_32
29249 - /* 32 bit has nosave before _edata */
29250 NOSAVE_DATA
29251 -#endif
29252
29253 PAGE_ALIGNED_DATA(PAGE_SIZE)
29254
29255 @@ -174,12 +232,19 @@ SECTIONS
29256 . = ALIGN(__vvar_page + PAGE_SIZE, PAGE_SIZE);
29257
29258 /* Init code and data - will be freed after init */
29259 - . = ALIGN(PAGE_SIZE);
29260 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
29261 + BYTE(0)
29262 +
29263 +#ifdef CONFIG_PAX_KERNEXEC
29264 + . = ALIGN(HPAGE_SIZE);
29265 +#else
29266 + . = ALIGN(PAGE_SIZE);
29267 +#endif
29268 +
29269 __init_begin = .; /* paired with __init_end */
29270 - }
29271 + } :init.begin
29272
29273 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
29274 +#ifdef CONFIG_SMP
29275 /*
29276 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
29277 * output PHDR, so the next output section - .init.text - should
29278 @@ -188,12 +253,27 @@ SECTIONS
29279 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
29280 #endif
29281
29282 - INIT_TEXT_SECTION(PAGE_SIZE)
29283 -#ifdef CONFIG_X86_64
29284 - :init
29285 -#endif
29286 + . = ALIGN(PAGE_SIZE);
29287 + init_begin = .;
29288 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
29289 + VMLINUX_SYMBOL(_sinittext) = .;
29290 + INIT_TEXT
29291 + VMLINUX_SYMBOL(_einittext) = .;
29292 + . = ALIGN(PAGE_SIZE);
29293 + } :text.init
29294
29295 - INIT_DATA_SECTION(16)
29296 + /*
29297 + * .exit.text is discard at runtime, not link time, to deal with
29298 + * references from .altinstructions and .eh_frame
29299 + */
29300 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
29301 + EXIT_TEXT
29302 + . = ALIGN(16);
29303 + } :text.exit
29304 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
29305 +
29306 + . = ALIGN(PAGE_SIZE);
29307 + INIT_DATA_SECTION(16) :init
29308
29309 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
29310 __x86_cpu_dev_start = .;
29311 @@ -264,19 +344,12 @@ SECTIONS
29312 }
29313
29314 . = ALIGN(8);
29315 - /*
29316 - * .exit.text is discard at runtime, not link time, to deal with
29317 - * references from .altinstructions and .eh_frame
29318 - */
29319 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
29320 - EXIT_TEXT
29321 - }
29322
29323 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
29324 EXIT_DATA
29325 }
29326
29327 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
29328 +#ifndef CONFIG_SMP
29329 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
29330 #endif
29331
29332 @@ -295,16 +368,10 @@ SECTIONS
29333 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
29334 __smp_locks = .;
29335 *(.smp_locks)
29336 - . = ALIGN(PAGE_SIZE);
29337 __smp_locks_end = .;
29338 + . = ALIGN(PAGE_SIZE);
29339 }
29340
29341 -#ifdef CONFIG_X86_64
29342 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
29343 - NOSAVE_DATA
29344 - }
29345 -#endif
29346 -
29347 /* BSS */
29348 . = ALIGN(PAGE_SIZE);
29349 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
29350 @@ -320,6 +387,7 @@ SECTIONS
29351 __brk_base = .;
29352 . += 64 * 1024; /* 64k alignment slop space */
29353 *(.brk_reservation) /* areas brk users have reserved */
29354 + . = ALIGN(HPAGE_SIZE);
29355 __brk_limit = .;
29356 }
29357
29358 @@ -346,13 +414,12 @@ SECTIONS
29359 * for the boot processor.
29360 */
29361 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
29362 -INIT_PER_CPU(gdt_page);
29363 INIT_PER_CPU(irq_stack_union);
29364
29365 /*
29366 * Build-time check on the image size:
29367 */
29368 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
29369 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
29370 "kernel image bigger than KERNEL_IMAGE_SIZE");
29371
29372 #ifdef CONFIG_SMP
29373 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
29374 index e1e1e80..1400089 100644
29375 --- a/arch/x86/kernel/vsyscall_64.c
29376 +++ b/arch/x86/kernel/vsyscall_64.c
29377 @@ -54,15 +54,13 @@
29378
29379 DEFINE_VVAR(int, vgetcpu_mode);
29380
29381 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
29382 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
29383
29384 static int __init vsyscall_setup(char *str)
29385 {
29386 if (str) {
29387 if (!strcmp("emulate", str))
29388 vsyscall_mode = EMULATE;
29389 - else if (!strcmp("native", str))
29390 - vsyscall_mode = NATIVE;
29391 else if (!strcmp("none", str))
29392 vsyscall_mode = NONE;
29393 else
29394 @@ -279,8 +277,7 @@ do_ret:
29395 return true;
29396
29397 sigsegv:
29398 - force_sig(SIGSEGV, current);
29399 - return true;
29400 + do_group_exit(SIGKILL);
29401 }
29402
29403 /*
29404 @@ -331,10 +328,7 @@ void __init map_vsyscall(void)
29405 extern char __vsyscall_page;
29406 unsigned long physaddr_vsyscall = __pa_symbol(&__vsyscall_page);
29407
29408 - __set_fixmap(VSYSCALL_PAGE, physaddr_vsyscall,
29409 - vsyscall_mode == NATIVE
29410 - ? PAGE_KERNEL_VSYSCALL
29411 - : PAGE_KERNEL_VVAR);
29412 + __set_fixmap(VSYSCALL_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
29413 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_PAGE) !=
29414 (unsigned long)VSYSCALL_ADDR);
29415 }
29416 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
29417 index 04068192..4d75aa6 100644
29418 --- a/arch/x86/kernel/x8664_ksyms_64.c
29419 +++ b/arch/x86/kernel/x8664_ksyms_64.c
29420 @@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
29421 EXPORT_SYMBOL(copy_user_generic_unrolled);
29422 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
29423 EXPORT_SYMBOL(__copy_user_nocache);
29424 -EXPORT_SYMBOL(_copy_from_user);
29425 -EXPORT_SYMBOL(_copy_to_user);
29426
29427 EXPORT_SYMBOL(copy_page);
29428 EXPORT_SYMBOL(clear_page);
29429 @@ -73,3 +71,7 @@ EXPORT_SYMBOL(___preempt_schedule);
29430 EXPORT_SYMBOL(___preempt_schedule_context);
29431 #endif
29432 #endif
29433 +
29434 +#ifdef CONFIG_PAX_PER_CPU_PGD
29435 +EXPORT_SYMBOL(cpu_pgd);
29436 +#endif
29437 diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
29438 index e48b674..a451dd9 100644
29439 --- a/arch/x86/kernel/x86_init.c
29440 +++ b/arch/x86/kernel/x86_init.c
29441 @@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit = {
29442 static void default_nmi_init(void) { };
29443 static int default_i8042_detect(void) { return 1; };
29444
29445 -struct x86_platform_ops x86_platform = {
29446 +struct x86_platform_ops x86_platform __read_only = {
29447 .calibrate_tsc = native_calibrate_tsc,
29448 .get_wallclock = mach_get_cmos_time,
29449 .set_wallclock = mach_set_rtc_mmss,
29450 @@ -109,7 +109,7 @@ struct x86_platform_ops x86_platform = {
29451 EXPORT_SYMBOL_GPL(x86_platform);
29452
29453 #if defined(CONFIG_PCI_MSI)
29454 -struct x86_msi_ops x86_msi = {
29455 +struct x86_msi_ops x86_msi __read_only = {
29456 .setup_msi_irqs = native_setup_msi_irqs,
29457 .compose_msi_msg = native_compose_msi_msg,
29458 .teardown_msi_irq = native_teardown_msi_irq,
29459 @@ -150,7 +150,7 @@ u32 arch_msix_mask_irq(struct msi_desc *desc, u32 flag)
29460 }
29461 #endif
29462
29463 -struct x86_io_apic_ops x86_io_apic_ops = {
29464 +struct x86_io_apic_ops x86_io_apic_ops __read_only = {
29465 .init = native_io_apic_init_mappings,
29466 .read = native_io_apic_read,
29467 .write = native_io_apic_write,
29468 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
29469 index 4c540c4..0b985b0 100644
29470 --- a/arch/x86/kernel/xsave.c
29471 +++ b/arch/x86/kernel/xsave.c
29472 @@ -167,18 +167,18 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
29473
29474 /* Setup the bytes not touched by the [f]xsave and reserved for SW. */
29475 sw_bytes = ia32_frame ? &fx_sw_reserved_ia32 : &fx_sw_reserved;
29476 - err = __copy_to_user(&x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
29477 + err = __copy_to_user(x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
29478
29479 if (!use_xsave())
29480 return err;
29481
29482 - err |= __put_user(FP_XSTATE_MAGIC2, (__u32 *)(buf + xstate_size));
29483 + err |= __put_user(FP_XSTATE_MAGIC2, (__u32 __user *)(buf + xstate_size));
29484
29485 /*
29486 * Read the xstate_bv which we copied (directly from the cpu or
29487 * from the state in task struct) to the user buffers.
29488 */
29489 - err |= __get_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
29490 + err |= __get_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
29491
29492 /*
29493 * For legacy compatible, we always set FP/SSE bits in the bit
29494 @@ -193,7 +193,7 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
29495 */
29496 xstate_bv |= XSTATE_FPSSE;
29497
29498 - err |= __put_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
29499 + err |= __put_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
29500
29501 return err;
29502 }
29503 @@ -202,6 +202,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
29504 {
29505 int err;
29506
29507 + buf = (struct xsave_struct __user *)____m(buf);
29508 if (use_xsave())
29509 err = xsave_user(buf);
29510 else if (use_fxsr())
29511 @@ -312,6 +313,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
29512 */
29513 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
29514 {
29515 + buf = (void __user *)____m(buf);
29516 if (use_xsave()) {
29517 if ((unsigned long)buf % 64 || fx_only) {
29518 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
29519 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
29520 index 38a0afe..94421a9 100644
29521 --- a/arch/x86/kvm/cpuid.c
29522 +++ b/arch/x86/kvm/cpuid.c
29523 @@ -166,15 +166,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
29524 struct kvm_cpuid2 *cpuid,
29525 struct kvm_cpuid_entry2 __user *entries)
29526 {
29527 - int r;
29528 + int r, i;
29529
29530 r = -E2BIG;
29531 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
29532 goto out;
29533 r = -EFAULT;
29534 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
29535 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
29536 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
29537 goto out;
29538 + for (i = 0; i < cpuid->nent; ++i) {
29539 + struct kvm_cpuid_entry2 cpuid_entry;
29540 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
29541 + goto out;
29542 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
29543 + }
29544 vcpu->arch.cpuid_nent = cpuid->nent;
29545 kvm_apic_set_version(vcpu);
29546 kvm_x86_ops->cpuid_update(vcpu);
29547 @@ -189,15 +194,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
29548 struct kvm_cpuid2 *cpuid,
29549 struct kvm_cpuid_entry2 __user *entries)
29550 {
29551 - int r;
29552 + int r, i;
29553
29554 r = -E2BIG;
29555 if (cpuid->nent < vcpu->arch.cpuid_nent)
29556 goto out;
29557 r = -EFAULT;
29558 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
29559 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
29560 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
29561 goto out;
29562 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
29563 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
29564 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
29565 + goto out;
29566 + }
29567 return 0;
29568
29569 out:
29570 diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
29571 index 9254069..bf25b97 100644
29572 --- a/arch/x86/kvm/emulate.c
29573 +++ b/arch/x86/kvm/emulate.c
29574 @@ -3550,7 +3550,7 @@ static int check_cr_write(struct x86_emulate_ctxt *ctxt)
29575
29576 ctxt->ops->get_msr(ctxt, MSR_EFER, &efer);
29577 if (efer & EFER_LMA)
29578 - rsvd = CR3_L_MODE_RESERVED_BITS;
29579 + rsvd = CR3_L_MODE_RESERVED_BITS & ~CR3_PCID_INVD;
29580
29581 if (new_val & rsvd)
29582 return emulate_gp(ctxt, 0);
29583 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
29584 index 08e8a89..0e9183e 100644
29585 --- a/arch/x86/kvm/lapic.c
29586 +++ b/arch/x86/kvm/lapic.c
29587 @@ -55,7 +55,7 @@
29588 #define APIC_BUS_CYCLE_NS 1
29589
29590 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
29591 -#define apic_debug(fmt, arg...)
29592 +#define apic_debug(fmt, arg...) do {} while (0)
29593
29594 #define APIC_LVT_NUM 6
29595 /* 14 is the version for Xeon and Pentium 8.4.8*/
29596 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
29597 index 4107765..d9eb358 100644
29598 --- a/arch/x86/kvm/paging_tmpl.h
29599 +++ b/arch/x86/kvm/paging_tmpl.h
29600 @@ -331,7 +331,7 @@ retry_walk:
29601 if (unlikely(kvm_is_error_hva(host_addr)))
29602 goto error;
29603
29604 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
29605 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
29606 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
29607 goto error;
29608 walker->ptep_user[walker->level - 1] = ptep_user;
29609 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
29610 index 78dadc3..fd84599 100644
29611 --- a/arch/x86/kvm/svm.c
29612 +++ b/arch/x86/kvm/svm.c
29613 @@ -3547,7 +3547,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
29614 int cpu = raw_smp_processor_id();
29615
29616 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
29617 +
29618 + pax_open_kernel();
29619 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
29620 + pax_close_kernel();
29621 +
29622 load_TR_desc();
29623 }
29624
29625 @@ -3948,6 +3952,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
29626 #endif
29627 #endif
29628
29629 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
29630 + __set_fs(current_thread_info()->addr_limit);
29631 +#endif
29632 +
29633 reload_tss(vcpu);
29634
29635 local_irq_disable();
29636 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
29637 index 41a5426..c0b3c00 100644
29638 --- a/arch/x86/kvm/vmx.c
29639 +++ b/arch/x86/kvm/vmx.c
29640 @@ -1341,12 +1341,12 @@ static void vmcs_write64(unsigned long field, u64 value)
29641 #endif
29642 }
29643
29644 -static void vmcs_clear_bits(unsigned long field, u32 mask)
29645 +static void vmcs_clear_bits(unsigned long field, unsigned long mask)
29646 {
29647 vmcs_writel(field, vmcs_readl(field) & ~mask);
29648 }
29649
29650 -static void vmcs_set_bits(unsigned long field, u32 mask)
29651 +static void vmcs_set_bits(unsigned long field, unsigned long mask)
29652 {
29653 vmcs_writel(field, vmcs_readl(field) | mask);
29654 }
29655 @@ -1606,7 +1606,11 @@ static void reload_tss(void)
29656 struct desc_struct *descs;
29657
29658 descs = (void *)gdt->address;
29659 +
29660 + pax_open_kernel();
29661 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
29662 + pax_close_kernel();
29663 +
29664 load_TR_desc();
29665 }
29666
29667 @@ -1834,6 +1838,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
29668 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
29669 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
29670
29671 +#ifdef CONFIG_PAX_PER_CPU_PGD
29672 + vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
29673 +#endif
29674 +
29675 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
29676 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
29677 vmx->loaded_vmcs->cpu = cpu;
29678 @@ -2123,7 +2131,7 @@ static void setup_msrs(struct vcpu_vmx *vmx)
29679 * reads and returns guest's timestamp counter "register"
29680 * guest_tsc = host_tsc + tsc_offset -- 21.3
29681 */
29682 -static u64 guest_read_tsc(void)
29683 +static u64 __intentional_overflow(-1) guest_read_tsc(void)
29684 {
29685 u64 host_tsc, tsc_offset;
29686
29687 @@ -3114,8 +3122,11 @@ static __init int hardware_setup(void)
29688 if (!cpu_has_vmx_flexpriority())
29689 flexpriority_enabled = 0;
29690
29691 - if (!cpu_has_vmx_tpr_shadow())
29692 - kvm_x86_ops->update_cr8_intercept = NULL;
29693 + if (!cpu_has_vmx_tpr_shadow()) {
29694 + pax_open_kernel();
29695 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
29696 + pax_close_kernel();
29697 + }
29698
29699 if (enable_ept && !cpu_has_vmx_ept_2m_page())
29700 kvm_disable_largepages();
29701 @@ -3126,13 +3137,15 @@ static __init int hardware_setup(void)
29702 if (!cpu_has_vmx_apicv())
29703 enable_apicv = 0;
29704
29705 + pax_open_kernel();
29706 if (enable_apicv)
29707 - kvm_x86_ops->update_cr8_intercept = NULL;
29708 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
29709 else {
29710 - kvm_x86_ops->hwapic_irr_update = NULL;
29711 - kvm_x86_ops->deliver_posted_interrupt = NULL;
29712 - kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
29713 + *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
29714 + *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
29715 + *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
29716 }
29717 + pax_close_kernel();
29718
29719 if (nested)
29720 nested_vmx_setup_ctls_msrs();
29721 @@ -4242,7 +4255,10 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
29722 unsigned long cr4;
29723
29724 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
29725 +
29726 +#ifndef CONFIG_PAX_PER_CPU_PGD
29727 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
29728 +#endif
29729
29730 /* Save the most likely value for this task's CR4 in the VMCS. */
29731 cr4 = read_cr4();
29732 @@ -4269,7 +4285,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
29733 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
29734 vmx->host_idt_base = dt.address;
29735
29736 - vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
29737 + vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
29738
29739 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
29740 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
29741 @@ -7475,6 +7491,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
29742 "jmp 2f \n\t"
29743 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
29744 "2: "
29745 +
29746 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
29747 + "ljmp %[cs],$3f\n\t"
29748 + "3: "
29749 +#endif
29750 +
29751 /* Save guest registers, load host registers, keep flags */
29752 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
29753 "pop %0 \n\t"
29754 @@ -7527,6 +7549,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
29755 #endif
29756 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
29757 [wordsize]"i"(sizeof(ulong))
29758 +
29759 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
29760 + ,[cs]"i"(__KERNEL_CS)
29761 +#endif
29762 +
29763 : "cc", "memory"
29764 #ifdef CONFIG_X86_64
29765 , "rax", "rbx", "rdi", "rsi"
29766 @@ -7540,7 +7567,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
29767 if (debugctlmsr)
29768 update_debugctlmsr(debugctlmsr);
29769
29770 -#ifndef CONFIG_X86_64
29771 +#ifdef CONFIG_X86_32
29772 /*
29773 * The sysexit path does not restore ds/es, so we must set them to
29774 * a reasonable value ourselves.
29775 @@ -7549,8 +7576,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
29776 * may be executed in interrupt context, which saves and restore segments
29777 * around it, nullifying its effect.
29778 */
29779 - loadsegment(ds, __USER_DS);
29780 - loadsegment(es, __USER_DS);
29781 + loadsegment(ds, __KERNEL_DS);
29782 + loadsegment(es, __KERNEL_DS);
29783 + loadsegment(ss, __KERNEL_DS);
29784 +
29785 +#ifdef CONFIG_PAX_KERNEXEC
29786 + loadsegment(fs, __KERNEL_PERCPU);
29787 +#endif
29788 +
29789 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29790 + __set_fs(current_thread_info()->addr_limit);
29791 +#endif
29792 +
29793 #endif
29794
29795 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
29796 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
29797 index d6aeccf..f0f150c 100644
29798 --- a/arch/x86/kvm/x86.c
29799 +++ b/arch/x86/kvm/x86.c
29800 @@ -729,6 +729,8 @@ EXPORT_SYMBOL_GPL(kvm_set_cr4);
29801
29802 int kvm_set_cr3(struct kvm_vcpu *vcpu, unsigned long cr3)
29803 {
29804 + cr3 &= ~CR3_PCID_INVD;
29805 +
29806 if (cr3 == kvm_read_cr3(vcpu) && !pdptrs_changed(vcpu)) {
29807 kvm_mmu_sync_roots(vcpu);
29808 kvm_mmu_flush_tlb(vcpu);
29809 @@ -1857,8 +1859,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
29810 {
29811 struct kvm *kvm = vcpu->kvm;
29812 int lm = is_long_mode(vcpu);
29813 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
29814 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
29815 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
29816 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
29817 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
29818 : kvm->arch.xen_hvm_config.blob_size_32;
29819 u32 page_num = data & ~PAGE_MASK;
29820 @@ -2779,6 +2781,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
29821 if (n < msr_list.nmsrs)
29822 goto out;
29823 r = -EFAULT;
29824 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
29825 + goto out;
29826 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
29827 num_msrs_to_save * sizeof(u32)))
29828 goto out;
29829 @@ -5639,7 +5643,7 @@ static struct notifier_block pvclock_gtod_notifier = {
29830 };
29831 #endif
29832
29833 -int kvm_arch_init(void *opaque)
29834 +int kvm_arch_init(const void *opaque)
29835 {
29836 int r;
29837 struct kvm_x86_ops *ops = opaque;
29838 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
29839 index aae9413..d11e829 100644
29840 --- a/arch/x86/lguest/boot.c
29841 +++ b/arch/x86/lguest/boot.c
29842 @@ -1206,9 +1206,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
29843 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
29844 * Launcher to reboot us.
29845 */
29846 -static void lguest_restart(char *reason)
29847 +static __noreturn void lguest_restart(char *reason)
29848 {
29849 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
29850 + BUG();
29851 }
29852
29853 /*G:050
29854 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
29855 index 00933d5..3a64af9 100644
29856 --- a/arch/x86/lib/atomic64_386_32.S
29857 +++ b/arch/x86/lib/atomic64_386_32.S
29858 @@ -48,6 +48,10 @@ BEGIN(read)
29859 movl (v), %eax
29860 movl 4(v), %edx
29861 RET_ENDP
29862 +BEGIN(read_unchecked)
29863 + movl (v), %eax
29864 + movl 4(v), %edx
29865 +RET_ENDP
29866 #undef v
29867
29868 #define v %esi
29869 @@ -55,6 +59,10 @@ BEGIN(set)
29870 movl %ebx, (v)
29871 movl %ecx, 4(v)
29872 RET_ENDP
29873 +BEGIN(set_unchecked)
29874 + movl %ebx, (v)
29875 + movl %ecx, 4(v)
29876 +RET_ENDP
29877 #undef v
29878
29879 #define v %esi
29880 @@ -70,6 +78,20 @@ RET_ENDP
29881 BEGIN(add)
29882 addl %eax, (v)
29883 adcl %edx, 4(v)
29884 +
29885 +#ifdef CONFIG_PAX_REFCOUNT
29886 + jno 0f
29887 + subl %eax, (v)
29888 + sbbl %edx, 4(v)
29889 + int $4
29890 +0:
29891 + _ASM_EXTABLE(0b, 0b)
29892 +#endif
29893 +
29894 +RET_ENDP
29895 +BEGIN(add_unchecked)
29896 + addl %eax, (v)
29897 + adcl %edx, 4(v)
29898 RET_ENDP
29899 #undef v
29900
29901 @@ -77,6 +99,24 @@ RET_ENDP
29902 BEGIN(add_return)
29903 addl (v), %eax
29904 adcl 4(v), %edx
29905 +
29906 +#ifdef CONFIG_PAX_REFCOUNT
29907 + into
29908 +1234:
29909 + _ASM_EXTABLE(1234b, 2f)
29910 +#endif
29911 +
29912 + movl %eax, (v)
29913 + movl %edx, 4(v)
29914 +
29915 +#ifdef CONFIG_PAX_REFCOUNT
29916 +2:
29917 +#endif
29918 +
29919 +RET_ENDP
29920 +BEGIN(add_return_unchecked)
29921 + addl (v), %eax
29922 + adcl 4(v), %edx
29923 movl %eax, (v)
29924 movl %edx, 4(v)
29925 RET_ENDP
29926 @@ -86,6 +126,20 @@ RET_ENDP
29927 BEGIN(sub)
29928 subl %eax, (v)
29929 sbbl %edx, 4(v)
29930 +
29931 +#ifdef CONFIG_PAX_REFCOUNT
29932 + jno 0f
29933 + addl %eax, (v)
29934 + adcl %edx, 4(v)
29935 + int $4
29936 +0:
29937 + _ASM_EXTABLE(0b, 0b)
29938 +#endif
29939 +
29940 +RET_ENDP
29941 +BEGIN(sub_unchecked)
29942 + subl %eax, (v)
29943 + sbbl %edx, 4(v)
29944 RET_ENDP
29945 #undef v
29946
29947 @@ -96,6 +150,27 @@ BEGIN(sub_return)
29948 sbbl $0, %edx
29949 addl (v), %eax
29950 adcl 4(v), %edx
29951 +
29952 +#ifdef CONFIG_PAX_REFCOUNT
29953 + into
29954 +1234:
29955 + _ASM_EXTABLE(1234b, 2f)
29956 +#endif
29957 +
29958 + movl %eax, (v)
29959 + movl %edx, 4(v)
29960 +
29961 +#ifdef CONFIG_PAX_REFCOUNT
29962 +2:
29963 +#endif
29964 +
29965 +RET_ENDP
29966 +BEGIN(sub_return_unchecked)
29967 + negl %edx
29968 + negl %eax
29969 + sbbl $0, %edx
29970 + addl (v), %eax
29971 + adcl 4(v), %edx
29972 movl %eax, (v)
29973 movl %edx, 4(v)
29974 RET_ENDP
29975 @@ -105,6 +180,20 @@ RET_ENDP
29976 BEGIN(inc)
29977 addl $1, (v)
29978 adcl $0, 4(v)
29979 +
29980 +#ifdef CONFIG_PAX_REFCOUNT
29981 + jno 0f
29982 + subl $1, (v)
29983 + sbbl $0, 4(v)
29984 + int $4
29985 +0:
29986 + _ASM_EXTABLE(0b, 0b)
29987 +#endif
29988 +
29989 +RET_ENDP
29990 +BEGIN(inc_unchecked)
29991 + addl $1, (v)
29992 + adcl $0, 4(v)
29993 RET_ENDP
29994 #undef v
29995
29996 @@ -114,6 +203,26 @@ BEGIN(inc_return)
29997 movl 4(v), %edx
29998 addl $1, %eax
29999 adcl $0, %edx
30000 +
30001 +#ifdef CONFIG_PAX_REFCOUNT
30002 + into
30003 +1234:
30004 + _ASM_EXTABLE(1234b, 2f)
30005 +#endif
30006 +
30007 + movl %eax, (v)
30008 + movl %edx, 4(v)
30009 +
30010 +#ifdef CONFIG_PAX_REFCOUNT
30011 +2:
30012 +#endif
30013 +
30014 +RET_ENDP
30015 +BEGIN(inc_return_unchecked)
30016 + movl (v), %eax
30017 + movl 4(v), %edx
30018 + addl $1, %eax
30019 + adcl $0, %edx
30020 movl %eax, (v)
30021 movl %edx, 4(v)
30022 RET_ENDP
30023 @@ -123,6 +232,20 @@ RET_ENDP
30024 BEGIN(dec)
30025 subl $1, (v)
30026 sbbl $0, 4(v)
30027 +
30028 +#ifdef CONFIG_PAX_REFCOUNT
30029 + jno 0f
30030 + addl $1, (v)
30031 + adcl $0, 4(v)
30032 + int $4
30033 +0:
30034 + _ASM_EXTABLE(0b, 0b)
30035 +#endif
30036 +
30037 +RET_ENDP
30038 +BEGIN(dec_unchecked)
30039 + subl $1, (v)
30040 + sbbl $0, 4(v)
30041 RET_ENDP
30042 #undef v
30043
30044 @@ -132,6 +255,26 @@ BEGIN(dec_return)
30045 movl 4(v), %edx
30046 subl $1, %eax
30047 sbbl $0, %edx
30048 +
30049 +#ifdef CONFIG_PAX_REFCOUNT
30050 + into
30051 +1234:
30052 + _ASM_EXTABLE(1234b, 2f)
30053 +#endif
30054 +
30055 + movl %eax, (v)
30056 + movl %edx, 4(v)
30057 +
30058 +#ifdef CONFIG_PAX_REFCOUNT
30059 +2:
30060 +#endif
30061 +
30062 +RET_ENDP
30063 +BEGIN(dec_return_unchecked)
30064 + movl (v), %eax
30065 + movl 4(v), %edx
30066 + subl $1, %eax
30067 + sbbl $0, %edx
30068 movl %eax, (v)
30069 movl %edx, 4(v)
30070 RET_ENDP
30071 @@ -143,6 +286,13 @@ BEGIN(add_unless)
30072 adcl %edx, %edi
30073 addl (v), %eax
30074 adcl 4(v), %edx
30075 +
30076 +#ifdef CONFIG_PAX_REFCOUNT
30077 + into
30078 +1234:
30079 + _ASM_EXTABLE(1234b, 2f)
30080 +#endif
30081 +
30082 cmpl %eax, %ecx
30083 je 3f
30084 1:
30085 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
30086 1:
30087 addl $1, %eax
30088 adcl $0, %edx
30089 +
30090 +#ifdef CONFIG_PAX_REFCOUNT
30091 + into
30092 +1234:
30093 + _ASM_EXTABLE(1234b, 2f)
30094 +#endif
30095 +
30096 movl %eax, (v)
30097 movl %edx, 4(v)
30098 movl $1, %eax
30099 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
30100 movl 4(v), %edx
30101 subl $1, %eax
30102 sbbl $0, %edx
30103 +
30104 +#ifdef CONFIG_PAX_REFCOUNT
30105 + into
30106 +1234:
30107 + _ASM_EXTABLE(1234b, 1f)
30108 +#endif
30109 +
30110 js 1f
30111 movl %eax, (v)
30112 movl %edx, 4(v)
30113 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
30114 index f5cc9eb..51fa319 100644
30115 --- a/arch/x86/lib/atomic64_cx8_32.S
30116 +++ b/arch/x86/lib/atomic64_cx8_32.S
30117 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
30118 CFI_STARTPROC
30119
30120 read64 %ecx
30121 + pax_force_retaddr
30122 ret
30123 CFI_ENDPROC
30124 ENDPROC(atomic64_read_cx8)
30125
30126 +ENTRY(atomic64_read_unchecked_cx8)
30127 + CFI_STARTPROC
30128 +
30129 + read64 %ecx
30130 + pax_force_retaddr
30131 + ret
30132 + CFI_ENDPROC
30133 +ENDPROC(atomic64_read_unchecked_cx8)
30134 +
30135 ENTRY(atomic64_set_cx8)
30136 CFI_STARTPROC
30137
30138 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
30139 cmpxchg8b (%esi)
30140 jne 1b
30141
30142 + pax_force_retaddr
30143 ret
30144 CFI_ENDPROC
30145 ENDPROC(atomic64_set_cx8)
30146
30147 +ENTRY(atomic64_set_unchecked_cx8)
30148 + CFI_STARTPROC
30149 +
30150 +1:
30151 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
30152 + * are atomic on 586 and newer */
30153 + cmpxchg8b (%esi)
30154 + jne 1b
30155 +
30156 + pax_force_retaddr
30157 + ret
30158 + CFI_ENDPROC
30159 +ENDPROC(atomic64_set_unchecked_cx8)
30160 +
30161 ENTRY(atomic64_xchg_cx8)
30162 CFI_STARTPROC
30163
30164 @@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
30165 cmpxchg8b (%esi)
30166 jne 1b
30167
30168 + pax_force_retaddr
30169 ret
30170 CFI_ENDPROC
30171 ENDPROC(atomic64_xchg_cx8)
30172
30173 -.macro addsub_return func ins insc
30174 -ENTRY(atomic64_\func\()_return_cx8)
30175 +.macro addsub_return func ins insc unchecked=""
30176 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
30177 CFI_STARTPROC
30178 SAVE ebp
30179 SAVE ebx
30180 @@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
30181 movl %edx, %ecx
30182 \ins\()l %esi, %ebx
30183 \insc\()l %edi, %ecx
30184 +
30185 +.ifb \unchecked
30186 +#ifdef CONFIG_PAX_REFCOUNT
30187 + into
30188 +2:
30189 + _ASM_EXTABLE(2b, 3f)
30190 +#endif
30191 +.endif
30192 +
30193 LOCK_PREFIX
30194 cmpxchg8b (%ebp)
30195 jne 1b
30196 -
30197 -10:
30198 movl %ebx, %eax
30199 movl %ecx, %edx
30200 +
30201 +.ifb \unchecked
30202 +#ifdef CONFIG_PAX_REFCOUNT
30203 +3:
30204 +#endif
30205 +.endif
30206 +
30207 RESTORE edi
30208 RESTORE esi
30209 RESTORE ebx
30210 RESTORE ebp
30211 + pax_force_retaddr
30212 ret
30213 CFI_ENDPROC
30214 -ENDPROC(atomic64_\func\()_return_cx8)
30215 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
30216 .endm
30217
30218 addsub_return add add adc
30219 addsub_return sub sub sbb
30220 +addsub_return add add adc _unchecked
30221 +addsub_return sub sub sbb _unchecked
30222
30223 -.macro incdec_return func ins insc
30224 -ENTRY(atomic64_\func\()_return_cx8)
30225 +.macro incdec_return func ins insc unchecked=""
30226 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
30227 CFI_STARTPROC
30228 SAVE ebx
30229
30230 @@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
30231 movl %edx, %ecx
30232 \ins\()l $1, %ebx
30233 \insc\()l $0, %ecx
30234 +
30235 +.ifb \unchecked
30236 +#ifdef CONFIG_PAX_REFCOUNT
30237 + into
30238 +2:
30239 + _ASM_EXTABLE(2b, 3f)
30240 +#endif
30241 +.endif
30242 +
30243 LOCK_PREFIX
30244 cmpxchg8b (%esi)
30245 jne 1b
30246
30247 -10:
30248 movl %ebx, %eax
30249 movl %ecx, %edx
30250 +
30251 +.ifb \unchecked
30252 +#ifdef CONFIG_PAX_REFCOUNT
30253 +3:
30254 +#endif
30255 +.endif
30256 +
30257 RESTORE ebx
30258 + pax_force_retaddr
30259 ret
30260 CFI_ENDPROC
30261 -ENDPROC(atomic64_\func\()_return_cx8)
30262 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
30263 .endm
30264
30265 incdec_return inc add adc
30266 incdec_return dec sub sbb
30267 +incdec_return inc add adc _unchecked
30268 +incdec_return dec sub sbb _unchecked
30269
30270 ENTRY(atomic64_dec_if_positive_cx8)
30271 CFI_STARTPROC
30272 @@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
30273 movl %edx, %ecx
30274 subl $1, %ebx
30275 sbb $0, %ecx
30276 +
30277 +#ifdef CONFIG_PAX_REFCOUNT
30278 + into
30279 +1234:
30280 + _ASM_EXTABLE(1234b, 2f)
30281 +#endif
30282 +
30283 js 2f
30284 LOCK_PREFIX
30285 cmpxchg8b (%esi)
30286 @@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
30287 movl %ebx, %eax
30288 movl %ecx, %edx
30289 RESTORE ebx
30290 + pax_force_retaddr
30291 ret
30292 CFI_ENDPROC
30293 ENDPROC(atomic64_dec_if_positive_cx8)
30294 @@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
30295 movl %edx, %ecx
30296 addl %ebp, %ebx
30297 adcl %edi, %ecx
30298 +
30299 +#ifdef CONFIG_PAX_REFCOUNT
30300 + into
30301 +1234:
30302 + _ASM_EXTABLE(1234b, 3f)
30303 +#endif
30304 +
30305 LOCK_PREFIX
30306 cmpxchg8b (%esi)
30307 jne 1b
30308 @@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
30309 CFI_ADJUST_CFA_OFFSET -8
30310 RESTORE ebx
30311 RESTORE ebp
30312 + pax_force_retaddr
30313 ret
30314 4:
30315 cmpl %edx, 4(%esp)
30316 @@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
30317 xorl %ecx, %ecx
30318 addl $1, %ebx
30319 adcl %edx, %ecx
30320 +
30321 +#ifdef CONFIG_PAX_REFCOUNT
30322 + into
30323 +1234:
30324 + _ASM_EXTABLE(1234b, 3f)
30325 +#endif
30326 +
30327 LOCK_PREFIX
30328 cmpxchg8b (%esi)
30329 jne 1b
30330 @@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
30331 movl $1, %eax
30332 3:
30333 RESTORE ebx
30334 + pax_force_retaddr
30335 ret
30336 CFI_ENDPROC
30337 ENDPROC(atomic64_inc_not_zero_cx8)
30338 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
30339 index e78b8eee..7e173a8 100644
30340 --- a/arch/x86/lib/checksum_32.S
30341 +++ b/arch/x86/lib/checksum_32.S
30342 @@ -29,7 +29,8 @@
30343 #include <asm/dwarf2.h>
30344 #include <asm/errno.h>
30345 #include <asm/asm.h>
30346 -
30347 +#include <asm/segment.h>
30348 +
30349 /*
30350 * computes a partial checksum, e.g. for TCP/UDP fragments
30351 */
30352 @@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
30353
30354 #define ARGBASE 16
30355 #define FP 12
30356 -
30357 -ENTRY(csum_partial_copy_generic)
30358 +
30359 +ENTRY(csum_partial_copy_generic_to_user)
30360 CFI_STARTPROC
30361 +
30362 +#ifdef CONFIG_PAX_MEMORY_UDEREF
30363 + pushl_cfi %gs
30364 + popl_cfi %es
30365 + jmp csum_partial_copy_generic
30366 +#endif
30367 +
30368 +ENTRY(csum_partial_copy_generic_from_user)
30369 +
30370 +#ifdef CONFIG_PAX_MEMORY_UDEREF
30371 + pushl_cfi %gs
30372 + popl_cfi %ds
30373 +#endif
30374 +
30375 +ENTRY(csum_partial_copy_generic)
30376 subl $4,%esp
30377 CFI_ADJUST_CFA_OFFSET 4
30378 pushl_cfi %edi
30379 @@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
30380 jmp 4f
30381 SRC(1: movw (%esi), %bx )
30382 addl $2, %esi
30383 -DST( movw %bx, (%edi) )
30384 +DST( movw %bx, %es:(%edi) )
30385 addl $2, %edi
30386 addw %bx, %ax
30387 adcl $0, %eax
30388 @@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
30389 SRC(1: movl (%esi), %ebx )
30390 SRC( movl 4(%esi), %edx )
30391 adcl %ebx, %eax
30392 -DST( movl %ebx, (%edi) )
30393 +DST( movl %ebx, %es:(%edi) )
30394 adcl %edx, %eax
30395 -DST( movl %edx, 4(%edi) )
30396 +DST( movl %edx, %es:4(%edi) )
30397
30398 SRC( movl 8(%esi), %ebx )
30399 SRC( movl 12(%esi), %edx )
30400 adcl %ebx, %eax
30401 -DST( movl %ebx, 8(%edi) )
30402 +DST( movl %ebx, %es:8(%edi) )
30403 adcl %edx, %eax
30404 -DST( movl %edx, 12(%edi) )
30405 +DST( movl %edx, %es:12(%edi) )
30406
30407 SRC( movl 16(%esi), %ebx )
30408 SRC( movl 20(%esi), %edx )
30409 adcl %ebx, %eax
30410 -DST( movl %ebx, 16(%edi) )
30411 +DST( movl %ebx, %es:16(%edi) )
30412 adcl %edx, %eax
30413 -DST( movl %edx, 20(%edi) )
30414 +DST( movl %edx, %es:20(%edi) )
30415
30416 SRC( movl 24(%esi), %ebx )
30417 SRC( movl 28(%esi), %edx )
30418 adcl %ebx, %eax
30419 -DST( movl %ebx, 24(%edi) )
30420 +DST( movl %ebx, %es:24(%edi) )
30421 adcl %edx, %eax
30422 -DST( movl %edx, 28(%edi) )
30423 +DST( movl %edx, %es:28(%edi) )
30424
30425 lea 32(%esi), %esi
30426 lea 32(%edi), %edi
30427 @@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
30428 shrl $2, %edx # This clears CF
30429 SRC(3: movl (%esi), %ebx )
30430 adcl %ebx, %eax
30431 -DST( movl %ebx, (%edi) )
30432 +DST( movl %ebx, %es:(%edi) )
30433 lea 4(%esi), %esi
30434 lea 4(%edi), %edi
30435 dec %edx
30436 @@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
30437 jb 5f
30438 SRC( movw (%esi), %cx )
30439 leal 2(%esi), %esi
30440 -DST( movw %cx, (%edi) )
30441 +DST( movw %cx, %es:(%edi) )
30442 leal 2(%edi), %edi
30443 je 6f
30444 shll $16,%ecx
30445 SRC(5: movb (%esi), %cl )
30446 -DST( movb %cl, (%edi) )
30447 +DST( movb %cl, %es:(%edi) )
30448 6: addl %ecx, %eax
30449 adcl $0, %eax
30450 7:
30451 @@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
30452
30453 6001:
30454 movl ARGBASE+20(%esp), %ebx # src_err_ptr
30455 - movl $-EFAULT, (%ebx)
30456 + movl $-EFAULT, %ss:(%ebx)
30457
30458 # zero the complete destination - computing the rest
30459 # is too much work
30460 @@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
30461
30462 6002:
30463 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
30464 - movl $-EFAULT,(%ebx)
30465 + movl $-EFAULT,%ss:(%ebx)
30466 jmp 5000b
30467
30468 .previous
30469
30470 + pushl_cfi %ss
30471 + popl_cfi %ds
30472 + pushl_cfi %ss
30473 + popl_cfi %es
30474 popl_cfi %ebx
30475 CFI_RESTORE ebx
30476 popl_cfi %esi
30477 @@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
30478 popl_cfi %ecx # equivalent to addl $4,%esp
30479 ret
30480 CFI_ENDPROC
30481 -ENDPROC(csum_partial_copy_generic)
30482 +ENDPROC(csum_partial_copy_generic_to_user)
30483
30484 #else
30485
30486 /* Version for PentiumII/PPro */
30487
30488 #define ROUND1(x) \
30489 + nop; nop; nop; \
30490 SRC(movl x(%esi), %ebx ) ; \
30491 addl %ebx, %eax ; \
30492 - DST(movl %ebx, x(%edi) ) ;
30493 + DST(movl %ebx, %es:x(%edi)) ;
30494
30495 #define ROUND(x) \
30496 + nop; nop; nop; \
30497 SRC(movl x(%esi), %ebx ) ; \
30498 adcl %ebx, %eax ; \
30499 - DST(movl %ebx, x(%edi) ) ;
30500 + DST(movl %ebx, %es:x(%edi)) ;
30501
30502 #define ARGBASE 12
30503 -
30504 -ENTRY(csum_partial_copy_generic)
30505 +
30506 +ENTRY(csum_partial_copy_generic_to_user)
30507 CFI_STARTPROC
30508 +
30509 +#ifdef CONFIG_PAX_MEMORY_UDEREF
30510 + pushl_cfi %gs
30511 + popl_cfi %es
30512 + jmp csum_partial_copy_generic
30513 +#endif
30514 +
30515 +ENTRY(csum_partial_copy_generic_from_user)
30516 +
30517 +#ifdef CONFIG_PAX_MEMORY_UDEREF
30518 + pushl_cfi %gs
30519 + popl_cfi %ds
30520 +#endif
30521 +
30522 +ENTRY(csum_partial_copy_generic)
30523 pushl_cfi %ebx
30524 CFI_REL_OFFSET ebx, 0
30525 pushl_cfi %edi
30526 @@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
30527 subl %ebx, %edi
30528 lea -1(%esi),%edx
30529 andl $-32,%edx
30530 - lea 3f(%ebx,%ebx), %ebx
30531 + lea 3f(%ebx,%ebx,2), %ebx
30532 testl %esi, %esi
30533 jmp *%ebx
30534 1: addl $64,%esi
30535 @@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
30536 jb 5f
30537 SRC( movw (%esi), %dx )
30538 leal 2(%esi), %esi
30539 -DST( movw %dx, (%edi) )
30540 +DST( movw %dx, %es:(%edi) )
30541 leal 2(%edi), %edi
30542 je 6f
30543 shll $16,%edx
30544 5:
30545 SRC( movb (%esi), %dl )
30546 -DST( movb %dl, (%edi) )
30547 +DST( movb %dl, %es:(%edi) )
30548 6: addl %edx, %eax
30549 adcl $0, %eax
30550 7:
30551 .section .fixup, "ax"
30552 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
30553 - movl $-EFAULT, (%ebx)
30554 + movl $-EFAULT, %ss:(%ebx)
30555 # zero the complete destination (computing the rest is too much work)
30556 movl ARGBASE+8(%esp),%edi # dst
30557 movl ARGBASE+12(%esp),%ecx # len
30558 @@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
30559 rep; stosb
30560 jmp 7b
30561 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
30562 - movl $-EFAULT, (%ebx)
30563 + movl $-EFAULT, %ss:(%ebx)
30564 jmp 7b
30565 .previous
30566
30567 +#ifdef CONFIG_PAX_MEMORY_UDEREF
30568 + pushl_cfi %ss
30569 + popl_cfi %ds
30570 + pushl_cfi %ss
30571 + popl_cfi %es
30572 +#endif
30573 +
30574 popl_cfi %esi
30575 CFI_RESTORE esi
30576 popl_cfi %edi
30577 @@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
30578 CFI_RESTORE ebx
30579 ret
30580 CFI_ENDPROC
30581 -ENDPROC(csum_partial_copy_generic)
30582 +ENDPROC(csum_partial_copy_generic_to_user)
30583
30584 #undef ROUND
30585 #undef ROUND1
30586 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
30587 index f2145cf..cea889d 100644
30588 --- a/arch/x86/lib/clear_page_64.S
30589 +++ b/arch/x86/lib/clear_page_64.S
30590 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
30591 movl $4096/8,%ecx
30592 xorl %eax,%eax
30593 rep stosq
30594 + pax_force_retaddr
30595 ret
30596 CFI_ENDPROC
30597 ENDPROC(clear_page_c)
30598 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
30599 movl $4096,%ecx
30600 xorl %eax,%eax
30601 rep stosb
30602 + pax_force_retaddr
30603 ret
30604 CFI_ENDPROC
30605 ENDPROC(clear_page_c_e)
30606 @@ -43,6 +45,7 @@ ENTRY(clear_page)
30607 leaq 64(%rdi),%rdi
30608 jnz .Lloop
30609 nop
30610 + pax_force_retaddr
30611 ret
30612 CFI_ENDPROC
30613 .Lclear_page_end:
30614 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
30615
30616 #include <asm/cpufeature.h>
30617
30618 - .section .altinstr_replacement,"ax"
30619 + .section .altinstr_replacement,"a"
30620 1: .byte 0xeb /* jmp <disp8> */
30621 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
30622 2: .byte 0xeb /* jmp <disp8> */
30623 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
30624 index 1e572c5..2a162cd 100644
30625 --- a/arch/x86/lib/cmpxchg16b_emu.S
30626 +++ b/arch/x86/lib/cmpxchg16b_emu.S
30627 @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
30628
30629 popf
30630 mov $1, %al
30631 + pax_force_retaddr
30632 ret
30633
30634 not_same:
30635 popf
30636 xor %al,%al
30637 + pax_force_retaddr
30638 ret
30639
30640 CFI_ENDPROC
30641 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
30642 index 176cca6..e0d658e 100644
30643 --- a/arch/x86/lib/copy_page_64.S
30644 +++ b/arch/x86/lib/copy_page_64.S
30645 @@ -9,6 +9,7 @@ copy_page_rep:
30646 CFI_STARTPROC
30647 movl $4096/8, %ecx
30648 rep movsq
30649 + pax_force_retaddr
30650 ret
30651 CFI_ENDPROC
30652 ENDPROC(copy_page_rep)
30653 @@ -24,8 +25,8 @@ ENTRY(copy_page)
30654 CFI_ADJUST_CFA_OFFSET 2*8
30655 movq %rbx, (%rsp)
30656 CFI_REL_OFFSET rbx, 0
30657 - movq %r12, 1*8(%rsp)
30658 - CFI_REL_OFFSET r12, 1*8
30659 + movq %r13, 1*8(%rsp)
30660 + CFI_REL_OFFSET r13, 1*8
30661
30662 movl $(4096/64)-5, %ecx
30663 .p2align 4
30664 @@ -38,7 +39,7 @@ ENTRY(copy_page)
30665 movq 0x8*4(%rsi), %r9
30666 movq 0x8*5(%rsi), %r10
30667 movq 0x8*6(%rsi), %r11
30668 - movq 0x8*7(%rsi), %r12
30669 + movq 0x8*7(%rsi), %r13
30670
30671 prefetcht0 5*64(%rsi)
30672
30673 @@ -49,7 +50,7 @@ ENTRY(copy_page)
30674 movq %r9, 0x8*4(%rdi)
30675 movq %r10, 0x8*5(%rdi)
30676 movq %r11, 0x8*6(%rdi)
30677 - movq %r12, 0x8*7(%rdi)
30678 + movq %r13, 0x8*7(%rdi)
30679
30680 leaq 64 (%rsi), %rsi
30681 leaq 64 (%rdi), %rdi
30682 @@ -68,7 +69,7 @@ ENTRY(copy_page)
30683 movq 0x8*4(%rsi), %r9
30684 movq 0x8*5(%rsi), %r10
30685 movq 0x8*6(%rsi), %r11
30686 - movq 0x8*7(%rsi), %r12
30687 + movq 0x8*7(%rsi), %r13
30688
30689 movq %rax, 0x8*0(%rdi)
30690 movq %rbx, 0x8*1(%rdi)
30691 @@ -77,7 +78,7 @@ ENTRY(copy_page)
30692 movq %r9, 0x8*4(%rdi)
30693 movq %r10, 0x8*5(%rdi)
30694 movq %r11, 0x8*6(%rdi)
30695 - movq %r12, 0x8*7(%rdi)
30696 + movq %r13, 0x8*7(%rdi)
30697
30698 leaq 64(%rdi), %rdi
30699 leaq 64(%rsi), %rsi
30700 @@ -85,10 +86,11 @@ ENTRY(copy_page)
30701
30702 movq (%rsp), %rbx
30703 CFI_RESTORE rbx
30704 - movq 1*8(%rsp), %r12
30705 - CFI_RESTORE r12
30706 + movq 1*8(%rsp), %r13
30707 + CFI_RESTORE r13
30708 addq $2*8, %rsp
30709 CFI_ADJUST_CFA_OFFSET -2*8
30710 + pax_force_retaddr
30711 ret
30712 .Lcopy_page_end:
30713 CFI_ENDPROC
30714 @@ -99,7 +101,7 @@ ENDPROC(copy_page)
30715
30716 #include <asm/cpufeature.h>
30717
30718 - .section .altinstr_replacement,"ax"
30719 + .section .altinstr_replacement,"a"
30720 1: .byte 0xeb /* jmp <disp8> */
30721 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
30722 2:
30723 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
30724 index dee945d..a84067b 100644
30725 --- a/arch/x86/lib/copy_user_64.S
30726 +++ b/arch/x86/lib/copy_user_64.S
30727 @@ -18,31 +18,7 @@
30728 #include <asm/alternative-asm.h>
30729 #include <asm/asm.h>
30730 #include <asm/smap.h>
30731 -
30732 -/*
30733 - * By placing feature2 after feature1 in altinstructions section, we logically
30734 - * implement:
30735 - * If CPU has feature2, jmp to alt2 is used
30736 - * else if CPU has feature1, jmp to alt1 is used
30737 - * else jmp to orig is used.
30738 - */
30739 - .macro ALTERNATIVE_JUMP feature1,feature2,orig,alt1,alt2
30740 -0:
30741 - .byte 0xe9 /* 32bit jump */
30742 - .long \orig-1f /* by default jump to orig */
30743 -1:
30744 - .section .altinstr_replacement,"ax"
30745 -2: .byte 0xe9 /* near jump with 32bit immediate */
30746 - .long \alt1-1b /* offset */ /* or alternatively to alt1 */
30747 -3: .byte 0xe9 /* near jump with 32bit immediate */
30748 - .long \alt2-1b /* offset */ /* or alternatively to alt2 */
30749 - .previous
30750 -
30751 - .section .altinstructions,"a"
30752 - altinstruction_entry 0b,2b,\feature1,5,5
30753 - altinstruction_entry 0b,3b,\feature2,5,5
30754 - .previous
30755 - .endm
30756 +#include <asm/pgtable.h>
30757
30758 .macro ALIGN_DESTINATION
30759 #ifdef FIX_ALIGNMENT
30760 @@ -70,52 +46,6 @@
30761 #endif
30762 .endm
30763
30764 -/* Standard copy_to_user with segment limit checking */
30765 -ENTRY(_copy_to_user)
30766 - CFI_STARTPROC
30767 - GET_THREAD_INFO(%rax)
30768 - movq %rdi,%rcx
30769 - addq %rdx,%rcx
30770 - jc bad_to_user
30771 - cmpq TI_addr_limit(%rax),%rcx
30772 - ja bad_to_user
30773 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
30774 - copy_user_generic_unrolled,copy_user_generic_string, \
30775 - copy_user_enhanced_fast_string
30776 - CFI_ENDPROC
30777 -ENDPROC(_copy_to_user)
30778 -
30779 -/* Standard copy_from_user with segment limit checking */
30780 -ENTRY(_copy_from_user)
30781 - CFI_STARTPROC
30782 - GET_THREAD_INFO(%rax)
30783 - movq %rsi,%rcx
30784 - addq %rdx,%rcx
30785 - jc bad_from_user
30786 - cmpq TI_addr_limit(%rax),%rcx
30787 - ja bad_from_user
30788 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
30789 - copy_user_generic_unrolled,copy_user_generic_string, \
30790 - copy_user_enhanced_fast_string
30791 - CFI_ENDPROC
30792 -ENDPROC(_copy_from_user)
30793 -
30794 - .section .fixup,"ax"
30795 - /* must zero dest */
30796 -ENTRY(bad_from_user)
30797 -bad_from_user:
30798 - CFI_STARTPROC
30799 - movl %edx,%ecx
30800 - xorl %eax,%eax
30801 - rep
30802 - stosb
30803 -bad_to_user:
30804 - movl %edx,%eax
30805 - ret
30806 - CFI_ENDPROC
30807 -ENDPROC(bad_from_user)
30808 - .previous
30809 -
30810 /*
30811 * copy_user_generic_unrolled - memory copy with exception handling.
30812 * This version is for CPUs like P4 that don't have efficient micro
30813 @@ -131,6 +61,7 @@ ENDPROC(bad_from_user)
30814 */
30815 ENTRY(copy_user_generic_unrolled)
30816 CFI_STARTPROC
30817 + ASM_PAX_OPEN_USERLAND
30818 ASM_STAC
30819 cmpl $8,%edx
30820 jb 20f /* less then 8 bytes, go to byte copy loop */
30821 @@ -180,6 +111,8 @@ ENTRY(copy_user_generic_unrolled)
30822 jnz 21b
30823 23: xor %eax,%eax
30824 ASM_CLAC
30825 + ASM_PAX_CLOSE_USERLAND
30826 + pax_force_retaddr
30827 ret
30828
30829 .section .fixup,"ax"
30830 @@ -235,6 +168,7 @@ ENDPROC(copy_user_generic_unrolled)
30831 */
30832 ENTRY(copy_user_generic_string)
30833 CFI_STARTPROC
30834 + ASM_PAX_OPEN_USERLAND
30835 ASM_STAC
30836 cmpl $8,%edx
30837 jb 2f /* less than 8 bytes, go to byte copy loop */
30838 @@ -249,6 +183,8 @@ ENTRY(copy_user_generic_string)
30839 movsb
30840 xorl %eax,%eax
30841 ASM_CLAC
30842 + ASM_PAX_CLOSE_USERLAND
30843 + pax_force_retaddr
30844 ret
30845
30846 .section .fixup,"ax"
30847 @@ -276,12 +212,15 @@ ENDPROC(copy_user_generic_string)
30848 */
30849 ENTRY(copy_user_enhanced_fast_string)
30850 CFI_STARTPROC
30851 + ASM_PAX_OPEN_USERLAND
30852 ASM_STAC
30853 movl %edx,%ecx
30854 1: rep
30855 movsb
30856 xorl %eax,%eax
30857 ASM_CLAC
30858 + ASM_PAX_CLOSE_USERLAND
30859 + pax_force_retaddr
30860 ret
30861
30862 .section .fixup,"ax"
30863 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
30864 index 6a4f43c..c70fb52 100644
30865 --- a/arch/x86/lib/copy_user_nocache_64.S
30866 +++ b/arch/x86/lib/copy_user_nocache_64.S
30867 @@ -8,6 +8,7 @@
30868
30869 #include <linux/linkage.h>
30870 #include <asm/dwarf2.h>
30871 +#include <asm/alternative-asm.h>
30872
30873 #define FIX_ALIGNMENT 1
30874
30875 @@ -16,6 +17,7 @@
30876 #include <asm/thread_info.h>
30877 #include <asm/asm.h>
30878 #include <asm/smap.h>
30879 +#include <asm/pgtable.h>
30880
30881 .macro ALIGN_DESTINATION
30882 #ifdef FIX_ALIGNMENT
30883 @@ -49,6 +51,16 @@
30884 */
30885 ENTRY(__copy_user_nocache)
30886 CFI_STARTPROC
30887 +
30888 +#ifdef CONFIG_PAX_MEMORY_UDEREF
30889 + mov pax_user_shadow_base,%rcx
30890 + cmp %rcx,%rsi
30891 + jae 1f
30892 + add %rcx,%rsi
30893 +1:
30894 +#endif
30895 +
30896 + ASM_PAX_OPEN_USERLAND
30897 ASM_STAC
30898 cmpl $8,%edx
30899 jb 20f /* less then 8 bytes, go to byte copy loop */
30900 @@ -98,7 +110,9 @@ ENTRY(__copy_user_nocache)
30901 jnz 21b
30902 23: xorl %eax,%eax
30903 ASM_CLAC
30904 + ASM_PAX_CLOSE_USERLAND
30905 sfence
30906 + pax_force_retaddr
30907 ret
30908
30909 .section .fixup,"ax"
30910 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
30911 index 2419d5f..fe52d0e 100644
30912 --- a/arch/x86/lib/csum-copy_64.S
30913 +++ b/arch/x86/lib/csum-copy_64.S
30914 @@ -9,6 +9,7 @@
30915 #include <asm/dwarf2.h>
30916 #include <asm/errno.h>
30917 #include <asm/asm.h>
30918 +#include <asm/alternative-asm.h>
30919
30920 /*
30921 * Checksum copy with exception handling.
30922 @@ -56,8 +57,8 @@ ENTRY(csum_partial_copy_generic)
30923 CFI_ADJUST_CFA_OFFSET 7*8
30924 movq %rbx, 2*8(%rsp)
30925 CFI_REL_OFFSET rbx, 2*8
30926 - movq %r12, 3*8(%rsp)
30927 - CFI_REL_OFFSET r12, 3*8
30928 + movq %r15, 3*8(%rsp)
30929 + CFI_REL_OFFSET r15, 3*8
30930 movq %r14, 4*8(%rsp)
30931 CFI_REL_OFFSET r14, 4*8
30932 movq %r13, 5*8(%rsp)
30933 @@ -72,16 +73,16 @@ ENTRY(csum_partial_copy_generic)
30934 movl %edx, %ecx
30935
30936 xorl %r9d, %r9d
30937 - movq %rcx, %r12
30938 + movq %rcx, %r15
30939
30940 - shrq $6, %r12
30941 + shrq $6, %r15
30942 jz .Lhandle_tail /* < 64 */
30943
30944 clc
30945
30946 /* main loop. clear in 64 byte blocks */
30947 /* r9: zero, r8: temp2, rbx: temp1, rax: sum, rcx: saved length */
30948 - /* r11: temp3, rdx: temp4, r12 loopcnt */
30949 + /* r11: temp3, rdx: temp4, r15 loopcnt */
30950 /* r10: temp5, rbp: temp6, r14 temp7, r13 temp8 */
30951 .p2align 4
30952 .Lloop:
30953 @@ -115,7 +116,7 @@ ENTRY(csum_partial_copy_generic)
30954 adcq %r14, %rax
30955 adcq %r13, %rax
30956
30957 - decl %r12d
30958 + decl %r15d
30959
30960 dest
30961 movq %rbx, (%rsi)
30962 @@ -210,8 +211,8 @@ ENTRY(csum_partial_copy_generic)
30963 .Lende:
30964 movq 2*8(%rsp), %rbx
30965 CFI_RESTORE rbx
30966 - movq 3*8(%rsp), %r12
30967 - CFI_RESTORE r12
30968 + movq 3*8(%rsp), %r15
30969 + CFI_RESTORE r15
30970 movq 4*8(%rsp), %r14
30971 CFI_RESTORE r14
30972 movq 5*8(%rsp), %r13
30973 @@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
30974 CFI_RESTORE rbp
30975 addq $7*8, %rsp
30976 CFI_ADJUST_CFA_OFFSET -7*8
30977 + pax_force_retaddr
30978 ret
30979 CFI_RESTORE_STATE
30980
30981 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
30982 index 7609e0e..b449b98 100644
30983 --- a/arch/x86/lib/csum-wrappers_64.c
30984 +++ b/arch/x86/lib/csum-wrappers_64.c
30985 @@ -53,10 +53,12 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
30986 len -= 2;
30987 }
30988 }
30989 + pax_open_userland();
30990 stac();
30991 - isum = csum_partial_copy_generic((__force const void *)src,
30992 + isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
30993 dst, len, isum, errp, NULL);
30994 clac();
30995 + pax_close_userland();
30996 if (unlikely(*errp))
30997 goto out_err;
30998
30999 @@ -110,10 +112,12 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
31000 }
31001
31002 *errp = 0;
31003 + pax_open_userland();
31004 stac();
31005 - ret = csum_partial_copy_generic(src, (void __force *)dst,
31006 + ret = csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
31007 len, isum, NULL, errp);
31008 clac();
31009 + pax_close_userland();
31010 return ret;
31011 }
31012 EXPORT_SYMBOL(csum_partial_copy_to_user);
31013 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
31014 index a451235..1daa956 100644
31015 --- a/arch/x86/lib/getuser.S
31016 +++ b/arch/x86/lib/getuser.S
31017 @@ -33,17 +33,40 @@
31018 #include <asm/thread_info.h>
31019 #include <asm/asm.h>
31020 #include <asm/smap.h>
31021 +#include <asm/segment.h>
31022 +#include <asm/pgtable.h>
31023 +#include <asm/alternative-asm.h>
31024 +
31025 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
31026 +#define __copyuser_seg gs;
31027 +#else
31028 +#define __copyuser_seg
31029 +#endif
31030
31031 .text
31032 ENTRY(__get_user_1)
31033 CFI_STARTPROC
31034 +
31035 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
31036 GET_THREAD_INFO(%_ASM_DX)
31037 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
31038 jae bad_get_user
31039 ASM_STAC
31040 -1: movzbl (%_ASM_AX),%edx
31041 +
31042 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31043 + mov pax_user_shadow_base,%_ASM_DX
31044 + cmp %_ASM_DX,%_ASM_AX
31045 + jae 1234f
31046 + add %_ASM_DX,%_ASM_AX
31047 +1234:
31048 +#endif
31049 +
31050 +#endif
31051 +
31052 +1: __copyuser_seg movzbl (%_ASM_AX),%edx
31053 xor %eax,%eax
31054 ASM_CLAC
31055 + pax_force_retaddr
31056 ret
31057 CFI_ENDPROC
31058 ENDPROC(__get_user_1)
31059 @@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
31060 ENTRY(__get_user_2)
31061 CFI_STARTPROC
31062 add $1,%_ASM_AX
31063 +
31064 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
31065 jc bad_get_user
31066 GET_THREAD_INFO(%_ASM_DX)
31067 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
31068 jae bad_get_user
31069 ASM_STAC
31070 -2: movzwl -1(%_ASM_AX),%edx
31071 +
31072 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31073 + mov pax_user_shadow_base,%_ASM_DX
31074 + cmp %_ASM_DX,%_ASM_AX
31075 + jae 1234f
31076 + add %_ASM_DX,%_ASM_AX
31077 +1234:
31078 +#endif
31079 +
31080 +#endif
31081 +
31082 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
31083 xor %eax,%eax
31084 ASM_CLAC
31085 + pax_force_retaddr
31086 ret
31087 CFI_ENDPROC
31088 ENDPROC(__get_user_2)
31089 @@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
31090 ENTRY(__get_user_4)
31091 CFI_STARTPROC
31092 add $3,%_ASM_AX
31093 +
31094 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
31095 jc bad_get_user
31096 GET_THREAD_INFO(%_ASM_DX)
31097 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
31098 jae bad_get_user
31099 ASM_STAC
31100 -3: movl -3(%_ASM_AX),%edx
31101 +
31102 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31103 + mov pax_user_shadow_base,%_ASM_DX
31104 + cmp %_ASM_DX,%_ASM_AX
31105 + jae 1234f
31106 + add %_ASM_DX,%_ASM_AX
31107 +1234:
31108 +#endif
31109 +
31110 +#endif
31111 +
31112 +3: __copyuser_seg movl -3(%_ASM_AX),%edx
31113 xor %eax,%eax
31114 ASM_CLAC
31115 + pax_force_retaddr
31116 ret
31117 CFI_ENDPROC
31118 ENDPROC(__get_user_4)
31119 @@ -86,10 +137,20 @@ ENTRY(__get_user_8)
31120 GET_THREAD_INFO(%_ASM_DX)
31121 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
31122 jae bad_get_user
31123 +
31124 +#ifdef CONFIG_PAX_MEMORY_UDEREF
31125 + mov pax_user_shadow_base,%_ASM_DX
31126 + cmp %_ASM_DX,%_ASM_AX
31127 + jae 1234f
31128 + add %_ASM_DX,%_ASM_AX
31129 +1234:
31130 +#endif
31131 +
31132 ASM_STAC
31133 4: movq -7(%_ASM_AX),%rdx
31134 xor %eax,%eax
31135 ASM_CLAC
31136 + pax_force_retaddr
31137 ret
31138 #else
31139 add $7,%_ASM_AX
31140 @@ -98,10 +159,11 @@ ENTRY(__get_user_8)
31141 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
31142 jae bad_get_user_8
31143 ASM_STAC
31144 -4: movl -7(%_ASM_AX),%edx
31145 -5: movl -3(%_ASM_AX),%ecx
31146 +4: __copyuser_seg movl -7(%_ASM_AX),%edx
31147 +5: __copyuser_seg movl -3(%_ASM_AX),%ecx
31148 xor %eax,%eax
31149 ASM_CLAC
31150 + pax_force_retaddr
31151 ret
31152 #endif
31153 CFI_ENDPROC
31154 @@ -113,6 +175,7 @@ bad_get_user:
31155 xor %edx,%edx
31156 mov $(-EFAULT),%_ASM_AX
31157 ASM_CLAC
31158 + pax_force_retaddr
31159 ret
31160 CFI_ENDPROC
31161 END(bad_get_user)
31162 @@ -124,6 +187,7 @@ bad_get_user_8:
31163 xor %ecx,%ecx
31164 mov $(-EFAULT),%_ASM_AX
31165 ASM_CLAC
31166 + pax_force_retaddr
31167 ret
31168 CFI_ENDPROC
31169 END(bad_get_user_8)
31170 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
31171 index 54fcffe..7be149e 100644
31172 --- a/arch/x86/lib/insn.c
31173 +++ b/arch/x86/lib/insn.c
31174 @@ -20,8 +20,10 @@
31175
31176 #ifdef __KERNEL__
31177 #include <linux/string.h>
31178 +#include <asm/pgtable_types.h>
31179 #else
31180 #include <string.h>
31181 +#define ktla_ktva(addr) addr
31182 #endif
31183 #include <asm/inat.h>
31184 #include <asm/insn.h>
31185 @@ -53,8 +55,8 @@
31186 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
31187 {
31188 memset(insn, 0, sizeof(*insn));
31189 - insn->kaddr = kaddr;
31190 - insn->next_byte = kaddr;
31191 + insn->kaddr = ktla_ktva(kaddr);
31192 + insn->next_byte = ktla_ktva(kaddr);
31193 insn->x86_64 = x86_64 ? 1 : 0;
31194 insn->opnd_bytes = 4;
31195 if (x86_64)
31196 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
31197 index 05a95e7..326f2fa 100644
31198 --- a/arch/x86/lib/iomap_copy_64.S
31199 +++ b/arch/x86/lib/iomap_copy_64.S
31200 @@ -17,6 +17,7 @@
31201
31202 #include <linux/linkage.h>
31203 #include <asm/dwarf2.h>
31204 +#include <asm/alternative-asm.h>
31205
31206 /*
31207 * override generic version in lib/iomap_copy.c
31208 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
31209 CFI_STARTPROC
31210 movl %edx,%ecx
31211 rep movsd
31212 + pax_force_retaddr
31213 ret
31214 CFI_ENDPROC
31215 ENDPROC(__iowrite32_copy)
31216 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
31217 index 56313a3..0db417e 100644
31218 --- a/arch/x86/lib/memcpy_64.S
31219 +++ b/arch/x86/lib/memcpy_64.S
31220 @@ -24,7 +24,7 @@
31221 * This gets patched over the unrolled variant (below) via the
31222 * alternative instructions framework:
31223 */
31224 - .section .altinstr_replacement, "ax", @progbits
31225 + .section .altinstr_replacement, "a", @progbits
31226 .Lmemcpy_c:
31227 movq %rdi, %rax
31228 movq %rdx, %rcx
31229 @@ -33,6 +33,7 @@
31230 rep movsq
31231 movl %edx, %ecx
31232 rep movsb
31233 + pax_force_retaddr
31234 ret
31235 .Lmemcpy_e:
31236 .previous
31237 @@ -44,11 +45,12 @@
31238 * This gets patched over the unrolled variant (below) via the
31239 * alternative instructions framework:
31240 */
31241 - .section .altinstr_replacement, "ax", @progbits
31242 + .section .altinstr_replacement, "a", @progbits
31243 .Lmemcpy_c_e:
31244 movq %rdi, %rax
31245 movq %rdx, %rcx
31246 rep movsb
31247 + pax_force_retaddr
31248 ret
31249 .Lmemcpy_e_e:
31250 .previous
31251 @@ -136,6 +138,7 @@ ENTRY(memcpy)
31252 movq %r9, 1*8(%rdi)
31253 movq %r10, -2*8(%rdi, %rdx)
31254 movq %r11, -1*8(%rdi, %rdx)
31255 + pax_force_retaddr
31256 retq
31257 .p2align 4
31258 .Lless_16bytes:
31259 @@ -148,6 +151,7 @@ ENTRY(memcpy)
31260 movq -1*8(%rsi, %rdx), %r9
31261 movq %r8, 0*8(%rdi)
31262 movq %r9, -1*8(%rdi, %rdx)
31263 + pax_force_retaddr
31264 retq
31265 .p2align 4
31266 .Lless_8bytes:
31267 @@ -161,6 +165,7 @@ ENTRY(memcpy)
31268 movl -4(%rsi, %rdx), %r8d
31269 movl %ecx, (%rdi)
31270 movl %r8d, -4(%rdi, %rdx)
31271 + pax_force_retaddr
31272 retq
31273 .p2align 4
31274 .Lless_3bytes:
31275 @@ -179,6 +184,7 @@ ENTRY(memcpy)
31276 movb %cl, (%rdi)
31277
31278 .Lend:
31279 + pax_force_retaddr
31280 retq
31281 CFI_ENDPROC
31282 ENDPROC(memcpy)
31283 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
31284 index 65268a6..dd1de11 100644
31285 --- a/arch/x86/lib/memmove_64.S
31286 +++ b/arch/x86/lib/memmove_64.S
31287 @@ -202,14 +202,16 @@ ENTRY(memmove)
31288 movb (%rsi), %r11b
31289 movb %r11b, (%rdi)
31290 13:
31291 + pax_force_retaddr
31292 retq
31293 CFI_ENDPROC
31294
31295 - .section .altinstr_replacement,"ax"
31296 + .section .altinstr_replacement,"a"
31297 .Lmemmove_begin_forward_efs:
31298 /* Forward moving data. */
31299 movq %rdx, %rcx
31300 rep movsb
31301 + pax_force_retaddr
31302 retq
31303 .Lmemmove_end_forward_efs:
31304 .previous
31305 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
31306 index 2dcb380..2eb79fe 100644
31307 --- a/arch/x86/lib/memset_64.S
31308 +++ b/arch/x86/lib/memset_64.S
31309 @@ -16,7 +16,7 @@
31310 *
31311 * rax original destination
31312 */
31313 - .section .altinstr_replacement, "ax", @progbits
31314 + .section .altinstr_replacement, "a", @progbits
31315 .Lmemset_c:
31316 movq %rdi,%r9
31317 movq %rdx,%rcx
31318 @@ -30,6 +30,7 @@
31319 movl %edx,%ecx
31320 rep stosb
31321 movq %r9,%rax
31322 + pax_force_retaddr
31323 ret
31324 .Lmemset_e:
31325 .previous
31326 @@ -45,13 +46,14 @@
31327 *
31328 * rax original destination
31329 */
31330 - .section .altinstr_replacement, "ax", @progbits
31331 + .section .altinstr_replacement, "a", @progbits
31332 .Lmemset_c_e:
31333 movq %rdi,%r9
31334 movb %sil,%al
31335 movq %rdx,%rcx
31336 rep stosb
31337 movq %r9,%rax
31338 + pax_force_retaddr
31339 ret
31340 .Lmemset_e_e:
31341 .previous
31342 @@ -118,6 +120,7 @@ ENTRY(__memset)
31343
31344 .Lende:
31345 movq %r10,%rax
31346 + pax_force_retaddr
31347 ret
31348
31349 CFI_RESTORE_STATE
31350 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
31351 index c9f2d9b..e7fd2c0 100644
31352 --- a/arch/x86/lib/mmx_32.c
31353 +++ b/arch/x86/lib/mmx_32.c
31354 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
31355 {
31356 void *p;
31357 int i;
31358 + unsigned long cr0;
31359
31360 if (unlikely(in_interrupt()))
31361 return __memcpy(to, from, len);
31362 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
31363 kernel_fpu_begin();
31364
31365 __asm__ __volatile__ (
31366 - "1: prefetch (%0)\n" /* This set is 28 bytes */
31367 - " prefetch 64(%0)\n"
31368 - " prefetch 128(%0)\n"
31369 - " prefetch 192(%0)\n"
31370 - " prefetch 256(%0)\n"
31371 + "1: prefetch (%1)\n" /* This set is 28 bytes */
31372 + " prefetch 64(%1)\n"
31373 + " prefetch 128(%1)\n"
31374 + " prefetch 192(%1)\n"
31375 + " prefetch 256(%1)\n"
31376 "2: \n"
31377 ".section .fixup, \"ax\"\n"
31378 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
31379 + "3: \n"
31380 +
31381 +#ifdef CONFIG_PAX_KERNEXEC
31382 + " movl %%cr0, %0\n"
31383 + " movl %0, %%eax\n"
31384 + " andl $0xFFFEFFFF, %%eax\n"
31385 + " movl %%eax, %%cr0\n"
31386 +#endif
31387 +
31388 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
31389 +
31390 +#ifdef CONFIG_PAX_KERNEXEC
31391 + " movl %0, %%cr0\n"
31392 +#endif
31393 +
31394 " jmp 2b\n"
31395 ".previous\n"
31396 _ASM_EXTABLE(1b, 3b)
31397 - : : "r" (from));
31398 + : "=&r" (cr0) : "r" (from) : "ax");
31399
31400 for ( ; i > 5; i--) {
31401 __asm__ __volatile__ (
31402 - "1: prefetch 320(%0)\n"
31403 - "2: movq (%0), %%mm0\n"
31404 - " movq 8(%0), %%mm1\n"
31405 - " movq 16(%0), %%mm2\n"
31406 - " movq 24(%0), %%mm3\n"
31407 - " movq %%mm0, (%1)\n"
31408 - " movq %%mm1, 8(%1)\n"
31409 - " movq %%mm2, 16(%1)\n"
31410 - " movq %%mm3, 24(%1)\n"
31411 - " movq 32(%0), %%mm0\n"
31412 - " movq 40(%0), %%mm1\n"
31413 - " movq 48(%0), %%mm2\n"
31414 - " movq 56(%0), %%mm3\n"
31415 - " movq %%mm0, 32(%1)\n"
31416 - " movq %%mm1, 40(%1)\n"
31417 - " movq %%mm2, 48(%1)\n"
31418 - " movq %%mm3, 56(%1)\n"
31419 + "1: prefetch 320(%1)\n"
31420 + "2: movq (%1), %%mm0\n"
31421 + " movq 8(%1), %%mm1\n"
31422 + " movq 16(%1), %%mm2\n"
31423 + " movq 24(%1), %%mm3\n"
31424 + " movq %%mm0, (%2)\n"
31425 + " movq %%mm1, 8(%2)\n"
31426 + " movq %%mm2, 16(%2)\n"
31427 + " movq %%mm3, 24(%2)\n"
31428 + " movq 32(%1), %%mm0\n"
31429 + " movq 40(%1), %%mm1\n"
31430 + " movq 48(%1), %%mm2\n"
31431 + " movq 56(%1), %%mm3\n"
31432 + " movq %%mm0, 32(%2)\n"
31433 + " movq %%mm1, 40(%2)\n"
31434 + " movq %%mm2, 48(%2)\n"
31435 + " movq %%mm3, 56(%2)\n"
31436 ".section .fixup, \"ax\"\n"
31437 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
31438 + "3:\n"
31439 +
31440 +#ifdef CONFIG_PAX_KERNEXEC
31441 + " movl %%cr0, %0\n"
31442 + " movl %0, %%eax\n"
31443 + " andl $0xFFFEFFFF, %%eax\n"
31444 + " movl %%eax, %%cr0\n"
31445 +#endif
31446 +
31447 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
31448 +
31449 +#ifdef CONFIG_PAX_KERNEXEC
31450 + " movl %0, %%cr0\n"
31451 +#endif
31452 +
31453 " jmp 2b\n"
31454 ".previous\n"
31455 _ASM_EXTABLE(1b, 3b)
31456 - : : "r" (from), "r" (to) : "memory");
31457 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
31458
31459 from += 64;
31460 to += 64;
31461 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
31462 static void fast_copy_page(void *to, void *from)
31463 {
31464 int i;
31465 + unsigned long cr0;
31466
31467 kernel_fpu_begin();
31468
31469 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
31470 * but that is for later. -AV
31471 */
31472 __asm__ __volatile__(
31473 - "1: prefetch (%0)\n"
31474 - " prefetch 64(%0)\n"
31475 - " prefetch 128(%0)\n"
31476 - " prefetch 192(%0)\n"
31477 - " prefetch 256(%0)\n"
31478 + "1: prefetch (%1)\n"
31479 + " prefetch 64(%1)\n"
31480 + " prefetch 128(%1)\n"
31481 + " prefetch 192(%1)\n"
31482 + " prefetch 256(%1)\n"
31483 "2: \n"
31484 ".section .fixup, \"ax\"\n"
31485 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
31486 + "3: \n"
31487 +
31488 +#ifdef CONFIG_PAX_KERNEXEC
31489 + " movl %%cr0, %0\n"
31490 + " movl %0, %%eax\n"
31491 + " andl $0xFFFEFFFF, %%eax\n"
31492 + " movl %%eax, %%cr0\n"
31493 +#endif
31494 +
31495 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
31496 +
31497 +#ifdef CONFIG_PAX_KERNEXEC
31498 + " movl %0, %%cr0\n"
31499 +#endif
31500 +
31501 " jmp 2b\n"
31502 ".previous\n"
31503 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
31504 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
31505
31506 for (i = 0; i < (4096-320)/64; i++) {
31507 __asm__ __volatile__ (
31508 - "1: prefetch 320(%0)\n"
31509 - "2: movq (%0), %%mm0\n"
31510 - " movntq %%mm0, (%1)\n"
31511 - " movq 8(%0), %%mm1\n"
31512 - " movntq %%mm1, 8(%1)\n"
31513 - " movq 16(%0), %%mm2\n"
31514 - " movntq %%mm2, 16(%1)\n"
31515 - " movq 24(%0), %%mm3\n"
31516 - " movntq %%mm3, 24(%1)\n"
31517 - " movq 32(%0), %%mm4\n"
31518 - " movntq %%mm4, 32(%1)\n"
31519 - " movq 40(%0), %%mm5\n"
31520 - " movntq %%mm5, 40(%1)\n"
31521 - " movq 48(%0), %%mm6\n"
31522 - " movntq %%mm6, 48(%1)\n"
31523 - " movq 56(%0), %%mm7\n"
31524 - " movntq %%mm7, 56(%1)\n"
31525 + "1: prefetch 320(%1)\n"
31526 + "2: movq (%1), %%mm0\n"
31527 + " movntq %%mm0, (%2)\n"
31528 + " movq 8(%1), %%mm1\n"
31529 + " movntq %%mm1, 8(%2)\n"
31530 + " movq 16(%1), %%mm2\n"
31531 + " movntq %%mm2, 16(%2)\n"
31532 + " movq 24(%1), %%mm3\n"
31533 + " movntq %%mm3, 24(%2)\n"
31534 + " movq 32(%1), %%mm4\n"
31535 + " movntq %%mm4, 32(%2)\n"
31536 + " movq 40(%1), %%mm5\n"
31537 + " movntq %%mm5, 40(%2)\n"
31538 + " movq 48(%1), %%mm6\n"
31539 + " movntq %%mm6, 48(%2)\n"
31540 + " movq 56(%1), %%mm7\n"
31541 + " movntq %%mm7, 56(%2)\n"
31542 ".section .fixup, \"ax\"\n"
31543 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
31544 + "3:\n"
31545 +
31546 +#ifdef CONFIG_PAX_KERNEXEC
31547 + " movl %%cr0, %0\n"
31548 + " movl %0, %%eax\n"
31549 + " andl $0xFFFEFFFF, %%eax\n"
31550 + " movl %%eax, %%cr0\n"
31551 +#endif
31552 +
31553 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
31554 +
31555 +#ifdef CONFIG_PAX_KERNEXEC
31556 + " movl %0, %%cr0\n"
31557 +#endif
31558 +
31559 " jmp 2b\n"
31560 ".previous\n"
31561 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
31562 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
31563
31564 from += 64;
31565 to += 64;
31566 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
31567 static void fast_copy_page(void *to, void *from)
31568 {
31569 int i;
31570 + unsigned long cr0;
31571
31572 kernel_fpu_begin();
31573
31574 __asm__ __volatile__ (
31575 - "1: prefetch (%0)\n"
31576 - " prefetch 64(%0)\n"
31577 - " prefetch 128(%0)\n"
31578 - " prefetch 192(%0)\n"
31579 - " prefetch 256(%0)\n"
31580 + "1: prefetch (%1)\n"
31581 + " prefetch 64(%1)\n"
31582 + " prefetch 128(%1)\n"
31583 + " prefetch 192(%1)\n"
31584 + " prefetch 256(%1)\n"
31585 "2: \n"
31586 ".section .fixup, \"ax\"\n"
31587 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
31588 + "3: \n"
31589 +
31590 +#ifdef CONFIG_PAX_KERNEXEC
31591 + " movl %%cr0, %0\n"
31592 + " movl %0, %%eax\n"
31593 + " andl $0xFFFEFFFF, %%eax\n"
31594 + " movl %%eax, %%cr0\n"
31595 +#endif
31596 +
31597 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
31598 +
31599 +#ifdef CONFIG_PAX_KERNEXEC
31600 + " movl %0, %%cr0\n"
31601 +#endif
31602 +
31603 " jmp 2b\n"
31604 ".previous\n"
31605 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
31606 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
31607
31608 for (i = 0; i < 4096/64; i++) {
31609 __asm__ __volatile__ (
31610 - "1: prefetch 320(%0)\n"
31611 - "2: movq (%0), %%mm0\n"
31612 - " movq 8(%0), %%mm1\n"
31613 - " movq 16(%0), %%mm2\n"
31614 - " movq 24(%0), %%mm3\n"
31615 - " movq %%mm0, (%1)\n"
31616 - " movq %%mm1, 8(%1)\n"
31617 - " movq %%mm2, 16(%1)\n"
31618 - " movq %%mm3, 24(%1)\n"
31619 - " movq 32(%0), %%mm0\n"
31620 - " movq 40(%0), %%mm1\n"
31621 - " movq 48(%0), %%mm2\n"
31622 - " movq 56(%0), %%mm3\n"
31623 - " movq %%mm0, 32(%1)\n"
31624 - " movq %%mm1, 40(%1)\n"
31625 - " movq %%mm2, 48(%1)\n"
31626 - " movq %%mm3, 56(%1)\n"
31627 + "1: prefetch 320(%1)\n"
31628 + "2: movq (%1), %%mm0\n"
31629 + " movq 8(%1), %%mm1\n"
31630 + " movq 16(%1), %%mm2\n"
31631 + " movq 24(%1), %%mm3\n"
31632 + " movq %%mm0, (%2)\n"
31633 + " movq %%mm1, 8(%2)\n"
31634 + " movq %%mm2, 16(%2)\n"
31635 + " movq %%mm3, 24(%2)\n"
31636 + " movq 32(%1), %%mm0\n"
31637 + " movq 40(%1), %%mm1\n"
31638 + " movq 48(%1), %%mm2\n"
31639 + " movq 56(%1), %%mm3\n"
31640 + " movq %%mm0, 32(%2)\n"
31641 + " movq %%mm1, 40(%2)\n"
31642 + " movq %%mm2, 48(%2)\n"
31643 + " movq %%mm3, 56(%2)\n"
31644 ".section .fixup, \"ax\"\n"
31645 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
31646 + "3:\n"
31647 +
31648 +#ifdef CONFIG_PAX_KERNEXEC
31649 + " movl %%cr0, %0\n"
31650 + " movl %0, %%eax\n"
31651 + " andl $0xFFFEFFFF, %%eax\n"
31652 + " movl %%eax, %%cr0\n"
31653 +#endif
31654 +
31655 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
31656 +
31657 +#ifdef CONFIG_PAX_KERNEXEC
31658 + " movl %0, %%cr0\n"
31659 +#endif
31660 +
31661 " jmp 2b\n"
31662 ".previous\n"
31663 _ASM_EXTABLE(1b, 3b)
31664 - : : "r" (from), "r" (to) : "memory");
31665 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
31666
31667 from += 64;
31668 to += 64;
31669 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
31670 index f6d13ee..d789440 100644
31671 --- a/arch/x86/lib/msr-reg.S
31672 +++ b/arch/x86/lib/msr-reg.S
31673 @@ -3,6 +3,7 @@
31674 #include <asm/dwarf2.h>
31675 #include <asm/asm.h>
31676 #include <asm/msr.h>
31677 +#include <asm/alternative-asm.h>
31678
31679 #ifdef CONFIG_X86_64
31680 /*
31681 @@ -37,6 +38,7 @@ ENTRY(\op\()_safe_regs)
31682 movl %edi, 28(%r10)
31683 popq_cfi %rbp
31684 popq_cfi %rbx
31685 + pax_force_retaddr
31686 ret
31687 3:
31688 CFI_RESTORE_STATE
31689 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
31690 index fc6ba17..d4d989d 100644
31691 --- a/arch/x86/lib/putuser.S
31692 +++ b/arch/x86/lib/putuser.S
31693 @@ -16,7 +16,9 @@
31694 #include <asm/errno.h>
31695 #include <asm/asm.h>
31696 #include <asm/smap.h>
31697 -
31698 +#include <asm/segment.h>
31699 +#include <asm/pgtable.h>
31700 +#include <asm/alternative-asm.h>
31701
31702 /*
31703 * __put_user_X
31704 @@ -30,57 +32,125 @@
31705 * as they get called from within inline assembly.
31706 */
31707
31708 -#define ENTER CFI_STARTPROC ; \
31709 - GET_THREAD_INFO(%_ASM_BX)
31710 -#define EXIT ASM_CLAC ; \
31711 - ret ; \
31712 +#define ENTER CFI_STARTPROC
31713 +#define EXIT ASM_CLAC ; \
31714 + pax_force_retaddr ; \
31715 + ret ; \
31716 CFI_ENDPROC
31717
31718 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31719 +#define _DEST %_ASM_CX,%_ASM_BX
31720 +#else
31721 +#define _DEST %_ASM_CX
31722 +#endif
31723 +
31724 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
31725 +#define __copyuser_seg gs;
31726 +#else
31727 +#define __copyuser_seg
31728 +#endif
31729 +
31730 .text
31731 ENTRY(__put_user_1)
31732 ENTER
31733 +
31734 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
31735 + GET_THREAD_INFO(%_ASM_BX)
31736 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
31737 jae bad_put_user
31738 ASM_STAC
31739 -1: movb %al,(%_ASM_CX)
31740 +
31741 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31742 + mov pax_user_shadow_base,%_ASM_BX
31743 + cmp %_ASM_BX,%_ASM_CX
31744 + jb 1234f
31745 + xor %ebx,%ebx
31746 +1234:
31747 +#endif
31748 +
31749 +#endif
31750 +
31751 +1: __copyuser_seg movb %al,(_DEST)
31752 xor %eax,%eax
31753 EXIT
31754 ENDPROC(__put_user_1)
31755
31756 ENTRY(__put_user_2)
31757 ENTER
31758 +
31759 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
31760 + GET_THREAD_INFO(%_ASM_BX)
31761 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
31762 sub $1,%_ASM_BX
31763 cmp %_ASM_BX,%_ASM_CX
31764 jae bad_put_user
31765 ASM_STAC
31766 -2: movw %ax,(%_ASM_CX)
31767 +
31768 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31769 + mov pax_user_shadow_base,%_ASM_BX
31770 + cmp %_ASM_BX,%_ASM_CX
31771 + jb 1234f
31772 + xor %ebx,%ebx
31773 +1234:
31774 +#endif
31775 +
31776 +#endif
31777 +
31778 +2: __copyuser_seg movw %ax,(_DEST)
31779 xor %eax,%eax
31780 EXIT
31781 ENDPROC(__put_user_2)
31782
31783 ENTRY(__put_user_4)
31784 ENTER
31785 +
31786 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
31787 + GET_THREAD_INFO(%_ASM_BX)
31788 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
31789 sub $3,%_ASM_BX
31790 cmp %_ASM_BX,%_ASM_CX
31791 jae bad_put_user
31792 ASM_STAC
31793 -3: movl %eax,(%_ASM_CX)
31794 +
31795 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31796 + mov pax_user_shadow_base,%_ASM_BX
31797 + cmp %_ASM_BX,%_ASM_CX
31798 + jb 1234f
31799 + xor %ebx,%ebx
31800 +1234:
31801 +#endif
31802 +
31803 +#endif
31804 +
31805 +3: __copyuser_seg movl %eax,(_DEST)
31806 xor %eax,%eax
31807 EXIT
31808 ENDPROC(__put_user_4)
31809
31810 ENTRY(__put_user_8)
31811 ENTER
31812 +
31813 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
31814 + GET_THREAD_INFO(%_ASM_BX)
31815 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
31816 sub $7,%_ASM_BX
31817 cmp %_ASM_BX,%_ASM_CX
31818 jae bad_put_user
31819 ASM_STAC
31820 -4: mov %_ASM_AX,(%_ASM_CX)
31821 +
31822 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31823 + mov pax_user_shadow_base,%_ASM_BX
31824 + cmp %_ASM_BX,%_ASM_CX
31825 + jb 1234f
31826 + xor %ebx,%ebx
31827 +1234:
31828 +#endif
31829 +
31830 +#endif
31831 +
31832 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
31833 #ifdef CONFIG_X86_32
31834 -5: movl %edx,4(%_ASM_CX)
31835 +5: __copyuser_seg movl %edx,4(_DEST)
31836 #endif
31837 xor %eax,%eax
31838 EXIT
31839 diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
31840 index 1cad221..de671ee 100644
31841 --- a/arch/x86/lib/rwlock.S
31842 +++ b/arch/x86/lib/rwlock.S
31843 @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
31844 FRAME
31845 0: LOCK_PREFIX
31846 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
31847 +
31848 +#ifdef CONFIG_PAX_REFCOUNT
31849 + jno 1234f
31850 + LOCK_PREFIX
31851 + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
31852 + int $4
31853 +1234:
31854 + _ASM_EXTABLE(1234b, 1234b)
31855 +#endif
31856 +
31857 1: rep; nop
31858 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
31859 jne 1b
31860 LOCK_PREFIX
31861 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
31862 +
31863 +#ifdef CONFIG_PAX_REFCOUNT
31864 + jno 1234f
31865 + LOCK_PREFIX
31866 + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
31867 + int $4
31868 +1234:
31869 + _ASM_EXTABLE(1234b, 1234b)
31870 +#endif
31871 +
31872 jnz 0b
31873 ENDFRAME
31874 + pax_force_retaddr
31875 ret
31876 CFI_ENDPROC
31877 END(__write_lock_failed)
31878 @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
31879 FRAME
31880 0: LOCK_PREFIX
31881 READ_LOCK_SIZE(inc) (%__lock_ptr)
31882 +
31883 +#ifdef CONFIG_PAX_REFCOUNT
31884 + jno 1234f
31885 + LOCK_PREFIX
31886 + READ_LOCK_SIZE(dec) (%__lock_ptr)
31887 + int $4
31888 +1234:
31889 + _ASM_EXTABLE(1234b, 1234b)
31890 +#endif
31891 +
31892 1: rep; nop
31893 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
31894 js 1b
31895 LOCK_PREFIX
31896 READ_LOCK_SIZE(dec) (%__lock_ptr)
31897 +
31898 +#ifdef CONFIG_PAX_REFCOUNT
31899 + jno 1234f
31900 + LOCK_PREFIX
31901 + READ_LOCK_SIZE(inc) (%__lock_ptr)
31902 + int $4
31903 +1234:
31904 + _ASM_EXTABLE(1234b, 1234b)
31905 +#endif
31906 +
31907 js 0b
31908 ENDFRAME
31909 + pax_force_retaddr
31910 ret
31911 CFI_ENDPROC
31912 END(__read_lock_failed)
31913 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
31914 index 5dff5f0..cadebf4 100644
31915 --- a/arch/x86/lib/rwsem.S
31916 +++ b/arch/x86/lib/rwsem.S
31917 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
31918 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
31919 CFI_RESTORE __ASM_REG(dx)
31920 restore_common_regs
31921 + pax_force_retaddr
31922 ret
31923 CFI_ENDPROC
31924 ENDPROC(call_rwsem_down_read_failed)
31925 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
31926 movq %rax,%rdi
31927 call rwsem_down_write_failed
31928 restore_common_regs
31929 + pax_force_retaddr
31930 ret
31931 CFI_ENDPROC
31932 ENDPROC(call_rwsem_down_write_failed)
31933 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
31934 movq %rax,%rdi
31935 call rwsem_wake
31936 restore_common_regs
31937 -1: ret
31938 +1: pax_force_retaddr
31939 + ret
31940 CFI_ENDPROC
31941 ENDPROC(call_rwsem_wake)
31942
31943 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
31944 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
31945 CFI_RESTORE __ASM_REG(dx)
31946 restore_common_regs
31947 + pax_force_retaddr
31948 ret
31949 CFI_ENDPROC
31950 ENDPROC(call_rwsem_downgrade_wake)
31951 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
31952 index 92d9fea..b2762c8 100644
31953 --- a/arch/x86/lib/thunk_64.S
31954 +++ b/arch/x86/lib/thunk_64.S
31955 @@ -9,6 +9,7 @@
31956 #include <asm/dwarf2.h>
31957 #include <asm/calling.h>
31958 #include <asm/asm.h>
31959 +#include <asm/alternative-asm.h>
31960
31961 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
31962 .macro THUNK name, func, put_ret_addr_in_rdi=0
31963 @@ -16,11 +17,11 @@
31964 \name:
31965 CFI_STARTPROC
31966
31967 - /* this one pushes 9 elems, the next one would be %rIP */
31968 - SAVE_ARGS
31969 + /* this one pushes 15+1 elems, the next one would be %rIP */
31970 + SAVE_ARGS 8
31971
31972 .if \put_ret_addr_in_rdi
31973 - movq_cfi_restore 9*8, rdi
31974 + movq_cfi_restore RIP, rdi
31975 .endif
31976
31977 call \func
31978 @@ -40,9 +41,10 @@
31979
31980 /* SAVE_ARGS below is used only for the .cfi directives it contains. */
31981 CFI_STARTPROC
31982 - SAVE_ARGS
31983 + SAVE_ARGS 8
31984 restore:
31985 - RESTORE_ARGS
31986 + RESTORE_ARGS 1,8
31987 + pax_force_retaddr
31988 ret
31989 CFI_ENDPROC
31990 _ASM_NOKPROBE(restore)
31991 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
31992 index e2f5e21..4b22130 100644
31993 --- a/arch/x86/lib/usercopy_32.c
31994 +++ b/arch/x86/lib/usercopy_32.c
31995 @@ -42,11 +42,13 @@ do { \
31996 int __d0; \
31997 might_fault(); \
31998 __asm__ __volatile__( \
31999 + __COPYUSER_SET_ES \
32000 ASM_STAC "\n" \
32001 "0: rep; stosl\n" \
32002 " movl %2,%0\n" \
32003 "1: rep; stosb\n" \
32004 "2: " ASM_CLAC "\n" \
32005 + __COPYUSER_RESTORE_ES \
32006 ".section .fixup,\"ax\"\n" \
32007 "3: lea 0(%2,%0,4),%0\n" \
32008 " jmp 2b\n" \
32009 @@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
32010
32011 #ifdef CONFIG_X86_INTEL_USERCOPY
32012 static unsigned long
32013 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
32014 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
32015 {
32016 int d0, d1;
32017 __asm__ __volatile__(
32018 @@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
32019 " .align 2,0x90\n"
32020 "3: movl 0(%4), %%eax\n"
32021 "4: movl 4(%4), %%edx\n"
32022 - "5: movl %%eax, 0(%3)\n"
32023 - "6: movl %%edx, 4(%3)\n"
32024 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
32025 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
32026 "7: movl 8(%4), %%eax\n"
32027 "8: movl 12(%4),%%edx\n"
32028 - "9: movl %%eax, 8(%3)\n"
32029 - "10: movl %%edx, 12(%3)\n"
32030 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
32031 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
32032 "11: movl 16(%4), %%eax\n"
32033 "12: movl 20(%4), %%edx\n"
32034 - "13: movl %%eax, 16(%3)\n"
32035 - "14: movl %%edx, 20(%3)\n"
32036 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
32037 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
32038 "15: movl 24(%4), %%eax\n"
32039 "16: movl 28(%4), %%edx\n"
32040 - "17: movl %%eax, 24(%3)\n"
32041 - "18: movl %%edx, 28(%3)\n"
32042 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
32043 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
32044 "19: movl 32(%4), %%eax\n"
32045 "20: movl 36(%4), %%edx\n"
32046 - "21: movl %%eax, 32(%3)\n"
32047 - "22: movl %%edx, 36(%3)\n"
32048 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
32049 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
32050 "23: movl 40(%4), %%eax\n"
32051 "24: movl 44(%4), %%edx\n"
32052 - "25: movl %%eax, 40(%3)\n"
32053 - "26: movl %%edx, 44(%3)\n"
32054 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
32055 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
32056 "27: movl 48(%4), %%eax\n"
32057 "28: movl 52(%4), %%edx\n"
32058 - "29: movl %%eax, 48(%3)\n"
32059 - "30: movl %%edx, 52(%3)\n"
32060 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
32061 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
32062 "31: movl 56(%4), %%eax\n"
32063 "32: movl 60(%4), %%edx\n"
32064 - "33: movl %%eax, 56(%3)\n"
32065 - "34: movl %%edx, 60(%3)\n"
32066 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
32067 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
32068 " addl $-64, %0\n"
32069 " addl $64, %4\n"
32070 " addl $64, %3\n"
32071 @@ -149,10 +151,116 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
32072 " shrl $2, %0\n"
32073 " andl $3, %%eax\n"
32074 " cld\n"
32075 + __COPYUSER_SET_ES
32076 "99: rep; movsl\n"
32077 "36: movl %%eax, %0\n"
32078 "37: rep; movsb\n"
32079 "100:\n"
32080 + __COPYUSER_RESTORE_ES
32081 + ".section .fixup,\"ax\"\n"
32082 + "101: lea 0(%%eax,%0,4),%0\n"
32083 + " jmp 100b\n"
32084 + ".previous\n"
32085 + _ASM_EXTABLE(1b,100b)
32086 + _ASM_EXTABLE(2b,100b)
32087 + _ASM_EXTABLE(3b,100b)
32088 + _ASM_EXTABLE(4b,100b)
32089 + _ASM_EXTABLE(5b,100b)
32090 + _ASM_EXTABLE(6b,100b)
32091 + _ASM_EXTABLE(7b,100b)
32092 + _ASM_EXTABLE(8b,100b)
32093 + _ASM_EXTABLE(9b,100b)
32094 + _ASM_EXTABLE(10b,100b)
32095 + _ASM_EXTABLE(11b,100b)
32096 + _ASM_EXTABLE(12b,100b)
32097 + _ASM_EXTABLE(13b,100b)
32098 + _ASM_EXTABLE(14b,100b)
32099 + _ASM_EXTABLE(15b,100b)
32100 + _ASM_EXTABLE(16b,100b)
32101 + _ASM_EXTABLE(17b,100b)
32102 + _ASM_EXTABLE(18b,100b)
32103 + _ASM_EXTABLE(19b,100b)
32104 + _ASM_EXTABLE(20b,100b)
32105 + _ASM_EXTABLE(21b,100b)
32106 + _ASM_EXTABLE(22b,100b)
32107 + _ASM_EXTABLE(23b,100b)
32108 + _ASM_EXTABLE(24b,100b)
32109 + _ASM_EXTABLE(25b,100b)
32110 + _ASM_EXTABLE(26b,100b)
32111 + _ASM_EXTABLE(27b,100b)
32112 + _ASM_EXTABLE(28b,100b)
32113 + _ASM_EXTABLE(29b,100b)
32114 + _ASM_EXTABLE(30b,100b)
32115 + _ASM_EXTABLE(31b,100b)
32116 + _ASM_EXTABLE(32b,100b)
32117 + _ASM_EXTABLE(33b,100b)
32118 + _ASM_EXTABLE(34b,100b)
32119 + _ASM_EXTABLE(35b,100b)
32120 + _ASM_EXTABLE(36b,100b)
32121 + _ASM_EXTABLE(37b,100b)
32122 + _ASM_EXTABLE(99b,101b)
32123 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
32124 + : "1"(to), "2"(from), "0"(size)
32125 + : "eax", "edx", "memory");
32126 + return size;
32127 +}
32128 +
32129 +static unsigned long
32130 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
32131 +{
32132 + int d0, d1;
32133 + __asm__ __volatile__(
32134 + " .align 2,0x90\n"
32135 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
32136 + " cmpl $67, %0\n"
32137 + " jbe 3f\n"
32138 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
32139 + " .align 2,0x90\n"
32140 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
32141 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
32142 + "5: movl %%eax, 0(%3)\n"
32143 + "6: movl %%edx, 4(%3)\n"
32144 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
32145 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
32146 + "9: movl %%eax, 8(%3)\n"
32147 + "10: movl %%edx, 12(%3)\n"
32148 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
32149 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
32150 + "13: movl %%eax, 16(%3)\n"
32151 + "14: movl %%edx, 20(%3)\n"
32152 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
32153 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
32154 + "17: movl %%eax, 24(%3)\n"
32155 + "18: movl %%edx, 28(%3)\n"
32156 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
32157 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
32158 + "21: movl %%eax, 32(%3)\n"
32159 + "22: movl %%edx, 36(%3)\n"
32160 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
32161 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
32162 + "25: movl %%eax, 40(%3)\n"
32163 + "26: movl %%edx, 44(%3)\n"
32164 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
32165 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
32166 + "29: movl %%eax, 48(%3)\n"
32167 + "30: movl %%edx, 52(%3)\n"
32168 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
32169 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
32170 + "33: movl %%eax, 56(%3)\n"
32171 + "34: movl %%edx, 60(%3)\n"
32172 + " addl $-64, %0\n"
32173 + " addl $64, %4\n"
32174 + " addl $64, %3\n"
32175 + " cmpl $63, %0\n"
32176 + " ja 1b\n"
32177 + "35: movl %0, %%eax\n"
32178 + " shrl $2, %0\n"
32179 + " andl $3, %%eax\n"
32180 + " cld\n"
32181 + "99: rep; "__copyuser_seg" movsl\n"
32182 + "36: movl %%eax, %0\n"
32183 + "37: rep; "__copyuser_seg" movsb\n"
32184 + "100:\n"
32185 ".section .fixup,\"ax\"\n"
32186 "101: lea 0(%%eax,%0,4),%0\n"
32187 " jmp 100b\n"
32188 @@ -207,41 +315,41 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
32189 int d0, d1;
32190 __asm__ __volatile__(
32191 " .align 2,0x90\n"
32192 - "0: movl 32(%4), %%eax\n"
32193 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
32194 " cmpl $67, %0\n"
32195 " jbe 2f\n"
32196 - "1: movl 64(%4), %%eax\n"
32197 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
32198 " .align 2,0x90\n"
32199 - "2: movl 0(%4), %%eax\n"
32200 - "21: movl 4(%4), %%edx\n"
32201 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
32202 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
32203 " movl %%eax, 0(%3)\n"
32204 " movl %%edx, 4(%3)\n"
32205 - "3: movl 8(%4), %%eax\n"
32206 - "31: movl 12(%4),%%edx\n"
32207 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
32208 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
32209 " movl %%eax, 8(%3)\n"
32210 " movl %%edx, 12(%3)\n"
32211 - "4: movl 16(%4), %%eax\n"
32212 - "41: movl 20(%4), %%edx\n"
32213 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
32214 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
32215 " movl %%eax, 16(%3)\n"
32216 " movl %%edx, 20(%3)\n"
32217 - "10: movl 24(%4), %%eax\n"
32218 - "51: movl 28(%4), %%edx\n"
32219 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
32220 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
32221 " movl %%eax, 24(%3)\n"
32222 " movl %%edx, 28(%3)\n"
32223 - "11: movl 32(%4), %%eax\n"
32224 - "61: movl 36(%4), %%edx\n"
32225 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
32226 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
32227 " movl %%eax, 32(%3)\n"
32228 " movl %%edx, 36(%3)\n"
32229 - "12: movl 40(%4), %%eax\n"
32230 - "71: movl 44(%4), %%edx\n"
32231 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
32232 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
32233 " movl %%eax, 40(%3)\n"
32234 " movl %%edx, 44(%3)\n"
32235 - "13: movl 48(%4), %%eax\n"
32236 - "81: movl 52(%4), %%edx\n"
32237 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
32238 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
32239 " movl %%eax, 48(%3)\n"
32240 " movl %%edx, 52(%3)\n"
32241 - "14: movl 56(%4), %%eax\n"
32242 - "91: movl 60(%4), %%edx\n"
32243 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
32244 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
32245 " movl %%eax, 56(%3)\n"
32246 " movl %%edx, 60(%3)\n"
32247 " addl $-64, %0\n"
32248 @@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
32249 " shrl $2, %0\n"
32250 " andl $3, %%eax\n"
32251 " cld\n"
32252 - "6: rep; movsl\n"
32253 + "6: rep; "__copyuser_seg" movsl\n"
32254 " movl %%eax,%0\n"
32255 - "7: rep; movsb\n"
32256 + "7: rep; "__copyuser_seg" movsb\n"
32257 "8:\n"
32258 ".section .fixup,\"ax\"\n"
32259 "9: lea 0(%%eax,%0,4),%0\n"
32260 @@ -305,41 +413,41 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
32261
32262 __asm__ __volatile__(
32263 " .align 2,0x90\n"
32264 - "0: movl 32(%4), %%eax\n"
32265 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
32266 " cmpl $67, %0\n"
32267 " jbe 2f\n"
32268 - "1: movl 64(%4), %%eax\n"
32269 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
32270 " .align 2,0x90\n"
32271 - "2: movl 0(%4), %%eax\n"
32272 - "21: movl 4(%4), %%edx\n"
32273 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
32274 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
32275 " movnti %%eax, 0(%3)\n"
32276 " movnti %%edx, 4(%3)\n"
32277 - "3: movl 8(%4), %%eax\n"
32278 - "31: movl 12(%4),%%edx\n"
32279 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
32280 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
32281 " movnti %%eax, 8(%3)\n"
32282 " movnti %%edx, 12(%3)\n"
32283 - "4: movl 16(%4), %%eax\n"
32284 - "41: movl 20(%4), %%edx\n"
32285 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
32286 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
32287 " movnti %%eax, 16(%3)\n"
32288 " movnti %%edx, 20(%3)\n"
32289 - "10: movl 24(%4), %%eax\n"
32290 - "51: movl 28(%4), %%edx\n"
32291 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
32292 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
32293 " movnti %%eax, 24(%3)\n"
32294 " movnti %%edx, 28(%3)\n"
32295 - "11: movl 32(%4), %%eax\n"
32296 - "61: movl 36(%4), %%edx\n"
32297 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
32298 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
32299 " movnti %%eax, 32(%3)\n"
32300 " movnti %%edx, 36(%3)\n"
32301 - "12: movl 40(%4), %%eax\n"
32302 - "71: movl 44(%4), %%edx\n"
32303 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
32304 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
32305 " movnti %%eax, 40(%3)\n"
32306 " movnti %%edx, 44(%3)\n"
32307 - "13: movl 48(%4), %%eax\n"
32308 - "81: movl 52(%4), %%edx\n"
32309 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
32310 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
32311 " movnti %%eax, 48(%3)\n"
32312 " movnti %%edx, 52(%3)\n"
32313 - "14: movl 56(%4), %%eax\n"
32314 - "91: movl 60(%4), %%edx\n"
32315 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
32316 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
32317 " movnti %%eax, 56(%3)\n"
32318 " movnti %%edx, 60(%3)\n"
32319 " addl $-64, %0\n"
32320 @@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
32321 " shrl $2, %0\n"
32322 " andl $3, %%eax\n"
32323 " cld\n"
32324 - "6: rep; movsl\n"
32325 + "6: rep; "__copyuser_seg" movsl\n"
32326 " movl %%eax,%0\n"
32327 - "7: rep; movsb\n"
32328 + "7: rep; "__copyuser_seg" movsb\n"
32329 "8:\n"
32330 ".section .fixup,\"ax\"\n"
32331 "9: lea 0(%%eax,%0,4),%0\n"
32332 @@ -399,41 +507,41 @@ static unsigned long __copy_user_intel_nocache(void *to,
32333
32334 __asm__ __volatile__(
32335 " .align 2,0x90\n"
32336 - "0: movl 32(%4), %%eax\n"
32337 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
32338 " cmpl $67, %0\n"
32339 " jbe 2f\n"
32340 - "1: movl 64(%4), %%eax\n"
32341 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
32342 " .align 2,0x90\n"
32343 - "2: movl 0(%4), %%eax\n"
32344 - "21: movl 4(%4), %%edx\n"
32345 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
32346 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
32347 " movnti %%eax, 0(%3)\n"
32348 " movnti %%edx, 4(%3)\n"
32349 - "3: movl 8(%4), %%eax\n"
32350 - "31: movl 12(%4),%%edx\n"
32351 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
32352 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
32353 " movnti %%eax, 8(%3)\n"
32354 " movnti %%edx, 12(%3)\n"
32355 - "4: movl 16(%4), %%eax\n"
32356 - "41: movl 20(%4), %%edx\n"
32357 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
32358 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
32359 " movnti %%eax, 16(%3)\n"
32360 " movnti %%edx, 20(%3)\n"
32361 - "10: movl 24(%4), %%eax\n"
32362 - "51: movl 28(%4), %%edx\n"
32363 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
32364 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
32365 " movnti %%eax, 24(%3)\n"
32366 " movnti %%edx, 28(%3)\n"
32367 - "11: movl 32(%4), %%eax\n"
32368 - "61: movl 36(%4), %%edx\n"
32369 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
32370 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
32371 " movnti %%eax, 32(%3)\n"
32372 " movnti %%edx, 36(%3)\n"
32373 - "12: movl 40(%4), %%eax\n"
32374 - "71: movl 44(%4), %%edx\n"
32375 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
32376 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
32377 " movnti %%eax, 40(%3)\n"
32378 " movnti %%edx, 44(%3)\n"
32379 - "13: movl 48(%4), %%eax\n"
32380 - "81: movl 52(%4), %%edx\n"
32381 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
32382 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
32383 " movnti %%eax, 48(%3)\n"
32384 " movnti %%edx, 52(%3)\n"
32385 - "14: movl 56(%4), %%eax\n"
32386 - "91: movl 60(%4), %%edx\n"
32387 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
32388 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
32389 " movnti %%eax, 56(%3)\n"
32390 " movnti %%edx, 60(%3)\n"
32391 " addl $-64, %0\n"
32392 @@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
32393 " shrl $2, %0\n"
32394 " andl $3, %%eax\n"
32395 " cld\n"
32396 - "6: rep; movsl\n"
32397 + "6: rep; "__copyuser_seg" movsl\n"
32398 " movl %%eax,%0\n"
32399 - "7: rep; movsb\n"
32400 + "7: rep; "__copyuser_seg" movsb\n"
32401 "8:\n"
32402 ".section .fixup,\"ax\"\n"
32403 "9: lea 0(%%eax,%0,4),%0\n"
32404 @@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
32405 */
32406 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
32407 unsigned long size);
32408 -unsigned long __copy_user_intel(void __user *to, const void *from,
32409 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
32410 + unsigned long size);
32411 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
32412 unsigned long size);
32413 unsigned long __copy_user_zeroing_intel_nocache(void *to,
32414 const void __user *from, unsigned long size);
32415 #endif /* CONFIG_X86_INTEL_USERCOPY */
32416
32417 /* Generic arbitrary sized copy. */
32418 -#define __copy_user(to, from, size) \
32419 +#define __copy_user(to, from, size, prefix, set, restore) \
32420 do { \
32421 int __d0, __d1, __d2; \
32422 __asm__ __volatile__( \
32423 + set \
32424 " cmp $7,%0\n" \
32425 " jbe 1f\n" \
32426 " movl %1,%0\n" \
32427 " negl %0\n" \
32428 " andl $7,%0\n" \
32429 " subl %0,%3\n" \
32430 - "4: rep; movsb\n" \
32431 + "4: rep; "prefix"movsb\n" \
32432 " movl %3,%0\n" \
32433 " shrl $2,%0\n" \
32434 " andl $3,%3\n" \
32435 " .align 2,0x90\n" \
32436 - "0: rep; movsl\n" \
32437 + "0: rep; "prefix"movsl\n" \
32438 " movl %3,%0\n" \
32439 - "1: rep; movsb\n" \
32440 + "1: rep; "prefix"movsb\n" \
32441 "2:\n" \
32442 + restore \
32443 ".section .fixup,\"ax\"\n" \
32444 "5: addl %3,%0\n" \
32445 " jmp 2b\n" \
32446 @@ -538,14 +650,14 @@ do { \
32447 " negl %0\n" \
32448 " andl $7,%0\n" \
32449 " subl %0,%3\n" \
32450 - "4: rep; movsb\n" \
32451 + "4: rep; "__copyuser_seg"movsb\n" \
32452 " movl %3,%0\n" \
32453 " shrl $2,%0\n" \
32454 " andl $3,%3\n" \
32455 " .align 2,0x90\n" \
32456 - "0: rep; movsl\n" \
32457 + "0: rep; "__copyuser_seg"movsl\n" \
32458 " movl %3,%0\n" \
32459 - "1: rep; movsb\n" \
32460 + "1: rep; "__copyuser_seg"movsb\n" \
32461 "2:\n" \
32462 ".section .fixup,\"ax\"\n" \
32463 "5: addl %3,%0\n" \
32464 @@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
32465 {
32466 stac();
32467 if (movsl_is_ok(to, from, n))
32468 - __copy_user(to, from, n);
32469 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
32470 else
32471 - n = __copy_user_intel(to, from, n);
32472 + n = __generic_copy_to_user_intel(to, from, n);
32473 clac();
32474 return n;
32475 }
32476 @@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
32477 {
32478 stac();
32479 if (movsl_is_ok(to, from, n))
32480 - __copy_user(to, from, n);
32481 + __copy_user(to, from, n, __copyuser_seg, "", "");
32482 else
32483 - n = __copy_user_intel((void __user *)to,
32484 - (const void *)from, n);
32485 + n = __generic_copy_from_user_intel(to, from, n);
32486 clac();
32487 return n;
32488 }
32489 @@ -632,58 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
32490 if (n > 64 && cpu_has_xmm2)
32491 n = __copy_user_intel_nocache(to, from, n);
32492 else
32493 - __copy_user(to, from, n);
32494 + __copy_user(to, from, n, __copyuser_seg, "", "");
32495 #else
32496 - __copy_user(to, from, n);
32497 + __copy_user(to, from, n, __copyuser_seg, "", "");
32498 #endif
32499 clac();
32500 return n;
32501 }
32502 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
32503
32504 -/**
32505 - * copy_to_user: - Copy a block of data into user space.
32506 - * @to: Destination address, in user space.
32507 - * @from: Source address, in kernel space.
32508 - * @n: Number of bytes to copy.
32509 - *
32510 - * Context: User context only. This function may sleep.
32511 - *
32512 - * Copy data from kernel space to user space.
32513 - *
32514 - * Returns number of bytes that could not be copied.
32515 - * On success, this will be zero.
32516 - */
32517 -unsigned long _copy_to_user(void __user *to, const void *from, unsigned n)
32518 +#ifdef CONFIG_PAX_MEMORY_UDEREF
32519 +void __set_fs(mm_segment_t x)
32520 {
32521 - if (access_ok(VERIFY_WRITE, to, n))
32522 - n = __copy_to_user(to, from, n);
32523 - return n;
32524 + switch (x.seg) {
32525 + case 0:
32526 + loadsegment(gs, 0);
32527 + break;
32528 + case TASK_SIZE_MAX:
32529 + loadsegment(gs, __USER_DS);
32530 + break;
32531 + case -1UL:
32532 + loadsegment(gs, __KERNEL_DS);
32533 + break;
32534 + default:
32535 + BUG();
32536 + }
32537 }
32538 -EXPORT_SYMBOL(_copy_to_user);
32539 +EXPORT_SYMBOL(__set_fs);
32540
32541 -/**
32542 - * copy_from_user: - Copy a block of data from user space.
32543 - * @to: Destination address, in kernel space.
32544 - * @from: Source address, in user space.
32545 - * @n: Number of bytes to copy.
32546 - *
32547 - * Context: User context only. This function may sleep.
32548 - *
32549 - * Copy data from user space to kernel space.
32550 - *
32551 - * Returns number of bytes that could not be copied.
32552 - * On success, this will be zero.
32553 - *
32554 - * If some data could not be copied, this function will pad the copied
32555 - * data to the requested size using zero bytes.
32556 - */
32557 -unsigned long _copy_from_user(void *to, const void __user *from, unsigned n)
32558 +void set_fs(mm_segment_t x)
32559 {
32560 - if (access_ok(VERIFY_READ, from, n))
32561 - n = __copy_from_user(to, from, n);
32562 - else
32563 - memset(to, 0, n);
32564 - return n;
32565 + current_thread_info()->addr_limit = x;
32566 + __set_fs(x);
32567 }
32568 -EXPORT_SYMBOL(_copy_from_user);
32569 +EXPORT_SYMBOL(set_fs);
32570 +#endif
32571 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
32572 index c905e89..01ab928 100644
32573 --- a/arch/x86/lib/usercopy_64.c
32574 +++ b/arch/x86/lib/usercopy_64.c
32575 @@ -18,6 +18,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
32576 might_fault();
32577 /* no memory constraint because it doesn't change any memory gcc knows
32578 about */
32579 + pax_open_userland();
32580 stac();
32581 asm volatile(
32582 " testq %[size8],%[size8]\n"
32583 @@ -39,9 +40,10 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
32584 _ASM_EXTABLE(0b,3b)
32585 _ASM_EXTABLE(1b,2b)
32586 : [size8] "=&c"(size), [dst] "=&D" (__d0)
32587 - : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
32588 + : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
32589 [zero] "r" (0UL), [eight] "r" (8UL));
32590 clac();
32591 + pax_close_userland();
32592 return size;
32593 }
32594 EXPORT_SYMBOL(__clear_user);
32595 @@ -54,12 +56,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
32596 }
32597 EXPORT_SYMBOL(clear_user);
32598
32599 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
32600 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
32601 {
32602 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
32603 - return copy_user_generic((__force void *)to, (__force void *)from, len);
32604 - }
32605 - return len;
32606 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
32607 + return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
32608 + return len;
32609 }
32610 EXPORT_SYMBOL(copy_in_user);
32611
32612 @@ -69,11 +70,13 @@ EXPORT_SYMBOL(copy_in_user);
32613 * it is not necessary to optimize tail handling.
32614 */
32615 __visible unsigned long
32616 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
32617 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
32618 {
32619 char c;
32620 unsigned zero_len;
32621
32622 + clac();
32623 + pax_close_userland();
32624 for (; len; --len, to++) {
32625 if (__get_user_nocheck(c, from++, sizeof(char)))
32626 break;
32627 @@ -84,6 +87,5 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
32628 for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
32629 if (__put_user_nocheck(c, to++, sizeof(char)))
32630 break;
32631 - clac();
32632 return len;
32633 }
32634 diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
32635 index 6a19ad9..1c48f9a 100644
32636 --- a/arch/x86/mm/Makefile
32637 +++ b/arch/x86/mm/Makefile
32638 @@ -30,3 +30,7 @@ obj-$(CONFIG_ACPI_NUMA) += srat.o
32639 obj-$(CONFIG_NUMA_EMU) += numa_emulation.o
32640
32641 obj-$(CONFIG_MEMTEST) += memtest.o
32642 +
32643 +quote:="
32644 +obj-$(CONFIG_X86_64) += uderef_64.o
32645 +CFLAGS_uderef_64.o := $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
32646 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
32647 index 903ec1e..c4166b2 100644
32648 --- a/arch/x86/mm/extable.c
32649 +++ b/arch/x86/mm/extable.c
32650 @@ -6,12 +6,24 @@
32651 static inline unsigned long
32652 ex_insn_addr(const struct exception_table_entry *x)
32653 {
32654 - return (unsigned long)&x->insn + x->insn;
32655 + unsigned long reloc = 0;
32656 +
32657 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
32658 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
32659 +#endif
32660 +
32661 + return (unsigned long)&x->insn + x->insn + reloc;
32662 }
32663 static inline unsigned long
32664 ex_fixup_addr(const struct exception_table_entry *x)
32665 {
32666 - return (unsigned long)&x->fixup + x->fixup;
32667 + unsigned long reloc = 0;
32668 +
32669 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
32670 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
32671 +#endif
32672 +
32673 + return (unsigned long)&x->fixup + x->fixup + reloc;
32674 }
32675
32676 int fixup_exception(struct pt_regs *regs)
32677 @@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
32678 unsigned long new_ip;
32679
32680 #ifdef CONFIG_PNPBIOS
32681 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
32682 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
32683 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
32684 extern u32 pnp_bios_is_utter_crap;
32685 pnp_bios_is_utter_crap = 1;
32686 @@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
32687 i += 4;
32688 p->fixup -= i;
32689 i += 4;
32690 +
32691 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
32692 + BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
32693 + p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
32694 + p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
32695 +#endif
32696 +
32697 }
32698 }
32699
32700 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
32701 index a241946..d7a04cf 100644
32702 --- a/arch/x86/mm/fault.c
32703 +++ b/arch/x86/mm/fault.c
32704 @@ -14,12 +14,19 @@
32705 #include <linux/hugetlb.h> /* hstate_index_to_shift */
32706 #include <linux/prefetch.h> /* prefetchw */
32707 #include <linux/context_tracking.h> /* exception_enter(), ... */
32708 +#include <linux/unistd.h>
32709 +#include <linux/compiler.h>
32710
32711 #include <asm/traps.h> /* dotraplinkage, ... */
32712 #include <asm/pgalloc.h> /* pgd_*(), ... */
32713 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
32714 #include <asm/fixmap.h> /* VSYSCALL_ADDR */
32715 #include <asm/vsyscall.h> /* emulate_vsyscall */
32716 +#include <asm/tlbflush.h>
32717 +
32718 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
32719 +#include <asm/stacktrace.h>
32720 +#endif
32721
32722 #define CREATE_TRACE_POINTS
32723 #include <asm/trace/exceptions.h>
32724 @@ -60,7 +67,7 @@ static nokprobe_inline int kprobes_fault(struct pt_regs *regs)
32725 int ret = 0;
32726
32727 /* kprobe_running() needs smp_processor_id() */
32728 - if (kprobes_built_in() && !user_mode_vm(regs)) {
32729 + if (kprobes_built_in() && !user_mode(regs)) {
32730 preempt_disable();
32731 if (kprobe_running() && kprobe_fault_handler(regs, 14))
32732 ret = 1;
32733 @@ -121,7 +128,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
32734 return !instr_lo || (instr_lo>>1) == 1;
32735 case 0x00:
32736 /* Prefetch instruction is 0x0F0D or 0x0F18 */
32737 - if (probe_kernel_address(instr, opcode))
32738 + if (user_mode(regs)) {
32739 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
32740 + return 0;
32741 + } else if (probe_kernel_address(instr, opcode))
32742 return 0;
32743
32744 *prefetch = (instr_lo == 0xF) &&
32745 @@ -155,7 +165,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
32746 while (instr < max_instr) {
32747 unsigned char opcode;
32748
32749 - if (probe_kernel_address(instr, opcode))
32750 + if (user_mode(regs)) {
32751 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
32752 + break;
32753 + } else if (probe_kernel_address(instr, opcode))
32754 break;
32755
32756 instr++;
32757 @@ -186,6 +199,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
32758 force_sig_info(si_signo, &info, tsk);
32759 }
32760
32761 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32762 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
32763 +#endif
32764 +
32765 +#ifdef CONFIG_PAX_EMUTRAMP
32766 +static int pax_handle_fetch_fault(struct pt_regs *regs);
32767 +#endif
32768 +
32769 +#ifdef CONFIG_PAX_PAGEEXEC
32770 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
32771 +{
32772 + pgd_t *pgd;
32773 + pud_t *pud;
32774 + pmd_t *pmd;
32775 +
32776 + pgd = pgd_offset(mm, address);
32777 + if (!pgd_present(*pgd))
32778 + return NULL;
32779 + pud = pud_offset(pgd, address);
32780 + if (!pud_present(*pud))
32781 + return NULL;
32782 + pmd = pmd_offset(pud, address);
32783 + if (!pmd_present(*pmd))
32784 + return NULL;
32785 + return pmd;
32786 +}
32787 +#endif
32788 +
32789 DEFINE_SPINLOCK(pgd_lock);
32790 LIST_HEAD(pgd_list);
32791
32792 @@ -236,10 +277,27 @@ void vmalloc_sync_all(void)
32793 for (address = VMALLOC_START & PMD_MASK;
32794 address >= TASK_SIZE && address < FIXADDR_TOP;
32795 address += PMD_SIZE) {
32796 +
32797 +#ifdef CONFIG_PAX_PER_CPU_PGD
32798 + unsigned long cpu;
32799 +#else
32800 struct page *page;
32801 +#endif
32802
32803 spin_lock(&pgd_lock);
32804 +
32805 +#ifdef CONFIG_PAX_PER_CPU_PGD
32806 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
32807 + pgd_t *pgd = get_cpu_pgd(cpu, user);
32808 + pmd_t *ret;
32809 +
32810 + ret = vmalloc_sync_one(pgd, address);
32811 + if (!ret)
32812 + break;
32813 + pgd = get_cpu_pgd(cpu, kernel);
32814 +#else
32815 list_for_each_entry(page, &pgd_list, lru) {
32816 + pgd_t *pgd;
32817 spinlock_t *pgt_lock;
32818 pmd_t *ret;
32819
32820 @@ -247,8 +305,14 @@ void vmalloc_sync_all(void)
32821 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
32822
32823 spin_lock(pgt_lock);
32824 - ret = vmalloc_sync_one(page_address(page), address);
32825 + pgd = page_address(page);
32826 +#endif
32827 +
32828 + ret = vmalloc_sync_one(pgd, address);
32829 +
32830 +#ifndef CONFIG_PAX_PER_CPU_PGD
32831 spin_unlock(pgt_lock);
32832 +#endif
32833
32834 if (!ret)
32835 break;
32836 @@ -282,6 +346,12 @@ static noinline int vmalloc_fault(unsigned long address)
32837 * an interrupt in the middle of a task switch..
32838 */
32839 pgd_paddr = read_cr3();
32840 +
32841 +#ifdef CONFIG_PAX_PER_CPU_PGD
32842 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (pgd_paddr & __PHYSICAL_MASK));
32843 + vmalloc_sync_one(__va(pgd_paddr + PAGE_SIZE), address);
32844 +#endif
32845 +
32846 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
32847 if (!pmd_k)
32848 return -1;
32849 @@ -378,11 +448,25 @@ static noinline int vmalloc_fault(unsigned long address)
32850 * happen within a race in page table update. In the later
32851 * case just flush:
32852 */
32853 - pgd = pgd_offset(current->active_mm, address);
32854 +
32855 pgd_ref = pgd_offset_k(address);
32856 if (pgd_none(*pgd_ref))
32857 return -1;
32858
32859 +#ifdef CONFIG_PAX_PER_CPU_PGD
32860 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (read_cr3() & __PHYSICAL_MASK));
32861 + pgd = pgd_offset_cpu(smp_processor_id(), user, address);
32862 + if (pgd_none(*pgd)) {
32863 + set_pgd(pgd, *pgd_ref);
32864 + arch_flush_lazy_mmu_mode();
32865 + } else {
32866 + BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
32867 + }
32868 + pgd = pgd_offset_cpu(smp_processor_id(), kernel, address);
32869 +#else
32870 + pgd = pgd_offset(current->active_mm, address);
32871 +#endif
32872 +
32873 if (pgd_none(*pgd)) {
32874 set_pgd(pgd, *pgd_ref);
32875 arch_flush_lazy_mmu_mode();
32876 @@ -549,7 +633,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
32877 static int is_errata100(struct pt_regs *regs, unsigned long address)
32878 {
32879 #ifdef CONFIG_X86_64
32880 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
32881 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
32882 return 1;
32883 #endif
32884 return 0;
32885 @@ -576,9 +660,9 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
32886 }
32887
32888 static const char nx_warning[] = KERN_CRIT
32889 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
32890 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
32891 static const char smep_warning[] = KERN_CRIT
32892 -"unable to execute userspace code (SMEP?) (uid: %d)\n";
32893 +"unable to execute userspace code (SMEP?) (uid: %d, task: %s, pid: %d)\n";
32894
32895 static void
32896 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
32897 @@ -587,7 +671,7 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
32898 if (!oops_may_print())
32899 return;
32900
32901 - if (error_code & PF_INSTR) {
32902 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
32903 unsigned int level;
32904 pgd_t *pgd;
32905 pte_t *pte;
32906 @@ -598,13 +682,25 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
32907 pte = lookup_address_in_pgd(pgd, address, &level);
32908
32909 if (pte && pte_present(*pte) && !pte_exec(*pte))
32910 - printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
32911 + printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
32912 if (pte && pte_present(*pte) && pte_exec(*pte) &&
32913 (pgd_flags(*pgd) & _PAGE_USER) &&
32914 (read_cr4() & X86_CR4_SMEP))
32915 - printk(smep_warning, from_kuid(&init_user_ns, current_uid()));
32916 + printk(smep_warning, from_kuid(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
32917 }
32918
32919 +#ifdef CONFIG_PAX_KERNEXEC
32920 + if (init_mm.start_code <= address && address < init_mm.end_code) {
32921 + if (current->signal->curr_ip)
32922 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
32923 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
32924 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
32925 + else
32926 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
32927 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
32928 + }
32929 +#endif
32930 +
32931 printk(KERN_ALERT "BUG: unable to handle kernel ");
32932 if (address < PAGE_SIZE)
32933 printk(KERN_CONT "NULL pointer dereference");
32934 @@ -785,6 +881,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
32935 return;
32936 }
32937 #endif
32938 +
32939 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32940 + if (pax_is_fetch_fault(regs, error_code, address)) {
32941 +
32942 +#ifdef CONFIG_PAX_EMUTRAMP
32943 + switch (pax_handle_fetch_fault(regs)) {
32944 + case 2:
32945 + return;
32946 + }
32947 +#endif
32948 +
32949 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
32950 + do_group_exit(SIGKILL);
32951 + }
32952 +#endif
32953 +
32954 /* Kernel addresses are always protection faults: */
32955 if (address >= TASK_SIZE)
32956 error_code |= PF_PROT;
32957 @@ -870,7 +982,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
32958 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
32959 printk(KERN_ERR
32960 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
32961 - tsk->comm, tsk->pid, address);
32962 + tsk->comm, task_pid_nr(tsk), address);
32963 code = BUS_MCEERR_AR;
32964 }
32965 #endif
32966 @@ -924,6 +1036,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
32967 return 1;
32968 }
32969
32970 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
32971 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
32972 +{
32973 + pte_t *pte;
32974 + pmd_t *pmd;
32975 + spinlock_t *ptl;
32976 + unsigned char pte_mask;
32977 +
32978 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
32979 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
32980 + return 0;
32981 +
32982 + /* PaX: it's our fault, let's handle it if we can */
32983 +
32984 + /* PaX: take a look at read faults before acquiring any locks */
32985 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
32986 + /* instruction fetch attempt from a protected page in user mode */
32987 + up_read(&mm->mmap_sem);
32988 +
32989 +#ifdef CONFIG_PAX_EMUTRAMP
32990 + switch (pax_handle_fetch_fault(regs)) {
32991 + case 2:
32992 + return 1;
32993 + }
32994 +#endif
32995 +
32996 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
32997 + do_group_exit(SIGKILL);
32998 + }
32999 +
33000 + pmd = pax_get_pmd(mm, address);
33001 + if (unlikely(!pmd))
33002 + return 0;
33003 +
33004 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
33005 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
33006 + pte_unmap_unlock(pte, ptl);
33007 + return 0;
33008 + }
33009 +
33010 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
33011 + /* write attempt to a protected page in user mode */
33012 + pte_unmap_unlock(pte, ptl);
33013 + return 0;
33014 + }
33015 +
33016 +#ifdef CONFIG_SMP
33017 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
33018 +#else
33019 + if (likely(address > get_limit(regs->cs)))
33020 +#endif
33021 + {
33022 + set_pte(pte, pte_mkread(*pte));
33023 + __flush_tlb_one(address);
33024 + pte_unmap_unlock(pte, ptl);
33025 + up_read(&mm->mmap_sem);
33026 + return 1;
33027 + }
33028 +
33029 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
33030 +
33031 + /*
33032 + * PaX: fill DTLB with user rights and retry
33033 + */
33034 + __asm__ __volatile__ (
33035 + "orb %2,(%1)\n"
33036 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
33037 +/*
33038 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
33039 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
33040 + * page fault when examined during a TLB load attempt. this is true not only
33041 + * for PTEs holding a non-present entry but also present entries that will
33042 + * raise a page fault (such as those set up by PaX, or the copy-on-write
33043 + * mechanism). in effect it means that we do *not* need to flush the TLBs
33044 + * for our target pages since their PTEs are simply not in the TLBs at all.
33045 +
33046 + * the best thing in omitting it is that we gain around 15-20% speed in the
33047 + * fast path of the page fault handler and can get rid of tracing since we
33048 + * can no longer flush unintended entries.
33049 + */
33050 + "invlpg (%0)\n"
33051 +#endif
33052 + __copyuser_seg"testb $0,(%0)\n"
33053 + "xorb %3,(%1)\n"
33054 + :
33055 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
33056 + : "memory", "cc");
33057 + pte_unmap_unlock(pte, ptl);
33058 + up_read(&mm->mmap_sem);
33059 + return 1;
33060 +}
33061 +#endif
33062 +
33063 /*
33064 * Handle a spurious fault caused by a stale TLB entry.
33065 *
33066 @@ -991,6 +1196,9 @@ int show_unhandled_signals = 1;
33067 static inline int
33068 access_error(unsigned long error_code, struct vm_area_struct *vma)
33069 {
33070 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
33071 + return 1;
33072 +
33073 if (error_code & PF_WRITE) {
33074 /* write, present and write, not present: */
33075 if (unlikely(!(vma->vm_flags & VM_WRITE)))
33076 @@ -1025,7 +1233,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
33077 if (error_code & PF_USER)
33078 return false;
33079
33080 - if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
33081 + if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
33082 return false;
33083
33084 return true;
33085 @@ -1053,6 +1261,22 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
33086 tsk = current;
33087 mm = tsk->mm;
33088
33089 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33090 + if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
33091 + if (!search_exception_tables(regs->ip)) {
33092 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
33093 + bad_area_nosemaphore(regs, error_code, address);
33094 + return;
33095 + }
33096 + if (address < pax_user_shadow_base) {
33097 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
33098 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
33099 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
33100 + } else
33101 + address -= pax_user_shadow_base;
33102 + }
33103 +#endif
33104 +
33105 /*
33106 * Detect and handle instructions that would cause a page fault for
33107 * both a tracked kernel page and a userspace page.
33108 @@ -1130,7 +1354,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
33109 * User-mode registers count as a user access even for any
33110 * potential system fault or CPU buglet:
33111 */
33112 - if (user_mode_vm(regs)) {
33113 + if (user_mode(regs)) {
33114 local_irq_enable();
33115 error_code |= PF_USER;
33116 flags |= FAULT_FLAG_USER;
33117 @@ -1177,6 +1401,11 @@ retry:
33118 might_sleep();
33119 }
33120
33121 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
33122 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
33123 + return;
33124 +#endif
33125 +
33126 vma = find_vma(mm, address);
33127 if (unlikely(!vma)) {
33128 bad_area(regs, error_code, address);
33129 @@ -1188,18 +1417,24 @@ retry:
33130 bad_area(regs, error_code, address);
33131 return;
33132 }
33133 - if (error_code & PF_USER) {
33134 - /*
33135 - * Accessing the stack below %sp is always a bug.
33136 - * The large cushion allows instructions like enter
33137 - * and pusha to work. ("enter $65535, $31" pushes
33138 - * 32 pointers and then decrements %sp by 65535.)
33139 - */
33140 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
33141 - bad_area(regs, error_code, address);
33142 - return;
33143 - }
33144 + /*
33145 + * Accessing the stack below %sp is always a bug.
33146 + * The large cushion allows instructions like enter
33147 + * and pusha to work. ("enter $65535, $31" pushes
33148 + * 32 pointers and then decrements %sp by 65535.)
33149 + */
33150 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
33151 + bad_area(regs, error_code, address);
33152 + return;
33153 }
33154 +
33155 +#ifdef CONFIG_PAX_SEGMEXEC
33156 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
33157 + bad_area(regs, error_code, address);
33158 + return;
33159 + }
33160 +#endif
33161 +
33162 if (unlikely(expand_stack(vma, address))) {
33163 bad_area(regs, error_code, address);
33164 return;
33165 @@ -1316,3 +1551,292 @@ trace_do_page_fault(struct pt_regs *regs, unsigned long error_code)
33166 }
33167 NOKPROBE_SYMBOL(trace_do_page_fault);
33168 #endif /* CONFIG_TRACING */
33169 +
33170 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
33171 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
33172 +{
33173 + struct mm_struct *mm = current->mm;
33174 + unsigned long ip = regs->ip;
33175 +
33176 + if (v8086_mode(regs))
33177 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
33178 +
33179 +#ifdef CONFIG_PAX_PAGEEXEC
33180 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
33181 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
33182 + return true;
33183 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
33184 + return true;
33185 + return false;
33186 + }
33187 +#endif
33188 +
33189 +#ifdef CONFIG_PAX_SEGMEXEC
33190 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
33191 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
33192 + return true;
33193 + return false;
33194 + }
33195 +#endif
33196 +
33197 + return false;
33198 +}
33199 +#endif
33200 +
33201 +#ifdef CONFIG_PAX_EMUTRAMP
33202 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
33203 +{
33204 + int err;
33205 +
33206 + do { /* PaX: libffi trampoline emulation */
33207 + unsigned char mov, jmp;
33208 + unsigned int addr1, addr2;
33209 +
33210 +#ifdef CONFIG_X86_64
33211 + if ((regs->ip + 9) >> 32)
33212 + break;
33213 +#endif
33214 +
33215 + err = get_user(mov, (unsigned char __user *)regs->ip);
33216 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
33217 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
33218 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
33219 +
33220 + if (err)
33221 + break;
33222 +
33223 + if (mov == 0xB8 && jmp == 0xE9) {
33224 + regs->ax = addr1;
33225 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
33226 + return 2;
33227 + }
33228 + } while (0);
33229 +
33230 + do { /* PaX: gcc trampoline emulation #1 */
33231 + unsigned char mov1, mov2;
33232 + unsigned short jmp;
33233 + unsigned int addr1, addr2;
33234 +
33235 +#ifdef CONFIG_X86_64
33236 + if ((regs->ip + 11) >> 32)
33237 + break;
33238 +#endif
33239 +
33240 + err = get_user(mov1, (unsigned char __user *)regs->ip);
33241 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
33242 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
33243 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
33244 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
33245 +
33246 + if (err)
33247 + break;
33248 +
33249 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
33250 + regs->cx = addr1;
33251 + regs->ax = addr2;
33252 + regs->ip = addr2;
33253 + return 2;
33254 + }
33255 + } while (0);
33256 +
33257 + do { /* PaX: gcc trampoline emulation #2 */
33258 + unsigned char mov, jmp;
33259 + unsigned int addr1, addr2;
33260 +
33261 +#ifdef CONFIG_X86_64
33262 + if ((regs->ip + 9) >> 32)
33263 + break;
33264 +#endif
33265 +
33266 + err = get_user(mov, (unsigned char __user *)regs->ip);
33267 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
33268 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
33269 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
33270 +
33271 + if (err)
33272 + break;
33273 +
33274 + if (mov == 0xB9 && jmp == 0xE9) {
33275 + regs->cx = addr1;
33276 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
33277 + return 2;
33278 + }
33279 + } while (0);
33280 +
33281 + return 1; /* PaX in action */
33282 +}
33283 +
33284 +#ifdef CONFIG_X86_64
33285 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
33286 +{
33287 + int err;
33288 +
33289 + do { /* PaX: libffi trampoline emulation */
33290 + unsigned short mov1, mov2, jmp1;
33291 + unsigned char stcclc, jmp2;
33292 + unsigned long addr1, addr2;
33293 +
33294 + err = get_user(mov1, (unsigned short __user *)regs->ip);
33295 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
33296 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
33297 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
33298 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
33299 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
33300 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
33301 +
33302 + if (err)
33303 + break;
33304 +
33305 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
33306 + regs->r11 = addr1;
33307 + regs->r10 = addr2;
33308 + if (stcclc == 0xF8)
33309 + regs->flags &= ~X86_EFLAGS_CF;
33310 + else
33311 + regs->flags |= X86_EFLAGS_CF;
33312 + regs->ip = addr1;
33313 + return 2;
33314 + }
33315 + } while (0);
33316 +
33317 + do { /* PaX: gcc trampoline emulation #1 */
33318 + unsigned short mov1, mov2, jmp1;
33319 + unsigned char jmp2;
33320 + unsigned int addr1;
33321 + unsigned long addr2;
33322 +
33323 + err = get_user(mov1, (unsigned short __user *)regs->ip);
33324 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
33325 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
33326 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
33327 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
33328 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
33329 +
33330 + if (err)
33331 + break;
33332 +
33333 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
33334 + regs->r11 = addr1;
33335 + regs->r10 = addr2;
33336 + regs->ip = addr1;
33337 + return 2;
33338 + }
33339 + } while (0);
33340 +
33341 + do { /* PaX: gcc trampoline emulation #2 */
33342 + unsigned short mov1, mov2, jmp1;
33343 + unsigned char jmp2;
33344 + unsigned long addr1, addr2;
33345 +
33346 + err = get_user(mov1, (unsigned short __user *)regs->ip);
33347 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
33348 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
33349 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
33350 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
33351 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
33352 +
33353 + if (err)
33354 + break;
33355 +
33356 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
33357 + regs->r11 = addr1;
33358 + regs->r10 = addr2;
33359 + regs->ip = addr1;
33360 + return 2;
33361 + }
33362 + } while (0);
33363 +
33364 + return 1; /* PaX in action */
33365 +}
33366 +#endif
33367 +
33368 +/*
33369 + * PaX: decide what to do with offenders (regs->ip = fault address)
33370 + *
33371 + * returns 1 when task should be killed
33372 + * 2 when gcc trampoline was detected
33373 + */
33374 +static int pax_handle_fetch_fault(struct pt_regs *regs)
33375 +{
33376 + if (v8086_mode(regs))
33377 + return 1;
33378 +
33379 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
33380 + return 1;
33381 +
33382 +#ifdef CONFIG_X86_32
33383 + return pax_handle_fetch_fault_32(regs);
33384 +#else
33385 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
33386 + return pax_handle_fetch_fault_32(regs);
33387 + else
33388 + return pax_handle_fetch_fault_64(regs);
33389 +#endif
33390 +}
33391 +#endif
33392 +
33393 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
33394 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
33395 +{
33396 + long i;
33397 +
33398 + printk(KERN_ERR "PAX: bytes at PC: ");
33399 + for (i = 0; i < 20; i++) {
33400 + unsigned char c;
33401 + if (get_user(c, (unsigned char __force_user *)pc+i))
33402 + printk(KERN_CONT "?? ");
33403 + else
33404 + printk(KERN_CONT "%02x ", c);
33405 + }
33406 + printk("\n");
33407 +
33408 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
33409 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
33410 + unsigned long c;
33411 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
33412 +#ifdef CONFIG_X86_32
33413 + printk(KERN_CONT "???????? ");
33414 +#else
33415 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
33416 + printk(KERN_CONT "???????? ???????? ");
33417 + else
33418 + printk(KERN_CONT "???????????????? ");
33419 +#endif
33420 + } else {
33421 +#ifdef CONFIG_X86_64
33422 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
33423 + printk(KERN_CONT "%08x ", (unsigned int)c);
33424 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
33425 + } else
33426 +#endif
33427 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
33428 + }
33429 + }
33430 + printk("\n");
33431 +}
33432 +#endif
33433 +
33434 +/**
33435 + * probe_kernel_write(): safely attempt to write to a location
33436 + * @dst: address to write to
33437 + * @src: pointer to the data that shall be written
33438 + * @size: size of the data chunk
33439 + *
33440 + * Safely write to address @dst from the buffer at @src. If a kernel fault
33441 + * happens, handle that and return -EFAULT.
33442 + */
33443 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
33444 +{
33445 + long ret;
33446 + mm_segment_t old_fs = get_fs();
33447 +
33448 + set_fs(KERNEL_DS);
33449 + pagefault_disable();
33450 + pax_open_kernel();
33451 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
33452 + pax_close_kernel();
33453 + pagefault_enable();
33454 + set_fs(old_fs);
33455 +
33456 + return ret ? -EFAULT : 0;
33457 +}
33458 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
33459 index 207d9aef..69030980 100644
33460 --- a/arch/x86/mm/gup.c
33461 +++ b/arch/x86/mm/gup.c
33462 @@ -268,7 +268,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
33463 addr = start;
33464 len = (unsigned long) nr_pages << PAGE_SHIFT;
33465 end = start + len;
33466 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
33467 + if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
33468 (void __user *)start, len)))
33469 return 0;
33470
33471 @@ -344,6 +344,10 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
33472 goto slow_irqon;
33473 #endif
33474
33475 + if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
33476 + (void __user *)start, len)))
33477 + return 0;
33478 +
33479 /*
33480 * XXX: batch / limit 'nr', to avoid large irq off latency
33481 * needs some instrumenting to determine the common sizes used by
33482 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
33483 index 4500142..53a363c 100644
33484 --- a/arch/x86/mm/highmem_32.c
33485 +++ b/arch/x86/mm/highmem_32.c
33486 @@ -45,7 +45,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
33487 idx = type + KM_TYPE_NR*smp_processor_id();
33488 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
33489 BUG_ON(!pte_none(*(kmap_pte-idx)));
33490 +
33491 + pax_open_kernel();
33492 set_pte(kmap_pte-idx, mk_pte(page, prot));
33493 + pax_close_kernel();
33494 +
33495 arch_flush_lazy_mmu_mode();
33496
33497 return (void *)vaddr;
33498 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
33499 index 8b977eb..4732c33 100644
33500 --- a/arch/x86/mm/hugetlbpage.c
33501 +++ b/arch/x86/mm/hugetlbpage.c
33502 @@ -80,23 +80,24 @@ int pud_huge(pud_t pud)
33503 #ifdef CONFIG_HUGETLB_PAGE
33504 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
33505 unsigned long addr, unsigned long len,
33506 - unsigned long pgoff, unsigned long flags)
33507 + unsigned long pgoff, unsigned long flags, unsigned long offset)
33508 {
33509 struct hstate *h = hstate_file(file);
33510 struct vm_unmapped_area_info info;
33511 -
33512 +
33513 info.flags = 0;
33514 info.length = len;
33515 info.low_limit = current->mm->mmap_legacy_base;
33516 info.high_limit = TASK_SIZE;
33517 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
33518 info.align_offset = 0;
33519 + info.threadstack_offset = offset;
33520 return vm_unmapped_area(&info);
33521 }
33522
33523 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
33524 unsigned long addr0, unsigned long len,
33525 - unsigned long pgoff, unsigned long flags)
33526 + unsigned long pgoff, unsigned long flags, unsigned long offset)
33527 {
33528 struct hstate *h = hstate_file(file);
33529 struct vm_unmapped_area_info info;
33530 @@ -108,6 +109,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
33531 info.high_limit = current->mm->mmap_base;
33532 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
33533 info.align_offset = 0;
33534 + info.threadstack_offset = offset;
33535 addr = vm_unmapped_area(&info);
33536
33537 /*
33538 @@ -120,6 +122,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
33539 VM_BUG_ON(addr != -ENOMEM);
33540 info.flags = 0;
33541 info.low_limit = TASK_UNMAPPED_BASE;
33542 +
33543 +#ifdef CONFIG_PAX_RANDMMAP
33544 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
33545 + info.low_limit += current->mm->delta_mmap;
33546 +#endif
33547 +
33548 info.high_limit = TASK_SIZE;
33549 addr = vm_unmapped_area(&info);
33550 }
33551 @@ -134,10 +142,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
33552 struct hstate *h = hstate_file(file);
33553 struct mm_struct *mm = current->mm;
33554 struct vm_area_struct *vma;
33555 + unsigned long pax_task_size = TASK_SIZE;
33556 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
33557
33558 if (len & ~huge_page_mask(h))
33559 return -EINVAL;
33560 - if (len > TASK_SIZE)
33561 +
33562 +#ifdef CONFIG_PAX_SEGMEXEC
33563 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
33564 + pax_task_size = SEGMEXEC_TASK_SIZE;
33565 +#endif
33566 +
33567 + pax_task_size -= PAGE_SIZE;
33568 +
33569 + if (len > pax_task_size)
33570 return -ENOMEM;
33571
33572 if (flags & MAP_FIXED) {
33573 @@ -146,19 +164,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
33574 return addr;
33575 }
33576
33577 +#ifdef CONFIG_PAX_RANDMMAP
33578 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
33579 +#endif
33580 +
33581 if (addr) {
33582 addr = ALIGN(addr, huge_page_size(h));
33583 vma = find_vma(mm, addr);
33584 - if (TASK_SIZE - len >= addr &&
33585 - (!vma || addr + len <= vma->vm_start))
33586 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
33587 return addr;
33588 }
33589 if (mm->get_unmapped_area == arch_get_unmapped_area)
33590 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
33591 - pgoff, flags);
33592 + pgoff, flags, offset);
33593 else
33594 return hugetlb_get_unmapped_area_topdown(file, addr, len,
33595 - pgoff, flags);
33596 + pgoff, flags, offset);
33597 }
33598 #endif /* CONFIG_HUGETLB_PAGE */
33599
33600 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
33601 index 66dba36..f8082ec 100644
33602 --- a/arch/x86/mm/init.c
33603 +++ b/arch/x86/mm/init.c
33604 @@ -4,6 +4,7 @@
33605 #include <linux/swap.h>
33606 #include <linux/memblock.h>
33607 #include <linux/bootmem.h> /* for max_low_pfn */
33608 +#include <linux/tboot.h>
33609
33610 #include <asm/cacheflush.h>
33611 #include <asm/e820.h>
33612 @@ -17,6 +18,8 @@
33613 #include <asm/proto.h>
33614 #include <asm/dma.h> /* for MAX_DMA_PFN */
33615 #include <asm/microcode.h>
33616 +#include <asm/desc.h>
33617 +#include <asm/bios_ebda.h>
33618
33619 /*
33620 * We need to define the tracepoints somewhere, and tlb.c
33621 @@ -570,7 +573,18 @@ void __init init_mem_mapping(void)
33622 early_ioremap_page_table_range_init();
33623 #endif
33624
33625 +#ifdef CONFIG_PAX_PER_CPU_PGD
33626 + clone_pgd_range(get_cpu_pgd(0, kernel) + KERNEL_PGD_BOUNDARY,
33627 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
33628 + KERNEL_PGD_PTRS);
33629 + clone_pgd_range(get_cpu_pgd(0, user) + KERNEL_PGD_BOUNDARY,
33630 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
33631 + KERNEL_PGD_PTRS);
33632 + load_cr3(get_cpu_pgd(0, kernel));
33633 +#else
33634 load_cr3(swapper_pg_dir);
33635 +#endif
33636 +
33637 __flush_tlb_all();
33638
33639 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
33640 @@ -586,10 +600,40 @@ void __init init_mem_mapping(void)
33641 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
33642 * mmio resources as well as potential bios/acpi data regions.
33643 */
33644 +
33645 +#ifdef CONFIG_GRKERNSEC_KMEM
33646 +static unsigned int ebda_start __read_only;
33647 +static unsigned int ebda_end __read_only;
33648 +#endif
33649 +
33650 int devmem_is_allowed(unsigned long pagenr)
33651 {
33652 - if (pagenr < 256)
33653 +#ifdef CONFIG_GRKERNSEC_KMEM
33654 + /* allow BDA */
33655 + if (!pagenr)
33656 return 1;
33657 + /* allow EBDA */
33658 + if (pagenr >= ebda_start && pagenr < ebda_end)
33659 + return 1;
33660 + /* if tboot is in use, allow access to its hardcoded serial log range */
33661 + if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
33662 + return 1;
33663 +#else
33664 + if (!pagenr)
33665 + return 1;
33666 +#ifdef CONFIG_VM86
33667 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
33668 + return 1;
33669 +#endif
33670 +#endif
33671 +
33672 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
33673 + return 1;
33674 +#ifdef CONFIG_GRKERNSEC_KMEM
33675 + /* throw out everything else below 1MB */
33676 + if (pagenr <= 256)
33677 + return 0;
33678 +#endif
33679 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
33680 return 0;
33681 if (!page_is_ram(pagenr))
33682 @@ -635,8 +679,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
33683 #endif
33684 }
33685
33686 +#ifdef CONFIG_GRKERNSEC_KMEM
33687 +static inline void gr_init_ebda(void)
33688 +{
33689 + unsigned int ebda_addr;
33690 + unsigned int ebda_size = 0;
33691 +
33692 + ebda_addr = get_bios_ebda();
33693 + if (ebda_addr) {
33694 + ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
33695 + ebda_size <<= 10;
33696 + }
33697 + if (ebda_addr && ebda_size) {
33698 + ebda_start = ebda_addr >> PAGE_SHIFT;
33699 + ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
33700 + } else {
33701 + ebda_start = 0x9f000 >> PAGE_SHIFT;
33702 + ebda_end = 0xa0000 >> PAGE_SHIFT;
33703 + }
33704 +}
33705 +#else
33706 +static inline void gr_init_ebda(void) { }
33707 +#endif
33708 +
33709 void free_initmem(void)
33710 {
33711 +#ifdef CONFIG_PAX_KERNEXEC
33712 +#ifdef CONFIG_X86_32
33713 + /* PaX: limit KERNEL_CS to actual size */
33714 + unsigned long addr, limit;
33715 + struct desc_struct d;
33716 + int cpu;
33717 +#else
33718 + pgd_t *pgd;
33719 + pud_t *pud;
33720 + pmd_t *pmd;
33721 + unsigned long addr, end;
33722 +#endif
33723 +#endif
33724 +
33725 + gr_init_ebda();
33726 +
33727 +#ifdef CONFIG_PAX_KERNEXEC
33728 +#ifdef CONFIG_X86_32
33729 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
33730 + limit = (limit - 1UL) >> PAGE_SHIFT;
33731 +
33732 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
33733 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
33734 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
33735 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
33736 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
33737 + }
33738 +
33739 + /* PaX: make KERNEL_CS read-only */
33740 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
33741 + if (!paravirt_enabled())
33742 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
33743 +/*
33744 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
33745 + pgd = pgd_offset_k(addr);
33746 + pud = pud_offset(pgd, addr);
33747 + pmd = pmd_offset(pud, addr);
33748 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
33749 + }
33750 +*/
33751 +#ifdef CONFIG_X86_PAE
33752 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
33753 +/*
33754 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
33755 + pgd = pgd_offset_k(addr);
33756 + pud = pud_offset(pgd, addr);
33757 + pmd = pmd_offset(pud, addr);
33758 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
33759 + }
33760 +*/
33761 +#endif
33762 +
33763 +#ifdef CONFIG_MODULES
33764 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
33765 +#endif
33766 +
33767 +#else
33768 + /* PaX: make kernel code/rodata read-only, rest non-executable */
33769 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
33770 + pgd = pgd_offset_k(addr);
33771 + pud = pud_offset(pgd, addr);
33772 + pmd = pmd_offset(pud, addr);
33773 + if (!pmd_present(*pmd))
33774 + continue;
33775 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
33776 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
33777 + else
33778 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
33779 + }
33780 +
33781 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
33782 + end = addr + KERNEL_IMAGE_SIZE;
33783 + for (; addr < end; addr += PMD_SIZE) {
33784 + pgd = pgd_offset_k(addr);
33785 + pud = pud_offset(pgd, addr);
33786 + pmd = pmd_offset(pud, addr);
33787 + if (!pmd_present(*pmd))
33788 + continue;
33789 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
33790 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
33791 + }
33792 +#endif
33793 +
33794 + flush_tlb_all();
33795 +#endif
33796 +
33797 free_init_pages("unused kernel",
33798 (unsigned long)(&__init_begin),
33799 (unsigned long)(&__init_end));
33800 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
33801 index 7d05565..bfc5338 100644
33802 --- a/arch/x86/mm/init_32.c
33803 +++ b/arch/x86/mm/init_32.c
33804 @@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
33805 bool __read_mostly __vmalloc_start_set = false;
33806
33807 /*
33808 - * Creates a middle page table and puts a pointer to it in the
33809 - * given global directory entry. This only returns the gd entry
33810 - * in non-PAE compilation mode, since the middle layer is folded.
33811 - */
33812 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
33813 -{
33814 - pud_t *pud;
33815 - pmd_t *pmd_table;
33816 -
33817 -#ifdef CONFIG_X86_PAE
33818 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
33819 - pmd_table = (pmd_t *)alloc_low_page();
33820 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
33821 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
33822 - pud = pud_offset(pgd, 0);
33823 - BUG_ON(pmd_table != pmd_offset(pud, 0));
33824 -
33825 - return pmd_table;
33826 - }
33827 -#endif
33828 - pud = pud_offset(pgd, 0);
33829 - pmd_table = pmd_offset(pud, 0);
33830 -
33831 - return pmd_table;
33832 -}
33833 -
33834 -/*
33835 * Create a page table and place a pointer to it in a middle page
33836 * directory entry:
33837 */
33838 @@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
33839 pte_t *page_table = (pte_t *)alloc_low_page();
33840
33841 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
33842 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
33843 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
33844 +#else
33845 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
33846 +#endif
33847 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
33848 }
33849
33850 return pte_offset_kernel(pmd, 0);
33851 }
33852
33853 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
33854 +{
33855 + pud_t *pud;
33856 + pmd_t *pmd_table;
33857 +
33858 + pud = pud_offset(pgd, 0);
33859 + pmd_table = pmd_offset(pud, 0);
33860 +
33861 + return pmd_table;
33862 +}
33863 +
33864 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
33865 {
33866 int pgd_idx = pgd_index(vaddr);
33867 @@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
33868 int pgd_idx, pmd_idx;
33869 unsigned long vaddr;
33870 pgd_t *pgd;
33871 + pud_t *pud;
33872 pmd_t *pmd;
33873 pte_t *pte = NULL;
33874 unsigned long count = page_table_range_init_count(start, end);
33875 @@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
33876 pgd = pgd_base + pgd_idx;
33877
33878 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
33879 - pmd = one_md_table_init(pgd);
33880 - pmd = pmd + pmd_index(vaddr);
33881 + pud = pud_offset(pgd, vaddr);
33882 + pmd = pmd_offset(pud, vaddr);
33883 +
33884 +#ifdef CONFIG_X86_PAE
33885 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
33886 +#endif
33887 +
33888 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
33889 pmd++, pmd_idx++) {
33890 pte = page_table_kmap_check(one_page_table_init(pmd),
33891 @@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
33892 }
33893 }
33894
33895 -static inline int is_kernel_text(unsigned long addr)
33896 +static inline int is_kernel_text(unsigned long start, unsigned long end)
33897 {
33898 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
33899 - return 1;
33900 - return 0;
33901 + if ((start >= ktla_ktva((unsigned long)_etext) ||
33902 + end <= ktla_ktva((unsigned long)_stext)) &&
33903 + (start >= ktla_ktva((unsigned long)_einittext) ||
33904 + end <= ktla_ktva((unsigned long)_sinittext)) &&
33905 +
33906 +#ifdef CONFIG_ACPI_SLEEP
33907 + (start >= (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
33908 +#endif
33909 +
33910 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
33911 + return 0;
33912 + return 1;
33913 }
33914
33915 /*
33916 @@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
33917 unsigned long last_map_addr = end;
33918 unsigned long start_pfn, end_pfn;
33919 pgd_t *pgd_base = swapper_pg_dir;
33920 - int pgd_idx, pmd_idx, pte_ofs;
33921 + unsigned int pgd_idx, pmd_idx, pte_ofs;
33922 unsigned long pfn;
33923 pgd_t *pgd;
33924 + pud_t *pud;
33925 pmd_t *pmd;
33926 pte_t *pte;
33927 unsigned pages_2m, pages_4k;
33928 @@ -291,8 +295,13 @@ repeat:
33929 pfn = start_pfn;
33930 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
33931 pgd = pgd_base + pgd_idx;
33932 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
33933 - pmd = one_md_table_init(pgd);
33934 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
33935 + pud = pud_offset(pgd, 0);
33936 + pmd = pmd_offset(pud, 0);
33937 +
33938 +#ifdef CONFIG_X86_PAE
33939 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
33940 +#endif
33941
33942 if (pfn >= end_pfn)
33943 continue;
33944 @@ -304,14 +313,13 @@ repeat:
33945 #endif
33946 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
33947 pmd++, pmd_idx++) {
33948 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
33949 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
33950
33951 /*
33952 * Map with big pages if possible, otherwise
33953 * create normal page tables:
33954 */
33955 if (use_pse) {
33956 - unsigned int addr2;
33957 pgprot_t prot = PAGE_KERNEL_LARGE;
33958 /*
33959 * first pass will use the same initial
33960 @@ -322,11 +330,7 @@ repeat:
33961 _PAGE_PSE);
33962
33963 pfn &= PMD_MASK >> PAGE_SHIFT;
33964 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
33965 - PAGE_OFFSET + PAGE_SIZE-1;
33966 -
33967 - if (is_kernel_text(addr) ||
33968 - is_kernel_text(addr2))
33969 + if (is_kernel_text(address, address + PMD_SIZE))
33970 prot = PAGE_KERNEL_LARGE_EXEC;
33971
33972 pages_2m++;
33973 @@ -343,7 +347,7 @@ repeat:
33974 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
33975 pte += pte_ofs;
33976 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
33977 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
33978 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
33979 pgprot_t prot = PAGE_KERNEL;
33980 /*
33981 * first pass will use the same initial
33982 @@ -351,7 +355,7 @@ repeat:
33983 */
33984 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
33985
33986 - if (is_kernel_text(addr))
33987 + if (is_kernel_text(address, address + PAGE_SIZE))
33988 prot = PAGE_KERNEL_EXEC;
33989
33990 pages_4k++;
33991 @@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
33992
33993 pud = pud_offset(pgd, va);
33994 pmd = pmd_offset(pud, va);
33995 - if (!pmd_present(*pmd))
33996 + if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
33997 break;
33998
33999 /* should not be large page here */
34000 @@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
34001
34002 static void __init pagetable_init(void)
34003 {
34004 - pgd_t *pgd_base = swapper_pg_dir;
34005 -
34006 - permanent_kmaps_init(pgd_base);
34007 + permanent_kmaps_init(swapper_pg_dir);
34008 }
34009
34010 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
34011 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
34012 EXPORT_SYMBOL_GPL(__supported_pte_mask);
34013
34014 /* user-defined highmem size */
34015 @@ -787,10 +789,10 @@ void __init mem_init(void)
34016 ((unsigned long)&__init_end -
34017 (unsigned long)&__init_begin) >> 10,
34018
34019 - (unsigned long)&_etext, (unsigned long)&_edata,
34020 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
34021 + (unsigned long)&_sdata, (unsigned long)&_edata,
34022 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
34023
34024 - (unsigned long)&_text, (unsigned long)&_etext,
34025 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
34026 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
34027
34028 /*
34029 @@ -884,6 +886,7 @@ void set_kernel_text_rw(void)
34030 if (!kernel_set_to_readonly)
34031 return;
34032
34033 + start = ktla_ktva(start);
34034 pr_debug("Set kernel text: %lx - %lx for read write\n",
34035 start, start+size);
34036
34037 @@ -898,6 +901,7 @@ void set_kernel_text_ro(void)
34038 if (!kernel_set_to_readonly)
34039 return;
34040
34041 + start = ktla_ktva(start);
34042 pr_debug("Set kernel text: %lx - %lx for read only\n",
34043 start, start+size);
34044
34045 @@ -926,6 +930,7 @@ void mark_rodata_ro(void)
34046 unsigned long start = PFN_ALIGN(_text);
34047 unsigned long size = PFN_ALIGN(_etext) - start;
34048
34049 + start = ktla_ktva(start);
34050 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
34051 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
34052 size >> 10);
34053 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
34054 index ac7de5f..ceb56df 100644
34055 --- a/arch/x86/mm/init_64.c
34056 +++ b/arch/x86/mm/init_64.c
34057 @@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
34058 * around without checking the pgd every time.
34059 */
34060
34061 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
34062 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
34063 EXPORT_SYMBOL_GPL(__supported_pte_mask);
34064
34065 int force_personality32;
34066 @@ -184,12 +184,29 @@ void sync_global_pgds(unsigned long start, unsigned long end)
34067
34068 for (address = start; address <= end; address += PGDIR_SIZE) {
34069 const pgd_t *pgd_ref = pgd_offset_k(address);
34070 +
34071 +#ifdef CONFIG_PAX_PER_CPU_PGD
34072 + unsigned long cpu;
34073 +#else
34074 struct page *page;
34075 +#endif
34076
34077 if (pgd_none(*pgd_ref))
34078 continue;
34079
34080 spin_lock(&pgd_lock);
34081 +
34082 +#ifdef CONFIG_PAX_PER_CPU_PGD
34083 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
34084 + pgd_t *pgd = pgd_offset_cpu(cpu, user, address);
34085 +
34086 + if (pgd_none(*pgd))
34087 + set_pgd(pgd, *pgd_ref);
34088 + else
34089 + BUG_ON(pgd_page_vaddr(*pgd)
34090 + != pgd_page_vaddr(*pgd_ref));
34091 + pgd = pgd_offset_cpu(cpu, kernel, address);
34092 +#else
34093 list_for_each_entry(page, &pgd_list, lru) {
34094 pgd_t *pgd;
34095 spinlock_t *pgt_lock;
34096 @@ -198,6 +215,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
34097 /* the pgt_lock only for Xen */
34098 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
34099 spin_lock(pgt_lock);
34100 +#endif
34101
34102 if (pgd_none(*pgd))
34103 set_pgd(pgd, *pgd_ref);
34104 @@ -205,7 +223,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
34105 BUG_ON(pgd_page_vaddr(*pgd)
34106 != pgd_page_vaddr(*pgd_ref));
34107
34108 +#ifndef CONFIG_PAX_PER_CPU_PGD
34109 spin_unlock(pgt_lock);
34110 +#endif
34111 +
34112 }
34113 spin_unlock(&pgd_lock);
34114 }
34115 @@ -238,7 +259,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
34116 {
34117 if (pgd_none(*pgd)) {
34118 pud_t *pud = (pud_t *)spp_getpage();
34119 - pgd_populate(&init_mm, pgd, pud);
34120 + pgd_populate_kernel(&init_mm, pgd, pud);
34121 if (pud != pud_offset(pgd, 0))
34122 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
34123 pud, pud_offset(pgd, 0));
34124 @@ -250,7 +271,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
34125 {
34126 if (pud_none(*pud)) {
34127 pmd_t *pmd = (pmd_t *) spp_getpage();
34128 - pud_populate(&init_mm, pud, pmd);
34129 + pud_populate_kernel(&init_mm, pud, pmd);
34130 if (pmd != pmd_offset(pud, 0))
34131 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
34132 pmd, pmd_offset(pud, 0));
34133 @@ -279,7 +300,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
34134 pmd = fill_pmd(pud, vaddr);
34135 pte = fill_pte(pmd, vaddr);
34136
34137 + pax_open_kernel();
34138 set_pte(pte, new_pte);
34139 + pax_close_kernel();
34140
34141 /*
34142 * It's enough to flush this one mapping.
34143 @@ -338,14 +361,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
34144 pgd = pgd_offset_k((unsigned long)__va(phys));
34145 if (pgd_none(*pgd)) {
34146 pud = (pud_t *) spp_getpage();
34147 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
34148 - _PAGE_USER));
34149 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
34150 }
34151 pud = pud_offset(pgd, (unsigned long)__va(phys));
34152 if (pud_none(*pud)) {
34153 pmd = (pmd_t *) spp_getpage();
34154 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
34155 - _PAGE_USER));
34156 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
34157 }
34158 pmd = pmd_offset(pud, phys);
34159 BUG_ON(!pmd_none(*pmd));
34160 @@ -586,7 +607,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
34161 prot);
34162
34163 spin_lock(&init_mm.page_table_lock);
34164 - pud_populate(&init_mm, pud, pmd);
34165 + pud_populate_kernel(&init_mm, pud, pmd);
34166 spin_unlock(&init_mm.page_table_lock);
34167 }
34168 __flush_tlb_all();
34169 @@ -627,7 +648,7 @@ kernel_physical_mapping_init(unsigned long start,
34170 page_size_mask);
34171
34172 spin_lock(&init_mm.page_table_lock);
34173 - pgd_populate(&init_mm, pgd, pud);
34174 + pgd_populate_kernel(&init_mm, pgd, pud);
34175 spin_unlock(&init_mm.page_table_lock);
34176 pgd_changed = true;
34177 }
34178 @@ -1205,8 +1226,8 @@ static struct vm_operations_struct gate_vma_ops = {
34179 static struct vm_area_struct gate_vma = {
34180 .vm_start = VSYSCALL_ADDR,
34181 .vm_end = VSYSCALL_ADDR + PAGE_SIZE,
34182 - .vm_page_prot = PAGE_READONLY_EXEC,
34183 - .vm_flags = VM_READ | VM_EXEC,
34184 + .vm_page_prot = PAGE_READONLY,
34185 + .vm_flags = VM_READ,
34186 .vm_ops = &gate_vma_ops,
34187 };
34188
34189 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
34190 index 7b179b49..6bd17777 100644
34191 --- a/arch/x86/mm/iomap_32.c
34192 +++ b/arch/x86/mm/iomap_32.c
34193 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
34194 type = kmap_atomic_idx_push();
34195 idx = type + KM_TYPE_NR * smp_processor_id();
34196 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
34197 +
34198 + pax_open_kernel();
34199 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
34200 + pax_close_kernel();
34201 +
34202 arch_flush_lazy_mmu_mode();
34203
34204 return (void *)vaddr;
34205 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
34206 index baff1da..2816ef4 100644
34207 --- a/arch/x86/mm/ioremap.c
34208 +++ b/arch/x86/mm/ioremap.c
34209 @@ -56,8 +56,8 @@ static int __ioremap_check_ram(unsigned long start_pfn, unsigned long nr_pages,
34210 unsigned long i;
34211
34212 for (i = 0; i < nr_pages; ++i)
34213 - if (pfn_valid(start_pfn + i) &&
34214 - !PageReserved(pfn_to_page(start_pfn + i)))
34215 + if (pfn_valid(start_pfn + i) && (start_pfn + i >= 0x100 ||
34216 + !PageReserved(pfn_to_page(start_pfn + i))))
34217 return 1;
34218
34219 WARN_ONCE(1, "ioremap on RAM pfn 0x%lx\n", start_pfn);
34220 @@ -268,7 +268,7 @@ EXPORT_SYMBOL(ioremap_prot);
34221 *
34222 * Caller must ensure there is only one unmapping for the same pointer.
34223 */
34224 -void iounmap(volatile void __iomem *addr)
34225 +void iounmap(const volatile void __iomem *addr)
34226 {
34227 struct vm_struct *p, *o;
34228
34229 @@ -322,6 +322,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
34230
34231 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
34232 if (page_is_ram(start >> PAGE_SHIFT))
34233 +#ifdef CONFIG_HIGHMEM
34234 + if ((start >> PAGE_SHIFT) < max_low_pfn)
34235 +#endif
34236 return __va(phys);
34237
34238 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
34239 @@ -334,13 +337,16 @@ void *xlate_dev_mem_ptr(unsigned long phys)
34240 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
34241 {
34242 if (page_is_ram(phys >> PAGE_SHIFT))
34243 +#ifdef CONFIG_HIGHMEM
34244 + if ((phys >> PAGE_SHIFT) < max_low_pfn)
34245 +#endif
34246 return;
34247
34248 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
34249 return;
34250 }
34251
34252 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
34253 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
34254
34255 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
34256 {
34257 @@ -376,8 +382,7 @@ void __init early_ioremap_init(void)
34258 early_ioremap_setup();
34259
34260 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
34261 - memset(bm_pte, 0, sizeof(bm_pte));
34262 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
34263 + pmd_populate_user(&init_mm, pmd, bm_pte);
34264
34265 /*
34266 * The boot-ioremap range spans multiple pmds, for which
34267 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
34268 index dd89a13..d77bdcc 100644
34269 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
34270 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
34271 @@ -628,9 +628,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
34272 * memory (e.g. tracked pages)? For now, we need this to avoid
34273 * invoking kmemcheck for PnP BIOS calls.
34274 */
34275 - if (regs->flags & X86_VM_MASK)
34276 + if (v8086_mode(regs))
34277 return false;
34278 - if (regs->cs != __KERNEL_CS)
34279 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
34280 return false;
34281
34282 pte = kmemcheck_pte_lookup(address);
34283 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
34284 index 919b912..9267313 100644
34285 --- a/arch/x86/mm/mmap.c
34286 +++ b/arch/x86/mm/mmap.c
34287 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
34288 * Leave an at least ~128 MB hole with possible stack randomization.
34289 */
34290 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
34291 -#define MAX_GAP (TASK_SIZE/6*5)
34292 +#define MAX_GAP (pax_task_size/6*5)
34293
34294 static int mmap_is_legacy(void)
34295 {
34296 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
34297 return rnd << PAGE_SHIFT;
34298 }
34299
34300 -static unsigned long mmap_base(void)
34301 +static unsigned long mmap_base(struct mm_struct *mm)
34302 {
34303 unsigned long gap = rlimit(RLIMIT_STACK);
34304 + unsigned long pax_task_size = TASK_SIZE;
34305 +
34306 +#ifdef CONFIG_PAX_SEGMEXEC
34307 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
34308 + pax_task_size = SEGMEXEC_TASK_SIZE;
34309 +#endif
34310
34311 if (gap < MIN_GAP)
34312 gap = MIN_GAP;
34313 else if (gap > MAX_GAP)
34314 gap = MAX_GAP;
34315
34316 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
34317 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
34318 }
34319
34320 /*
34321 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
34322 * does, but not when emulating X86_32
34323 */
34324 -static unsigned long mmap_legacy_base(void)
34325 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
34326 {
34327 - if (mmap_is_ia32())
34328 + if (mmap_is_ia32()) {
34329 +
34330 +#ifdef CONFIG_PAX_SEGMEXEC
34331 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
34332 + return SEGMEXEC_TASK_UNMAPPED_BASE;
34333 + else
34334 +#endif
34335 +
34336 return TASK_UNMAPPED_BASE;
34337 - else
34338 + } else
34339 return TASK_UNMAPPED_BASE + mmap_rnd();
34340 }
34341
34342 @@ -112,8 +125,15 @@ static unsigned long mmap_legacy_base(void)
34343 */
34344 void arch_pick_mmap_layout(struct mm_struct *mm)
34345 {
34346 - mm->mmap_legacy_base = mmap_legacy_base();
34347 - mm->mmap_base = mmap_base();
34348 + mm->mmap_legacy_base = mmap_legacy_base(mm);
34349 + mm->mmap_base = mmap_base(mm);
34350 +
34351 +#ifdef CONFIG_PAX_RANDMMAP
34352 + if (mm->pax_flags & MF_PAX_RANDMMAP) {
34353 + mm->mmap_legacy_base += mm->delta_mmap;
34354 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
34355 + }
34356 +#endif
34357
34358 if (mmap_is_legacy()) {
34359 mm->mmap_base = mm->mmap_legacy_base;
34360 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
34361 index 0057a7a..95c7edd 100644
34362 --- a/arch/x86/mm/mmio-mod.c
34363 +++ b/arch/x86/mm/mmio-mod.c
34364 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
34365 break;
34366 default:
34367 {
34368 - unsigned char *ip = (unsigned char *)instptr;
34369 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
34370 my_trace->opcode = MMIO_UNKNOWN_OP;
34371 my_trace->width = 0;
34372 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
34373 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
34374 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
34375 void __iomem *addr)
34376 {
34377 - static atomic_t next_id;
34378 + static atomic_unchecked_t next_id;
34379 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
34380 /* These are page-unaligned. */
34381 struct mmiotrace_map map = {
34382 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
34383 .private = trace
34384 },
34385 .phys = offset,
34386 - .id = atomic_inc_return(&next_id)
34387 + .id = atomic_inc_return_unchecked(&next_id)
34388 };
34389 map.map_id = trace->id;
34390
34391 @@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
34392 ioremap_trace_core(offset, size, addr);
34393 }
34394
34395 -static void iounmap_trace_core(volatile void __iomem *addr)
34396 +static void iounmap_trace_core(const volatile void __iomem *addr)
34397 {
34398 struct mmiotrace_map map = {
34399 .phys = 0,
34400 @@ -328,7 +328,7 @@ not_enabled:
34401 }
34402 }
34403
34404 -void mmiotrace_iounmap(volatile void __iomem *addr)
34405 +void mmiotrace_iounmap(const volatile void __iomem *addr)
34406 {
34407 might_sleep();
34408 if (is_enabled()) /* recheck and proper locking in *_core() */
34409 diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
34410 index a32b706..efb308b 100644
34411 --- a/arch/x86/mm/numa.c
34412 +++ b/arch/x86/mm/numa.c
34413 @@ -478,7 +478,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
34414 return true;
34415 }
34416
34417 -static int __init numa_register_memblks(struct numa_meminfo *mi)
34418 +static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
34419 {
34420 unsigned long uninitialized_var(pfn_align);
34421 int i, nid;
34422 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
34423 index 36de293..b820ddc 100644
34424 --- a/arch/x86/mm/pageattr.c
34425 +++ b/arch/x86/mm/pageattr.c
34426 @@ -262,7 +262,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
34427 */
34428 #ifdef CONFIG_PCI_BIOS
34429 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
34430 - pgprot_val(forbidden) |= _PAGE_NX;
34431 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
34432 #endif
34433
34434 /*
34435 @@ -270,9 +270,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
34436 * Does not cover __inittext since that is gone later on. On
34437 * 64bit we do not enforce !NX on the low mapping
34438 */
34439 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
34440 - pgprot_val(forbidden) |= _PAGE_NX;
34441 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
34442 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
34443
34444 +#ifdef CONFIG_DEBUG_RODATA
34445 /*
34446 * The .rodata section needs to be read-only. Using the pfn
34447 * catches all aliases.
34448 @@ -280,6 +281,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
34449 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
34450 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
34451 pgprot_val(forbidden) |= _PAGE_RW;
34452 +#endif
34453
34454 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
34455 /*
34456 @@ -318,6 +320,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
34457 }
34458 #endif
34459
34460 +#ifdef CONFIG_PAX_KERNEXEC
34461 + if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
34462 + pgprot_val(forbidden) |= _PAGE_RW;
34463 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
34464 + }
34465 +#endif
34466 +
34467 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
34468
34469 return prot;
34470 @@ -420,23 +429,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
34471 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
34472 {
34473 /* change init_mm */
34474 + pax_open_kernel();
34475 set_pte_atomic(kpte, pte);
34476 +
34477 #ifdef CONFIG_X86_32
34478 if (!SHARED_KERNEL_PMD) {
34479 +
34480 +#ifdef CONFIG_PAX_PER_CPU_PGD
34481 + unsigned long cpu;
34482 +#else
34483 struct page *page;
34484 +#endif
34485
34486 +#ifdef CONFIG_PAX_PER_CPU_PGD
34487 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
34488 + pgd_t *pgd = get_cpu_pgd(cpu, kernel);
34489 +#else
34490 list_for_each_entry(page, &pgd_list, lru) {
34491 - pgd_t *pgd;
34492 + pgd_t *pgd = (pgd_t *)page_address(page);
34493 +#endif
34494 +
34495 pud_t *pud;
34496 pmd_t *pmd;
34497
34498 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
34499 + pgd += pgd_index(address);
34500 pud = pud_offset(pgd, address);
34501 pmd = pmd_offset(pud, address);
34502 set_pte_atomic((pte_t *)pmd, pte);
34503 }
34504 }
34505 #endif
34506 + pax_close_kernel();
34507 }
34508
34509 static int
34510 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
34511 index 6574388..87e9bef 100644
34512 --- a/arch/x86/mm/pat.c
34513 +++ b/arch/x86/mm/pat.c
34514 @@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
34515
34516 if (!entry) {
34517 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
34518 - current->comm, current->pid, start, end - 1);
34519 + current->comm, task_pid_nr(current), start, end - 1);
34520 return -EINVAL;
34521 }
34522
34523 @@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
34524
34525 while (cursor < to) {
34526 if (!devmem_is_allowed(pfn)) {
34527 - printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
34528 - current->comm, from, to - 1);
34529 + printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
34530 + current->comm, from, to - 1, cursor);
34531 return 0;
34532 }
34533 cursor += PAGE_SIZE;
34534 @@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
34535 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
34536 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
34537 "for [mem %#010Lx-%#010Lx]\n",
34538 - current->comm, current->pid,
34539 + current->comm, task_pid_nr(current),
34540 cattr_name(flags),
34541 base, (unsigned long long)(base + size-1));
34542 return -EINVAL;
34543 @@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
34544 flags = lookup_memtype(paddr);
34545 if (want_flags != flags) {
34546 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
34547 - current->comm, current->pid,
34548 + current->comm, task_pid_nr(current),
34549 cattr_name(want_flags),
34550 (unsigned long long)paddr,
34551 (unsigned long long)(paddr + size - 1),
34552 @@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
34553 free_memtype(paddr, paddr + size);
34554 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
34555 " for [mem %#010Lx-%#010Lx], got %s\n",
34556 - current->comm, current->pid,
34557 + current->comm, task_pid_nr(current),
34558 cattr_name(want_flags),
34559 (unsigned long long)paddr,
34560 (unsigned long long)(paddr + size - 1),
34561 diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
34562 index 415f6c4..d319983 100644
34563 --- a/arch/x86/mm/pat_rbtree.c
34564 +++ b/arch/x86/mm/pat_rbtree.c
34565 @@ -160,7 +160,7 @@ success:
34566
34567 failure:
34568 printk(KERN_INFO "%s:%d conflicting memory types "
34569 - "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
34570 + "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
34571 end, cattr_name(found_type), cattr_name(match->type));
34572 return -EBUSY;
34573 }
34574 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
34575 index 9f0614d..92ae64a 100644
34576 --- a/arch/x86/mm/pf_in.c
34577 +++ b/arch/x86/mm/pf_in.c
34578 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
34579 int i;
34580 enum reason_type rv = OTHERS;
34581
34582 - p = (unsigned char *)ins_addr;
34583 + p = (unsigned char *)ktla_ktva(ins_addr);
34584 p += skip_prefix(p, &prf);
34585 p += get_opcode(p, &opcode);
34586
34587 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
34588 struct prefix_bits prf;
34589 int i;
34590
34591 - p = (unsigned char *)ins_addr;
34592 + p = (unsigned char *)ktla_ktva(ins_addr);
34593 p += skip_prefix(p, &prf);
34594 p += get_opcode(p, &opcode);
34595
34596 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
34597 struct prefix_bits prf;
34598 int i;
34599
34600 - p = (unsigned char *)ins_addr;
34601 + p = (unsigned char *)ktla_ktva(ins_addr);
34602 p += skip_prefix(p, &prf);
34603 p += get_opcode(p, &opcode);
34604
34605 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
34606 struct prefix_bits prf;
34607 int i;
34608
34609 - p = (unsigned char *)ins_addr;
34610 + p = (unsigned char *)ktla_ktva(ins_addr);
34611 p += skip_prefix(p, &prf);
34612 p += get_opcode(p, &opcode);
34613 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
34614 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
34615 struct prefix_bits prf;
34616 int i;
34617
34618 - p = (unsigned char *)ins_addr;
34619 + p = (unsigned char *)ktla_ktva(ins_addr);
34620 p += skip_prefix(p, &prf);
34621 p += get_opcode(p, &opcode);
34622 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
34623 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
34624 index 6fb6927..4fc13c0 100644
34625 --- a/arch/x86/mm/pgtable.c
34626 +++ b/arch/x86/mm/pgtable.c
34627 @@ -97,10 +97,71 @@ static inline void pgd_list_del(pgd_t *pgd)
34628 list_del(&page->lru);
34629 }
34630
34631 -#define UNSHARED_PTRS_PER_PGD \
34632 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
34633 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
34634 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
34635
34636 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
34637 +{
34638 + unsigned int count = USER_PGD_PTRS;
34639
34640 + if (!pax_user_shadow_base)
34641 + return;
34642 +
34643 + while (count--)
34644 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
34645 +}
34646 +#endif
34647 +
34648 +#ifdef CONFIG_PAX_PER_CPU_PGD
34649 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
34650 +{
34651 + unsigned int count = USER_PGD_PTRS;
34652 +
34653 + while (count--) {
34654 + pgd_t pgd;
34655 +
34656 +#ifdef CONFIG_X86_64
34657 + pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
34658 +#else
34659 + pgd = *src++;
34660 +#endif
34661 +
34662 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
34663 + pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
34664 +#endif
34665 +
34666 + *dst++ = pgd;
34667 + }
34668 +
34669 +}
34670 +#endif
34671 +
34672 +#ifdef CONFIG_X86_64
34673 +#define pxd_t pud_t
34674 +#define pyd_t pgd_t
34675 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
34676 +#define pgtable_pxd_page_ctor(page) true
34677 +#define pgtable_pxd_page_dtor(page)
34678 +#define pxd_free(mm, pud) pud_free((mm), (pud))
34679 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
34680 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
34681 +#define PYD_SIZE PGDIR_SIZE
34682 +#else
34683 +#define pxd_t pmd_t
34684 +#define pyd_t pud_t
34685 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
34686 +#define pgtable_pxd_page_ctor(page) pgtable_pmd_page_ctor(page)
34687 +#define pgtable_pxd_page_dtor(page) pgtable_pmd_page_dtor(page)
34688 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
34689 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
34690 +#define pyd_offset(mm, address) pud_offset((mm), (address))
34691 +#define PYD_SIZE PUD_SIZE
34692 +#endif
34693 +
34694 +#ifdef CONFIG_PAX_PER_CPU_PGD
34695 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
34696 +static inline void pgd_dtor(pgd_t *pgd) {}
34697 +#else
34698 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
34699 {
34700 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
34701 @@ -141,6 +202,7 @@ static void pgd_dtor(pgd_t *pgd)
34702 pgd_list_del(pgd);
34703 spin_unlock(&pgd_lock);
34704 }
34705 +#endif
34706
34707 /*
34708 * List of all pgd's needed for non-PAE so it can invalidate entries
34709 @@ -153,7 +215,7 @@ static void pgd_dtor(pgd_t *pgd)
34710 * -- nyc
34711 */
34712
34713 -#ifdef CONFIG_X86_PAE
34714 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
34715 /*
34716 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
34717 * updating the top-level pagetable entries to guarantee the
34718 @@ -165,7 +227,7 @@ static void pgd_dtor(pgd_t *pgd)
34719 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
34720 * and initialize the kernel pmds here.
34721 */
34722 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
34723 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
34724
34725 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
34726 {
34727 @@ -183,43 +245,45 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
34728 */
34729 flush_tlb_mm(mm);
34730 }
34731 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
34732 +#define PREALLOCATED_PXDS USER_PGD_PTRS
34733 #else /* !CONFIG_X86_PAE */
34734
34735 /* No need to prepopulate any pagetable entries in non-PAE modes. */
34736 -#define PREALLOCATED_PMDS 0
34737 +#define PREALLOCATED_PXDS 0
34738
34739 #endif /* CONFIG_X86_PAE */
34740
34741 -static void free_pmds(pmd_t *pmds[])
34742 +static void free_pxds(pxd_t *pxds[])
34743 {
34744 int i;
34745
34746 - for(i = 0; i < PREALLOCATED_PMDS; i++)
34747 - if (pmds[i]) {
34748 - pgtable_pmd_page_dtor(virt_to_page(pmds[i]));
34749 - free_page((unsigned long)pmds[i]);
34750 + for(i = 0; i < PREALLOCATED_PXDS; i++)
34751 + if (pxds[i]) {
34752 + pgtable_pxd_page_dtor(virt_to_page(pxds[i]));
34753 + free_page((unsigned long)pxds[i]);
34754 }
34755 }
34756
34757 -static int preallocate_pmds(pmd_t *pmds[])
34758 +static int preallocate_pxds(pxd_t *pxds[])
34759 {
34760 int i;
34761 bool failed = false;
34762
34763 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
34764 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
34765 - if (!pmd)
34766 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
34767 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
34768 + if (!pxd)
34769 failed = true;
34770 - if (pmd && !pgtable_pmd_page_ctor(virt_to_page(pmd))) {
34771 - free_page((unsigned long)pmd);
34772 - pmd = NULL;
34773 + if (pxd && !pgtable_pxd_page_ctor(virt_to_page(pxd))) {
34774 + free_page((unsigned long)pxd);
34775 + pxd = NULL;
34776 failed = true;
34777 }
34778 - pmds[i] = pmd;
34779 + pxds[i] = pxd;
34780 }
34781
34782 if (failed) {
34783 - free_pmds(pmds);
34784 + free_pxds(pxds);
34785 return -ENOMEM;
34786 }
34787
34788 @@ -232,49 +296,52 @@ static int preallocate_pmds(pmd_t *pmds[])
34789 * preallocate which never got a corresponding vma will need to be
34790 * freed manually.
34791 */
34792 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
34793 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
34794 {
34795 int i;
34796
34797 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
34798 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
34799 pgd_t pgd = pgdp[i];
34800
34801 if (pgd_val(pgd) != 0) {
34802 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
34803 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
34804
34805 - pgdp[i] = native_make_pgd(0);
34806 + set_pgd(pgdp + i, native_make_pgd(0));
34807
34808 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
34809 - pmd_free(mm, pmd);
34810 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
34811 + pxd_free(mm, pxd);
34812 }
34813 }
34814 }
34815
34816 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
34817 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
34818 {
34819 - pud_t *pud;
34820 + pyd_t *pyd;
34821 int i;
34822
34823 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
34824 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
34825 return;
34826
34827 - pud = pud_offset(pgd, 0);
34828 -
34829 - for (i = 0; i < PREALLOCATED_PMDS; i++, pud++) {
34830 - pmd_t *pmd = pmds[i];
34831 +#ifdef CONFIG_X86_64
34832 + pyd = pyd_offset(mm, 0L);
34833 +#else
34834 + pyd = pyd_offset(pgd, 0L);
34835 +#endif
34836
34837 + for (i = 0; i < PREALLOCATED_PXDS; i++, pyd++) {
34838 + pxd_t *pxd = pxds[i];
34839 if (i >= KERNEL_PGD_BOUNDARY)
34840 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
34841 - sizeof(pmd_t) * PTRS_PER_PMD);
34842 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
34843 + sizeof(pxd_t) * PTRS_PER_PMD);
34844
34845 - pud_populate(mm, pud, pmd);
34846 + pyd_populate(mm, pyd, pxd);
34847 }
34848 }
34849
34850 pgd_t *pgd_alloc(struct mm_struct *mm)
34851 {
34852 pgd_t *pgd;
34853 - pmd_t *pmds[PREALLOCATED_PMDS];
34854 + pxd_t *pxds[PREALLOCATED_PXDS];
34855
34856 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
34857
34858 @@ -283,11 +350,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
34859
34860 mm->pgd = pgd;
34861
34862 - if (preallocate_pmds(pmds) != 0)
34863 + if (preallocate_pxds(pxds) != 0)
34864 goto out_free_pgd;
34865
34866 if (paravirt_pgd_alloc(mm) != 0)
34867 - goto out_free_pmds;
34868 + goto out_free_pxds;
34869
34870 /*
34871 * Make sure that pre-populating the pmds is atomic with
34872 @@ -297,14 +364,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
34873 spin_lock(&pgd_lock);
34874
34875 pgd_ctor(mm, pgd);
34876 - pgd_prepopulate_pmd(mm, pgd, pmds);
34877 + pgd_prepopulate_pxd(mm, pgd, pxds);
34878
34879 spin_unlock(&pgd_lock);
34880
34881 return pgd;
34882
34883 -out_free_pmds:
34884 - free_pmds(pmds);
34885 +out_free_pxds:
34886 + free_pxds(pxds);
34887 out_free_pgd:
34888 free_page((unsigned long)pgd);
34889 out:
34890 @@ -313,7 +380,7 @@ out:
34891
34892 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
34893 {
34894 - pgd_mop_up_pmds(mm, pgd);
34895 + pgd_mop_up_pxds(mm, pgd);
34896 pgd_dtor(pgd);
34897 paravirt_pgd_free(mm, pgd);
34898 free_page((unsigned long)pgd);
34899 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
34900 index 4dd8cf6..f9d143e 100644
34901 --- a/arch/x86/mm/pgtable_32.c
34902 +++ b/arch/x86/mm/pgtable_32.c
34903 @@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
34904 return;
34905 }
34906 pte = pte_offset_kernel(pmd, vaddr);
34907 +
34908 + pax_open_kernel();
34909 if (pte_val(pteval))
34910 set_pte_at(&init_mm, vaddr, pte, pteval);
34911 else
34912 pte_clear(&init_mm, vaddr, pte);
34913 + pax_close_kernel();
34914
34915 /*
34916 * It's enough to flush this one mapping.
34917 diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
34918 index e666cbb..61788c45 100644
34919 --- a/arch/x86/mm/physaddr.c
34920 +++ b/arch/x86/mm/physaddr.c
34921 @@ -10,7 +10,7 @@
34922 #ifdef CONFIG_X86_64
34923
34924 #ifdef CONFIG_DEBUG_VIRTUAL
34925 -unsigned long __phys_addr(unsigned long x)
34926 +unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
34927 {
34928 unsigned long y = x - __START_KERNEL_map;
34929
34930 @@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
34931 #else
34932
34933 #ifdef CONFIG_DEBUG_VIRTUAL
34934 -unsigned long __phys_addr(unsigned long x)
34935 +unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
34936 {
34937 unsigned long phys_addr = x - PAGE_OFFSET;
34938 /* VMALLOC_* aren't constants */
34939 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
34940 index 90555bf..f5f1828 100644
34941 --- a/arch/x86/mm/setup_nx.c
34942 +++ b/arch/x86/mm/setup_nx.c
34943 @@ -5,8 +5,10 @@
34944 #include <asm/pgtable.h>
34945 #include <asm/proto.h>
34946
34947 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
34948 static int disable_nx;
34949
34950 +#ifndef CONFIG_PAX_PAGEEXEC
34951 /*
34952 * noexec = on|off
34953 *
34954 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
34955 return 0;
34956 }
34957 early_param("noexec", noexec_setup);
34958 +#endif
34959 +
34960 +#endif
34961
34962 void x86_configure_nx(void)
34963 {
34964 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
34965 if (cpu_has_nx && !disable_nx)
34966 __supported_pte_mask |= _PAGE_NX;
34967 else
34968 +#endif
34969 __supported_pte_mask &= ~_PAGE_NX;
34970 }
34971
34972 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
34973 index ee61c36..e6fedeb 100644
34974 --- a/arch/x86/mm/tlb.c
34975 +++ b/arch/x86/mm/tlb.c
34976 @@ -48,7 +48,11 @@ void leave_mm(int cpu)
34977 BUG();
34978 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
34979 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
34980 +
34981 +#ifndef CONFIG_PAX_PER_CPU_PGD
34982 load_cr3(swapper_pg_dir);
34983 +#endif
34984 +
34985 /*
34986 * This gets called in the idle path where RCU
34987 * functions differently. Tracing normally
34988 diff --git a/arch/x86/mm/uderef_64.c b/arch/x86/mm/uderef_64.c
34989 new file mode 100644
34990 index 0000000..dace51c
34991 --- /dev/null
34992 +++ b/arch/x86/mm/uderef_64.c
34993 @@ -0,0 +1,37 @@
34994 +#include <linux/mm.h>
34995 +#include <asm/pgtable.h>
34996 +#include <asm/uaccess.h>
34997 +
34998 +#ifdef CONFIG_PAX_MEMORY_UDEREF
34999 +/* PaX: due to the special call convention these functions must
35000 + * - remain leaf functions under all configurations,
35001 + * - never be called directly, only dereferenced from the wrappers.
35002 + */
35003 +void __pax_open_userland(void)
35004 +{
35005 + unsigned int cpu;
35006 +
35007 + if (unlikely(!segment_eq(get_fs(), USER_DS)))
35008 + return;
35009 +
35010 + cpu = raw_get_cpu();
35011 + BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_KERNEL);
35012 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
35013 + raw_put_cpu_no_resched();
35014 +}
35015 +EXPORT_SYMBOL(__pax_open_userland);
35016 +
35017 +void __pax_close_userland(void)
35018 +{
35019 + unsigned int cpu;
35020 +
35021 + if (unlikely(!segment_eq(get_fs(), USER_DS)))
35022 + return;
35023 +
35024 + cpu = raw_get_cpu();
35025 + BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_USER);
35026 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
35027 + raw_put_cpu_no_resched();
35028 +}
35029 +EXPORT_SYMBOL(__pax_close_userland);
35030 +#endif
35031 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
35032 index 6440221..f84b5c7 100644
35033 --- a/arch/x86/net/bpf_jit.S
35034 +++ b/arch/x86/net/bpf_jit.S
35035 @@ -9,6 +9,7 @@
35036 */
35037 #include <linux/linkage.h>
35038 #include <asm/dwarf2.h>
35039 +#include <asm/alternative-asm.h>
35040
35041 /*
35042 * Calling convention :
35043 @@ -38,6 +39,7 @@ sk_load_word_positive_offset:
35044 jle bpf_slow_path_word
35045 mov (SKBDATA,%rsi),%eax
35046 bswap %eax /* ntohl() */
35047 + pax_force_retaddr
35048 ret
35049
35050 sk_load_half:
35051 @@ -55,6 +57,7 @@ sk_load_half_positive_offset:
35052 jle bpf_slow_path_half
35053 movzwl (SKBDATA,%rsi),%eax
35054 rol $8,%ax # ntohs()
35055 + pax_force_retaddr
35056 ret
35057
35058 sk_load_byte:
35059 @@ -69,6 +72,7 @@ sk_load_byte_positive_offset:
35060 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
35061 jle bpf_slow_path_byte
35062 movzbl (SKBDATA,%rsi),%eax
35063 + pax_force_retaddr
35064 ret
35065
35066 /* rsi contains offset and can be scratched */
35067 @@ -90,6 +94,7 @@ bpf_slow_path_word:
35068 js bpf_error
35069 mov - MAX_BPF_STACK + 32(%rbp),%eax
35070 bswap %eax
35071 + pax_force_retaddr
35072 ret
35073
35074 bpf_slow_path_half:
35075 @@ -98,12 +103,14 @@ bpf_slow_path_half:
35076 mov - MAX_BPF_STACK + 32(%rbp),%ax
35077 rol $8,%ax
35078 movzwl %ax,%eax
35079 + pax_force_retaddr
35080 ret
35081
35082 bpf_slow_path_byte:
35083 bpf_slow_path_common(1)
35084 js bpf_error
35085 movzbl - MAX_BPF_STACK + 32(%rbp),%eax
35086 + pax_force_retaddr
35087 ret
35088
35089 #define sk_negative_common(SIZE) \
35090 @@ -126,6 +133,7 @@ sk_load_word_negative_offset:
35091 sk_negative_common(4)
35092 mov (%rax), %eax
35093 bswap %eax
35094 + pax_force_retaddr
35095 ret
35096
35097 bpf_slow_path_half_neg:
35098 @@ -137,6 +145,7 @@ sk_load_half_negative_offset:
35099 mov (%rax),%ax
35100 rol $8,%ax
35101 movzwl %ax,%eax
35102 + pax_force_retaddr
35103 ret
35104
35105 bpf_slow_path_byte_neg:
35106 @@ -146,6 +155,7 @@ sk_load_byte_negative_offset:
35107 .globl sk_load_byte_negative_offset
35108 sk_negative_common(1)
35109 movzbl (%rax), %eax
35110 + pax_force_retaddr
35111 ret
35112
35113 bpf_error:
35114 @@ -156,4 +166,5 @@ bpf_error:
35115 mov - MAX_BPF_STACK + 16(%rbp),%r14
35116 mov - MAX_BPF_STACK + 24(%rbp),%r15
35117 leaveq
35118 + pax_force_retaddr
35119 ret
35120 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
35121 index c881ba8..71aca2e 100644
35122 --- a/arch/x86/net/bpf_jit_comp.c
35123 +++ b/arch/x86/net/bpf_jit_comp.c
35124 @@ -15,7 +15,11 @@
35125 #include <linux/if_vlan.h>
35126 #include <linux/random.h>
35127
35128 +#ifdef CONFIG_GRKERNSEC_BPF_HARDEN
35129 +int bpf_jit_enable __read_only;
35130 +#else
35131 int bpf_jit_enable __read_mostly;
35132 +#endif
35133
35134 /*
35135 * assembly code in arch/x86/net/bpf_jit.S
35136 @@ -109,36 +113,32 @@ static inline void bpf_flush_icache(void *start, void *end)
35137 #define CHOOSE_LOAD_FUNC(K, func) \
35138 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
35139
35140 -struct bpf_binary_header {
35141 - unsigned int pages;
35142 - /* Note : for security reasons, bpf code will follow a randomly
35143 - * sized amount of int3 instructions
35144 - */
35145 - u8 image[];
35146 -};
35147 -
35148 -static struct bpf_binary_header *bpf_alloc_binary(unsigned int proglen,
35149 +/* Note : for security reasons, bpf code will follow a randomly
35150 + * sized amount of int3 instructions
35151 + */
35152 +static u8 *bpf_alloc_binary(unsigned int proglen,
35153 u8 **image_ptr)
35154 {
35155 unsigned int sz, hole;
35156 - struct bpf_binary_header *header;
35157 + u8 *header;
35158
35159 /* Most of BPF filters are really small,
35160 * but if some of them fill a page, allow at least
35161 * 128 extra bytes to insert a random section of int3
35162 */
35163 - sz = round_up(proglen + sizeof(*header) + 128, PAGE_SIZE);
35164 - header = module_alloc(sz);
35165 + sz = round_up(proglen + 128, PAGE_SIZE);
35166 + header = module_alloc_exec(sz);
35167 if (!header)
35168 return NULL;
35169
35170 + pax_open_kernel();
35171 memset(header, 0xcc, sz); /* fill whole space with int3 instructions */
35172 + pax_close_kernel();
35173
35174 - header->pages = sz / PAGE_SIZE;
35175 - hole = min(sz - (proglen + sizeof(*header)), PAGE_SIZE - sizeof(*header));
35176 + hole = PAGE_SIZE - (proglen & ~PAGE_MASK);
35177
35178 /* insert a random number of int3 instructions before BPF code */
35179 - *image_ptr = &header->image[prandom_u32() % hole];
35180 + *image_ptr = &header[prandom_u32() % hole];
35181 return header;
35182 }
35183
35184 @@ -864,7 +864,9 @@ common_load:
35185 pr_err("bpf_jit_compile fatal error\n");
35186 return -EFAULT;
35187 }
35188 + pax_open_kernel();
35189 memcpy(image + proglen, temp, ilen);
35190 + pax_close_kernel();
35191 }
35192 proglen += ilen;
35193 addrs[i] = proglen;
35194 @@ -879,7 +881,7 @@ void bpf_jit_compile(struct bpf_prog *prog)
35195
35196 void bpf_int_jit_compile(struct bpf_prog *prog)
35197 {
35198 - struct bpf_binary_header *header = NULL;
35199 + u8 *header = NULL;
35200 int proglen, oldproglen = 0;
35201 struct jit_context ctx = {};
35202 u8 *image = NULL;
35203 @@ -911,7 +913,7 @@ void bpf_int_jit_compile(struct bpf_prog *prog)
35204 if (proglen <= 0) {
35205 image = NULL;
35206 if (header)
35207 - module_free(NULL, header);
35208 + module_free_exec(NULL, image);
35209 goto out;
35210 }
35211 if (image) {
35212 @@ -935,7 +937,6 @@ void bpf_int_jit_compile(struct bpf_prog *prog)
35213
35214 if (image) {
35215 bpf_flush_icache(header, image + proglen);
35216 - set_memory_ro((unsigned long)header, header->pages);
35217 prog->bpf_func = (void *)image;
35218 prog->jited = 1;
35219 }
35220 @@ -943,23 +944,15 @@ out:
35221 kfree(addrs);
35222 }
35223
35224 -static void bpf_jit_free_deferred(struct work_struct *work)
35225 -{
35226 - struct bpf_prog *fp = container_of(work, struct bpf_prog, work);
35227 - unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
35228 - struct bpf_binary_header *header = (void *)addr;
35229 -
35230 - set_memory_rw(addr, header->pages);
35231 - module_free(NULL, header);
35232 - kfree(fp);
35233 -}
35234 -
35235 void bpf_jit_free(struct bpf_prog *fp)
35236 {
35237 - if (fp->jited) {
35238 - INIT_WORK(&fp->work, bpf_jit_free_deferred);
35239 - schedule_work(&fp->work);
35240 - } else {
35241 - kfree(fp);
35242 - }
35243 + unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
35244 +
35245 + if (!fp->jited)
35246 + goto free_filter;
35247 +
35248 + module_free_exec(NULL, (void *)addr);
35249 +
35250 +free_filter:
35251 + bpf_prog_unlock_free(fp);
35252 }
35253 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
35254 index 5d04be5..2beeaa2 100644
35255 --- a/arch/x86/oprofile/backtrace.c
35256 +++ b/arch/x86/oprofile/backtrace.c
35257 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
35258 struct stack_frame_ia32 *fp;
35259 unsigned long bytes;
35260
35261 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
35262 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
35263 if (bytes != 0)
35264 return NULL;
35265
35266 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
35267 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
35268
35269 oprofile_add_trace(bufhead[0].return_address);
35270
35271 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
35272 struct stack_frame bufhead[2];
35273 unsigned long bytes;
35274
35275 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
35276 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
35277 if (bytes != 0)
35278 return NULL;
35279
35280 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
35281 {
35282 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
35283
35284 - if (!user_mode_vm(regs)) {
35285 + if (!user_mode(regs)) {
35286 unsigned long stack = kernel_stack_pointer(regs);
35287 if (depth)
35288 dump_trace(NULL, regs, (unsigned long *)stack, 0,
35289 diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
35290 index 379e8bd..6386e09 100644
35291 --- a/arch/x86/oprofile/nmi_int.c
35292 +++ b/arch/x86/oprofile/nmi_int.c
35293 @@ -23,6 +23,7 @@
35294 #include <asm/nmi.h>
35295 #include <asm/msr.h>
35296 #include <asm/apic.h>
35297 +#include <asm/pgtable.h>
35298
35299 #include "op_counter.h"
35300 #include "op_x86_model.h"
35301 @@ -785,8 +786,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
35302 if (ret)
35303 return ret;
35304
35305 - if (!model->num_virt_counters)
35306 - model->num_virt_counters = model->num_counters;
35307 + if (!model->num_virt_counters) {
35308 + pax_open_kernel();
35309 + *(unsigned int *)&model->num_virt_counters = model->num_counters;
35310 + pax_close_kernel();
35311 + }
35312
35313 mux_init(ops);
35314
35315 diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
35316 index 50d86c0..7985318 100644
35317 --- a/arch/x86/oprofile/op_model_amd.c
35318 +++ b/arch/x86/oprofile/op_model_amd.c
35319 @@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
35320 num_counters = AMD64_NUM_COUNTERS;
35321 }
35322
35323 - op_amd_spec.num_counters = num_counters;
35324 - op_amd_spec.num_controls = num_counters;
35325 - op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
35326 + pax_open_kernel();
35327 + *(unsigned int *)&op_amd_spec.num_counters = num_counters;
35328 + *(unsigned int *)&op_amd_spec.num_controls = num_counters;
35329 + *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
35330 + pax_close_kernel();
35331
35332 return 0;
35333 }
35334 diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
35335 index d90528e..0127e2b 100644
35336 --- a/arch/x86/oprofile/op_model_ppro.c
35337 +++ b/arch/x86/oprofile/op_model_ppro.c
35338 @@ -19,6 +19,7 @@
35339 #include <asm/msr.h>
35340 #include <asm/apic.h>
35341 #include <asm/nmi.h>
35342 +#include <asm/pgtable.h>
35343
35344 #include "op_x86_model.h"
35345 #include "op_counter.h"
35346 @@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
35347
35348 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
35349
35350 - op_arch_perfmon_spec.num_counters = num_counters;
35351 - op_arch_perfmon_spec.num_controls = num_counters;
35352 + pax_open_kernel();
35353 + *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
35354 + *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
35355 + pax_close_kernel();
35356 }
35357
35358 static int arch_perfmon_init(struct oprofile_operations *ignore)
35359 diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
35360 index 71e8a67..6a313bb 100644
35361 --- a/arch/x86/oprofile/op_x86_model.h
35362 +++ b/arch/x86/oprofile/op_x86_model.h
35363 @@ -52,7 +52,7 @@ struct op_x86_model_spec {
35364 void (*switch_ctrl)(struct op_x86_model_spec const *model,
35365 struct op_msrs const * const msrs);
35366 #endif
35367 -};
35368 +} __do_const;
35369
35370 struct op_counter_config;
35371
35372 diff --git a/arch/x86/pci/intel_mid_pci.c b/arch/x86/pci/intel_mid_pci.c
35373 index b9958c3..24229ab 100644
35374 --- a/arch/x86/pci/intel_mid_pci.c
35375 +++ b/arch/x86/pci/intel_mid_pci.c
35376 @@ -250,7 +250,7 @@ int __init intel_mid_pci_init(void)
35377 pci_mmcfg_late_init();
35378 pcibios_enable_irq = intel_mid_pci_irq_enable;
35379 pcibios_disable_irq = intel_mid_pci_irq_disable;
35380 - pci_root_ops = intel_mid_pci_ops;
35381 + memcpy((void *)&pci_root_ops, &intel_mid_pci_ops, sizeof pci_root_ops);
35382 pci_soc_mode = 1;
35383 /* Continue with standard init */
35384 return 1;
35385 diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
35386 index eb500c2..eab9e70 100644
35387 --- a/arch/x86/pci/irq.c
35388 +++ b/arch/x86/pci/irq.c
35389 @@ -51,7 +51,7 @@ struct irq_router {
35390 struct irq_router_handler {
35391 u16 vendor;
35392 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
35393 -};
35394 +} __do_const;
35395
35396 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
35397 void (*pcibios_disable_irq)(struct pci_dev *dev) = pirq_disable_irq;
35398 @@ -791,7 +791,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
35399 return 0;
35400 }
35401
35402 -static __initdata struct irq_router_handler pirq_routers[] = {
35403 +static __initconst const struct irq_router_handler pirq_routers[] = {
35404 { PCI_VENDOR_ID_INTEL, intel_router_probe },
35405 { PCI_VENDOR_ID_AL, ali_router_probe },
35406 { PCI_VENDOR_ID_ITE, ite_router_probe },
35407 @@ -818,7 +818,7 @@ static struct pci_dev *pirq_router_dev;
35408 static void __init pirq_find_router(struct irq_router *r)
35409 {
35410 struct irq_routing_table *rt = pirq_table;
35411 - struct irq_router_handler *h;
35412 + const struct irq_router_handler *h;
35413
35414 #ifdef CONFIG_PCI_BIOS
35415 if (!rt->signature) {
35416 @@ -1091,7 +1091,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
35417 return 0;
35418 }
35419
35420 -static struct dmi_system_id __initdata pciirq_dmi_table[] = {
35421 +static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
35422 {
35423 .callback = fix_broken_hp_bios_irq9,
35424 .ident = "HP Pavilion N5400 Series Laptop",
35425 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
35426 index c77b24a..c979855 100644
35427 --- a/arch/x86/pci/pcbios.c
35428 +++ b/arch/x86/pci/pcbios.c
35429 @@ -79,7 +79,7 @@ union bios32 {
35430 static struct {
35431 unsigned long address;
35432 unsigned short segment;
35433 -} bios32_indirect = { 0, __KERNEL_CS };
35434 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
35435
35436 /*
35437 * Returns the entry point for the given service, NULL on error
35438 @@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
35439 unsigned long length; /* %ecx */
35440 unsigned long entry; /* %edx */
35441 unsigned long flags;
35442 + struct desc_struct d, *gdt;
35443
35444 local_irq_save(flags);
35445 - __asm__("lcall *(%%edi); cld"
35446 +
35447 + gdt = get_cpu_gdt_table(smp_processor_id());
35448 +
35449 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
35450 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
35451 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
35452 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
35453 +
35454 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
35455 : "=a" (return_code),
35456 "=b" (address),
35457 "=c" (length),
35458 "=d" (entry)
35459 : "0" (service),
35460 "1" (0),
35461 - "D" (&bios32_indirect));
35462 + "D" (&bios32_indirect),
35463 + "r"(__PCIBIOS_DS)
35464 + : "memory");
35465 +
35466 + pax_open_kernel();
35467 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
35468 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
35469 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
35470 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
35471 + pax_close_kernel();
35472 +
35473 local_irq_restore(flags);
35474
35475 switch (return_code) {
35476 - case 0:
35477 - return address + entry;
35478 - case 0x80: /* Not present */
35479 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
35480 - return 0;
35481 - default: /* Shouldn't happen */
35482 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
35483 - service, return_code);
35484 + case 0: {
35485 + int cpu;
35486 + unsigned char flags;
35487 +
35488 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
35489 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
35490 + printk(KERN_WARNING "bios32_service: not valid\n");
35491 return 0;
35492 + }
35493 + address = address + PAGE_OFFSET;
35494 + length += 16UL; /* some BIOSs underreport this... */
35495 + flags = 4;
35496 + if (length >= 64*1024*1024) {
35497 + length >>= PAGE_SHIFT;
35498 + flags |= 8;
35499 + }
35500 +
35501 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
35502 + gdt = get_cpu_gdt_table(cpu);
35503 + pack_descriptor(&d, address, length, 0x9b, flags);
35504 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
35505 + pack_descriptor(&d, address, length, 0x93, flags);
35506 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
35507 + }
35508 + return entry;
35509 + }
35510 + case 0x80: /* Not present */
35511 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
35512 + return 0;
35513 + default: /* Shouldn't happen */
35514 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
35515 + service, return_code);
35516 + return 0;
35517 }
35518 }
35519
35520 static struct {
35521 unsigned long address;
35522 unsigned short segment;
35523 -} pci_indirect = { 0, __KERNEL_CS };
35524 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
35525
35526 -static int pci_bios_present;
35527 +static int pci_bios_present __read_only;
35528
35529 static int check_pcibios(void)
35530 {
35531 @@ -131,11 +174,13 @@ static int check_pcibios(void)
35532 unsigned long flags, pcibios_entry;
35533
35534 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
35535 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
35536 + pci_indirect.address = pcibios_entry;
35537
35538 local_irq_save(flags);
35539 - __asm__(
35540 - "lcall *(%%edi); cld\n\t"
35541 + __asm__("movw %w6, %%ds\n\t"
35542 + "lcall *%%ss:(%%edi); cld\n\t"
35543 + "push %%ss\n\t"
35544 + "pop %%ds\n\t"
35545 "jc 1f\n\t"
35546 "xor %%ah, %%ah\n"
35547 "1:"
35548 @@ -144,7 +189,8 @@ static int check_pcibios(void)
35549 "=b" (ebx),
35550 "=c" (ecx)
35551 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
35552 - "D" (&pci_indirect)
35553 + "D" (&pci_indirect),
35554 + "r" (__PCIBIOS_DS)
35555 : "memory");
35556 local_irq_restore(flags);
35557
35558 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
35559
35560 switch (len) {
35561 case 1:
35562 - __asm__("lcall *(%%esi); cld\n\t"
35563 + __asm__("movw %w6, %%ds\n\t"
35564 + "lcall *%%ss:(%%esi); cld\n\t"
35565 + "push %%ss\n\t"
35566 + "pop %%ds\n\t"
35567 "jc 1f\n\t"
35568 "xor %%ah, %%ah\n"
35569 "1:"
35570 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
35571 : "1" (PCIBIOS_READ_CONFIG_BYTE),
35572 "b" (bx),
35573 "D" ((long)reg),
35574 - "S" (&pci_indirect));
35575 + "S" (&pci_indirect),
35576 + "r" (__PCIBIOS_DS));
35577 /*
35578 * Zero-extend the result beyond 8 bits, do not trust the
35579 * BIOS having done it:
35580 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
35581 *value &= 0xff;
35582 break;
35583 case 2:
35584 - __asm__("lcall *(%%esi); cld\n\t"
35585 + __asm__("movw %w6, %%ds\n\t"
35586 + "lcall *%%ss:(%%esi); cld\n\t"
35587 + "push %%ss\n\t"
35588 + "pop %%ds\n\t"
35589 "jc 1f\n\t"
35590 "xor %%ah, %%ah\n"
35591 "1:"
35592 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
35593 : "1" (PCIBIOS_READ_CONFIG_WORD),
35594 "b" (bx),
35595 "D" ((long)reg),
35596 - "S" (&pci_indirect));
35597 + "S" (&pci_indirect),
35598 + "r" (__PCIBIOS_DS));
35599 /*
35600 * Zero-extend the result beyond 16 bits, do not trust the
35601 * BIOS having done it:
35602 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
35603 *value &= 0xffff;
35604 break;
35605 case 4:
35606 - __asm__("lcall *(%%esi); cld\n\t"
35607 + __asm__("movw %w6, %%ds\n\t"
35608 + "lcall *%%ss:(%%esi); cld\n\t"
35609 + "push %%ss\n\t"
35610 + "pop %%ds\n\t"
35611 "jc 1f\n\t"
35612 "xor %%ah, %%ah\n"
35613 "1:"
35614 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
35615 : "1" (PCIBIOS_READ_CONFIG_DWORD),
35616 "b" (bx),
35617 "D" ((long)reg),
35618 - "S" (&pci_indirect));
35619 + "S" (&pci_indirect),
35620 + "r" (__PCIBIOS_DS));
35621 break;
35622 }
35623
35624 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
35625
35626 switch (len) {
35627 case 1:
35628 - __asm__("lcall *(%%esi); cld\n\t"
35629 + __asm__("movw %w6, %%ds\n\t"
35630 + "lcall *%%ss:(%%esi); cld\n\t"
35631 + "push %%ss\n\t"
35632 + "pop %%ds\n\t"
35633 "jc 1f\n\t"
35634 "xor %%ah, %%ah\n"
35635 "1:"
35636 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
35637 "c" (value),
35638 "b" (bx),
35639 "D" ((long)reg),
35640 - "S" (&pci_indirect));
35641 + "S" (&pci_indirect),
35642 + "r" (__PCIBIOS_DS));
35643 break;
35644 case 2:
35645 - __asm__("lcall *(%%esi); cld\n\t"
35646 + __asm__("movw %w6, %%ds\n\t"
35647 + "lcall *%%ss:(%%esi); cld\n\t"
35648 + "push %%ss\n\t"
35649 + "pop %%ds\n\t"
35650 "jc 1f\n\t"
35651 "xor %%ah, %%ah\n"
35652 "1:"
35653 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
35654 "c" (value),
35655 "b" (bx),
35656 "D" ((long)reg),
35657 - "S" (&pci_indirect));
35658 + "S" (&pci_indirect),
35659 + "r" (__PCIBIOS_DS));
35660 break;
35661 case 4:
35662 - __asm__("lcall *(%%esi); cld\n\t"
35663 + __asm__("movw %w6, %%ds\n\t"
35664 + "lcall *%%ss:(%%esi); cld\n\t"
35665 + "push %%ss\n\t"
35666 + "pop %%ds\n\t"
35667 "jc 1f\n\t"
35668 "xor %%ah, %%ah\n"
35669 "1:"
35670 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
35671 "c" (value),
35672 "b" (bx),
35673 "D" ((long)reg),
35674 - "S" (&pci_indirect));
35675 + "S" (&pci_indirect),
35676 + "r" (__PCIBIOS_DS));
35677 break;
35678 }
35679
35680 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
35681
35682 DBG("PCI: Fetching IRQ routing table... ");
35683 __asm__("push %%es\n\t"
35684 + "movw %w8, %%ds\n\t"
35685 "push %%ds\n\t"
35686 "pop %%es\n\t"
35687 - "lcall *(%%esi); cld\n\t"
35688 + "lcall *%%ss:(%%esi); cld\n\t"
35689 "pop %%es\n\t"
35690 + "push %%ss\n\t"
35691 + "pop %%ds\n"
35692 "jc 1f\n\t"
35693 "xor %%ah, %%ah\n"
35694 "1:"
35695 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
35696 "1" (0),
35697 "D" ((long) &opt),
35698 "S" (&pci_indirect),
35699 - "m" (opt)
35700 + "m" (opt),
35701 + "r" (__PCIBIOS_DS)
35702 : "memory");
35703 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
35704 if (ret & 0xff00)
35705 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
35706 {
35707 int ret;
35708
35709 - __asm__("lcall *(%%esi); cld\n\t"
35710 + __asm__("movw %w5, %%ds\n\t"
35711 + "lcall *%%ss:(%%esi); cld\n\t"
35712 + "push %%ss\n\t"
35713 + "pop %%ds\n"
35714 "jc 1f\n\t"
35715 "xor %%ah, %%ah\n"
35716 "1:"
35717 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
35718 : "0" (PCIBIOS_SET_PCI_HW_INT),
35719 "b" ((dev->bus->number << 8) | dev->devfn),
35720 "c" ((irq << 8) | (pin + 10)),
35721 - "S" (&pci_indirect));
35722 + "S" (&pci_indirect),
35723 + "r" (__PCIBIOS_DS));
35724 return !(ret & 0xff00);
35725 }
35726 EXPORT_SYMBOL(pcibios_set_irq_routing);
35727 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
35728 index 9ee3491..872192f 100644
35729 --- a/arch/x86/platform/efi/efi_32.c
35730 +++ b/arch/x86/platform/efi/efi_32.c
35731 @@ -59,11 +59,22 @@ void efi_call_phys_prelog(void)
35732 {
35733 struct desc_ptr gdt_descr;
35734
35735 +#ifdef CONFIG_PAX_KERNEXEC
35736 + struct desc_struct d;
35737 +#endif
35738 +
35739 local_irq_save(efi_rt_eflags);
35740
35741 load_cr3(initial_page_table);
35742 __flush_tlb_all();
35743
35744 +#ifdef CONFIG_PAX_KERNEXEC
35745 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
35746 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
35747 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
35748 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
35749 +#endif
35750 +
35751 gdt_descr.address = __pa(get_cpu_gdt_table(0));
35752 gdt_descr.size = GDT_SIZE - 1;
35753 load_gdt(&gdt_descr);
35754 @@ -73,11 +84,24 @@ void efi_call_phys_epilog(void)
35755 {
35756 struct desc_ptr gdt_descr;
35757
35758 +#ifdef CONFIG_PAX_KERNEXEC
35759 + struct desc_struct d;
35760 +
35761 + memset(&d, 0, sizeof d);
35762 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
35763 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
35764 +#endif
35765 +
35766 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
35767 gdt_descr.size = GDT_SIZE - 1;
35768 load_gdt(&gdt_descr);
35769
35770 +#ifdef CONFIG_PAX_PER_CPU_PGD
35771 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
35772 +#else
35773 load_cr3(swapper_pg_dir);
35774 +#endif
35775 +
35776 __flush_tlb_all();
35777
35778 local_irq_restore(efi_rt_eflags);
35779 diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
35780 index 290d397..e09d270 100644
35781 --- a/arch/x86/platform/efi/efi_64.c
35782 +++ b/arch/x86/platform/efi/efi_64.c
35783 @@ -99,6 +99,11 @@ void __init efi_call_phys_prelog(void)
35784 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
35785 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
35786 }
35787 +
35788 +#ifdef CONFIG_PAX_PER_CPU_PGD
35789 + load_cr3(swapper_pg_dir);
35790 +#endif
35791 +
35792 __flush_tlb_all();
35793 }
35794
35795 @@ -116,6 +121,11 @@ void __init efi_call_phys_epilog(void)
35796 for (pgd = 0; pgd < n_pgds; pgd++)
35797 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
35798 kfree(save_pgd);
35799 +
35800 +#ifdef CONFIG_PAX_PER_CPU_PGD
35801 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
35802 +#endif
35803 +
35804 __flush_tlb_all();
35805 local_irq_restore(efi_flags);
35806 early_code_mapping_set_exec(0);
35807 @@ -146,8 +156,23 @@ int efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages)
35808 unsigned npages;
35809 pgd_t *pgd;
35810
35811 - if (efi_enabled(EFI_OLD_MEMMAP))
35812 + if (efi_enabled(EFI_OLD_MEMMAP)) {
35813 + /* PaX: We need to disable the NX bit in the PGD, otherwise we won't be
35814 + * able to execute the EFI services.
35815 + */
35816 + if (__supported_pte_mask & _PAGE_NX) {
35817 + unsigned long addr = (unsigned long) __va(0);
35818 + pgd_t pe = __pgd(pgd_val(*pgd_offset_k(addr)) & ~_PAGE_NX);
35819 +
35820 + pr_alert("PAX: Disabling NX protection for low memory map. Try booting without \"efi=old_map\"\n");
35821 +#ifdef CONFIG_PAX_PER_CPU_PGD
35822 + set_pgd(pgd_offset_cpu(0, kernel, addr), pe);
35823 +#endif
35824 + set_pgd(pgd_offset_k(addr), pe);
35825 + }
35826 +
35827 return 0;
35828 + }
35829
35830 efi_scratch.efi_pgt = (pgd_t *)(unsigned long)real_mode_header->trampoline_pgd;
35831 pgd = __va(efi_scratch.efi_pgt);
35832 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
35833 index fbe66e6..eae5e38 100644
35834 --- a/arch/x86/platform/efi/efi_stub_32.S
35835 +++ b/arch/x86/platform/efi/efi_stub_32.S
35836 @@ -6,7 +6,9 @@
35837 */
35838
35839 #include <linux/linkage.h>
35840 +#include <linux/init.h>
35841 #include <asm/page_types.h>
35842 +#include <asm/segment.h>
35843
35844 /*
35845 * efi_call_phys(void *, ...) is a function with variable parameters.
35846 @@ -20,7 +22,7 @@
35847 * service functions will comply with gcc calling convention, too.
35848 */
35849
35850 -.text
35851 +__INIT
35852 ENTRY(efi_call_phys)
35853 /*
35854 * 0. The function can only be called in Linux kernel. So CS has been
35855 @@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
35856 * The mapping of lower virtual memory has been created in prelog and
35857 * epilog.
35858 */
35859 - movl $1f, %edx
35860 - subl $__PAGE_OFFSET, %edx
35861 - jmp *%edx
35862 +#ifdef CONFIG_PAX_KERNEXEC
35863 + movl $(__KERNEXEC_EFI_DS), %edx
35864 + mov %edx, %ds
35865 + mov %edx, %es
35866 + mov %edx, %ss
35867 + addl $2f,(1f)
35868 + ljmp *(1f)
35869 +
35870 +__INITDATA
35871 +1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
35872 +.previous
35873 +
35874 +2:
35875 + subl $2b,(1b)
35876 +#else
35877 + jmp 1f-__PAGE_OFFSET
35878 1:
35879 +#endif
35880
35881 /*
35882 * 2. Now on the top of stack is the return
35883 @@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
35884 * parameter 2, ..., param n. To make things easy, we save the return
35885 * address of efi_call_phys in a global variable.
35886 */
35887 - popl %edx
35888 - movl %edx, saved_return_addr
35889 - /* get the function pointer into ECX*/
35890 - popl %ecx
35891 - movl %ecx, efi_rt_function_ptr
35892 - movl $2f, %edx
35893 - subl $__PAGE_OFFSET, %edx
35894 - pushl %edx
35895 + popl (saved_return_addr)
35896 + popl (efi_rt_function_ptr)
35897
35898 /*
35899 * 3. Clear PG bit in %CR0.
35900 @@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
35901 /*
35902 * 5. Call the physical function.
35903 */
35904 - jmp *%ecx
35905 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
35906
35907 -2:
35908 /*
35909 * 6. After EFI runtime service returns, control will return to
35910 * following instruction. We'd better readjust stack pointer first.
35911 @@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
35912 movl %cr0, %edx
35913 orl $0x80000000, %edx
35914 movl %edx, %cr0
35915 - jmp 1f
35916 -1:
35917 +
35918 /*
35919 * 8. Now restore the virtual mode from flat mode by
35920 * adding EIP with PAGE_OFFSET.
35921 */
35922 - movl $1f, %edx
35923 - jmp *%edx
35924 +#ifdef CONFIG_PAX_KERNEXEC
35925 + movl $(__KERNEL_DS), %edx
35926 + mov %edx, %ds
35927 + mov %edx, %es
35928 + mov %edx, %ss
35929 + ljmp $(__KERNEL_CS),$1f
35930 +#else
35931 + jmp 1f+__PAGE_OFFSET
35932 +#endif
35933 1:
35934
35935 /*
35936 * 9. Balance the stack. And because EAX contain the return value,
35937 * we'd better not clobber it.
35938 */
35939 - leal efi_rt_function_ptr, %edx
35940 - movl (%edx), %ecx
35941 - pushl %ecx
35942 + pushl (efi_rt_function_ptr)
35943
35944 /*
35945 - * 10. Push the saved return address onto the stack and return.
35946 + * 10. Return to the saved return address.
35947 */
35948 - leal saved_return_addr, %edx
35949 - movl (%edx), %ecx
35950 - pushl %ecx
35951 - ret
35952 + jmpl *(saved_return_addr)
35953 ENDPROC(efi_call_phys)
35954 .previous
35955
35956 -.data
35957 +__INITDATA
35958 saved_return_addr:
35959 .long 0
35960 efi_rt_function_ptr:
35961 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
35962 index 5fcda72..cd4dc41 100644
35963 --- a/arch/x86/platform/efi/efi_stub_64.S
35964 +++ b/arch/x86/platform/efi/efi_stub_64.S
35965 @@ -11,6 +11,7 @@
35966 #include <asm/msr.h>
35967 #include <asm/processor-flags.h>
35968 #include <asm/page_types.h>
35969 +#include <asm/alternative-asm.h>
35970
35971 #define SAVE_XMM \
35972 mov %rsp, %rax; \
35973 @@ -88,6 +89,7 @@ ENTRY(efi_call)
35974 RESTORE_PGT
35975 addq $48, %rsp
35976 RESTORE_XMM
35977 + pax_force_retaddr 0, 1
35978 ret
35979 ENDPROC(efi_call)
35980
35981 @@ -245,8 +247,8 @@ efi_gdt64:
35982 .long 0 /* Filled out by user */
35983 .word 0
35984 .quad 0x0000000000000000 /* NULL descriptor */
35985 - .quad 0x00af9a000000ffff /* __KERNEL_CS */
35986 - .quad 0x00cf92000000ffff /* __KERNEL_DS */
35987 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
35988 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
35989 .quad 0x0080890000000000 /* TS descriptor */
35990 .quad 0x0000000000000000 /* TS continued */
35991 efi_gdt64_end:
35992 diff --git a/arch/x86/platform/intel-mid/intel-mid.c b/arch/x86/platform/intel-mid/intel-mid.c
35993 index 1bbedc4..eb795b5 100644
35994 --- a/arch/x86/platform/intel-mid/intel-mid.c
35995 +++ b/arch/x86/platform/intel-mid/intel-mid.c
35996 @@ -71,9 +71,10 @@ static void intel_mid_power_off(void)
35997 {
35998 };
35999
36000 -static void intel_mid_reboot(void)
36001 +static void __noreturn intel_mid_reboot(void)
36002 {
36003 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
36004 + BUG();
36005 }
36006
36007 static unsigned long __init intel_mid_calibrate_tsc(void)
36008 diff --git a/arch/x86/platform/intel-mid/intel_mid_weak_decls.h b/arch/x86/platform/intel-mid/intel_mid_weak_decls.h
36009 index 46aa25c..59a68ed 100644
36010 --- a/arch/x86/platform/intel-mid/intel_mid_weak_decls.h
36011 +++ b/arch/x86/platform/intel-mid/intel_mid_weak_decls.h
36012 @@ -10,10 +10,9 @@
36013 */
36014
36015
36016 -/* __attribute__((weak)) makes these declarations overridable */
36017 /* For every CPU addition a new get_<cpuname>_ops interface needs
36018 * to be added.
36019 */
36020 -extern void *get_penwell_ops(void) __attribute__((weak));
36021 -extern void *get_cloverview_ops(void) __attribute__((weak));
36022 -extern void *get_tangier_ops(void) __attribute__((weak));
36023 +extern const void *get_penwell_ops(void);
36024 +extern const void *get_cloverview_ops(void);
36025 +extern const void *get_tangier_ops(void);
36026 diff --git a/arch/x86/platform/intel-mid/mfld.c b/arch/x86/platform/intel-mid/mfld.c
36027 index 23381d2..8ddc10e 100644
36028 --- a/arch/x86/platform/intel-mid/mfld.c
36029 +++ b/arch/x86/platform/intel-mid/mfld.c
36030 @@ -64,12 +64,12 @@ static void __init penwell_arch_setup(void)
36031 pm_power_off = mfld_power_off;
36032 }
36033
36034 -void *get_penwell_ops(void)
36035 +const void *get_penwell_ops(void)
36036 {
36037 return &penwell_ops;
36038 }
36039
36040 -void *get_cloverview_ops(void)
36041 +const void *get_cloverview_ops(void)
36042 {
36043 return &penwell_ops;
36044 }
36045 diff --git a/arch/x86/platform/intel-mid/mrfl.c b/arch/x86/platform/intel-mid/mrfl.c
36046 index aaca917..66eadbc 100644
36047 --- a/arch/x86/platform/intel-mid/mrfl.c
36048 +++ b/arch/x86/platform/intel-mid/mrfl.c
36049 @@ -97,7 +97,7 @@ static struct intel_mid_ops tangier_ops = {
36050 .arch_setup = tangier_arch_setup,
36051 };
36052
36053 -void *get_tangier_ops(void)
36054 +const void *get_tangier_ops(void)
36055 {
36056 return &tangier_ops;
36057 }
36058 diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
36059 index d6ee929..3637cb5 100644
36060 --- a/arch/x86/platform/olpc/olpc_dt.c
36061 +++ b/arch/x86/platform/olpc/olpc_dt.c
36062 @@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
36063 return res;
36064 }
36065
36066 -static struct of_pdt_ops prom_olpc_ops __initdata = {
36067 +static struct of_pdt_ops prom_olpc_ops __initconst = {
36068 .nextprop = olpc_dt_nextprop,
36069 .getproplen = olpc_dt_getproplen,
36070 .getproperty = olpc_dt_getproperty,
36071 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
36072 index 6ec7910..ecdbb11 100644
36073 --- a/arch/x86/power/cpu.c
36074 +++ b/arch/x86/power/cpu.c
36075 @@ -137,11 +137,8 @@ static void do_fpu_end(void)
36076 static void fix_processor_context(void)
36077 {
36078 int cpu = smp_processor_id();
36079 - struct tss_struct *t = &per_cpu(init_tss, cpu);
36080 -#ifdef CONFIG_X86_64
36081 - struct desc_struct *desc = get_cpu_gdt_table(cpu);
36082 - tss_desc tss;
36083 -#endif
36084 + struct tss_struct *t = init_tss + cpu;
36085 +
36086 set_tss_desc(cpu, t); /*
36087 * This just modifies memory; should not be
36088 * necessary. But... This is necessary, because
36089 @@ -150,10 +147,6 @@ static void fix_processor_context(void)
36090 */
36091
36092 #ifdef CONFIG_X86_64
36093 - memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
36094 - tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
36095 - write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
36096 -
36097 syscall_init(); /* This sets MSR_*STAR and related */
36098 #endif
36099 load_TR_desc(); /* This does ltr */
36100 diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
36101 index bad628a..a102610 100644
36102 --- a/arch/x86/realmode/init.c
36103 +++ b/arch/x86/realmode/init.c
36104 @@ -68,7 +68,13 @@ void __init setup_real_mode(void)
36105 __va(real_mode_header->trampoline_header);
36106
36107 #ifdef CONFIG_X86_32
36108 - trampoline_header->start = __pa_symbol(startup_32_smp);
36109 + trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
36110 +
36111 +#ifdef CONFIG_PAX_KERNEXEC
36112 + trampoline_header->start -= LOAD_PHYSICAL_ADDR;
36113 +#endif
36114 +
36115 + trampoline_header->boot_cs = __BOOT_CS;
36116 trampoline_header->gdt_limit = __BOOT_DS + 7;
36117 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
36118 #else
36119 @@ -84,7 +90,7 @@ void __init setup_real_mode(void)
36120 *trampoline_cr4_features = read_cr4();
36121
36122 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
36123 - trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
36124 + trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
36125 trampoline_pgd[511] = init_level4_pgt[511].pgd;
36126 #endif
36127 }
36128 diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
36129 index 7c0d7be..d24dc88 100644
36130 --- a/arch/x86/realmode/rm/Makefile
36131 +++ b/arch/x86/realmode/rm/Makefile
36132 @@ -67,5 +67,8 @@ $(obj)/realmode.relocs: $(obj)/realmode.elf FORCE
36133
36134 KBUILD_CFLAGS := $(LINUXINCLUDE) $(REALMODE_CFLAGS) -D_SETUP -D_WAKEUP \
36135 -I$(srctree)/arch/x86/boot
36136 +ifdef CONSTIFY_PLUGIN
36137 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
36138 +endif
36139 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
36140 GCOV_PROFILE := n
36141 diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
36142 index a28221d..93c40f1 100644
36143 --- a/arch/x86/realmode/rm/header.S
36144 +++ b/arch/x86/realmode/rm/header.S
36145 @@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
36146 #endif
36147 /* APM/BIOS reboot */
36148 .long pa_machine_real_restart_asm
36149 -#ifdef CONFIG_X86_64
36150 +#ifdef CONFIG_X86_32
36151 + .long __KERNEL_CS
36152 +#else
36153 .long __KERNEL32_CS
36154 #endif
36155 END(real_mode_header)
36156 diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
36157 index 48ddd76..c26749f 100644
36158 --- a/arch/x86/realmode/rm/trampoline_32.S
36159 +++ b/arch/x86/realmode/rm/trampoline_32.S
36160 @@ -24,6 +24,12 @@
36161 #include <asm/page_types.h>
36162 #include "realmode.h"
36163
36164 +#ifdef CONFIG_PAX_KERNEXEC
36165 +#define ta(X) (X)
36166 +#else
36167 +#define ta(X) (pa_ ## X)
36168 +#endif
36169 +
36170 .text
36171 .code16
36172
36173 @@ -38,8 +44,6 @@ ENTRY(trampoline_start)
36174
36175 cli # We should be safe anyway
36176
36177 - movl tr_start, %eax # where we need to go
36178 -
36179 movl $0xA5A5A5A5, trampoline_status
36180 # write marker for master knows we're running
36181
36182 @@ -55,7 +59,7 @@ ENTRY(trampoline_start)
36183 movw $1, %dx # protected mode (PE) bit
36184 lmsw %dx # into protected mode
36185
36186 - ljmpl $__BOOT_CS, $pa_startup_32
36187 + ljmpl *(trampoline_header)
36188
36189 .section ".text32","ax"
36190 .code32
36191 @@ -66,7 +70,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
36192 .balign 8
36193 GLOBAL(trampoline_header)
36194 tr_start: .space 4
36195 - tr_gdt_pad: .space 2
36196 + tr_boot_cs: .space 2
36197 tr_gdt: .space 6
36198 END(trampoline_header)
36199
36200 diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
36201 index dac7b20..72dbaca 100644
36202 --- a/arch/x86/realmode/rm/trampoline_64.S
36203 +++ b/arch/x86/realmode/rm/trampoline_64.S
36204 @@ -93,6 +93,7 @@ ENTRY(startup_32)
36205 movl %edx, %gs
36206
36207 movl pa_tr_cr4, %eax
36208 + andl $~X86_CR4_PCIDE, %eax
36209 movl %eax, %cr4 # Enable PAE mode
36210
36211 # Setup trampoline 4 level pagetables
36212 @@ -106,7 +107,7 @@ ENTRY(startup_32)
36213 wrmsr
36214
36215 # Enable paging and in turn activate Long Mode
36216 - movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
36217 + movl $(X86_CR0_PG | X86_CR0_PE), %eax
36218 movl %eax, %cr0
36219
36220 /*
36221 diff --git a/arch/x86/realmode/rm/wakeup_asm.S b/arch/x86/realmode/rm/wakeup_asm.S
36222 index 9e7e147..25a4158 100644
36223 --- a/arch/x86/realmode/rm/wakeup_asm.S
36224 +++ b/arch/x86/realmode/rm/wakeup_asm.S
36225 @@ -126,11 +126,10 @@ ENTRY(wakeup_start)
36226 lgdtl pmode_gdt
36227
36228 /* This really couldn't... */
36229 - movl pmode_entry, %eax
36230 movl pmode_cr0, %ecx
36231 movl %ecx, %cr0
36232 - ljmpl $__KERNEL_CS, $pa_startup_32
36233 - /* -> jmp *%eax in trampoline_32.S */
36234 +
36235 + ljmpl *pmode_entry
36236 #else
36237 jmp trampoline_start
36238 #endif
36239 diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
36240 index 604a37e..e49702a 100644
36241 --- a/arch/x86/tools/Makefile
36242 +++ b/arch/x86/tools/Makefile
36243 @@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
36244
36245 $(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
36246
36247 -HOST_EXTRACFLAGS += -I$(srctree)/tools/include
36248 +HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
36249 hostprogs-y += relocs
36250 relocs-objs := relocs_32.o relocs_64.o relocs_common.o
36251 PHONY += relocs
36252 diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
36253 index bbb1d22..e505211 100644
36254 --- a/arch/x86/tools/relocs.c
36255 +++ b/arch/x86/tools/relocs.c
36256 @@ -1,5 +1,7 @@
36257 /* This is included from relocs_32/64.c */
36258
36259 +#include "../../../include/generated/autoconf.h"
36260 +
36261 #define ElfW(type) _ElfW(ELF_BITS, type)
36262 #define _ElfW(bits, type) __ElfW(bits, type)
36263 #define __ElfW(bits, type) Elf##bits##_##type
36264 @@ -11,6 +13,7 @@
36265 #define Elf_Sym ElfW(Sym)
36266
36267 static Elf_Ehdr ehdr;
36268 +static Elf_Phdr *phdr;
36269
36270 struct relocs {
36271 uint32_t *offset;
36272 @@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
36273 }
36274 }
36275
36276 +static void read_phdrs(FILE *fp)
36277 +{
36278 + unsigned int i;
36279 +
36280 + phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
36281 + if (!phdr) {
36282 + die("Unable to allocate %d program headers\n",
36283 + ehdr.e_phnum);
36284 + }
36285 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
36286 + die("Seek to %d failed: %s\n",
36287 + ehdr.e_phoff, strerror(errno));
36288 + }
36289 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
36290 + die("Cannot read ELF program headers: %s\n",
36291 + strerror(errno));
36292 + }
36293 + for(i = 0; i < ehdr.e_phnum; i++) {
36294 + phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
36295 + phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
36296 + phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
36297 + phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
36298 + phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
36299 + phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
36300 + phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
36301 + phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
36302 + }
36303 +
36304 +}
36305 +
36306 static void read_shdrs(FILE *fp)
36307 {
36308 - int i;
36309 + unsigned int i;
36310 Elf_Shdr shdr;
36311
36312 secs = calloc(ehdr.e_shnum, sizeof(struct section));
36313 @@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
36314
36315 static void read_strtabs(FILE *fp)
36316 {
36317 - int i;
36318 + unsigned int i;
36319 for (i = 0; i < ehdr.e_shnum; i++) {
36320 struct section *sec = &secs[i];
36321 if (sec->shdr.sh_type != SHT_STRTAB) {
36322 @@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
36323
36324 static void read_symtabs(FILE *fp)
36325 {
36326 - int i,j;
36327 + unsigned int i,j;
36328 for (i = 0; i < ehdr.e_shnum; i++) {
36329 struct section *sec = &secs[i];
36330 if (sec->shdr.sh_type != SHT_SYMTAB) {
36331 @@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
36332 }
36333
36334
36335 -static void read_relocs(FILE *fp)
36336 +static void read_relocs(FILE *fp, int use_real_mode)
36337 {
36338 - int i,j;
36339 + unsigned int i,j;
36340 + uint32_t base;
36341 +
36342 for (i = 0; i < ehdr.e_shnum; i++) {
36343 struct section *sec = &secs[i];
36344 if (sec->shdr.sh_type != SHT_REL_TYPE) {
36345 @@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
36346 die("Cannot read symbol table: %s\n",
36347 strerror(errno));
36348 }
36349 + base = 0;
36350 +
36351 +#ifdef CONFIG_X86_32
36352 + for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
36353 + if (phdr[j].p_type != PT_LOAD )
36354 + continue;
36355 + 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)
36356 + continue;
36357 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
36358 + break;
36359 + }
36360 +#endif
36361 +
36362 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
36363 Elf_Rel *rel = &sec->reltab[j];
36364 - rel->r_offset = elf_addr_to_cpu(rel->r_offset);
36365 + rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
36366 rel->r_info = elf_xword_to_cpu(rel->r_info);
36367 #if (SHT_REL_TYPE == SHT_RELA)
36368 rel->r_addend = elf_xword_to_cpu(rel->r_addend);
36369 @@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
36370
36371 static void print_absolute_symbols(void)
36372 {
36373 - int i;
36374 + unsigned int i;
36375 const char *format;
36376
36377 if (ELF_BITS == 64)
36378 @@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
36379 for (i = 0; i < ehdr.e_shnum; i++) {
36380 struct section *sec = &secs[i];
36381 char *sym_strtab;
36382 - int j;
36383 + unsigned int j;
36384
36385 if (sec->shdr.sh_type != SHT_SYMTAB) {
36386 continue;
36387 @@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
36388
36389 static void print_absolute_relocs(void)
36390 {
36391 - int i, printed = 0;
36392 + unsigned int i, printed = 0;
36393 const char *format;
36394
36395 if (ELF_BITS == 64)
36396 @@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
36397 struct section *sec_applies, *sec_symtab;
36398 char *sym_strtab;
36399 Elf_Sym *sh_symtab;
36400 - int j;
36401 + unsigned int j;
36402 if (sec->shdr.sh_type != SHT_REL_TYPE) {
36403 continue;
36404 }
36405 @@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
36406 static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
36407 Elf_Sym *sym, const char *symname))
36408 {
36409 - int i;
36410 + unsigned int i;
36411 /* Walk through the relocations */
36412 for (i = 0; i < ehdr.e_shnum; i++) {
36413 char *sym_strtab;
36414 Elf_Sym *sh_symtab;
36415 struct section *sec_applies, *sec_symtab;
36416 - int j;
36417 + unsigned int j;
36418 struct section *sec = &secs[i];
36419
36420 if (sec->shdr.sh_type != SHT_REL_TYPE) {
36421 @@ -822,6 +870,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
36422 {
36423 unsigned r_type = ELF32_R_TYPE(rel->r_info);
36424 int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
36425 + char *sym_strtab = sec->link->link->strtab;
36426 +
36427 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
36428 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
36429 + return 0;
36430 +
36431 +#ifdef CONFIG_PAX_KERNEXEC
36432 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
36433 + if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
36434 + return 0;
36435 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
36436 + return 0;
36437 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
36438 + return 0;
36439 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
36440 + return 0;
36441 +#endif
36442
36443 switch (r_type) {
36444 case R_386_NONE:
36445 @@ -960,7 +1025,7 @@ static int write32_as_text(uint32_t v, FILE *f)
36446
36447 static void emit_relocs(int as_text, int use_real_mode)
36448 {
36449 - int i;
36450 + unsigned int i;
36451 int (*write_reloc)(uint32_t, FILE *) = write32;
36452 int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
36453 const char *symname);
36454 @@ -1060,10 +1125,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
36455 {
36456 regex_init(use_real_mode);
36457 read_ehdr(fp);
36458 + read_phdrs(fp);
36459 read_shdrs(fp);
36460 read_strtabs(fp);
36461 read_symtabs(fp);
36462 - read_relocs(fp);
36463 + read_relocs(fp, use_real_mode);
36464 if (ELF_BITS == 64)
36465 percpu_init();
36466 if (show_absolute_syms) {
36467 diff --git a/arch/x86/um/mem_32.c b/arch/x86/um/mem_32.c
36468 index f40281e..92728c9 100644
36469 --- a/arch/x86/um/mem_32.c
36470 +++ b/arch/x86/um/mem_32.c
36471 @@ -21,7 +21,7 @@ static int __init gate_vma_init(void)
36472 gate_vma.vm_start = FIXADDR_USER_START;
36473 gate_vma.vm_end = FIXADDR_USER_END;
36474 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
36475 - gate_vma.vm_page_prot = __P101;
36476 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
36477
36478 return 0;
36479 }
36480 diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
36481 index 80ffa5b..a33bd15 100644
36482 --- a/arch/x86/um/tls_32.c
36483 +++ b/arch/x86/um/tls_32.c
36484 @@ -260,7 +260,7 @@ out:
36485 if (unlikely(task == current &&
36486 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
36487 printk(KERN_ERR "get_tls_entry: task with pid %d got here "
36488 - "without flushed TLS.", current->pid);
36489 + "without flushed TLS.", task_pid_nr(current));
36490 }
36491
36492 return 0;
36493 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
36494 index 5a4affe..9e2d522 100644
36495 --- a/arch/x86/vdso/Makefile
36496 +++ b/arch/x86/vdso/Makefile
36497 @@ -174,7 +174,7 @@ quiet_cmd_vdso = VDSO $@
36498 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
36499 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
36500
36501 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv) \
36502 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv) \
36503 $(call cc-ldoption, -Wl$(comma)--build-id) -Wl,-Bsymbolic $(LTO_CFLAGS)
36504 GCOV_PROFILE := n
36505
36506 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
36507 index e904c27..b9eaa03 100644
36508 --- a/arch/x86/vdso/vdso32-setup.c
36509 +++ b/arch/x86/vdso/vdso32-setup.c
36510 @@ -14,6 +14,7 @@
36511 #include <asm/cpufeature.h>
36512 #include <asm/processor.h>
36513 #include <asm/vdso.h>
36514 +#include <asm/mman.h>
36515
36516 #ifdef CONFIG_COMPAT_VDSO
36517 #define VDSO_DEFAULT 0
36518 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
36519 index 970463b..da82d3e 100644
36520 --- a/arch/x86/vdso/vma.c
36521 +++ b/arch/x86/vdso/vma.c
36522 @@ -16,10 +16,9 @@
36523 #include <asm/vdso.h>
36524 #include <asm/page.h>
36525 #include <asm/hpet.h>
36526 +#include <asm/mman.h>
36527
36528 #if defined(CONFIG_X86_64)
36529 -unsigned int __read_mostly vdso64_enabled = 1;
36530 -
36531 extern unsigned short vdso_sync_cpuid;
36532 #endif
36533
36534 @@ -101,6 +100,11 @@ static int map_vdso(const struct vdso_image *image, bool calculate_addr)
36535 .pages = no_pages,
36536 };
36537
36538 +#ifdef CONFIG_PAX_RANDMMAP
36539 + if (mm->pax_flags & MF_PAX_RANDMMAP)
36540 + calculate_addr = false;
36541 +#endif
36542 +
36543 if (calculate_addr) {
36544 addr = vdso_addr(current->mm->start_stack,
36545 image->size - image->sym_vvar_start);
36546 @@ -111,14 +115,14 @@ static int map_vdso(const struct vdso_image *image, bool calculate_addr)
36547 down_write(&mm->mmap_sem);
36548
36549 addr = get_unmapped_area(NULL, addr,
36550 - image->size - image->sym_vvar_start, 0, 0);
36551 + image->size - image->sym_vvar_start, 0, MAP_EXECUTABLE);
36552 if (IS_ERR_VALUE(addr)) {
36553 ret = addr;
36554 goto up_fail;
36555 }
36556
36557 text_start = addr - image->sym_vvar_start;
36558 - current->mm->context.vdso = (void __user *)text_start;
36559 + mm->context.vdso = text_start;
36560
36561 /*
36562 * MAYWRITE to allow gdb to COW and set breakpoints
36563 @@ -163,15 +167,12 @@ static int map_vdso(const struct vdso_image *image, bool calculate_addr)
36564 hpet_address >> PAGE_SHIFT,
36565 PAGE_SIZE,
36566 pgprot_noncached(PAGE_READONLY));
36567 -
36568 - if (ret)
36569 - goto up_fail;
36570 }
36571 #endif
36572
36573 up_fail:
36574 if (ret)
36575 - current->mm->context.vdso = NULL;
36576 + current->mm->context.vdso = 0;
36577
36578 up_write(&mm->mmap_sem);
36579 return ret;
36580 @@ -191,8 +192,8 @@ static int load_vdso32(void)
36581
36582 if (selected_vdso32->sym_VDSO32_SYSENTER_RETURN)
36583 current_thread_info()->sysenter_return =
36584 - current->mm->context.vdso +
36585 - selected_vdso32->sym_VDSO32_SYSENTER_RETURN;
36586 + (void __force_user *)(current->mm->context.vdso +
36587 + selected_vdso32->sym_VDSO32_SYSENTER_RETURN);
36588
36589 return 0;
36590 }
36591 @@ -201,9 +202,6 @@ static int load_vdso32(void)
36592 #ifdef CONFIG_X86_64
36593 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
36594 {
36595 - if (!vdso64_enabled)
36596 - return 0;
36597 -
36598 return map_vdso(&vdso_image_64, true);
36599 }
36600
36601 @@ -212,12 +210,8 @@ int compat_arch_setup_additional_pages(struct linux_binprm *bprm,
36602 int uses_interp)
36603 {
36604 #ifdef CONFIG_X86_X32_ABI
36605 - if (test_thread_flag(TIF_X32)) {
36606 - if (!vdso64_enabled)
36607 - return 0;
36608 -
36609 + if (test_thread_flag(TIF_X32))
36610 return map_vdso(&vdso_image_x32, true);
36611 - }
36612 #endif
36613
36614 return load_vdso32();
36615 @@ -229,12 +223,3 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
36616 return load_vdso32();
36617 }
36618 #endif
36619 -
36620 -#ifdef CONFIG_X86_64
36621 -static __init int vdso_setup(char *s)
36622 -{
36623 - vdso64_enabled = simple_strtoul(s, NULL, 0);
36624 - return 0;
36625 -}
36626 -__setup("vdso=", vdso_setup);
36627 -#endif
36628 diff --git a/arch/x86/xen/Kconfig b/arch/x86/xen/Kconfig
36629 index e88fda8..76ce7ce 100644
36630 --- a/arch/x86/xen/Kconfig
36631 +++ b/arch/x86/xen/Kconfig
36632 @@ -9,6 +9,7 @@ config XEN
36633 select XEN_HAVE_PVMMU
36634 depends on X86_64 || (X86_32 && X86_PAE)
36635 depends on X86_TSC
36636 + depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_XEN
36637 help
36638 This is the Linux Xen port. Enabling this will allow the
36639 kernel to boot in a paravirtualized environment under the
36640 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
36641 index c0cb11f..bed56ff 100644
36642 --- a/arch/x86/xen/enlighten.c
36643 +++ b/arch/x86/xen/enlighten.c
36644 @@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
36645
36646 struct shared_info xen_dummy_shared_info;
36647
36648 -void *xen_initial_gdt;
36649 -
36650 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
36651 __read_mostly int xen_have_vector_callback;
36652 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
36653 @@ -542,8 +540,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
36654 {
36655 unsigned long va = dtr->address;
36656 unsigned int size = dtr->size + 1;
36657 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
36658 - unsigned long frames[pages];
36659 + unsigned long frames[65536 / PAGE_SIZE];
36660 int f;
36661
36662 /*
36663 @@ -591,8 +588,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
36664 {
36665 unsigned long va = dtr->address;
36666 unsigned int size = dtr->size + 1;
36667 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
36668 - unsigned long frames[pages];
36669 + unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
36670 int f;
36671
36672 /*
36673 @@ -600,7 +596,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
36674 * 8-byte entries, or 16 4k pages..
36675 */
36676
36677 - BUG_ON(size > 65536);
36678 + BUG_ON(size > GDT_SIZE);
36679 BUG_ON(va & ~PAGE_MASK);
36680
36681 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
36682 @@ -989,7 +985,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
36683 return 0;
36684 }
36685
36686 -static void set_xen_basic_apic_ops(void)
36687 +static void __init set_xen_basic_apic_ops(void)
36688 {
36689 apic->read = xen_apic_read;
36690 apic->write = xen_apic_write;
36691 @@ -1295,30 +1291,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
36692 #endif
36693 };
36694
36695 -static void xen_reboot(int reason)
36696 +static __noreturn void xen_reboot(int reason)
36697 {
36698 struct sched_shutdown r = { .reason = reason };
36699
36700 - if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
36701 - BUG();
36702 + HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
36703 + BUG();
36704 }
36705
36706 -static void xen_restart(char *msg)
36707 +static __noreturn void xen_restart(char *msg)
36708 {
36709 xen_reboot(SHUTDOWN_reboot);
36710 }
36711
36712 -static void xen_emergency_restart(void)
36713 +static __noreturn void xen_emergency_restart(void)
36714 {
36715 xen_reboot(SHUTDOWN_reboot);
36716 }
36717
36718 -static void xen_machine_halt(void)
36719 +static __noreturn void xen_machine_halt(void)
36720 {
36721 xen_reboot(SHUTDOWN_poweroff);
36722 }
36723
36724 -static void xen_machine_power_off(void)
36725 +static __noreturn void xen_machine_power_off(void)
36726 {
36727 if (pm_power_off)
36728 pm_power_off();
36729 @@ -1568,7 +1564,17 @@ asmlinkage __visible void __init xen_start_kernel(void)
36730 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
36731
36732 /* Work out if we support NX */
36733 - x86_configure_nx();
36734 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
36735 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
36736 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
36737 + unsigned l, h;
36738 +
36739 + __supported_pte_mask |= _PAGE_NX;
36740 + rdmsr(MSR_EFER, l, h);
36741 + l |= EFER_NX;
36742 + wrmsr(MSR_EFER, l, h);
36743 + }
36744 +#endif
36745
36746 /* Get mfn list */
36747 xen_build_dynamic_phys_to_machine();
36748 @@ -1596,13 +1602,6 @@ asmlinkage __visible void __init xen_start_kernel(void)
36749
36750 machine_ops = xen_machine_ops;
36751
36752 - /*
36753 - * The only reliable way to retain the initial address of the
36754 - * percpu gdt_page is to remember it here, so we can go and
36755 - * mark it RW later, when the initial percpu area is freed.
36756 - */
36757 - xen_initial_gdt = &per_cpu(gdt_page, 0);
36758 -
36759 xen_smp_init();
36760
36761 #ifdef CONFIG_ACPI_NUMA
36762 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
36763 index 16fb009..02b7801 100644
36764 --- a/arch/x86/xen/mmu.c
36765 +++ b/arch/x86/xen/mmu.c
36766 @@ -379,7 +379,7 @@ static pteval_t pte_mfn_to_pfn(pteval_t val)
36767 return val;
36768 }
36769
36770 -static pteval_t pte_pfn_to_mfn(pteval_t val)
36771 +static pteval_t __intentional_overflow(-1) pte_pfn_to_mfn(pteval_t val)
36772 {
36773 if (val & _PAGE_PRESENT) {
36774 unsigned long pfn = (val & PTE_PFN_MASK) >> PAGE_SHIFT;
36775 @@ -1904,7 +1904,11 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
36776 * L3_k[511] -> level2_fixmap_pgt */
36777 convert_pfn_mfn(level3_kernel_pgt);
36778
36779 + convert_pfn_mfn(level3_vmalloc_start_pgt);
36780 + convert_pfn_mfn(level3_vmalloc_end_pgt);
36781 + convert_pfn_mfn(level3_vmemmap_pgt);
36782 /* L3_k[511][506] -> level1_fixmap_pgt */
36783 + /* L3_k[511][507] -> level1_vsyscall_pgt */
36784 convert_pfn_mfn(level2_fixmap_pgt);
36785 }
36786 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
36787 @@ -1929,11 +1933,16 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
36788 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
36789 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
36790 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
36791 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
36792 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
36793 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
36794 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
36795 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
36796 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
36797 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
36798 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
36799 set_page_prot(level1_fixmap_pgt, PAGE_KERNEL_RO);
36800 + set_page_prot(level1_vsyscall_pgt, PAGE_KERNEL_RO);
36801
36802 /* Pin down new L4 */
36803 pin_pagetable_pfn(MMUEXT_PIN_L4_TABLE,
36804 @@ -2117,6 +2126,7 @@ static void __init xen_post_allocator_init(void)
36805 pv_mmu_ops.set_pud = xen_set_pud;
36806 #if PAGETABLE_LEVELS == 4
36807 pv_mmu_ops.set_pgd = xen_set_pgd;
36808 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
36809 #endif
36810
36811 /* This will work as long as patching hasn't happened yet
36812 @@ -2195,6 +2205,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
36813 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
36814 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
36815 .set_pgd = xen_set_pgd_hyper,
36816 + .set_pgd_batched = xen_set_pgd_hyper,
36817
36818 .alloc_pud = xen_alloc_pmd_init,
36819 .release_pud = xen_release_pmd_init,
36820 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
36821 index 7005974..54fb05f 100644
36822 --- a/arch/x86/xen/smp.c
36823 +++ b/arch/x86/xen/smp.c
36824 @@ -283,17 +283,13 @@ static void __init xen_smp_prepare_boot_cpu(void)
36825
36826 if (xen_pv_domain()) {
36827 if (!xen_feature(XENFEAT_writable_page_tables))
36828 - /* We've switched to the "real" per-cpu gdt, so make
36829 - * sure the old memory can be recycled. */
36830 - make_lowmem_page_readwrite(xen_initial_gdt);
36831 -
36832 #ifdef CONFIG_X86_32
36833 /*
36834 * Xen starts us with XEN_FLAT_RING1_DS, but linux code
36835 * expects __USER_DS
36836 */
36837 - loadsegment(ds, __USER_DS);
36838 - loadsegment(es, __USER_DS);
36839 + loadsegment(ds, __KERNEL_DS);
36840 + loadsegment(es, __KERNEL_DS);
36841 #endif
36842
36843 xen_filter_cpu_maps();
36844 @@ -372,7 +368,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
36845 #ifdef CONFIG_X86_32
36846 /* Note: PVH is not yet supported on x86_32. */
36847 ctxt->user_regs.fs = __KERNEL_PERCPU;
36848 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
36849 + savesegment(gs, ctxt->user_regs.gs);
36850 #endif
36851 ctxt->user_regs.eip = (unsigned long)cpu_bringup_and_idle;
36852
36853 @@ -381,8 +377,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
36854 if (!xen_feature(XENFEAT_auto_translated_physmap)) {
36855 ctxt->flags = VGCF_IN_KERNEL;
36856 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
36857 - ctxt->user_regs.ds = __USER_DS;
36858 - ctxt->user_regs.es = __USER_DS;
36859 + ctxt->user_regs.ds = __KERNEL_DS;
36860 + ctxt->user_regs.es = __KERNEL_DS;
36861 ctxt->user_regs.ss = __KERNEL_DS;
36862
36863 xen_copy_trap_info(ctxt->trap_ctxt);
36864 @@ -437,14 +433,13 @@ static int xen_cpu_up(unsigned int cpu, struct task_struct *idle)
36865 int rc;
36866
36867 per_cpu(current_task, cpu) = idle;
36868 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
36869 #ifdef CONFIG_X86_32
36870 irq_ctx_init(cpu);
36871 #else
36872 clear_tsk_thread_flag(idle, TIF_FORK);
36873 #endif
36874 - per_cpu(kernel_stack, cpu) =
36875 - (unsigned long)task_stack_page(idle) -
36876 - KERNEL_STACK_OFFSET + THREAD_SIZE;
36877 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
36878
36879 xen_setup_runstate_info(cpu);
36880 xen_setup_timer(cpu);
36881 @@ -720,7 +715,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
36882
36883 void __init xen_smp_init(void)
36884 {
36885 - smp_ops = xen_smp_ops;
36886 + memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
36887 xen_fill_possible_map();
36888 }
36889
36890 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
36891 index fd92a64..1f72641 100644
36892 --- a/arch/x86/xen/xen-asm_32.S
36893 +++ b/arch/x86/xen/xen-asm_32.S
36894 @@ -99,7 +99,7 @@ ENTRY(xen_iret)
36895 pushw %fs
36896 movl $(__KERNEL_PERCPU), %eax
36897 movl %eax, %fs
36898 - movl %fs:xen_vcpu, %eax
36899 + mov PER_CPU_VAR(xen_vcpu), %eax
36900 POP_FS
36901 #else
36902 movl %ss:xen_vcpu, %eax
36903 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
36904 index 485b695..fda3e7c 100644
36905 --- a/arch/x86/xen/xen-head.S
36906 +++ b/arch/x86/xen/xen-head.S
36907 @@ -39,6 +39,17 @@ ENTRY(startup_xen)
36908 #ifdef CONFIG_X86_32
36909 mov %esi,xen_start_info
36910 mov $init_thread_union+THREAD_SIZE,%esp
36911 +#ifdef CONFIG_SMP
36912 + movl $cpu_gdt_table,%edi
36913 + movl $__per_cpu_load,%eax
36914 + movw %ax,__KERNEL_PERCPU + 2(%edi)
36915 + rorl $16,%eax
36916 + movb %al,__KERNEL_PERCPU + 4(%edi)
36917 + movb %ah,__KERNEL_PERCPU + 7(%edi)
36918 + movl $__per_cpu_end - 1,%eax
36919 + subl $__per_cpu_start,%eax
36920 + movw %ax,__KERNEL_PERCPU + 0(%edi)
36921 +#endif
36922 #else
36923 mov %rsi,xen_start_info
36924 mov $init_thread_union+THREAD_SIZE,%rsp
36925 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
36926 index 28c7e0b..2acfec7 100644
36927 --- a/arch/x86/xen/xen-ops.h
36928 +++ b/arch/x86/xen/xen-ops.h
36929 @@ -10,8 +10,6 @@
36930 extern const char xen_hypervisor_callback[];
36931 extern const char xen_failsafe_callback[];
36932
36933 -extern void *xen_initial_gdt;
36934 -
36935 struct trap_info;
36936 void xen_copy_trap_info(struct trap_info *traps);
36937
36938 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
36939 index 525bd3d..ef888b1 100644
36940 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
36941 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
36942 @@ -119,9 +119,9 @@
36943 ----------------------------------------------------------------------*/
36944
36945 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
36946 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
36947 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
36948 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
36949 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
36950
36951 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
36952 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
36953 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
36954 index 2f33760..835e50a 100644
36955 --- a/arch/xtensa/variants/fsf/include/variant/core.h
36956 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
36957 @@ -11,6 +11,7 @@
36958 #ifndef _XTENSA_CORE_H
36959 #define _XTENSA_CORE_H
36960
36961 +#include <linux/const.h>
36962
36963 /****************************************************************************
36964 Parameters Useful for Any Code, USER or PRIVILEGED
36965 @@ -112,9 +113,9 @@
36966 ----------------------------------------------------------------------*/
36967
36968 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
36969 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
36970 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
36971 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
36972 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
36973
36974 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
36975 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
36976 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
36977 index af00795..2bb8105 100644
36978 --- a/arch/xtensa/variants/s6000/include/variant/core.h
36979 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
36980 @@ -11,6 +11,7 @@
36981 #ifndef _XTENSA_CORE_CONFIGURATION_H
36982 #define _XTENSA_CORE_CONFIGURATION_H
36983
36984 +#include <linux/const.h>
36985
36986 /****************************************************************************
36987 Parameters Useful for Any Code, USER or PRIVILEGED
36988 @@ -118,9 +119,9 @@
36989 ----------------------------------------------------------------------*/
36990
36991 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
36992 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
36993 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
36994 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
36995 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
36996
36997 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
36998 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
36999 diff --git a/block/bio.c b/block/bio.c
37000 index 3e6331d..f970433 100644
37001 --- a/block/bio.c
37002 +++ b/block/bio.c
37003 @@ -1160,7 +1160,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
37004 /*
37005 * Overflow, abort
37006 */
37007 - if (end < start)
37008 + if (end < start || end - start > INT_MAX - nr_pages)
37009 return ERR_PTR(-EINVAL);
37010
37011 nr_pages += end - start;
37012 @@ -1294,7 +1294,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
37013 /*
37014 * Overflow, abort
37015 */
37016 - if (end < start)
37017 + if (end < start || end - start > INT_MAX - nr_pages)
37018 return ERR_PTR(-EINVAL);
37019
37020 nr_pages += end - start;
37021 @@ -1556,7 +1556,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
37022 const int read = bio_data_dir(bio) == READ;
37023 struct bio_map_data *bmd = bio->bi_private;
37024 int i;
37025 - char *p = bmd->sgvecs[0].iov_base;
37026 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
37027
37028 bio_for_each_segment_all(bvec, bio, i) {
37029 char *addr = page_address(bvec->bv_page);
37030 diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
37031 index e17da94..e01cce1 100644
37032 --- a/block/blk-cgroup.c
37033 +++ b/block/blk-cgroup.c
37034 @@ -822,7 +822,7 @@ static void blkcg_css_free(struct cgroup_subsys_state *css)
37035 static struct cgroup_subsys_state *
37036 blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
37037 {
37038 - static atomic64_t id_seq = ATOMIC64_INIT(0);
37039 + static atomic64_unchecked_t id_seq = ATOMIC64_INIT(0);
37040 struct blkcg *blkcg;
37041
37042 if (!parent_css) {
37043 @@ -836,7 +836,7 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
37044
37045 blkcg->cfq_weight = CFQ_WEIGHT_DEFAULT;
37046 blkcg->cfq_leaf_weight = CFQ_WEIGHT_DEFAULT;
37047 - blkcg->id = atomic64_inc_return(&id_seq); /* root is 0, start from 1 */
37048 + blkcg->id = atomic64_inc_return_unchecked(&id_seq); /* root is 0, start from 1 */
37049 done:
37050 spin_lock_init(&blkcg->lock);
37051 INIT_RADIX_TREE(&blkcg->blkg_tree, GFP_ATOMIC);
37052 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
37053 index 0736729..2ec3b48 100644
37054 --- a/block/blk-iopoll.c
37055 +++ b/block/blk-iopoll.c
37056 @@ -74,7 +74,7 @@ void blk_iopoll_complete(struct blk_iopoll *iop)
37057 }
37058 EXPORT_SYMBOL(blk_iopoll_complete);
37059
37060 -static void blk_iopoll_softirq(struct softirq_action *h)
37061 +static __latent_entropy void blk_iopoll_softirq(void)
37062 {
37063 struct list_head *list = this_cpu_ptr(&blk_cpu_iopoll);
37064 int rearm = 0, budget = blk_iopoll_budget;
37065 diff --git a/block/blk-map.c b/block/blk-map.c
37066 index f890d43..97b0482 100644
37067 --- a/block/blk-map.c
37068 +++ b/block/blk-map.c
37069 @@ -300,7 +300,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
37070 if (!len || !kbuf)
37071 return -EINVAL;
37072
37073 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
37074 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
37075 if (do_copy)
37076 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
37077 else
37078 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
37079 index 53b1737..08177d2e 100644
37080 --- a/block/blk-softirq.c
37081 +++ b/block/blk-softirq.c
37082 @@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
37083 * Softirq action handler - move entries to local list and loop over them
37084 * while passing them to the queue registered handler.
37085 */
37086 -static void blk_done_softirq(struct softirq_action *h)
37087 +static __latent_entropy void blk_done_softirq(void)
37088 {
37089 struct list_head *cpu_list, local_list;
37090
37091 diff --git a/block/bsg.c b/block/bsg.c
37092 index ff46add..c4ba8ee 100644
37093 --- a/block/bsg.c
37094 +++ b/block/bsg.c
37095 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
37096 struct sg_io_v4 *hdr, struct bsg_device *bd,
37097 fmode_t has_write_perm)
37098 {
37099 + unsigned char tmpcmd[sizeof(rq->__cmd)];
37100 + unsigned char *cmdptr;
37101 +
37102 if (hdr->request_len > BLK_MAX_CDB) {
37103 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
37104 if (!rq->cmd)
37105 return -ENOMEM;
37106 - }
37107 + cmdptr = rq->cmd;
37108 + } else
37109 + cmdptr = tmpcmd;
37110
37111 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
37112 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
37113 hdr->request_len))
37114 return -EFAULT;
37115
37116 + if (cmdptr != rq->cmd)
37117 + memcpy(rq->cmd, cmdptr, hdr->request_len);
37118 +
37119 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
37120 if (blk_verify_command(rq->cmd, has_write_perm))
37121 return -EPERM;
37122 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
37123 index 18b282c..050dbe5 100644
37124 --- a/block/compat_ioctl.c
37125 +++ b/block/compat_ioctl.c
37126 @@ -156,7 +156,7 @@ static int compat_cdrom_generic_command(struct block_device *bdev, fmode_t mode,
37127 cgc = compat_alloc_user_space(sizeof(*cgc));
37128 cgc32 = compat_ptr(arg);
37129
37130 - if (copy_in_user(&cgc->cmd, &cgc32->cmd, sizeof(cgc->cmd)) ||
37131 + if (copy_in_user(cgc->cmd, cgc32->cmd, sizeof(cgc->cmd)) ||
37132 get_user(data, &cgc32->buffer) ||
37133 put_user(compat_ptr(data), &cgc->buffer) ||
37134 copy_in_user(&cgc->buflen, &cgc32->buflen,
37135 @@ -341,7 +341,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
37136 err |= __get_user(f->spec1, &uf->spec1);
37137 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
37138 err |= __get_user(name, &uf->name);
37139 - f->name = compat_ptr(name);
37140 + f->name = (void __force_kernel *)compat_ptr(name);
37141 if (err) {
37142 err = -EFAULT;
37143 goto out;
37144 diff --git a/block/genhd.c b/block/genhd.c
37145 index e6723bd..703e4ac 100644
37146 --- a/block/genhd.c
37147 +++ b/block/genhd.c
37148 @@ -469,21 +469,24 @@ static char *bdevt_str(dev_t devt, char *buf)
37149
37150 /*
37151 * Register device numbers dev..(dev+range-1)
37152 - * range must be nonzero
37153 + * Noop if @range is zero.
37154 * The hash chain is sorted on range, so that subranges can override.
37155 */
37156 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
37157 struct kobject *(*probe)(dev_t, int *, void *),
37158 int (*lock)(dev_t, void *), void *data)
37159 {
37160 - kobj_map(bdev_map, devt, range, module, probe, lock, data);
37161 + if (range)
37162 + kobj_map(bdev_map, devt, range, module, probe, lock, data);
37163 }
37164
37165 EXPORT_SYMBOL(blk_register_region);
37166
37167 +/* undo blk_register_region(), noop if @range is zero */
37168 void blk_unregister_region(dev_t devt, unsigned long range)
37169 {
37170 - kobj_unmap(bdev_map, devt, range);
37171 + if (range)
37172 + kobj_unmap(bdev_map, devt, range);
37173 }
37174
37175 EXPORT_SYMBOL(blk_unregister_region);
37176 diff --git a/block/partitions/efi.c b/block/partitions/efi.c
37177 index 56d08fd..2e07090 100644
37178 --- a/block/partitions/efi.c
37179 +++ b/block/partitions/efi.c
37180 @@ -293,14 +293,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
37181 if (!gpt)
37182 return NULL;
37183
37184 + if (!le32_to_cpu(gpt->num_partition_entries))
37185 + return NULL;
37186 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
37187 + if (!pte)
37188 + return NULL;
37189 +
37190 count = le32_to_cpu(gpt->num_partition_entries) *
37191 le32_to_cpu(gpt->sizeof_partition_entry);
37192 - if (!count)
37193 - return NULL;
37194 - pte = kmalloc(count, GFP_KERNEL);
37195 - if (!pte)
37196 - return NULL;
37197 -
37198 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
37199 (u8 *) pte, count) < count) {
37200 kfree(pte);
37201 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
37202 index a6d6270..c4bb72f 100644
37203 --- a/block/scsi_ioctl.c
37204 +++ b/block/scsi_ioctl.c
37205 @@ -67,7 +67,7 @@ static int scsi_get_bus(struct request_queue *q, int __user *p)
37206 return put_user(0, p);
37207 }
37208
37209 -static int sg_get_timeout(struct request_queue *q)
37210 +static int __intentional_overflow(-1) sg_get_timeout(struct request_queue *q)
37211 {
37212 return jiffies_to_clock_t(q->sg_timeout);
37213 }
37214 @@ -227,8 +227,20 @@ EXPORT_SYMBOL(blk_verify_command);
37215 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
37216 struct sg_io_hdr *hdr, fmode_t mode)
37217 {
37218 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
37219 + unsigned char tmpcmd[sizeof(rq->__cmd)];
37220 + unsigned char *cmdptr;
37221 +
37222 + if (rq->cmd != rq->__cmd)
37223 + cmdptr = rq->cmd;
37224 + else
37225 + cmdptr = tmpcmd;
37226 +
37227 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
37228 return -EFAULT;
37229 +
37230 + if (cmdptr != rq->cmd)
37231 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
37232 +
37233 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
37234 return -EPERM;
37235
37236 @@ -432,6 +444,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
37237 int err;
37238 unsigned int in_len, out_len, bytes, opcode, cmdlen;
37239 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
37240 + unsigned char tmpcmd[sizeof(rq->__cmd)];
37241 + unsigned char *cmdptr;
37242
37243 if (!sic)
37244 return -EINVAL;
37245 @@ -470,9 +484,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
37246 */
37247 err = -EFAULT;
37248 rq->cmd_len = cmdlen;
37249 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
37250 +
37251 + if (rq->cmd != rq->__cmd)
37252 + cmdptr = rq->cmd;
37253 + else
37254 + cmdptr = tmpcmd;
37255 +
37256 + if (copy_from_user(cmdptr, sic->data, cmdlen))
37257 goto error;
37258
37259 + if (rq->cmd != cmdptr)
37260 + memcpy(rq->cmd, cmdptr, cmdlen);
37261 +
37262 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
37263 goto error;
37264
37265 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
37266 index e592c90..c566114 100644
37267 --- a/crypto/cryptd.c
37268 +++ b/crypto/cryptd.c
37269 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
37270
37271 struct cryptd_blkcipher_request_ctx {
37272 crypto_completion_t complete;
37273 -};
37274 +} __no_const;
37275
37276 struct cryptd_hash_ctx {
37277 struct crypto_shash *child;
37278 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
37279
37280 struct cryptd_aead_request_ctx {
37281 crypto_completion_t complete;
37282 -};
37283 +} __no_const;
37284
37285 static void cryptd_queue_worker(struct work_struct *work);
37286
37287 diff --git a/crypto/cts.c b/crypto/cts.c
37288 index 042223f..133f087 100644
37289 --- a/crypto/cts.c
37290 +++ b/crypto/cts.c
37291 @@ -202,7 +202,8 @@ static int cts_cbc_decrypt(struct crypto_cts_ctx *ctx,
37292 /* 5. Append the tail (BB - Ln) bytes of Xn (tmp) to Cn to create En */
37293 memcpy(s + bsize + lastn, tmp + lastn, bsize - lastn);
37294 /* 6. Decrypt En to create Pn-1 */
37295 - memset(iv, 0, sizeof(iv));
37296 + memzero_explicit(iv, sizeof(iv));
37297 +
37298 sg_set_buf(&sgsrc[0], s + bsize, bsize);
37299 sg_set_buf(&sgdst[0], d, bsize);
37300 err = crypto_blkcipher_decrypt_iv(&lcldesc, sgdst, sgsrc, bsize);
37301 diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
37302 index 309d345..1632720 100644
37303 --- a/crypto/pcrypt.c
37304 +++ b/crypto/pcrypt.c
37305 @@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
37306 int ret;
37307
37308 pinst->kobj.kset = pcrypt_kset;
37309 - ret = kobject_add(&pinst->kobj, NULL, name);
37310 + ret = kobject_add(&pinst->kobj, NULL, "%s", name);
37311 if (!ret)
37312 kobject_uevent(&pinst->kobj, KOBJ_ADD);
37313
37314 diff --git a/crypto/sha1_generic.c b/crypto/sha1_generic.c
37315 index 4279480..7bb0474 100644
37316 --- a/crypto/sha1_generic.c
37317 +++ b/crypto/sha1_generic.c
37318 @@ -64,7 +64,7 @@ int crypto_sha1_update(struct shash_desc *desc, const u8 *data,
37319 src = data + done;
37320 } while (done + SHA1_BLOCK_SIZE <= len);
37321
37322 - memset(temp, 0, sizeof(temp));
37323 + memzero_explicit(temp, sizeof(temp));
37324 partial = 0;
37325 }
37326 memcpy(sctx->buffer + partial, src, len - done);
37327 diff --git a/crypto/sha256_generic.c b/crypto/sha256_generic.c
37328 index 5433667..32c5e5e 100644
37329 --- a/crypto/sha256_generic.c
37330 +++ b/crypto/sha256_generic.c
37331 @@ -210,10 +210,9 @@ static void sha256_transform(u32 *state, const u8 *input)
37332
37333 /* clear any sensitive info... */
37334 a = b = c = d = e = f = g = h = t1 = t2 = 0;
37335 - memset(W, 0, 64 * sizeof(u32));
37336 + memzero_explicit(W, 64 * sizeof(u32));
37337 }
37338
37339 -
37340 static int sha224_init(struct shash_desc *desc)
37341 {
37342 struct sha256_state *sctx = shash_desc_ctx(desc);
37343 @@ -316,7 +315,7 @@ static int sha224_final(struct shash_desc *desc, u8 *hash)
37344 sha256_final(desc, D);
37345
37346 memcpy(hash, D, SHA224_DIGEST_SIZE);
37347 - memset(D, 0, SHA256_DIGEST_SIZE);
37348 + memzero_explicit(D, SHA256_DIGEST_SIZE);
37349
37350 return 0;
37351 }
37352 diff --git a/crypto/sha512_generic.c b/crypto/sha512_generic.c
37353 index 6ed124f..04d295a 100644
37354 --- a/crypto/sha512_generic.c
37355 +++ b/crypto/sha512_generic.c
37356 @@ -238,7 +238,7 @@ static int sha384_final(struct shash_desc *desc, u8 *hash)
37357 sha512_final(desc, D);
37358
37359 memcpy(hash, D, 48);
37360 - memset(D, 0, 64);
37361 + memzero_explicit(D, 64);
37362
37363 return 0;
37364 }
37365 diff --git a/crypto/tgr192.c b/crypto/tgr192.c
37366 index 8740355..3c7af0d 100644
37367 --- a/crypto/tgr192.c
37368 +++ b/crypto/tgr192.c
37369 @@ -612,7 +612,7 @@ static int tgr160_final(struct shash_desc *desc, u8 * out)
37370
37371 tgr192_final(desc, D);
37372 memcpy(out, D, TGR160_DIGEST_SIZE);
37373 - memset(D, 0, TGR192_DIGEST_SIZE);
37374 + memzero_explicit(D, TGR192_DIGEST_SIZE);
37375
37376 return 0;
37377 }
37378 @@ -623,7 +623,7 @@ static int tgr128_final(struct shash_desc *desc, u8 * out)
37379
37380 tgr192_final(desc, D);
37381 memcpy(out, D, TGR128_DIGEST_SIZE);
37382 - memset(D, 0, TGR192_DIGEST_SIZE);
37383 + memzero_explicit(D, TGR192_DIGEST_SIZE);
37384
37385 return 0;
37386 }
37387 diff --git a/crypto/vmac.c b/crypto/vmac.c
37388 index 2eb11a3..d84c24b 100644
37389 --- a/crypto/vmac.c
37390 +++ b/crypto/vmac.c
37391 @@ -613,7 +613,7 @@ static int vmac_final(struct shash_desc *pdesc, u8 *out)
37392 }
37393 mac = vmac(ctx->partial, ctx->partial_size, nonce, NULL, ctx);
37394 memcpy(out, &mac, sizeof(vmac_t));
37395 - memset(&mac, 0, sizeof(vmac_t));
37396 + memzero_explicit(&mac, sizeof(vmac_t));
37397 memset(&ctx->__vmac_ctx, 0, sizeof(struct vmac_ctx));
37398 ctx->partial_size = 0;
37399 return 0;
37400 diff --git a/crypto/wp512.c b/crypto/wp512.c
37401 index 180f1d6..ec64e77 100644
37402 --- a/crypto/wp512.c
37403 +++ b/crypto/wp512.c
37404 @@ -1102,8 +1102,8 @@ static int wp384_final(struct shash_desc *desc, u8 *out)
37405 u8 D[64];
37406
37407 wp512_final(desc, D);
37408 - memcpy (out, D, WP384_DIGEST_SIZE);
37409 - memset (D, 0, WP512_DIGEST_SIZE);
37410 + memcpy(out, D, WP384_DIGEST_SIZE);
37411 + memzero_explicit(D, WP512_DIGEST_SIZE);
37412
37413 return 0;
37414 }
37415 @@ -1113,8 +1113,8 @@ static int wp256_final(struct shash_desc *desc, u8 *out)
37416 u8 D[64];
37417
37418 wp512_final(desc, D);
37419 - memcpy (out, D, WP256_DIGEST_SIZE);
37420 - memset (D, 0, WP512_DIGEST_SIZE);
37421 + memcpy(out, D, WP256_DIGEST_SIZE);
37422 + memzero_explicit(D, WP512_DIGEST_SIZE);
37423
37424 return 0;
37425 }
37426 diff --git a/drivers/acpi/acpica/hwxfsleep.c b/drivers/acpi/acpica/hwxfsleep.c
37427 index 6921c7f..78e1af7 100644
37428 --- a/drivers/acpi/acpica/hwxfsleep.c
37429 +++ b/drivers/acpi/acpica/hwxfsleep.c
37430 @@ -63,11 +63,12 @@ static acpi_status acpi_hw_sleep_dispatch(u8 sleep_state, u32 function_id);
37431 /* Legacy functions are optional, based upon ACPI_REDUCED_HARDWARE */
37432
37433 static struct acpi_sleep_functions acpi_sleep_dispatch[] = {
37434 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
37435 - acpi_hw_extended_sleep},
37436 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
37437 - acpi_hw_extended_wake_prep},
37438 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake), acpi_hw_extended_wake}
37439 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
37440 + .extended_function = acpi_hw_extended_sleep},
37441 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
37442 + .extended_function = acpi_hw_extended_wake_prep},
37443 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake),
37444 + .extended_function = acpi_hw_extended_wake}
37445 };
37446
37447 /*
37448 diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
37449 index 16129c7..8b675cd 100644
37450 --- a/drivers/acpi/apei/apei-internal.h
37451 +++ b/drivers/acpi/apei/apei-internal.h
37452 @@ -19,7 +19,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
37453 struct apei_exec_ins_type {
37454 u32 flags;
37455 apei_exec_ins_func_t run;
37456 -};
37457 +} __do_const;
37458
37459 struct apei_exec_context {
37460 u32 ip;
37461 diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
37462 index fc5f780..e5ac91a 100644
37463 --- a/drivers/acpi/apei/ghes.c
37464 +++ b/drivers/acpi/apei/ghes.c
37465 @@ -478,7 +478,7 @@ static void __ghes_print_estatus(const char *pfx,
37466 const struct acpi_hest_generic *generic,
37467 const struct acpi_hest_generic_status *estatus)
37468 {
37469 - static atomic_t seqno;
37470 + static atomic_unchecked_t seqno;
37471 unsigned int curr_seqno;
37472 char pfx_seq[64];
37473
37474 @@ -489,7 +489,7 @@ static void __ghes_print_estatus(const char *pfx,
37475 else
37476 pfx = KERN_ERR;
37477 }
37478 - curr_seqno = atomic_inc_return(&seqno);
37479 + curr_seqno = atomic_inc_return_unchecked(&seqno);
37480 snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}" HW_ERR, pfx, curr_seqno);
37481 printk("%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
37482 pfx_seq, generic->header.source_id);
37483 diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
37484 index a83e3c6..c3d617f 100644
37485 --- a/drivers/acpi/bgrt.c
37486 +++ b/drivers/acpi/bgrt.c
37487 @@ -86,8 +86,10 @@ static int __init bgrt_init(void)
37488 if (!bgrt_image)
37489 return -ENODEV;
37490
37491 - bin_attr_image.private = bgrt_image;
37492 - bin_attr_image.size = bgrt_image_size;
37493 + pax_open_kernel();
37494 + *(void **)&bin_attr_image.private = bgrt_image;
37495 + *(size_t *)&bin_attr_image.size = bgrt_image_size;
37496 + pax_close_kernel();
37497
37498 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
37499 if (!bgrt_kobj)
37500 diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
37501 index 36eb42e..3b2f47e 100644
37502 --- a/drivers/acpi/blacklist.c
37503 +++ b/drivers/acpi/blacklist.c
37504 @@ -51,7 +51,7 @@ struct acpi_blacklist_item {
37505 u32 is_critical_error;
37506 };
37507
37508 -static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
37509 +static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
37510
37511 /*
37512 * POLICY: If *anything* doesn't work, put it on the blacklist.
37513 @@ -163,7 +163,7 @@ static int __init dmi_disable_osi_win8(const struct dmi_system_id *d)
37514 return 0;
37515 }
37516
37517 -static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
37518 +static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
37519 {
37520 .callback = dmi_disable_osi_vista,
37521 .ident = "Fujitsu Siemens",
37522 diff --git a/drivers/acpi/custom_method.c b/drivers/acpi/custom_method.c
37523 index c68e724..e863008 100644
37524 --- a/drivers/acpi/custom_method.c
37525 +++ b/drivers/acpi/custom_method.c
37526 @@ -29,6 +29,10 @@ static ssize_t cm_write(struct file *file, const char __user * user_buf,
37527 struct acpi_table_header table;
37528 acpi_status status;
37529
37530 +#ifdef CONFIG_GRKERNSEC_KMEM
37531 + return -EPERM;
37532 +#endif
37533 +
37534 if (!(*ppos)) {
37535 /* parse the table header to get the table length */
37536 if (count <= sizeof(struct acpi_table_header))
37537 diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
37538 index 17f9ec5..d9a455e 100644
37539 --- a/drivers/acpi/processor_idle.c
37540 +++ b/drivers/acpi/processor_idle.c
37541 @@ -952,7 +952,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
37542 {
37543 int i, count = CPUIDLE_DRIVER_STATE_START;
37544 struct acpi_processor_cx *cx;
37545 - struct cpuidle_state *state;
37546 + cpuidle_state_no_const *state;
37547 struct cpuidle_driver *drv = &acpi_idle_driver;
37548
37549 if (!pr->flags.power_setup_done)
37550 diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
37551 index 38cb978..352c761 100644
37552 --- a/drivers/acpi/sysfs.c
37553 +++ b/drivers/acpi/sysfs.c
37554 @@ -423,11 +423,11 @@ static u32 num_counters;
37555 static struct attribute **all_attrs;
37556 static u32 acpi_gpe_count;
37557
37558 -static struct attribute_group interrupt_stats_attr_group = {
37559 +static attribute_group_no_const interrupt_stats_attr_group = {
37560 .name = "interrupts",
37561 };
37562
37563 -static struct kobj_attribute *counter_attrs;
37564 +static kobj_attribute_no_const *counter_attrs;
37565
37566 static void delete_gpe_attr_array(void)
37567 {
37568 diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
37569 index b784e9d..a69a049 100644
37570 --- a/drivers/ata/libahci.c
37571 +++ b/drivers/ata/libahci.c
37572 @@ -1252,7 +1252,7 @@ int ahci_kick_engine(struct ata_port *ap)
37573 }
37574 EXPORT_SYMBOL_GPL(ahci_kick_engine);
37575
37576 -static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
37577 +static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
37578 struct ata_taskfile *tf, int is_cmd, u16 flags,
37579 unsigned long timeout_msec)
37580 {
37581 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
37582 index 6f67490..f951ead 100644
37583 --- a/drivers/ata/libata-core.c
37584 +++ b/drivers/ata/libata-core.c
37585 @@ -99,7 +99,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
37586 static void ata_dev_xfermask(struct ata_device *dev);
37587 static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
37588
37589 -atomic_t ata_print_id = ATOMIC_INIT(0);
37590 +atomic_unchecked_t ata_print_id = ATOMIC_INIT(0);
37591
37592 struct ata_force_param {
37593 const char *name;
37594 @@ -4797,7 +4797,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
37595 struct ata_port *ap;
37596 unsigned int tag;
37597
37598 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
37599 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
37600 ap = qc->ap;
37601
37602 qc->flags = 0;
37603 @@ -4813,7 +4813,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
37604 struct ata_port *ap;
37605 struct ata_link *link;
37606
37607 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
37608 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
37609 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
37610 ap = qc->ap;
37611 link = qc->dev->link;
37612 @@ -5917,6 +5917,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
37613 return;
37614
37615 spin_lock(&lock);
37616 + pax_open_kernel();
37617
37618 for (cur = ops->inherits; cur; cur = cur->inherits) {
37619 void **inherit = (void **)cur;
37620 @@ -5930,8 +5931,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
37621 if (IS_ERR(*pp))
37622 *pp = NULL;
37623
37624 - ops->inherits = NULL;
37625 + *(struct ata_port_operations **)&ops->inherits = NULL;
37626
37627 + pax_close_kernel();
37628 spin_unlock(&lock);
37629 }
37630
37631 @@ -6127,7 +6129,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
37632
37633 /* give ports names and add SCSI hosts */
37634 for (i = 0; i < host->n_ports; i++) {
37635 - host->ports[i]->print_id = atomic_inc_return(&ata_print_id);
37636 + host->ports[i]->print_id = atomic_inc_return_unchecked(&ata_print_id);
37637 host->ports[i]->local_port_no = i + 1;
37638 }
37639
37640 diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
37641 index 0586f66..1a8f74a 100644
37642 --- a/drivers/ata/libata-scsi.c
37643 +++ b/drivers/ata/libata-scsi.c
37644 @@ -4151,7 +4151,7 @@ int ata_sas_port_init(struct ata_port *ap)
37645
37646 if (rc)
37647 return rc;
37648 - ap->print_id = atomic_inc_return(&ata_print_id);
37649 + ap->print_id = atomic_inc_return_unchecked(&ata_print_id);
37650 return 0;
37651 }
37652 EXPORT_SYMBOL_GPL(ata_sas_port_init);
37653 diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
37654 index 5f4e0cc..ff2c347 100644
37655 --- a/drivers/ata/libata.h
37656 +++ b/drivers/ata/libata.h
37657 @@ -53,7 +53,7 @@ enum {
37658 ATA_DNXFER_QUIET = (1 << 31),
37659 };
37660
37661 -extern atomic_t ata_print_id;
37662 +extern atomic_unchecked_t ata_print_id;
37663 extern int atapi_passthru16;
37664 extern int libata_fua;
37665 extern int libata_noacpi;
37666 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
37667 index 4edb1a8..84e1658 100644
37668 --- a/drivers/ata/pata_arasan_cf.c
37669 +++ b/drivers/ata/pata_arasan_cf.c
37670 @@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
37671 /* Handle platform specific quirks */
37672 if (quirk) {
37673 if (quirk & CF_BROKEN_PIO) {
37674 - ap->ops->set_piomode = NULL;
37675 + pax_open_kernel();
37676 + *(void **)&ap->ops->set_piomode = NULL;
37677 + pax_close_kernel();
37678 ap->pio_mask = 0;
37679 }
37680 if (quirk & CF_BROKEN_MWDMA)
37681 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
37682 index f9b983a..887b9d8 100644
37683 --- a/drivers/atm/adummy.c
37684 +++ b/drivers/atm/adummy.c
37685 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
37686 vcc->pop(vcc, skb);
37687 else
37688 dev_kfree_skb_any(skb);
37689 - atomic_inc(&vcc->stats->tx);
37690 + atomic_inc_unchecked(&vcc->stats->tx);
37691
37692 return 0;
37693 }
37694 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
37695 index f1a9198..f466a4a 100644
37696 --- a/drivers/atm/ambassador.c
37697 +++ b/drivers/atm/ambassador.c
37698 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
37699 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
37700
37701 // VC layer stats
37702 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
37703 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
37704
37705 // free the descriptor
37706 kfree (tx_descr);
37707 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
37708 dump_skb ("<<<", vc, skb);
37709
37710 // VC layer stats
37711 - atomic_inc(&atm_vcc->stats->rx);
37712 + atomic_inc_unchecked(&atm_vcc->stats->rx);
37713 __net_timestamp(skb);
37714 // end of our responsibility
37715 atm_vcc->push (atm_vcc, skb);
37716 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
37717 } else {
37718 PRINTK (KERN_INFO, "dropped over-size frame");
37719 // should we count this?
37720 - atomic_inc(&atm_vcc->stats->rx_drop);
37721 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
37722 }
37723
37724 } else {
37725 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
37726 }
37727
37728 if (check_area (skb->data, skb->len)) {
37729 - atomic_inc(&atm_vcc->stats->tx_err);
37730 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
37731 return -ENOMEM; // ?
37732 }
37733
37734 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
37735 index 480fa6f..947067c 100644
37736 --- a/drivers/atm/atmtcp.c
37737 +++ b/drivers/atm/atmtcp.c
37738 @@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
37739 if (vcc->pop) vcc->pop(vcc,skb);
37740 else dev_kfree_skb(skb);
37741 if (dev_data) return 0;
37742 - atomic_inc(&vcc->stats->tx_err);
37743 + atomic_inc_unchecked(&vcc->stats->tx_err);
37744 return -ENOLINK;
37745 }
37746 size = skb->len+sizeof(struct atmtcp_hdr);
37747 @@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
37748 if (!new_skb) {
37749 if (vcc->pop) vcc->pop(vcc,skb);
37750 else dev_kfree_skb(skb);
37751 - atomic_inc(&vcc->stats->tx_err);
37752 + atomic_inc_unchecked(&vcc->stats->tx_err);
37753 return -ENOBUFS;
37754 }
37755 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
37756 @@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
37757 if (vcc->pop) vcc->pop(vcc,skb);
37758 else dev_kfree_skb(skb);
37759 out_vcc->push(out_vcc,new_skb);
37760 - atomic_inc(&vcc->stats->tx);
37761 - atomic_inc(&out_vcc->stats->rx);
37762 + atomic_inc_unchecked(&vcc->stats->tx);
37763 + atomic_inc_unchecked(&out_vcc->stats->rx);
37764 return 0;
37765 }
37766
37767 @@ -300,7 +300,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
37768 read_unlock(&vcc_sklist_lock);
37769 if (!out_vcc) {
37770 result = -EUNATCH;
37771 - atomic_inc(&vcc->stats->tx_err);
37772 + atomic_inc_unchecked(&vcc->stats->tx_err);
37773 goto done;
37774 }
37775 skb_pull(skb,sizeof(struct atmtcp_hdr));
37776 @@ -312,8 +312,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
37777 __net_timestamp(new_skb);
37778 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
37779 out_vcc->push(out_vcc,new_skb);
37780 - atomic_inc(&vcc->stats->tx);
37781 - atomic_inc(&out_vcc->stats->rx);
37782 + atomic_inc_unchecked(&vcc->stats->tx);
37783 + atomic_inc_unchecked(&out_vcc->stats->rx);
37784 done:
37785 if (vcc->pop) vcc->pop(vcc,skb);
37786 else dev_kfree_skb(skb);
37787 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
37788 index d65975a..0b87e20 100644
37789 --- a/drivers/atm/eni.c
37790 +++ b/drivers/atm/eni.c
37791 @@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
37792 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
37793 vcc->dev->number);
37794 length = 0;
37795 - atomic_inc(&vcc->stats->rx_err);
37796 + atomic_inc_unchecked(&vcc->stats->rx_err);
37797 }
37798 else {
37799 length = ATM_CELL_SIZE-1; /* no HEC */
37800 @@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
37801 size);
37802 }
37803 eff = length = 0;
37804 - atomic_inc(&vcc->stats->rx_err);
37805 + atomic_inc_unchecked(&vcc->stats->rx_err);
37806 }
37807 else {
37808 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
37809 @@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
37810 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
37811 vcc->dev->number,vcc->vci,length,size << 2,descr);
37812 length = eff = 0;
37813 - atomic_inc(&vcc->stats->rx_err);
37814 + atomic_inc_unchecked(&vcc->stats->rx_err);
37815 }
37816 }
37817 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
37818 @@ -767,7 +767,7 @@ rx_dequeued++;
37819 vcc->push(vcc,skb);
37820 pushed++;
37821 }
37822 - atomic_inc(&vcc->stats->rx);
37823 + atomic_inc_unchecked(&vcc->stats->rx);
37824 }
37825 wake_up(&eni_dev->rx_wait);
37826 }
37827 @@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
37828 PCI_DMA_TODEVICE);
37829 if (vcc->pop) vcc->pop(vcc,skb);
37830 else dev_kfree_skb_irq(skb);
37831 - atomic_inc(&vcc->stats->tx);
37832 + atomic_inc_unchecked(&vcc->stats->tx);
37833 wake_up(&eni_dev->tx_wait);
37834 dma_complete++;
37835 }
37836 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
37837 index 82f2ae0..f205c02 100644
37838 --- a/drivers/atm/firestream.c
37839 +++ b/drivers/atm/firestream.c
37840 @@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
37841 }
37842 }
37843
37844 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
37845 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
37846
37847 fs_dprintk (FS_DEBUG_TXMEM, "i");
37848 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
37849 @@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
37850 #endif
37851 skb_put (skb, qe->p1 & 0xffff);
37852 ATM_SKB(skb)->vcc = atm_vcc;
37853 - atomic_inc(&atm_vcc->stats->rx);
37854 + atomic_inc_unchecked(&atm_vcc->stats->rx);
37855 __net_timestamp(skb);
37856 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
37857 atm_vcc->push (atm_vcc, skb);
37858 @@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
37859 kfree (pe);
37860 }
37861 if (atm_vcc)
37862 - atomic_inc(&atm_vcc->stats->rx_drop);
37863 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
37864 break;
37865 case 0x1f: /* Reassembly abort: no buffers. */
37866 /* Silently increment error counter. */
37867 if (atm_vcc)
37868 - atomic_inc(&atm_vcc->stats->rx_drop);
37869 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
37870 break;
37871 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
37872 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
37873 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
37874 index d4725fc..2d4ea65 100644
37875 --- a/drivers/atm/fore200e.c
37876 +++ b/drivers/atm/fore200e.c
37877 @@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
37878 #endif
37879 /* check error condition */
37880 if (*entry->status & STATUS_ERROR)
37881 - atomic_inc(&vcc->stats->tx_err);
37882 + atomic_inc_unchecked(&vcc->stats->tx_err);
37883 else
37884 - atomic_inc(&vcc->stats->tx);
37885 + atomic_inc_unchecked(&vcc->stats->tx);
37886 }
37887 }
37888
37889 @@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
37890 if (skb == NULL) {
37891 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
37892
37893 - atomic_inc(&vcc->stats->rx_drop);
37894 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37895 return -ENOMEM;
37896 }
37897
37898 @@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
37899
37900 dev_kfree_skb_any(skb);
37901
37902 - atomic_inc(&vcc->stats->rx_drop);
37903 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37904 return -ENOMEM;
37905 }
37906
37907 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
37908
37909 vcc->push(vcc, skb);
37910 - atomic_inc(&vcc->stats->rx);
37911 + atomic_inc_unchecked(&vcc->stats->rx);
37912
37913 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
37914
37915 @@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
37916 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
37917 fore200e->atm_dev->number,
37918 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
37919 - atomic_inc(&vcc->stats->rx_err);
37920 + atomic_inc_unchecked(&vcc->stats->rx_err);
37921 }
37922 }
37923
37924 @@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
37925 goto retry_here;
37926 }
37927
37928 - atomic_inc(&vcc->stats->tx_err);
37929 + atomic_inc_unchecked(&vcc->stats->tx_err);
37930
37931 fore200e->tx_sat++;
37932 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
37933 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
37934 index c39702b..785b73b 100644
37935 --- a/drivers/atm/he.c
37936 +++ b/drivers/atm/he.c
37937 @@ -1689,7 +1689,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
37938
37939 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
37940 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
37941 - atomic_inc(&vcc->stats->rx_drop);
37942 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37943 goto return_host_buffers;
37944 }
37945
37946 @@ -1716,7 +1716,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
37947 RBRQ_LEN_ERR(he_dev->rbrq_head)
37948 ? "LEN_ERR" : "",
37949 vcc->vpi, vcc->vci);
37950 - atomic_inc(&vcc->stats->rx_err);
37951 + atomic_inc_unchecked(&vcc->stats->rx_err);
37952 goto return_host_buffers;
37953 }
37954
37955 @@ -1768,7 +1768,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
37956 vcc->push(vcc, skb);
37957 spin_lock(&he_dev->global_lock);
37958
37959 - atomic_inc(&vcc->stats->rx);
37960 + atomic_inc_unchecked(&vcc->stats->rx);
37961
37962 return_host_buffers:
37963 ++pdus_assembled;
37964 @@ -2094,7 +2094,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
37965 tpd->vcc->pop(tpd->vcc, tpd->skb);
37966 else
37967 dev_kfree_skb_any(tpd->skb);
37968 - atomic_inc(&tpd->vcc->stats->tx_err);
37969 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
37970 }
37971 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
37972 return;
37973 @@ -2506,7 +2506,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
37974 vcc->pop(vcc, skb);
37975 else
37976 dev_kfree_skb_any(skb);
37977 - atomic_inc(&vcc->stats->tx_err);
37978 + atomic_inc_unchecked(&vcc->stats->tx_err);
37979 return -EINVAL;
37980 }
37981
37982 @@ -2517,7 +2517,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
37983 vcc->pop(vcc, skb);
37984 else
37985 dev_kfree_skb_any(skb);
37986 - atomic_inc(&vcc->stats->tx_err);
37987 + atomic_inc_unchecked(&vcc->stats->tx_err);
37988 return -EINVAL;
37989 }
37990 #endif
37991 @@ -2529,7 +2529,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
37992 vcc->pop(vcc, skb);
37993 else
37994 dev_kfree_skb_any(skb);
37995 - atomic_inc(&vcc->stats->tx_err);
37996 + atomic_inc_unchecked(&vcc->stats->tx_err);
37997 spin_unlock_irqrestore(&he_dev->global_lock, flags);
37998 return -ENOMEM;
37999 }
38000 @@ -2571,7 +2571,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
38001 vcc->pop(vcc, skb);
38002 else
38003 dev_kfree_skb_any(skb);
38004 - atomic_inc(&vcc->stats->tx_err);
38005 + atomic_inc_unchecked(&vcc->stats->tx_err);
38006 spin_unlock_irqrestore(&he_dev->global_lock, flags);
38007 return -ENOMEM;
38008 }
38009 @@ -2602,7 +2602,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
38010 __enqueue_tpd(he_dev, tpd, cid);
38011 spin_unlock_irqrestore(&he_dev->global_lock, flags);
38012
38013 - atomic_inc(&vcc->stats->tx);
38014 + atomic_inc_unchecked(&vcc->stats->tx);
38015
38016 return 0;
38017 }
38018 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
38019 index 1dc0519..1aadaf7 100644
38020 --- a/drivers/atm/horizon.c
38021 +++ b/drivers/atm/horizon.c
38022 @@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
38023 {
38024 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
38025 // VC layer stats
38026 - atomic_inc(&vcc->stats->rx);
38027 + atomic_inc_unchecked(&vcc->stats->rx);
38028 __net_timestamp(skb);
38029 // end of our responsibility
38030 vcc->push (vcc, skb);
38031 @@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
38032 dev->tx_iovec = NULL;
38033
38034 // VC layer stats
38035 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
38036 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
38037
38038 // free the skb
38039 hrz_kfree_skb (skb);
38040 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
38041 index 2b24ed0..b3d6acc 100644
38042 --- a/drivers/atm/idt77252.c
38043 +++ b/drivers/atm/idt77252.c
38044 @@ -810,7 +810,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
38045 else
38046 dev_kfree_skb(skb);
38047
38048 - atomic_inc(&vcc->stats->tx);
38049 + atomic_inc_unchecked(&vcc->stats->tx);
38050 }
38051
38052 atomic_dec(&scq->used);
38053 @@ -1072,13 +1072,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
38054 if ((sb = dev_alloc_skb(64)) == NULL) {
38055 printk("%s: Can't allocate buffers for aal0.\n",
38056 card->name);
38057 - atomic_add(i, &vcc->stats->rx_drop);
38058 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
38059 break;
38060 }
38061 if (!atm_charge(vcc, sb->truesize)) {
38062 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
38063 card->name);
38064 - atomic_add(i - 1, &vcc->stats->rx_drop);
38065 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
38066 dev_kfree_skb(sb);
38067 break;
38068 }
38069 @@ -1095,7 +1095,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
38070 ATM_SKB(sb)->vcc = vcc;
38071 __net_timestamp(sb);
38072 vcc->push(vcc, sb);
38073 - atomic_inc(&vcc->stats->rx);
38074 + atomic_inc_unchecked(&vcc->stats->rx);
38075
38076 cell += ATM_CELL_PAYLOAD;
38077 }
38078 @@ -1132,13 +1132,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
38079 "(CDC: %08x)\n",
38080 card->name, len, rpp->len, readl(SAR_REG_CDC));
38081 recycle_rx_pool_skb(card, rpp);
38082 - atomic_inc(&vcc->stats->rx_err);
38083 + atomic_inc_unchecked(&vcc->stats->rx_err);
38084 return;
38085 }
38086 if (stat & SAR_RSQE_CRC) {
38087 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
38088 recycle_rx_pool_skb(card, rpp);
38089 - atomic_inc(&vcc->stats->rx_err);
38090 + atomic_inc_unchecked(&vcc->stats->rx_err);
38091 return;
38092 }
38093 if (skb_queue_len(&rpp->queue) > 1) {
38094 @@ -1149,7 +1149,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
38095 RXPRINTK("%s: Can't alloc RX skb.\n",
38096 card->name);
38097 recycle_rx_pool_skb(card, rpp);
38098 - atomic_inc(&vcc->stats->rx_err);
38099 + atomic_inc_unchecked(&vcc->stats->rx_err);
38100 return;
38101 }
38102 if (!atm_charge(vcc, skb->truesize)) {
38103 @@ -1168,7 +1168,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
38104 __net_timestamp(skb);
38105
38106 vcc->push(vcc, skb);
38107 - atomic_inc(&vcc->stats->rx);
38108 + atomic_inc_unchecked(&vcc->stats->rx);
38109
38110 return;
38111 }
38112 @@ -1190,7 +1190,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
38113 __net_timestamp(skb);
38114
38115 vcc->push(vcc, skb);
38116 - atomic_inc(&vcc->stats->rx);
38117 + atomic_inc_unchecked(&vcc->stats->rx);
38118
38119 if (skb->truesize > SAR_FB_SIZE_3)
38120 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
38121 @@ -1301,14 +1301,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
38122 if (vcc->qos.aal != ATM_AAL0) {
38123 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
38124 card->name, vpi, vci);
38125 - atomic_inc(&vcc->stats->rx_drop);
38126 + atomic_inc_unchecked(&vcc->stats->rx_drop);
38127 goto drop;
38128 }
38129
38130 if ((sb = dev_alloc_skb(64)) == NULL) {
38131 printk("%s: Can't allocate buffers for AAL0.\n",
38132 card->name);
38133 - atomic_inc(&vcc->stats->rx_err);
38134 + atomic_inc_unchecked(&vcc->stats->rx_err);
38135 goto drop;
38136 }
38137
38138 @@ -1327,7 +1327,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
38139 ATM_SKB(sb)->vcc = vcc;
38140 __net_timestamp(sb);
38141 vcc->push(vcc, sb);
38142 - atomic_inc(&vcc->stats->rx);
38143 + atomic_inc_unchecked(&vcc->stats->rx);
38144
38145 drop:
38146 skb_pull(queue, 64);
38147 @@ -1952,13 +1952,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
38148
38149 if (vc == NULL) {
38150 printk("%s: NULL connection in send().\n", card->name);
38151 - atomic_inc(&vcc->stats->tx_err);
38152 + atomic_inc_unchecked(&vcc->stats->tx_err);
38153 dev_kfree_skb(skb);
38154 return -EINVAL;
38155 }
38156 if (!test_bit(VCF_TX, &vc->flags)) {
38157 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
38158 - atomic_inc(&vcc->stats->tx_err);
38159 + atomic_inc_unchecked(&vcc->stats->tx_err);
38160 dev_kfree_skb(skb);
38161 return -EINVAL;
38162 }
38163 @@ -1970,14 +1970,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
38164 break;
38165 default:
38166 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
38167 - atomic_inc(&vcc->stats->tx_err);
38168 + atomic_inc_unchecked(&vcc->stats->tx_err);
38169 dev_kfree_skb(skb);
38170 return -EINVAL;
38171 }
38172
38173 if (skb_shinfo(skb)->nr_frags != 0) {
38174 printk("%s: No scatter-gather yet.\n", card->name);
38175 - atomic_inc(&vcc->stats->tx_err);
38176 + atomic_inc_unchecked(&vcc->stats->tx_err);
38177 dev_kfree_skb(skb);
38178 return -EINVAL;
38179 }
38180 @@ -1985,7 +1985,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
38181
38182 err = queue_skb(card, vc, skb, oam);
38183 if (err) {
38184 - atomic_inc(&vcc->stats->tx_err);
38185 + atomic_inc_unchecked(&vcc->stats->tx_err);
38186 dev_kfree_skb(skb);
38187 return err;
38188 }
38189 @@ -2008,7 +2008,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
38190 skb = dev_alloc_skb(64);
38191 if (!skb) {
38192 printk("%s: Out of memory in send_oam().\n", card->name);
38193 - atomic_inc(&vcc->stats->tx_err);
38194 + atomic_inc_unchecked(&vcc->stats->tx_err);
38195 return -ENOMEM;
38196 }
38197 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
38198 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
38199 index 4217f29..88f547a 100644
38200 --- a/drivers/atm/iphase.c
38201 +++ b/drivers/atm/iphase.c
38202 @@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
38203 status = (u_short) (buf_desc_ptr->desc_mode);
38204 if (status & (RX_CER | RX_PTE | RX_OFL))
38205 {
38206 - atomic_inc(&vcc->stats->rx_err);
38207 + atomic_inc_unchecked(&vcc->stats->rx_err);
38208 IF_ERR(printk("IA: bad packet, dropping it");)
38209 if (status & RX_CER) {
38210 IF_ERR(printk(" cause: packet CRC error\n");)
38211 @@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
38212 len = dma_addr - buf_addr;
38213 if (len > iadev->rx_buf_sz) {
38214 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
38215 - atomic_inc(&vcc->stats->rx_err);
38216 + atomic_inc_unchecked(&vcc->stats->rx_err);
38217 goto out_free_desc;
38218 }
38219
38220 @@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
38221 ia_vcc = INPH_IA_VCC(vcc);
38222 if (ia_vcc == NULL)
38223 {
38224 - atomic_inc(&vcc->stats->rx_err);
38225 + atomic_inc_unchecked(&vcc->stats->rx_err);
38226 atm_return(vcc, skb->truesize);
38227 dev_kfree_skb_any(skb);
38228 goto INCR_DLE;
38229 @@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
38230 if ((length > iadev->rx_buf_sz) || (length >
38231 (skb->len - sizeof(struct cpcs_trailer))))
38232 {
38233 - atomic_inc(&vcc->stats->rx_err);
38234 + atomic_inc_unchecked(&vcc->stats->rx_err);
38235 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
38236 length, skb->len);)
38237 atm_return(vcc, skb->truesize);
38238 @@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
38239
38240 IF_RX(printk("rx_dle_intr: skb push");)
38241 vcc->push(vcc,skb);
38242 - atomic_inc(&vcc->stats->rx);
38243 + atomic_inc_unchecked(&vcc->stats->rx);
38244 iadev->rx_pkt_cnt++;
38245 }
38246 INCR_DLE:
38247 @@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
38248 {
38249 struct k_sonet_stats *stats;
38250 stats = &PRIV(_ia_dev[board])->sonet_stats;
38251 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
38252 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
38253 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
38254 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
38255 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
38256 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
38257 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
38258 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
38259 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
38260 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
38261 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
38262 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
38263 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
38264 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
38265 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
38266 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
38267 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
38268 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
38269 }
38270 ia_cmds.status = 0;
38271 break;
38272 @@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
38273 if ((desc == 0) || (desc > iadev->num_tx_desc))
38274 {
38275 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
38276 - atomic_inc(&vcc->stats->tx);
38277 + atomic_inc_unchecked(&vcc->stats->tx);
38278 if (vcc->pop)
38279 vcc->pop(vcc, skb);
38280 else
38281 @@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
38282 ATM_DESC(skb) = vcc->vci;
38283 skb_queue_tail(&iadev->tx_dma_q, skb);
38284
38285 - atomic_inc(&vcc->stats->tx);
38286 + atomic_inc_unchecked(&vcc->stats->tx);
38287 iadev->tx_pkt_cnt++;
38288 /* Increment transaction counter */
38289 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
38290
38291 #if 0
38292 /* add flow control logic */
38293 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
38294 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
38295 if (iavcc->vc_desc_cnt > 10) {
38296 vcc->tx_quota = vcc->tx_quota * 3 / 4;
38297 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
38298 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
38299 index fa7d7019..1e404c7 100644
38300 --- a/drivers/atm/lanai.c
38301 +++ b/drivers/atm/lanai.c
38302 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
38303 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
38304 lanai_endtx(lanai, lvcc);
38305 lanai_free_skb(lvcc->tx.atmvcc, skb);
38306 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
38307 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
38308 }
38309
38310 /* Try to fill the buffer - don't call unless there is backlog */
38311 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
38312 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
38313 __net_timestamp(skb);
38314 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
38315 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
38316 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
38317 out:
38318 lvcc->rx.buf.ptr = end;
38319 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
38320 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
38321 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
38322 "vcc %d\n", lanai->number, (unsigned int) s, vci);
38323 lanai->stats.service_rxnotaal5++;
38324 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
38325 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
38326 return 0;
38327 }
38328 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
38329 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
38330 int bytes;
38331 read_unlock(&vcc_sklist_lock);
38332 DPRINTK("got trashed rx pdu on vci %d\n", vci);
38333 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
38334 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
38335 lvcc->stats.x.aal5.service_trash++;
38336 bytes = (SERVICE_GET_END(s) * 16) -
38337 (((unsigned long) lvcc->rx.buf.ptr) -
38338 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
38339 }
38340 if (s & SERVICE_STREAM) {
38341 read_unlock(&vcc_sklist_lock);
38342 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
38343 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
38344 lvcc->stats.x.aal5.service_stream++;
38345 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
38346 "PDU on VCI %d!\n", lanai->number, vci);
38347 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
38348 return 0;
38349 }
38350 DPRINTK("got rx crc error on vci %d\n", vci);
38351 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
38352 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
38353 lvcc->stats.x.aal5.service_rxcrc++;
38354 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
38355 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
38356 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
38357 index 9988ac9..7c52585 100644
38358 --- a/drivers/atm/nicstar.c
38359 +++ b/drivers/atm/nicstar.c
38360 @@ -1640,7 +1640,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
38361 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
38362 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
38363 card->index);
38364 - atomic_inc(&vcc->stats->tx_err);
38365 + atomic_inc_unchecked(&vcc->stats->tx_err);
38366 dev_kfree_skb_any(skb);
38367 return -EINVAL;
38368 }
38369 @@ -1648,7 +1648,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
38370 if (!vc->tx) {
38371 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
38372 card->index);
38373 - atomic_inc(&vcc->stats->tx_err);
38374 + atomic_inc_unchecked(&vcc->stats->tx_err);
38375 dev_kfree_skb_any(skb);
38376 return -EINVAL;
38377 }
38378 @@ -1656,14 +1656,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
38379 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
38380 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
38381 card->index);
38382 - atomic_inc(&vcc->stats->tx_err);
38383 + atomic_inc_unchecked(&vcc->stats->tx_err);
38384 dev_kfree_skb_any(skb);
38385 return -EINVAL;
38386 }
38387
38388 if (skb_shinfo(skb)->nr_frags != 0) {
38389 printk("nicstar%d: No scatter-gather yet.\n", card->index);
38390 - atomic_inc(&vcc->stats->tx_err);
38391 + atomic_inc_unchecked(&vcc->stats->tx_err);
38392 dev_kfree_skb_any(skb);
38393 return -EINVAL;
38394 }
38395 @@ -1711,11 +1711,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
38396 }
38397
38398 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
38399 - atomic_inc(&vcc->stats->tx_err);
38400 + atomic_inc_unchecked(&vcc->stats->tx_err);
38401 dev_kfree_skb_any(skb);
38402 return -EIO;
38403 }
38404 - atomic_inc(&vcc->stats->tx);
38405 + atomic_inc_unchecked(&vcc->stats->tx);
38406
38407 return 0;
38408 }
38409 @@ -2032,14 +2032,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38410 printk
38411 ("nicstar%d: Can't allocate buffers for aal0.\n",
38412 card->index);
38413 - atomic_add(i, &vcc->stats->rx_drop);
38414 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
38415 break;
38416 }
38417 if (!atm_charge(vcc, sb->truesize)) {
38418 RXPRINTK
38419 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
38420 card->index);
38421 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
38422 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
38423 dev_kfree_skb_any(sb);
38424 break;
38425 }
38426 @@ -2054,7 +2054,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38427 ATM_SKB(sb)->vcc = vcc;
38428 __net_timestamp(sb);
38429 vcc->push(vcc, sb);
38430 - atomic_inc(&vcc->stats->rx);
38431 + atomic_inc_unchecked(&vcc->stats->rx);
38432 cell += ATM_CELL_PAYLOAD;
38433 }
38434
38435 @@ -2071,7 +2071,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38436 if (iovb == NULL) {
38437 printk("nicstar%d: Out of iovec buffers.\n",
38438 card->index);
38439 - atomic_inc(&vcc->stats->rx_drop);
38440 + atomic_inc_unchecked(&vcc->stats->rx_drop);
38441 recycle_rx_buf(card, skb);
38442 return;
38443 }
38444 @@ -2095,7 +2095,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38445 small or large buffer itself. */
38446 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
38447 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
38448 - atomic_inc(&vcc->stats->rx_err);
38449 + atomic_inc_unchecked(&vcc->stats->rx_err);
38450 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
38451 NS_MAX_IOVECS);
38452 NS_PRV_IOVCNT(iovb) = 0;
38453 @@ -2115,7 +2115,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38454 ("nicstar%d: Expected a small buffer, and this is not one.\n",
38455 card->index);
38456 which_list(card, skb);
38457 - atomic_inc(&vcc->stats->rx_err);
38458 + atomic_inc_unchecked(&vcc->stats->rx_err);
38459 recycle_rx_buf(card, skb);
38460 vc->rx_iov = NULL;
38461 recycle_iov_buf(card, iovb);
38462 @@ -2128,7 +2128,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38463 ("nicstar%d: Expected a large buffer, and this is not one.\n",
38464 card->index);
38465 which_list(card, skb);
38466 - atomic_inc(&vcc->stats->rx_err);
38467 + atomic_inc_unchecked(&vcc->stats->rx_err);
38468 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
38469 NS_PRV_IOVCNT(iovb));
38470 vc->rx_iov = NULL;
38471 @@ -2151,7 +2151,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38472 printk(" - PDU size mismatch.\n");
38473 else
38474 printk(".\n");
38475 - atomic_inc(&vcc->stats->rx_err);
38476 + atomic_inc_unchecked(&vcc->stats->rx_err);
38477 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
38478 NS_PRV_IOVCNT(iovb));
38479 vc->rx_iov = NULL;
38480 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38481 /* skb points to a small buffer */
38482 if (!atm_charge(vcc, skb->truesize)) {
38483 push_rxbufs(card, skb);
38484 - atomic_inc(&vcc->stats->rx_drop);
38485 + atomic_inc_unchecked(&vcc->stats->rx_drop);
38486 } else {
38487 skb_put(skb, len);
38488 dequeue_sm_buf(card, skb);
38489 @@ -2175,7 +2175,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38490 ATM_SKB(skb)->vcc = vcc;
38491 __net_timestamp(skb);
38492 vcc->push(vcc, skb);
38493 - atomic_inc(&vcc->stats->rx);
38494 + atomic_inc_unchecked(&vcc->stats->rx);
38495 }
38496 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
38497 struct sk_buff *sb;
38498 @@ -2186,7 +2186,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38499 if (len <= NS_SMBUFSIZE) {
38500 if (!atm_charge(vcc, sb->truesize)) {
38501 push_rxbufs(card, sb);
38502 - atomic_inc(&vcc->stats->rx_drop);
38503 + atomic_inc_unchecked(&vcc->stats->rx_drop);
38504 } else {
38505 skb_put(sb, len);
38506 dequeue_sm_buf(card, sb);
38507 @@ -2196,7 +2196,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38508 ATM_SKB(sb)->vcc = vcc;
38509 __net_timestamp(sb);
38510 vcc->push(vcc, sb);
38511 - atomic_inc(&vcc->stats->rx);
38512 + atomic_inc_unchecked(&vcc->stats->rx);
38513 }
38514
38515 push_rxbufs(card, skb);
38516 @@ -2205,7 +2205,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38517
38518 if (!atm_charge(vcc, skb->truesize)) {
38519 push_rxbufs(card, skb);
38520 - atomic_inc(&vcc->stats->rx_drop);
38521 + atomic_inc_unchecked(&vcc->stats->rx_drop);
38522 } else {
38523 dequeue_lg_buf(card, skb);
38524 #ifdef NS_USE_DESTRUCTORS
38525 @@ -2218,7 +2218,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38526 ATM_SKB(skb)->vcc = vcc;
38527 __net_timestamp(skb);
38528 vcc->push(vcc, skb);
38529 - atomic_inc(&vcc->stats->rx);
38530 + atomic_inc_unchecked(&vcc->stats->rx);
38531 }
38532
38533 push_rxbufs(card, sb);
38534 @@ -2239,7 +2239,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38535 printk
38536 ("nicstar%d: Out of huge buffers.\n",
38537 card->index);
38538 - atomic_inc(&vcc->stats->rx_drop);
38539 + atomic_inc_unchecked(&vcc->stats->rx_drop);
38540 recycle_iovec_rx_bufs(card,
38541 (struct iovec *)
38542 iovb->data,
38543 @@ -2290,7 +2290,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38544 card->hbpool.count++;
38545 } else
38546 dev_kfree_skb_any(hb);
38547 - atomic_inc(&vcc->stats->rx_drop);
38548 + atomic_inc_unchecked(&vcc->stats->rx_drop);
38549 } else {
38550 /* Copy the small buffer to the huge buffer */
38551 sb = (struct sk_buff *)iov->iov_base;
38552 @@ -2327,7 +2327,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38553 #endif /* NS_USE_DESTRUCTORS */
38554 __net_timestamp(hb);
38555 vcc->push(vcc, hb);
38556 - atomic_inc(&vcc->stats->rx);
38557 + atomic_inc_unchecked(&vcc->stats->rx);
38558 }
38559 }
38560
38561 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
38562 index 7652e8d..db45069 100644
38563 --- a/drivers/atm/solos-pci.c
38564 +++ b/drivers/atm/solos-pci.c
38565 @@ -838,7 +838,7 @@ static void solos_bh(unsigned long card_arg)
38566 }
38567 atm_charge(vcc, skb->truesize);
38568 vcc->push(vcc, skb);
38569 - atomic_inc(&vcc->stats->rx);
38570 + atomic_inc_unchecked(&vcc->stats->rx);
38571 break;
38572
38573 case PKT_STATUS:
38574 @@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
38575 vcc = SKB_CB(oldskb)->vcc;
38576
38577 if (vcc) {
38578 - atomic_inc(&vcc->stats->tx);
38579 + atomic_inc_unchecked(&vcc->stats->tx);
38580 solos_pop(vcc, oldskb);
38581 } else {
38582 dev_kfree_skb_irq(oldskb);
38583 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
38584 index 0215934..ce9f5b1 100644
38585 --- a/drivers/atm/suni.c
38586 +++ b/drivers/atm/suni.c
38587 @@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
38588
38589
38590 #define ADD_LIMITED(s,v) \
38591 - atomic_add((v),&stats->s); \
38592 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
38593 + atomic_add_unchecked((v),&stats->s); \
38594 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
38595
38596
38597 static void suni_hz(unsigned long from_timer)
38598 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
38599 index 5120a96..e2572bd 100644
38600 --- a/drivers/atm/uPD98402.c
38601 +++ b/drivers/atm/uPD98402.c
38602 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
38603 struct sonet_stats tmp;
38604 int error = 0;
38605
38606 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
38607 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
38608 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
38609 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
38610 if (zero && !error) {
38611 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
38612
38613
38614 #define ADD_LIMITED(s,v) \
38615 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
38616 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
38617 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
38618 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
38619 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
38620 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
38621
38622
38623 static void stat_event(struct atm_dev *dev)
38624 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
38625 if (reason & uPD98402_INT_PFM) stat_event(dev);
38626 if (reason & uPD98402_INT_PCO) {
38627 (void) GET(PCOCR); /* clear interrupt cause */
38628 - atomic_add(GET(HECCT),
38629 + atomic_add_unchecked(GET(HECCT),
38630 &PRIV(dev)->sonet_stats.uncorr_hcs);
38631 }
38632 if ((reason & uPD98402_INT_RFO) &&
38633 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
38634 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
38635 uPD98402_INT_LOS),PIMR); /* enable them */
38636 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
38637 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
38638 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
38639 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
38640 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
38641 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
38642 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
38643 return 0;
38644 }
38645
38646 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
38647 index 969c3c2..9b72956 100644
38648 --- a/drivers/atm/zatm.c
38649 +++ b/drivers/atm/zatm.c
38650 @@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
38651 }
38652 if (!size) {
38653 dev_kfree_skb_irq(skb);
38654 - if (vcc) atomic_inc(&vcc->stats->rx_err);
38655 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
38656 continue;
38657 }
38658 if (!atm_charge(vcc,skb->truesize)) {
38659 @@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
38660 skb->len = size;
38661 ATM_SKB(skb)->vcc = vcc;
38662 vcc->push(vcc,skb);
38663 - atomic_inc(&vcc->stats->rx);
38664 + atomic_inc_unchecked(&vcc->stats->rx);
38665 }
38666 zout(pos & 0xffff,MTA(mbx));
38667 #if 0 /* probably a stupid idea */
38668 @@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
38669 skb_queue_head(&zatm_vcc->backlog,skb);
38670 break;
38671 }
38672 - atomic_inc(&vcc->stats->tx);
38673 + atomic_inc_unchecked(&vcc->stats->tx);
38674 wake_up(&zatm_vcc->tx_wait);
38675 }
38676
38677 diff --git a/drivers/base/bus.c b/drivers/base/bus.c
38678 index 83e910a..b224a73 100644
38679 --- a/drivers/base/bus.c
38680 +++ b/drivers/base/bus.c
38681 @@ -1124,7 +1124,7 @@ int subsys_interface_register(struct subsys_interface *sif)
38682 return -EINVAL;
38683
38684 mutex_lock(&subsys->p->mutex);
38685 - list_add_tail(&sif->node, &subsys->p->interfaces);
38686 + pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
38687 if (sif->add_dev) {
38688 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
38689 while ((dev = subsys_dev_iter_next(&iter)))
38690 @@ -1149,7 +1149,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
38691 subsys = sif->subsys;
38692
38693 mutex_lock(&subsys->p->mutex);
38694 - list_del_init(&sif->node);
38695 + pax_list_del_init((struct list_head *)&sif->node);
38696 if (sif->remove_dev) {
38697 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
38698 while ((dev = subsys_dev_iter_next(&iter)))
38699 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
38700 index 25798db..15f130e 100644
38701 --- a/drivers/base/devtmpfs.c
38702 +++ b/drivers/base/devtmpfs.c
38703 @@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
38704 if (!thread)
38705 return 0;
38706
38707 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
38708 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
38709 if (err)
38710 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
38711 else
38712 @@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
38713 *err = sys_unshare(CLONE_NEWNS);
38714 if (*err)
38715 goto out;
38716 - *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
38717 + *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
38718 if (*err)
38719 goto out;
38720 - sys_chdir("/.."); /* will traverse into overmounted root */
38721 - sys_chroot(".");
38722 + sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
38723 + sys_chroot((char __force_user *)".");
38724 complete(&setup_done);
38725 while (1) {
38726 spin_lock(&req_lock);
38727 diff --git a/drivers/base/node.c b/drivers/base/node.c
38728 index d51c49c..28908df 100644
38729 --- a/drivers/base/node.c
38730 +++ b/drivers/base/node.c
38731 @@ -623,7 +623,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
38732 struct node_attr {
38733 struct device_attribute attr;
38734 enum node_states state;
38735 -};
38736 +} __do_const;
38737
38738 static ssize_t show_node_state(struct device *dev,
38739 struct device_attribute *attr, char *buf)
38740 diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
38741 index eee55c1..b8c9393 100644
38742 --- a/drivers/base/power/domain.c
38743 +++ b/drivers/base/power/domain.c
38744 @@ -1821,9 +1821,9 @@ int __pm_genpd_remove_callbacks(struct device *dev, bool clear_td)
38745
38746 if (dev->power.subsys_data->domain_data) {
38747 gpd_data = to_gpd_data(dev->power.subsys_data->domain_data);
38748 - gpd_data->ops = (struct gpd_dev_ops){ NULL };
38749 + memset(&gpd_data->ops, 0, sizeof(gpd_data->ops));
38750 if (clear_td)
38751 - gpd_data->td = (struct gpd_timing_data){ 0 };
38752 + memset(&gpd_data->td, 0, sizeof(gpd_data->td));
38753
38754 if (--gpd_data->refcount == 0) {
38755 dev->power.subsys_data->domain_data = NULL;
38756 @@ -1862,7 +1862,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
38757 {
38758 struct cpuidle_driver *cpuidle_drv;
38759 struct gpd_cpu_data *cpu_data;
38760 - struct cpuidle_state *idle_state;
38761 + cpuidle_state_no_const *idle_state;
38762 int ret = 0;
38763
38764 if (IS_ERR_OR_NULL(genpd) || state < 0)
38765 @@ -1930,7 +1930,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
38766 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
38767 {
38768 struct gpd_cpu_data *cpu_data;
38769 - struct cpuidle_state *idle_state;
38770 + cpuidle_state_no_const *idle_state;
38771 int ret = 0;
38772
38773 if (IS_ERR_OR_NULL(genpd))
38774 diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
38775 index 95b181d1..c4f0e19 100644
38776 --- a/drivers/base/power/sysfs.c
38777 +++ b/drivers/base/power/sysfs.c
38778 @@ -185,7 +185,7 @@ static ssize_t rtpm_status_show(struct device *dev,
38779 return -EIO;
38780 }
38781 }
38782 - return sprintf(buf, p);
38783 + return sprintf(buf, "%s", p);
38784 }
38785
38786 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
38787 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
38788 index eb1bd2e..2667d3a 100644
38789 --- a/drivers/base/power/wakeup.c
38790 +++ b/drivers/base/power/wakeup.c
38791 @@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
38792 * They need to be modified together atomically, so it's better to use one
38793 * atomic variable to hold them both.
38794 */
38795 -static atomic_t combined_event_count = ATOMIC_INIT(0);
38796 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
38797
38798 #define IN_PROGRESS_BITS (sizeof(int) * 4)
38799 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
38800
38801 static void split_counters(unsigned int *cnt, unsigned int *inpr)
38802 {
38803 - unsigned int comb = atomic_read(&combined_event_count);
38804 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
38805
38806 *cnt = (comb >> IN_PROGRESS_BITS);
38807 *inpr = comb & MAX_IN_PROGRESS;
38808 @@ -401,7 +401,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
38809 ws->start_prevent_time = ws->last_time;
38810
38811 /* Increment the counter of events in progress. */
38812 - cec = atomic_inc_return(&combined_event_count);
38813 + cec = atomic_inc_return_unchecked(&combined_event_count);
38814
38815 trace_wakeup_source_activate(ws->name, cec);
38816 }
38817 @@ -527,7 +527,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
38818 * Increment the counter of registered wakeup events and decrement the
38819 * couter of wakeup events in progress simultaneously.
38820 */
38821 - cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
38822 + cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
38823 trace_wakeup_source_deactivate(ws->name, cec);
38824
38825 split_counters(&cnt, &inpr);
38826 diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
38827 index dbb8350..4762f4c 100644
38828 --- a/drivers/base/syscore.c
38829 +++ b/drivers/base/syscore.c
38830 @@ -22,7 +22,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
38831 void register_syscore_ops(struct syscore_ops *ops)
38832 {
38833 mutex_lock(&syscore_ops_lock);
38834 - list_add_tail(&ops->node, &syscore_ops_list);
38835 + pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
38836 mutex_unlock(&syscore_ops_lock);
38837 }
38838 EXPORT_SYMBOL_GPL(register_syscore_ops);
38839 @@ -34,7 +34,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
38840 void unregister_syscore_ops(struct syscore_ops *ops)
38841 {
38842 mutex_lock(&syscore_ops_lock);
38843 - list_del(&ops->node);
38844 + pax_list_del((struct list_head *)&ops->node);
38845 mutex_unlock(&syscore_ops_lock);
38846 }
38847 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
38848 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
38849 index ff20f19..018f1da 100644
38850 --- a/drivers/block/cciss.c
38851 +++ b/drivers/block/cciss.c
38852 @@ -3008,7 +3008,7 @@ static void start_io(ctlr_info_t *h)
38853 while (!list_empty(&h->reqQ)) {
38854 c = list_entry(h->reqQ.next, CommandList_struct, list);
38855 /* can't do anything if fifo is full */
38856 - if ((h->access.fifo_full(h))) {
38857 + if ((h->access->fifo_full(h))) {
38858 dev_warn(&h->pdev->dev, "fifo full\n");
38859 break;
38860 }
38861 @@ -3018,7 +3018,7 @@ static void start_io(ctlr_info_t *h)
38862 h->Qdepth--;
38863
38864 /* Tell the controller execute command */
38865 - h->access.submit_command(h, c);
38866 + h->access->submit_command(h, c);
38867
38868 /* Put job onto the completed Q */
38869 addQ(&h->cmpQ, c);
38870 @@ -3444,17 +3444,17 @@ startio:
38871
38872 static inline unsigned long get_next_completion(ctlr_info_t *h)
38873 {
38874 - return h->access.command_completed(h);
38875 + return h->access->command_completed(h);
38876 }
38877
38878 static inline int interrupt_pending(ctlr_info_t *h)
38879 {
38880 - return h->access.intr_pending(h);
38881 + return h->access->intr_pending(h);
38882 }
38883
38884 static inline long interrupt_not_for_us(ctlr_info_t *h)
38885 {
38886 - return ((h->access.intr_pending(h) == 0) ||
38887 + return ((h->access->intr_pending(h) == 0) ||
38888 (h->interrupts_enabled == 0));
38889 }
38890
38891 @@ -3487,7 +3487,7 @@ static inline u32 next_command(ctlr_info_t *h)
38892 u32 a;
38893
38894 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
38895 - return h->access.command_completed(h);
38896 + return h->access->command_completed(h);
38897
38898 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
38899 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
38900 @@ -4044,7 +4044,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
38901 trans_support & CFGTBL_Trans_use_short_tags);
38902
38903 /* Change the access methods to the performant access methods */
38904 - h->access = SA5_performant_access;
38905 + h->access = &SA5_performant_access;
38906 h->transMethod = CFGTBL_Trans_Performant;
38907
38908 return;
38909 @@ -4318,7 +4318,7 @@ static int cciss_pci_init(ctlr_info_t *h)
38910 if (prod_index < 0)
38911 return -ENODEV;
38912 h->product_name = products[prod_index].product_name;
38913 - h->access = *(products[prod_index].access);
38914 + h->access = products[prod_index].access;
38915
38916 if (cciss_board_disabled(h)) {
38917 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
38918 @@ -5050,7 +5050,7 @@ reinit_after_soft_reset:
38919 }
38920
38921 /* make sure the board interrupts are off */
38922 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
38923 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
38924 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
38925 if (rc)
38926 goto clean2;
38927 @@ -5100,7 +5100,7 @@ reinit_after_soft_reset:
38928 * fake ones to scoop up any residual completions.
38929 */
38930 spin_lock_irqsave(&h->lock, flags);
38931 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
38932 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
38933 spin_unlock_irqrestore(&h->lock, flags);
38934 free_irq(h->intr[h->intr_mode], h);
38935 rc = cciss_request_irq(h, cciss_msix_discard_completions,
38936 @@ -5120,9 +5120,9 @@ reinit_after_soft_reset:
38937 dev_info(&h->pdev->dev, "Board READY.\n");
38938 dev_info(&h->pdev->dev,
38939 "Waiting for stale completions to drain.\n");
38940 - h->access.set_intr_mask(h, CCISS_INTR_ON);
38941 + h->access->set_intr_mask(h, CCISS_INTR_ON);
38942 msleep(10000);
38943 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
38944 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
38945
38946 rc = controller_reset_failed(h->cfgtable);
38947 if (rc)
38948 @@ -5145,7 +5145,7 @@ reinit_after_soft_reset:
38949 cciss_scsi_setup(h);
38950
38951 /* Turn the interrupts on so we can service requests */
38952 - h->access.set_intr_mask(h, CCISS_INTR_ON);
38953 + h->access->set_intr_mask(h, CCISS_INTR_ON);
38954
38955 /* Get the firmware version */
38956 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
38957 @@ -5217,7 +5217,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
38958 kfree(flush_buf);
38959 if (return_code != IO_OK)
38960 dev_warn(&h->pdev->dev, "Error flushing cache\n");
38961 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
38962 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
38963 free_irq(h->intr[h->intr_mode], h);
38964 }
38965
38966 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
38967 index 7fda30e..2f27946 100644
38968 --- a/drivers/block/cciss.h
38969 +++ b/drivers/block/cciss.h
38970 @@ -101,7 +101,7 @@ struct ctlr_info
38971 /* information about each logical volume */
38972 drive_info_struct *drv[CISS_MAX_LUN];
38973
38974 - struct access_method access;
38975 + struct access_method *access;
38976
38977 /* queue and queue Info */
38978 struct list_head reqQ;
38979 @@ -402,27 +402,27 @@ static bool SA5_performant_intr_pending(ctlr_info_t *h)
38980 }
38981
38982 static struct access_method SA5_access = {
38983 - SA5_submit_command,
38984 - SA5_intr_mask,
38985 - SA5_fifo_full,
38986 - SA5_intr_pending,
38987 - SA5_completed,
38988 + .submit_command = SA5_submit_command,
38989 + .set_intr_mask = SA5_intr_mask,
38990 + .fifo_full = SA5_fifo_full,
38991 + .intr_pending = SA5_intr_pending,
38992 + .command_completed = SA5_completed,
38993 };
38994
38995 static struct access_method SA5B_access = {
38996 - SA5_submit_command,
38997 - SA5B_intr_mask,
38998 - SA5_fifo_full,
38999 - SA5B_intr_pending,
39000 - SA5_completed,
39001 + .submit_command = SA5_submit_command,
39002 + .set_intr_mask = SA5B_intr_mask,
39003 + .fifo_full = SA5_fifo_full,
39004 + .intr_pending = SA5B_intr_pending,
39005 + .command_completed = SA5_completed,
39006 };
39007
39008 static struct access_method SA5_performant_access = {
39009 - SA5_submit_command,
39010 - SA5_performant_intr_mask,
39011 - SA5_fifo_full,
39012 - SA5_performant_intr_pending,
39013 - SA5_performant_completed,
39014 + .submit_command = SA5_submit_command,
39015 + .set_intr_mask = SA5_performant_intr_mask,
39016 + .fifo_full = SA5_fifo_full,
39017 + .intr_pending = SA5_performant_intr_pending,
39018 + .command_completed = SA5_performant_completed,
39019 };
39020
39021 struct board_type {
39022 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
39023 index 2b94403..fd6ad1f 100644
39024 --- a/drivers/block/cpqarray.c
39025 +++ b/drivers/block/cpqarray.c
39026 @@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
39027 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
39028 goto Enomem4;
39029 }
39030 - hba[i]->access.set_intr_mask(hba[i], 0);
39031 + hba[i]->access->set_intr_mask(hba[i], 0);
39032 if (request_irq(hba[i]->intr, do_ida_intr,
39033 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
39034 {
39035 @@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
39036 add_timer(&hba[i]->timer);
39037
39038 /* Enable IRQ now that spinlock and rate limit timer are set up */
39039 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
39040 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
39041
39042 for(j=0; j<NWD; j++) {
39043 struct gendisk *disk = ida_gendisk[i][j];
39044 @@ -694,7 +694,7 @@ DBGINFO(
39045 for(i=0; i<NR_PRODUCTS; i++) {
39046 if (board_id == products[i].board_id) {
39047 c->product_name = products[i].product_name;
39048 - c->access = *(products[i].access);
39049 + c->access = products[i].access;
39050 break;
39051 }
39052 }
39053 @@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
39054 hba[ctlr]->intr = intr;
39055 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
39056 hba[ctlr]->product_name = products[j].product_name;
39057 - hba[ctlr]->access = *(products[j].access);
39058 + hba[ctlr]->access = products[j].access;
39059 hba[ctlr]->ctlr = ctlr;
39060 hba[ctlr]->board_id = board_id;
39061 hba[ctlr]->pci_dev = NULL; /* not PCI */
39062 @@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
39063
39064 while((c = h->reqQ) != NULL) {
39065 /* Can't do anything if we're busy */
39066 - if (h->access.fifo_full(h) == 0)
39067 + if (h->access->fifo_full(h) == 0)
39068 return;
39069
39070 /* Get the first entry from the request Q */
39071 @@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
39072 h->Qdepth--;
39073
39074 /* Tell the controller to do our bidding */
39075 - h->access.submit_command(h, c);
39076 + h->access->submit_command(h, c);
39077
39078 /* Get onto the completion Q */
39079 addQ(&h->cmpQ, c);
39080 @@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
39081 unsigned long flags;
39082 __u32 a,a1;
39083
39084 - istat = h->access.intr_pending(h);
39085 + istat = h->access->intr_pending(h);
39086 /* Is this interrupt for us? */
39087 if (istat == 0)
39088 return IRQ_NONE;
39089 @@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
39090 */
39091 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
39092 if (istat & FIFO_NOT_EMPTY) {
39093 - while((a = h->access.command_completed(h))) {
39094 + while((a = h->access->command_completed(h))) {
39095 a1 = a; a &= ~3;
39096 if ((c = h->cmpQ) == NULL)
39097 {
39098 @@ -1448,11 +1448,11 @@ static int sendcmd(
39099 /*
39100 * Disable interrupt
39101 */
39102 - info_p->access.set_intr_mask(info_p, 0);
39103 + info_p->access->set_intr_mask(info_p, 0);
39104 /* Make sure there is room in the command FIFO */
39105 /* Actually it should be completely empty at this time. */
39106 for (i = 200000; i > 0; i--) {
39107 - temp = info_p->access.fifo_full(info_p);
39108 + temp = info_p->access->fifo_full(info_p);
39109 if (temp != 0) {
39110 break;
39111 }
39112 @@ -1465,7 +1465,7 @@ DBG(
39113 /*
39114 * Send the cmd
39115 */
39116 - info_p->access.submit_command(info_p, c);
39117 + info_p->access->submit_command(info_p, c);
39118 complete = pollcomplete(ctlr);
39119
39120 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
39121 @@ -1548,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
39122 * we check the new geometry. Then turn interrupts back on when
39123 * we're done.
39124 */
39125 - host->access.set_intr_mask(host, 0);
39126 + host->access->set_intr_mask(host, 0);
39127 getgeometry(ctlr);
39128 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
39129 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
39130
39131 for(i=0; i<NWD; i++) {
39132 struct gendisk *disk = ida_gendisk[ctlr][i];
39133 @@ -1590,7 +1590,7 @@ static int pollcomplete(int ctlr)
39134 /* Wait (up to 2 seconds) for a command to complete */
39135
39136 for (i = 200000; i > 0; i--) {
39137 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
39138 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
39139 if (done == 0) {
39140 udelay(10); /* a short fixed delay */
39141 } else
39142 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
39143 index be73e9d..7fbf140 100644
39144 --- a/drivers/block/cpqarray.h
39145 +++ b/drivers/block/cpqarray.h
39146 @@ -99,7 +99,7 @@ struct ctlr_info {
39147 drv_info_t drv[NWD];
39148 struct proc_dir_entry *proc;
39149
39150 - struct access_method access;
39151 + struct access_method *access;
39152
39153 cmdlist_t *reqQ;
39154 cmdlist_t *cmpQ;
39155 diff --git a/drivers/block/drbd/drbd_bitmap.c b/drivers/block/drbd/drbd_bitmap.c
39156 index 426c97a..8c58607 100644
39157 --- a/drivers/block/drbd/drbd_bitmap.c
39158 +++ b/drivers/block/drbd/drbd_bitmap.c
39159 @@ -1036,7 +1036,7 @@ static void bm_page_io_async(struct drbd_bm_aio_ctx *ctx, int page_nr) __must_ho
39160 submit_bio(rw, bio);
39161 /* this should not count as user activity and cause the
39162 * resync to throttle -- see drbd_rs_should_slow_down(). */
39163 - atomic_add(len >> 9, &device->rs_sect_ev);
39164 + atomic_add_unchecked(len >> 9, &device->rs_sect_ev);
39165 }
39166 }
39167
39168 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
39169 index 1a00001..c0d4253 100644
39170 --- a/drivers/block/drbd/drbd_int.h
39171 +++ b/drivers/block/drbd/drbd_int.h
39172 @@ -387,7 +387,7 @@ struct drbd_epoch {
39173 struct drbd_connection *connection;
39174 struct list_head list;
39175 unsigned int barrier_nr;
39176 - atomic_t epoch_size; /* increased on every request added. */
39177 + atomic_unchecked_t epoch_size; /* increased on every request added. */
39178 atomic_t active; /* increased on every req. added, and dec on every finished. */
39179 unsigned long flags;
39180 };
39181 @@ -948,7 +948,7 @@ struct drbd_device {
39182 unsigned int al_tr_number;
39183 int al_tr_cycle;
39184 wait_queue_head_t seq_wait;
39185 - atomic_t packet_seq;
39186 + atomic_unchecked_t packet_seq;
39187 unsigned int peer_seq;
39188 spinlock_t peer_seq_lock;
39189 unsigned long comm_bm_set; /* communicated number of set bits. */
39190 @@ -957,8 +957,8 @@ struct drbd_device {
39191 struct mutex own_state_mutex;
39192 struct mutex *state_mutex; /* either own_state_mutex or first_peer_device(device)->connection->cstate_mutex */
39193 char congestion_reason; /* Why we where congested... */
39194 - atomic_t rs_sect_in; /* for incoming resync data rate, SyncTarget */
39195 - atomic_t rs_sect_ev; /* for submitted resync data rate, both */
39196 + atomic_unchecked_t rs_sect_in; /* for incoming resync data rate, SyncTarget */
39197 + atomic_unchecked_t rs_sect_ev; /* for submitted resync data rate, both */
39198 int rs_last_sect_ev; /* counter to compare with */
39199 int rs_last_events; /* counter of read or write "events" (unit sectors)
39200 * on the lower level device when we last looked. */
39201 @@ -1569,7 +1569,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
39202 char __user *uoptval;
39203 int err;
39204
39205 - uoptval = (char __user __force *)optval;
39206 + uoptval = (char __force_user *)optval;
39207
39208 set_fs(KERNEL_DS);
39209 if (level == SOL_SOCKET)
39210 diff --git a/drivers/block/drbd/drbd_interval.c b/drivers/block/drbd/drbd_interval.c
39211 index 04a14e0..5b8f0aa 100644
39212 --- a/drivers/block/drbd/drbd_interval.c
39213 +++ b/drivers/block/drbd/drbd_interval.c
39214 @@ -67,9 +67,9 @@ static void augment_rotate(struct rb_node *rb_old, struct rb_node *rb_new)
39215 }
39216
39217 static const struct rb_augment_callbacks augment_callbacks = {
39218 - augment_propagate,
39219 - augment_copy,
39220 - augment_rotate,
39221 + .propagate = augment_propagate,
39222 + .copy = augment_copy,
39223 + .rotate = augment_rotate,
39224 };
39225
39226 /**
39227 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
39228 index 9b465bb..00034ecf 100644
39229 --- a/drivers/block/drbd/drbd_main.c
39230 +++ b/drivers/block/drbd/drbd_main.c
39231 @@ -1328,7 +1328,7 @@ static int _drbd_send_ack(struct drbd_peer_device *peer_device, enum drbd_packet
39232 p->sector = sector;
39233 p->block_id = block_id;
39234 p->blksize = blksize;
39235 - p->seq_num = cpu_to_be32(atomic_inc_return(&peer_device->device->packet_seq));
39236 + p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&peer_device->device->packet_seq));
39237 return drbd_send_command(peer_device, sock, cmd, sizeof(*p), NULL, 0);
39238 }
39239
39240 @@ -1634,7 +1634,7 @@ int drbd_send_dblock(struct drbd_peer_device *peer_device, struct drbd_request *
39241 return -EIO;
39242 p->sector = cpu_to_be64(req->i.sector);
39243 p->block_id = (unsigned long)req;
39244 - p->seq_num = cpu_to_be32(atomic_inc_return(&device->packet_seq));
39245 + p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&device->packet_seq));
39246 dp_flags = bio_flags_to_wire(peer_device->connection, req->master_bio->bi_rw);
39247 if (device->state.conn >= C_SYNC_SOURCE &&
39248 device->state.conn <= C_PAUSED_SYNC_T)
39249 @@ -1915,8 +1915,8 @@ void drbd_init_set_defaults(struct drbd_device *device)
39250 atomic_set(&device->unacked_cnt, 0);
39251 atomic_set(&device->local_cnt, 0);
39252 atomic_set(&device->pp_in_use_by_net, 0);
39253 - atomic_set(&device->rs_sect_in, 0);
39254 - atomic_set(&device->rs_sect_ev, 0);
39255 + atomic_set_unchecked(&device->rs_sect_in, 0);
39256 + atomic_set_unchecked(&device->rs_sect_ev, 0);
39257 atomic_set(&device->ap_in_flight, 0);
39258 atomic_set(&device->md_io.in_use, 0);
39259
39260 @@ -2688,8 +2688,8 @@ void drbd_destroy_connection(struct kref *kref)
39261 struct drbd_connection *connection = container_of(kref, struct drbd_connection, kref);
39262 struct drbd_resource *resource = connection->resource;
39263
39264 - if (atomic_read(&connection->current_epoch->epoch_size) != 0)
39265 - drbd_err(connection, "epoch_size:%d\n", atomic_read(&connection->current_epoch->epoch_size));
39266 + if (atomic_read_unchecked(&connection->current_epoch->epoch_size) != 0)
39267 + drbd_err(connection, "epoch_size:%d\n", atomic_read_unchecked(&connection->current_epoch->epoch_size));
39268 kfree(connection->current_epoch);
39269
39270 idr_destroy(&connection->peer_devices);
39271 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
39272 index 1cd47df..57c53c0 100644
39273 --- a/drivers/block/drbd/drbd_nl.c
39274 +++ b/drivers/block/drbd/drbd_nl.c
39275 @@ -3645,13 +3645,13 @@ finish:
39276
39277 void drbd_bcast_event(struct drbd_device *device, const struct sib_info *sib)
39278 {
39279 - static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
39280 + static atomic_unchecked_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
39281 struct sk_buff *msg;
39282 struct drbd_genlmsghdr *d_out;
39283 unsigned seq;
39284 int err = -ENOMEM;
39285
39286 - seq = atomic_inc_return(&drbd_genl_seq);
39287 + seq = atomic_inc_return_unchecked(&drbd_genl_seq);
39288 msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO);
39289 if (!msg)
39290 goto failed;
39291 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
39292 index 9342b8d..b6a6825 100644
39293 --- a/drivers/block/drbd/drbd_receiver.c
39294 +++ b/drivers/block/drbd/drbd_receiver.c
39295 @@ -870,7 +870,7 @@ int drbd_connected(struct drbd_peer_device *peer_device)
39296 struct drbd_device *device = peer_device->device;
39297 int err;
39298
39299 - atomic_set(&device->packet_seq, 0);
39300 + atomic_set_unchecked(&device->packet_seq, 0);
39301 device->peer_seq = 0;
39302
39303 device->state_mutex = peer_device->connection->agreed_pro_version < 100 ?
39304 @@ -1233,7 +1233,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_connection *connectio
39305 do {
39306 next_epoch = NULL;
39307
39308 - epoch_size = atomic_read(&epoch->epoch_size);
39309 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
39310
39311 switch (ev & ~EV_CLEANUP) {
39312 case EV_PUT:
39313 @@ -1273,7 +1273,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_connection *connectio
39314 rv = FE_DESTROYED;
39315 } else {
39316 epoch->flags = 0;
39317 - atomic_set(&epoch->epoch_size, 0);
39318 + atomic_set_unchecked(&epoch->epoch_size, 0);
39319 /* atomic_set(&epoch->active, 0); is already zero */
39320 if (rv == FE_STILL_LIVE)
39321 rv = FE_RECYCLED;
39322 @@ -1550,7 +1550,7 @@ static int receive_Barrier(struct drbd_connection *connection, struct packet_inf
39323 conn_wait_active_ee_empty(connection);
39324 drbd_flush(connection);
39325
39326 - if (atomic_read(&connection->current_epoch->epoch_size)) {
39327 + if (atomic_read_unchecked(&connection->current_epoch->epoch_size)) {
39328 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
39329 if (epoch)
39330 break;
39331 @@ -1564,11 +1564,11 @@ static int receive_Barrier(struct drbd_connection *connection, struct packet_inf
39332 }
39333
39334 epoch->flags = 0;
39335 - atomic_set(&epoch->epoch_size, 0);
39336 + atomic_set_unchecked(&epoch->epoch_size, 0);
39337 atomic_set(&epoch->active, 0);
39338
39339 spin_lock(&connection->epoch_lock);
39340 - if (atomic_read(&connection->current_epoch->epoch_size)) {
39341 + if (atomic_read_unchecked(&connection->current_epoch->epoch_size)) {
39342 list_add(&epoch->list, &connection->current_epoch->list);
39343 connection->current_epoch = epoch;
39344 connection->epochs++;
39345 @@ -1802,7 +1802,7 @@ static int recv_resync_read(struct drbd_peer_device *peer_device, sector_t secto
39346 list_add_tail(&peer_req->w.list, &device->sync_ee);
39347 spin_unlock_irq(&device->resource->req_lock);
39348
39349 - atomic_add(pi->size >> 9, &device->rs_sect_ev);
39350 + atomic_add_unchecked(pi->size >> 9, &device->rs_sect_ev);
39351 if (drbd_submit_peer_request(device, peer_req, WRITE, DRBD_FAULT_RS_WR) == 0)
39352 return 0;
39353
39354 @@ -1900,7 +1900,7 @@ static int receive_RSDataReply(struct drbd_connection *connection, struct packet
39355 drbd_send_ack_dp(peer_device, P_NEG_ACK, p, pi->size);
39356 }
39357
39358 - atomic_add(pi->size >> 9, &device->rs_sect_in);
39359 + atomic_add_unchecked(pi->size >> 9, &device->rs_sect_in);
39360
39361 return err;
39362 }
39363 @@ -2290,7 +2290,7 @@ static int receive_Data(struct drbd_connection *connection, struct packet_info *
39364
39365 err = wait_for_and_update_peer_seq(peer_device, peer_seq);
39366 drbd_send_ack_dp(peer_device, P_NEG_ACK, p, pi->size);
39367 - atomic_inc(&connection->current_epoch->epoch_size);
39368 + atomic_inc_unchecked(&connection->current_epoch->epoch_size);
39369 err2 = drbd_drain_block(peer_device, pi->size);
39370 if (!err)
39371 err = err2;
39372 @@ -2334,7 +2334,7 @@ static int receive_Data(struct drbd_connection *connection, struct packet_info *
39373
39374 spin_lock(&connection->epoch_lock);
39375 peer_req->epoch = connection->current_epoch;
39376 - atomic_inc(&peer_req->epoch->epoch_size);
39377 + atomic_inc_unchecked(&peer_req->epoch->epoch_size);
39378 atomic_inc(&peer_req->epoch->active);
39379 spin_unlock(&connection->epoch_lock);
39380
39381 @@ -2479,7 +2479,7 @@ bool drbd_rs_c_min_rate_throttle(struct drbd_device *device)
39382
39383 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
39384 (int)part_stat_read(&disk->part0, sectors[1]) -
39385 - atomic_read(&device->rs_sect_ev);
39386 + atomic_read_unchecked(&device->rs_sect_ev);
39387
39388 if (atomic_read(&device->ap_actlog_cnt)
39389 || !device->rs_last_events || curr_events - device->rs_last_events > 64) {
39390 @@ -2618,7 +2618,7 @@ static int receive_DataRequest(struct drbd_connection *connection, struct packet
39391 device->use_csums = true;
39392 } else if (pi->cmd == P_OV_REPLY) {
39393 /* track progress, we may need to throttle */
39394 - atomic_add(size >> 9, &device->rs_sect_in);
39395 + atomic_add_unchecked(size >> 9, &device->rs_sect_in);
39396 peer_req->w.cb = w_e_end_ov_reply;
39397 dec_rs_pending(device);
39398 /* drbd_rs_begin_io done when we sent this request,
39399 @@ -2691,7 +2691,7 @@ static int receive_DataRequest(struct drbd_connection *connection, struct packet
39400 goto out_free_e;
39401
39402 submit_for_resync:
39403 - atomic_add(size >> 9, &device->rs_sect_ev);
39404 + atomic_add_unchecked(size >> 9, &device->rs_sect_ev);
39405
39406 submit:
39407 update_receiver_timing_details(connection, drbd_submit_peer_request);
39408 @@ -4564,7 +4564,7 @@ struct data_cmd {
39409 int expect_payload;
39410 size_t pkt_size;
39411 int (*fn)(struct drbd_connection *, struct packet_info *);
39412 -};
39413 +} __do_const;
39414
39415 static struct data_cmd drbd_cmd_handler[] = {
39416 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
39417 @@ -4678,7 +4678,7 @@ static void conn_disconnect(struct drbd_connection *connection)
39418 if (!list_empty(&connection->current_epoch->list))
39419 drbd_err(connection, "ASSERTION FAILED: connection->current_epoch->list not empty\n");
39420 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
39421 - atomic_set(&connection->current_epoch->epoch_size, 0);
39422 + atomic_set_unchecked(&connection->current_epoch->epoch_size, 0);
39423 connection->send.seen_any_write_yet = false;
39424
39425 drbd_info(connection, "Connection closed\n");
39426 @@ -5182,7 +5182,7 @@ static int got_IsInSync(struct drbd_connection *connection, struct packet_info *
39427 put_ldev(device);
39428 }
39429 dec_rs_pending(device);
39430 - atomic_add(blksize >> 9, &device->rs_sect_in);
39431 + atomic_add_unchecked(blksize >> 9, &device->rs_sect_in);
39432
39433 return 0;
39434 }
39435 @@ -5470,7 +5470,7 @@ static int connection_finish_peer_reqs(struct drbd_connection *connection)
39436 struct asender_cmd {
39437 size_t pkt_size;
39438 int (*fn)(struct drbd_connection *connection, struct packet_info *);
39439 -};
39440 +} __do_const;
39441
39442 static struct asender_cmd asender_tbl[] = {
39443 [P_PING] = { 0, got_Ping },
39444 diff --git a/drivers/block/drbd/drbd_worker.c b/drivers/block/drbd/drbd_worker.c
39445 index 50776b3..1477c3f 100644
39446 --- a/drivers/block/drbd/drbd_worker.c
39447 +++ b/drivers/block/drbd/drbd_worker.c
39448 @@ -408,7 +408,7 @@ static int read_for_csum(struct drbd_peer_device *peer_device, sector_t sector,
39449 list_add_tail(&peer_req->w.list, &device->read_ee);
39450 spin_unlock_irq(&device->resource->req_lock);
39451
39452 - atomic_add(size >> 9, &device->rs_sect_ev);
39453 + atomic_add_unchecked(size >> 9, &device->rs_sect_ev);
39454 if (drbd_submit_peer_request(device, peer_req, READ, DRBD_FAULT_RS_RD) == 0)
39455 return 0;
39456
39457 @@ -553,7 +553,7 @@ static int drbd_rs_number_requests(struct drbd_device *device)
39458 unsigned int sect_in; /* Number of sectors that came in since the last turn */
39459 int number, mxb;
39460
39461 - sect_in = atomic_xchg(&device->rs_sect_in, 0);
39462 + sect_in = atomic_xchg_unchecked(&device->rs_sect_in, 0);
39463 device->rs_in_flight -= sect_in;
39464
39465 rcu_read_lock();
39466 @@ -1594,8 +1594,8 @@ void drbd_rs_controller_reset(struct drbd_device *device)
39467 {
39468 struct fifo_buffer *plan;
39469
39470 - atomic_set(&device->rs_sect_in, 0);
39471 - atomic_set(&device->rs_sect_ev, 0);
39472 + atomic_set_unchecked(&device->rs_sect_in, 0);
39473 + atomic_set_unchecked(&device->rs_sect_ev, 0);
39474 device->rs_in_flight = 0;
39475
39476 /* Updating the RCU protected object in place is necessary since
39477 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
39478 index 6cb1beb..bf490f7 100644
39479 --- a/drivers/block/loop.c
39480 +++ b/drivers/block/loop.c
39481 @@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
39482
39483 file_start_write(file);
39484 set_fs(get_ds());
39485 - bw = file->f_op->write(file, buf, len, &pos);
39486 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
39487 set_fs(old_fs);
39488 file_end_write(file);
39489 if (likely(bw == len))
39490 diff --git a/drivers/block/nvme-core.c b/drivers/block/nvme-core.c
39491 index 02351e2..a9ea617 100644
39492 --- a/drivers/block/nvme-core.c
39493 +++ b/drivers/block/nvme-core.c
39494 @@ -73,7 +73,6 @@ static LIST_HEAD(dev_list);
39495 static struct task_struct *nvme_thread;
39496 static struct workqueue_struct *nvme_workq;
39497 static wait_queue_head_t nvme_kthread_wait;
39498 -static struct notifier_block nvme_nb;
39499
39500 static void nvme_reset_failed_dev(struct work_struct *ws);
39501
39502 @@ -2925,6 +2924,10 @@ static struct pci_driver nvme_driver = {
39503 .err_handler = &nvme_err_handler,
39504 };
39505
39506 +static struct notifier_block nvme_nb = {
39507 + .notifier_call = &nvme_cpu_notify,
39508 +};
39509 +
39510 static int __init nvme_init(void)
39511 {
39512 int result;
39513 @@ -2941,7 +2944,6 @@ static int __init nvme_init(void)
39514 else if (result > 0)
39515 nvme_major = result;
39516
39517 - nvme_nb.notifier_call = &nvme_cpu_notify;
39518 result = register_hotcpu_notifier(&nvme_nb);
39519 if (result)
39520 goto unregister_blkdev;
39521 diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
39522 index 758ac44..58087fd 100644
39523 --- a/drivers/block/pktcdvd.c
39524 +++ b/drivers/block/pktcdvd.c
39525 @@ -108,7 +108,7 @@ static int pkt_seq_show(struct seq_file *m, void *p);
39526
39527 static sector_t get_zone(sector_t sector, struct pktcdvd_device *pd)
39528 {
39529 - return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1);
39530 + return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1UL);
39531 }
39532
39533 /*
39534 @@ -1888,7 +1888,7 @@ static noinline_for_stack int pkt_probe_settings(struct pktcdvd_device *pd)
39535 return -EROFS;
39536 }
39537 pd->settings.fp = ti.fp;
39538 - pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1);
39539 + pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1UL);
39540
39541 if (ti.nwa_v) {
39542 pd->nwa = be32_to_cpu(ti.next_writable);
39543 diff --git a/drivers/block/smart1,2.h b/drivers/block/smart1,2.h
39544 index e5565fb..71be10b4 100644
39545 --- a/drivers/block/smart1,2.h
39546 +++ b/drivers/block/smart1,2.h
39547 @@ -108,11 +108,11 @@ static unsigned long smart4_intr_pending(ctlr_info_t *h)
39548 }
39549
39550 static struct access_method smart4_access = {
39551 - smart4_submit_command,
39552 - smart4_intr_mask,
39553 - smart4_fifo_full,
39554 - smart4_intr_pending,
39555 - smart4_completed,
39556 + .submit_command = smart4_submit_command,
39557 + .set_intr_mask = smart4_intr_mask,
39558 + .fifo_full = smart4_fifo_full,
39559 + .intr_pending = smart4_intr_pending,
39560 + .command_completed = smart4_completed,
39561 };
39562
39563 /*
39564 @@ -144,11 +144,11 @@ static unsigned long smart2_intr_pending(ctlr_info_t *h)
39565 }
39566
39567 static struct access_method smart2_access = {
39568 - smart2_submit_command,
39569 - smart2_intr_mask,
39570 - smart2_fifo_full,
39571 - smart2_intr_pending,
39572 - smart2_completed,
39573 + .submit_command = smart2_submit_command,
39574 + .set_intr_mask = smart2_intr_mask,
39575 + .fifo_full = smart2_fifo_full,
39576 + .intr_pending = smart2_intr_pending,
39577 + .command_completed = smart2_completed,
39578 };
39579
39580 /*
39581 @@ -180,11 +180,11 @@ static unsigned long smart2e_intr_pending(ctlr_info_t *h)
39582 }
39583
39584 static struct access_method smart2e_access = {
39585 - smart2e_submit_command,
39586 - smart2e_intr_mask,
39587 - smart2e_fifo_full,
39588 - smart2e_intr_pending,
39589 - smart2e_completed,
39590 + .submit_command = smart2e_submit_command,
39591 + .set_intr_mask = smart2e_intr_mask,
39592 + .fifo_full = smart2e_fifo_full,
39593 + .intr_pending = smart2e_intr_pending,
39594 + .command_completed = smart2e_completed,
39595 };
39596
39597 /*
39598 @@ -270,9 +270,9 @@ static unsigned long smart1_intr_pending(ctlr_info_t *h)
39599 }
39600
39601 static struct access_method smart1_access = {
39602 - smart1_submit_command,
39603 - smart1_intr_mask,
39604 - smart1_fifo_full,
39605 - smart1_intr_pending,
39606 - smart1_completed,
39607 + .submit_command = smart1_submit_command,
39608 + .set_intr_mask = smart1_intr_mask,
39609 + .fifo_full = smart1_fifo_full,
39610 + .intr_pending = smart1_intr_pending,
39611 + .command_completed = smart1_completed,
39612 };
39613 diff --git a/drivers/bluetooth/btwilink.c b/drivers/bluetooth/btwilink.c
39614 index f038dba..bb74c08 100644
39615 --- a/drivers/bluetooth/btwilink.c
39616 +++ b/drivers/bluetooth/btwilink.c
39617 @@ -288,7 +288,7 @@ static int ti_st_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
39618
39619 static int bt_ti_probe(struct platform_device *pdev)
39620 {
39621 - static struct ti_st *hst;
39622 + struct ti_st *hst;
39623 struct hci_dev *hdev;
39624 int err;
39625
39626 diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
39627 index 898b84b..86f74b9 100644
39628 --- a/drivers/cdrom/cdrom.c
39629 +++ b/drivers/cdrom/cdrom.c
39630 @@ -610,7 +610,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
39631 ENSURE(reset, CDC_RESET);
39632 ENSURE(generic_packet, CDC_GENERIC_PACKET);
39633 cdi->mc_flags = 0;
39634 - cdo->n_minors = 0;
39635 cdi->options = CDO_USE_FFLAGS;
39636
39637 if (autoclose == 1 && CDROM_CAN(CDC_CLOSE_TRAY))
39638 @@ -630,8 +629,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
39639 else
39640 cdi->cdda_method = CDDA_OLD;
39641
39642 - if (!cdo->generic_packet)
39643 - cdo->generic_packet = cdrom_dummy_generic_packet;
39644 + if (!cdo->generic_packet) {
39645 + pax_open_kernel();
39646 + *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
39647 + pax_close_kernel();
39648 + }
39649
39650 cd_dbg(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
39651 mutex_lock(&cdrom_mutex);
39652 @@ -652,7 +654,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
39653 if (cdi->exit)
39654 cdi->exit(cdi);
39655
39656 - cdi->ops->n_minors--;
39657 cd_dbg(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
39658 }
39659
39660 @@ -2126,7 +2127,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
39661 */
39662 nr = nframes;
39663 do {
39664 - cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
39665 + cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
39666 if (cgc.buffer)
39667 break;
39668
39669 @@ -3434,7 +3435,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
39670 struct cdrom_device_info *cdi;
39671 int ret;
39672
39673 - ret = scnprintf(info + *pos, max_size - *pos, header);
39674 + ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
39675 if (!ret)
39676 return 1;
39677
39678 diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
39679 index 584bc31..e64a12c 100644
39680 --- a/drivers/cdrom/gdrom.c
39681 +++ b/drivers/cdrom/gdrom.c
39682 @@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
39683 .audio_ioctl = gdrom_audio_ioctl,
39684 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
39685 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
39686 - .n_minors = 1,
39687 };
39688
39689 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
39690 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
39691 index 6e9f74a..50c7cea 100644
39692 --- a/drivers/char/Kconfig
39693 +++ b/drivers/char/Kconfig
39694 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
39695
39696 config DEVKMEM
39697 bool "/dev/kmem virtual device support"
39698 - default y
39699 + default n
39700 + depends on !GRKERNSEC_KMEM
39701 help
39702 Say Y here if you want to support the /dev/kmem device. The
39703 /dev/kmem device is rarely used, but can be used for certain
39704 @@ -577,6 +578,7 @@ config DEVPORT
39705 bool
39706 depends on !M68K
39707 depends on ISA || PCI
39708 + depends on !GRKERNSEC_KMEM
39709 default y
39710
39711 source "drivers/s390/char/Kconfig"
39712 diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
39713 index a48e05b..6bac831 100644
39714 --- a/drivers/char/agp/compat_ioctl.c
39715 +++ b/drivers/char/agp/compat_ioctl.c
39716 @@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
39717 return -ENOMEM;
39718 }
39719
39720 - if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
39721 + if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
39722 sizeof(*usegment) * ureserve.seg_count)) {
39723 kfree(usegment);
39724 kfree(ksegment);
39725 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
39726 index 09f17eb..8531d2f 100644
39727 --- a/drivers/char/agp/frontend.c
39728 +++ b/drivers/char/agp/frontend.c
39729 @@ -806,7 +806,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
39730 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
39731 return -EFAULT;
39732
39733 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
39734 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
39735 return -EFAULT;
39736
39737 client = agp_find_client_by_pid(reserve.pid);
39738 @@ -836,7 +836,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
39739 if (segment == NULL)
39740 return -ENOMEM;
39741
39742 - if (copy_from_user(segment, (void __user *) reserve.seg_list,
39743 + if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
39744 sizeof(struct agp_segment) * reserve.seg_count)) {
39745 kfree(segment);
39746 return -EFAULT;
39747 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
39748 index 4f94375..413694e 100644
39749 --- a/drivers/char/genrtc.c
39750 +++ b/drivers/char/genrtc.c
39751 @@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
39752 switch (cmd) {
39753
39754 case RTC_PLL_GET:
39755 + memset(&pll, 0, sizeof(pll));
39756 if (get_rtc_pll(&pll))
39757 return -EINVAL;
39758 else
39759 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
39760 index d5d4cd8..22d561d 100644
39761 --- a/drivers/char/hpet.c
39762 +++ b/drivers/char/hpet.c
39763 @@ -575,7 +575,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
39764 }
39765
39766 static int
39767 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
39768 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
39769 struct hpet_info *info)
39770 {
39771 struct hpet_timer __iomem *timer;
39772 diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
39773 index 86fe45c..c0ea948 100644
39774 --- a/drivers/char/hw_random/intel-rng.c
39775 +++ b/drivers/char/hw_random/intel-rng.c
39776 @@ -314,7 +314,7 @@ PFX "RNG, try using the 'no_fwh_detect' option.\n";
39777
39778 if (no_fwh_detect)
39779 return -ENODEV;
39780 - printk(warning);
39781 + printk("%s", warning);
39782 return -EBUSY;
39783 }
39784
39785 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
39786 index e6db938..835e3a2 100644
39787 --- a/drivers/char/ipmi/ipmi_msghandler.c
39788 +++ b/drivers/char/ipmi/ipmi_msghandler.c
39789 @@ -438,7 +438,7 @@ struct ipmi_smi {
39790 struct proc_dir_entry *proc_dir;
39791 char proc_dir_name[10];
39792
39793 - atomic_t stats[IPMI_NUM_STATS];
39794 + atomic_unchecked_t stats[IPMI_NUM_STATS];
39795
39796 /*
39797 * run_to_completion duplicate of smb_info, smi_info
39798 @@ -470,9 +470,9 @@ static LIST_HEAD(smi_watchers);
39799 static DEFINE_MUTEX(smi_watchers_mutex);
39800
39801 #define ipmi_inc_stat(intf, stat) \
39802 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
39803 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
39804 #define ipmi_get_stat(intf, stat) \
39805 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
39806 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
39807
39808 static int is_lan_addr(struct ipmi_addr *addr)
39809 {
39810 @@ -2926,7 +2926,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
39811 INIT_LIST_HEAD(&intf->cmd_rcvrs);
39812 init_waitqueue_head(&intf->waitq);
39813 for (i = 0; i < IPMI_NUM_STATS; i++)
39814 - atomic_set(&intf->stats[i], 0);
39815 + atomic_set_unchecked(&intf->stats[i], 0);
39816
39817 intf->proc_dir = NULL;
39818
39819 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
39820 index 5d66568..c9d93c3 100644
39821 --- a/drivers/char/ipmi/ipmi_si_intf.c
39822 +++ b/drivers/char/ipmi/ipmi_si_intf.c
39823 @@ -285,7 +285,7 @@ struct smi_info {
39824 unsigned char slave_addr;
39825
39826 /* Counters and things for the proc filesystem. */
39827 - atomic_t stats[SI_NUM_STATS];
39828 + atomic_unchecked_t stats[SI_NUM_STATS];
39829
39830 struct task_struct *thread;
39831
39832 @@ -294,9 +294,9 @@ struct smi_info {
39833 };
39834
39835 #define smi_inc_stat(smi, stat) \
39836 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
39837 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
39838 #define smi_get_stat(smi, stat) \
39839 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
39840 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
39841
39842 #define SI_MAX_PARMS 4
39843
39844 @@ -3374,7 +3374,7 @@ static int try_smi_init(struct smi_info *new_smi)
39845 atomic_set(&new_smi->req_events, 0);
39846 new_smi->run_to_completion = false;
39847 for (i = 0; i < SI_NUM_STATS; i++)
39848 - atomic_set(&new_smi->stats[i], 0);
39849 + atomic_set_unchecked(&new_smi->stats[i], 0);
39850
39851 new_smi->interrupt_disabled = true;
39852 atomic_set(&new_smi->stop_operation, 0);
39853 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
39854 index 917403f..dddd899 100644
39855 --- a/drivers/char/mem.c
39856 +++ b/drivers/char/mem.c
39857 @@ -18,6 +18,7 @@
39858 #include <linux/raw.h>
39859 #include <linux/tty.h>
39860 #include <linux/capability.h>
39861 +#include <linux/security.h>
39862 #include <linux/ptrace.h>
39863 #include <linux/device.h>
39864 #include <linux/highmem.h>
39865 @@ -36,6 +37,10 @@
39866
39867 #define DEVPORT_MINOR 4
39868
39869 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
39870 +extern const struct file_operations grsec_fops;
39871 +#endif
39872 +
39873 static inline unsigned long size_inside_page(unsigned long start,
39874 unsigned long size)
39875 {
39876 @@ -67,9 +72,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
39877
39878 while (cursor < to) {
39879 if (!devmem_is_allowed(pfn)) {
39880 +#ifdef CONFIG_GRKERNSEC_KMEM
39881 + gr_handle_mem_readwrite(from, to);
39882 +#else
39883 printk(KERN_INFO
39884 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
39885 current->comm, from, to);
39886 +#endif
39887 return 0;
39888 }
39889 cursor += PAGE_SIZE;
39890 @@ -77,6 +86,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
39891 }
39892 return 1;
39893 }
39894 +#elif defined(CONFIG_GRKERNSEC_KMEM)
39895 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
39896 +{
39897 + return 0;
39898 +}
39899 #else
39900 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
39901 {
39902 @@ -122,6 +136,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
39903
39904 while (count > 0) {
39905 unsigned long remaining;
39906 + char *temp;
39907
39908 sz = size_inside_page(p, count);
39909
39910 @@ -137,7 +152,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
39911 if (!ptr)
39912 return -EFAULT;
39913
39914 - remaining = copy_to_user(buf, ptr, sz);
39915 +#ifdef CONFIG_PAX_USERCOPY
39916 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
39917 + if (!temp) {
39918 + unxlate_dev_mem_ptr(p, ptr);
39919 + return -ENOMEM;
39920 + }
39921 + memcpy(temp, ptr, sz);
39922 +#else
39923 + temp = ptr;
39924 +#endif
39925 +
39926 + remaining = copy_to_user(buf, temp, sz);
39927 +
39928 +#ifdef CONFIG_PAX_USERCOPY
39929 + kfree(temp);
39930 +#endif
39931 +
39932 unxlate_dev_mem_ptr(p, ptr);
39933 if (remaining)
39934 return -EFAULT;
39935 @@ -369,9 +400,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
39936 size_t count, loff_t *ppos)
39937 {
39938 unsigned long p = *ppos;
39939 - ssize_t low_count, read, sz;
39940 + ssize_t low_count, read, sz, err = 0;
39941 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
39942 - int err = 0;
39943
39944 read = 0;
39945 if (p < (unsigned long) high_memory) {
39946 @@ -393,6 +423,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
39947 }
39948 #endif
39949 while (low_count > 0) {
39950 + char *temp;
39951 +
39952 sz = size_inside_page(p, low_count);
39953
39954 /*
39955 @@ -402,7 +434,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
39956 */
39957 kbuf = xlate_dev_kmem_ptr((char *)p);
39958
39959 - if (copy_to_user(buf, kbuf, sz))
39960 +#ifdef CONFIG_PAX_USERCOPY
39961 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
39962 + if (!temp)
39963 + return -ENOMEM;
39964 + memcpy(temp, kbuf, sz);
39965 +#else
39966 + temp = kbuf;
39967 +#endif
39968 +
39969 + err = copy_to_user(buf, temp, sz);
39970 +
39971 +#ifdef CONFIG_PAX_USERCOPY
39972 + kfree(temp);
39973 +#endif
39974 +
39975 + if (err)
39976 return -EFAULT;
39977 buf += sz;
39978 p += sz;
39979 @@ -827,6 +874,9 @@ static const struct memdev {
39980 #ifdef CONFIG_PRINTK
39981 [11] = { "kmsg", 0644, &kmsg_fops, NULL },
39982 #endif
39983 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
39984 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
39985 +#endif
39986 };
39987
39988 static int memory_open(struct inode *inode, struct file *filp)
39989 @@ -898,7 +948,7 @@ static int __init chr_dev_init(void)
39990 continue;
39991
39992 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
39993 - NULL, devlist[minor].name);
39994 + NULL, "%s", devlist[minor].name);
39995 }
39996
39997 return tty_init();
39998 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
39999 index 9df78e2..01ba9ae 100644
40000 --- a/drivers/char/nvram.c
40001 +++ b/drivers/char/nvram.c
40002 @@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
40003
40004 spin_unlock_irq(&rtc_lock);
40005
40006 - if (copy_to_user(buf, contents, tmp - contents))
40007 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
40008 return -EFAULT;
40009
40010 *ppos = i;
40011 diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
40012 index 0ea9986..e7b07e4 100644
40013 --- a/drivers/char/pcmcia/synclink_cs.c
40014 +++ b/drivers/char/pcmcia/synclink_cs.c
40015 @@ -2345,7 +2345,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
40016
40017 if (debug_level >= DEBUG_LEVEL_INFO)
40018 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
40019 - __FILE__, __LINE__, info->device_name, port->count);
40020 + __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
40021
40022 if (tty_port_close_start(port, tty, filp) == 0)
40023 goto cleanup;
40024 @@ -2363,7 +2363,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
40025 cleanup:
40026 if (debug_level >= DEBUG_LEVEL_INFO)
40027 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
40028 - tty->driver->name, port->count);
40029 + tty->driver->name, atomic_read(&port->count));
40030 }
40031
40032 /* Wait until the transmitter is empty.
40033 @@ -2505,7 +2505,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
40034
40035 if (debug_level >= DEBUG_LEVEL_INFO)
40036 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
40037 - __FILE__, __LINE__, tty->driver->name, port->count);
40038 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
40039
40040 /* If port is closing, signal caller to try again */
40041 if (port->flags & ASYNC_CLOSING){
40042 @@ -2525,11 +2525,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
40043 goto cleanup;
40044 }
40045 spin_lock(&port->lock);
40046 - port->count++;
40047 + atomic_inc(&port->count);
40048 spin_unlock(&port->lock);
40049 spin_unlock_irqrestore(&info->netlock, flags);
40050
40051 - if (port->count == 1) {
40052 + if (atomic_read(&port->count) == 1) {
40053 /* 1st open on this device, init hardware */
40054 retval = startup(info, tty);
40055 if (retval < 0)
40056 @@ -3918,7 +3918,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
40057 unsigned short new_crctype;
40058
40059 /* return error if TTY interface open */
40060 - if (info->port.count)
40061 + if (atomic_read(&info->port.count))
40062 return -EBUSY;
40063
40064 switch (encoding)
40065 @@ -4022,7 +4022,7 @@ static int hdlcdev_open(struct net_device *dev)
40066
40067 /* arbitrate between network and tty opens */
40068 spin_lock_irqsave(&info->netlock, flags);
40069 - if (info->port.count != 0 || info->netcount != 0) {
40070 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
40071 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
40072 spin_unlock_irqrestore(&info->netlock, flags);
40073 return -EBUSY;
40074 @@ -4112,7 +4112,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
40075 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
40076
40077 /* return error if TTY interface open */
40078 - if (info->port.count)
40079 + if (atomic_read(&info->port.count))
40080 return -EBUSY;
40081
40082 if (cmd != SIOCWANDEV)
40083 diff --git a/drivers/char/random.c b/drivers/char/random.c
40084 index 8c86a95..7c499f3 100644
40085 --- a/drivers/char/random.c
40086 +++ b/drivers/char/random.c
40087 @@ -289,9 +289,6 @@
40088 /*
40089 * To allow fractional bits to be tracked, the entropy_count field is
40090 * denominated in units of 1/8th bits.
40091 - *
40092 - * 2*(ENTROPY_SHIFT + log2(poolbits)) must <= 31, or the multiply in
40093 - * credit_entropy_bits() needs to be 64 bits wide.
40094 */
40095 #define ENTROPY_SHIFT 3
40096 #define ENTROPY_BITS(r) ((r)->entropy_count >> ENTROPY_SHIFT)
40097 @@ -439,9 +436,9 @@ struct entropy_store {
40098 };
40099
40100 static void push_to_pool(struct work_struct *work);
40101 -static __u32 input_pool_data[INPUT_POOL_WORDS];
40102 -static __u32 blocking_pool_data[OUTPUT_POOL_WORDS];
40103 -static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS];
40104 +static __u32 input_pool_data[INPUT_POOL_WORDS] __latent_entropy;
40105 +static __u32 blocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
40106 +static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
40107
40108 static struct entropy_store input_pool = {
40109 .poolinfo = &poolinfo_table[0],
40110 @@ -635,7 +632,7 @@ retry:
40111 /* The +2 corresponds to the /4 in the denominator */
40112
40113 do {
40114 - unsigned int anfrac = min(pnfrac, pool_size/2);
40115 + u64 anfrac = min(pnfrac, pool_size/2);
40116 unsigned int add =
40117 ((pool_size - entropy_count)*anfrac*3) >> s;
40118
40119 @@ -1207,7 +1204,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
40120
40121 extract_buf(r, tmp);
40122 i = min_t(int, nbytes, EXTRACT_SIZE);
40123 - if (copy_to_user(buf, tmp, i)) {
40124 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
40125 ret = -EFAULT;
40126 break;
40127 }
40128 @@ -1590,7 +1587,7 @@ static char sysctl_bootid[16];
40129 static int proc_do_uuid(struct ctl_table *table, int write,
40130 void __user *buffer, size_t *lenp, loff_t *ppos)
40131 {
40132 - struct ctl_table fake_table;
40133 + ctl_table_no_const fake_table;
40134 unsigned char buf[64], tmp_uuid[16], *uuid;
40135
40136 uuid = table->data;
40137 @@ -1620,7 +1617,7 @@ static int proc_do_uuid(struct ctl_table *table, int write,
40138 static int proc_do_entropy(struct ctl_table *table, int write,
40139 void __user *buffer, size_t *lenp, loff_t *ppos)
40140 {
40141 - struct ctl_table fake_table;
40142 + ctl_table_no_const fake_table;
40143 int entropy_count;
40144
40145 entropy_count = *(int *)table->data >> ENTROPY_SHIFT;
40146 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
40147 index 7cc1fe22..b602d6b 100644
40148 --- a/drivers/char/sonypi.c
40149 +++ b/drivers/char/sonypi.c
40150 @@ -54,6 +54,7 @@
40151
40152 #include <asm/uaccess.h>
40153 #include <asm/io.h>
40154 +#include <asm/local.h>
40155
40156 #include <linux/sonypi.h>
40157
40158 @@ -490,7 +491,7 @@ static struct sonypi_device {
40159 spinlock_t fifo_lock;
40160 wait_queue_head_t fifo_proc_list;
40161 struct fasync_struct *fifo_async;
40162 - int open_count;
40163 + local_t open_count;
40164 int model;
40165 struct input_dev *input_jog_dev;
40166 struct input_dev *input_key_dev;
40167 @@ -892,7 +893,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
40168 static int sonypi_misc_release(struct inode *inode, struct file *file)
40169 {
40170 mutex_lock(&sonypi_device.lock);
40171 - sonypi_device.open_count--;
40172 + local_dec(&sonypi_device.open_count);
40173 mutex_unlock(&sonypi_device.lock);
40174 return 0;
40175 }
40176 @@ -901,9 +902,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
40177 {
40178 mutex_lock(&sonypi_device.lock);
40179 /* Flush input queue on first open */
40180 - if (!sonypi_device.open_count)
40181 + if (!local_read(&sonypi_device.open_count))
40182 kfifo_reset(&sonypi_device.fifo);
40183 - sonypi_device.open_count++;
40184 + local_inc(&sonypi_device.open_count);
40185 mutex_unlock(&sonypi_device.lock);
40186
40187 return 0;
40188 diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
40189 index 565a947..dcdc06e 100644
40190 --- a/drivers/char/tpm/tpm_acpi.c
40191 +++ b/drivers/char/tpm/tpm_acpi.c
40192 @@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
40193 virt = acpi_os_map_iomem(start, len);
40194 if (!virt) {
40195 kfree(log->bios_event_log);
40196 + log->bios_event_log = NULL;
40197 printk("%s: ERROR - Unable to map memory\n", __func__);
40198 return -EIO;
40199 }
40200
40201 - memcpy_fromio(log->bios_event_log, virt, len);
40202 + memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
40203
40204 acpi_os_unmap_iomem(virt, len);
40205 return 0;
40206 diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
40207 index 3a56a13..f8cbd25 100644
40208 --- a/drivers/char/tpm/tpm_eventlog.c
40209 +++ b/drivers/char/tpm/tpm_eventlog.c
40210 @@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
40211 event = addr;
40212
40213 if ((event->event_type == 0 && event->event_size == 0) ||
40214 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
40215 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
40216 return NULL;
40217
40218 return addr;
40219 @@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
40220 return NULL;
40221
40222 if ((event->event_type == 0 && event->event_size == 0) ||
40223 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
40224 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
40225 return NULL;
40226
40227 (*pos)++;
40228 @@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
40229 int i;
40230
40231 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
40232 - seq_putc(m, data[i]);
40233 + if (!seq_putc(m, data[i]))
40234 + return -EFAULT;
40235
40236 return 0;
40237 }
40238 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
40239 index b585b47..488f43e 100644
40240 --- a/drivers/char/virtio_console.c
40241 +++ b/drivers/char/virtio_console.c
40242 @@ -684,7 +684,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
40243 if (to_user) {
40244 ssize_t ret;
40245
40246 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
40247 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
40248 if (ret)
40249 return -EFAULT;
40250 } else {
40251 @@ -787,7 +787,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
40252 if (!port_has_data(port) && !port->host_connected)
40253 return 0;
40254
40255 - return fill_readbuf(port, ubuf, count, true);
40256 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
40257 }
40258
40259 static int wait_port_writable(struct port *port, bool nonblock)
40260 diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
40261 index b9355da..9611f4e 100644
40262 --- a/drivers/clk/clk-composite.c
40263 +++ b/drivers/clk/clk-composite.c
40264 @@ -191,7 +191,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
40265 struct clk *clk;
40266 struct clk_init_data init;
40267 struct clk_composite *composite;
40268 - struct clk_ops *clk_composite_ops;
40269 + clk_ops_no_const *clk_composite_ops;
40270
40271 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
40272 if (!composite) {
40273 diff --git a/drivers/clk/socfpga/clk-gate.c b/drivers/clk/socfpga/clk-gate.c
40274 index dd3a78c..386d49c 100644
40275 --- a/drivers/clk/socfpga/clk-gate.c
40276 +++ b/drivers/clk/socfpga/clk-gate.c
40277 @@ -22,6 +22,7 @@
40278 #include <linux/mfd/syscon.h>
40279 #include <linux/of.h>
40280 #include <linux/regmap.h>
40281 +#include <asm/pgtable.h>
40282
40283 #include "clk.h"
40284
40285 @@ -174,7 +175,7 @@ static int socfpga_clk_prepare(struct clk_hw *hwclk)
40286 return 0;
40287 }
40288
40289 -static struct clk_ops gateclk_ops = {
40290 +static clk_ops_no_const gateclk_ops __read_only = {
40291 .prepare = socfpga_clk_prepare,
40292 .recalc_rate = socfpga_clk_recalc_rate,
40293 .get_parent = socfpga_clk_get_parent,
40294 @@ -208,8 +209,10 @@ static void __init __socfpga_gate_init(struct device_node *node,
40295 socfpga_clk->hw.reg = clk_mgr_base_addr + clk_gate[0];
40296 socfpga_clk->hw.bit_idx = clk_gate[1];
40297
40298 - gateclk_ops.enable = clk_gate_ops.enable;
40299 - gateclk_ops.disable = clk_gate_ops.disable;
40300 + pax_open_kernel();
40301 + *(void **)&gateclk_ops.enable = clk_gate_ops.enable;
40302 + *(void **)&gateclk_ops.disable = clk_gate_ops.disable;
40303 + pax_close_kernel();
40304 }
40305
40306 rc = of_property_read_u32(node, "fixed-divider", &fixed_div);
40307 diff --git a/drivers/clk/socfpga/clk-pll.c b/drivers/clk/socfpga/clk-pll.c
40308 index de6da95..c98278b 100644
40309 --- a/drivers/clk/socfpga/clk-pll.c
40310 +++ b/drivers/clk/socfpga/clk-pll.c
40311 @@ -21,6 +21,7 @@
40312 #include <linux/io.h>
40313 #include <linux/of.h>
40314 #include <linux/of_address.h>
40315 +#include <asm/pgtable.h>
40316
40317 #include "clk.h"
40318
40319 @@ -76,7 +77,7 @@ static u8 clk_pll_get_parent(struct clk_hw *hwclk)
40320 CLK_MGR_PLL_CLK_SRC_MASK;
40321 }
40322
40323 -static struct clk_ops clk_pll_ops = {
40324 +static clk_ops_no_const clk_pll_ops __read_only = {
40325 .recalc_rate = clk_pll_recalc_rate,
40326 .get_parent = clk_pll_get_parent,
40327 };
40328 @@ -120,8 +121,10 @@ static __init struct clk *__socfpga_pll_init(struct device_node *node,
40329 pll_clk->hw.hw.init = &init;
40330
40331 pll_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
40332 - clk_pll_ops.enable = clk_gate_ops.enable;
40333 - clk_pll_ops.disable = clk_gate_ops.disable;
40334 + pax_open_kernel();
40335 + *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
40336 + *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
40337 + pax_close_kernel();
40338
40339 clk = clk_register(NULL, &pll_clk->hw.hw);
40340 if (WARN_ON(IS_ERR(clk))) {
40341 diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
40342 index b0c18ed..1713a80 100644
40343 --- a/drivers/cpufreq/acpi-cpufreq.c
40344 +++ b/drivers/cpufreq/acpi-cpufreq.c
40345 @@ -675,8 +675,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
40346 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
40347 per_cpu(acfreq_data, cpu) = data;
40348
40349 - if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
40350 - acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
40351 + if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
40352 + pax_open_kernel();
40353 + *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
40354 + pax_close_kernel();
40355 + }
40356
40357 result = acpi_processor_register_performance(data->acpi_data, cpu);
40358 if (result)
40359 @@ -809,7 +812,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
40360 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
40361 break;
40362 case ACPI_ADR_SPACE_FIXED_HARDWARE:
40363 - acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
40364 + pax_open_kernel();
40365 + *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
40366 + pax_close_kernel();
40367 break;
40368 default:
40369 break;
40370 @@ -903,8 +908,10 @@ static void __init acpi_cpufreq_boost_init(void)
40371 if (!msrs)
40372 return;
40373
40374 - acpi_cpufreq_driver.boost_supported = true;
40375 - acpi_cpufreq_driver.boost_enabled = boost_state(0);
40376 + pax_open_kernel();
40377 + *(bool *)&acpi_cpufreq_driver.boost_supported = true;
40378 + *(bool *)&acpi_cpufreq_driver.boost_enabled = boost_state(0);
40379 + pax_close_kernel();
40380
40381 cpu_notifier_register_begin();
40382
40383 diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
40384 index 07c8276..38bd07c 100644
40385 --- a/drivers/cpufreq/cpufreq.c
40386 +++ b/drivers/cpufreq/cpufreq.c
40387 @@ -2107,7 +2107,7 @@ void cpufreq_unregister_governor(struct cpufreq_governor *governor)
40388 }
40389
40390 mutex_lock(&cpufreq_governor_mutex);
40391 - list_del(&governor->governor_list);
40392 + pax_list_del(&governor->governor_list);
40393 mutex_unlock(&cpufreq_governor_mutex);
40394 return;
40395 }
40396 @@ -2323,7 +2323,7 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
40397 return NOTIFY_OK;
40398 }
40399
40400 -static struct notifier_block __refdata cpufreq_cpu_notifier = {
40401 +static struct notifier_block cpufreq_cpu_notifier = {
40402 .notifier_call = cpufreq_cpu_callback,
40403 };
40404
40405 @@ -2363,13 +2363,17 @@ int cpufreq_boost_trigger_state(int state)
40406 return 0;
40407
40408 write_lock_irqsave(&cpufreq_driver_lock, flags);
40409 - cpufreq_driver->boost_enabled = state;
40410 + pax_open_kernel();
40411 + *(bool *)&cpufreq_driver->boost_enabled = state;
40412 + pax_close_kernel();
40413 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
40414
40415 ret = cpufreq_driver->set_boost(state);
40416 if (ret) {
40417 write_lock_irqsave(&cpufreq_driver_lock, flags);
40418 - cpufreq_driver->boost_enabled = !state;
40419 + pax_open_kernel();
40420 + *(bool *)&cpufreq_driver->boost_enabled = !state;
40421 + pax_close_kernel();
40422 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
40423
40424 pr_err("%s: Cannot %s BOOST\n",
40425 @@ -2426,8 +2430,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
40426
40427 pr_debug("trying to register driver %s\n", driver_data->name);
40428
40429 - if (driver_data->setpolicy)
40430 - driver_data->flags |= CPUFREQ_CONST_LOOPS;
40431 + if (driver_data->setpolicy) {
40432 + pax_open_kernel();
40433 + *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
40434 + pax_close_kernel();
40435 + }
40436
40437 write_lock_irqsave(&cpufreq_driver_lock, flags);
40438 if (cpufreq_driver) {
40439 @@ -2442,8 +2449,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
40440 * Check if driver provides function to enable boost -
40441 * if not, use cpufreq_boost_set_sw as default
40442 */
40443 - if (!cpufreq_driver->set_boost)
40444 - cpufreq_driver->set_boost = cpufreq_boost_set_sw;
40445 + if (!cpufreq_driver->set_boost) {
40446 + pax_open_kernel();
40447 + *(void **)&cpufreq_driver->set_boost = cpufreq_boost_set_sw;
40448 + pax_close_kernel();
40449 + }
40450
40451 ret = cpufreq_sysfs_create_file(&boost.attr);
40452 if (ret) {
40453 diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
40454 index 1b44496..b80ff5e 100644
40455 --- a/drivers/cpufreq/cpufreq_governor.c
40456 +++ b/drivers/cpufreq/cpufreq_governor.c
40457 @@ -245,7 +245,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
40458 struct dbs_data *dbs_data;
40459 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
40460 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
40461 - struct od_ops *od_ops = NULL;
40462 + const struct od_ops *od_ops = NULL;
40463 struct od_dbs_tuners *od_tuners = NULL;
40464 struct cs_dbs_tuners *cs_tuners = NULL;
40465 struct cpu_dbs_common_info *cpu_cdbs;
40466 @@ -311,7 +311,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
40467
40468 if ((cdata->governor == GOV_CONSERVATIVE) &&
40469 (!policy->governor->initialized)) {
40470 - struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
40471 + const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
40472
40473 cpufreq_register_notifier(cs_ops->notifier_block,
40474 CPUFREQ_TRANSITION_NOTIFIER);
40475 @@ -331,7 +331,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
40476
40477 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
40478 (policy->governor->initialized == 1)) {
40479 - struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
40480 + const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
40481
40482 cpufreq_unregister_notifier(cs_ops->notifier_block,
40483 CPUFREQ_TRANSITION_NOTIFIER);
40484 diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
40485 index cc401d1..8197340 100644
40486 --- a/drivers/cpufreq/cpufreq_governor.h
40487 +++ b/drivers/cpufreq/cpufreq_governor.h
40488 @@ -212,7 +212,7 @@ struct common_dbs_data {
40489 void (*exit)(struct dbs_data *dbs_data);
40490
40491 /* Governor specific ops, see below */
40492 - void *gov_ops;
40493 + const void *gov_ops;
40494 };
40495
40496 /* Governor Per policy data */
40497 @@ -232,7 +232,7 @@ struct od_ops {
40498 unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy,
40499 unsigned int freq_next, unsigned int relation);
40500 void (*freq_increase)(struct cpufreq_policy *policy, unsigned int freq);
40501 -};
40502 +} __no_const;
40503
40504 struct cs_ops {
40505 struct notifier_block *notifier_block;
40506 diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
40507 index ad3f38f..8f086cd 100644
40508 --- a/drivers/cpufreq/cpufreq_ondemand.c
40509 +++ b/drivers/cpufreq/cpufreq_ondemand.c
40510 @@ -524,7 +524,7 @@ static void od_exit(struct dbs_data *dbs_data)
40511
40512 define_get_cpu_dbs_routines(od_cpu_dbs_info);
40513
40514 -static struct od_ops od_ops = {
40515 +static struct od_ops od_ops __read_only = {
40516 .powersave_bias_init_cpu = ondemand_powersave_bias_init_cpu,
40517 .powersave_bias_target = generic_powersave_bias_target,
40518 .freq_increase = dbs_freq_increase,
40519 @@ -579,14 +579,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
40520 (struct cpufreq_policy *, unsigned int, unsigned int),
40521 unsigned int powersave_bias)
40522 {
40523 - od_ops.powersave_bias_target = f;
40524 + pax_open_kernel();
40525 + *(void **)&od_ops.powersave_bias_target = f;
40526 + pax_close_kernel();
40527 od_set_powersave_bias(powersave_bias);
40528 }
40529 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
40530
40531 void od_unregister_powersave_bias_handler(void)
40532 {
40533 - od_ops.powersave_bias_target = generic_powersave_bias_target;
40534 + pax_open_kernel();
40535 + *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
40536 + pax_close_kernel();
40537 od_set_powersave_bias(0);
40538 }
40539 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
40540 diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
40541 index 27bb6d3..4cf595c 100644
40542 --- a/drivers/cpufreq/intel_pstate.c
40543 +++ b/drivers/cpufreq/intel_pstate.c
40544 @@ -133,10 +133,10 @@ struct pstate_funcs {
40545 struct cpu_defaults {
40546 struct pstate_adjust_policy pid_policy;
40547 struct pstate_funcs funcs;
40548 -};
40549 +} __do_const;
40550
40551 static struct pstate_adjust_policy pid_params;
40552 -static struct pstate_funcs pstate_funcs;
40553 +static struct pstate_funcs *pstate_funcs;
40554
40555 struct perf_limits {
40556 int no_turbo;
40557 @@ -594,18 +594,18 @@ static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate)
40558
40559 cpu->pstate.current_pstate = pstate;
40560
40561 - pstate_funcs.set(cpu, pstate);
40562 + pstate_funcs->set(cpu, pstate);
40563 }
40564
40565 static void intel_pstate_get_cpu_pstates(struct cpudata *cpu)
40566 {
40567 - cpu->pstate.min_pstate = pstate_funcs.get_min();
40568 - cpu->pstate.max_pstate = pstate_funcs.get_max();
40569 - cpu->pstate.turbo_pstate = pstate_funcs.get_turbo();
40570 - cpu->pstate.scaling = pstate_funcs.get_scaling();
40571 + cpu->pstate.min_pstate = pstate_funcs->get_min();
40572 + cpu->pstate.max_pstate = pstate_funcs->get_max();
40573 + cpu->pstate.turbo_pstate = pstate_funcs->get_turbo();
40574 + cpu->pstate.scaling = pstate_funcs->get_scaling();
40575
40576 - if (pstate_funcs.get_vid)
40577 - pstate_funcs.get_vid(cpu);
40578 + if (pstate_funcs->get_vid)
40579 + pstate_funcs->get_vid(cpu);
40580 intel_pstate_set_pstate(cpu, cpu->pstate.min_pstate);
40581 }
40582
40583 @@ -875,9 +875,9 @@ static int intel_pstate_msrs_not_valid(void)
40584 rdmsrl(MSR_IA32_APERF, aperf);
40585 rdmsrl(MSR_IA32_MPERF, mperf);
40586
40587 - if (!pstate_funcs.get_max() ||
40588 - !pstate_funcs.get_min() ||
40589 - !pstate_funcs.get_turbo())
40590 + if (!pstate_funcs->get_max() ||
40591 + !pstate_funcs->get_min() ||
40592 + !pstate_funcs->get_turbo())
40593 return -ENODEV;
40594
40595 rdmsrl(MSR_IA32_APERF, tmp);
40596 @@ -891,7 +891,7 @@ static int intel_pstate_msrs_not_valid(void)
40597 return 0;
40598 }
40599
40600 -static void copy_pid_params(struct pstate_adjust_policy *policy)
40601 +static void copy_pid_params(const struct pstate_adjust_policy *policy)
40602 {
40603 pid_params.sample_rate_ms = policy->sample_rate_ms;
40604 pid_params.p_gain_pct = policy->p_gain_pct;
40605 @@ -903,12 +903,7 @@ static void copy_pid_params(struct pstate_adjust_policy *policy)
40606
40607 static void copy_cpu_funcs(struct pstate_funcs *funcs)
40608 {
40609 - pstate_funcs.get_max = funcs->get_max;
40610 - pstate_funcs.get_min = funcs->get_min;
40611 - pstate_funcs.get_turbo = funcs->get_turbo;
40612 - pstate_funcs.get_scaling = funcs->get_scaling;
40613 - pstate_funcs.set = funcs->set;
40614 - pstate_funcs.get_vid = funcs->get_vid;
40615 + pstate_funcs = funcs;
40616 }
40617
40618 #if IS_ENABLED(CONFIG_ACPI)
40619 diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
40620 index 529cfd9..0e28fff 100644
40621 --- a/drivers/cpufreq/p4-clockmod.c
40622 +++ b/drivers/cpufreq/p4-clockmod.c
40623 @@ -134,10 +134,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
40624 case 0x0F: /* Core Duo */
40625 case 0x16: /* Celeron Core */
40626 case 0x1C: /* Atom */
40627 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
40628 + pax_open_kernel();
40629 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
40630 + pax_close_kernel();
40631 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
40632 case 0x0D: /* Pentium M (Dothan) */
40633 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
40634 + pax_open_kernel();
40635 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
40636 + pax_close_kernel();
40637 /* fall through */
40638 case 0x09: /* Pentium M (Banias) */
40639 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
40640 @@ -149,7 +153,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
40641
40642 /* on P-4s, the TSC runs with constant frequency independent whether
40643 * throttling is active or not. */
40644 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
40645 + pax_open_kernel();
40646 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
40647 + pax_close_kernel();
40648
40649 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
40650 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
40651 diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
40652 index 9bb42ba..b01b4a2 100644
40653 --- a/drivers/cpufreq/sparc-us3-cpufreq.c
40654 +++ b/drivers/cpufreq/sparc-us3-cpufreq.c
40655 @@ -18,14 +18,12 @@
40656 #include <asm/head.h>
40657 #include <asm/timer.h>
40658
40659 -static struct cpufreq_driver *cpufreq_us3_driver;
40660 -
40661 struct us3_freq_percpu_info {
40662 struct cpufreq_frequency_table table[4];
40663 };
40664
40665 /* Indexed by cpu number. */
40666 -static struct us3_freq_percpu_info *us3_freq_table;
40667 +static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
40668
40669 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
40670 * in the Safari config register.
40671 @@ -156,16 +154,27 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
40672
40673 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
40674 {
40675 - if (cpufreq_us3_driver)
40676 - us3_freq_target(policy, 0);
40677 + us3_freq_target(policy, 0);
40678
40679 return 0;
40680 }
40681
40682 +static int __init us3_freq_init(void);
40683 +static void __exit us3_freq_exit(void);
40684 +
40685 +static struct cpufreq_driver cpufreq_us3_driver = {
40686 + .init = us3_freq_cpu_init,
40687 + .verify = cpufreq_generic_frequency_table_verify,
40688 + .target_index = us3_freq_target,
40689 + .get = us3_freq_get,
40690 + .exit = us3_freq_cpu_exit,
40691 + .name = "UltraSPARC-III",
40692 +
40693 +};
40694 +
40695 static int __init us3_freq_init(void)
40696 {
40697 unsigned long manuf, impl, ver;
40698 - int ret;
40699
40700 if (tlb_type != cheetah && tlb_type != cheetah_plus)
40701 return -ENODEV;
40702 @@ -178,55 +187,15 @@ static int __init us3_freq_init(void)
40703 (impl == CHEETAH_IMPL ||
40704 impl == CHEETAH_PLUS_IMPL ||
40705 impl == JAGUAR_IMPL ||
40706 - impl == PANTHER_IMPL)) {
40707 - struct cpufreq_driver *driver;
40708 -
40709 - ret = -ENOMEM;
40710 - driver = kzalloc(sizeof(*driver), GFP_KERNEL);
40711 - if (!driver)
40712 - goto err_out;
40713 -
40714 - us3_freq_table = kzalloc((NR_CPUS * sizeof(*us3_freq_table)),
40715 - GFP_KERNEL);
40716 - if (!us3_freq_table)
40717 - goto err_out;
40718 -
40719 - driver->init = us3_freq_cpu_init;
40720 - driver->verify = cpufreq_generic_frequency_table_verify;
40721 - driver->target_index = us3_freq_target;
40722 - driver->get = us3_freq_get;
40723 - driver->exit = us3_freq_cpu_exit;
40724 - strcpy(driver->name, "UltraSPARC-III");
40725 -
40726 - cpufreq_us3_driver = driver;
40727 - ret = cpufreq_register_driver(driver);
40728 - if (ret)
40729 - goto err_out;
40730 -
40731 - return 0;
40732 -
40733 -err_out:
40734 - if (driver) {
40735 - kfree(driver);
40736 - cpufreq_us3_driver = NULL;
40737 - }
40738 - kfree(us3_freq_table);
40739 - us3_freq_table = NULL;
40740 - return ret;
40741 - }
40742 + impl == PANTHER_IMPL))
40743 + return cpufreq_register_driver(&cpufreq_us3_driver);
40744
40745 return -ENODEV;
40746 }
40747
40748 static void __exit us3_freq_exit(void)
40749 {
40750 - if (cpufreq_us3_driver) {
40751 - cpufreq_unregister_driver(cpufreq_us3_driver);
40752 - kfree(cpufreq_us3_driver);
40753 - cpufreq_us3_driver = NULL;
40754 - kfree(us3_freq_table);
40755 - us3_freq_table = NULL;
40756 - }
40757 + cpufreq_unregister_driver(&cpufreq_us3_driver);
40758 }
40759
40760 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
40761 diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
40762 index 7d4a315..21bb886 100644
40763 --- a/drivers/cpufreq/speedstep-centrino.c
40764 +++ b/drivers/cpufreq/speedstep-centrino.c
40765 @@ -351,8 +351,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
40766 !cpu_has(cpu, X86_FEATURE_EST))
40767 return -ENODEV;
40768
40769 - if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
40770 - centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
40771 + if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
40772 + pax_open_kernel();
40773 + *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
40774 + pax_close_kernel();
40775 + }
40776
40777 if (policy->cpu != 0)
40778 return -ENODEV;
40779 diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
40780 index e431d11..d0b997e 100644
40781 --- a/drivers/cpuidle/driver.c
40782 +++ b/drivers/cpuidle/driver.c
40783 @@ -194,7 +194,7 @@ static int poll_idle(struct cpuidle_device *dev,
40784
40785 static void poll_idle_init(struct cpuidle_driver *drv)
40786 {
40787 - struct cpuidle_state *state = &drv->states[0];
40788 + cpuidle_state_no_const *state = &drv->states[0];
40789
40790 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
40791 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
40792 diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
40793 index ca89412..a7b9c49 100644
40794 --- a/drivers/cpuidle/governor.c
40795 +++ b/drivers/cpuidle/governor.c
40796 @@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
40797 mutex_lock(&cpuidle_lock);
40798 if (__cpuidle_find_governor(gov->name) == NULL) {
40799 ret = 0;
40800 - list_add_tail(&gov->governor_list, &cpuidle_governors);
40801 + pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
40802 if (!cpuidle_curr_governor ||
40803 cpuidle_curr_governor->rating < gov->rating)
40804 cpuidle_switch_governor(gov);
40805 diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
40806 index 97c5903..023ad23 100644
40807 --- a/drivers/cpuidle/sysfs.c
40808 +++ b/drivers/cpuidle/sysfs.c
40809 @@ -135,7 +135,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
40810 NULL
40811 };
40812
40813 -static struct attribute_group cpuidle_attr_group = {
40814 +static attribute_group_no_const cpuidle_attr_group = {
40815 .attrs = cpuidle_default_attrs,
40816 .name = "cpuidle",
40817 };
40818 diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
40819 index 8d2a772..33826c9 100644
40820 --- a/drivers/crypto/hifn_795x.c
40821 +++ b/drivers/crypto/hifn_795x.c
40822 @@ -51,7 +51,7 @@ module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
40823 MODULE_PARM_DESC(hifn_pll_ref,
40824 "PLL reference clock (pci[freq] or ext[freq], default ext)");
40825
40826 -static atomic_t hifn_dev_number;
40827 +static atomic_unchecked_t hifn_dev_number;
40828
40829 #define ACRYPTO_OP_DECRYPT 0
40830 #define ACRYPTO_OP_ENCRYPT 1
40831 @@ -2577,7 +2577,7 @@ static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
40832 goto err_out_disable_pci_device;
40833
40834 snprintf(name, sizeof(name), "hifn%d",
40835 - atomic_inc_return(&hifn_dev_number)-1);
40836 + atomic_inc_return_unchecked(&hifn_dev_number)-1);
40837
40838 err = pci_request_regions(pdev, name);
40839 if (err)
40840 diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
40841 index 9f90369..bfcacdb 100644
40842 --- a/drivers/devfreq/devfreq.c
40843 +++ b/drivers/devfreq/devfreq.c
40844 @@ -673,7 +673,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
40845 goto err_out;
40846 }
40847
40848 - list_add(&governor->node, &devfreq_governor_list);
40849 + pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
40850
40851 list_for_each_entry(devfreq, &devfreq_list, node) {
40852 int ret = 0;
40853 @@ -761,7 +761,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
40854 }
40855 }
40856
40857 - list_del(&governor->node);
40858 + pax_list_del((struct list_head *)&governor->node);
40859 err_out:
40860 mutex_unlock(&devfreq_list_lock);
40861
40862 diff --git a/drivers/dma/sh/shdma-base.c b/drivers/dma/sh/shdma-base.c
40863 index 42d4974..2714f36 100644
40864 --- a/drivers/dma/sh/shdma-base.c
40865 +++ b/drivers/dma/sh/shdma-base.c
40866 @@ -228,8 +228,8 @@ static int shdma_alloc_chan_resources(struct dma_chan *chan)
40867 schan->slave_id = -EINVAL;
40868 }
40869
40870 - schan->desc = kcalloc(NR_DESCS_PER_CHANNEL,
40871 - sdev->desc_size, GFP_KERNEL);
40872 + schan->desc = kcalloc(sdev->desc_size,
40873 + NR_DESCS_PER_CHANNEL, GFP_KERNEL);
40874 if (!schan->desc) {
40875 ret = -ENOMEM;
40876 goto edescalloc;
40877 diff --git a/drivers/dma/sh/shdmac.c b/drivers/dma/sh/shdmac.c
40878 index 58eb857..d7e42c8 100644
40879 --- a/drivers/dma/sh/shdmac.c
40880 +++ b/drivers/dma/sh/shdmac.c
40881 @@ -513,7 +513,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
40882 return ret;
40883 }
40884
40885 -static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
40886 +static struct notifier_block sh_dmae_nmi_notifier = {
40887 .notifier_call = sh_dmae_nmi_handler,
40888
40889 /* Run before NMI debug handler and KGDB */
40890 diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
40891 index 592af5f..bb1d583 100644
40892 --- a/drivers/edac/edac_device.c
40893 +++ b/drivers/edac/edac_device.c
40894 @@ -477,9 +477,9 @@ void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
40895 */
40896 int edac_device_alloc_index(void)
40897 {
40898 - static atomic_t device_indexes = ATOMIC_INIT(0);
40899 + static atomic_unchecked_t device_indexes = ATOMIC_INIT(0);
40900
40901 - return atomic_inc_return(&device_indexes) - 1;
40902 + return atomic_inc_return_unchecked(&device_indexes) - 1;
40903 }
40904 EXPORT_SYMBOL_GPL(edac_device_alloc_index);
40905
40906 diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
40907 index a6cd361..7bdbf53 100644
40908 --- a/drivers/edac/edac_mc_sysfs.c
40909 +++ b/drivers/edac/edac_mc_sysfs.c
40910 @@ -154,7 +154,7 @@ static const char * const edac_caps[] = {
40911 struct dev_ch_attribute {
40912 struct device_attribute attr;
40913 int channel;
40914 -};
40915 +} __do_const;
40916
40917 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
40918 struct dev_ch_attribute dev_attr_legacy_##_name = \
40919 @@ -1011,14 +1011,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
40920 }
40921
40922 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
40923 + pax_open_kernel();
40924 if (mci->get_sdram_scrub_rate) {
40925 - dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
40926 - dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
40927 + *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
40928 + *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
40929 }
40930 if (mci->set_sdram_scrub_rate) {
40931 - dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
40932 - dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
40933 + *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
40934 + *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
40935 }
40936 + pax_close_kernel();
40937 err = device_create_file(&mci->dev,
40938 &dev_attr_sdram_scrub_rate);
40939 if (err) {
40940 diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
40941 index 2cf44b4d..6dd2dc7 100644
40942 --- a/drivers/edac/edac_pci.c
40943 +++ b/drivers/edac/edac_pci.c
40944 @@ -29,7 +29,7 @@
40945
40946 static DEFINE_MUTEX(edac_pci_ctls_mutex);
40947 static LIST_HEAD(edac_pci_list);
40948 -static atomic_t pci_indexes = ATOMIC_INIT(0);
40949 +static atomic_unchecked_t pci_indexes = ATOMIC_INIT(0);
40950
40951 /*
40952 * edac_pci_alloc_ctl_info
40953 @@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(edac_pci_reset_delay_period);
40954 */
40955 int edac_pci_alloc_index(void)
40956 {
40957 - return atomic_inc_return(&pci_indexes) - 1;
40958 + return atomic_inc_return_unchecked(&pci_indexes) - 1;
40959 }
40960 EXPORT_SYMBOL_GPL(edac_pci_alloc_index);
40961
40962 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
40963 index e8658e4..22746d6 100644
40964 --- a/drivers/edac/edac_pci_sysfs.c
40965 +++ b/drivers/edac/edac_pci_sysfs.c
40966 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
40967 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
40968 static int edac_pci_poll_msec = 1000; /* one second workq period */
40969
40970 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
40971 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
40972 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
40973 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
40974
40975 static struct kobject *edac_pci_top_main_kobj;
40976 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
40977 @@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
40978 void *value;
40979 ssize_t(*show) (void *, char *);
40980 ssize_t(*store) (void *, const char *, size_t);
40981 -};
40982 +} __do_const;
40983
40984 /* Set of show/store abstract level functions for PCI Parity object */
40985 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
40986 @@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
40987 edac_printk(KERN_CRIT, EDAC_PCI,
40988 "Signaled System Error on %s\n",
40989 pci_name(dev));
40990 - atomic_inc(&pci_nonparity_count);
40991 + atomic_inc_unchecked(&pci_nonparity_count);
40992 }
40993
40994 if (status & (PCI_STATUS_PARITY)) {
40995 @@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
40996 "Master Data Parity Error on %s\n",
40997 pci_name(dev));
40998
40999 - atomic_inc(&pci_parity_count);
41000 + atomic_inc_unchecked(&pci_parity_count);
41001 }
41002
41003 if (status & (PCI_STATUS_DETECTED_PARITY)) {
41004 @@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
41005 "Detected Parity Error on %s\n",
41006 pci_name(dev));
41007
41008 - atomic_inc(&pci_parity_count);
41009 + atomic_inc_unchecked(&pci_parity_count);
41010 }
41011 }
41012
41013 @@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
41014 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
41015 "Signaled System Error on %s\n",
41016 pci_name(dev));
41017 - atomic_inc(&pci_nonparity_count);
41018 + atomic_inc_unchecked(&pci_nonparity_count);
41019 }
41020
41021 if (status & (PCI_STATUS_PARITY)) {
41022 @@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
41023 "Master Data Parity Error on "
41024 "%s\n", pci_name(dev));
41025
41026 - atomic_inc(&pci_parity_count);
41027 + atomic_inc_unchecked(&pci_parity_count);
41028 }
41029
41030 if (status & (PCI_STATUS_DETECTED_PARITY)) {
41031 @@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
41032 "Detected Parity Error on %s\n",
41033 pci_name(dev));
41034
41035 - atomic_inc(&pci_parity_count);
41036 + atomic_inc_unchecked(&pci_parity_count);
41037 }
41038 }
41039 }
41040 @@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
41041 if (!check_pci_errors)
41042 return;
41043
41044 - before_count = atomic_read(&pci_parity_count);
41045 + before_count = atomic_read_unchecked(&pci_parity_count);
41046
41047 /* scan all PCI devices looking for a Parity Error on devices and
41048 * bridges.
41049 @@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
41050 /* Only if operator has selected panic on PCI Error */
41051 if (edac_pci_get_panic_on_pe()) {
41052 /* If the count is different 'after' from 'before' */
41053 - if (before_count != atomic_read(&pci_parity_count))
41054 + if (before_count != atomic_read_unchecked(&pci_parity_count))
41055 panic("EDAC: PCI Parity Error");
41056 }
41057 }
41058 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
41059 index 51b7e3a..aa8a3e8 100644
41060 --- a/drivers/edac/mce_amd.h
41061 +++ b/drivers/edac/mce_amd.h
41062 @@ -77,7 +77,7 @@ struct amd_decoder_ops {
41063 bool (*mc0_mce)(u16, u8);
41064 bool (*mc1_mce)(u16, u8);
41065 bool (*mc2_mce)(u16, u8);
41066 -};
41067 +} __no_const;
41068
41069 void amd_report_gart_errors(bool);
41070 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
41071 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
41072 index 57ea7f4..af06b76 100644
41073 --- a/drivers/firewire/core-card.c
41074 +++ b/drivers/firewire/core-card.c
41075 @@ -528,9 +528,9 @@ void fw_card_initialize(struct fw_card *card,
41076 const struct fw_card_driver *driver,
41077 struct device *device)
41078 {
41079 - static atomic_t index = ATOMIC_INIT(-1);
41080 + static atomic_unchecked_t index = ATOMIC_INIT(-1);
41081
41082 - card->index = atomic_inc_return(&index);
41083 + card->index = atomic_inc_return_unchecked(&index);
41084 card->driver = driver;
41085 card->device = device;
41086 card->current_tlabel = 0;
41087 @@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
41088
41089 void fw_core_remove_card(struct fw_card *card)
41090 {
41091 - struct fw_card_driver dummy_driver = dummy_driver_template;
41092 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
41093
41094 card->driver->update_phy_reg(card, 4,
41095 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
41096 diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
41097 index 2c6d5e1..a2cca6b 100644
41098 --- a/drivers/firewire/core-device.c
41099 +++ b/drivers/firewire/core-device.c
41100 @@ -253,7 +253,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
41101 struct config_rom_attribute {
41102 struct device_attribute attr;
41103 u32 key;
41104 -};
41105 +} __do_const;
41106
41107 static ssize_t show_immediate(struct device *dev,
41108 struct device_attribute *dattr, char *buf)
41109 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
41110 index eb6935c..3cc2bfa 100644
41111 --- a/drivers/firewire/core-transaction.c
41112 +++ b/drivers/firewire/core-transaction.c
41113 @@ -38,6 +38,7 @@
41114 #include <linux/timer.h>
41115 #include <linux/types.h>
41116 #include <linux/workqueue.h>
41117 +#include <linux/sched.h>
41118
41119 #include <asm/byteorder.h>
41120
41121 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
41122 index e1480ff6..1a429bd 100644
41123 --- a/drivers/firewire/core.h
41124 +++ b/drivers/firewire/core.h
41125 @@ -111,6 +111,7 @@ struct fw_card_driver {
41126
41127 int (*stop_iso)(struct fw_iso_context *ctx);
41128 };
41129 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
41130
41131 void fw_card_initialize(struct fw_card *card,
41132 const struct fw_card_driver *driver, struct device *device);
41133 diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c
41134 index a66a321..f6caf20 100644
41135 --- a/drivers/firewire/ohci.c
41136 +++ b/drivers/firewire/ohci.c
41137 @@ -2056,10 +2056,12 @@ static void bus_reset_work(struct work_struct *work)
41138 be32_to_cpu(ohci->next_header));
41139 }
41140
41141 +#ifndef CONFIG_GRKERNSEC
41142 if (param_remote_dma) {
41143 reg_write(ohci, OHCI1394_PhyReqFilterHiSet, ~0);
41144 reg_write(ohci, OHCI1394_PhyReqFilterLoSet, ~0);
41145 }
41146 +#endif
41147
41148 spin_unlock_irq(&ohci->lock);
41149
41150 @@ -2591,8 +2593,10 @@ static int ohci_enable_phys_dma(struct fw_card *card,
41151 unsigned long flags;
41152 int n, ret = 0;
41153
41154 +#ifndef CONFIG_GRKERNSEC
41155 if (param_remote_dma)
41156 return 0;
41157 +#endif
41158
41159 /*
41160 * FIXME: Make sure this bitmask is cleared when we clear the busReset
41161 diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
41162 index 94a58a0..f5eba42 100644
41163 --- a/drivers/firmware/dmi-id.c
41164 +++ b/drivers/firmware/dmi-id.c
41165 @@ -16,7 +16,7 @@
41166 struct dmi_device_attribute{
41167 struct device_attribute dev_attr;
41168 int field;
41169 -};
41170 +} __do_const;
41171 #define to_dmi_dev_attr(_dev_attr) \
41172 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
41173
41174 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
41175 index 17afc51..0ef90cd 100644
41176 --- a/drivers/firmware/dmi_scan.c
41177 +++ b/drivers/firmware/dmi_scan.c
41178 @@ -835,7 +835,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
41179 if (buf == NULL)
41180 return -1;
41181
41182 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
41183 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
41184
41185 dmi_unmap(buf);
41186 return 0;
41187 diff --git a/drivers/firmware/efi/cper.c b/drivers/firmware/efi/cper.c
41188 index 5b53d61..72cee96 100644
41189 --- a/drivers/firmware/efi/cper.c
41190 +++ b/drivers/firmware/efi/cper.c
41191 @@ -44,12 +44,12 @@ static char rcd_decode_str[CPER_REC_LEN];
41192 */
41193 u64 cper_next_record_id(void)
41194 {
41195 - static atomic64_t seq;
41196 + static atomic64_unchecked_t seq;
41197
41198 - if (!atomic64_read(&seq))
41199 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
41200 + if (!atomic64_read_unchecked(&seq))
41201 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
41202
41203 - return atomic64_inc_return(&seq);
41204 + return atomic64_inc_return_unchecked(&seq);
41205 }
41206 EXPORT_SYMBOL_GPL(cper_next_record_id);
41207
41208 diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
41209 index 64ecbb5..d921eb3 100644
41210 --- a/drivers/firmware/efi/efi.c
41211 +++ b/drivers/firmware/efi/efi.c
41212 @@ -126,14 +126,16 @@ static struct attribute_group efi_subsys_attr_group = {
41213 };
41214
41215 static struct efivars generic_efivars;
41216 -static struct efivar_operations generic_ops;
41217 +static efivar_operations_no_const generic_ops __read_only;
41218
41219 static int generic_ops_register(void)
41220 {
41221 - generic_ops.get_variable = efi.get_variable;
41222 - generic_ops.set_variable = efi.set_variable;
41223 - generic_ops.get_next_variable = efi.get_next_variable;
41224 - generic_ops.query_variable_store = efi_query_variable_store;
41225 + pax_open_kernel();
41226 + *(void **)&generic_ops.get_variable = efi.get_variable;
41227 + *(void **)&generic_ops.set_variable = efi.set_variable;
41228 + *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
41229 + *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
41230 + pax_close_kernel();
41231
41232 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
41233 }
41234 diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
41235 index f256ecd..387dcb1 100644
41236 --- a/drivers/firmware/efi/efivars.c
41237 +++ b/drivers/firmware/efi/efivars.c
41238 @@ -589,7 +589,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
41239 static int
41240 create_efivars_bin_attributes(void)
41241 {
41242 - struct bin_attribute *attr;
41243 + bin_attribute_no_const *attr;
41244 int error;
41245
41246 /* new_var */
41247 diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
41248 index 2f569aa..c95f4fb 100644
41249 --- a/drivers/firmware/google/memconsole.c
41250 +++ b/drivers/firmware/google/memconsole.c
41251 @@ -155,7 +155,10 @@ static int __init memconsole_init(void)
41252 if (!found_memconsole())
41253 return -ENODEV;
41254
41255 - memconsole_bin_attr.size = memconsole_length;
41256 + pax_open_kernel();
41257 + *(size_t *)&memconsole_bin_attr.size = memconsole_length;
41258 + pax_close_kernel();
41259 +
41260 return sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
41261 }
41262
41263 diff --git a/drivers/gpio/gpio-em.c b/drivers/gpio/gpio-em.c
41264 index fe49ec3..1ade794 100644
41265 --- a/drivers/gpio/gpio-em.c
41266 +++ b/drivers/gpio/gpio-em.c
41267 @@ -278,7 +278,7 @@ static int em_gio_probe(struct platform_device *pdev)
41268 struct em_gio_priv *p;
41269 struct resource *io[2], *irq[2];
41270 struct gpio_chip *gpio_chip;
41271 - struct irq_chip *irq_chip;
41272 + irq_chip_no_const *irq_chip;
41273 const char *name = dev_name(&pdev->dev);
41274 int ret;
41275
41276 diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
41277 index 3784e81..73637b5 100644
41278 --- a/drivers/gpio/gpio-ich.c
41279 +++ b/drivers/gpio/gpio-ich.c
41280 @@ -94,7 +94,7 @@ struct ichx_desc {
41281 * this option allows driver caching written output values
41282 */
41283 bool use_outlvl_cache;
41284 -};
41285 +} __do_const;
41286
41287 static struct {
41288 spinlock_t lock;
41289 diff --git a/drivers/gpio/gpio-rcar.c b/drivers/gpio/gpio-rcar.c
41290 index bf6c094..6573caf 100644
41291 --- a/drivers/gpio/gpio-rcar.c
41292 +++ b/drivers/gpio/gpio-rcar.c
41293 @@ -357,7 +357,7 @@ static int gpio_rcar_probe(struct platform_device *pdev)
41294 struct gpio_rcar_priv *p;
41295 struct resource *io, *irq;
41296 struct gpio_chip *gpio_chip;
41297 - struct irq_chip *irq_chip;
41298 + irq_chip_no_const *irq_chip;
41299 struct device *dev = &pdev->dev;
41300 const char *name = dev_name(dev);
41301 int ret;
41302 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
41303 index dbf28fa..04dad4e 100644
41304 --- a/drivers/gpio/gpio-vr41xx.c
41305 +++ b/drivers/gpio/gpio-vr41xx.c
41306 @@ -224,7 +224,7 @@ static int giu_get_irq(unsigned int irq)
41307 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
41308 maskl, pendl, maskh, pendh);
41309
41310 - atomic_inc(&irq_err_count);
41311 + atomic_inc_unchecked(&irq_err_count);
41312
41313 return -EINVAL;
41314 }
41315 diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
41316 index c68d037..2f4f9a9 100644
41317 --- a/drivers/gpio/gpiolib.c
41318 +++ b/drivers/gpio/gpiolib.c
41319 @@ -529,8 +529,10 @@ static void gpiochip_irqchip_remove(struct gpio_chip *gpiochip)
41320 }
41321
41322 if (gpiochip->irqchip) {
41323 - gpiochip->irqchip->irq_request_resources = NULL;
41324 - gpiochip->irqchip->irq_release_resources = NULL;
41325 + pax_open_kernel();
41326 + *(void **)&gpiochip->irqchip->irq_request_resources = NULL;
41327 + *(void **)&gpiochip->irqchip->irq_release_resources = NULL;
41328 + pax_close_kernel();
41329 gpiochip->irqchip = NULL;
41330 }
41331 }
41332 @@ -596,8 +598,11 @@ int gpiochip_irqchip_add(struct gpio_chip *gpiochip,
41333 gpiochip->irqchip = NULL;
41334 return -EINVAL;
41335 }
41336 - irqchip->irq_request_resources = gpiochip_irq_reqres;
41337 - irqchip->irq_release_resources = gpiochip_irq_relres;
41338 +
41339 + pax_open_kernel();
41340 + *(void **)&irqchip->irq_request_resources = gpiochip_irq_reqres;
41341 + *(void **)&irqchip->irq_release_resources = gpiochip_irq_relres;
41342 + pax_close_kernel();
41343
41344 /*
41345 * Prepare the mapping since the irqchip shall be orthogonal to
41346 diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
41347 index 90e7730..3b41807 100644
41348 --- a/drivers/gpu/drm/drm_crtc.c
41349 +++ b/drivers/gpu/drm/drm_crtc.c
41350 @@ -3861,7 +3861,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
41351 goto done;
41352 }
41353
41354 - if (copy_to_user(&enum_ptr[copied].name,
41355 + if (copy_to_user(enum_ptr[copied].name,
41356 &prop_enum->name, DRM_PROP_NAME_LEN)) {
41357 ret = -EFAULT;
41358 goto done;
41359 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
41360 index 3242e20..7e4f621 100644
41361 --- a/drivers/gpu/drm/drm_drv.c
41362 +++ b/drivers/gpu/drm/drm_drv.c
41363 @@ -463,7 +463,7 @@ void drm_unplug_dev(struct drm_device *dev)
41364
41365 drm_device_set_unplugged(dev);
41366
41367 - if (dev->open_count == 0) {
41368 + if (local_read(&dev->open_count) == 0) {
41369 drm_put_dev(dev);
41370 }
41371 mutex_unlock(&drm_global_mutex);
41372 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
41373 index 79d5221..7ff73496 100644
41374 --- a/drivers/gpu/drm/drm_fops.c
41375 +++ b/drivers/gpu/drm/drm_fops.c
41376 @@ -89,7 +89,7 @@ int drm_open(struct inode *inode, struct file *filp)
41377 return PTR_ERR(minor);
41378
41379 dev = minor->dev;
41380 - if (!dev->open_count++)
41381 + if (local_inc_return(&dev->open_count) == 1)
41382 need_setup = 1;
41383
41384 /* share address_space across all char-devs of a single device */
41385 @@ -106,7 +106,7 @@ int drm_open(struct inode *inode, struct file *filp)
41386 return 0;
41387
41388 err_undo:
41389 - dev->open_count--;
41390 + local_dec(&dev->open_count);
41391 drm_minor_release(minor);
41392 return retcode;
41393 }
41394 @@ -384,7 +384,7 @@ int drm_release(struct inode *inode, struct file *filp)
41395
41396 mutex_lock(&drm_global_mutex);
41397
41398 - DRM_DEBUG("open_count = %d\n", dev->open_count);
41399 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
41400
41401 mutex_lock(&dev->struct_mutex);
41402 list_del(&file_priv->lhead);
41403 @@ -397,10 +397,10 @@ int drm_release(struct inode *inode, struct file *filp)
41404 * Begin inline drm_release
41405 */
41406
41407 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
41408 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
41409 task_pid_nr(current),
41410 (long)old_encode_dev(file_priv->minor->kdev->devt),
41411 - dev->open_count);
41412 + local_read(&dev->open_count));
41413
41414 /* Release any auth tokens that might point to this file_priv,
41415 (do that under the drm_global_mutex) */
41416 @@ -471,7 +471,7 @@ int drm_release(struct inode *inode, struct file *filp)
41417 * End inline drm_release
41418 */
41419
41420 - if (!--dev->open_count) {
41421 + if (local_dec_and_test(&dev->open_count)) {
41422 retcode = drm_lastclose(dev);
41423 if (drm_device_is_unplugged(dev))
41424 drm_put_dev(dev);
41425 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
41426 index 3d2e91c..d31c4c9 100644
41427 --- a/drivers/gpu/drm/drm_global.c
41428 +++ b/drivers/gpu/drm/drm_global.c
41429 @@ -36,7 +36,7 @@
41430 struct drm_global_item {
41431 struct mutex mutex;
41432 void *object;
41433 - int refcount;
41434 + atomic_t refcount;
41435 };
41436
41437 static struct drm_global_item glob[DRM_GLOBAL_NUM];
41438 @@ -49,7 +49,7 @@ void drm_global_init(void)
41439 struct drm_global_item *item = &glob[i];
41440 mutex_init(&item->mutex);
41441 item->object = NULL;
41442 - item->refcount = 0;
41443 + atomic_set(&item->refcount, 0);
41444 }
41445 }
41446
41447 @@ -59,7 +59,7 @@ void drm_global_release(void)
41448 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
41449 struct drm_global_item *item = &glob[i];
41450 BUG_ON(item->object != NULL);
41451 - BUG_ON(item->refcount != 0);
41452 + BUG_ON(atomic_read(&item->refcount) != 0);
41453 }
41454 }
41455
41456 @@ -69,7 +69,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
41457 struct drm_global_item *item = &glob[ref->global_type];
41458
41459 mutex_lock(&item->mutex);
41460 - if (item->refcount == 0) {
41461 + if (atomic_read(&item->refcount) == 0) {
41462 item->object = kzalloc(ref->size, GFP_KERNEL);
41463 if (unlikely(item->object == NULL)) {
41464 ret = -ENOMEM;
41465 @@ -82,7 +82,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
41466 goto out_err;
41467
41468 }
41469 - ++item->refcount;
41470 + atomic_inc(&item->refcount);
41471 ref->object = item->object;
41472 mutex_unlock(&item->mutex);
41473 return 0;
41474 @@ -98,9 +98,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
41475 struct drm_global_item *item = &glob[ref->global_type];
41476
41477 mutex_lock(&item->mutex);
41478 - BUG_ON(item->refcount == 0);
41479 + BUG_ON(atomic_read(&item->refcount) == 0);
41480 BUG_ON(ref->object != item->object);
41481 - if (--item->refcount == 0) {
41482 + if (atomic_dec_and_test(&item->refcount)) {
41483 ref->release(ref);
41484 item->object = NULL;
41485 }
41486 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
41487 index ecaf0fa..a49cee9 100644
41488 --- a/drivers/gpu/drm/drm_info.c
41489 +++ b/drivers/gpu/drm/drm_info.c
41490 @@ -73,10 +73,13 @@ int drm_vm_info(struct seq_file *m, void *data)
41491 struct drm_local_map *map;
41492 struct drm_map_list *r_list;
41493
41494 - /* Hardcoded from _DRM_FRAME_BUFFER,
41495 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
41496 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
41497 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
41498 + static const char * const types[] = {
41499 + [_DRM_FRAME_BUFFER] = "FB",
41500 + [_DRM_REGISTERS] = "REG",
41501 + [_DRM_SHM] = "SHM",
41502 + [_DRM_AGP] = "AGP",
41503 + [_DRM_SCATTER_GATHER] = "SG",
41504 + [_DRM_CONSISTENT] = "PCI"};
41505 const char *type;
41506 int i;
41507
41508 @@ -87,7 +90,7 @@ int drm_vm_info(struct seq_file *m, void *data)
41509 map = r_list->map;
41510 if (!map)
41511 continue;
41512 - if (map->type < 0 || map->type > 5)
41513 + if (map->type >= ARRAY_SIZE(types))
41514 type = "??";
41515 else
41516 type = types[map->type];
41517 @@ -259,7 +262,11 @@ int drm_vma_info(struct seq_file *m, void *data)
41518 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
41519 vma->vm_flags & VM_LOCKED ? 'l' : '-',
41520 vma->vm_flags & VM_IO ? 'i' : '-',
41521 +#ifdef CONFIG_GRKERNSEC_HIDESYM
41522 + 0);
41523 +#else
41524 vma->vm_pgoff);
41525 +#endif
41526
41527 #if defined(__i386__)
41528 pgprot = pgprot_val(vma->vm_page_prot);
41529 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
41530 index 2f4c4343..dd12cd2 100644
41531 --- a/drivers/gpu/drm/drm_ioc32.c
41532 +++ b/drivers/gpu/drm/drm_ioc32.c
41533 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
41534 request = compat_alloc_user_space(nbytes);
41535 if (!access_ok(VERIFY_WRITE, request, nbytes))
41536 return -EFAULT;
41537 - list = (struct drm_buf_desc *) (request + 1);
41538 + list = (struct drm_buf_desc __user *) (request + 1);
41539
41540 if (__put_user(count, &request->count)
41541 || __put_user(list, &request->list))
41542 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
41543 request = compat_alloc_user_space(nbytes);
41544 if (!access_ok(VERIFY_WRITE, request, nbytes))
41545 return -EFAULT;
41546 - list = (struct drm_buf_pub *) (request + 1);
41547 + list = (struct drm_buf_pub __user *) (request + 1);
41548
41549 if (__put_user(count, &request->count)
41550 || __put_user(list, &request->list))
41551 @@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
41552 return 0;
41553 }
41554
41555 -drm_ioctl_compat_t *drm_compat_ioctls[] = {
41556 +drm_ioctl_compat_t drm_compat_ioctls[] = {
41557 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
41558 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
41559 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
41560 @@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
41561 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
41562 {
41563 unsigned int nr = DRM_IOCTL_NR(cmd);
41564 - drm_ioctl_compat_t *fn;
41565 int ret;
41566
41567 /* Assume that ioctls without an explicit compat routine will just
41568 @@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
41569 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
41570 return drm_ioctl(filp, cmd, arg);
41571
41572 - fn = drm_compat_ioctls[nr];
41573 -
41574 - if (fn != NULL)
41575 - ret = (*fn) (filp, cmd, arg);
41576 + if (drm_compat_ioctls[nr] != NULL)
41577 + ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
41578 else
41579 ret = drm_ioctl(filp, cmd, arg);
41580
41581 diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
41582 index 40be746..fd78faf 100644
41583 --- a/drivers/gpu/drm/drm_ioctl.c
41584 +++ b/drivers/gpu/drm/drm_ioctl.c
41585 @@ -642,7 +642,7 @@ long drm_ioctl(struct file *filp,
41586 struct drm_file *file_priv = filp->private_data;
41587 struct drm_device *dev;
41588 const struct drm_ioctl_desc *ioctl = NULL;
41589 - drm_ioctl_t *func;
41590 + drm_ioctl_no_const_t func;
41591 unsigned int nr = DRM_IOCTL_NR(cmd);
41592 int retcode = -EINVAL;
41593 char stack_kdata[128];
41594 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
41595 index d4d16ed..8fb0b51 100644
41596 --- a/drivers/gpu/drm/i810/i810_drv.h
41597 +++ b/drivers/gpu/drm/i810/i810_drv.h
41598 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
41599 int page_flipping;
41600
41601 wait_queue_head_t irq_queue;
41602 - atomic_t irq_received;
41603 - atomic_t irq_emitted;
41604 + atomic_unchecked_t irq_received;
41605 + atomic_unchecked_t irq_emitted;
41606
41607 int front_offset;
41608 } drm_i810_private_t;
41609 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
41610 index 2d23e57..1c61d41 100644
41611 --- a/drivers/gpu/drm/i915/i915_dma.c
41612 +++ b/drivers/gpu/drm/i915/i915_dma.c
41613 @@ -1292,7 +1292,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
41614 * locking inversion with the driver load path. And the access here is
41615 * completely racy anyway. So don't bother with locking for now.
41616 */
41617 - return dev->open_count == 0;
41618 + return local_read(&dev->open_count) == 0;
41619 }
41620
41621 static const struct vga_switcheroo_client_ops i915_switcheroo_ops = {
41622 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
41623 index 60998fc..3b244bc 100644
41624 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
41625 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
41626 @@ -891,9 +891,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
41627
41628 static int
41629 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
41630 - int count)
41631 + unsigned int count)
41632 {
41633 - int i;
41634 + unsigned int i;
41635 unsigned relocs_total = 0;
41636 unsigned relocs_max = UINT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
41637
41638 diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
41639 index 2e0613e..a8b94d9 100644
41640 --- a/drivers/gpu/drm/i915/i915_ioc32.c
41641 +++ b/drivers/gpu/drm/i915/i915_ioc32.c
41642 @@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
41643 (unsigned long)request);
41644 }
41645
41646 -static drm_ioctl_compat_t *i915_compat_ioctls[] = {
41647 +static drm_ioctl_compat_t i915_compat_ioctls[] = {
41648 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
41649 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
41650 [DRM_I915_GETPARAM] = compat_i915_getparam,
41651 @@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
41652 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
41653 {
41654 unsigned int nr = DRM_IOCTL_NR(cmd);
41655 - drm_ioctl_compat_t *fn = NULL;
41656 int ret;
41657
41658 if (nr < DRM_COMMAND_BASE)
41659 return drm_compat_ioctl(filp, cmd, arg);
41660
41661 - if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(i915_compat_ioctls))
41662 - fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
41663 -
41664 - if (fn != NULL)
41665 + if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(i915_compat_ioctls)) {
41666 + drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
41667 ret = (*fn) (filp, cmd, arg);
41668 - else
41669 + } else
41670 ret = drm_ioctl(filp, cmd, arg);
41671
41672 return ret;
41673 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
41674 index 8663c21..46f2cbf 100644
41675 --- a/drivers/gpu/drm/i915/intel_display.c
41676 +++ b/drivers/gpu/drm/i915/intel_display.c
41677 @@ -12439,13 +12439,13 @@ struct intel_quirk {
41678 int subsystem_vendor;
41679 int subsystem_device;
41680 void (*hook)(struct drm_device *dev);
41681 -};
41682 +} __do_const;
41683
41684 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
41685 struct intel_dmi_quirk {
41686 void (*hook)(struct drm_device *dev);
41687 const struct dmi_system_id (*dmi_id_list)[];
41688 -};
41689 +} __do_const;
41690
41691 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
41692 {
41693 @@ -12453,18 +12453,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
41694 return 1;
41695 }
41696
41697 -static const struct intel_dmi_quirk intel_dmi_quirks[] = {
41698 +static const struct dmi_system_id intel_dmi_quirks_table[] = {
41699 {
41700 - .dmi_id_list = &(const struct dmi_system_id[]) {
41701 - {
41702 - .callback = intel_dmi_reverse_brightness,
41703 - .ident = "NCR Corporation",
41704 - .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
41705 - DMI_MATCH(DMI_PRODUCT_NAME, ""),
41706 - },
41707 - },
41708 - { } /* terminating entry */
41709 + .callback = intel_dmi_reverse_brightness,
41710 + .ident = "NCR Corporation",
41711 + .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
41712 + DMI_MATCH(DMI_PRODUCT_NAME, ""),
41713 },
41714 + },
41715 + { } /* terminating entry */
41716 +};
41717 +
41718 +static const struct intel_dmi_quirk intel_dmi_quirks[] = {
41719 + {
41720 + .dmi_id_list = &intel_dmi_quirks_table,
41721 .hook = quirk_invert_brightness,
41722 },
41723 };
41724 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
41725 index fe45321..836fdca 100644
41726 --- a/drivers/gpu/drm/mga/mga_drv.h
41727 +++ b/drivers/gpu/drm/mga/mga_drv.h
41728 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
41729 u32 clear_cmd;
41730 u32 maccess;
41731
41732 - atomic_t vbl_received; /**< Number of vblanks received. */
41733 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
41734 wait_queue_head_t fence_queue;
41735 - atomic_t last_fence_retired;
41736 + atomic_unchecked_t last_fence_retired;
41737 u32 next_fence_to_post;
41738
41739 unsigned int fb_cpp;
41740 diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
41741 index 729bfd5..ead8823 100644
41742 --- a/drivers/gpu/drm/mga/mga_ioc32.c
41743 +++ b/drivers/gpu/drm/mga/mga_ioc32.c
41744 @@ -190,7 +190,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
41745 return 0;
41746 }
41747
41748 -drm_ioctl_compat_t *mga_compat_ioctls[] = {
41749 +drm_ioctl_compat_t mga_compat_ioctls[] = {
41750 [DRM_MGA_INIT] = compat_mga_init,
41751 [DRM_MGA_GETPARAM] = compat_mga_getparam,
41752 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
41753 @@ -208,18 +208,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
41754 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
41755 {
41756 unsigned int nr = DRM_IOCTL_NR(cmd);
41757 - drm_ioctl_compat_t *fn = NULL;
41758 int ret;
41759
41760 if (nr < DRM_COMMAND_BASE)
41761 return drm_compat_ioctl(filp, cmd, arg);
41762
41763 - if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(mga_compat_ioctls))
41764 - fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
41765 -
41766 - if (fn != NULL)
41767 + if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(mga_compat_ioctls)) {
41768 + drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
41769 ret = (*fn) (filp, cmd, arg);
41770 - else
41771 + } else
41772 ret = drm_ioctl(filp, cmd, arg);
41773
41774 return ret;
41775 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
41776 index 1b071b8..de8601a 100644
41777 --- a/drivers/gpu/drm/mga/mga_irq.c
41778 +++ b/drivers/gpu/drm/mga/mga_irq.c
41779 @@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
41780 if (crtc != 0)
41781 return 0;
41782
41783 - return atomic_read(&dev_priv->vbl_received);
41784 + return atomic_read_unchecked(&dev_priv->vbl_received);
41785 }
41786
41787
41788 @@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
41789 /* VBLANK interrupt */
41790 if (status & MGA_VLINEPEN) {
41791 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
41792 - atomic_inc(&dev_priv->vbl_received);
41793 + atomic_inc_unchecked(&dev_priv->vbl_received);
41794 drm_handle_vblank(dev, 0);
41795 handled = 1;
41796 }
41797 @@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
41798 if ((prim_start & ~0x03) != (prim_end & ~0x03))
41799 MGA_WRITE(MGA_PRIMEND, prim_end);
41800
41801 - atomic_inc(&dev_priv->last_fence_retired);
41802 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
41803 wake_up(&dev_priv->fence_queue);
41804 handled = 1;
41805 }
41806 @@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
41807 * using fences.
41808 */
41809 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * HZ,
41810 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
41811 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
41812 - *sequence) <= (1 << 23)));
41813
41814 *sequence = cur_fence;
41815 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
41816 index dae2c96..324dbe4 100644
41817 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
41818 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
41819 @@ -963,7 +963,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
41820 struct bit_table {
41821 const char id;
41822 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
41823 -};
41824 +} __no_const;
41825
41826 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
41827
41828 diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
41829 index b02b024..aed7bad 100644
41830 --- a/drivers/gpu/drm/nouveau/nouveau_drm.h
41831 +++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
41832 @@ -119,7 +119,6 @@ struct nouveau_drm {
41833 struct drm_global_reference mem_global_ref;
41834 struct ttm_bo_global_ref bo_global_ref;
41835 struct ttm_bo_device bdev;
41836 - atomic_t validate_sequence;
41837 int (*move)(struct nouveau_channel *,
41838 struct ttm_buffer_object *,
41839 struct ttm_mem_reg *, struct ttm_mem_reg *);
41840 diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
41841 index 462679a..88e32a7 100644
41842 --- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
41843 +++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
41844 @@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
41845 unsigned long arg)
41846 {
41847 unsigned int nr = DRM_IOCTL_NR(cmd);
41848 - drm_ioctl_compat_t *fn = NULL;
41849 + drm_ioctl_compat_t fn = NULL;
41850 int ret;
41851
41852 if (nr < DRM_COMMAND_BASE)
41853 diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
41854 index 53874b7..1db0a68 100644
41855 --- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
41856 +++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
41857 @@ -127,11 +127,11 @@ nouveau_vram_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
41858 }
41859
41860 const struct ttm_mem_type_manager_func nouveau_vram_manager = {
41861 - nouveau_vram_manager_init,
41862 - nouveau_vram_manager_fini,
41863 - nouveau_vram_manager_new,
41864 - nouveau_vram_manager_del,
41865 - nouveau_vram_manager_debug
41866 + .init = nouveau_vram_manager_init,
41867 + .takedown = nouveau_vram_manager_fini,
41868 + .get_node = nouveau_vram_manager_new,
41869 + .put_node = nouveau_vram_manager_del,
41870 + .debug = nouveau_vram_manager_debug
41871 };
41872
41873 static int
41874 @@ -196,11 +196,11 @@ nouveau_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
41875 }
41876
41877 const struct ttm_mem_type_manager_func nouveau_gart_manager = {
41878 - nouveau_gart_manager_init,
41879 - nouveau_gart_manager_fini,
41880 - nouveau_gart_manager_new,
41881 - nouveau_gart_manager_del,
41882 - nouveau_gart_manager_debug
41883 + .init = nouveau_gart_manager_init,
41884 + .takedown = nouveau_gart_manager_fini,
41885 + .get_node = nouveau_gart_manager_new,
41886 + .put_node = nouveau_gart_manager_del,
41887 + .debug = nouveau_gart_manager_debug
41888 };
41889
41890 /*XXX*/
41891 @@ -270,11 +270,11 @@ nv04_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
41892 }
41893
41894 const struct ttm_mem_type_manager_func nv04_gart_manager = {
41895 - nv04_gart_manager_init,
41896 - nv04_gart_manager_fini,
41897 - nv04_gart_manager_new,
41898 - nv04_gart_manager_del,
41899 - nv04_gart_manager_debug
41900 + .init = nv04_gart_manager_init,
41901 + .takedown = nv04_gart_manager_fini,
41902 + .get_node = nv04_gart_manager_new,
41903 + .put_node = nv04_gart_manager_del,
41904 + .debug = nv04_gart_manager_debug
41905 };
41906
41907 int
41908 diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
41909 index c7592ec..dd45ebc 100644
41910 --- a/drivers/gpu/drm/nouveau/nouveau_vga.c
41911 +++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
41912 @@ -72,7 +72,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
41913 * locking inversion with the driver load path. And the access here is
41914 * completely racy anyway. So don't bother with locking for now.
41915 */
41916 - return dev->open_count == 0;
41917 + return local_read(&dev->open_count) == 0;
41918 }
41919
41920 static const struct vga_switcheroo_client_ops
41921 diff --git a/drivers/gpu/drm/qxl/qxl_cmd.c b/drivers/gpu/drm/qxl/qxl_cmd.c
41922 index eb89653..613cf71 100644
41923 --- a/drivers/gpu/drm/qxl/qxl_cmd.c
41924 +++ b/drivers/gpu/drm/qxl/qxl_cmd.c
41925 @@ -285,27 +285,27 @@ static int wait_for_io_cmd_user(struct qxl_device *qdev, uint8_t val, long port,
41926 int ret;
41927
41928 mutex_lock(&qdev->async_io_mutex);
41929 - irq_num = atomic_read(&qdev->irq_received_io_cmd);
41930 + irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
41931 if (qdev->last_sent_io_cmd > irq_num) {
41932 if (intr)
41933 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
41934 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41935 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41936 else
41937 ret = wait_event_timeout(qdev->io_cmd_event,
41938 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41939 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41940 /* 0 is timeout, just bail the "hw" has gone away */
41941 if (ret <= 0)
41942 goto out;
41943 - irq_num = atomic_read(&qdev->irq_received_io_cmd);
41944 + irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
41945 }
41946 outb(val, addr);
41947 qdev->last_sent_io_cmd = irq_num + 1;
41948 if (intr)
41949 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
41950 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41951 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41952 else
41953 ret = wait_event_timeout(qdev->io_cmd_event,
41954 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41955 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41956 out:
41957 if (ret > 0)
41958 ret = 0;
41959 diff --git a/drivers/gpu/drm/qxl/qxl_debugfs.c b/drivers/gpu/drm/qxl/qxl_debugfs.c
41960 index c3c2bbd..bc3c0fb 100644
41961 --- a/drivers/gpu/drm/qxl/qxl_debugfs.c
41962 +++ b/drivers/gpu/drm/qxl/qxl_debugfs.c
41963 @@ -42,10 +42,10 @@ qxl_debugfs_irq_received(struct seq_file *m, void *data)
41964 struct drm_info_node *node = (struct drm_info_node *) m->private;
41965 struct qxl_device *qdev = node->minor->dev->dev_private;
41966
41967 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received));
41968 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_display));
41969 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_cursor));
41970 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_io_cmd));
41971 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received));
41972 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_display));
41973 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_cursor));
41974 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_io_cmd));
41975 seq_printf(m, "%d\n", qdev->irq_received_error);
41976 return 0;
41977 }
41978 diff --git a/drivers/gpu/drm/qxl/qxl_drv.h b/drivers/gpu/drm/qxl/qxl_drv.h
41979 index 36ed40b..0397633 100644
41980 --- a/drivers/gpu/drm/qxl/qxl_drv.h
41981 +++ b/drivers/gpu/drm/qxl/qxl_drv.h
41982 @@ -290,10 +290,10 @@ struct qxl_device {
41983 unsigned int last_sent_io_cmd;
41984
41985 /* interrupt handling */
41986 - atomic_t irq_received;
41987 - atomic_t irq_received_display;
41988 - atomic_t irq_received_cursor;
41989 - atomic_t irq_received_io_cmd;
41990 + atomic_unchecked_t irq_received;
41991 + atomic_unchecked_t irq_received_display;
41992 + atomic_unchecked_t irq_received_cursor;
41993 + atomic_unchecked_t irq_received_io_cmd;
41994 unsigned irq_received_error;
41995 wait_queue_head_t display_event;
41996 wait_queue_head_t cursor_event;
41997 diff --git a/drivers/gpu/drm/qxl/qxl_ioctl.c b/drivers/gpu/drm/qxl/qxl_ioctl.c
41998 index b110883..dd06418 100644
41999 --- a/drivers/gpu/drm/qxl/qxl_ioctl.c
42000 +++ b/drivers/gpu/drm/qxl/qxl_ioctl.c
42001 @@ -181,7 +181,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
42002
42003 /* TODO copy slow path code from i915 */
42004 fb_cmd = qxl_bo_kmap_atomic_page(qdev, cmd_bo, (release->release_offset & PAGE_SIZE));
42005 - 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);
42006 + 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);
42007
42008 {
42009 struct qxl_drawable *draw = fb_cmd;
42010 @@ -201,7 +201,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
42011 struct drm_qxl_reloc reloc;
42012
42013 if (copy_from_user(&reloc,
42014 - &((struct drm_qxl_reloc *)(uintptr_t)cmd->relocs)[i],
42015 + &((struct drm_qxl_reloc __force_user *)(uintptr_t)cmd->relocs)[i],
42016 sizeof(reloc))) {
42017 ret = -EFAULT;
42018 goto out_free_bos;
42019 @@ -294,10 +294,10 @@ static int qxl_execbuffer_ioctl(struct drm_device *dev, void *data,
42020
42021 for (cmd_num = 0; cmd_num < execbuffer->commands_num; ++cmd_num) {
42022
42023 - struct drm_qxl_command *commands =
42024 - (struct drm_qxl_command *)(uintptr_t)execbuffer->commands;
42025 + struct drm_qxl_command __user *commands =
42026 + (struct drm_qxl_command __user *)(uintptr_t)execbuffer->commands;
42027
42028 - if (copy_from_user(&user_cmd, &commands[cmd_num],
42029 + if (copy_from_user(&user_cmd, (struct drm_qxl_command __force_user *)&commands[cmd_num],
42030 sizeof(user_cmd)))
42031 return -EFAULT;
42032
42033 diff --git a/drivers/gpu/drm/qxl/qxl_irq.c b/drivers/gpu/drm/qxl/qxl_irq.c
42034 index 0bf1e20..42a7310 100644
42035 --- a/drivers/gpu/drm/qxl/qxl_irq.c
42036 +++ b/drivers/gpu/drm/qxl/qxl_irq.c
42037 @@ -36,19 +36,19 @@ irqreturn_t qxl_irq_handler(int irq, void *arg)
42038 if (!pending)
42039 return IRQ_NONE;
42040
42041 - atomic_inc(&qdev->irq_received);
42042 + atomic_inc_unchecked(&qdev->irq_received);
42043
42044 if (pending & QXL_INTERRUPT_DISPLAY) {
42045 - atomic_inc(&qdev->irq_received_display);
42046 + atomic_inc_unchecked(&qdev->irq_received_display);
42047 wake_up_all(&qdev->display_event);
42048 qxl_queue_garbage_collect(qdev, false);
42049 }
42050 if (pending & QXL_INTERRUPT_CURSOR) {
42051 - atomic_inc(&qdev->irq_received_cursor);
42052 + atomic_inc_unchecked(&qdev->irq_received_cursor);
42053 wake_up_all(&qdev->cursor_event);
42054 }
42055 if (pending & QXL_INTERRUPT_IO_CMD) {
42056 - atomic_inc(&qdev->irq_received_io_cmd);
42057 + atomic_inc_unchecked(&qdev->irq_received_io_cmd);
42058 wake_up_all(&qdev->io_cmd_event);
42059 }
42060 if (pending & QXL_INTERRUPT_ERROR) {
42061 @@ -85,10 +85,10 @@ int qxl_irq_init(struct qxl_device *qdev)
42062 init_waitqueue_head(&qdev->io_cmd_event);
42063 INIT_WORK(&qdev->client_monitors_config_work,
42064 qxl_client_monitors_config_work_func);
42065 - atomic_set(&qdev->irq_received, 0);
42066 - atomic_set(&qdev->irq_received_display, 0);
42067 - atomic_set(&qdev->irq_received_cursor, 0);
42068 - atomic_set(&qdev->irq_received_io_cmd, 0);
42069 + atomic_set_unchecked(&qdev->irq_received, 0);
42070 + atomic_set_unchecked(&qdev->irq_received_display, 0);
42071 + atomic_set_unchecked(&qdev->irq_received_cursor, 0);
42072 + atomic_set_unchecked(&qdev->irq_received_io_cmd, 0);
42073 qdev->irq_received_error = 0;
42074 ret = drm_irq_install(qdev->ddev, qdev->ddev->pdev->irq);
42075 qdev->ram_header->int_mask = QXL_INTERRUPT_MASK;
42076 diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
42077 index 71a1bae..cb1f103 100644
42078 --- a/drivers/gpu/drm/qxl/qxl_ttm.c
42079 +++ b/drivers/gpu/drm/qxl/qxl_ttm.c
42080 @@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
42081 }
42082 }
42083
42084 -static struct vm_operations_struct qxl_ttm_vm_ops;
42085 +static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
42086 static const struct vm_operations_struct *ttm_vm_ops;
42087
42088 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
42089 @@ -145,8 +145,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
42090 return r;
42091 if (unlikely(ttm_vm_ops == NULL)) {
42092 ttm_vm_ops = vma->vm_ops;
42093 + pax_open_kernel();
42094 qxl_ttm_vm_ops = *ttm_vm_ops;
42095 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
42096 + pax_close_kernel();
42097 }
42098 vma->vm_ops = &qxl_ttm_vm_ops;
42099 return 0;
42100 @@ -555,25 +557,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
42101 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
42102 {
42103 #if defined(CONFIG_DEBUG_FS)
42104 - static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
42105 - static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
42106 - unsigned i;
42107 + static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
42108 + {
42109 + .name = "qxl_mem_mm",
42110 + .show = &qxl_mm_dump_table,
42111 + },
42112 + {
42113 + .name = "qxl_surf_mm",
42114 + .show = &qxl_mm_dump_table,
42115 + }
42116 + };
42117
42118 - for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
42119 - if (i == 0)
42120 - sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
42121 - else
42122 - sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
42123 - qxl_mem_types_list[i].name = qxl_mem_types_names[i];
42124 - qxl_mem_types_list[i].show = &qxl_mm_dump_table;
42125 - qxl_mem_types_list[i].driver_features = 0;
42126 - if (i == 0)
42127 - qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
42128 - else
42129 - qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
42130 + pax_open_kernel();
42131 + *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
42132 + *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
42133 + pax_close_kernel();
42134
42135 - }
42136 - return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
42137 + return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
42138 #else
42139 return 0;
42140 #endif
42141 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
42142 index 59459fe..be26b31 100644
42143 --- a/drivers/gpu/drm/r128/r128_cce.c
42144 +++ b/drivers/gpu/drm/r128/r128_cce.c
42145 @@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
42146
42147 /* GH: Simple idle check.
42148 */
42149 - atomic_set(&dev_priv->idle_count, 0);
42150 + atomic_set_unchecked(&dev_priv->idle_count, 0);
42151
42152 /* We don't support anything other than bus-mastering ring mode,
42153 * but the ring can be in either AGP or PCI space for the ring
42154 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
42155 index 5bf3f5f..7000661 100644
42156 --- a/drivers/gpu/drm/r128/r128_drv.h
42157 +++ b/drivers/gpu/drm/r128/r128_drv.h
42158 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
42159 int is_pci;
42160 unsigned long cce_buffers_offset;
42161
42162 - atomic_t idle_count;
42163 + atomic_unchecked_t idle_count;
42164
42165 int page_flipping;
42166 int current_page;
42167 u32 crtc_offset;
42168 u32 crtc_offset_cntl;
42169
42170 - atomic_t vbl_received;
42171 + atomic_unchecked_t vbl_received;
42172
42173 u32 color_fmt;
42174 unsigned int front_offset;
42175 diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
42176 index 663f38c..c689495 100644
42177 --- a/drivers/gpu/drm/r128/r128_ioc32.c
42178 +++ b/drivers/gpu/drm/r128/r128_ioc32.c
42179 @@ -178,7 +178,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
42180 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
42181 }
42182
42183 -drm_ioctl_compat_t *r128_compat_ioctls[] = {
42184 +drm_ioctl_compat_t r128_compat_ioctls[] = {
42185 [DRM_R128_INIT] = compat_r128_init,
42186 [DRM_R128_DEPTH] = compat_r128_depth,
42187 [DRM_R128_STIPPLE] = compat_r128_stipple,
42188 @@ -197,18 +197,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
42189 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
42190 {
42191 unsigned int nr = DRM_IOCTL_NR(cmd);
42192 - drm_ioctl_compat_t *fn = NULL;
42193 int ret;
42194
42195 if (nr < DRM_COMMAND_BASE)
42196 return drm_compat_ioctl(filp, cmd, arg);
42197
42198 - if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(r128_compat_ioctls))
42199 - fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
42200 -
42201 - if (fn != NULL)
42202 + if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(r128_compat_ioctls)) {
42203 + drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
42204 ret = (*fn) (filp, cmd, arg);
42205 - else
42206 + } else
42207 ret = drm_ioctl(filp, cmd, arg);
42208
42209 return ret;
42210 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
42211 index c2ae496..30b5993 100644
42212 --- a/drivers/gpu/drm/r128/r128_irq.c
42213 +++ b/drivers/gpu/drm/r128/r128_irq.c
42214 @@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
42215 if (crtc != 0)
42216 return 0;
42217
42218 - return atomic_read(&dev_priv->vbl_received);
42219 + return atomic_read_unchecked(&dev_priv->vbl_received);
42220 }
42221
42222 irqreturn_t r128_driver_irq_handler(int irq, void *arg)
42223 @@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(int irq, void *arg)
42224 /* VBLANK interrupt */
42225 if (status & R128_CRTC_VBLANK_INT) {
42226 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
42227 - atomic_inc(&dev_priv->vbl_received);
42228 + atomic_inc_unchecked(&dev_priv->vbl_received);
42229 drm_handle_vblank(dev, 0);
42230 return IRQ_HANDLED;
42231 }
42232 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
42233 index 575e986..66e62ca 100644
42234 --- a/drivers/gpu/drm/r128/r128_state.c
42235 +++ b/drivers/gpu/drm/r128/r128_state.c
42236 @@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
42237
42238 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
42239 {
42240 - if (atomic_read(&dev_priv->idle_count) == 0)
42241 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
42242 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
42243 else
42244 - atomic_set(&dev_priv->idle_count, 0);
42245 + atomic_set_unchecked(&dev_priv->idle_count, 0);
42246 }
42247
42248 #endif
42249 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
42250 index 4a85bb6..aaea819 100644
42251 --- a/drivers/gpu/drm/radeon/mkregtable.c
42252 +++ b/drivers/gpu/drm/radeon/mkregtable.c
42253 @@ -624,14 +624,14 @@ static int parser_auth(struct table *t, const char *filename)
42254 regex_t mask_rex;
42255 regmatch_t match[4];
42256 char buf[1024];
42257 - size_t end;
42258 + long end;
42259 int len;
42260 int done = 0;
42261 int r;
42262 unsigned o;
42263 struct offset *offset;
42264 char last_reg_s[10];
42265 - int last_reg;
42266 + unsigned long last_reg;
42267
42268 if (regcomp
42269 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
42270 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
42271 index 5d4416f..80b7fc4 100644
42272 --- a/drivers/gpu/drm/radeon/radeon_device.c
42273 +++ b/drivers/gpu/drm/radeon/radeon_device.c
42274 @@ -1214,7 +1214,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
42275 * locking inversion with the driver load path. And the access here is
42276 * completely racy anyway. So don't bother with locking for now.
42277 */
42278 - return dev->open_count == 0;
42279 + return local_read(&dev->open_count) == 0;
42280 }
42281
42282 static const struct vga_switcheroo_client_ops radeon_switcheroo_ops = {
42283 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
42284 index dafd812..1bf20c7 100644
42285 --- a/drivers/gpu/drm/radeon/radeon_drv.h
42286 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
42287 @@ -262,7 +262,7 @@ typedef struct drm_radeon_private {
42288
42289 /* SW interrupt */
42290 wait_queue_head_t swi_queue;
42291 - atomic_t swi_emitted;
42292 + atomic_unchecked_t swi_emitted;
42293 int vblank_crtc;
42294 uint32_t irq_enable_reg;
42295 uint32_t r500_disp_irq_reg;
42296 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
42297 index 0b98ea1..0881827 100644
42298 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
42299 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
42300 @@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
42301 request = compat_alloc_user_space(sizeof(*request));
42302 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
42303 || __put_user(req32.param, &request->param)
42304 - || __put_user((void __user *)(unsigned long)req32.value,
42305 + || __put_user((unsigned long)req32.value,
42306 &request->value))
42307 return -EFAULT;
42308
42309 @@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
42310 #define compat_radeon_cp_setparam NULL
42311 #endif /* X86_64 || IA64 */
42312
42313 -static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
42314 +static drm_ioctl_compat_t radeon_compat_ioctls[] = {
42315 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
42316 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
42317 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
42318 @@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
42319 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
42320 {
42321 unsigned int nr = DRM_IOCTL_NR(cmd);
42322 - drm_ioctl_compat_t *fn = NULL;
42323 int ret;
42324
42325 if (nr < DRM_COMMAND_BASE)
42326 return drm_compat_ioctl(filp, cmd, arg);
42327
42328 - if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(radeon_compat_ioctls))
42329 - fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
42330 -
42331 - if (fn != NULL)
42332 + if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(radeon_compat_ioctls)) {
42333 + drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
42334 ret = (*fn) (filp, cmd, arg);
42335 - else
42336 + } else
42337 ret = drm_ioctl(filp, cmd, arg);
42338
42339 return ret;
42340 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
42341 index 244b19b..c19226d 100644
42342 --- a/drivers/gpu/drm/radeon/radeon_irq.c
42343 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
42344 @@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
42345 unsigned int ret;
42346 RING_LOCALS;
42347
42348 - atomic_inc(&dev_priv->swi_emitted);
42349 - ret = atomic_read(&dev_priv->swi_emitted);
42350 + atomic_inc_unchecked(&dev_priv->swi_emitted);
42351 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
42352
42353 BEGIN_RING(4);
42354 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
42355 @@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
42356 drm_radeon_private_t *dev_priv =
42357 (drm_radeon_private_t *) dev->dev_private;
42358
42359 - atomic_set(&dev_priv->swi_emitted, 0);
42360 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
42361 init_waitqueue_head(&dev_priv->swi_queue);
42362
42363 dev->max_vblank_count = 0x001fffff;
42364 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
42365 index 23bb64f..69d7234 100644
42366 --- a/drivers/gpu/drm/radeon/radeon_state.c
42367 +++ b/drivers/gpu/drm/radeon/radeon_state.c
42368 @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
42369 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
42370 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
42371
42372 - if (copy_from_user(&depth_boxes, clear->depth_boxes,
42373 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || copy_from_user(&depth_boxes, clear->depth_boxes,
42374 sarea_priv->nbox * sizeof(depth_boxes[0])))
42375 return -EFAULT;
42376
42377 @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
42378 {
42379 drm_radeon_private_t *dev_priv = dev->dev_private;
42380 drm_radeon_getparam_t *param = data;
42381 - int value;
42382 + int value = 0;
42383
42384 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
42385
42386 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
42387 index 72afe82..056a57a 100644
42388 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
42389 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
42390 @@ -801,7 +801,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
42391 man->size = size >> PAGE_SHIFT;
42392 }
42393
42394 -static struct vm_operations_struct radeon_ttm_vm_ops;
42395 +static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
42396 static const struct vm_operations_struct *ttm_vm_ops = NULL;
42397
42398 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
42399 @@ -842,8 +842,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
42400 }
42401 if (unlikely(ttm_vm_ops == NULL)) {
42402 ttm_vm_ops = vma->vm_ops;
42403 + pax_open_kernel();
42404 radeon_ttm_vm_ops = *ttm_vm_ops;
42405 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
42406 + pax_close_kernel();
42407 }
42408 vma->vm_ops = &radeon_ttm_vm_ops;
42409 return 0;
42410 diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c
42411 index 6553fd2..aecd29c 100644
42412 --- a/drivers/gpu/drm/tegra/dc.c
42413 +++ b/drivers/gpu/drm/tegra/dc.c
42414 @@ -1243,7 +1243,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
42415 }
42416
42417 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
42418 - dc->debugfs_files[i].data = dc;
42419 + *(void **)&dc->debugfs_files[i].data = dc;
42420
42421 err = drm_debugfs_create_files(dc->debugfs_files,
42422 ARRAY_SIZE(debugfs_files),
42423 diff --git a/drivers/gpu/drm/tegra/dsi.c b/drivers/gpu/drm/tegra/dsi.c
42424 index f787445..2df2c65 100644
42425 --- a/drivers/gpu/drm/tegra/dsi.c
42426 +++ b/drivers/gpu/drm/tegra/dsi.c
42427 @@ -41,7 +41,7 @@ struct tegra_dsi {
42428 struct clk *clk_lp;
42429 struct clk *clk;
42430
42431 - struct drm_info_list *debugfs_files;
42432 + drm_info_list_no_const *debugfs_files;
42433 struct drm_minor *minor;
42434 struct dentry *debugfs;
42435
42436 diff --git a/drivers/gpu/drm/tegra/hdmi.c b/drivers/gpu/drm/tegra/hdmi.c
42437 index ffe2654..03c7b1c 100644
42438 --- a/drivers/gpu/drm/tegra/hdmi.c
42439 +++ b/drivers/gpu/drm/tegra/hdmi.c
42440 @@ -60,7 +60,7 @@ struct tegra_hdmi {
42441 bool stereo;
42442 bool dvi;
42443
42444 - struct drm_info_list *debugfs_files;
42445 + drm_info_list_no_const *debugfs_files;
42446 struct drm_minor *minor;
42447 struct dentry *debugfs;
42448 };
42449 diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
42450 index 9e103a48..0e117f3 100644
42451 --- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
42452 +++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
42453 @@ -147,10 +147,10 @@ static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
42454 }
42455
42456 const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
42457 - ttm_bo_man_init,
42458 - ttm_bo_man_takedown,
42459 - ttm_bo_man_get_node,
42460 - ttm_bo_man_put_node,
42461 - ttm_bo_man_debug
42462 + .init = ttm_bo_man_init,
42463 + .takedown = ttm_bo_man_takedown,
42464 + .get_node = ttm_bo_man_get_node,
42465 + .put_node = ttm_bo_man_put_node,
42466 + .debug = ttm_bo_man_debug
42467 };
42468 EXPORT_SYMBOL(ttm_bo_manager_func);
42469 diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
42470 index dbc2def..0a9f710 100644
42471 --- a/drivers/gpu/drm/ttm/ttm_memory.c
42472 +++ b/drivers/gpu/drm/ttm/ttm_memory.c
42473 @@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
42474 zone->glob = glob;
42475 glob->zone_kernel = zone;
42476 ret = kobject_init_and_add(
42477 - &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
42478 + &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
42479 if (unlikely(ret != 0)) {
42480 kobject_put(&zone->kobj);
42481 return ret;
42482 @@ -347,7 +347,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
42483 zone->glob = glob;
42484 glob->zone_dma32 = zone;
42485 ret = kobject_init_and_add(
42486 - &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
42487 + &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
42488 if (unlikely(ret != 0)) {
42489 kobject_put(&zone->kobj);
42490 return ret;
42491 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
42492 index 09874d6..d6da1de 100644
42493 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
42494 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
42495 @@ -54,7 +54,7 @@
42496
42497 #define NUM_PAGES_TO_ALLOC (PAGE_SIZE/sizeof(struct page *))
42498 #define SMALL_ALLOCATION 16
42499 -#define FREE_ALL_PAGES (~0U)
42500 +#define FREE_ALL_PAGES (~0UL)
42501 /* times are in msecs */
42502 #define PAGE_FREE_INTERVAL 1000
42503
42504 @@ -299,14 +299,13 @@ static void ttm_pool_update_free_locked(struct ttm_page_pool *pool,
42505 * @free_all: If set to true will free all pages in pool
42506 * @gfp: GFP flags.
42507 **/
42508 -static int ttm_page_pool_free(struct ttm_page_pool *pool, unsigned nr_free,
42509 +static unsigned long ttm_page_pool_free(struct ttm_page_pool *pool, unsigned long nr_free,
42510 gfp_t gfp)
42511 {
42512 unsigned long irq_flags;
42513 struct page *p;
42514 struct page **pages_to_free;
42515 - unsigned freed_pages = 0,
42516 - npages_to_free = nr_free;
42517 + unsigned long freed_pages = 0, npages_to_free = nr_free;
42518
42519 if (NUM_PAGES_TO_ALLOC < nr_free)
42520 npages_to_free = NUM_PAGES_TO_ALLOC;
42521 @@ -366,7 +365,8 @@ restart:
42522 __list_del(&p->lru, &pool->list);
42523
42524 ttm_pool_update_free_locked(pool, freed_pages);
42525 - nr_free -= freed_pages;
42526 + if (likely(nr_free != FREE_ALL_PAGES))
42527 + nr_free -= freed_pages;
42528 }
42529
42530 spin_unlock_irqrestore(&pool->lock, irq_flags);
42531 @@ -395,7 +395,7 @@ ttm_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
42532 unsigned i;
42533 unsigned pool_offset;
42534 struct ttm_page_pool *pool;
42535 - int shrink_pages = sc->nr_to_scan;
42536 + unsigned long shrink_pages = sc->nr_to_scan;
42537 unsigned long freed = 0;
42538
42539 if (!mutex_trylock(&lock))
42540 @@ -403,7 +403,7 @@ ttm_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
42541 pool_offset = ++start_pool % NUM_POOLS;
42542 /* select start pool in round robin fashion */
42543 for (i = 0; i < NUM_POOLS; ++i) {
42544 - unsigned nr_free = shrink_pages;
42545 + unsigned long nr_free = shrink_pages;
42546 if (shrink_pages == 0)
42547 break;
42548 pool = &_manager->pools[(i + pool_offset)%NUM_POOLS];
42549 @@ -669,7 +669,7 @@ out:
42550 }
42551
42552 /* Put all pages in pages list to correct pool to wait for reuse */
42553 -static void ttm_put_pages(struct page **pages, unsigned npages, int flags,
42554 +static void ttm_put_pages(struct page **pages, unsigned long npages, int flags,
42555 enum ttm_caching_state cstate)
42556 {
42557 unsigned long irq_flags;
42558 @@ -724,7 +724,7 @@ static int ttm_get_pages(struct page **pages, unsigned npages, int flags,
42559 struct list_head plist;
42560 struct page *p = NULL;
42561 gfp_t gfp_flags = GFP_USER;
42562 - unsigned count;
42563 + unsigned long count;
42564 int r;
42565
42566 /* set zero flag for page allocation if required */
42567 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c b/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
42568 index c96db43..c367557 100644
42569 --- a/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
42570 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
42571 @@ -56,7 +56,7 @@
42572
42573 #define NUM_PAGES_TO_ALLOC (PAGE_SIZE/sizeof(struct page *))
42574 #define SMALL_ALLOCATION 4
42575 -#define FREE_ALL_PAGES (~0U)
42576 +#define FREE_ALL_PAGES (~0UL)
42577 /* times are in msecs */
42578 #define IS_UNDEFINED (0)
42579 #define IS_WC (1<<1)
42580 @@ -413,15 +413,14 @@ static void ttm_dma_page_put(struct dma_pool *pool, struct dma_page *d_page)
42581 * @nr_free: If set to true will free all pages in pool
42582 * @gfp: GFP flags.
42583 **/
42584 -static unsigned ttm_dma_page_pool_free(struct dma_pool *pool, unsigned nr_free,
42585 +static unsigned long ttm_dma_page_pool_free(struct dma_pool *pool, unsigned long nr_free,
42586 gfp_t gfp)
42587 {
42588 unsigned long irq_flags;
42589 struct dma_page *dma_p, *tmp;
42590 struct page **pages_to_free;
42591 struct list_head d_pages;
42592 - unsigned freed_pages = 0,
42593 - npages_to_free = nr_free;
42594 + unsigned long freed_pages = 0, npages_to_free = nr_free;
42595
42596 if (NUM_PAGES_TO_ALLOC < nr_free)
42597 npages_to_free = NUM_PAGES_TO_ALLOC;
42598 @@ -494,7 +493,8 @@ restart:
42599 /* remove range of pages from the pool */
42600 if (freed_pages) {
42601 ttm_pool_update_free_locked(pool, freed_pages);
42602 - nr_free -= freed_pages;
42603 + if (likely(nr_free != FREE_ALL_PAGES))
42604 + nr_free -= freed_pages;
42605 }
42606
42607 spin_unlock_irqrestore(&pool->lock, irq_flags);
42608 @@ -929,7 +929,7 @@ void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev)
42609 struct dma_page *d_page, *next;
42610 enum pool_type type;
42611 bool is_cached = false;
42612 - unsigned count = 0, i, npages = 0;
42613 + unsigned long count = 0, i, npages = 0;
42614 unsigned long irq_flags;
42615
42616 type = ttm_to_type(ttm->page_flags, ttm->caching_state);
42617 @@ -1007,7 +1007,7 @@ ttm_dma_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
42618 static unsigned start_pool;
42619 unsigned idx = 0;
42620 unsigned pool_offset;
42621 - unsigned shrink_pages = sc->nr_to_scan;
42622 + unsigned long shrink_pages = sc->nr_to_scan;
42623 struct device_pools *p;
42624 unsigned long freed = 0;
42625
42626 @@ -1020,7 +1020,7 @@ ttm_dma_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
42627 goto out;
42628 pool_offset = ++start_pool % _manager->npools;
42629 list_for_each_entry(p, &_manager->pools, pools) {
42630 - unsigned nr_free;
42631 + unsigned long nr_free;
42632
42633 if (!p->dev)
42634 continue;
42635 @@ -1034,7 +1034,7 @@ ttm_dma_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
42636 sc->gfp_mask);
42637 freed += nr_free - shrink_pages;
42638
42639 - pr_debug("%s: (%s:%d) Asked to shrink %d, have %d more to go\n",
42640 + pr_debug("%s: (%s:%d) Asked to shrink %lu, have %lu more to go\n",
42641 p->pool->dev_name, p->pool->name, current->pid,
42642 nr_free, shrink_pages);
42643 }
42644 diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
42645 index d1da339..829235e 100644
42646 --- a/drivers/gpu/drm/udl/udl_fb.c
42647 +++ b/drivers/gpu/drm/udl/udl_fb.c
42648 @@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
42649 fb_deferred_io_cleanup(info);
42650 kfree(info->fbdefio);
42651 info->fbdefio = NULL;
42652 - info->fbops->fb_mmap = udl_fb_mmap;
42653 }
42654
42655 pr_warn("released /dev/fb%d user=%d count=%d\n",
42656 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
42657 index ad02732..144f5ed 100644
42658 --- a/drivers/gpu/drm/via/via_drv.h
42659 +++ b/drivers/gpu/drm/via/via_drv.h
42660 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
42661 typedef uint32_t maskarray_t[5];
42662
42663 typedef struct drm_via_irq {
42664 - atomic_t irq_received;
42665 + atomic_unchecked_t irq_received;
42666 uint32_t pending_mask;
42667 uint32_t enable_mask;
42668 wait_queue_head_t irq_queue;
42669 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
42670 struct timeval last_vblank;
42671 int last_vblank_valid;
42672 unsigned usec_per_vblank;
42673 - atomic_t vbl_received;
42674 + atomic_unchecked_t vbl_received;
42675 drm_via_state_t hc_state;
42676 char pci_buf[VIA_PCI_BUF_SIZE];
42677 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
42678 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
42679 index 1319433..a993b0c 100644
42680 --- a/drivers/gpu/drm/via/via_irq.c
42681 +++ b/drivers/gpu/drm/via/via_irq.c
42682 @@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
42683 if (crtc != 0)
42684 return 0;
42685
42686 - return atomic_read(&dev_priv->vbl_received);
42687 + return atomic_read_unchecked(&dev_priv->vbl_received);
42688 }
42689
42690 irqreturn_t via_driver_irq_handler(int irq, void *arg)
42691 @@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
42692
42693 status = VIA_READ(VIA_REG_INTERRUPT);
42694 if (status & VIA_IRQ_VBLANK_PENDING) {
42695 - atomic_inc(&dev_priv->vbl_received);
42696 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
42697 + atomic_inc_unchecked(&dev_priv->vbl_received);
42698 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
42699 do_gettimeofday(&cur_vblank);
42700 if (dev_priv->last_vblank_valid) {
42701 dev_priv->usec_per_vblank =
42702 @@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
42703 dev_priv->last_vblank = cur_vblank;
42704 dev_priv->last_vblank_valid = 1;
42705 }
42706 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
42707 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
42708 DRM_DEBUG("US per vblank is: %u\n",
42709 dev_priv->usec_per_vblank);
42710 }
42711 @@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
42712
42713 for (i = 0; i < dev_priv->num_irqs; ++i) {
42714 if (status & cur_irq->pending_mask) {
42715 - atomic_inc(&cur_irq->irq_received);
42716 + atomic_inc_unchecked(&cur_irq->irq_received);
42717 wake_up(&cur_irq->irq_queue);
42718 handled = 1;
42719 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
42720 @@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
42721 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
42722 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
42723 masks[irq][4]));
42724 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
42725 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
42726 } else {
42727 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
42728 (((cur_irq_sequence =
42729 - atomic_read(&cur_irq->irq_received)) -
42730 + atomic_read_unchecked(&cur_irq->irq_received)) -
42731 *sequence) <= (1 << 23)));
42732 }
42733 *sequence = cur_irq_sequence;
42734 @@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
42735 }
42736
42737 for (i = 0; i < dev_priv->num_irqs; ++i) {
42738 - atomic_set(&cur_irq->irq_received, 0);
42739 + atomic_set_unchecked(&cur_irq->irq_received, 0);
42740 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
42741 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
42742 init_waitqueue_head(&cur_irq->irq_queue);
42743 @@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
42744 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
42745 case VIA_IRQ_RELATIVE:
42746 irqwait->request.sequence +=
42747 - atomic_read(&cur_irq->irq_received);
42748 + atomic_read_unchecked(&cur_irq->irq_received);
42749 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
42750 case VIA_IRQ_ABSOLUTE:
42751 break;
42752 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
42753 index 99f7317..33a835b 100644
42754 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
42755 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
42756 @@ -447,7 +447,7 @@ struct vmw_private {
42757 * Fencing and IRQs.
42758 */
42759
42760 - atomic_t marker_seq;
42761 + atomic_unchecked_t marker_seq;
42762 wait_queue_head_t fence_queue;
42763 wait_queue_head_t fifo_queue;
42764 int fence_queue_waiters; /* Protected by hw_mutex */
42765 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
42766 index 6eae14d..aa311b3 100644
42767 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
42768 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
42769 @@ -154,7 +154,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
42770 (unsigned int) min,
42771 (unsigned int) fifo->capabilities);
42772
42773 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
42774 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
42775 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
42776 vmw_marker_queue_init(&fifo->marker_queue);
42777 return vmw_fifo_send_fence(dev_priv, &dummy);
42778 @@ -373,7 +373,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
42779 if (reserveable)
42780 iowrite32(bytes, fifo_mem +
42781 SVGA_FIFO_RESERVED);
42782 - return fifo_mem + (next_cmd >> 2);
42783 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
42784 } else {
42785 need_bounce = true;
42786 }
42787 @@ -493,7 +493,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
42788
42789 fm = vmw_fifo_reserve(dev_priv, bytes);
42790 if (unlikely(fm == NULL)) {
42791 - *seqno = atomic_read(&dev_priv->marker_seq);
42792 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
42793 ret = -ENOMEM;
42794 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
42795 false, 3*HZ);
42796 @@ -501,7 +501,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
42797 }
42798
42799 do {
42800 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
42801 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
42802 } while (*seqno == 0);
42803
42804 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
42805 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
42806 index 26f8bdd..90a0008 100644
42807 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
42808 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
42809 @@ -165,9 +165,9 @@ static void vmw_gmrid_man_debug(struct ttm_mem_type_manager *man,
42810 }
42811
42812 const struct ttm_mem_type_manager_func vmw_gmrid_manager_func = {
42813 - vmw_gmrid_man_init,
42814 - vmw_gmrid_man_takedown,
42815 - vmw_gmrid_man_get_node,
42816 - vmw_gmrid_man_put_node,
42817 - vmw_gmrid_man_debug
42818 + .init = vmw_gmrid_man_init,
42819 + .takedown = vmw_gmrid_man_takedown,
42820 + .get_node = vmw_gmrid_man_get_node,
42821 + .put_node = vmw_gmrid_man_put_node,
42822 + .debug = vmw_gmrid_man_debug
42823 };
42824 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
42825 index 37881ec..319065d 100644
42826 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
42827 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
42828 @@ -235,7 +235,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
42829 int ret;
42830
42831 num_clips = arg->num_clips;
42832 - clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
42833 + clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
42834
42835 if (unlikely(num_clips == 0))
42836 return 0;
42837 @@ -318,7 +318,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
42838 int ret;
42839
42840 num_clips = arg->num_clips;
42841 - clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
42842 + clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
42843
42844 if (unlikely(num_clips == 0))
42845 return 0;
42846 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
42847 index 0c42376..6febe77 100644
42848 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
42849 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
42850 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
42851 * emitted. Then the fence is stale and signaled.
42852 */
42853
42854 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
42855 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
42856 > VMW_FENCE_WRAP);
42857
42858 return ret;
42859 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
42860
42861 if (fifo_idle)
42862 down_read(&fifo_state->rwsem);
42863 - signal_seq = atomic_read(&dev_priv->marker_seq);
42864 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
42865 ret = 0;
42866
42867 for (;;) {
42868 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
42869 index efd1ffd..0ae13ca 100644
42870 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
42871 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
42872 @@ -135,7 +135,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
42873 while (!vmw_lag_lt(queue, us)) {
42874 spin_lock(&queue->lock);
42875 if (list_empty(&queue->head))
42876 - seqno = atomic_read(&dev_priv->marker_seq);
42877 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
42878 else {
42879 marker = list_first_entry(&queue->head,
42880 struct vmw_marker, head);
42881 diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
42882 index 37ac7b5..d52a5c9 100644
42883 --- a/drivers/gpu/vga/vga_switcheroo.c
42884 +++ b/drivers/gpu/vga/vga_switcheroo.c
42885 @@ -644,7 +644,7 @@ static int vga_switcheroo_runtime_resume(struct device *dev)
42886
42887 /* this version is for the case where the power switch is separate
42888 to the device being powered down. */
42889 -int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain)
42890 +int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain)
42891 {
42892 /* copy over all the bus versions */
42893 if (dev->bus && dev->bus->pm) {
42894 @@ -695,7 +695,7 @@ static int vga_switcheroo_runtime_resume_hdmi_audio(struct device *dev)
42895 return ret;
42896 }
42897
42898 -int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain)
42899 +int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain)
42900 {
42901 /* copy over all the bus versions */
42902 if (dev->bus && dev->bus->pm) {
42903 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
42904 index 12b6e67..ddd983c 100644
42905 --- a/drivers/hid/hid-core.c
42906 +++ b/drivers/hid/hid-core.c
42907 @@ -2500,7 +2500,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
42908
42909 int hid_add_device(struct hid_device *hdev)
42910 {
42911 - static atomic_t id = ATOMIC_INIT(0);
42912 + static atomic_unchecked_t id = ATOMIC_INIT(0);
42913 int ret;
42914
42915 if (WARN_ON(hdev->status & HID_STAT_ADDED))
42916 @@ -2542,7 +2542,7 @@ int hid_add_device(struct hid_device *hdev)
42917 /* XXX hack, any other cleaner solution after the driver core
42918 * is converted to allow more than 20 bytes as the device name? */
42919 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
42920 - hdev->vendor, hdev->product, atomic_inc_return(&id));
42921 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
42922
42923 hid_debug_register(hdev, dev_name(&hdev->dev));
42924 ret = device_add(&hdev->dev);
42925 diff --git a/drivers/hid/hid-logitech-dj.c b/drivers/hid/hid-logitech-dj.c
42926 index 9bf8637..f462416 100644
42927 --- a/drivers/hid/hid-logitech-dj.c
42928 +++ b/drivers/hid/hid-logitech-dj.c
42929 @@ -682,6 +682,12 @@ static int logi_dj_raw_event(struct hid_device *hdev,
42930 * device (via hid_input_report() ) and return 1 so hid-core does not do
42931 * anything else with it.
42932 */
42933 + if ((dj_report->device_index < DJ_DEVICE_INDEX_MIN) ||
42934 + (dj_report->device_index > DJ_DEVICE_INDEX_MAX)) {
42935 + dev_err(&hdev->dev, "%s: invalid device index:%d\n",
42936 + __func__, dj_report->device_index);
42937 + return false;
42938 + }
42939
42940 /* case 1) */
42941 if (data[0] != REPORT_ID_DJ_SHORT)
42942 diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c
42943 index c372368..ecb9d90 100644
42944 --- a/drivers/hid/hid-sony.c
42945 +++ b/drivers/hid/hid-sony.c
42946 @@ -797,6 +797,12 @@ union sixaxis_output_report_01 {
42947 __u8 buf[36];
42948 };
42949
42950 +#define DS4_REPORT_0x02_SIZE 37
42951 +#define DS4_REPORT_0x05_SIZE 32
42952 +#define DS4_REPORT_0x11_SIZE 78
42953 +#define DS4_REPORT_0x81_SIZE 7
42954 +#define SIXAXIS_REPORT_0xF2_SIZE 18
42955 +
42956 static spinlock_t sony_dev_list_lock;
42957 static LIST_HEAD(sony_device_list);
42958 static DEFINE_IDA(sony_device_id_allocator);
42959 @@ -810,6 +816,7 @@ struct sony_sc {
42960 struct work_struct state_worker;
42961 struct power_supply battery;
42962 int device_id;
42963 + __u8 *output_report_dmabuf;
42964
42965 #ifdef CONFIG_SONY_FF
42966 __u8 left;
42967 @@ -1108,9 +1115,20 @@ static int sixaxis_set_operational_usb(struct hid_device *hdev)
42968
42969 static int sixaxis_set_operational_bt(struct hid_device *hdev)
42970 {
42971 - unsigned char buf[] = { 0xf4, 0x42, 0x03, 0x00, 0x00 };
42972 - return hid_hw_raw_request(hdev, buf[0], buf, sizeof(buf),
42973 + static const __u8 report[] = { 0xf4, 0x42, 0x03, 0x00, 0x00 };
42974 + __u8 *buf;
42975 + int ret;
42976 +
42977 + buf = kmemdup(report, sizeof(report), GFP_KERNEL);
42978 + if (!buf)
42979 + return -ENOMEM;
42980 +
42981 + ret = hid_hw_raw_request(hdev, buf[0], buf, sizeof(report),
42982 HID_FEATURE_REPORT, HID_REQ_SET_REPORT);
42983 +
42984 + kfree(buf);
42985 +
42986 + return ret;
42987 }
42988
42989 /*
42990 @@ -1119,10 +1137,19 @@ static int sixaxis_set_operational_bt(struct hid_device *hdev)
42991 */
42992 static int dualshock4_set_operational_bt(struct hid_device *hdev)
42993 {
42994 - __u8 buf[37] = { 0 };
42995 + __u8 *buf;
42996 + int ret;
42997
42998 - return hid_hw_raw_request(hdev, 0x02, buf, sizeof(buf),
42999 + buf = kmalloc(DS4_REPORT_0x02_SIZE, GFP_KERNEL);
43000 + if (!buf)
43001 + return -ENOMEM;
43002 +
43003 + ret = hid_hw_raw_request(hdev, 0x02, buf, DS4_REPORT_0x02_SIZE,
43004 HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
43005 +
43006 + kfree(buf);
43007 +
43008 + return ret;
43009 }
43010
43011 static void sixaxis_set_leds_from_id(int id, __u8 values[MAX_LEDS])
43012 @@ -1437,9 +1464,7 @@ error_leds:
43013
43014 static void sixaxis_state_worker(struct work_struct *work)
43015 {
43016 - struct sony_sc *sc = container_of(work, struct sony_sc, state_worker);
43017 - int n;
43018 - union sixaxis_output_report_01 report = {
43019 + static const union sixaxis_output_report_01 default_report = {
43020 .buf = {
43021 0x01,
43022 0x00, 0xff, 0x00, 0xff, 0x00,
43023 @@ -1451,20 +1476,27 @@ static void sixaxis_state_worker(struct work_struct *work)
43024 0x00, 0x00, 0x00, 0x00, 0x00
43025 }
43026 };
43027 + struct sony_sc *sc = container_of(work, struct sony_sc, state_worker);
43028 + struct sixaxis_output_report *report =
43029 + (struct sixaxis_output_report *)sc->output_report_dmabuf;
43030 + int n;
43031 +
43032 + /* Initialize the report with default values */
43033 + memcpy(report, &default_report, sizeof(struct sixaxis_output_report));
43034
43035 #ifdef CONFIG_SONY_FF
43036 - report.data.rumble.right_motor_on = sc->right ? 1 : 0;
43037 - report.data.rumble.left_motor_force = sc->left;
43038 + report->rumble.right_motor_on = sc->right ? 1 : 0;
43039 + report->rumble.left_motor_force = sc->left;
43040 #endif
43041
43042 - report.data.leds_bitmap |= sc->led_state[0] << 1;
43043 - report.data.leds_bitmap |= sc->led_state[1] << 2;
43044 - report.data.leds_bitmap |= sc->led_state[2] << 3;
43045 - report.data.leds_bitmap |= sc->led_state[3] << 4;
43046 + report->leds_bitmap |= sc->led_state[0] << 1;
43047 + report->leds_bitmap |= sc->led_state[1] << 2;
43048 + report->leds_bitmap |= sc->led_state[2] << 3;
43049 + report->leds_bitmap |= sc->led_state[3] << 4;
43050
43051 /* Set flag for all leds off, required for 3rd party INTEC controller */
43052 - if ((report.data.leds_bitmap & 0x1E) == 0)
43053 - report.data.leds_bitmap |= 0x20;
43054 + if ((report->leds_bitmap & 0x1E) == 0)
43055 + report->leds_bitmap |= 0x20;
43056
43057 /*
43058 * The LEDs in the report are indexed in reverse order to their
43059 @@ -1477,28 +1509,30 @@ static void sixaxis_state_worker(struct work_struct *work)
43060 */
43061 for (n = 0; n < 4; n++) {
43062 if (sc->led_delay_on[n] || sc->led_delay_off[n]) {
43063 - report.data.led[3 - n].duty_off = sc->led_delay_off[n];
43064 - report.data.led[3 - n].duty_on = sc->led_delay_on[n];
43065 + report->led[3 - n].duty_off = sc->led_delay_off[n];
43066 + report->led[3 - n].duty_on = sc->led_delay_on[n];
43067 }
43068 }
43069
43070 - hid_hw_raw_request(sc->hdev, report.data.report_id, report.buf,
43071 - sizeof(report), HID_OUTPUT_REPORT, HID_REQ_SET_REPORT);
43072 + hid_hw_raw_request(sc->hdev, report->report_id, (__u8 *)report,
43073 + sizeof(struct sixaxis_output_report),
43074 + HID_OUTPUT_REPORT, HID_REQ_SET_REPORT);
43075 }
43076
43077 static void dualshock4_state_worker(struct work_struct *work)
43078 {
43079 struct sony_sc *sc = container_of(work, struct sony_sc, state_worker);
43080 struct hid_device *hdev = sc->hdev;
43081 + __u8 *buf = sc->output_report_dmabuf;
43082 int offset;
43083
43084 - __u8 buf[78] = { 0 };
43085 -
43086 if (sc->quirks & DUALSHOCK4_CONTROLLER_USB) {
43087 + memset(buf, 0, DS4_REPORT_0x05_SIZE);
43088 buf[0] = 0x05;
43089 buf[1] = 0xFF;
43090 offset = 4;
43091 } else {
43092 + memset(buf, 0, DS4_REPORT_0x11_SIZE);
43093 buf[0] = 0x11;
43094 buf[1] = 0xB0;
43095 buf[3] = 0x0F;
43096 @@ -1526,12 +1560,33 @@ static void dualshock4_state_worker(struct work_struct *work)
43097 buf[offset++] = sc->led_delay_off[3];
43098
43099 if (sc->quirks & DUALSHOCK4_CONTROLLER_USB)
43100 - hid_hw_output_report(hdev, buf, 32);
43101 + hid_hw_output_report(hdev, buf, DS4_REPORT_0x05_SIZE);
43102 else
43103 - hid_hw_raw_request(hdev, 0x11, buf, 78,
43104 + hid_hw_raw_request(hdev, 0x11, buf, DS4_REPORT_0x11_SIZE,
43105 HID_OUTPUT_REPORT, HID_REQ_SET_REPORT);
43106 }
43107
43108 +static int sony_allocate_output_report(struct sony_sc *sc)
43109 +{
43110 + if (sc->quirks & SIXAXIS_CONTROLLER)
43111 + sc->output_report_dmabuf =
43112 + kmalloc(sizeof(union sixaxis_output_report_01),
43113 + GFP_KERNEL);
43114 + else if (sc->quirks & DUALSHOCK4_CONTROLLER_BT)
43115 + sc->output_report_dmabuf = kmalloc(DS4_REPORT_0x11_SIZE,
43116 + GFP_KERNEL);
43117 + else if (sc->quirks & DUALSHOCK4_CONTROLLER_USB)
43118 + sc->output_report_dmabuf = kmalloc(DS4_REPORT_0x05_SIZE,
43119 + GFP_KERNEL);
43120 + else
43121 + return 0;
43122 +
43123 + if (!sc->output_report_dmabuf)
43124 + return -ENOMEM;
43125 +
43126 + return 0;
43127 +}
43128 +
43129 #ifdef CONFIG_SONY_FF
43130 static int sony_play_effect(struct input_dev *dev, void *data,
43131 struct ff_effect *effect)
43132 @@ -1740,6 +1795,7 @@ static int sony_get_bt_devaddr(struct sony_sc *sc)
43133
43134 static int sony_check_add(struct sony_sc *sc)
43135 {
43136 + __u8 *buf = NULL;
43137 int n, ret;
43138
43139 if ((sc->quirks & DUALSHOCK4_CONTROLLER_BT) ||
43140 @@ -1755,36 +1811,44 @@ static int sony_check_add(struct sony_sc *sc)
43141 return 0;
43142 }
43143 } else if (sc->quirks & DUALSHOCK4_CONTROLLER_USB) {
43144 - __u8 buf[7];
43145 + buf = kmalloc(DS4_REPORT_0x81_SIZE, GFP_KERNEL);
43146 + if (!buf)
43147 + return -ENOMEM;
43148
43149 /*
43150 * The MAC address of a DS4 controller connected via USB can be
43151 * retrieved with feature report 0x81. The address begins at
43152 * offset 1.
43153 */
43154 - ret = hid_hw_raw_request(sc->hdev, 0x81, buf, sizeof(buf),
43155 - HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
43156 + ret = hid_hw_raw_request(sc->hdev, 0x81, buf,
43157 + DS4_REPORT_0x81_SIZE, HID_FEATURE_REPORT,
43158 + HID_REQ_GET_REPORT);
43159
43160 - if (ret != 7) {
43161 + if (ret != DS4_REPORT_0x81_SIZE) {
43162 hid_err(sc->hdev, "failed to retrieve feature report 0x81 with the DualShock 4 MAC address\n");
43163 - return ret < 0 ? ret : -EINVAL;
43164 + ret = ret < 0 ? ret : -EINVAL;
43165 + goto out_free;
43166 }
43167
43168 memcpy(sc->mac_address, &buf[1], sizeof(sc->mac_address));
43169 } else if (sc->quirks & SIXAXIS_CONTROLLER_USB) {
43170 - __u8 buf[18];
43171 + buf = kmalloc(SIXAXIS_REPORT_0xF2_SIZE, GFP_KERNEL);
43172 + if (!buf)
43173 + return -ENOMEM;
43174
43175 /*
43176 * The MAC address of a Sixaxis controller connected via USB can
43177 * be retrieved with feature report 0xf2. The address begins at
43178 * offset 4.
43179 */
43180 - ret = hid_hw_raw_request(sc->hdev, 0xf2, buf, sizeof(buf),
43181 - HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
43182 + ret = hid_hw_raw_request(sc->hdev, 0xf2, buf,
43183 + SIXAXIS_REPORT_0xF2_SIZE, HID_FEATURE_REPORT,
43184 + HID_REQ_GET_REPORT);
43185
43186 - if (ret != 18) {
43187 + if (ret != SIXAXIS_REPORT_0xF2_SIZE) {
43188 hid_err(sc->hdev, "failed to retrieve feature report 0xf2 with the Sixaxis MAC address\n");
43189 - return ret < 0 ? ret : -EINVAL;
43190 + ret = ret < 0 ? ret : -EINVAL;
43191 + goto out_free;
43192 }
43193
43194 /*
43195 @@ -1797,7 +1861,13 @@ static int sony_check_add(struct sony_sc *sc)
43196 return 0;
43197 }
43198
43199 - return sony_check_add_dev_list(sc);
43200 + ret = sony_check_add_dev_list(sc);
43201 +
43202 +out_free:
43203 +
43204 + kfree(buf);
43205 +
43206 + return ret;
43207 }
43208
43209 static int sony_set_device_id(struct sony_sc *sc)
43210 @@ -1881,6 +1951,12 @@ static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id)
43211 return ret;
43212 }
43213
43214 + ret = sony_allocate_output_report(sc);
43215 + if (ret < 0) {
43216 + hid_err(hdev, "failed to allocate the output report buffer\n");
43217 + goto err_stop;
43218 + }
43219 +
43220 ret = sony_set_device_id(sc);
43221 if (ret < 0) {
43222 hid_err(hdev, "failed to allocate the device id\n");
43223 @@ -1977,6 +2053,7 @@ err_stop:
43224 if (sc->quirks & SONY_BATTERY_SUPPORT)
43225 sony_battery_remove(sc);
43226 sony_cancel_work_sync(sc);
43227 + kfree(sc->output_report_dmabuf);
43228 sony_remove_dev_list(sc);
43229 sony_release_device_id(sc);
43230 hid_hw_stop(hdev);
43231 @@ -1997,6 +2074,8 @@ static void sony_remove(struct hid_device *hdev)
43232
43233 sony_cancel_work_sync(sc);
43234
43235 + kfree(sc->output_report_dmabuf);
43236 +
43237 sony_remove_dev_list(sc);
43238
43239 sony_release_device_id(sc);
43240 diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
43241 index c13fb5b..55a3802 100644
43242 --- a/drivers/hid/hid-wiimote-debug.c
43243 +++ b/drivers/hid/hid-wiimote-debug.c
43244 @@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
43245 else if (size == 0)
43246 return -EIO;
43247
43248 - if (copy_to_user(u, buf, size))
43249 + if (size > sizeof(buf) || copy_to_user(u, buf, size))
43250 return -EFAULT;
43251
43252 *off += size;
43253 diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
43254 index 0cb92e3..c7d453d 100644
43255 --- a/drivers/hid/uhid.c
43256 +++ b/drivers/hid/uhid.c
43257 @@ -47,7 +47,7 @@ struct uhid_device {
43258 struct mutex report_lock;
43259 wait_queue_head_t report_wait;
43260 atomic_t report_done;
43261 - atomic_t report_id;
43262 + atomic_unchecked_t report_id;
43263 struct uhid_event report_buf;
43264 };
43265
43266 @@ -163,7 +163,7 @@ static int uhid_hid_get_raw(struct hid_device *hid, unsigned char rnum,
43267
43268 spin_lock_irqsave(&uhid->qlock, flags);
43269 ev->type = UHID_FEATURE;
43270 - ev->u.feature.id = atomic_inc_return(&uhid->report_id);
43271 + ev->u.feature.id = atomic_inc_return_unchecked(&uhid->report_id);
43272 ev->u.feature.rnum = rnum;
43273 ev->u.feature.rtype = report_type;
43274
43275 @@ -538,7 +538,7 @@ static int uhid_dev_feature_answer(struct uhid_device *uhid,
43276 spin_lock_irqsave(&uhid->qlock, flags);
43277
43278 /* id for old report; drop it silently */
43279 - if (atomic_read(&uhid->report_id) != ev->u.feature_answer.id)
43280 + if (atomic_read_unchecked(&uhid->report_id) != ev->u.feature_answer.id)
43281 goto unlock;
43282 if (atomic_read(&uhid->report_done))
43283 goto unlock;
43284 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
43285 index 19bad59..ca24eaf 100644
43286 --- a/drivers/hv/channel.c
43287 +++ b/drivers/hv/channel.c
43288 @@ -366,8 +366,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
43289 unsigned long flags;
43290 int ret = 0;
43291
43292 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
43293 - atomic_inc(&vmbus_connection.next_gpadl_handle);
43294 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
43295 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
43296
43297 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
43298 if (ret)
43299 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
43300 index 3e4235c..877d0e5 100644
43301 --- a/drivers/hv/hv.c
43302 +++ b/drivers/hv/hv.c
43303 @@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
43304 u64 output_address = (output) ? virt_to_phys(output) : 0;
43305 u32 output_address_hi = output_address >> 32;
43306 u32 output_address_lo = output_address & 0xFFFFFFFF;
43307 - void *hypercall_page = hv_context.hypercall_page;
43308 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
43309
43310 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
43311 "=a"(hv_status_lo) : "d" (control_hi),
43312 @@ -156,7 +156,7 @@ int hv_init(void)
43313 /* See if the hypercall page is already set */
43314 rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
43315
43316 - virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_EXEC);
43317 + virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_RX);
43318
43319 if (!virtaddr)
43320 goto cleanup;
43321 diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
43322 index 5e90c5d..d8fcefb 100644
43323 --- a/drivers/hv/hv_balloon.c
43324 +++ b/drivers/hv/hv_balloon.c
43325 @@ -470,7 +470,7 @@ MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add");
43326
43327 module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
43328 MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
43329 -static atomic_t trans_id = ATOMIC_INIT(0);
43330 +static atomic_unchecked_t trans_id = ATOMIC_INIT(0);
43331
43332 static int dm_ring_size = (5 * PAGE_SIZE);
43333
43334 @@ -893,7 +893,7 @@ static void hot_add_req(struct work_struct *dummy)
43335 pr_info("Memory hot add failed\n");
43336
43337 dm->state = DM_INITIALIZED;
43338 - resp.hdr.trans_id = atomic_inc_return(&trans_id);
43339 + resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
43340 vmbus_sendpacket(dm->dev->channel, &resp,
43341 sizeof(struct dm_hot_add_response),
43342 (unsigned long)NULL,
43343 @@ -973,7 +973,7 @@ static void post_status(struct hv_dynmem_device *dm)
43344 memset(&status, 0, sizeof(struct dm_status));
43345 status.hdr.type = DM_STATUS_REPORT;
43346 status.hdr.size = sizeof(struct dm_status);
43347 - status.hdr.trans_id = atomic_inc_return(&trans_id);
43348 + status.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
43349
43350 /*
43351 * The host expects the guest to report free memory.
43352 @@ -993,7 +993,7 @@ static void post_status(struct hv_dynmem_device *dm)
43353 * send the status. This can happen if we were interrupted
43354 * after we picked our transaction ID.
43355 */
43356 - if (status.hdr.trans_id != atomic_read(&trans_id))
43357 + if (status.hdr.trans_id != atomic_read_unchecked(&trans_id))
43358 return;
43359
43360 /*
43361 @@ -1129,7 +1129,7 @@ static void balloon_up(struct work_struct *dummy)
43362 */
43363
43364 do {
43365 - bl_resp->hdr.trans_id = atomic_inc_return(&trans_id);
43366 + bl_resp->hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
43367 ret = vmbus_sendpacket(dm_device.dev->channel,
43368 bl_resp,
43369 bl_resp->hdr.size,
43370 @@ -1175,7 +1175,7 @@ static void balloon_down(struct hv_dynmem_device *dm,
43371
43372 memset(&resp, 0, sizeof(struct dm_unballoon_response));
43373 resp.hdr.type = DM_UNBALLOON_RESPONSE;
43374 - resp.hdr.trans_id = atomic_inc_return(&trans_id);
43375 + resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
43376 resp.hdr.size = sizeof(struct dm_unballoon_response);
43377
43378 vmbus_sendpacket(dm_device.dev->channel, &resp,
43379 @@ -1239,7 +1239,7 @@ static void version_resp(struct hv_dynmem_device *dm,
43380 memset(&version_req, 0, sizeof(struct dm_version_request));
43381 version_req.hdr.type = DM_VERSION_REQUEST;
43382 version_req.hdr.size = sizeof(struct dm_version_request);
43383 - version_req.hdr.trans_id = atomic_inc_return(&trans_id);
43384 + version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
43385 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN7;
43386 version_req.is_last_attempt = 1;
43387
43388 @@ -1409,7 +1409,7 @@ static int balloon_probe(struct hv_device *dev,
43389 memset(&version_req, 0, sizeof(struct dm_version_request));
43390 version_req.hdr.type = DM_VERSION_REQUEST;
43391 version_req.hdr.size = sizeof(struct dm_version_request);
43392 - version_req.hdr.trans_id = atomic_inc_return(&trans_id);
43393 + version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
43394 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN8;
43395 version_req.is_last_attempt = 0;
43396
43397 @@ -1440,7 +1440,7 @@ static int balloon_probe(struct hv_device *dev,
43398 memset(&cap_msg, 0, sizeof(struct dm_capabilities));
43399 cap_msg.hdr.type = DM_CAPABILITIES_REPORT;
43400 cap_msg.hdr.size = sizeof(struct dm_capabilities);
43401 - cap_msg.hdr.trans_id = atomic_inc_return(&trans_id);
43402 + cap_msg.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
43403
43404 cap_msg.caps.cap_bits.balloon = 1;
43405 cap_msg.caps.cap_bits.hot_add = 1;
43406 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
43407 index c386d8d..d6004c4 100644
43408 --- a/drivers/hv/hyperv_vmbus.h
43409 +++ b/drivers/hv/hyperv_vmbus.h
43410 @@ -611,7 +611,7 @@ enum vmbus_connect_state {
43411 struct vmbus_connection {
43412 enum vmbus_connect_state conn_state;
43413
43414 - atomic_t next_gpadl_handle;
43415 + atomic_unchecked_t next_gpadl_handle;
43416
43417 /*
43418 * Represents channel interrupts. Each bit position represents a
43419 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
43420 index 4d6b269..2e23b86 100644
43421 --- a/drivers/hv/vmbus_drv.c
43422 +++ b/drivers/hv/vmbus_drv.c
43423 @@ -807,10 +807,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
43424 {
43425 int ret = 0;
43426
43427 - static atomic_t device_num = ATOMIC_INIT(0);
43428 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
43429
43430 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
43431 - atomic_inc_return(&device_num));
43432 + atomic_inc_return_unchecked(&device_num));
43433
43434 child_device_obj->device.bus = &hv_bus;
43435 child_device_obj->device.parent = &hv_acpi_dev->dev;
43436 diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
43437 index 579bdf9..75118b5 100644
43438 --- a/drivers/hwmon/acpi_power_meter.c
43439 +++ b/drivers/hwmon/acpi_power_meter.c
43440 @@ -116,7 +116,7 @@ struct sensor_template {
43441 struct device_attribute *devattr,
43442 const char *buf, size_t count);
43443 int index;
43444 -};
43445 +} __do_const;
43446
43447 /* Averaging interval */
43448 static int update_avg_interval(struct acpi_power_meter_resource *resource)
43449 @@ -631,7 +631,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
43450 struct sensor_template *attrs)
43451 {
43452 struct device *dev = &resource->acpi_dev->dev;
43453 - struct sensor_device_attribute *sensors =
43454 + sensor_device_attribute_no_const *sensors =
43455 &resource->sensors[resource->num_sensors];
43456 int res = 0;
43457
43458 diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
43459 index 3288f13..71cfb4e 100644
43460 --- a/drivers/hwmon/applesmc.c
43461 +++ b/drivers/hwmon/applesmc.c
43462 @@ -1106,7 +1106,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
43463 {
43464 struct applesmc_node_group *grp;
43465 struct applesmc_dev_attr *node;
43466 - struct attribute *attr;
43467 + attribute_no_const *attr;
43468 int ret, i;
43469
43470 for (grp = groups; grp->format; grp++) {
43471 diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
43472 index cccef87..06ce8ec 100644
43473 --- a/drivers/hwmon/asus_atk0110.c
43474 +++ b/drivers/hwmon/asus_atk0110.c
43475 @@ -147,10 +147,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
43476 struct atk_sensor_data {
43477 struct list_head list;
43478 struct atk_data *data;
43479 - struct device_attribute label_attr;
43480 - struct device_attribute input_attr;
43481 - struct device_attribute limit1_attr;
43482 - struct device_attribute limit2_attr;
43483 + device_attribute_no_const label_attr;
43484 + device_attribute_no_const input_attr;
43485 + device_attribute_no_const limit1_attr;
43486 + device_attribute_no_const limit2_attr;
43487 char label_attr_name[ATTR_NAME_SIZE];
43488 char input_attr_name[ATTR_NAME_SIZE];
43489 char limit1_attr_name[ATTR_NAME_SIZE];
43490 @@ -270,7 +270,7 @@ static ssize_t atk_name_show(struct device *dev,
43491 static struct device_attribute atk_name_attr =
43492 __ATTR(name, 0444, atk_name_show, NULL);
43493
43494 -static void atk_init_attribute(struct device_attribute *attr, char *name,
43495 +static void atk_init_attribute(device_attribute_no_const *attr, char *name,
43496 sysfs_show_func show)
43497 {
43498 sysfs_attr_init(&attr->attr);
43499 diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
43500 index d76f0b7..55ae976 100644
43501 --- a/drivers/hwmon/coretemp.c
43502 +++ b/drivers/hwmon/coretemp.c
43503 @@ -784,7 +784,7 @@ static int coretemp_cpu_callback(struct notifier_block *nfb,
43504 return NOTIFY_OK;
43505 }
43506
43507 -static struct notifier_block coretemp_cpu_notifier __refdata = {
43508 +static struct notifier_block coretemp_cpu_notifier = {
43509 .notifier_call = coretemp_cpu_callback,
43510 };
43511
43512 diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
43513 index 7a8a6fb..015c1fd 100644
43514 --- a/drivers/hwmon/ibmaem.c
43515 +++ b/drivers/hwmon/ibmaem.c
43516 @@ -924,7 +924,7 @@ static int aem_register_sensors(struct aem_data *data,
43517 struct aem_rw_sensor_template *rw)
43518 {
43519 struct device *dev = &data->pdev->dev;
43520 - struct sensor_device_attribute *sensors = data->sensors;
43521 + sensor_device_attribute_no_const *sensors = data->sensors;
43522 int err;
43523
43524 /* Set up read-only sensors */
43525 diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
43526 index 14c82da..09b25d7 100644
43527 --- a/drivers/hwmon/iio_hwmon.c
43528 +++ b/drivers/hwmon/iio_hwmon.c
43529 @@ -61,7 +61,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
43530 {
43531 struct device *dev = &pdev->dev;
43532 struct iio_hwmon_state *st;
43533 - struct sensor_device_attribute *a;
43534 + sensor_device_attribute_no_const *a;
43535 int ret, i;
43536 int in_i = 1, temp_i = 1, curr_i = 1;
43537 enum iio_chan_type type;
43538 diff --git a/drivers/hwmon/nct6683.c b/drivers/hwmon/nct6683.c
43539 index 7710f46..427a28d 100644
43540 --- a/drivers/hwmon/nct6683.c
43541 +++ b/drivers/hwmon/nct6683.c
43542 @@ -397,11 +397,11 @@ static struct attribute_group *
43543 nct6683_create_attr_group(struct device *dev, struct sensor_template_group *tg,
43544 int repeat)
43545 {
43546 - struct sensor_device_attribute_2 *a2;
43547 - struct sensor_device_attribute *a;
43548 + sensor_device_attribute_2_no_const *a2;
43549 + sensor_device_attribute_no_const *a;
43550 struct sensor_device_template **t;
43551 struct sensor_device_attr_u *su;
43552 - struct attribute_group *group;
43553 + attribute_group_no_const *group;
43554 struct attribute **attrs;
43555 int i, j, count;
43556
43557 diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
43558 index 504cbdd..35d6f25 100644
43559 --- a/drivers/hwmon/nct6775.c
43560 +++ b/drivers/hwmon/nct6775.c
43561 @@ -943,10 +943,10 @@ static struct attribute_group *
43562 nct6775_create_attr_group(struct device *dev, struct sensor_template_group *tg,
43563 int repeat)
43564 {
43565 - struct attribute_group *group;
43566 + attribute_group_no_const *group;
43567 struct sensor_device_attr_u *su;
43568 - struct sensor_device_attribute *a;
43569 - struct sensor_device_attribute_2 *a2;
43570 + sensor_device_attribute_no_const *a;
43571 + sensor_device_attribute_2_no_const *a2;
43572 struct attribute **attrs;
43573 struct sensor_device_template **t;
43574 int i, count;
43575 diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
43576 index 291d11f..3f0dbbd 100644
43577 --- a/drivers/hwmon/pmbus/pmbus_core.c
43578 +++ b/drivers/hwmon/pmbus/pmbus_core.c
43579 @@ -783,7 +783,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
43580 return 0;
43581 }
43582
43583 -static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
43584 +static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
43585 const char *name,
43586 umode_t mode,
43587 ssize_t (*show)(struct device *dev,
43588 @@ -800,7 +800,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
43589 dev_attr->store = store;
43590 }
43591
43592 -static void pmbus_attr_init(struct sensor_device_attribute *a,
43593 +static void pmbus_attr_init(sensor_device_attribute_no_const *a,
43594 const char *name,
43595 umode_t mode,
43596 ssize_t (*show)(struct device *dev,
43597 @@ -822,7 +822,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
43598 u16 reg, u8 mask)
43599 {
43600 struct pmbus_boolean *boolean;
43601 - struct sensor_device_attribute *a;
43602 + sensor_device_attribute_no_const *a;
43603
43604 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
43605 if (!boolean)
43606 @@ -847,7 +847,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
43607 bool update, bool readonly)
43608 {
43609 struct pmbus_sensor *sensor;
43610 - struct device_attribute *a;
43611 + device_attribute_no_const *a;
43612
43613 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
43614 if (!sensor)
43615 @@ -878,7 +878,7 @@ static int pmbus_add_label(struct pmbus_data *data,
43616 const char *lstring, int index)
43617 {
43618 struct pmbus_label *label;
43619 - struct device_attribute *a;
43620 + device_attribute_no_const *a;
43621
43622 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
43623 if (!label)
43624 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
43625 index 97cd45a..ac54d8b 100644
43626 --- a/drivers/hwmon/sht15.c
43627 +++ b/drivers/hwmon/sht15.c
43628 @@ -169,7 +169,7 @@ struct sht15_data {
43629 int supply_uv;
43630 bool supply_uv_valid;
43631 struct work_struct update_supply_work;
43632 - atomic_t interrupt_handled;
43633 + atomic_unchecked_t interrupt_handled;
43634 };
43635
43636 /**
43637 @@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
43638 ret = gpio_direction_input(data->pdata->gpio_data);
43639 if (ret)
43640 return ret;
43641 - atomic_set(&data->interrupt_handled, 0);
43642 + atomic_set_unchecked(&data->interrupt_handled, 0);
43643
43644 enable_irq(gpio_to_irq(data->pdata->gpio_data));
43645 if (gpio_get_value(data->pdata->gpio_data) == 0) {
43646 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
43647 /* Only relevant if the interrupt hasn't occurred. */
43648 - if (!atomic_read(&data->interrupt_handled))
43649 + if (!atomic_read_unchecked(&data->interrupt_handled))
43650 schedule_work(&data->read_work);
43651 }
43652 ret = wait_event_timeout(data->wait_queue,
43653 @@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
43654
43655 /* First disable the interrupt */
43656 disable_irq_nosync(irq);
43657 - atomic_inc(&data->interrupt_handled);
43658 + atomic_inc_unchecked(&data->interrupt_handled);
43659 /* Then schedule a reading work struct */
43660 if (data->state != SHT15_READING_NOTHING)
43661 schedule_work(&data->read_work);
43662 @@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
43663 * If not, then start the interrupt again - care here as could
43664 * have gone low in meantime so verify it hasn't!
43665 */
43666 - atomic_set(&data->interrupt_handled, 0);
43667 + atomic_set_unchecked(&data->interrupt_handled, 0);
43668 enable_irq(gpio_to_irq(data->pdata->gpio_data));
43669 /* If still not occurred or another handler was scheduled */
43670 if (gpio_get_value(data->pdata->gpio_data)
43671 - || atomic_read(&data->interrupt_handled))
43672 + || atomic_read_unchecked(&data->interrupt_handled))
43673 return;
43674 }
43675
43676 diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
43677 index 8df43c5..b07b91d 100644
43678 --- a/drivers/hwmon/via-cputemp.c
43679 +++ b/drivers/hwmon/via-cputemp.c
43680 @@ -296,7 +296,7 @@ static int via_cputemp_cpu_callback(struct notifier_block *nfb,
43681 return NOTIFY_OK;
43682 }
43683
43684 -static struct notifier_block via_cputemp_cpu_notifier __refdata = {
43685 +static struct notifier_block via_cputemp_cpu_notifier = {
43686 .notifier_call = via_cputemp_cpu_callback,
43687 };
43688
43689 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
43690 index 41fc683..a39cfea 100644
43691 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
43692 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
43693 @@ -43,7 +43,7 @@
43694 extern struct i2c_adapter amd756_smbus;
43695
43696 static struct i2c_adapter *s4882_adapter;
43697 -static struct i2c_algorithm *s4882_algo;
43698 +static i2c_algorithm_no_const *s4882_algo;
43699
43700 /* Wrapper access functions for multiplexed SMBus */
43701 static DEFINE_MUTEX(amd756_lock);
43702 diff --git a/drivers/i2c/busses/i2c-diolan-u2c.c b/drivers/i2c/busses/i2c-diolan-u2c.c
43703 index b19a310..d6eece0 100644
43704 --- a/drivers/i2c/busses/i2c-diolan-u2c.c
43705 +++ b/drivers/i2c/busses/i2c-diolan-u2c.c
43706 @@ -98,7 +98,7 @@ MODULE_PARM_DESC(frequency, "I2C clock frequency in hertz");
43707 /* usb layer */
43708
43709 /* Send command to device, and get response. */
43710 -static int diolan_usb_transfer(struct i2c_diolan_u2c *dev)
43711 +static int __intentional_overflow(-1) diolan_usb_transfer(struct i2c_diolan_u2c *dev)
43712 {
43713 int ret = 0;
43714 int actual;
43715 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
43716 index b170bdf..3c76427 100644
43717 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
43718 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
43719 @@ -41,7 +41,7 @@
43720 extern struct i2c_adapter *nforce2_smbus;
43721
43722 static struct i2c_adapter *s4985_adapter;
43723 -static struct i2c_algorithm *s4985_algo;
43724 +static i2c_algorithm_no_const *s4985_algo;
43725
43726 /* Wrapper access functions for multiplexed SMBus */
43727 static DEFINE_MUTEX(nforce2_lock);
43728 diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
43729 index 80b47e8..1a6040d9 100644
43730 --- a/drivers/i2c/i2c-dev.c
43731 +++ b/drivers/i2c/i2c-dev.c
43732 @@ -277,7 +277,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
43733 break;
43734 }
43735
43736 - data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
43737 + data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
43738 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
43739 if (IS_ERR(rdwr_pa[i].buf)) {
43740 res = PTR_ERR(rdwr_pa[i].buf);
43741 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
43742 index 0b510ba..4fbb5085 100644
43743 --- a/drivers/ide/ide-cd.c
43744 +++ b/drivers/ide/ide-cd.c
43745 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
43746 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
43747 if ((unsigned long)buf & alignment
43748 || blk_rq_bytes(rq) & q->dma_pad_mask
43749 - || object_is_on_stack(buf))
43750 + || object_starts_on_stack(buf))
43751 drive->dma = 0;
43752 }
43753 }
43754 diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
43755 index af3e76d..96dfe5e 100644
43756 --- a/drivers/iio/industrialio-core.c
43757 +++ b/drivers/iio/industrialio-core.c
43758 @@ -555,7 +555,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
43759 }
43760
43761 static
43762 -int __iio_device_attr_init(struct device_attribute *dev_attr,
43763 +int __iio_device_attr_init(device_attribute_no_const *dev_attr,
43764 const char *postfix,
43765 struct iio_chan_spec const *chan,
43766 ssize_t (*readfunc)(struct device *dev,
43767 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
43768 index e28a494..f7c2671 100644
43769 --- a/drivers/infiniband/core/cm.c
43770 +++ b/drivers/infiniband/core/cm.c
43771 @@ -115,7 +115,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
43772
43773 struct cm_counter_group {
43774 struct kobject obj;
43775 - atomic_long_t counter[CM_ATTR_COUNT];
43776 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
43777 };
43778
43779 struct cm_counter_attribute {
43780 @@ -1398,7 +1398,7 @@ static void cm_dup_req_handler(struct cm_work *work,
43781 struct ib_mad_send_buf *msg = NULL;
43782 int ret;
43783
43784 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43785 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43786 counter[CM_REQ_COUNTER]);
43787
43788 /* Quick state check to discard duplicate REQs. */
43789 @@ -1785,7 +1785,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
43790 if (!cm_id_priv)
43791 return;
43792
43793 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43794 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43795 counter[CM_REP_COUNTER]);
43796 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
43797 if (ret)
43798 @@ -1952,7 +1952,7 @@ static int cm_rtu_handler(struct cm_work *work)
43799 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
43800 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
43801 spin_unlock_irq(&cm_id_priv->lock);
43802 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43803 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43804 counter[CM_RTU_COUNTER]);
43805 goto out;
43806 }
43807 @@ -2135,7 +2135,7 @@ static int cm_dreq_handler(struct cm_work *work)
43808 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
43809 dreq_msg->local_comm_id);
43810 if (!cm_id_priv) {
43811 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43812 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43813 counter[CM_DREQ_COUNTER]);
43814 cm_issue_drep(work->port, work->mad_recv_wc);
43815 return -EINVAL;
43816 @@ -2160,7 +2160,7 @@ static int cm_dreq_handler(struct cm_work *work)
43817 case IB_CM_MRA_REP_RCVD:
43818 break;
43819 case IB_CM_TIMEWAIT:
43820 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43821 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43822 counter[CM_DREQ_COUNTER]);
43823 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
43824 goto unlock;
43825 @@ -2174,7 +2174,7 @@ static int cm_dreq_handler(struct cm_work *work)
43826 cm_free_msg(msg);
43827 goto deref;
43828 case IB_CM_DREQ_RCVD:
43829 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43830 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43831 counter[CM_DREQ_COUNTER]);
43832 goto unlock;
43833 default:
43834 @@ -2541,7 +2541,7 @@ static int cm_mra_handler(struct cm_work *work)
43835 ib_modify_mad(cm_id_priv->av.port->mad_agent,
43836 cm_id_priv->msg, timeout)) {
43837 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
43838 - atomic_long_inc(&work->port->
43839 + atomic_long_inc_unchecked(&work->port->
43840 counter_group[CM_RECV_DUPLICATES].
43841 counter[CM_MRA_COUNTER]);
43842 goto out;
43843 @@ -2550,7 +2550,7 @@ static int cm_mra_handler(struct cm_work *work)
43844 break;
43845 case IB_CM_MRA_REQ_RCVD:
43846 case IB_CM_MRA_REP_RCVD:
43847 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43848 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43849 counter[CM_MRA_COUNTER]);
43850 /* fall through */
43851 default:
43852 @@ -2712,7 +2712,7 @@ static int cm_lap_handler(struct cm_work *work)
43853 case IB_CM_LAP_IDLE:
43854 break;
43855 case IB_CM_MRA_LAP_SENT:
43856 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43857 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43858 counter[CM_LAP_COUNTER]);
43859 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
43860 goto unlock;
43861 @@ -2728,7 +2728,7 @@ static int cm_lap_handler(struct cm_work *work)
43862 cm_free_msg(msg);
43863 goto deref;
43864 case IB_CM_LAP_RCVD:
43865 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43866 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43867 counter[CM_LAP_COUNTER]);
43868 goto unlock;
43869 default:
43870 @@ -3012,7 +3012,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
43871 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
43872 if (cur_cm_id_priv) {
43873 spin_unlock_irq(&cm.lock);
43874 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43875 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43876 counter[CM_SIDR_REQ_COUNTER]);
43877 goto out; /* Duplicate message. */
43878 }
43879 @@ -3224,10 +3224,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
43880 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
43881 msg->retries = 1;
43882
43883 - atomic_long_add(1 + msg->retries,
43884 + atomic_long_add_unchecked(1 + msg->retries,
43885 &port->counter_group[CM_XMIT].counter[attr_index]);
43886 if (msg->retries)
43887 - atomic_long_add(msg->retries,
43888 + atomic_long_add_unchecked(msg->retries,
43889 &port->counter_group[CM_XMIT_RETRIES].
43890 counter[attr_index]);
43891
43892 @@ -3437,7 +3437,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
43893 }
43894
43895 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
43896 - atomic_long_inc(&port->counter_group[CM_RECV].
43897 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
43898 counter[attr_id - CM_ATTR_ID_OFFSET]);
43899
43900 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
43901 @@ -3668,7 +3668,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
43902 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
43903
43904 return sprintf(buf, "%ld\n",
43905 - atomic_long_read(&group->counter[cm_attr->index]));
43906 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
43907 }
43908
43909 static const struct sysfs_ops cm_counter_ops = {
43910 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
43911 index 9f5ad7c..588cd84 100644
43912 --- a/drivers/infiniband/core/fmr_pool.c
43913 +++ b/drivers/infiniband/core/fmr_pool.c
43914 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
43915
43916 struct task_struct *thread;
43917
43918 - atomic_t req_ser;
43919 - atomic_t flush_ser;
43920 + atomic_unchecked_t req_ser;
43921 + atomic_unchecked_t flush_ser;
43922
43923 wait_queue_head_t force_wait;
43924 };
43925 @@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
43926 struct ib_fmr_pool *pool = pool_ptr;
43927
43928 do {
43929 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
43930 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
43931 ib_fmr_batch_release(pool);
43932
43933 - atomic_inc(&pool->flush_ser);
43934 + atomic_inc_unchecked(&pool->flush_ser);
43935 wake_up_interruptible(&pool->force_wait);
43936
43937 if (pool->flush_function)
43938 @@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
43939 }
43940
43941 set_current_state(TASK_INTERRUPTIBLE);
43942 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
43943 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
43944 !kthread_should_stop())
43945 schedule();
43946 __set_current_state(TASK_RUNNING);
43947 @@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
43948 pool->dirty_watermark = params->dirty_watermark;
43949 pool->dirty_len = 0;
43950 spin_lock_init(&pool->pool_lock);
43951 - atomic_set(&pool->req_ser, 0);
43952 - atomic_set(&pool->flush_ser, 0);
43953 + atomic_set_unchecked(&pool->req_ser, 0);
43954 + atomic_set_unchecked(&pool->flush_ser, 0);
43955 init_waitqueue_head(&pool->force_wait);
43956
43957 pool->thread = kthread_run(ib_fmr_cleanup_thread,
43958 @@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
43959 }
43960 spin_unlock_irq(&pool->pool_lock);
43961
43962 - serial = atomic_inc_return(&pool->req_ser);
43963 + serial = atomic_inc_return_unchecked(&pool->req_ser);
43964 wake_up_process(pool->thread);
43965
43966 if (wait_event_interruptible(pool->force_wait,
43967 - atomic_read(&pool->flush_ser) - serial >= 0))
43968 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
43969 return -EINTR;
43970
43971 return 0;
43972 @@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
43973 } else {
43974 list_add_tail(&fmr->list, &pool->dirty_list);
43975 if (++pool->dirty_len >= pool->dirty_watermark) {
43976 - atomic_inc(&pool->req_ser);
43977 + atomic_inc_unchecked(&pool->req_ser);
43978 wake_up_process(pool->thread);
43979 }
43980 }
43981 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
43982 index ec7a298..8742e59 100644
43983 --- a/drivers/infiniband/hw/cxgb4/mem.c
43984 +++ b/drivers/infiniband/hw/cxgb4/mem.c
43985 @@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
43986 int err;
43987 struct fw_ri_tpte tpt;
43988 u32 stag_idx;
43989 - static atomic_t key;
43990 + static atomic_unchecked_t key;
43991
43992 if (c4iw_fatal_error(rdev))
43993 return -EIO;
43994 @@ -270,7 +270,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
43995 if (rdev->stats.stag.cur > rdev->stats.stag.max)
43996 rdev->stats.stag.max = rdev->stats.stag.cur;
43997 mutex_unlock(&rdev->stats.lock);
43998 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
43999 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
44000 }
44001 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
44002 __func__, stag_state, type, pdid, stag_idx);
44003 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
44004 index 79b3dbc..96e5fcc 100644
44005 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
44006 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
44007 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
44008 struct ib_atomic_eth *ateth;
44009 struct ipath_ack_entry *e;
44010 u64 vaddr;
44011 - atomic64_t *maddr;
44012 + atomic64_unchecked_t *maddr;
44013 u64 sdata;
44014 u32 rkey;
44015 u8 next;
44016 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
44017 IB_ACCESS_REMOTE_ATOMIC)))
44018 goto nack_acc_unlck;
44019 /* Perform atomic OP and save result. */
44020 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
44021 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
44022 sdata = be64_to_cpu(ateth->swap_data);
44023 e = &qp->s_ack_queue[qp->r_head_ack_queue];
44024 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
44025 - (u64) atomic64_add_return(sdata, maddr) - sdata :
44026 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
44027 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
44028 be64_to_cpu(ateth->compare_data),
44029 sdata);
44030 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
44031 index 1f95bba..9530f87 100644
44032 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
44033 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
44034 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
44035 unsigned long flags;
44036 struct ib_wc wc;
44037 u64 sdata;
44038 - atomic64_t *maddr;
44039 + atomic64_unchecked_t *maddr;
44040 enum ib_wc_status send_status;
44041
44042 /*
44043 @@ -382,11 +382,11 @@ again:
44044 IB_ACCESS_REMOTE_ATOMIC)))
44045 goto acc_err;
44046 /* Perform atomic OP and save result. */
44047 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
44048 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
44049 sdata = wqe->wr.wr.atomic.compare_add;
44050 *(u64 *) sqp->s_sge.sge.vaddr =
44051 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
44052 - (u64) atomic64_add_return(sdata, maddr) - sdata :
44053 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
44054 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
44055 sdata, wqe->wr.wr.atomic.swap);
44056 goto send_comp;
44057 diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
44058 index 82a7dd8..8fb6ba6 100644
44059 --- a/drivers/infiniband/hw/mlx4/mad.c
44060 +++ b/drivers/infiniband/hw/mlx4/mad.c
44061 @@ -98,7 +98,7 @@ __be64 mlx4_ib_gen_node_guid(void)
44062
44063 __be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx)
44064 {
44065 - return cpu_to_be64(atomic_inc_return(&ctx->tid)) |
44066 + return cpu_to_be64(atomic_inc_return_unchecked(&ctx->tid)) |
44067 cpu_to_be64(0xff00000000000000LL);
44068 }
44069
44070 diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c
44071 index ed327e6..ca1739e0 100644
44072 --- a/drivers/infiniband/hw/mlx4/mcg.c
44073 +++ b/drivers/infiniband/hw/mlx4/mcg.c
44074 @@ -1041,7 +1041,7 @@ int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx)
44075 {
44076 char name[20];
44077
44078 - atomic_set(&ctx->tid, 0);
44079 + atomic_set_unchecked(&ctx->tid, 0);
44080 sprintf(name, "mlx4_ib_mcg%d", ctx->port);
44081 ctx->mcg_wq = create_singlethread_workqueue(name);
44082 if (!ctx->mcg_wq)
44083 diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
44084 index 6eb743f..a7b0f6d 100644
44085 --- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
44086 +++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
44087 @@ -426,7 +426,7 @@ struct mlx4_ib_demux_ctx {
44088 struct list_head mcg_mgid0_list;
44089 struct workqueue_struct *mcg_wq;
44090 struct mlx4_ib_demux_pv_ctx **tun;
44091 - atomic_t tid;
44092 + atomic_unchecked_t tid;
44093 int flushing; /* flushing the work queue */
44094 };
44095
44096 diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
44097 index 9d3e5c1..6f166df 100644
44098 --- a/drivers/infiniband/hw/mthca/mthca_cmd.c
44099 +++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
44100 @@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
44101 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
44102 }
44103
44104 -int mthca_QUERY_FW(struct mthca_dev *dev)
44105 +int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
44106 {
44107 struct mthca_mailbox *mailbox;
44108 u32 *outbox;
44109 @@ -1612,7 +1612,7 @@ int mthca_HW2SW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
44110 CMD_TIME_CLASS_B);
44111 }
44112
44113 -int mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
44114 +int __intentional_overflow(-1) mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
44115 int num_mtt)
44116 {
44117 return mthca_cmd(dev, mailbox->dma, num_mtt, 0, CMD_WRITE_MTT,
44118 @@ -1634,7 +1634,7 @@ int mthca_MAP_EQ(struct mthca_dev *dev, u64 event_mask, int unmap,
44119 0, CMD_MAP_EQ, CMD_TIME_CLASS_B);
44120 }
44121
44122 -int mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
44123 +int __intentional_overflow(-1) mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
44124 int eq_num)
44125 {
44126 return mthca_cmd(dev, mailbox->dma, eq_num, 0, CMD_SW2HW_EQ,
44127 @@ -1857,7 +1857,7 @@ int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn)
44128 CMD_TIME_CLASS_B);
44129 }
44130
44131 -int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
44132 +int __intentional_overflow(-1) mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
44133 int port, struct ib_wc *in_wc, struct ib_grh *in_grh,
44134 void *in_mad, void *response_mad)
44135 {
44136 diff --git a/drivers/infiniband/hw/mthca/mthca_main.c b/drivers/infiniband/hw/mthca/mthca_main.c
44137 index ded76c1..0cf0a08 100644
44138 --- a/drivers/infiniband/hw/mthca/mthca_main.c
44139 +++ b/drivers/infiniband/hw/mthca/mthca_main.c
44140 @@ -692,7 +692,7 @@ err_close:
44141 return err;
44142 }
44143
44144 -static int mthca_setup_hca(struct mthca_dev *dev)
44145 +static int __intentional_overflow(-1) mthca_setup_hca(struct mthca_dev *dev)
44146 {
44147 int err;
44148
44149 diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
44150 index ed9a989..6aa5dc2 100644
44151 --- a/drivers/infiniband/hw/mthca/mthca_mr.c
44152 +++ b/drivers/infiniband/hw/mthca/mthca_mr.c
44153 @@ -81,7 +81,7 @@ struct mthca_mpt_entry {
44154 * through the bitmaps)
44155 */
44156
44157 -static u32 mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
44158 +static u32 __intentional_overflow(-1) mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
44159 {
44160 int o;
44161 int m;
44162 @@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
44163 return key;
44164 }
44165
44166 -int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
44167 +int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
44168 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
44169 {
44170 struct mthca_mailbox *mailbox;
44171 @@ -516,7 +516,7 @@ int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,
44172 return mthca_mr_alloc(dev, pd, 12, 0, ~0ULL, access, mr);
44173 }
44174
44175 -int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
44176 +int __intentional_overflow(-1) mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
44177 u64 *buffer_list, int buffer_size_shift,
44178 int list_len, u64 iova, u64 total_size,
44179 u32 access, struct mthca_mr *mr)
44180 diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c
44181 index 415f8e1..e34214e 100644
44182 --- a/drivers/infiniband/hw/mthca/mthca_provider.c
44183 +++ b/drivers/infiniband/hw/mthca/mthca_provider.c
44184 @@ -764,7 +764,7 @@ unlock:
44185 return 0;
44186 }
44187
44188 -static int mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
44189 +static int __intentional_overflow(-1) mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
44190 {
44191 struct mthca_dev *dev = to_mdev(ibcq->device);
44192 struct mthca_cq *cq = to_mcq(ibcq);
44193 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
44194 index 3b2a6dc..bce26ff 100644
44195 --- a/drivers/infiniband/hw/nes/nes.c
44196 +++ b/drivers/infiniband/hw/nes/nes.c
44197 @@ -97,7 +97,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
44198 LIST_HEAD(nes_adapter_list);
44199 static LIST_HEAD(nes_dev_list);
44200
44201 -atomic_t qps_destroyed;
44202 +atomic_unchecked_t qps_destroyed;
44203
44204 static unsigned int ee_flsh_adapter;
44205 static unsigned int sysfs_nonidx_addr;
44206 @@ -278,7 +278,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
44207 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
44208 struct nes_adapter *nesadapter = nesdev->nesadapter;
44209
44210 - atomic_inc(&qps_destroyed);
44211 + atomic_inc_unchecked(&qps_destroyed);
44212
44213 /* Free the control structures */
44214
44215 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
44216 index bd9d132..70d84f4 100644
44217 --- a/drivers/infiniband/hw/nes/nes.h
44218 +++ b/drivers/infiniband/hw/nes/nes.h
44219 @@ -180,17 +180,17 @@ extern unsigned int nes_debug_level;
44220 extern unsigned int wqm_quanta;
44221 extern struct list_head nes_adapter_list;
44222
44223 -extern atomic_t cm_connects;
44224 -extern atomic_t cm_accepts;
44225 -extern atomic_t cm_disconnects;
44226 -extern atomic_t cm_closes;
44227 -extern atomic_t cm_connecteds;
44228 -extern atomic_t cm_connect_reqs;
44229 -extern atomic_t cm_rejects;
44230 -extern atomic_t mod_qp_timouts;
44231 -extern atomic_t qps_created;
44232 -extern atomic_t qps_destroyed;
44233 -extern atomic_t sw_qps_destroyed;
44234 +extern atomic_unchecked_t cm_connects;
44235 +extern atomic_unchecked_t cm_accepts;
44236 +extern atomic_unchecked_t cm_disconnects;
44237 +extern atomic_unchecked_t cm_closes;
44238 +extern atomic_unchecked_t cm_connecteds;
44239 +extern atomic_unchecked_t cm_connect_reqs;
44240 +extern atomic_unchecked_t cm_rejects;
44241 +extern atomic_unchecked_t mod_qp_timouts;
44242 +extern atomic_unchecked_t qps_created;
44243 +extern atomic_unchecked_t qps_destroyed;
44244 +extern atomic_unchecked_t sw_qps_destroyed;
44245 extern u32 mh_detected;
44246 extern u32 mh_pauses_sent;
44247 extern u32 cm_packets_sent;
44248 @@ -199,16 +199,16 @@ extern u32 cm_packets_created;
44249 extern u32 cm_packets_received;
44250 extern u32 cm_packets_dropped;
44251 extern u32 cm_packets_retrans;
44252 -extern atomic_t cm_listens_created;
44253 -extern atomic_t cm_listens_destroyed;
44254 +extern atomic_unchecked_t cm_listens_created;
44255 +extern atomic_unchecked_t cm_listens_destroyed;
44256 extern u32 cm_backlog_drops;
44257 -extern atomic_t cm_loopbacks;
44258 -extern atomic_t cm_nodes_created;
44259 -extern atomic_t cm_nodes_destroyed;
44260 -extern atomic_t cm_accel_dropped_pkts;
44261 -extern atomic_t cm_resets_recvd;
44262 -extern atomic_t pau_qps_created;
44263 -extern atomic_t pau_qps_destroyed;
44264 +extern atomic_unchecked_t cm_loopbacks;
44265 +extern atomic_unchecked_t cm_nodes_created;
44266 +extern atomic_unchecked_t cm_nodes_destroyed;
44267 +extern atomic_unchecked_t cm_accel_dropped_pkts;
44268 +extern atomic_unchecked_t cm_resets_recvd;
44269 +extern atomic_unchecked_t pau_qps_created;
44270 +extern atomic_unchecked_t pau_qps_destroyed;
44271
44272 extern u32 int_mod_timer_init;
44273 extern u32 int_mod_cq_depth_256;
44274 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
44275 index 6f09a72..cf4399d 100644
44276 --- a/drivers/infiniband/hw/nes/nes_cm.c
44277 +++ b/drivers/infiniband/hw/nes/nes_cm.c
44278 @@ -69,14 +69,14 @@ u32 cm_packets_dropped;
44279 u32 cm_packets_retrans;
44280 u32 cm_packets_created;
44281 u32 cm_packets_received;
44282 -atomic_t cm_listens_created;
44283 -atomic_t cm_listens_destroyed;
44284 +atomic_unchecked_t cm_listens_created;
44285 +atomic_unchecked_t cm_listens_destroyed;
44286 u32 cm_backlog_drops;
44287 -atomic_t cm_loopbacks;
44288 -atomic_t cm_nodes_created;
44289 -atomic_t cm_nodes_destroyed;
44290 -atomic_t cm_accel_dropped_pkts;
44291 -atomic_t cm_resets_recvd;
44292 +atomic_unchecked_t cm_loopbacks;
44293 +atomic_unchecked_t cm_nodes_created;
44294 +atomic_unchecked_t cm_nodes_destroyed;
44295 +atomic_unchecked_t cm_accel_dropped_pkts;
44296 +atomic_unchecked_t cm_resets_recvd;
44297
44298 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
44299 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
44300 @@ -135,28 +135,28 @@ static void record_ird_ord(struct nes_cm_node *, u16, u16);
44301 /* instance of function pointers for client API */
44302 /* set address of this instance to cm_core->cm_ops at cm_core alloc */
44303 static struct nes_cm_ops nes_cm_api = {
44304 - mini_cm_accelerated,
44305 - mini_cm_listen,
44306 - mini_cm_del_listen,
44307 - mini_cm_connect,
44308 - mini_cm_close,
44309 - mini_cm_accept,
44310 - mini_cm_reject,
44311 - mini_cm_recv_pkt,
44312 - mini_cm_dealloc_core,
44313 - mini_cm_get,
44314 - mini_cm_set
44315 + .accelerated = mini_cm_accelerated,
44316 + .listen = mini_cm_listen,
44317 + .stop_listener = mini_cm_del_listen,
44318 + .connect = mini_cm_connect,
44319 + .close = mini_cm_close,
44320 + .accept = mini_cm_accept,
44321 + .reject = mini_cm_reject,
44322 + .recv_pkt = mini_cm_recv_pkt,
44323 + .destroy_cm_core = mini_cm_dealloc_core,
44324 + .get = mini_cm_get,
44325 + .set = mini_cm_set
44326 };
44327
44328 static struct nes_cm_core *g_cm_core;
44329
44330 -atomic_t cm_connects;
44331 -atomic_t cm_accepts;
44332 -atomic_t cm_disconnects;
44333 -atomic_t cm_closes;
44334 -atomic_t cm_connecteds;
44335 -atomic_t cm_connect_reqs;
44336 -atomic_t cm_rejects;
44337 +atomic_unchecked_t cm_connects;
44338 +atomic_unchecked_t cm_accepts;
44339 +atomic_unchecked_t cm_disconnects;
44340 +atomic_unchecked_t cm_closes;
44341 +atomic_unchecked_t cm_connecteds;
44342 +atomic_unchecked_t cm_connect_reqs;
44343 +atomic_unchecked_t cm_rejects;
44344
44345 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
44346 {
44347 @@ -1436,7 +1436,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
44348 kfree(listener);
44349 listener = NULL;
44350 ret = 0;
44351 - atomic_inc(&cm_listens_destroyed);
44352 + atomic_inc_unchecked(&cm_listens_destroyed);
44353 } else {
44354 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
44355 }
44356 @@ -1637,7 +1637,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
44357 cm_node->rem_mac);
44358
44359 add_hte_node(cm_core, cm_node);
44360 - atomic_inc(&cm_nodes_created);
44361 + atomic_inc_unchecked(&cm_nodes_created);
44362
44363 return cm_node;
44364 }
44365 @@ -1698,7 +1698,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
44366 }
44367
44368 atomic_dec(&cm_core->node_cnt);
44369 - atomic_inc(&cm_nodes_destroyed);
44370 + atomic_inc_unchecked(&cm_nodes_destroyed);
44371 nesqp = cm_node->nesqp;
44372 if (nesqp) {
44373 nesqp->cm_node = NULL;
44374 @@ -1762,7 +1762,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
44375
44376 static void drop_packet(struct sk_buff *skb)
44377 {
44378 - atomic_inc(&cm_accel_dropped_pkts);
44379 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
44380 dev_kfree_skb_any(skb);
44381 }
44382
44383 @@ -1825,7 +1825,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
44384 {
44385
44386 int reset = 0; /* whether to send reset in case of err.. */
44387 - atomic_inc(&cm_resets_recvd);
44388 + atomic_inc_unchecked(&cm_resets_recvd);
44389 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
44390 " refcnt=%d\n", cm_node, cm_node->state,
44391 atomic_read(&cm_node->ref_count));
44392 @@ -2492,7 +2492,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
44393 rem_ref_cm_node(cm_node->cm_core, cm_node);
44394 return NULL;
44395 }
44396 - atomic_inc(&cm_loopbacks);
44397 + atomic_inc_unchecked(&cm_loopbacks);
44398 loopbackremotenode->loopbackpartner = cm_node;
44399 loopbackremotenode->tcp_cntxt.rcv_wscale =
44400 NES_CM_DEFAULT_RCV_WND_SCALE;
44401 @@ -2773,7 +2773,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
44402 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
44403 else {
44404 rem_ref_cm_node(cm_core, cm_node);
44405 - atomic_inc(&cm_accel_dropped_pkts);
44406 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
44407 dev_kfree_skb_any(skb);
44408 }
44409 break;
44410 @@ -3081,7 +3081,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
44411
44412 if ((cm_id) && (cm_id->event_handler)) {
44413 if (issue_disconn) {
44414 - atomic_inc(&cm_disconnects);
44415 + atomic_inc_unchecked(&cm_disconnects);
44416 cm_event.event = IW_CM_EVENT_DISCONNECT;
44417 cm_event.status = disconn_status;
44418 cm_event.local_addr = cm_id->local_addr;
44419 @@ -3103,7 +3103,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
44420 }
44421
44422 if (issue_close) {
44423 - atomic_inc(&cm_closes);
44424 + atomic_inc_unchecked(&cm_closes);
44425 nes_disconnect(nesqp, 1);
44426
44427 cm_id->provider_data = nesqp;
44428 @@ -3241,7 +3241,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
44429
44430 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
44431 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
44432 - atomic_inc(&cm_accepts);
44433 + atomic_inc_unchecked(&cm_accepts);
44434
44435 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
44436 netdev_refcnt_read(nesvnic->netdev));
44437 @@ -3439,7 +3439,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
44438 struct nes_cm_core *cm_core;
44439 u8 *start_buff;
44440
44441 - atomic_inc(&cm_rejects);
44442 + atomic_inc_unchecked(&cm_rejects);
44443 cm_node = (struct nes_cm_node *)cm_id->provider_data;
44444 loopback = cm_node->loopbackpartner;
44445 cm_core = cm_node->cm_core;
44446 @@ -3504,7 +3504,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
44447 ntohs(raddr->sin_port), ntohl(laddr->sin_addr.s_addr),
44448 ntohs(laddr->sin_port));
44449
44450 - atomic_inc(&cm_connects);
44451 + atomic_inc_unchecked(&cm_connects);
44452 nesqp->active_conn = 1;
44453
44454 /* cache the cm_id in the qp */
44455 @@ -3649,7 +3649,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
44456 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
44457 return err;
44458 }
44459 - atomic_inc(&cm_listens_created);
44460 + atomic_inc_unchecked(&cm_listens_created);
44461 }
44462
44463 cm_id->add_ref(cm_id);
44464 @@ -3756,7 +3756,7 @@ static void cm_event_connected(struct nes_cm_event *event)
44465
44466 if (nesqp->destroyed)
44467 return;
44468 - atomic_inc(&cm_connecteds);
44469 + atomic_inc_unchecked(&cm_connecteds);
44470 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
44471 " local port 0x%04X. jiffies = %lu.\n",
44472 nesqp->hwqp.qp_id, ntohl(raddr->sin_addr.s_addr),
44473 @@ -3941,7 +3941,7 @@ static void cm_event_reset(struct nes_cm_event *event)
44474
44475 cm_id->add_ref(cm_id);
44476 ret = cm_id->event_handler(cm_id, &cm_event);
44477 - atomic_inc(&cm_closes);
44478 + atomic_inc_unchecked(&cm_closes);
44479 cm_event.event = IW_CM_EVENT_CLOSE;
44480 cm_event.status = 0;
44481 cm_event.provider_data = cm_id->provider_data;
44482 @@ -3981,7 +3981,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
44483 return;
44484 cm_id = cm_node->cm_id;
44485
44486 - atomic_inc(&cm_connect_reqs);
44487 + atomic_inc_unchecked(&cm_connect_reqs);
44488 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
44489 cm_node, cm_id, jiffies);
44490
44491 @@ -4030,7 +4030,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
44492 return;
44493 cm_id = cm_node->cm_id;
44494
44495 - atomic_inc(&cm_connect_reqs);
44496 + atomic_inc_unchecked(&cm_connect_reqs);
44497 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
44498 cm_node, cm_id, jiffies);
44499
44500 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
44501 index 4166452..fc952c3 100644
44502 --- a/drivers/infiniband/hw/nes/nes_mgt.c
44503 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
44504 @@ -40,8 +40,8 @@
44505 #include "nes.h"
44506 #include "nes_mgt.h"
44507
44508 -atomic_t pau_qps_created;
44509 -atomic_t pau_qps_destroyed;
44510 +atomic_unchecked_t pau_qps_created;
44511 +atomic_unchecked_t pau_qps_destroyed;
44512
44513 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
44514 {
44515 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
44516 {
44517 struct sk_buff *skb;
44518 unsigned long flags;
44519 - atomic_inc(&pau_qps_destroyed);
44520 + atomic_inc_unchecked(&pau_qps_destroyed);
44521
44522 /* Free packets that have not yet been forwarded */
44523 /* Lock is acquired by skb_dequeue when removing the skb */
44524 @@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
44525 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
44526 skb_queue_head_init(&nesqp->pau_list);
44527 spin_lock_init(&nesqp->pau_lock);
44528 - atomic_inc(&pau_qps_created);
44529 + atomic_inc_unchecked(&pau_qps_created);
44530 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
44531 }
44532
44533 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
44534 index 49eb511..a774366 100644
44535 --- a/drivers/infiniband/hw/nes/nes_nic.c
44536 +++ b/drivers/infiniband/hw/nes/nes_nic.c
44537 @@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
44538 target_stat_values[++index] = mh_detected;
44539 target_stat_values[++index] = mh_pauses_sent;
44540 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
44541 - target_stat_values[++index] = atomic_read(&cm_connects);
44542 - target_stat_values[++index] = atomic_read(&cm_accepts);
44543 - target_stat_values[++index] = atomic_read(&cm_disconnects);
44544 - target_stat_values[++index] = atomic_read(&cm_connecteds);
44545 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
44546 - target_stat_values[++index] = atomic_read(&cm_rejects);
44547 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
44548 - target_stat_values[++index] = atomic_read(&qps_created);
44549 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
44550 - target_stat_values[++index] = atomic_read(&qps_destroyed);
44551 - target_stat_values[++index] = atomic_read(&cm_closes);
44552 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
44553 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
44554 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
44555 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
44556 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
44557 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
44558 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
44559 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
44560 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
44561 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
44562 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
44563 target_stat_values[++index] = cm_packets_sent;
44564 target_stat_values[++index] = cm_packets_bounced;
44565 target_stat_values[++index] = cm_packets_created;
44566 target_stat_values[++index] = cm_packets_received;
44567 target_stat_values[++index] = cm_packets_dropped;
44568 target_stat_values[++index] = cm_packets_retrans;
44569 - target_stat_values[++index] = atomic_read(&cm_listens_created);
44570 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
44571 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
44572 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
44573 target_stat_values[++index] = cm_backlog_drops;
44574 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
44575 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
44576 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
44577 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
44578 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
44579 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
44580 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
44581 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
44582 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
44583 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
44584 target_stat_values[++index] = nesadapter->free_4kpbl;
44585 target_stat_values[++index] = nesadapter->free_256pbl;
44586 target_stat_values[++index] = int_mod_timer_init;
44587 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
44588 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
44589 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
44590 - target_stat_values[++index] = atomic_read(&pau_qps_created);
44591 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
44592 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
44593 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
44594 }
44595
44596 /**
44597 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
44598 index fef067c..6a25ccd 100644
44599 --- a/drivers/infiniband/hw/nes/nes_verbs.c
44600 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
44601 @@ -46,9 +46,9 @@
44602
44603 #include <rdma/ib_umem.h>
44604
44605 -atomic_t mod_qp_timouts;
44606 -atomic_t qps_created;
44607 -atomic_t sw_qps_destroyed;
44608 +atomic_unchecked_t mod_qp_timouts;
44609 +atomic_unchecked_t qps_created;
44610 +atomic_unchecked_t sw_qps_destroyed;
44611
44612 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
44613
44614 @@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
44615 if (init_attr->create_flags)
44616 return ERR_PTR(-EINVAL);
44617
44618 - atomic_inc(&qps_created);
44619 + atomic_inc_unchecked(&qps_created);
44620 switch (init_attr->qp_type) {
44621 case IB_QPT_RC:
44622 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
44623 @@ -1468,7 +1468,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
44624 struct iw_cm_event cm_event;
44625 int ret = 0;
44626
44627 - atomic_inc(&sw_qps_destroyed);
44628 + atomic_inc_unchecked(&sw_qps_destroyed);
44629 nesqp->destroyed = 1;
44630
44631 /* Blow away the connection if it exists. */
44632 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
44633 index c00ae09..04e91be 100644
44634 --- a/drivers/infiniband/hw/qib/qib.h
44635 +++ b/drivers/infiniband/hw/qib/qib.h
44636 @@ -52,6 +52,7 @@
44637 #include <linux/kref.h>
44638 #include <linux/sched.h>
44639 #include <linux/kthread.h>
44640 +#include <linux/slab.h>
44641
44642 #include "qib_common.h"
44643 #include "qib_verbs.h"
44644 diff --git a/drivers/infiniband/ulp/ipoib/ipoib_netlink.c b/drivers/infiniband/ulp/ipoib/ipoib_netlink.c
44645 index cdc7df4..a2fdfdb 100644
44646 --- a/drivers/infiniband/ulp/ipoib/ipoib_netlink.c
44647 +++ b/drivers/infiniband/ulp/ipoib/ipoib_netlink.c
44648 @@ -156,7 +156,7 @@ static size_t ipoib_get_size(const struct net_device *dev)
44649 nla_total_size(2); /* IFLA_IPOIB_UMCAST */
44650 }
44651
44652 -static struct rtnl_link_ops ipoib_link_ops __read_mostly = {
44653 +static struct rtnl_link_ops ipoib_link_ops = {
44654 .kind = "ipoib",
44655 .maxtype = IFLA_IPOIB_MAX,
44656 .policy = ipoib_policy,
44657 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
44658 index 24c41ba..102d71f 100644
44659 --- a/drivers/input/gameport/gameport.c
44660 +++ b/drivers/input/gameport/gameport.c
44661 @@ -490,14 +490,14 @@ EXPORT_SYMBOL(gameport_set_phys);
44662 */
44663 static void gameport_init_port(struct gameport *gameport)
44664 {
44665 - static atomic_t gameport_no = ATOMIC_INIT(0);
44666 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
44667
44668 __module_get(THIS_MODULE);
44669
44670 mutex_init(&gameport->drv_mutex);
44671 device_initialize(&gameport->dev);
44672 dev_set_name(&gameport->dev, "gameport%lu",
44673 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
44674 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
44675 gameport->dev.bus = &gameport_bus;
44676 gameport->dev.release = gameport_release_port;
44677 if (gameport->parent)
44678 diff --git a/drivers/input/input.c b/drivers/input/input.c
44679 index 29ca0bb..f4bc2e3 100644
44680 --- a/drivers/input/input.c
44681 +++ b/drivers/input/input.c
44682 @@ -1774,7 +1774,7 @@ EXPORT_SYMBOL_GPL(input_class);
44683 */
44684 struct input_dev *input_allocate_device(void)
44685 {
44686 - static atomic_t input_no = ATOMIC_INIT(0);
44687 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
44688 struct input_dev *dev;
44689
44690 dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL);
44691 @@ -1789,7 +1789,7 @@ struct input_dev *input_allocate_device(void)
44692 INIT_LIST_HEAD(&dev->node);
44693
44694 dev_set_name(&dev->dev, "input%ld",
44695 - (unsigned long) atomic_inc_return(&input_no) - 1);
44696 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
44697
44698 __module_get(THIS_MODULE);
44699 }
44700 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
44701 index 4a95b22..874c182 100644
44702 --- a/drivers/input/joystick/sidewinder.c
44703 +++ b/drivers/input/joystick/sidewinder.c
44704 @@ -30,6 +30,7 @@
44705 #include <linux/kernel.h>
44706 #include <linux/module.h>
44707 #include <linux/slab.h>
44708 +#include <linux/sched.h>
44709 #include <linux/input.h>
44710 #include <linux/gameport.h>
44711 #include <linux/jiffies.h>
44712 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
44713 index e65d9c0..ad3942e 100644
44714 --- a/drivers/input/joystick/xpad.c
44715 +++ b/drivers/input/joystick/xpad.c
44716 @@ -850,7 +850,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
44717
44718 static int xpad_led_probe(struct usb_xpad *xpad)
44719 {
44720 - static atomic_t led_seq = ATOMIC_INIT(0);
44721 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
44722 long led_no;
44723 struct xpad_led *led;
44724 struct led_classdev *led_cdev;
44725 @@ -863,7 +863,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
44726 if (!led)
44727 return -ENOMEM;
44728
44729 - led_no = (long)atomic_inc_return(&led_seq) - 1;
44730 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
44731
44732 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
44733 led->xpad = xpad;
44734 diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
44735 index 719410f..1896169 100644
44736 --- a/drivers/input/misc/ims-pcu.c
44737 +++ b/drivers/input/misc/ims-pcu.c
44738 @@ -1851,7 +1851,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id)
44739
44740 static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
44741 {
44742 - static atomic_t device_no = ATOMIC_INIT(0);
44743 + static atomic_unchecked_t device_no = ATOMIC_INIT(0);
44744
44745 const struct ims_pcu_device_info *info;
44746 int error;
44747 @@ -1882,7 +1882,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
44748 }
44749
44750 /* Device appears to be operable, complete initialization */
44751 - pcu->device_no = atomic_inc_return(&device_no) - 1;
44752 + pcu->device_no = atomic_inc_return_unchecked(&device_no) - 1;
44753
44754 /*
44755 * PCU-B devices, both GEN_1 and GEN_2 do not have OFN sensor
44756 diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
44757 index 2f0b39d..7370f13 100644
44758 --- a/drivers/input/mouse/psmouse.h
44759 +++ b/drivers/input/mouse/psmouse.h
44760 @@ -116,7 +116,7 @@ struct psmouse_attribute {
44761 ssize_t (*set)(struct psmouse *psmouse, void *data,
44762 const char *buf, size_t count);
44763 bool protect;
44764 -};
44765 +} __do_const;
44766 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
44767
44768 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
44769 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
44770 index b604564..3f14ae4 100644
44771 --- a/drivers/input/mousedev.c
44772 +++ b/drivers/input/mousedev.c
44773 @@ -744,7 +744,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
44774
44775 spin_unlock_irq(&client->packet_lock);
44776
44777 - if (copy_to_user(buffer, data, count))
44778 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
44779 return -EFAULT;
44780
44781 return count;
44782 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
44783 index b29134d..394deb0 100644
44784 --- a/drivers/input/serio/serio.c
44785 +++ b/drivers/input/serio/serio.c
44786 @@ -514,7 +514,7 @@ static void serio_release_port(struct device *dev)
44787 */
44788 static void serio_init_port(struct serio *serio)
44789 {
44790 - static atomic_t serio_no = ATOMIC_INIT(0);
44791 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
44792
44793 __module_get(THIS_MODULE);
44794
44795 @@ -525,7 +525,7 @@ static void serio_init_port(struct serio *serio)
44796 mutex_init(&serio->drv_mutex);
44797 device_initialize(&serio->dev);
44798 dev_set_name(&serio->dev, "serio%ld",
44799 - (long)atomic_inc_return(&serio_no) - 1);
44800 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
44801 serio->dev.bus = &serio_bus;
44802 serio->dev.release = serio_release_port;
44803 serio->dev.groups = serio_device_attr_groups;
44804 diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
44805 index c9a02fe..0debc75 100644
44806 --- a/drivers/input/serio/serio_raw.c
44807 +++ b/drivers/input/serio/serio_raw.c
44808 @@ -292,7 +292,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data,
44809
44810 static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
44811 {
44812 - static atomic_t serio_raw_no = ATOMIC_INIT(0);
44813 + static atomic_unchecked_t serio_raw_no = ATOMIC_INIT(0);
44814 struct serio_raw *serio_raw;
44815 int err;
44816
44817 @@ -303,7 +303,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
44818 }
44819
44820 snprintf(serio_raw->name, sizeof(serio_raw->name),
44821 - "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1);
44822 + "serio_raw%ld", (long)atomic_inc_return_unchecked(&serio_raw_no) - 1);
44823 kref_init(&serio_raw->kref);
44824 INIT_LIST_HEAD(&serio_raw->client_list);
44825 init_waitqueue_head(&serio_raw->wait);
44826 diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
44827 index 5aff937..9cff67c 100644
44828 --- a/drivers/iommu/amd_iommu.c
44829 +++ b/drivers/iommu/amd_iommu.c
44830 @@ -798,11 +798,21 @@ static void copy_cmd_to_buffer(struct amd_iommu *iommu,
44831
44832 static void build_completion_wait(struct iommu_cmd *cmd, u64 address)
44833 {
44834 + phys_addr_t physaddr;
44835 WARN_ON(address & 0x7ULL);
44836
44837 memset(cmd, 0, sizeof(*cmd));
44838 - cmd->data[0] = lower_32_bits(__pa(address)) | CMD_COMPL_WAIT_STORE_MASK;
44839 - cmd->data[1] = upper_32_bits(__pa(address));
44840 +
44841 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
44842 + if (object_starts_on_stack(address)) {
44843 + void *adjbuf = (void *)address - current->stack + current->lowmem_stack;
44844 + physaddr = __pa((u64)adjbuf);
44845 + } else
44846 +#endif
44847 + physaddr = __pa(address);
44848 +
44849 + cmd->data[0] = lower_32_bits(physaddr) | CMD_COMPL_WAIT_STORE_MASK;
44850 + cmd->data[1] = upper_32_bits(physaddr);
44851 cmd->data[2] = 1;
44852 CMD_SET_TYPE(cmd, CMD_COMPL_WAIT);
44853 }
44854 diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c
44855 index a83cc2a..64462e6 100644
44856 --- a/drivers/iommu/arm-smmu.c
44857 +++ b/drivers/iommu/arm-smmu.c
44858 @@ -921,7 +921,7 @@ static int arm_smmu_init_domain_context(struct iommu_domain *domain,
44859 cfg->irptndx = cfg->cbndx;
44860 }
44861
44862 - ACCESS_ONCE(smmu_domain->smmu) = smmu;
44863 + ACCESS_ONCE_RW(smmu_domain->smmu) = smmu;
44864 arm_smmu_init_context_bank(smmu_domain);
44865 spin_unlock_irqrestore(&smmu_domain->lock, flags);
44866
44867 diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
44868 index 33c4395..e06447e 100644
44869 --- a/drivers/iommu/irq_remapping.c
44870 +++ b/drivers/iommu/irq_remapping.c
44871 @@ -354,7 +354,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
44872 void panic_if_irq_remap(const char *msg)
44873 {
44874 if (irq_remapping_enabled)
44875 - panic(msg);
44876 + panic("%s", msg);
44877 }
44878
44879 static void ir_ack_apic_edge(struct irq_data *data)
44880 @@ -375,10 +375,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
44881
44882 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
44883 {
44884 - chip->irq_print_chip = ir_print_prefix;
44885 - chip->irq_ack = ir_ack_apic_edge;
44886 - chip->irq_eoi = ir_ack_apic_level;
44887 - chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
44888 + pax_open_kernel();
44889 + *(void **)&chip->irq_print_chip = ir_print_prefix;
44890 + *(void **)&chip->irq_ack = ir_ack_apic_edge;
44891 + *(void **)&chip->irq_eoi = ir_ack_apic_level;
44892 + *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
44893 + pax_close_kernel();
44894 }
44895
44896 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
44897 diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
44898 index dda6dbc..f9adebb 100644
44899 --- a/drivers/irqchip/irq-gic.c
44900 +++ b/drivers/irqchip/irq-gic.c
44901 @@ -84,7 +84,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
44902 * Supported arch specific GIC irq extension.
44903 * Default make them NULL.
44904 */
44905 -struct irq_chip gic_arch_extn = {
44906 +irq_chip_no_const gic_arch_extn = {
44907 .irq_eoi = NULL,
44908 .irq_mask = NULL,
44909 .irq_unmask = NULL,
44910 @@ -312,7 +312,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
44911 chained_irq_exit(chip, desc);
44912 }
44913
44914 -static struct irq_chip gic_chip = {
44915 +static irq_chip_no_const gic_chip __read_only = {
44916 .name = "GIC",
44917 .irq_mask = gic_mask_irq,
44918 .irq_unmask = gic_unmask_irq,
44919 diff --git a/drivers/irqchip/irq-renesas-irqc.c b/drivers/irqchip/irq-renesas-irqc.c
44920 index 8777065..a4a9967 100644
44921 --- a/drivers/irqchip/irq-renesas-irqc.c
44922 +++ b/drivers/irqchip/irq-renesas-irqc.c
44923 @@ -151,7 +151,7 @@ static int irqc_probe(struct platform_device *pdev)
44924 struct irqc_priv *p;
44925 struct resource *io;
44926 struct resource *irq;
44927 - struct irq_chip *irq_chip;
44928 + irq_chip_no_const *irq_chip;
44929 const char *name = dev_name(&pdev->dev);
44930 int ret;
44931 int k;
44932 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
44933 index 6a2df32..dc962f1 100644
44934 --- a/drivers/isdn/capi/capi.c
44935 +++ b/drivers/isdn/capi/capi.c
44936 @@ -81,8 +81,8 @@ struct capiminor {
44937
44938 struct capi20_appl *ap;
44939 u32 ncci;
44940 - atomic_t datahandle;
44941 - atomic_t msgid;
44942 + atomic_unchecked_t datahandle;
44943 + atomic_unchecked_t msgid;
44944
44945 struct tty_port port;
44946 int ttyinstop;
44947 @@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
44948 capimsg_setu16(s, 2, mp->ap->applid);
44949 capimsg_setu8 (s, 4, CAPI_DATA_B3);
44950 capimsg_setu8 (s, 5, CAPI_RESP);
44951 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
44952 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
44953 capimsg_setu32(s, 8, mp->ncci);
44954 capimsg_setu16(s, 12, datahandle);
44955 }
44956 @@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
44957 mp->outbytes -= len;
44958 spin_unlock_bh(&mp->outlock);
44959
44960 - datahandle = atomic_inc_return(&mp->datahandle);
44961 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
44962 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
44963 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
44964 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
44965 capimsg_setu16(skb->data, 2, mp->ap->applid);
44966 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
44967 capimsg_setu8 (skb->data, 5, CAPI_REQ);
44968 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
44969 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
44970 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
44971 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
44972 capimsg_setu16(skb->data, 16, len); /* Data length */
44973 diff --git a/drivers/isdn/gigaset/bas-gigaset.c b/drivers/isdn/gigaset/bas-gigaset.c
44974 index b7ae0a0..04590fa 100644
44975 --- a/drivers/isdn/gigaset/bas-gigaset.c
44976 +++ b/drivers/isdn/gigaset/bas-gigaset.c
44977 @@ -2565,22 +2565,22 @@ static int gigaset_post_reset(struct usb_interface *intf)
44978
44979
44980 static const struct gigaset_ops gigops = {
44981 - gigaset_write_cmd,
44982 - gigaset_write_room,
44983 - gigaset_chars_in_buffer,
44984 - gigaset_brkchars,
44985 - gigaset_init_bchannel,
44986 - gigaset_close_bchannel,
44987 - gigaset_initbcshw,
44988 - gigaset_freebcshw,
44989 - gigaset_reinitbcshw,
44990 - gigaset_initcshw,
44991 - gigaset_freecshw,
44992 - gigaset_set_modem_ctrl,
44993 - gigaset_baud_rate,
44994 - gigaset_set_line_ctrl,
44995 - gigaset_isoc_send_skb,
44996 - gigaset_isoc_input,
44997 + .write_cmd = gigaset_write_cmd,
44998 + .write_room = gigaset_write_room,
44999 + .chars_in_buffer = gigaset_chars_in_buffer,
45000 + .brkchars = gigaset_brkchars,
45001 + .init_bchannel = gigaset_init_bchannel,
45002 + .close_bchannel = gigaset_close_bchannel,
45003 + .initbcshw = gigaset_initbcshw,
45004 + .freebcshw = gigaset_freebcshw,
45005 + .reinitbcshw = gigaset_reinitbcshw,
45006 + .initcshw = gigaset_initcshw,
45007 + .freecshw = gigaset_freecshw,
45008 + .set_modem_ctrl = gigaset_set_modem_ctrl,
45009 + .baud_rate = gigaset_baud_rate,
45010 + .set_line_ctrl = gigaset_set_line_ctrl,
45011 + .send_skb = gigaset_isoc_send_skb,
45012 + .handle_input = gigaset_isoc_input,
45013 };
45014
45015 /* bas_gigaset_init
45016 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
45017 index 600c79b..3752bab 100644
45018 --- a/drivers/isdn/gigaset/interface.c
45019 +++ b/drivers/isdn/gigaset/interface.c
45020 @@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
45021 }
45022 tty->driver_data = cs;
45023
45024 - ++cs->port.count;
45025 + atomic_inc(&cs->port.count);
45026
45027 - if (cs->port.count == 1) {
45028 + if (atomic_read(&cs->port.count) == 1) {
45029 tty_port_tty_set(&cs->port, tty);
45030 cs->port.low_latency = 1;
45031 }
45032 @@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
45033
45034 if (!cs->connected)
45035 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
45036 - else if (!cs->port.count)
45037 + else if (!atomic_read(&cs->port.count))
45038 dev_warn(cs->dev, "%s: device not opened\n", __func__);
45039 - else if (!--cs->port.count)
45040 + else if (!atomic_dec_return(&cs->port.count))
45041 tty_port_tty_set(&cs->port, NULL);
45042
45043 mutex_unlock(&cs->mutex);
45044 diff --git a/drivers/isdn/gigaset/ser-gigaset.c b/drivers/isdn/gigaset/ser-gigaset.c
45045 index 8c91fd5..14f13ce 100644
45046 --- a/drivers/isdn/gigaset/ser-gigaset.c
45047 +++ b/drivers/isdn/gigaset/ser-gigaset.c
45048 @@ -453,22 +453,22 @@ static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
45049 }
45050
45051 static const struct gigaset_ops ops = {
45052 - gigaset_write_cmd,
45053 - gigaset_write_room,
45054 - gigaset_chars_in_buffer,
45055 - gigaset_brkchars,
45056 - gigaset_init_bchannel,
45057 - gigaset_close_bchannel,
45058 - gigaset_initbcshw,
45059 - gigaset_freebcshw,
45060 - gigaset_reinitbcshw,
45061 - gigaset_initcshw,
45062 - gigaset_freecshw,
45063 - gigaset_set_modem_ctrl,
45064 - gigaset_baud_rate,
45065 - gigaset_set_line_ctrl,
45066 - gigaset_m10x_send_skb, /* asyncdata.c */
45067 - gigaset_m10x_input, /* asyncdata.c */
45068 + .write_cmd = gigaset_write_cmd,
45069 + .write_room = gigaset_write_room,
45070 + .chars_in_buffer = gigaset_chars_in_buffer,
45071 + .brkchars = gigaset_brkchars,
45072 + .init_bchannel = gigaset_init_bchannel,
45073 + .close_bchannel = gigaset_close_bchannel,
45074 + .initbcshw = gigaset_initbcshw,
45075 + .freebcshw = gigaset_freebcshw,
45076 + .reinitbcshw = gigaset_reinitbcshw,
45077 + .initcshw = gigaset_initcshw,
45078 + .freecshw = gigaset_freecshw,
45079 + .set_modem_ctrl = gigaset_set_modem_ctrl,
45080 + .baud_rate = gigaset_baud_rate,
45081 + .set_line_ctrl = gigaset_set_line_ctrl,
45082 + .send_skb = gigaset_m10x_send_skb, /* asyncdata.c */
45083 + .handle_input = gigaset_m10x_input, /* asyncdata.c */
45084 };
45085
45086
45087 diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
45088 index d0a41cb..b953e50 100644
45089 --- a/drivers/isdn/gigaset/usb-gigaset.c
45090 +++ b/drivers/isdn/gigaset/usb-gigaset.c
45091 @@ -547,7 +547,7 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
45092 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
45093 memcpy(cs->hw.usb->bchars, buf, 6);
45094 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
45095 - 0, 0, &buf, 6, 2000);
45096 + 0, 0, buf, 6, 2000);
45097 }
45098
45099 static void gigaset_freebcshw(struct bc_state *bcs)
45100 @@ -869,22 +869,22 @@ static int gigaset_pre_reset(struct usb_interface *intf)
45101 }
45102
45103 static const struct gigaset_ops ops = {
45104 - gigaset_write_cmd,
45105 - gigaset_write_room,
45106 - gigaset_chars_in_buffer,
45107 - gigaset_brkchars,
45108 - gigaset_init_bchannel,
45109 - gigaset_close_bchannel,
45110 - gigaset_initbcshw,
45111 - gigaset_freebcshw,
45112 - gigaset_reinitbcshw,
45113 - gigaset_initcshw,
45114 - gigaset_freecshw,
45115 - gigaset_set_modem_ctrl,
45116 - gigaset_baud_rate,
45117 - gigaset_set_line_ctrl,
45118 - gigaset_m10x_send_skb,
45119 - gigaset_m10x_input,
45120 + .write_cmd = gigaset_write_cmd,
45121 + .write_room = gigaset_write_room,
45122 + .chars_in_buffer = gigaset_chars_in_buffer,
45123 + .brkchars = gigaset_brkchars,
45124 + .init_bchannel = gigaset_init_bchannel,
45125 + .close_bchannel = gigaset_close_bchannel,
45126 + .initbcshw = gigaset_initbcshw,
45127 + .freebcshw = gigaset_freebcshw,
45128 + .reinitbcshw = gigaset_reinitbcshw,
45129 + .initcshw = gigaset_initcshw,
45130 + .freecshw = gigaset_freecshw,
45131 + .set_modem_ctrl = gigaset_set_modem_ctrl,
45132 + .baud_rate = gigaset_baud_rate,
45133 + .set_line_ctrl = gigaset_set_line_ctrl,
45134 + .send_skb = gigaset_m10x_send_skb,
45135 + .handle_input = gigaset_m10x_input,
45136 };
45137
45138 /*
45139 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
45140 index 4d9b195..455075c 100644
45141 --- a/drivers/isdn/hardware/avm/b1.c
45142 +++ b/drivers/isdn/hardware/avm/b1.c
45143 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
45144 }
45145 if (left) {
45146 if (t4file->user) {
45147 - if (copy_from_user(buf, dp, left))
45148 + if (left > sizeof buf || copy_from_user(buf, dp, left))
45149 return -EFAULT;
45150 } else {
45151 memcpy(buf, dp, left);
45152 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
45153 }
45154 if (left) {
45155 if (config->user) {
45156 - if (copy_from_user(buf, dp, left))
45157 + if (left > sizeof buf || copy_from_user(buf, dp, left))
45158 return -EFAULT;
45159 } else {
45160 memcpy(buf, dp, left);
45161 diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
45162 index 9b856e1..fa03c92 100644
45163 --- a/drivers/isdn/i4l/isdn_common.c
45164 +++ b/drivers/isdn/i4l/isdn_common.c
45165 @@ -1654,6 +1654,8 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
45166 } else
45167 return -EINVAL;
45168 case IIOCDBGVAR:
45169 + if (!capable(CAP_SYS_RAWIO))
45170 + return -EPERM;
45171 if (arg) {
45172 if (copy_to_user(argp, &dev, sizeof(ulong)))
45173 return -EFAULT;
45174 diff --git a/drivers/isdn/i4l/isdn_concap.c b/drivers/isdn/i4l/isdn_concap.c
45175 index 91d5730..336523e 100644
45176 --- a/drivers/isdn/i4l/isdn_concap.c
45177 +++ b/drivers/isdn/i4l/isdn_concap.c
45178 @@ -80,9 +80,9 @@ static int isdn_concap_dl_disconn_req(struct concap_proto *concap)
45179 }
45180
45181 struct concap_device_ops isdn_concap_reliable_dl_dops = {
45182 - &isdn_concap_dl_data_req,
45183 - &isdn_concap_dl_connect_req,
45184 - &isdn_concap_dl_disconn_req
45185 + .data_req = &isdn_concap_dl_data_req,
45186 + .connect_req = &isdn_concap_dl_connect_req,
45187 + .disconn_req = &isdn_concap_dl_disconn_req
45188 };
45189
45190 /* The following should better go into a dedicated source file such that
45191 diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
45192 index 3c5f249..5fac4d0 100644
45193 --- a/drivers/isdn/i4l/isdn_tty.c
45194 +++ b/drivers/isdn/i4l/isdn_tty.c
45195 @@ -1508,9 +1508,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
45196
45197 #ifdef ISDN_DEBUG_MODEM_OPEN
45198 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
45199 - port->count);
45200 + atomic_read(&port->count));
45201 #endif
45202 - port->count++;
45203 + atomic_inc(&port->count);
45204 port->tty = tty;
45205 /*
45206 * Start up serial port
45207 @@ -1554,7 +1554,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
45208 #endif
45209 return;
45210 }
45211 - if ((tty->count == 1) && (port->count != 1)) {
45212 + if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
45213 /*
45214 * Uh, oh. tty->count is 1, which means that the tty
45215 * structure will be freed. Info->count should always
45216 @@ -1563,15 +1563,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
45217 * serial port won't be shutdown.
45218 */
45219 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
45220 - "info->count is %d\n", port->count);
45221 - port->count = 1;
45222 + "info->count is %d\n", atomic_read(&port->count));
45223 + atomic_set(&port->count, 1);
45224 }
45225 - if (--port->count < 0) {
45226 + if (atomic_dec_return(&port->count) < 0) {
45227 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
45228 - info->line, port->count);
45229 - port->count = 0;
45230 + info->line, atomic_read(&port->count));
45231 + atomic_set(&port->count, 0);
45232 }
45233 - if (port->count) {
45234 + if (atomic_read(&port->count)) {
45235 #ifdef ISDN_DEBUG_MODEM_OPEN
45236 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
45237 #endif
45238 @@ -1625,7 +1625,7 @@ isdn_tty_hangup(struct tty_struct *tty)
45239 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
45240 return;
45241 isdn_tty_shutdown(info);
45242 - port->count = 0;
45243 + atomic_set(&port->count, 0);
45244 port->flags &= ~ASYNC_NORMAL_ACTIVE;
45245 port->tty = NULL;
45246 wake_up_interruptible(&port->open_wait);
45247 @@ -1970,7 +1970,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
45248 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
45249 modem_info *info = &dev->mdm.info[i];
45250
45251 - if (info->port.count == 0)
45252 + if (atomic_read(&info->port.count) == 0)
45253 continue;
45254 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
45255 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
45256 diff --git a/drivers/isdn/i4l/isdn_x25iface.c b/drivers/isdn/i4l/isdn_x25iface.c
45257 index e2d4e58..40cd045 100644
45258 --- a/drivers/isdn/i4l/isdn_x25iface.c
45259 +++ b/drivers/isdn/i4l/isdn_x25iface.c
45260 @@ -53,14 +53,14 @@ static int isdn_x25iface_disconn_ind(struct concap_proto *);
45261
45262
45263 static struct concap_proto_ops ix25_pops = {
45264 - &isdn_x25iface_proto_new,
45265 - &isdn_x25iface_proto_del,
45266 - &isdn_x25iface_proto_restart,
45267 - &isdn_x25iface_proto_close,
45268 - &isdn_x25iface_xmit,
45269 - &isdn_x25iface_receive,
45270 - &isdn_x25iface_connect_ind,
45271 - &isdn_x25iface_disconn_ind
45272 + .proto_new = &isdn_x25iface_proto_new,
45273 + .proto_del = &isdn_x25iface_proto_del,
45274 + .restart = &isdn_x25iface_proto_restart,
45275 + .close = &isdn_x25iface_proto_close,
45276 + .encap_and_xmit = &isdn_x25iface_xmit,
45277 + .data_ind = &isdn_x25iface_receive,
45278 + .connect_ind = &isdn_x25iface_connect_ind,
45279 + .disconn_ind = &isdn_x25iface_disconn_ind
45280 };
45281
45282 /* error message helper function */
45283 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
45284 index 6a7447c..cae33fe 100644
45285 --- a/drivers/isdn/icn/icn.c
45286 +++ b/drivers/isdn/icn/icn.c
45287 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
45288 if (count > len)
45289 count = len;
45290 if (user) {
45291 - if (copy_from_user(msg, buf, count))
45292 + if (count > sizeof msg || copy_from_user(msg, buf, count))
45293 return -EFAULT;
45294 } else
45295 memcpy(msg, buf, count);
45296 diff --git a/drivers/isdn/mISDN/dsp_cmx.c b/drivers/isdn/mISDN/dsp_cmx.c
45297 index a4f05c5..1433bc5 100644
45298 --- a/drivers/isdn/mISDN/dsp_cmx.c
45299 +++ b/drivers/isdn/mISDN/dsp_cmx.c
45300 @@ -1628,7 +1628,7 @@ unsigned long dsp_spl_jiffies; /* calculate the next time to fire */
45301 static u16 dsp_count; /* last sample count */
45302 static int dsp_count_valid; /* if we have last sample count */
45303
45304 -void
45305 +void __intentional_overflow(-1)
45306 dsp_cmx_send(void *arg)
45307 {
45308 struct dsp_conf *conf;
45309 diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
45310 index f58a354..fbae176 100644
45311 --- a/drivers/leds/leds-clevo-mail.c
45312 +++ b/drivers/leds/leds-clevo-mail.c
45313 @@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
45314 * detected as working, but in reality it is not) as low as
45315 * possible.
45316 */
45317 -static struct dmi_system_id clevo_mail_led_dmi_table[] __initdata = {
45318 +static struct dmi_system_id clevo_mail_led_dmi_table[] __initconst = {
45319 {
45320 .callback = clevo_mail_led_dmi_callback,
45321 .ident = "Clevo D410J",
45322 diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
45323 index 046cb70..6b20d39 100644
45324 --- a/drivers/leds/leds-ss4200.c
45325 +++ b/drivers/leds/leds-ss4200.c
45326 @@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
45327 * detected as working, but in reality it is not) as low as
45328 * possible.
45329 */
45330 -static struct dmi_system_id nas_led_whitelist[] __initdata = {
45331 +static struct dmi_system_id nas_led_whitelist[] __initconst = {
45332 {
45333 .callback = ss4200_led_dmi_callback,
45334 .ident = "Intel SS4200-E",
45335 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
45336 index 6590558..a74c5dd 100644
45337 --- a/drivers/lguest/core.c
45338 +++ b/drivers/lguest/core.c
45339 @@ -96,9 +96,17 @@ static __init int map_switcher(void)
45340 * The end address needs +1 because __get_vm_area allocates an
45341 * extra guard page, so we need space for that.
45342 */
45343 +
45344 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
45345 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
45346 + VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
45347 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
45348 +#else
45349 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
45350 VM_ALLOC, switcher_addr, switcher_addr
45351 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
45352 +#endif
45353 +
45354 if (!switcher_vma) {
45355 err = -ENOMEM;
45356 printk("lguest: could not map switcher pages high\n");
45357 @@ -121,7 +129,7 @@ static __init int map_switcher(void)
45358 * Now the Switcher is mapped at the right address, we can't fail!
45359 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
45360 */
45361 - memcpy(switcher_vma->addr, start_switcher_text,
45362 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
45363 end_switcher_text - start_switcher_text);
45364
45365 printk(KERN_INFO "lguest: mapped switcher at %p\n",
45366 diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
45367 index e8b55c3..3514c37 100644
45368 --- a/drivers/lguest/page_tables.c
45369 +++ b/drivers/lguest/page_tables.c
45370 @@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
45371 /*:*/
45372
45373 #ifdef CONFIG_X86_PAE
45374 -static void release_pmd(pmd_t *spmd)
45375 +static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
45376 {
45377 /* If the entry's not present, there's nothing to release. */
45378 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
45379 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
45380 index 922a1ac..9dd0c2a 100644
45381 --- a/drivers/lguest/x86/core.c
45382 +++ b/drivers/lguest/x86/core.c
45383 @@ -59,7 +59,7 @@ static struct {
45384 /* Offset from where switcher.S was compiled to where we've copied it */
45385 static unsigned long switcher_offset(void)
45386 {
45387 - return switcher_addr - (unsigned long)start_switcher_text;
45388 + return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
45389 }
45390
45391 /* This cpu's struct lguest_pages (after the Switcher text page) */
45392 @@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
45393 * These copies are pretty cheap, so we do them unconditionally: */
45394 /* Save the current Host top-level page directory.
45395 */
45396 +
45397 +#ifdef CONFIG_PAX_PER_CPU_PGD
45398 + pages->state.host_cr3 = read_cr3();
45399 +#else
45400 pages->state.host_cr3 = __pa(current->mm->pgd);
45401 +#endif
45402 +
45403 /*
45404 * Set up the Guest's page tables to see this CPU's pages (and no
45405 * other CPU's pages).
45406 @@ -477,7 +483,7 @@ void __init lguest_arch_host_init(void)
45407 * compiled-in switcher code and the high-mapped copy we just made.
45408 */
45409 for (i = 0; i < IDT_ENTRIES; i++)
45410 - default_idt_entries[i] += switcher_offset();
45411 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
45412
45413 /*
45414 * Set up the Switcher's per-cpu areas.
45415 @@ -560,7 +566,7 @@ void __init lguest_arch_host_init(void)
45416 * it will be undisturbed when we switch. To change %cs and jump we
45417 * need this structure to feed to Intel's "lcall" instruction.
45418 */
45419 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
45420 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
45421 lguest_entry.segment = LGUEST_CS;
45422
45423 /*
45424 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
45425 index 40634b0..4f5855e 100644
45426 --- a/drivers/lguest/x86/switcher_32.S
45427 +++ b/drivers/lguest/x86/switcher_32.S
45428 @@ -87,6 +87,7 @@
45429 #include <asm/page.h>
45430 #include <asm/segment.h>
45431 #include <asm/lguest.h>
45432 +#include <asm/processor-flags.h>
45433
45434 // We mark the start of the code to copy
45435 // It's placed in .text tho it's never run here
45436 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
45437 // Changes type when we load it: damn Intel!
45438 // For after we switch over our page tables
45439 // That entry will be read-only: we'd crash.
45440 +
45441 +#ifdef CONFIG_PAX_KERNEXEC
45442 + mov %cr0, %edx
45443 + xor $X86_CR0_WP, %edx
45444 + mov %edx, %cr0
45445 +#endif
45446 +
45447 movl $(GDT_ENTRY_TSS*8), %edx
45448 ltr %dx
45449
45450 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
45451 // Let's clear it again for our return.
45452 // The GDT descriptor of the Host
45453 // Points to the table after two "size" bytes
45454 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
45455 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
45456 // Clear "used" from type field (byte 5, bit 2)
45457 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
45458 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
45459 +
45460 +#ifdef CONFIG_PAX_KERNEXEC
45461 + mov %cr0, %eax
45462 + xor $X86_CR0_WP, %eax
45463 + mov %eax, %cr0
45464 +#endif
45465
45466 // Once our page table's switched, the Guest is live!
45467 // The Host fades as we run this final step.
45468 @@ -295,13 +309,12 @@ deliver_to_host:
45469 // I consulted gcc, and it gave
45470 // These instructions, which I gladly credit:
45471 leal (%edx,%ebx,8), %eax
45472 - movzwl (%eax),%edx
45473 - movl 4(%eax), %eax
45474 - xorw %ax, %ax
45475 - orl %eax, %edx
45476 + movl 4(%eax), %edx
45477 + movw (%eax), %dx
45478 // Now the address of the handler's in %edx
45479 // We call it now: its "iret" drops us home.
45480 - jmp *%edx
45481 + ljmp $__KERNEL_CS, $1f
45482 +1: jmp *%edx
45483
45484 // Every interrupt can come to us here
45485 // But we must truly tell each apart.
45486 diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
45487 index a08e3ee..df8ade2 100644
45488 --- a/drivers/md/bcache/closure.h
45489 +++ b/drivers/md/bcache/closure.h
45490 @@ -238,7 +238,7 @@ static inline void closure_set_stopped(struct closure *cl)
45491 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
45492 struct workqueue_struct *wq)
45493 {
45494 - BUG_ON(object_is_on_stack(cl));
45495 + BUG_ON(object_starts_on_stack(cl));
45496 closure_set_ip(cl);
45497 cl->fn = fn;
45498 cl->wq = wq;
45499 diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
45500 index 67f8b31..9418f2b 100644
45501 --- a/drivers/md/bitmap.c
45502 +++ b/drivers/md/bitmap.c
45503 @@ -1775,7 +1775,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
45504 chunk_kb ? "KB" : "B");
45505 if (bitmap->storage.file) {
45506 seq_printf(seq, ", file: ");
45507 - seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
45508 + seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
45509 }
45510
45511 seq_printf(seq, "\n");
45512 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
45513 index 5152142..623d141 100644
45514 --- a/drivers/md/dm-ioctl.c
45515 +++ b/drivers/md/dm-ioctl.c
45516 @@ -1769,7 +1769,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
45517 cmd == DM_LIST_VERSIONS_CMD)
45518 return 0;
45519
45520 - if ((cmd == DM_DEV_CREATE_CMD)) {
45521 + if (cmd == DM_DEV_CREATE_CMD) {
45522 if (!*param->name) {
45523 DMWARN("name not supplied when creating device");
45524 return -EINVAL;
45525 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
45526 index 7dfdb5c..4caada6 100644
45527 --- a/drivers/md/dm-raid1.c
45528 +++ b/drivers/md/dm-raid1.c
45529 @@ -40,7 +40,7 @@ enum dm_raid1_error {
45530
45531 struct mirror {
45532 struct mirror_set *ms;
45533 - atomic_t error_count;
45534 + atomic_unchecked_t error_count;
45535 unsigned long error_type;
45536 struct dm_dev *dev;
45537 sector_t offset;
45538 @@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
45539 struct mirror *m;
45540
45541 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
45542 - if (!atomic_read(&m->error_count))
45543 + if (!atomic_read_unchecked(&m->error_count))
45544 return m;
45545
45546 return NULL;
45547 @@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
45548 * simple way to tell if a device has encountered
45549 * errors.
45550 */
45551 - atomic_inc(&m->error_count);
45552 + atomic_inc_unchecked(&m->error_count);
45553
45554 if (test_and_set_bit(error_type, &m->error_type))
45555 return;
45556 @@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
45557 struct mirror *m = get_default_mirror(ms);
45558
45559 do {
45560 - if (likely(!atomic_read(&m->error_count)))
45561 + if (likely(!atomic_read_unchecked(&m->error_count)))
45562 return m;
45563
45564 if (m-- == ms->mirror)
45565 @@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
45566 {
45567 struct mirror *default_mirror = get_default_mirror(m->ms);
45568
45569 - return !atomic_read(&default_mirror->error_count);
45570 + return !atomic_read_unchecked(&default_mirror->error_count);
45571 }
45572
45573 static int mirror_available(struct mirror_set *ms, struct bio *bio)
45574 @@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
45575 */
45576 if (likely(region_in_sync(ms, region, 1)))
45577 m = choose_mirror(ms, bio->bi_iter.bi_sector);
45578 - else if (m && atomic_read(&m->error_count))
45579 + else if (m && atomic_read_unchecked(&m->error_count))
45580 m = NULL;
45581
45582 if (likely(m))
45583 @@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
45584 }
45585
45586 ms->mirror[mirror].ms = ms;
45587 - atomic_set(&(ms->mirror[mirror].error_count), 0);
45588 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
45589 ms->mirror[mirror].error_type = 0;
45590 ms->mirror[mirror].offset = offset;
45591
45592 @@ -1342,7 +1342,7 @@ static void mirror_resume(struct dm_target *ti)
45593 */
45594 static char device_status_char(struct mirror *m)
45595 {
45596 - if (!atomic_read(&(m->error_count)))
45597 + if (!atomic_read_unchecked(&(m->error_count)))
45598 return 'A';
45599
45600 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
45601 diff --git a/drivers/md/dm-stats.c b/drivers/md/dm-stats.c
45602 index 28a9012..9c0f6a5 100644
45603 --- a/drivers/md/dm-stats.c
45604 +++ b/drivers/md/dm-stats.c
45605 @@ -382,7 +382,7 @@ do_sync_free:
45606 synchronize_rcu_expedited();
45607 dm_stat_free(&s->rcu_head);
45608 } else {
45609 - ACCESS_ONCE(dm_stat_need_rcu_barrier) = 1;
45610 + ACCESS_ONCE_RW(dm_stat_need_rcu_barrier) = 1;
45611 call_rcu(&s->rcu_head, dm_stat_free);
45612 }
45613 return 0;
45614 @@ -554,8 +554,8 @@ void dm_stats_account_io(struct dm_stats *stats, unsigned long bi_rw,
45615 ((bi_rw & (REQ_WRITE | REQ_DISCARD)) ==
45616 (ACCESS_ONCE(last->last_rw) & (REQ_WRITE | REQ_DISCARD)))
45617 ));
45618 - ACCESS_ONCE(last->last_sector) = end_sector;
45619 - ACCESS_ONCE(last->last_rw) = bi_rw;
45620 + ACCESS_ONCE_RW(last->last_sector) = end_sector;
45621 + ACCESS_ONCE_RW(last->last_rw) = bi_rw;
45622 }
45623
45624 rcu_read_lock();
45625 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
45626 index d1600d2..4c3af3a 100644
45627 --- a/drivers/md/dm-stripe.c
45628 +++ b/drivers/md/dm-stripe.c
45629 @@ -21,7 +21,7 @@ struct stripe {
45630 struct dm_dev *dev;
45631 sector_t physical_start;
45632
45633 - atomic_t error_count;
45634 + atomic_unchecked_t error_count;
45635 };
45636
45637 struct stripe_c {
45638 @@ -186,7 +186,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
45639 kfree(sc);
45640 return r;
45641 }
45642 - atomic_set(&(sc->stripe[i].error_count), 0);
45643 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
45644 }
45645
45646 ti->private = sc;
45647 @@ -330,7 +330,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
45648 DMEMIT("%d ", sc->stripes);
45649 for (i = 0; i < sc->stripes; i++) {
45650 DMEMIT("%s ", sc->stripe[i].dev->name);
45651 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
45652 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
45653 'D' : 'A';
45654 }
45655 buffer[i] = '\0';
45656 @@ -375,8 +375,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
45657 */
45658 for (i = 0; i < sc->stripes; i++)
45659 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
45660 - atomic_inc(&(sc->stripe[i].error_count));
45661 - if (atomic_read(&(sc->stripe[i].error_count)) <
45662 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
45663 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
45664 DM_IO_ERROR_THRESHOLD)
45665 schedule_work(&sc->trigger_event);
45666 }
45667 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
45668 index f9c6cb8..e272df6 100644
45669 --- a/drivers/md/dm-table.c
45670 +++ b/drivers/md/dm-table.c
45671 @@ -274,7 +274,7 @@ static struct dm_dev_internal *find_device(struct list_head *l, dev_t dev)
45672 static int open_dev(struct dm_dev_internal *d, dev_t dev,
45673 struct mapped_device *md)
45674 {
45675 - static char *_claim_ptr = "I belong to device-mapper";
45676 + static char _claim_ptr[] = "I belong to device-mapper";
45677 struct block_device *bdev;
45678
45679 int r;
45680 @@ -342,7 +342,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
45681 if (!dev_size)
45682 return 0;
45683
45684 - if ((start >= dev_size) || (start + len > dev_size)) {
45685 + if ((start >= dev_size) || (len > dev_size - start)) {
45686 DMWARN("%s: %s too small for target: "
45687 "start=%llu, len=%llu, dev_size=%llu",
45688 dm_device_name(ti->table->md), bdevname(bdev, b),
45689 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
45690 index e9d33ad..dae9880d 100644
45691 --- a/drivers/md/dm-thin-metadata.c
45692 +++ b/drivers/md/dm-thin-metadata.c
45693 @@ -404,7 +404,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
45694 {
45695 pmd->info.tm = pmd->tm;
45696 pmd->info.levels = 2;
45697 - pmd->info.value_type.context = pmd->data_sm;
45698 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
45699 pmd->info.value_type.size = sizeof(__le64);
45700 pmd->info.value_type.inc = data_block_inc;
45701 pmd->info.value_type.dec = data_block_dec;
45702 @@ -423,7 +423,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
45703
45704 pmd->bl_info.tm = pmd->tm;
45705 pmd->bl_info.levels = 1;
45706 - pmd->bl_info.value_type.context = pmd->data_sm;
45707 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
45708 pmd->bl_info.value_type.size = sizeof(__le64);
45709 pmd->bl_info.value_type.inc = data_block_inc;
45710 pmd->bl_info.value_type.dec = data_block_dec;
45711 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
45712 index 32b958d..34011e8 100644
45713 --- a/drivers/md/dm.c
45714 +++ b/drivers/md/dm.c
45715 @@ -180,9 +180,9 @@ struct mapped_device {
45716 /*
45717 * Event handling.
45718 */
45719 - atomic_t event_nr;
45720 + atomic_unchecked_t event_nr;
45721 wait_queue_head_t eventq;
45722 - atomic_t uevent_seq;
45723 + atomic_unchecked_t uevent_seq;
45724 struct list_head uevent_list;
45725 spinlock_t uevent_lock; /* Protect access to uevent_list */
45726
45727 @@ -1952,8 +1952,8 @@ static struct mapped_device *alloc_dev(int minor)
45728 spin_lock_init(&md->deferred_lock);
45729 atomic_set(&md->holders, 1);
45730 atomic_set(&md->open_count, 0);
45731 - atomic_set(&md->event_nr, 0);
45732 - atomic_set(&md->uevent_seq, 0);
45733 + atomic_set_unchecked(&md->event_nr, 0);
45734 + atomic_set_unchecked(&md->uevent_seq, 0);
45735 INIT_LIST_HEAD(&md->uevent_list);
45736 spin_lock_init(&md->uevent_lock);
45737
45738 @@ -2107,7 +2107,7 @@ static void event_callback(void *context)
45739
45740 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
45741
45742 - atomic_inc(&md->event_nr);
45743 + atomic_inc_unchecked(&md->event_nr);
45744 wake_up(&md->eventq);
45745 }
45746
45747 @@ -2800,18 +2800,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
45748
45749 uint32_t dm_next_uevent_seq(struct mapped_device *md)
45750 {
45751 - return atomic_add_return(1, &md->uevent_seq);
45752 + return atomic_add_return_unchecked(1, &md->uevent_seq);
45753 }
45754
45755 uint32_t dm_get_event_nr(struct mapped_device *md)
45756 {
45757 - return atomic_read(&md->event_nr);
45758 + return atomic_read_unchecked(&md->event_nr);
45759 }
45760
45761 int dm_wait_event(struct mapped_device *md, int event_nr)
45762 {
45763 return wait_event_interruptible(md->eventq,
45764 - (event_nr != atomic_read(&md->event_nr)));
45765 + (event_nr != atomic_read_unchecked(&md->event_nr)));
45766 }
45767
45768 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
45769 diff --git a/drivers/md/md.c b/drivers/md/md.c
45770 index b7f603c..723d2bd 100644
45771 --- a/drivers/md/md.c
45772 +++ b/drivers/md/md.c
45773 @@ -194,10 +194,10 @@ EXPORT_SYMBOL_GPL(bio_clone_mddev);
45774 * start build, activate spare
45775 */
45776 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
45777 -static atomic_t md_event_count;
45778 +static atomic_unchecked_t md_event_count;
45779 void md_new_event(struct mddev *mddev)
45780 {
45781 - atomic_inc(&md_event_count);
45782 + atomic_inc_unchecked(&md_event_count);
45783 wake_up(&md_event_waiters);
45784 }
45785 EXPORT_SYMBOL_GPL(md_new_event);
45786 @@ -207,7 +207,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
45787 */
45788 static void md_new_event_inintr(struct mddev *mddev)
45789 {
45790 - atomic_inc(&md_event_count);
45791 + atomic_inc_unchecked(&md_event_count);
45792 wake_up(&md_event_waiters);
45793 }
45794
45795 @@ -1462,7 +1462,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
45796 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
45797 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
45798 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
45799 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
45800 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
45801
45802 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
45803 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
45804 @@ -1713,7 +1713,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
45805 else
45806 sb->resync_offset = cpu_to_le64(0);
45807
45808 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
45809 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
45810
45811 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
45812 sb->size = cpu_to_le64(mddev->dev_sectors);
45813 @@ -2725,7 +2725,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
45814 static ssize_t
45815 errors_show(struct md_rdev *rdev, char *page)
45816 {
45817 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
45818 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
45819 }
45820
45821 static ssize_t
45822 @@ -2734,7 +2734,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
45823 char *e;
45824 unsigned long n = simple_strtoul(buf, &e, 10);
45825 if (*buf && (*e == 0 || *e == '\n')) {
45826 - atomic_set(&rdev->corrected_errors, n);
45827 + atomic_set_unchecked(&rdev->corrected_errors, n);
45828 return len;
45829 }
45830 return -EINVAL;
45831 @@ -3183,8 +3183,8 @@ int md_rdev_init(struct md_rdev *rdev)
45832 rdev->sb_loaded = 0;
45833 rdev->bb_page = NULL;
45834 atomic_set(&rdev->nr_pending, 0);
45835 - atomic_set(&rdev->read_errors, 0);
45836 - atomic_set(&rdev->corrected_errors, 0);
45837 + atomic_set_unchecked(&rdev->read_errors, 0);
45838 + atomic_set_unchecked(&rdev->corrected_errors, 0);
45839
45840 INIT_LIST_HEAD(&rdev->same_set);
45841 init_waitqueue_head(&rdev->blocked_wait);
45842 @@ -7072,7 +7072,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
45843
45844 spin_unlock(&pers_lock);
45845 seq_printf(seq, "\n");
45846 - seq->poll_event = atomic_read(&md_event_count);
45847 + seq->poll_event = atomic_read_unchecked(&md_event_count);
45848 return 0;
45849 }
45850 if (v == (void*)2) {
45851 @@ -7175,7 +7175,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
45852 return error;
45853
45854 seq = file->private_data;
45855 - seq->poll_event = atomic_read(&md_event_count);
45856 + seq->poll_event = atomic_read_unchecked(&md_event_count);
45857 return error;
45858 }
45859
45860 @@ -7192,7 +7192,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
45861 /* always allow read */
45862 mask = POLLIN | POLLRDNORM;
45863
45864 - if (seq->poll_event != atomic_read(&md_event_count))
45865 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
45866 mask |= POLLERR | POLLPRI;
45867 return mask;
45868 }
45869 @@ -7236,7 +7236,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
45870 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
45871 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
45872 (int)part_stat_read(&disk->part0, sectors[1]) -
45873 - atomic_read(&disk->sync_io);
45874 + atomic_read_unchecked(&disk->sync_io);
45875 /* sync IO will cause sync_io to increase before the disk_stats
45876 * as sync_io is counted when a request starts, and
45877 * disk_stats is counted when it completes.
45878 diff --git a/drivers/md/md.h b/drivers/md/md.h
45879 index a49d991..3582bb7 100644
45880 --- a/drivers/md/md.h
45881 +++ b/drivers/md/md.h
45882 @@ -94,13 +94,13 @@ struct md_rdev {
45883 * only maintained for arrays that
45884 * support hot removal
45885 */
45886 - atomic_t read_errors; /* number of consecutive read errors that
45887 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
45888 * we have tried to ignore.
45889 */
45890 struct timespec last_read_error; /* monotonic time since our
45891 * last read error
45892 */
45893 - atomic_t corrected_errors; /* number of corrected read errors,
45894 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
45895 * for reporting to userspace and storing
45896 * in superblock.
45897 */
45898 @@ -449,7 +449,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
45899
45900 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
45901 {
45902 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
45903 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
45904 }
45905
45906 struct md_personality
45907 diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
45908 index 786b689..ea8c956 100644
45909 --- a/drivers/md/persistent-data/dm-space-map-metadata.c
45910 +++ b/drivers/md/persistent-data/dm-space-map-metadata.c
45911 @@ -679,7 +679,7 @@ static int sm_metadata_extend(struct dm_space_map *sm, dm_block_t extra_blocks)
45912 * Flick into a mode where all blocks get allocated in the new area.
45913 */
45914 smm->begin = old_len;
45915 - memcpy(sm, &bootstrap_ops, sizeof(*sm));
45916 + memcpy((void *)sm, &bootstrap_ops, sizeof(*sm));
45917
45918 /*
45919 * Extend.
45920 @@ -710,7 +710,7 @@ out:
45921 /*
45922 * Switch back to normal behaviour.
45923 */
45924 - memcpy(sm, &ops, sizeof(*sm));
45925 + memcpy((void *)sm, &ops, sizeof(*sm));
45926 return r;
45927 }
45928
45929 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
45930 index 3e6d115..ffecdeb 100644
45931 --- a/drivers/md/persistent-data/dm-space-map.h
45932 +++ b/drivers/md/persistent-data/dm-space-map.h
45933 @@ -71,6 +71,7 @@ struct dm_space_map {
45934 dm_sm_threshold_fn fn,
45935 void *context);
45936 };
45937 +typedef struct dm_space_map __no_const dm_space_map_no_const;
45938
45939 /*----------------------------------------------------------------*/
45940
45941 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
45942 index 55de4f6..b1c57fe 100644
45943 --- a/drivers/md/raid1.c
45944 +++ b/drivers/md/raid1.c
45945 @@ -1936,7 +1936,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
45946 if (r1_sync_page_io(rdev, sect, s,
45947 bio->bi_io_vec[idx].bv_page,
45948 READ) != 0)
45949 - atomic_add(s, &rdev->corrected_errors);
45950 + atomic_add_unchecked(s, &rdev->corrected_errors);
45951 }
45952 sectors -= s;
45953 sect += s;
45954 @@ -2170,7 +2170,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
45955 !test_bit(Faulty, &rdev->flags)) {
45956 if (r1_sync_page_io(rdev, sect, s,
45957 conf->tmppage, READ)) {
45958 - atomic_add(s, &rdev->corrected_errors);
45959 + atomic_add_unchecked(s, &rdev->corrected_errors);
45960 printk(KERN_INFO
45961 "md/raid1:%s: read error corrected "
45962 "(%d sectors at %llu on %s)\n",
45963 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
45964 index 6703751..187af1e 100644
45965 --- a/drivers/md/raid10.c
45966 +++ b/drivers/md/raid10.c
45967 @@ -1948,7 +1948,7 @@ static void end_sync_read(struct bio *bio, int error)
45968 /* The write handler will notice the lack of
45969 * R10BIO_Uptodate and record any errors etc
45970 */
45971 - atomic_add(r10_bio->sectors,
45972 + atomic_add_unchecked(r10_bio->sectors,
45973 &conf->mirrors[d].rdev->corrected_errors);
45974
45975 /* for reconstruct, we always reschedule after a read.
45976 @@ -2306,7 +2306,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
45977 {
45978 struct timespec cur_time_mon;
45979 unsigned long hours_since_last;
45980 - unsigned int read_errors = atomic_read(&rdev->read_errors);
45981 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
45982
45983 ktime_get_ts(&cur_time_mon);
45984
45985 @@ -2328,9 +2328,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
45986 * overflowing the shift of read_errors by hours_since_last.
45987 */
45988 if (hours_since_last >= 8 * sizeof(read_errors))
45989 - atomic_set(&rdev->read_errors, 0);
45990 + atomic_set_unchecked(&rdev->read_errors, 0);
45991 else
45992 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
45993 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
45994 }
45995
45996 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
45997 @@ -2384,8 +2384,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
45998 return;
45999
46000 check_decay_read_errors(mddev, rdev);
46001 - atomic_inc(&rdev->read_errors);
46002 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
46003 + atomic_inc_unchecked(&rdev->read_errors);
46004 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
46005 char b[BDEVNAME_SIZE];
46006 bdevname(rdev->bdev, b);
46007
46008 @@ -2393,7 +2393,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
46009 "md/raid10:%s: %s: Raid device exceeded "
46010 "read_error threshold [cur %d:max %d]\n",
46011 mdname(mddev), b,
46012 - atomic_read(&rdev->read_errors), max_read_errors);
46013 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
46014 printk(KERN_NOTICE
46015 "md/raid10:%s: %s: Failing raid device\n",
46016 mdname(mddev), b);
46017 @@ -2548,7 +2548,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
46018 sect +
46019 choose_data_offset(r10_bio, rdev)),
46020 bdevname(rdev->bdev, b));
46021 - atomic_add(s, &rdev->corrected_errors);
46022 + atomic_add_unchecked(s, &rdev->corrected_errors);
46023 }
46024
46025 rdev_dec_pending(rdev, mddev);
46026 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
46027 index 9f0fbec..991e7a1 100644
46028 --- a/drivers/md/raid5.c
46029 +++ b/drivers/md/raid5.c
46030 @@ -1735,6 +1735,10 @@ static int grow_one_stripe(struct r5conf *conf, int hash)
46031 return 1;
46032 }
46033
46034 +#ifdef CONFIG_GRKERNSEC_HIDESYM
46035 +static atomic_unchecked_t raid5_cache_id = ATOMIC_INIT(0);
46036 +#endif
46037 +
46038 static int grow_stripes(struct r5conf *conf, int num)
46039 {
46040 struct kmem_cache *sc;
46041 @@ -1746,7 +1750,11 @@ static int grow_stripes(struct r5conf *conf, int num)
46042 "raid%d-%s", conf->level, mdname(conf->mddev));
46043 else
46044 sprintf(conf->cache_name[0],
46045 +#ifdef CONFIG_GRKERNSEC_HIDESYM
46046 + "raid%d-%08lx", conf->level, atomic_inc_return_unchecked(&raid5_cache_id));
46047 +#else
46048 "raid%d-%p", conf->level, conf->mddev);
46049 +#endif
46050 sprintf(conf->cache_name[1], "%s-alt", conf->cache_name[0]);
46051
46052 conf->active_name = 0;
46053 @@ -2022,21 +2030,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
46054 mdname(conf->mddev), STRIPE_SECTORS,
46055 (unsigned long long)s,
46056 bdevname(rdev->bdev, b));
46057 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
46058 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
46059 clear_bit(R5_ReadError, &sh->dev[i].flags);
46060 clear_bit(R5_ReWrite, &sh->dev[i].flags);
46061 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
46062 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
46063
46064 - if (atomic_read(&rdev->read_errors))
46065 - atomic_set(&rdev->read_errors, 0);
46066 + if (atomic_read_unchecked(&rdev->read_errors))
46067 + atomic_set_unchecked(&rdev->read_errors, 0);
46068 } else {
46069 const char *bdn = bdevname(rdev->bdev, b);
46070 int retry = 0;
46071 int set_bad = 0;
46072
46073 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
46074 - atomic_inc(&rdev->read_errors);
46075 + atomic_inc_unchecked(&rdev->read_errors);
46076 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
46077 printk_ratelimited(
46078 KERN_WARNING
46079 @@ -2064,7 +2072,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
46080 mdname(conf->mddev),
46081 (unsigned long long)s,
46082 bdn);
46083 - } else if (atomic_read(&rdev->read_errors)
46084 + } else if (atomic_read_unchecked(&rdev->read_errors)
46085 > conf->max_nr_stripes)
46086 printk(KERN_WARNING
46087 "md/raid:%s: Too many read errors, failing device %s.\n",
46088 diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
46089 index 983db75..ef9248c 100644
46090 --- a/drivers/media/dvb-core/dvbdev.c
46091 +++ b/drivers/media/dvb-core/dvbdev.c
46092 @@ -185,7 +185,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
46093 const struct dvb_device *template, void *priv, int type)
46094 {
46095 struct dvb_device *dvbdev;
46096 - struct file_operations *dvbdevfops;
46097 + file_operations_no_const *dvbdevfops;
46098 struct device *clsdev;
46099 int minor;
46100 int id;
46101 diff --git a/drivers/media/dvb-frontends/af9033.h b/drivers/media/dvb-frontends/af9033.h
46102 index 539f4db..cdd403b 100644
46103 --- a/drivers/media/dvb-frontends/af9033.h
46104 +++ b/drivers/media/dvb-frontends/af9033.h
46105 @@ -82,7 +82,7 @@ struct af9033_ops {
46106 int (*pid_filter_ctrl)(struct dvb_frontend *fe, int onoff);
46107 int (*pid_filter)(struct dvb_frontend *fe, int index, u16 pid,
46108 int onoff);
46109 -};
46110 +} __no_const;
46111
46112
46113 #if IS_ENABLED(CONFIG_DVB_AF9033)
46114 diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
46115 index 9b6c3bb..baeb5c7 100644
46116 --- a/drivers/media/dvb-frontends/dib3000.h
46117 +++ b/drivers/media/dvb-frontends/dib3000.h
46118 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
46119 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
46120 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
46121 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
46122 -};
46123 +} __no_const;
46124
46125 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
46126 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
46127 diff --git a/drivers/media/dvb-frontends/dib7000p.h b/drivers/media/dvb-frontends/dib7000p.h
46128 index 1fea0e9..321ce8f 100644
46129 --- a/drivers/media/dvb-frontends/dib7000p.h
46130 +++ b/drivers/media/dvb-frontends/dib7000p.h
46131 @@ -64,7 +64,7 @@ struct dib7000p_ops {
46132 int (*get_adc_power)(struct dvb_frontend *fe);
46133 int (*slave_reset)(struct dvb_frontend *fe);
46134 struct dvb_frontend *(*init)(struct i2c_adapter *i2c_adap, u8 i2c_addr, struct dib7000p_config *cfg);
46135 -};
46136 +} __no_const;
46137
46138 #if IS_ENABLED(CONFIG_DVB_DIB7000P)
46139 void *dib7000p_attach(struct dib7000p_ops *ops);
46140 diff --git a/drivers/media/dvb-frontends/dib8000.h b/drivers/media/dvb-frontends/dib8000.h
46141 index 84cc103..5780c54 100644
46142 --- a/drivers/media/dvb-frontends/dib8000.h
46143 +++ b/drivers/media/dvb-frontends/dib8000.h
46144 @@ -61,7 +61,7 @@ struct dib8000_ops {
46145 int (*pid_filter_ctrl)(struct dvb_frontend *fe, u8 onoff);
46146 int (*pid_filter)(struct dvb_frontend *fe, u8 id, u16 pid, u8 onoff);
46147 struct dvb_frontend *(*init)(struct i2c_adapter *i2c_adap, u8 i2c_addr, struct dib8000_config *cfg);
46148 -};
46149 +} __no_const;
46150
46151 #if IS_ENABLED(CONFIG_DVB_DIB8000)
46152 void *dib8000_attach(struct dib8000_ops *ops);
46153 diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
46154 index ed8cb90..5ef7f79 100644
46155 --- a/drivers/media/pci/cx88/cx88-video.c
46156 +++ b/drivers/media/pci/cx88/cx88-video.c
46157 @@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
46158
46159 /* ------------------------------------------------------------------ */
46160
46161 -static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
46162 -static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
46163 -static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
46164 +static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
46165 +static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
46166 +static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
46167
46168 module_param_array(video_nr, int, NULL, 0444);
46169 module_param_array(vbi_nr, int, NULL, 0444);
46170 diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
46171 index 802642d..5534900 100644
46172 --- a/drivers/media/pci/ivtv/ivtv-driver.c
46173 +++ b/drivers/media/pci/ivtv/ivtv-driver.c
46174 @@ -83,7 +83,7 @@ static struct pci_device_id ivtv_pci_tbl[] = {
46175 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
46176
46177 /* ivtv instance counter */
46178 -static atomic_t ivtv_instance = ATOMIC_INIT(0);
46179 +static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
46180
46181 /* Parameter declarations */
46182 static int cardtype[IVTV_MAX_CARDS];
46183 diff --git a/drivers/media/pci/solo6x10/solo6x10-core.c b/drivers/media/pci/solo6x10/solo6x10-core.c
46184 index 172583d..0f806f4 100644
46185 --- a/drivers/media/pci/solo6x10/solo6x10-core.c
46186 +++ b/drivers/media/pci/solo6x10/solo6x10-core.c
46187 @@ -430,7 +430,7 @@ static void solo_device_release(struct device *dev)
46188
46189 static int solo_sysfs_init(struct solo_dev *solo_dev)
46190 {
46191 - struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
46192 + bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
46193 struct device *dev = &solo_dev->dev;
46194 const char *driver;
46195 int i;
46196 diff --git a/drivers/media/pci/solo6x10/solo6x10-g723.c b/drivers/media/pci/solo6x10/solo6x10-g723.c
46197 index c7141f2..5301fec 100644
46198 --- a/drivers/media/pci/solo6x10/solo6x10-g723.c
46199 +++ b/drivers/media/pci/solo6x10/solo6x10-g723.c
46200 @@ -351,7 +351,7 @@ static int solo_snd_pcm_init(struct solo_dev *solo_dev)
46201
46202 int solo_g723_init(struct solo_dev *solo_dev)
46203 {
46204 - static struct snd_device_ops ops = { NULL };
46205 + static struct snd_device_ops ops = { };
46206 struct snd_card *card;
46207 struct snd_kcontrol_new kctl;
46208 char name[32];
46209 diff --git a/drivers/media/pci/solo6x10/solo6x10-p2m.c b/drivers/media/pci/solo6x10/solo6x10-p2m.c
46210 index 8c84846..27b4f83 100644
46211 --- a/drivers/media/pci/solo6x10/solo6x10-p2m.c
46212 +++ b/drivers/media/pci/solo6x10/solo6x10-p2m.c
46213 @@ -73,7 +73,7 @@ int solo_p2m_dma_desc(struct solo_dev *solo_dev,
46214
46215 /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
46216 if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
46217 - p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
46218 + p2m_id = atomic_inc_return_unchecked(&solo_dev->p2m_count) % SOLO_NR_P2M;
46219 if (p2m_id < 0)
46220 p2m_id = -p2m_id;
46221 }
46222 diff --git a/drivers/media/pci/solo6x10/solo6x10.h b/drivers/media/pci/solo6x10/solo6x10.h
46223 index c6154b0..73e4ae9 100644
46224 --- a/drivers/media/pci/solo6x10/solo6x10.h
46225 +++ b/drivers/media/pci/solo6x10/solo6x10.h
46226 @@ -219,7 +219,7 @@ struct solo_dev {
46227
46228 /* P2M DMA Engine */
46229 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
46230 - atomic_t p2m_count;
46231 + atomic_unchecked_t p2m_count;
46232 int p2m_jiffies;
46233 unsigned int p2m_timeouts;
46234
46235 diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
46236 index 2d177fa..5b925a1 100644
46237 --- a/drivers/media/platform/omap/omap_vout.c
46238 +++ b/drivers/media/platform/omap/omap_vout.c
46239 @@ -63,7 +63,6 @@ enum omap_vout_channels {
46240 OMAP_VIDEO2,
46241 };
46242
46243 -static struct videobuf_queue_ops video_vbq_ops;
46244 /* Variables configurable through module params*/
46245 static u32 video1_numbuffers = 3;
46246 static u32 video2_numbuffers = 3;
46247 @@ -1014,6 +1013,12 @@ static int omap_vout_open(struct file *file)
46248 {
46249 struct videobuf_queue *q;
46250 struct omap_vout_device *vout = NULL;
46251 + static struct videobuf_queue_ops video_vbq_ops = {
46252 + .buf_setup = omap_vout_buffer_setup,
46253 + .buf_prepare = omap_vout_buffer_prepare,
46254 + .buf_release = omap_vout_buffer_release,
46255 + .buf_queue = omap_vout_buffer_queue,
46256 + };
46257
46258 vout = video_drvdata(file);
46259 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
46260 @@ -1031,10 +1036,6 @@ static int omap_vout_open(struct file *file)
46261 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
46262
46263 q = &vout->vbq;
46264 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
46265 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
46266 - video_vbq_ops.buf_release = omap_vout_buffer_release;
46267 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
46268 spin_lock_init(&vout->vbq_lock);
46269
46270 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
46271 diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
46272 index fb2acc5..a2fcbdc4 100644
46273 --- a/drivers/media/platform/s5p-tv/mixer.h
46274 +++ b/drivers/media/platform/s5p-tv/mixer.h
46275 @@ -156,7 +156,7 @@ struct mxr_layer {
46276 /** layer index (unique identifier) */
46277 int idx;
46278 /** callbacks for layer methods */
46279 - struct mxr_layer_ops ops;
46280 + struct mxr_layer_ops *ops;
46281 /** format array */
46282 const struct mxr_format **fmt_array;
46283 /** size of format array */
46284 diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
46285 index 74344c7..a39e70e 100644
46286 --- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
46287 +++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
46288 @@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
46289 {
46290 struct mxr_layer *layer;
46291 int ret;
46292 - struct mxr_layer_ops ops = {
46293 + static struct mxr_layer_ops ops = {
46294 .release = mxr_graph_layer_release,
46295 .buffer_set = mxr_graph_buffer_set,
46296 .stream_set = mxr_graph_stream_set,
46297 diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
46298 index b713403..53cb5ad 100644
46299 --- a/drivers/media/platform/s5p-tv/mixer_reg.c
46300 +++ b/drivers/media/platform/s5p-tv/mixer_reg.c
46301 @@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
46302 layer->update_buf = next;
46303 }
46304
46305 - layer->ops.buffer_set(layer, layer->update_buf);
46306 + layer->ops->buffer_set(layer, layer->update_buf);
46307
46308 if (done && done != layer->shadow_buf)
46309 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
46310 diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
46311 index b4d2696..91df48e 100644
46312 --- a/drivers/media/platform/s5p-tv/mixer_video.c
46313 +++ b/drivers/media/platform/s5p-tv/mixer_video.c
46314 @@ -210,7 +210,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
46315 layer->geo.src.height = layer->geo.src.full_height;
46316
46317 mxr_geometry_dump(mdev, &layer->geo);
46318 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
46319 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
46320 mxr_geometry_dump(mdev, &layer->geo);
46321 }
46322
46323 @@ -228,7 +228,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
46324 layer->geo.dst.full_width = mbus_fmt.width;
46325 layer->geo.dst.full_height = mbus_fmt.height;
46326 layer->geo.dst.field = mbus_fmt.field;
46327 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
46328 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
46329
46330 mxr_geometry_dump(mdev, &layer->geo);
46331 }
46332 @@ -334,7 +334,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
46333 /* set source size to highest accepted value */
46334 geo->src.full_width = max(geo->dst.full_width, pix->width);
46335 geo->src.full_height = max(geo->dst.full_height, pix->height);
46336 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
46337 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
46338 mxr_geometry_dump(mdev, &layer->geo);
46339 /* set cropping to total visible screen */
46340 geo->src.width = pix->width;
46341 @@ -342,12 +342,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
46342 geo->src.x_offset = 0;
46343 geo->src.y_offset = 0;
46344 /* assure consistency of geometry */
46345 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
46346 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
46347 mxr_geometry_dump(mdev, &layer->geo);
46348 /* set full size to lowest possible value */
46349 geo->src.full_width = 0;
46350 geo->src.full_height = 0;
46351 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
46352 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
46353 mxr_geometry_dump(mdev, &layer->geo);
46354
46355 /* returning results */
46356 @@ -474,7 +474,7 @@ static int mxr_s_selection(struct file *file, void *fh,
46357 target->width = s->r.width;
46358 target->height = s->r.height;
46359
46360 - layer->ops.fix_geometry(layer, stage, s->flags);
46361 + layer->ops->fix_geometry(layer, stage, s->flags);
46362
46363 /* retrieve update selection rectangle */
46364 res.left = target->x_offset;
46365 @@ -954,13 +954,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
46366 mxr_output_get(mdev);
46367
46368 mxr_layer_update_output(layer);
46369 - layer->ops.format_set(layer);
46370 + layer->ops->format_set(layer);
46371 /* enabling layer in hardware */
46372 spin_lock_irqsave(&layer->enq_slock, flags);
46373 layer->state = MXR_LAYER_STREAMING;
46374 spin_unlock_irqrestore(&layer->enq_slock, flags);
46375
46376 - layer->ops.stream_set(layer, MXR_ENABLE);
46377 + layer->ops->stream_set(layer, MXR_ENABLE);
46378 mxr_streamer_get(mdev);
46379
46380 return 0;
46381 @@ -1030,7 +1030,7 @@ static void stop_streaming(struct vb2_queue *vq)
46382 spin_unlock_irqrestore(&layer->enq_slock, flags);
46383
46384 /* disabling layer in hardware */
46385 - layer->ops.stream_set(layer, MXR_DISABLE);
46386 + layer->ops->stream_set(layer, MXR_DISABLE);
46387 /* remove one streamer */
46388 mxr_streamer_put(mdev);
46389 /* allow changes in output configuration */
46390 @@ -1068,8 +1068,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
46391
46392 void mxr_layer_release(struct mxr_layer *layer)
46393 {
46394 - if (layer->ops.release)
46395 - layer->ops.release(layer);
46396 + if (layer->ops->release)
46397 + layer->ops->release(layer);
46398 }
46399
46400 void mxr_base_layer_release(struct mxr_layer *layer)
46401 @@ -1095,7 +1095,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
46402
46403 layer->mdev = mdev;
46404 layer->idx = idx;
46405 - layer->ops = *ops;
46406 + layer->ops = ops;
46407
46408 spin_lock_init(&layer->enq_slock);
46409 INIT_LIST_HEAD(&layer->enq_list);
46410 diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
46411 index c9388c4..ce71ece 100644
46412 --- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
46413 +++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
46414 @@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
46415 {
46416 struct mxr_layer *layer;
46417 int ret;
46418 - struct mxr_layer_ops ops = {
46419 + static struct mxr_layer_ops ops = {
46420 .release = mxr_vp_layer_release,
46421 .buffer_set = mxr_vp_buffer_set,
46422 .stream_set = mxr_vp_stream_set,
46423 diff --git a/drivers/media/platform/vivi.c b/drivers/media/platform/vivi.c
46424 index 8033371..de5bca0 100644
46425 --- a/drivers/media/platform/vivi.c
46426 +++ b/drivers/media/platform/vivi.c
46427 @@ -58,8 +58,8 @@ MODULE_AUTHOR("Mauro Carvalho Chehab, Ted Walther and John Sokol");
46428 MODULE_LICENSE("Dual BSD/GPL");
46429 MODULE_VERSION(VIVI_VERSION);
46430
46431 -static unsigned video_nr = -1;
46432 -module_param(video_nr, uint, 0644);
46433 +static int video_nr = -1;
46434 +module_param(video_nr, int, 0644);
46435 MODULE_PARM_DESC(video_nr, "videoX start number, -1 is autodetect");
46436
46437 static unsigned n_devs = 1;
46438 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
46439 index 82affae..42833ec 100644
46440 --- a/drivers/media/radio/radio-cadet.c
46441 +++ b/drivers/media/radio/radio-cadet.c
46442 @@ -333,6 +333,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
46443 unsigned char readbuf[RDS_BUFFER];
46444 int i = 0;
46445
46446 + if (count > RDS_BUFFER)
46447 + return -EFAULT;
46448 mutex_lock(&dev->lock);
46449 if (dev->rdsstat == 0)
46450 cadet_start_rds(dev);
46451 @@ -349,8 +351,9 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
46452 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
46453 mutex_unlock(&dev->lock);
46454
46455 - if (i && copy_to_user(data, readbuf, i))
46456 - return -EFAULT;
46457 + if (i > sizeof(readbuf) || (i && copy_to_user(data, readbuf, i)))
46458 + i = -EFAULT;
46459 +
46460 return i;
46461 }
46462
46463 diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
46464 index 5236035..c622c74 100644
46465 --- a/drivers/media/radio/radio-maxiradio.c
46466 +++ b/drivers/media/radio/radio-maxiradio.c
46467 @@ -61,7 +61,7 @@ MODULE_PARM_DESC(radio_nr, "Radio device number");
46468 /* TEA5757 pin mappings */
46469 static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
46470
46471 -static atomic_t maxiradio_instance = ATOMIC_INIT(0);
46472 +static atomic_unchecked_t maxiradio_instance = ATOMIC_INIT(0);
46473
46474 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
46475 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
46476 diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
46477 index 050b3bb..79f62b9 100644
46478 --- a/drivers/media/radio/radio-shark.c
46479 +++ b/drivers/media/radio/radio-shark.c
46480 @@ -79,7 +79,7 @@ struct shark_device {
46481 u32 last_val;
46482 };
46483
46484 -static atomic_t shark_instance = ATOMIC_INIT(0);
46485 +static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
46486
46487 static void shark_write_val(struct snd_tea575x *tea, u32 val)
46488 {
46489 diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
46490 index 8654e0d..0608a64 100644
46491 --- a/drivers/media/radio/radio-shark2.c
46492 +++ b/drivers/media/radio/radio-shark2.c
46493 @@ -74,7 +74,7 @@ struct shark_device {
46494 u8 *transfer_buffer;
46495 };
46496
46497 -static atomic_t shark_instance = ATOMIC_INIT(0);
46498 +static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
46499
46500 static int shark_write_reg(struct radio_tea5777 *tea, u64 reg)
46501 {
46502 diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
46503 index 633022b..7f10754 100644
46504 --- a/drivers/media/radio/radio-si476x.c
46505 +++ b/drivers/media/radio/radio-si476x.c
46506 @@ -1445,7 +1445,7 @@ static int si476x_radio_probe(struct platform_device *pdev)
46507 struct si476x_radio *radio;
46508 struct v4l2_ctrl *ctrl;
46509
46510 - static atomic_t instance = ATOMIC_INIT(0);
46511 + static atomic_unchecked_t instance = ATOMIC_INIT(0);
46512
46513 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
46514 if (!radio)
46515 diff --git a/drivers/media/usb/dvb-usb/cinergyT2-core.c b/drivers/media/usb/dvb-usb/cinergyT2-core.c
46516 index 9fd1527..8927230 100644
46517 --- a/drivers/media/usb/dvb-usb/cinergyT2-core.c
46518 +++ b/drivers/media/usb/dvb-usb/cinergyT2-core.c
46519 @@ -50,29 +50,73 @@ static struct dvb_usb_device_properties cinergyt2_properties;
46520
46521 static int cinergyt2_streaming_ctrl(struct dvb_usb_adapter *adap, int enable)
46522 {
46523 - char buf[] = { CINERGYT2_EP1_CONTROL_STREAM_TRANSFER, enable ? 1 : 0 };
46524 - char result[64];
46525 - return dvb_usb_generic_rw(adap->dev, buf, sizeof(buf), result,
46526 - sizeof(result), 0);
46527 + char *buf;
46528 + char *result;
46529 + int retval;
46530 +
46531 + buf = kmalloc(2, GFP_KERNEL);
46532 + if (buf == NULL)
46533 + return -ENOMEM;
46534 + result = kmalloc(64, GFP_KERNEL);
46535 + if (result == NULL) {
46536 + kfree(buf);
46537 + return -ENOMEM;
46538 + }
46539 +
46540 + buf[0] = CINERGYT2_EP1_CONTROL_STREAM_TRANSFER;
46541 + buf[1] = enable ? 1 : 0;
46542 +
46543 + retval = dvb_usb_generic_rw(adap->dev, buf, 2, result, 64, 0);
46544 +
46545 + kfree(buf);
46546 + kfree(result);
46547 + return retval;
46548 }
46549
46550 static int cinergyt2_power_ctrl(struct dvb_usb_device *d, int enable)
46551 {
46552 - char buf[] = { CINERGYT2_EP1_SLEEP_MODE, enable ? 0 : 1 };
46553 - char state[3];
46554 - return dvb_usb_generic_rw(d, buf, sizeof(buf), state, sizeof(state), 0);
46555 + char *buf;
46556 + char *state;
46557 + int retval;
46558 +
46559 + buf = kmalloc(2, GFP_KERNEL);
46560 + if (buf == NULL)
46561 + return -ENOMEM;
46562 + state = kmalloc(3, GFP_KERNEL);
46563 + if (state == NULL) {
46564 + kfree(buf);
46565 + return -ENOMEM;
46566 + }
46567 +
46568 + buf[0] = CINERGYT2_EP1_SLEEP_MODE;
46569 + buf[1] = enable ? 1 : 0;
46570 +
46571 + retval = dvb_usb_generic_rw(d, buf, 2, state, 3, 0);
46572 +
46573 + kfree(buf);
46574 + kfree(state);
46575 + return retval;
46576 }
46577
46578 static int cinergyt2_frontend_attach(struct dvb_usb_adapter *adap)
46579 {
46580 - char query[] = { CINERGYT2_EP1_GET_FIRMWARE_VERSION };
46581 - char state[3];
46582 + char *query;
46583 + char *state;
46584 int ret;
46585 + query = kmalloc(1, GFP_KERNEL);
46586 + if (query == NULL)
46587 + return -ENOMEM;
46588 + state = kmalloc(3, GFP_KERNEL);
46589 + if (state == NULL) {
46590 + kfree(query);
46591 + return -ENOMEM;
46592 + }
46593 +
46594 + query[0] = CINERGYT2_EP1_GET_FIRMWARE_VERSION;
46595
46596 adap->fe_adap[0].fe = cinergyt2_fe_attach(adap->dev);
46597
46598 - ret = dvb_usb_generic_rw(adap->dev, query, sizeof(query), state,
46599 - sizeof(state), 0);
46600 + ret = dvb_usb_generic_rw(adap->dev, query, 1, state, 3, 0);
46601 if (ret < 0) {
46602 deb_rc("cinergyt2_power_ctrl() Failed to retrieve sleep "
46603 "state info\n");
46604 @@ -80,7 +124,8 @@ static int cinergyt2_frontend_attach(struct dvb_usb_adapter *adap)
46605
46606 /* Copy this pointer as we are gonna need it in the release phase */
46607 cinergyt2_usb_device = adap->dev;
46608 -
46609 + kfree(query);
46610 + kfree(state);
46611 return 0;
46612 }
46613
46614 @@ -141,12 +186,23 @@ static int repeatable_keys[] = {
46615 static int cinergyt2_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
46616 {
46617 struct cinergyt2_state *st = d->priv;
46618 - u8 key[5] = {0, 0, 0, 0, 0}, cmd = CINERGYT2_EP1_GET_RC_EVENTS;
46619 + u8 *key, *cmd;
46620 int i;
46621
46622 + cmd = kmalloc(1, GFP_KERNEL);
46623 + if (cmd == NULL)
46624 + return -EINVAL;
46625 + key = kzalloc(5, GFP_KERNEL);
46626 + if (key == NULL) {
46627 + kfree(cmd);
46628 + return -EINVAL;
46629 + }
46630 +
46631 + cmd[0] = CINERGYT2_EP1_GET_RC_EVENTS;
46632 +
46633 *state = REMOTE_NO_KEY_PRESSED;
46634
46635 - dvb_usb_generic_rw(d, &cmd, 1, key, sizeof(key), 0);
46636 + dvb_usb_generic_rw(d, cmd, 1, key, 5, 0);
46637 if (key[4] == 0xff) {
46638 /* key repeat */
46639 st->rc_counter++;
46640 @@ -157,12 +213,12 @@ static int cinergyt2_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
46641 *event = d->last_event;
46642 deb_rc("repeat key, event %x\n",
46643 *event);
46644 - return 0;
46645 + goto out;
46646 }
46647 }
46648 deb_rc("repeated key (non repeatable)\n");
46649 }
46650 - return 0;
46651 + goto out;
46652 }
46653
46654 /* hack to pass checksum on the custom field */
46655 @@ -174,6 +230,9 @@ static int cinergyt2_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
46656
46657 deb_rc("key: %*ph\n", 5, key);
46658 }
46659 +out:
46660 + kfree(cmd);
46661 + kfree(key);
46662 return 0;
46663 }
46664
46665 diff --git a/drivers/media/usb/dvb-usb/cinergyT2-fe.c b/drivers/media/usb/dvb-usb/cinergyT2-fe.c
46666 index c890fe4..f9b2ae6 100644
46667 --- a/drivers/media/usb/dvb-usb/cinergyT2-fe.c
46668 +++ b/drivers/media/usb/dvb-usb/cinergyT2-fe.c
46669 @@ -145,103 +145,176 @@ static int cinergyt2_fe_read_status(struct dvb_frontend *fe,
46670 fe_status_t *status)
46671 {
46672 struct cinergyt2_fe_state *state = fe->demodulator_priv;
46673 - struct dvbt_get_status_msg result;
46674 - u8 cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
46675 + struct dvbt_get_status_msg *result;
46676 + u8 *cmd;
46677 int ret;
46678
46679 - ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (u8 *)&result,
46680 - sizeof(result), 0);
46681 + cmd = kmalloc(1, GFP_KERNEL);
46682 + if (cmd == NULL)
46683 + return -ENOMEM;
46684 + result = kmalloc(sizeof(*result), GFP_KERNEL);
46685 + if (result == NULL) {
46686 + kfree(cmd);
46687 + return -ENOMEM;
46688 + }
46689 +
46690 + cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
46691 +
46692 + ret = dvb_usb_generic_rw(state->d, cmd, 1, (u8 *)result,
46693 + sizeof(*result), 0);
46694 if (ret < 0)
46695 - return ret;
46696 + goto out;
46697
46698 *status = 0;
46699
46700 - if (0xffff - le16_to_cpu(result.gain) > 30)
46701 + if (0xffff - le16_to_cpu(result->gain) > 30)
46702 *status |= FE_HAS_SIGNAL;
46703 - if (result.lock_bits & (1 << 6))
46704 + if (result->lock_bits & (1 << 6))
46705 *status |= FE_HAS_LOCK;
46706 - if (result.lock_bits & (1 << 5))
46707 + if (result->lock_bits & (1 << 5))
46708 *status |= FE_HAS_SYNC;
46709 - if (result.lock_bits & (1 << 4))
46710 + if (result->lock_bits & (1 << 4))
46711 *status |= FE_HAS_CARRIER;
46712 - if (result.lock_bits & (1 << 1))
46713 + if (result->lock_bits & (1 << 1))
46714 *status |= FE_HAS_VITERBI;
46715
46716 if ((*status & (FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC)) !=
46717 (FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC))
46718 *status &= ~FE_HAS_LOCK;
46719
46720 - return 0;
46721 +out:
46722 + kfree(cmd);
46723 + kfree(result);
46724 + return ret;
46725 }
46726
46727 static int cinergyt2_fe_read_ber(struct dvb_frontend *fe, u32 *ber)
46728 {
46729 struct cinergyt2_fe_state *state = fe->demodulator_priv;
46730 - struct dvbt_get_status_msg status;
46731 - char cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
46732 + struct dvbt_get_status_msg *status;
46733 + char *cmd;
46734 int ret;
46735
46736 - ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (char *)&status,
46737 - sizeof(status), 0);
46738 + cmd = kmalloc(1, GFP_KERNEL);
46739 + if (cmd == NULL)
46740 + return -ENOMEM;
46741 + status = kmalloc(sizeof(*status), GFP_KERNEL);
46742 + if (status == NULL) {
46743 + kfree(cmd);
46744 + return -ENOMEM;
46745 + }
46746 +
46747 + cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
46748 +
46749 + ret = dvb_usb_generic_rw(state->d, cmd, 1, (char *)status,
46750 + sizeof(*status), 0);
46751 if (ret < 0)
46752 - return ret;
46753 + goto out;
46754
46755 - *ber = le32_to_cpu(status.viterbi_error_rate);
46756 + *ber = le32_to_cpu(status->viterbi_error_rate);
46757 +out:
46758 + kfree(cmd);
46759 + kfree(status);
46760 return 0;
46761 }
46762
46763 static int cinergyt2_fe_read_unc_blocks(struct dvb_frontend *fe, u32 *unc)
46764 {
46765 struct cinergyt2_fe_state *state = fe->demodulator_priv;
46766 - struct dvbt_get_status_msg status;
46767 - u8 cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
46768 + struct dvbt_get_status_msg *status;
46769 + u8 *cmd;
46770 int ret;
46771
46772 - ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (u8 *)&status,
46773 - sizeof(status), 0);
46774 + cmd = kmalloc(1, GFP_KERNEL);
46775 + if (cmd == NULL)
46776 + return -ENOMEM;
46777 + status = kmalloc(sizeof(*status), GFP_KERNEL);
46778 + if (status == NULL) {
46779 + kfree(cmd);
46780 + return -ENOMEM;
46781 + }
46782 +
46783 + cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
46784 +
46785 + ret = dvb_usb_generic_rw(state->d, cmd, 1, (u8 *)status,
46786 + sizeof(*status), 0);
46787 if (ret < 0) {
46788 err("cinergyt2_fe_read_unc_blocks() Failed! (Error=%d)\n",
46789 ret);
46790 - return ret;
46791 + goto out;
46792 }
46793 - *unc = le32_to_cpu(status.uncorrected_block_count);
46794 - return 0;
46795 + *unc = le32_to_cpu(status->uncorrected_block_count);
46796 +
46797 +out:
46798 + kfree(cmd);
46799 + kfree(status);
46800 + return ret;
46801 }
46802
46803 static int cinergyt2_fe_read_signal_strength(struct dvb_frontend *fe,
46804 u16 *strength)
46805 {
46806 struct cinergyt2_fe_state *state = fe->demodulator_priv;
46807 - struct dvbt_get_status_msg status;
46808 - char cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
46809 + struct dvbt_get_status_msg *status;
46810 + char *cmd;
46811 int ret;
46812
46813 - ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (char *)&status,
46814 - sizeof(status), 0);
46815 + cmd = kmalloc(1, GFP_KERNEL);
46816 + if (cmd == NULL)
46817 + return -ENOMEM;
46818 + status = kmalloc(sizeof(*status), GFP_KERNEL);
46819 + if (status == NULL) {
46820 + kfree(cmd);
46821 + return -ENOMEM;
46822 + }
46823 +
46824 + cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
46825 +
46826 + ret = dvb_usb_generic_rw(state->d, cmd, 1, (char *)status,
46827 + sizeof(*status), 0);
46828 if (ret < 0) {
46829 err("cinergyt2_fe_read_signal_strength() Failed!"
46830 " (Error=%d)\n", ret);
46831 - return ret;
46832 + goto out;
46833 }
46834 - *strength = (0xffff - le16_to_cpu(status.gain));
46835 + *strength = (0xffff - le16_to_cpu(status->gain));
46836 +
46837 +out:
46838 + kfree(cmd);
46839 + kfree(status);
46840 return 0;
46841 }
46842
46843 static int cinergyt2_fe_read_snr(struct dvb_frontend *fe, u16 *snr)
46844 {
46845 struct cinergyt2_fe_state *state = fe->demodulator_priv;
46846 - struct dvbt_get_status_msg status;
46847 - char cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
46848 + struct dvbt_get_status_msg *status;
46849 + char *cmd;
46850 int ret;
46851
46852 - ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (char *)&status,
46853 - sizeof(status), 0);
46854 + cmd = kmalloc(1, GFP_KERNEL);
46855 + if (cmd == NULL)
46856 + return -ENOMEM;
46857 + status = kmalloc(sizeof(*status), GFP_KERNEL);
46858 + if (status == NULL) {
46859 + kfree(cmd);
46860 + return -ENOMEM;
46861 + }
46862 +
46863 + cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
46864 +
46865 + ret = dvb_usb_generic_rw(state->d, cmd, 1, (char *)status,
46866 + sizeof(*status), 0);
46867 if (ret < 0) {
46868 err("cinergyt2_fe_read_snr() Failed! (Error=%d)\n", ret);
46869 - return ret;
46870 + goto out;
46871 }
46872 - *snr = (status.snr << 8) | status.snr;
46873 - return 0;
46874 + *snr = (status->snr << 8) | status->snr;
46875 +
46876 +out:
46877 + kfree(cmd);
46878 + kfree(status);
46879 + return ret;
46880 }
46881
46882 static int cinergyt2_fe_init(struct dvb_frontend *fe)
46883 @@ -266,35 +339,46 @@ static int cinergyt2_fe_set_frontend(struct dvb_frontend *fe)
46884 {
46885 struct dtv_frontend_properties *fep = &fe->dtv_property_cache;
46886 struct cinergyt2_fe_state *state = fe->demodulator_priv;
46887 - struct dvbt_set_parameters_msg param;
46888 - char result[2];
46889 + struct dvbt_set_parameters_msg *param;
46890 + char *result;
46891 int err;
46892
46893 - param.cmd = CINERGYT2_EP1_SET_TUNER_PARAMETERS;
46894 - param.tps = cpu_to_le16(compute_tps(fep));
46895 - param.freq = cpu_to_le32(fep->frequency / 1000);
46896 - param.flags = 0;
46897 + result = kmalloc(2, GFP_KERNEL);
46898 + if (result == NULL)
46899 + return -ENOMEM;
46900 + param = kmalloc(sizeof(*param), GFP_KERNEL);
46901 + if (param == NULL) {
46902 + kfree(result);
46903 + return -ENOMEM;
46904 + }
46905 +
46906 + param->cmd = CINERGYT2_EP1_SET_TUNER_PARAMETERS;
46907 + param->tps = cpu_to_le16(compute_tps(fep));
46908 + param->freq = cpu_to_le32(fep->frequency / 1000);
46909 + param->flags = 0;
46910
46911 switch (fep->bandwidth_hz) {
46912 default:
46913 case 8000000:
46914 - param.bandwidth = 8;
46915 + param->bandwidth = 8;
46916 break;
46917 case 7000000:
46918 - param.bandwidth = 7;
46919 + param->bandwidth = 7;
46920 break;
46921 case 6000000:
46922 - param.bandwidth = 6;
46923 + param->bandwidth = 6;
46924 break;
46925 }
46926
46927 err = dvb_usb_generic_rw(state->d,
46928 - (char *)&param, sizeof(param),
46929 - result, sizeof(result), 0);
46930 + (char *)param, sizeof(*param),
46931 + result, 2, 0);
46932 if (err < 0)
46933 err("cinergyt2_fe_set_frontend() Failed! err=%d\n", err);
46934
46935 - return (err < 0) ? err : 0;
46936 + kfree(result);
46937 + kfree(param);
46938 + return err;
46939 }
46940
46941 static void cinergyt2_fe_release(struct dvb_frontend *fe)
46942 diff --git a/drivers/media/usb/dvb-usb/dvb-usb-firmware.c b/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
46943 index 733a7ff..f8b52e3 100644
46944 --- a/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
46945 +++ b/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
46946 @@ -35,42 +35,57 @@ static int usb_cypress_writemem(struct usb_device *udev,u16 addr,u8 *data, u8 le
46947
46948 int usb_cypress_load_firmware(struct usb_device *udev, const struct firmware *fw, int type)
46949 {
46950 - struct hexline hx;
46951 - u8 reset;
46952 + struct hexline *hx;
46953 + u8 *reset;
46954 int ret,pos=0;
46955
46956 + reset = kmalloc(1, GFP_KERNEL);
46957 + if (reset == NULL)
46958 + return -ENOMEM;
46959 +
46960 + hx = kmalloc(sizeof(struct hexline), GFP_KERNEL);
46961 + if (hx == NULL) {
46962 + kfree(reset);
46963 + return -ENOMEM;
46964 + }
46965 +
46966 /* stop the CPU */
46967 - reset = 1;
46968 - if ((ret = usb_cypress_writemem(udev,cypress[type].cpu_cs_register,&reset,1)) != 1)
46969 + reset[0] = 1;
46970 + if ((ret = usb_cypress_writemem(udev,cypress[type].cpu_cs_register,reset,1)) != 1)
46971 err("could not stop the USB controller CPU.");
46972
46973 - while ((ret = dvb_usb_get_hexline(fw,&hx,&pos)) > 0) {
46974 - deb_fw("writing to address 0x%04x (buffer: 0x%02x %02x)\n",hx.addr,hx.len,hx.chk);
46975 - ret = usb_cypress_writemem(udev,hx.addr,hx.data,hx.len);
46976 + while ((ret = dvb_usb_get_hexline(fw,hx,&pos)) > 0) {
46977 + deb_fw("writing to address 0x%04x (buffer: 0x%02x %02x)\n",hx->addr,hx->len,hx->chk);
46978 + ret = usb_cypress_writemem(udev,hx->addr,hx->data,hx->len);
46979
46980 - if (ret != hx.len) {
46981 + if (ret != hx->len) {
46982 err("error while transferring firmware "
46983 "(transferred size: %d, block size: %d)",
46984 - ret,hx.len);
46985 + ret,hx->len);
46986 ret = -EINVAL;
46987 break;
46988 }
46989 }
46990 if (ret < 0) {
46991 err("firmware download failed at %d with %d",pos,ret);
46992 + kfree(reset);
46993 + kfree(hx);
46994 return ret;
46995 }
46996
46997 if (ret == 0) {
46998 /* restart the CPU */
46999 - reset = 0;
47000 - if (ret || usb_cypress_writemem(udev,cypress[type].cpu_cs_register,&reset,1) != 1) {
47001 + reset[0] = 0;
47002 + if (ret || usb_cypress_writemem(udev,cypress[type].cpu_cs_register,reset,1) != 1) {
47003 err("could not restart the USB controller CPU.");
47004 ret = -EINVAL;
47005 }
47006 } else
47007 ret = -EIO;
47008
47009 + kfree(reset);
47010 + kfree(hx);
47011 +
47012 return ret;
47013 }
47014 EXPORT_SYMBOL(usb_cypress_load_firmware);
47015 diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
47016 index 2add8c5..c33b854 100644
47017 --- a/drivers/media/usb/dvb-usb/dw2102.c
47018 +++ b/drivers/media/usb/dvb-usb/dw2102.c
47019 @@ -118,7 +118,7 @@ struct su3000_state {
47020
47021 struct s6x0_state {
47022 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
47023 -};
47024 +} __no_const;
47025
47026 /* debug */
47027 static int dvb_usb_dw2102_debug;
47028 diff --git a/drivers/media/usb/dvb-usb/technisat-usb2.c b/drivers/media/usb/dvb-usb/technisat-usb2.c
47029 index 6b0b8b6b..4038398 100644
47030 --- a/drivers/media/usb/dvb-usb/technisat-usb2.c
47031 +++ b/drivers/media/usb/dvb-usb/technisat-usb2.c
47032 @@ -87,8 +87,11 @@ struct technisat_usb2_state {
47033 static int technisat_usb2_i2c_access(struct usb_device *udev,
47034 u8 device_addr, u8 *tx, u8 txlen, u8 *rx, u8 rxlen)
47035 {
47036 - u8 b[64];
47037 - int ret, actual_length;
47038 + u8 *b = kmalloc(64, GFP_KERNEL);
47039 + int ret, actual_length, error = 0;
47040 +
47041 + if (b == NULL)
47042 + return -ENOMEM;
47043
47044 deb_i2c("i2c-access: %02x, tx: ", device_addr);
47045 debug_dump(tx, txlen, deb_i2c);
47046 @@ -121,7 +124,8 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
47047
47048 if (ret < 0) {
47049 err("i2c-error: out failed %02x = %d", device_addr, ret);
47050 - return -ENODEV;
47051 + error = -ENODEV;
47052 + goto out;
47053 }
47054
47055 ret = usb_bulk_msg(udev,
47056 @@ -129,7 +133,8 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
47057 b, 64, &actual_length, 1000);
47058 if (ret < 0) {
47059 err("i2c-error: in failed %02x = %d", device_addr, ret);
47060 - return -ENODEV;
47061 + error = -ENODEV;
47062 + goto out;
47063 }
47064
47065 if (b[0] != I2C_STATUS_OK) {
47066 @@ -137,8 +142,10 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
47067 /* handle tuner-i2c-nak */
47068 if (!(b[0] == I2C_STATUS_NAK &&
47069 device_addr == 0x60
47070 - /* && device_is_technisat_usb2 */))
47071 - return -ENODEV;
47072 + /* && device_is_technisat_usb2 */)) {
47073 + error = -ENODEV;
47074 + goto out;
47075 + }
47076 }
47077
47078 deb_i2c("status: %d, ", b[0]);
47079 @@ -152,7 +159,9 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
47080
47081 deb_i2c("\n");
47082
47083 - return 0;
47084 +out:
47085 + kfree(b);
47086 + return error;
47087 }
47088
47089 static int technisat_usb2_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msg,
47090 @@ -224,14 +233,16 @@ static int technisat_usb2_set_led(struct dvb_usb_device *d, int red, enum techni
47091 {
47092 int ret;
47093
47094 - u8 led[8] = {
47095 - red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST,
47096 - 0
47097 - };
47098 + u8 *led = kzalloc(8, GFP_KERNEL);
47099 +
47100 + if (led == NULL)
47101 + return -ENOMEM;
47102
47103 if (disable_led_control && state != TECH_LED_OFF)
47104 return 0;
47105
47106 + led[0] = red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST;
47107 +
47108 switch (state) {
47109 case TECH_LED_ON:
47110 led[1] = 0x82;
47111 @@ -263,16 +274,22 @@ static int technisat_usb2_set_led(struct dvb_usb_device *d, int red, enum techni
47112 red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST,
47113 USB_TYPE_VENDOR | USB_DIR_OUT,
47114 0, 0,
47115 - led, sizeof(led), 500);
47116 + led, 8, 500);
47117
47118 mutex_unlock(&d->i2c_mutex);
47119 +
47120 + kfree(led);
47121 +
47122 return ret;
47123 }
47124
47125 static int technisat_usb2_set_led_timer(struct dvb_usb_device *d, u8 red, u8 green)
47126 {
47127 int ret;
47128 - u8 b = 0;
47129 + u8 *b = kzalloc(1, GFP_KERNEL);
47130 +
47131 + if (b == NULL)
47132 + return -ENOMEM;
47133
47134 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
47135 return -EAGAIN;
47136 @@ -281,10 +298,12 @@ static int technisat_usb2_set_led_timer(struct dvb_usb_device *d, u8 red, u8 gre
47137 SET_LED_TIMER_DIVIDER_VENDOR_REQUEST,
47138 USB_TYPE_VENDOR | USB_DIR_OUT,
47139 (red << 8) | green, 0,
47140 - &b, 1, 500);
47141 + b, 1, 500);
47142
47143 mutex_unlock(&d->i2c_mutex);
47144
47145 + kfree(b);
47146 +
47147 return ret;
47148 }
47149
47150 @@ -328,7 +347,7 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
47151 struct dvb_usb_device_description **desc, int *cold)
47152 {
47153 int ret;
47154 - u8 version[3];
47155 + u8 *version = kmalloc(3, GFP_KERNEL);
47156
47157 /* first select the interface */
47158 if (usb_set_interface(udev, 0, 1) != 0)
47159 @@ -338,11 +357,14 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
47160
47161 *cold = 0; /* by default do not download a firmware - just in case something is wrong */
47162
47163 + if (version == NULL)
47164 + return 0;
47165 +
47166 ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
47167 GET_VERSION_INFO_VENDOR_REQUEST,
47168 USB_TYPE_VENDOR | USB_DIR_IN,
47169 0, 0,
47170 - version, sizeof(version), 500);
47171 + version, 3, 500);
47172
47173 if (ret < 0)
47174 *cold = 1;
47175 @@ -351,6 +373,8 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
47176 *cold = 0;
47177 }
47178
47179 + kfree(version);
47180 +
47181 return 0;
47182 }
47183
47184 @@ -591,10 +615,15 @@ static int technisat_usb2_frontend_attach(struct dvb_usb_adapter *a)
47185
47186 static int technisat_usb2_get_ir(struct dvb_usb_device *d)
47187 {
47188 - u8 buf[62], *b;
47189 + u8 *buf, *b;
47190 int ret;
47191 struct ir_raw_event ev;
47192
47193 + buf = kmalloc(62, GFP_KERNEL);
47194 +
47195 + if (buf == NULL)
47196 + return -ENOMEM;
47197 +
47198 buf[0] = GET_IR_DATA_VENDOR_REQUEST;
47199 buf[1] = 0x08;
47200 buf[2] = 0x8f;
47201 @@ -617,16 +646,20 @@ static int technisat_usb2_get_ir(struct dvb_usb_device *d)
47202 GET_IR_DATA_VENDOR_REQUEST,
47203 USB_TYPE_VENDOR | USB_DIR_IN,
47204 0x8080, 0,
47205 - buf, sizeof(buf), 500);
47206 + buf, 62, 500);
47207
47208 unlock:
47209 mutex_unlock(&d->i2c_mutex);
47210
47211 - if (ret < 0)
47212 + if (ret < 0) {
47213 + kfree(buf);
47214 return ret;
47215 + }
47216
47217 - if (ret == 1)
47218 + if (ret == 1) {
47219 + kfree(buf);
47220 return 0; /* no key pressed */
47221 + }
47222
47223 /* decoding */
47224 b = buf+1;
47225 @@ -653,6 +686,8 @@ unlock:
47226
47227 ir_raw_event_handle(d->rc_dev);
47228
47229 + kfree(buf);
47230 +
47231 return 1;
47232 }
47233
47234 diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
47235 index cca6c2f..77b9a18 100644
47236 --- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
47237 +++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
47238 @@ -328,7 +328,7 @@ struct v4l2_buffer32 {
47239 __u32 reserved;
47240 };
47241
47242 -static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
47243 +static int get_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
47244 enum v4l2_memory memory)
47245 {
47246 void __user *up_pln;
47247 @@ -357,7 +357,7 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
47248 return 0;
47249 }
47250
47251 -static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
47252 +static int put_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
47253 enum v4l2_memory memory)
47254 {
47255 if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
47256 @@ -427,7 +427,7 @@ static int get_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
47257 * by passing a very big num_planes value */
47258 uplane = compat_alloc_user_space(num_planes *
47259 sizeof(struct v4l2_plane));
47260 - kp->m.planes = uplane;
47261 + kp->m.planes = (struct v4l2_plane __force_kernel *)uplane;
47262
47263 while (--num_planes >= 0) {
47264 ret = get_v4l2_plane32(uplane, uplane32, kp->memory);
47265 @@ -498,7 +498,7 @@ static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
47266 if (num_planes == 0)
47267 return 0;
47268
47269 - uplane = kp->m.planes;
47270 + uplane = (struct v4l2_plane __force_user *)kp->m.planes;
47271 if (get_user(p, &up->m.planes))
47272 return -EFAULT;
47273 uplane32 = compat_ptr(p);
47274 @@ -562,7 +562,7 @@ static int get_v4l2_framebuffer32(struct v4l2_framebuffer *kp, struct v4l2_frame
47275 get_user(kp->flags, &up->flags) ||
47276 copy_from_user(&kp->fmt, &up->fmt, sizeof(up->fmt)))
47277 return -EFAULT;
47278 - kp->base = compat_ptr(tmp);
47279 + kp->base = (void __force_kernel *)compat_ptr(tmp);
47280 return 0;
47281 }
47282
47283 @@ -667,7 +667,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
47284 n * sizeof(struct v4l2_ext_control32)))
47285 return -EFAULT;
47286 kcontrols = compat_alloc_user_space(n * sizeof(struct v4l2_ext_control));
47287 - kp->controls = kcontrols;
47288 + kp->controls = (struct v4l2_ext_control __force_kernel *)kcontrols;
47289 while (--n >= 0) {
47290 if (copy_in_user(kcontrols, ucontrols, sizeof(*ucontrols)))
47291 return -EFAULT;
47292 @@ -689,7 +689,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
47293 static int put_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext_controls32 __user *up)
47294 {
47295 struct v4l2_ext_control32 __user *ucontrols;
47296 - struct v4l2_ext_control __user *kcontrols = kp->controls;
47297 + struct v4l2_ext_control __user *kcontrols = (struct v4l2_ext_control __force_user *)kp->controls;
47298 int n = kp->count;
47299 compat_caddr_t p;
47300
47301 @@ -783,7 +783,7 @@ static int put_v4l2_edid32(struct v4l2_edid *kp, struct v4l2_edid32 __user *up)
47302 put_user(kp->start_block, &up->start_block) ||
47303 put_user(kp->blocks, &up->blocks) ||
47304 put_user(tmp, &up->edid) ||
47305 - copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
47306 + copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved)))
47307 return -EFAULT;
47308 return 0;
47309 }
47310 diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
47311 index 015f92a..59e311e 100644
47312 --- a/drivers/media/v4l2-core/v4l2-device.c
47313 +++ b/drivers/media/v4l2-core/v4l2-device.c
47314 @@ -75,9 +75,9 @@ int v4l2_device_put(struct v4l2_device *v4l2_dev)
47315 EXPORT_SYMBOL_GPL(v4l2_device_put);
47316
47317 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
47318 - atomic_t *instance)
47319 + atomic_unchecked_t *instance)
47320 {
47321 - int num = atomic_inc_return(instance) - 1;
47322 + int num = atomic_inc_return_unchecked(instance) - 1;
47323 int len = strlen(basename);
47324
47325 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
47326 diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
47327 index d15e167..337f374 100644
47328 --- a/drivers/media/v4l2-core/v4l2-ioctl.c
47329 +++ b/drivers/media/v4l2-core/v4l2-ioctl.c
47330 @@ -2142,7 +2142,8 @@ struct v4l2_ioctl_info {
47331 struct file *file, void *fh, void *p);
47332 } u;
47333 void (*debug)(const void *arg, bool write_only);
47334 -};
47335 +} __do_const;
47336 +typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
47337
47338 /* This control needs a priority check */
47339 #define INFO_FL_PRIO (1 << 0)
47340 @@ -2326,7 +2327,7 @@ static long __video_do_ioctl(struct file *file,
47341 struct video_device *vfd = video_devdata(file);
47342 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
47343 bool write_only = false;
47344 - struct v4l2_ioctl_info default_info;
47345 + v4l2_ioctl_info_no_const default_info;
47346 const struct v4l2_ioctl_info *info;
47347 void *fh = file->private_data;
47348 struct v4l2_fh *vfh = NULL;
47349 @@ -2413,7 +2414,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
47350 ret = -EINVAL;
47351 break;
47352 }
47353 - *user_ptr = (void __user *)buf->m.planes;
47354 + *user_ptr = (void __force_user *)buf->m.planes;
47355 *kernel_ptr = (void **)&buf->m.planes;
47356 *array_size = sizeof(struct v4l2_plane) * buf->length;
47357 ret = 1;
47358 @@ -2430,7 +2431,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
47359 ret = -EINVAL;
47360 break;
47361 }
47362 - *user_ptr = (void __user *)edid->edid;
47363 + *user_ptr = (void __force_user *)edid->edid;
47364 *kernel_ptr = (void **)&edid->edid;
47365 *array_size = edid->blocks * 128;
47366 ret = 1;
47367 @@ -2448,7 +2449,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
47368 ret = -EINVAL;
47369 break;
47370 }
47371 - *user_ptr = (void __user *)ctrls->controls;
47372 + *user_ptr = (void __force_user *)ctrls->controls;
47373 *kernel_ptr = (void **)&ctrls->controls;
47374 *array_size = sizeof(struct v4l2_ext_control)
47375 * ctrls->count;
47376 @@ -2549,7 +2550,7 @@ video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
47377 }
47378
47379 if (has_array_args) {
47380 - *kernel_ptr = (void __force *)user_ptr;
47381 + *kernel_ptr = (void __force_kernel *)user_ptr;
47382 if (copy_to_user(user_ptr, mbuf, array_size))
47383 err = -EFAULT;
47384 goto out_array_args;
47385 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
47386 index a896d94..a5d56b1 100644
47387 --- a/drivers/message/fusion/mptbase.c
47388 +++ b/drivers/message/fusion/mptbase.c
47389 @@ -6752,8 +6752,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
47390 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
47391 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
47392
47393 +#ifdef CONFIG_GRKERNSEC_HIDESYM
47394 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
47395 +#else
47396 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
47397 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
47398 +#endif
47399 +
47400 /*
47401 * Rounding UP to nearest 4-kB boundary here...
47402 */
47403 @@ -6766,7 +6771,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
47404 ioc->facts.GlobalCredits);
47405
47406 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
47407 +#ifdef CONFIG_GRKERNSEC_HIDESYM
47408 + NULL, NULL);
47409 +#else
47410 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
47411 +#endif
47412 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
47413 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
47414 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
47415 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
47416 index 0707fa2..70ca794 100644
47417 --- a/drivers/message/fusion/mptsas.c
47418 +++ b/drivers/message/fusion/mptsas.c
47419 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
47420 return 0;
47421 }
47422
47423 +static inline void
47424 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
47425 +{
47426 + if (phy_info->port_details) {
47427 + phy_info->port_details->rphy = rphy;
47428 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
47429 + ioc->name, rphy));
47430 + }
47431 +
47432 + if (rphy) {
47433 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
47434 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
47435 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
47436 + ioc->name, rphy, rphy->dev.release));
47437 + }
47438 +}
47439 +
47440 /* no mutex */
47441 static void
47442 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
47443 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
47444 return NULL;
47445 }
47446
47447 -static inline void
47448 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
47449 -{
47450 - if (phy_info->port_details) {
47451 - phy_info->port_details->rphy = rphy;
47452 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
47453 - ioc->name, rphy));
47454 - }
47455 -
47456 - if (rphy) {
47457 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
47458 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
47459 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
47460 - ioc->name, rphy, rphy->dev.release));
47461 - }
47462 -}
47463 -
47464 static inline struct sas_port *
47465 mptsas_get_port(struct mptsas_phyinfo *phy_info)
47466 {
47467 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
47468 index b7d87cd..3fb36da 100644
47469 --- a/drivers/message/i2o/i2o_proc.c
47470 +++ b/drivers/message/i2o/i2o_proc.c
47471 @@ -255,12 +255,6 @@ static char *scsi_devices[] = {
47472 "Array Controller Device"
47473 };
47474
47475 -static char *chtostr(char *tmp, u8 *chars, int n)
47476 -{
47477 - tmp[0] = 0;
47478 - return strncat(tmp, (char *)chars, n);
47479 -}
47480 -
47481 static int i2o_report_query_status(struct seq_file *seq, int block_status,
47482 char *group)
47483 {
47484 @@ -707,9 +701,9 @@ static int i2o_seq_show_status(struct seq_file *seq, void *v)
47485 static int i2o_seq_show_hw(struct seq_file *seq, void *v)
47486 {
47487 struct i2o_controller *c = (struct i2o_controller *)seq->private;
47488 - static u32 work32[5];
47489 - static u8 *work8 = (u8 *) work32;
47490 - static u16 *work16 = (u16 *) work32;
47491 + u32 work32[5];
47492 + u8 *work8 = (u8 *) work32;
47493 + u16 *work16 = (u16 *) work32;
47494 int token;
47495 u32 hwcap;
47496
47497 @@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
47498 } *result;
47499
47500 i2o_exec_execute_ddm_table ddm_table;
47501 - char tmp[28 + 1];
47502
47503 result = kmalloc(sizeof(*result), GFP_KERNEL);
47504 if (!result)
47505 @@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
47506
47507 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
47508 seq_printf(seq, "%-#8x", ddm_table.module_id);
47509 - seq_printf(seq, "%-29s",
47510 - chtostr(tmp, ddm_table.module_name_version, 28));
47511 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
47512 seq_printf(seq, "%9d ", ddm_table.data_size);
47513 seq_printf(seq, "%8d", ddm_table.code_size);
47514
47515 @@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
47516
47517 i2o_driver_result_table *result;
47518 i2o_driver_store_table *dst;
47519 - char tmp[28 + 1];
47520
47521 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
47522 if (result == NULL)
47523 @@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
47524
47525 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
47526 seq_printf(seq, "%-#8x", dst->module_id);
47527 - seq_printf(seq, "%-29s",
47528 - chtostr(tmp, dst->module_name_version, 28));
47529 - seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
47530 + seq_printf(seq, "%-.28s", dst->module_name_version);
47531 + seq_printf(seq, "%-.8s", dst->date);
47532 seq_printf(seq, "%8d ", dst->module_size);
47533 seq_printf(seq, "%8d ", dst->mpb_size);
47534 seq_printf(seq, "0x%04x", dst->module_flags);
47535 @@ -1246,11 +1236,10 @@ static int i2o_seq_show_authorized_users(struct seq_file *seq, void *v)
47536 static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
47537 {
47538 struct i2o_device *d = (struct i2o_device *)seq->private;
47539 - static u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
47540 + u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
47541 // == (allow) 512d bytes (max)
47542 - static u16 *work16 = (u16 *) work32;
47543 + u16 *work16 = (u16 *) work32;
47544 int token;
47545 - char tmp[16 + 1];
47546
47547 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
47548
47549 @@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
47550 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
47551 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
47552 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
47553 - seq_printf(seq, "Vendor info : %s\n",
47554 - chtostr(tmp, (u8 *) (work32 + 2), 16));
47555 - seq_printf(seq, "Product info : %s\n",
47556 - chtostr(tmp, (u8 *) (work32 + 6), 16));
47557 - seq_printf(seq, "Description : %s\n",
47558 - chtostr(tmp, (u8 *) (work32 + 10), 16));
47559 - seq_printf(seq, "Product rev. : %s\n",
47560 - chtostr(tmp, (u8 *) (work32 + 14), 8));
47561 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
47562 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
47563 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
47564 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
47565
47566 seq_printf(seq, "Serial number : ");
47567 print_serial_number(seq, (u8 *) (work32 + 16),
47568 @@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
47569 u8 pad[256]; // allow up to 256 byte (max) serial number
47570 } result;
47571
47572 - char tmp[24 + 1];
47573 -
47574 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
47575
47576 if (token < 0) {
47577 @@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
47578 }
47579
47580 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
47581 - seq_printf(seq, "Module name : %s\n",
47582 - chtostr(tmp, result.module_name, 24));
47583 - seq_printf(seq, "Module revision : %s\n",
47584 - chtostr(tmp, result.module_rev, 8));
47585 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
47586 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
47587
47588 seq_printf(seq, "Serial number : ");
47589 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
47590 @@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
47591 u8 instance_number[4];
47592 } result;
47593
47594 - char tmp[64 + 1];
47595 -
47596 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
47597
47598 if (token < 0) {
47599 @@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
47600 return 0;
47601 }
47602
47603 - seq_printf(seq, "Device name : %s\n",
47604 - chtostr(tmp, result.device_name, 64));
47605 - seq_printf(seq, "Service name : %s\n",
47606 - chtostr(tmp, result.service_name, 64));
47607 - seq_printf(seq, "Physical name : %s\n",
47608 - chtostr(tmp, result.physical_location, 64));
47609 - seq_printf(seq, "Instance number : %s\n",
47610 - chtostr(tmp, result.instance_number, 4));
47611 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
47612 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
47613 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
47614 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
47615
47616 return 0;
47617 }
47618 @@ -1368,9 +1343,9 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
47619 static int i2o_seq_show_sgl_limits(struct seq_file *seq, void *v)
47620 {
47621 struct i2o_device *d = (struct i2o_device *)seq->private;
47622 - static u32 work32[12];
47623 - static u16 *work16 = (u16 *) work32;
47624 - static u8 *work8 = (u8 *) work32;
47625 + u32 work32[12];
47626 + u16 *work16 = (u16 *) work32;
47627 + u8 *work8 = (u8 *) work32;
47628 int token;
47629
47630 token = i2o_parm_field_get(d, 0xF103, -1, &work32, sizeof(work32));
47631 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
47632 index 92752fb..a7494f6 100644
47633 --- a/drivers/message/i2o/iop.c
47634 +++ b/drivers/message/i2o/iop.c
47635 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
47636
47637 spin_lock_irqsave(&c->context_list_lock, flags);
47638
47639 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
47640 - atomic_inc(&c->context_list_counter);
47641 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
47642 + atomic_inc_unchecked(&c->context_list_counter);
47643
47644 - entry->context = atomic_read(&c->context_list_counter);
47645 + entry->context = atomic_read_unchecked(&c->context_list_counter);
47646
47647 list_add(&entry->list, &c->context_list);
47648
47649 @@ -1076,7 +1076,7 @@ struct i2o_controller *i2o_iop_alloc(void)
47650
47651 #if BITS_PER_LONG == 64
47652 spin_lock_init(&c->context_list_lock);
47653 - atomic_set(&c->context_list_counter, 0);
47654 + atomic_set_unchecked(&c->context_list_counter, 0);
47655 INIT_LIST_HEAD(&c->context_list);
47656 #endif
47657
47658 diff --git a/drivers/mfd/ab8500-debugfs.c b/drivers/mfd/ab8500-debugfs.c
47659 index b2c7e3b..85aa4764 100644
47660 --- a/drivers/mfd/ab8500-debugfs.c
47661 +++ b/drivers/mfd/ab8500-debugfs.c
47662 @@ -100,7 +100,7 @@ static int irq_last;
47663 static u32 *irq_count;
47664 static int num_irqs;
47665
47666 -static struct device_attribute **dev_attr;
47667 +static device_attribute_no_const **dev_attr;
47668 static char **event_name;
47669
47670 static u8 avg_sample = SAMPLE_16;
47671 diff --git a/drivers/mfd/max8925-i2c.c b/drivers/mfd/max8925-i2c.c
47672 index ecbe78e..b2ca870 100644
47673 --- a/drivers/mfd/max8925-i2c.c
47674 +++ b/drivers/mfd/max8925-i2c.c
47675 @@ -152,7 +152,7 @@ static int max8925_probe(struct i2c_client *client,
47676 const struct i2c_device_id *id)
47677 {
47678 struct max8925_platform_data *pdata = dev_get_platdata(&client->dev);
47679 - static struct max8925_chip *chip;
47680 + struct max8925_chip *chip;
47681 struct device_node *node = client->dev.of_node;
47682
47683 if (node && !pdata) {
47684 diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
47685 index f243e75..322176c 100644
47686 --- a/drivers/mfd/tps65910.c
47687 +++ b/drivers/mfd/tps65910.c
47688 @@ -230,7 +230,7 @@ static int tps65910_irq_init(struct tps65910 *tps65910, int irq,
47689 struct tps65910_platform_data *pdata)
47690 {
47691 int ret = 0;
47692 - static struct regmap_irq_chip *tps6591x_irqs_chip;
47693 + struct regmap_irq_chip *tps6591x_irqs_chip;
47694
47695 if (!irq) {
47696 dev_warn(tps65910->dev, "No interrupt support, no core IRQ\n");
47697 diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
47698 index b1dabba..24a88f2 100644
47699 --- a/drivers/mfd/twl4030-irq.c
47700 +++ b/drivers/mfd/twl4030-irq.c
47701 @@ -34,6 +34,7 @@
47702 #include <linux/of.h>
47703 #include <linux/irqdomain.h>
47704 #include <linux/i2c/twl.h>
47705 +#include <asm/pgtable.h>
47706
47707 #include "twl-core.h"
47708
47709 @@ -725,10 +726,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
47710 * Install an irq handler for each of the SIH modules;
47711 * clone dummy irq_chip since PIH can't *do* anything
47712 */
47713 - twl4030_irq_chip = dummy_irq_chip;
47714 - twl4030_irq_chip.name = "twl4030";
47715 + pax_open_kernel();
47716 + memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
47717 + *(const char **)&twl4030_irq_chip.name = "twl4030";
47718
47719 - twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
47720 + *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
47721 + pax_close_kernel();
47722
47723 for (i = irq_base; i < irq_end; i++) {
47724 irq_set_chip_and_handler(i, &twl4030_irq_chip,
47725 diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
47726 index 464419b..64bae8d 100644
47727 --- a/drivers/misc/c2port/core.c
47728 +++ b/drivers/misc/c2port/core.c
47729 @@ -922,7 +922,9 @@ struct c2port_device *c2port_device_register(char *name,
47730 goto error_idr_alloc;
47731 c2dev->id = ret;
47732
47733 - bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
47734 + pax_open_kernel();
47735 + *(size_t *)&bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
47736 + pax_close_kernel();
47737
47738 c2dev->dev = device_create(c2port_class, NULL, 0, c2dev,
47739 "c2port%d", c2dev->id);
47740 diff --git a/drivers/misc/eeprom/sunxi_sid.c b/drivers/misc/eeprom/sunxi_sid.c
47741 index 3f2b625..945e179 100644
47742 --- a/drivers/misc/eeprom/sunxi_sid.c
47743 +++ b/drivers/misc/eeprom/sunxi_sid.c
47744 @@ -126,7 +126,9 @@ static int sunxi_sid_probe(struct platform_device *pdev)
47745
47746 platform_set_drvdata(pdev, sid_data);
47747
47748 - sid_bin_attr.size = sid_data->keysize;
47749 + pax_open_kernel();
47750 + *(size_t *)&sid_bin_attr.size = sid_data->keysize;
47751 + pax_close_kernel();
47752 if (device_create_bin_file(&pdev->dev, &sid_bin_attr))
47753 return -ENODEV;
47754
47755 diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
47756 index 36f5d52..32311c3 100644
47757 --- a/drivers/misc/kgdbts.c
47758 +++ b/drivers/misc/kgdbts.c
47759 @@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
47760 char before[BREAK_INSTR_SIZE];
47761 char after[BREAK_INSTR_SIZE];
47762
47763 - probe_kernel_read(before, (char *)kgdbts_break_test,
47764 + probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
47765 BREAK_INSTR_SIZE);
47766 init_simple_test();
47767 ts.tst = plant_and_detach_test;
47768 @@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
47769 /* Activate test with initial breakpoint */
47770 if (!is_early)
47771 kgdb_breakpoint();
47772 - probe_kernel_read(after, (char *)kgdbts_break_test,
47773 + probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
47774 BREAK_INSTR_SIZE);
47775 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
47776 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
47777 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
47778 index 3ef4627..8d00486 100644
47779 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
47780 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
47781 @@ -497,7 +497,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
47782 * the lid is closed. This leads to interrupts as soon as a little move
47783 * is done.
47784 */
47785 - atomic_inc(&lis3->count);
47786 + atomic_inc_unchecked(&lis3->count);
47787
47788 wake_up_interruptible(&lis3->misc_wait);
47789 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
47790 @@ -583,7 +583,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
47791 if (lis3->pm_dev)
47792 pm_runtime_get_sync(lis3->pm_dev);
47793
47794 - atomic_set(&lis3->count, 0);
47795 + atomic_set_unchecked(&lis3->count, 0);
47796 return 0;
47797 }
47798
47799 @@ -615,7 +615,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
47800 add_wait_queue(&lis3->misc_wait, &wait);
47801 while (true) {
47802 set_current_state(TASK_INTERRUPTIBLE);
47803 - data = atomic_xchg(&lis3->count, 0);
47804 + data = atomic_xchg_unchecked(&lis3->count, 0);
47805 if (data)
47806 break;
47807
47808 @@ -656,7 +656,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
47809 struct lis3lv02d, miscdev);
47810
47811 poll_wait(file, &lis3->misc_wait, wait);
47812 - if (atomic_read(&lis3->count))
47813 + if (atomic_read_unchecked(&lis3->count))
47814 return POLLIN | POLLRDNORM;
47815 return 0;
47816 }
47817 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
47818 index c439c82..1f20f57 100644
47819 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
47820 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
47821 @@ -297,7 +297,7 @@ struct lis3lv02d {
47822 struct input_polled_dev *idev; /* input device */
47823 struct platform_device *pdev; /* platform device */
47824 struct regulator_bulk_data regulators[2];
47825 - atomic_t count; /* interrupt count after last read */
47826 + atomic_unchecked_t count; /* interrupt count after last read */
47827 union axis_conversion ac; /* hw -> logical axis */
47828 int mapped_btns[3];
47829
47830 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
47831 index 2f30bad..c4c13d0 100644
47832 --- a/drivers/misc/sgi-gru/gruhandles.c
47833 +++ b/drivers/misc/sgi-gru/gruhandles.c
47834 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
47835 unsigned long nsec;
47836
47837 nsec = CLKS2NSEC(clks);
47838 - atomic_long_inc(&mcs_op_statistics[op].count);
47839 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
47840 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
47841 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
47842 if (mcs_op_statistics[op].max < nsec)
47843 mcs_op_statistics[op].max = nsec;
47844 }
47845 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
47846 index 4f76359..cdfcb2e 100644
47847 --- a/drivers/misc/sgi-gru/gruprocfs.c
47848 +++ b/drivers/misc/sgi-gru/gruprocfs.c
47849 @@ -32,9 +32,9 @@
47850
47851 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
47852
47853 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
47854 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
47855 {
47856 - unsigned long val = atomic_long_read(v);
47857 + unsigned long val = atomic_long_read_unchecked(v);
47858
47859 seq_printf(s, "%16lu %s\n", val, id);
47860 }
47861 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
47862
47863 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
47864 for (op = 0; op < mcsop_last; op++) {
47865 - count = atomic_long_read(&mcs_op_statistics[op].count);
47866 - total = atomic_long_read(&mcs_op_statistics[op].total);
47867 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
47868 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
47869 max = mcs_op_statistics[op].max;
47870 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
47871 count ? total / count : 0, max);
47872 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
47873 index 5c3ce24..4915ccb 100644
47874 --- a/drivers/misc/sgi-gru/grutables.h
47875 +++ b/drivers/misc/sgi-gru/grutables.h
47876 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
47877 * GRU statistics.
47878 */
47879 struct gru_stats_s {
47880 - atomic_long_t vdata_alloc;
47881 - atomic_long_t vdata_free;
47882 - atomic_long_t gts_alloc;
47883 - atomic_long_t gts_free;
47884 - atomic_long_t gms_alloc;
47885 - atomic_long_t gms_free;
47886 - atomic_long_t gts_double_allocate;
47887 - atomic_long_t assign_context;
47888 - atomic_long_t assign_context_failed;
47889 - atomic_long_t free_context;
47890 - atomic_long_t load_user_context;
47891 - atomic_long_t load_kernel_context;
47892 - atomic_long_t lock_kernel_context;
47893 - atomic_long_t unlock_kernel_context;
47894 - atomic_long_t steal_user_context;
47895 - atomic_long_t steal_kernel_context;
47896 - atomic_long_t steal_context_failed;
47897 - atomic_long_t nopfn;
47898 - atomic_long_t asid_new;
47899 - atomic_long_t asid_next;
47900 - atomic_long_t asid_wrap;
47901 - atomic_long_t asid_reuse;
47902 - atomic_long_t intr;
47903 - atomic_long_t intr_cbr;
47904 - atomic_long_t intr_tfh;
47905 - atomic_long_t intr_spurious;
47906 - atomic_long_t intr_mm_lock_failed;
47907 - atomic_long_t call_os;
47908 - atomic_long_t call_os_wait_queue;
47909 - atomic_long_t user_flush_tlb;
47910 - atomic_long_t user_unload_context;
47911 - atomic_long_t user_exception;
47912 - atomic_long_t set_context_option;
47913 - atomic_long_t check_context_retarget_intr;
47914 - atomic_long_t check_context_unload;
47915 - atomic_long_t tlb_dropin;
47916 - atomic_long_t tlb_preload_page;
47917 - atomic_long_t tlb_dropin_fail_no_asid;
47918 - atomic_long_t tlb_dropin_fail_upm;
47919 - atomic_long_t tlb_dropin_fail_invalid;
47920 - atomic_long_t tlb_dropin_fail_range_active;
47921 - atomic_long_t tlb_dropin_fail_idle;
47922 - atomic_long_t tlb_dropin_fail_fmm;
47923 - atomic_long_t tlb_dropin_fail_no_exception;
47924 - atomic_long_t tfh_stale_on_fault;
47925 - atomic_long_t mmu_invalidate_range;
47926 - atomic_long_t mmu_invalidate_page;
47927 - atomic_long_t flush_tlb;
47928 - atomic_long_t flush_tlb_gru;
47929 - atomic_long_t flush_tlb_gru_tgh;
47930 - atomic_long_t flush_tlb_gru_zero_asid;
47931 + atomic_long_unchecked_t vdata_alloc;
47932 + atomic_long_unchecked_t vdata_free;
47933 + atomic_long_unchecked_t gts_alloc;
47934 + atomic_long_unchecked_t gts_free;
47935 + atomic_long_unchecked_t gms_alloc;
47936 + atomic_long_unchecked_t gms_free;
47937 + atomic_long_unchecked_t gts_double_allocate;
47938 + atomic_long_unchecked_t assign_context;
47939 + atomic_long_unchecked_t assign_context_failed;
47940 + atomic_long_unchecked_t free_context;
47941 + atomic_long_unchecked_t load_user_context;
47942 + atomic_long_unchecked_t load_kernel_context;
47943 + atomic_long_unchecked_t lock_kernel_context;
47944 + atomic_long_unchecked_t unlock_kernel_context;
47945 + atomic_long_unchecked_t steal_user_context;
47946 + atomic_long_unchecked_t steal_kernel_context;
47947 + atomic_long_unchecked_t steal_context_failed;
47948 + atomic_long_unchecked_t nopfn;
47949 + atomic_long_unchecked_t asid_new;
47950 + atomic_long_unchecked_t asid_next;
47951 + atomic_long_unchecked_t asid_wrap;
47952 + atomic_long_unchecked_t asid_reuse;
47953 + atomic_long_unchecked_t intr;
47954 + atomic_long_unchecked_t intr_cbr;
47955 + atomic_long_unchecked_t intr_tfh;
47956 + atomic_long_unchecked_t intr_spurious;
47957 + atomic_long_unchecked_t intr_mm_lock_failed;
47958 + atomic_long_unchecked_t call_os;
47959 + atomic_long_unchecked_t call_os_wait_queue;
47960 + atomic_long_unchecked_t user_flush_tlb;
47961 + atomic_long_unchecked_t user_unload_context;
47962 + atomic_long_unchecked_t user_exception;
47963 + atomic_long_unchecked_t set_context_option;
47964 + atomic_long_unchecked_t check_context_retarget_intr;
47965 + atomic_long_unchecked_t check_context_unload;
47966 + atomic_long_unchecked_t tlb_dropin;
47967 + atomic_long_unchecked_t tlb_preload_page;
47968 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
47969 + atomic_long_unchecked_t tlb_dropin_fail_upm;
47970 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
47971 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
47972 + atomic_long_unchecked_t tlb_dropin_fail_idle;
47973 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
47974 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
47975 + atomic_long_unchecked_t tfh_stale_on_fault;
47976 + atomic_long_unchecked_t mmu_invalidate_range;
47977 + atomic_long_unchecked_t mmu_invalidate_page;
47978 + atomic_long_unchecked_t flush_tlb;
47979 + atomic_long_unchecked_t flush_tlb_gru;
47980 + atomic_long_unchecked_t flush_tlb_gru_tgh;
47981 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
47982
47983 - atomic_long_t copy_gpa;
47984 - atomic_long_t read_gpa;
47985 + atomic_long_unchecked_t copy_gpa;
47986 + atomic_long_unchecked_t read_gpa;
47987
47988 - atomic_long_t mesq_receive;
47989 - atomic_long_t mesq_receive_none;
47990 - atomic_long_t mesq_send;
47991 - atomic_long_t mesq_send_failed;
47992 - atomic_long_t mesq_noop;
47993 - atomic_long_t mesq_send_unexpected_error;
47994 - atomic_long_t mesq_send_lb_overflow;
47995 - atomic_long_t mesq_send_qlimit_reached;
47996 - atomic_long_t mesq_send_amo_nacked;
47997 - atomic_long_t mesq_send_put_nacked;
47998 - atomic_long_t mesq_page_overflow;
47999 - atomic_long_t mesq_qf_locked;
48000 - atomic_long_t mesq_qf_noop_not_full;
48001 - atomic_long_t mesq_qf_switch_head_failed;
48002 - atomic_long_t mesq_qf_unexpected_error;
48003 - atomic_long_t mesq_noop_unexpected_error;
48004 - atomic_long_t mesq_noop_lb_overflow;
48005 - atomic_long_t mesq_noop_qlimit_reached;
48006 - atomic_long_t mesq_noop_amo_nacked;
48007 - atomic_long_t mesq_noop_put_nacked;
48008 - atomic_long_t mesq_noop_page_overflow;
48009 + atomic_long_unchecked_t mesq_receive;
48010 + atomic_long_unchecked_t mesq_receive_none;
48011 + atomic_long_unchecked_t mesq_send;
48012 + atomic_long_unchecked_t mesq_send_failed;
48013 + atomic_long_unchecked_t mesq_noop;
48014 + atomic_long_unchecked_t mesq_send_unexpected_error;
48015 + atomic_long_unchecked_t mesq_send_lb_overflow;
48016 + atomic_long_unchecked_t mesq_send_qlimit_reached;
48017 + atomic_long_unchecked_t mesq_send_amo_nacked;
48018 + atomic_long_unchecked_t mesq_send_put_nacked;
48019 + atomic_long_unchecked_t mesq_page_overflow;
48020 + atomic_long_unchecked_t mesq_qf_locked;
48021 + atomic_long_unchecked_t mesq_qf_noop_not_full;
48022 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
48023 + atomic_long_unchecked_t mesq_qf_unexpected_error;
48024 + atomic_long_unchecked_t mesq_noop_unexpected_error;
48025 + atomic_long_unchecked_t mesq_noop_lb_overflow;
48026 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
48027 + atomic_long_unchecked_t mesq_noop_amo_nacked;
48028 + atomic_long_unchecked_t mesq_noop_put_nacked;
48029 + atomic_long_unchecked_t mesq_noop_page_overflow;
48030
48031 };
48032
48033 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
48034 tghop_invalidate, mcsop_last};
48035
48036 struct mcs_op_statistic {
48037 - atomic_long_t count;
48038 - atomic_long_t total;
48039 + atomic_long_unchecked_t count;
48040 + atomic_long_unchecked_t total;
48041 unsigned long max;
48042 };
48043
48044 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
48045
48046 #define STAT(id) do { \
48047 if (gru_options & OPT_STATS) \
48048 - atomic_long_inc(&gru_stats.id); \
48049 + atomic_long_inc_unchecked(&gru_stats.id); \
48050 } while (0)
48051
48052 #ifdef CONFIG_SGI_GRU_DEBUG
48053 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
48054 index c862cd4..0d176fe 100644
48055 --- a/drivers/misc/sgi-xp/xp.h
48056 +++ b/drivers/misc/sgi-xp/xp.h
48057 @@ -288,7 +288,7 @@ struct xpc_interface {
48058 xpc_notify_func, void *);
48059 void (*received) (short, int, void *);
48060 enum xp_retval (*partid_to_nasids) (short, void *);
48061 -};
48062 +} __no_const;
48063
48064 extern struct xpc_interface xpc_interface;
48065
48066 diff --git a/drivers/misc/sgi-xp/xp_main.c b/drivers/misc/sgi-xp/xp_main.c
48067 index 01be66d..e3a0c7e 100644
48068 --- a/drivers/misc/sgi-xp/xp_main.c
48069 +++ b/drivers/misc/sgi-xp/xp_main.c
48070 @@ -78,13 +78,13 @@ xpc_notloaded(void)
48071 }
48072
48073 struct xpc_interface xpc_interface = {
48074 - (void (*)(int))xpc_notloaded,
48075 - (void (*)(int))xpc_notloaded,
48076 - (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
48077 - (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
48078 + .connect = (void (*)(int))xpc_notloaded,
48079 + .disconnect = (void (*)(int))xpc_notloaded,
48080 + .send = (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
48081 + .send_notify = (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
48082 void *))xpc_notloaded,
48083 - (void (*)(short, int, void *))xpc_notloaded,
48084 - (enum xp_retval(*)(short, void *))xpc_notloaded
48085 + .received = (void (*)(short, int, void *))xpc_notloaded,
48086 + .partid_to_nasids = (enum xp_retval(*)(short, void *))xpc_notloaded
48087 };
48088 EXPORT_SYMBOL_GPL(xpc_interface);
48089
48090 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
48091 index b94d5f7..7f494c5 100644
48092 --- a/drivers/misc/sgi-xp/xpc.h
48093 +++ b/drivers/misc/sgi-xp/xpc.h
48094 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
48095 void (*received_payload) (struct xpc_channel *, void *);
48096 void (*notify_senders_of_disconnect) (struct xpc_channel *);
48097 };
48098 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
48099
48100 /* struct xpc_partition act_state values (for XPC HB) */
48101
48102 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
48103 /* found in xpc_main.c */
48104 extern struct device *xpc_part;
48105 extern struct device *xpc_chan;
48106 -extern struct xpc_arch_operations xpc_arch_ops;
48107 +extern xpc_arch_operations_no_const xpc_arch_ops;
48108 extern int xpc_disengage_timelimit;
48109 extern int xpc_disengage_timedout;
48110 extern int xpc_activate_IRQ_rcvd;
48111 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
48112 index 82dc574..8539ab2 100644
48113 --- a/drivers/misc/sgi-xp/xpc_main.c
48114 +++ b/drivers/misc/sgi-xp/xpc_main.c
48115 @@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
48116 .notifier_call = xpc_system_die,
48117 };
48118
48119 -struct xpc_arch_operations xpc_arch_ops;
48120 +xpc_arch_operations_no_const xpc_arch_ops;
48121
48122 /*
48123 * Timer function to enforce the timelimit on the partition disengage.
48124 @@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
48125
48126 if (((die_args->trapnr == X86_TRAP_MF) ||
48127 (die_args->trapnr == X86_TRAP_XF)) &&
48128 - !user_mode_vm(die_args->regs))
48129 + !user_mode(die_args->regs))
48130 xpc_die_deactivate();
48131
48132 break;
48133 diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
48134 index ede41f0..744fbd9 100644
48135 --- a/drivers/mmc/card/block.c
48136 +++ b/drivers/mmc/card/block.c
48137 @@ -574,7 +574,7 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev,
48138 if (idata->ic.postsleep_min_us)
48139 usleep_range(idata->ic.postsleep_min_us, idata->ic.postsleep_max_us);
48140
48141 - if (copy_to_user(&(ic_ptr->response), cmd.resp, sizeof(cmd.resp))) {
48142 + if (copy_to_user(ic_ptr->response, cmd.resp, sizeof(cmd.resp))) {
48143 err = -EFAULT;
48144 goto cmd_rel_host;
48145 }
48146 diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
48147 index f51b5ba..86614a7 100644
48148 --- a/drivers/mmc/core/mmc_ops.c
48149 +++ b/drivers/mmc/core/mmc_ops.c
48150 @@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
48151 void *data_buf;
48152 int is_on_stack;
48153
48154 - is_on_stack = object_is_on_stack(buf);
48155 + is_on_stack = object_starts_on_stack(buf);
48156 if (is_on_stack) {
48157 /*
48158 * dma onto stack is unsafe/nonportable, but callers to this
48159 diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
48160 index 08fd956..370487a 100644
48161 --- a/drivers/mmc/host/dw_mmc.h
48162 +++ b/drivers/mmc/host/dw_mmc.h
48163 @@ -262,5 +262,5 @@ struct dw_mci_drv_data {
48164 int (*parse_dt)(struct dw_mci *host);
48165 int (*execute_tuning)(struct dw_mci_slot *slot, u32 opcode,
48166 struct dw_mci_tuning_data *tuning_data);
48167 -};
48168 +} __do_const;
48169 #endif /* _DW_MMC_H_ */
48170 diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
48171 index e4d4707..28262a3 100644
48172 --- a/drivers/mmc/host/mmci.c
48173 +++ b/drivers/mmc/host/mmci.c
48174 @@ -1612,7 +1612,9 @@ static int mmci_probe(struct amba_device *dev,
48175 mmc->caps |= MMC_CAP_CMD23;
48176
48177 if (variant->busy_detect) {
48178 - mmci_ops.card_busy = mmci_card_busy;
48179 + pax_open_kernel();
48180 + *(void **)&mmci_ops.card_busy = mmci_card_busy;
48181 + pax_close_kernel();
48182 mmci_write_datactrlreg(host, MCI_ST_DPSM_BUSYMODE);
48183 mmc->caps |= MMC_CAP_WAIT_WHILE_BUSY;
48184 mmc->max_busy_timeout = 0;
48185 diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
48186 index ccec0e3..199f9ce 100644
48187 --- a/drivers/mmc/host/sdhci-esdhc-imx.c
48188 +++ b/drivers/mmc/host/sdhci-esdhc-imx.c
48189 @@ -1034,9 +1034,12 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
48190 host->mmc->caps |= MMC_CAP_1_8V_DDR;
48191 }
48192
48193 - if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING)
48194 - sdhci_esdhc_ops.platform_execute_tuning =
48195 + if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING) {
48196 + pax_open_kernel();
48197 + *(void **)&sdhci_esdhc_ops.platform_execute_tuning =
48198 esdhc_executing_tuning;
48199 + pax_close_kernel();
48200 + }
48201
48202 if (imx_data->socdata->flags & ESDHC_FLAG_STD_TUNING)
48203 writel(readl(host->ioaddr + ESDHC_TUNING_CTRL) |
48204 diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
48205 index 1e47903..7683916 100644
48206 --- a/drivers/mmc/host/sdhci-s3c.c
48207 +++ b/drivers/mmc/host/sdhci-s3c.c
48208 @@ -584,9 +584,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
48209 * we can use overriding functions instead of default.
48210 */
48211 if (sc->no_divider) {
48212 - sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
48213 - sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
48214 - sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
48215 + pax_open_kernel();
48216 + *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
48217 + *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
48218 + *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
48219 + pax_close_kernel();
48220 }
48221
48222 /* It supports additional host capabilities if needed */
48223 diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
48224 index 423666b..81ff5eb 100644
48225 --- a/drivers/mtd/chips/cfi_cmdset_0020.c
48226 +++ b/drivers/mtd/chips/cfi_cmdset_0020.c
48227 @@ -666,7 +666,7 @@ cfi_staa_writev(struct mtd_info *mtd, const struct kvec *vecs,
48228 size_t totlen = 0, thislen;
48229 int ret = 0;
48230 size_t buflen = 0;
48231 - static char *buffer;
48232 + char *buffer;
48233
48234 if (!ECCBUF_SIZE) {
48235 /* We should fall back to a general writev implementation.
48236 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
48237 index 0b071a3..8ec3d5b 100644
48238 --- a/drivers/mtd/nand/denali.c
48239 +++ b/drivers/mtd/nand/denali.c
48240 @@ -24,6 +24,7 @@
48241 #include <linux/slab.h>
48242 #include <linux/mtd/mtd.h>
48243 #include <linux/module.h>
48244 +#include <linux/slab.h>
48245
48246 #include "denali.h"
48247
48248 diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
48249 index 959cb9b..8520fe5 100644
48250 --- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
48251 +++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
48252 @@ -386,7 +386,7 @@ void prepare_data_dma(struct gpmi_nand_data *this, enum dma_data_direction dr)
48253
48254 /* first try to map the upper buffer directly */
48255 if (virt_addr_valid(this->upper_buf) &&
48256 - !object_is_on_stack(this->upper_buf)) {
48257 + !object_starts_on_stack(this->upper_buf)) {
48258 sg_init_one(sgl, this->upper_buf, this->upper_len);
48259 ret = dma_map_sg(this->dev, sgl, 1, dr);
48260 if (ret == 0)
48261 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
48262 index 51b9d6a..52af9a7 100644
48263 --- a/drivers/mtd/nftlmount.c
48264 +++ b/drivers/mtd/nftlmount.c
48265 @@ -24,6 +24,7 @@
48266 #include <asm/errno.h>
48267 #include <linux/delay.h>
48268 #include <linux/slab.h>
48269 +#include <linux/sched.h>
48270 #include <linux/mtd/mtd.h>
48271 #include <linux/mtd/nand.h>
48272 #include <linux/mtd/nftl.h>
48273 diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
48274 index cf49c22..971b133 100644
48275 --- a/drivers/mtd/sm_ftl.c
48276 +++ b/drivers/mtd/sm_ftl.c
48277 @@ -56,7 +56,7 @@ static ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
48278 #define SM_CIS_VENDOR_OFFSET 0x59
48279 static struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
48280 {
48281 - struct attribute_group *attr_group;
48282 + attribute_group_no_const *attr_group;
48283 struct attribute **attributes;
48284 struct sm_sysfs_attribute *vendor_attribute;
48285 char *vendor;
48286 diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c
48287 index fc061c3..53853ef 100644
48288 --- a/drivers/net/bonding/bond_netlink.c
48289 +++ b/drivers/net/bonding/bond_netlink.c
48290 @@ -553,7 +553,7 @@ nla_put_failure:
48291 return -EMSGSIZE;
48292 }
48293
48294 -struct rtnl_link_ops bond_link_ops __read_mostly = {
48295 +struct rtnl_link_ops bond_link_ops = {
48296 .kind = "bond",
48297 .priv_size = sizeof(struct bonding),
48298 .setup = bond_setup,
48299 diff --git a/drivers/net/caif/caif_hsi.c b/drivers/net/caif/caif_hsi.c
48300 index 5e40a8b..126bfda 100644
48301 --- a/drivers/net/caif/caif_hsi.c
48302 +++ b/drivers/net/caif/caif_hsi.c
48303 @@ -1445,7 +1445,7 @@ err:
48304 return -ENODEV;
48305 }
48306
48307 -static struct rtnl_link_ops caif_hsi_link_ops __read_mostly = {
48308 +static struct rtnl_link_ops caif_hsi_link_ops = {
48309 .kind = "cfhsi",
48310 .priv_size = sizeof(struct cfhsi),
48311 .setup = cfhsi_setup,
48312 diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig
48313 index 4168822..f38eeddf 100644
48314 --- a/drivers/net/can/Kconfig
48315 +++ b/drivers/net/can/Kconfig
48316 @@ -98,7 +98,7 @@ config CAN_JANZ_ICAN3
48317
48318 config CAN_FLEXCAN
48319 tristate "Support for Freescale FLEXCAN based chips"
48320 - depends on ARM || PPC
48321 + depends on (ARM && CPU_LITTLE_ENDIAN) || PPC
48322 ---help---
48323 Say Y here if you want to support for Freescale FlexCAN.
48324
48325 diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c
48326 index 6403503..a0c8bb6 100644
48327 --- a/drivers/net/can/dev.c
48328 +++ b/drivers/net/can/dev.c
48329 @@ -869,7 +869,7 @@ static int can_newlink(struct net *src_net, struct net_device *dev,
48330 return -EOPNOTSUPP;
48331 }
48332
48333 -static struct rtnl_link_ops can_link_ops __read_mostly = {
48334 +static struct rtnl_link_ops can_link_ops = {
48335 .kind = "can",
48336 .maxtype = IFLA_CAN_MAX,
48337 .policy = can_policy,
48338 diff --git a/drivers/net/can/vcan.c b/drivers/net/can/vcan.c
48339 index 4e94057..32032ff 100644
48340 --- a/drivers/net/can/vcan.c
48341 +++ b/drivers/net/can/vcan.c
48342 @@ -166,7 +166,7 @@ static void vcan_setup(struct net_device *dev)
48343 dev->destructor = free_netdev;
48344 }
48345
48346 -static struct rtnl_link_ops vcan_link_ops __read_mostly = {
48347 +static struct rtnl_link_ops vcan_link_ops = {
48348 .kind = "vcan",
48349 .setup = vcan_setup,
48350 };
48351 diff --git a/drivers/net/dummy.c b/drivers/net/dummy.c
48352 index ff435fb..d408b1f 100644
48353 --- a/drivers/net/dummy.c
48354 +++ b/drivers/net/dummy.c
48355 @@ -149,7 +149,7 @@ static int dummy_validate(struct nlattr *tb[], struct nlattr *data[])
48356 return 0;
48357 }
48358
48359 -static struct rtnl_link_ops dummy_link_ops __read_mostly = {
48360 +static struct rtnl_link_ops dummy_link_ops = {
48361 .kind = "dummy",
48362 .setup = dummy_setup,
48363 .validate = dummy_validate,
48364 diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
48365 index 1d162cc..b546a75 100644
48366 --- a/drivers/net/ethernet/8390/ax88796.c
48367 +++ b/drivers/net/ethernet/8390/ax88796.c
48368 @@ -889,9 +889,11 @@ static int ax_probe(struct platform_device *pdev)
48369 if (ax->plat->reg_offsets)
48370 ei_local->reg_offset = ax->plat->reg_offsets;
48371 else {
48372 + resource_size_t _mem_size = mem_size;
48373 + do_div(_mem_size, 0x18);
48374 ei_local->reg_offset = ax->reg_offsets;
48375 for (ret = 0; ret < 0x18; ret++)
48376 - ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
48377 + ax->reg_offsets[ret] = _mem_size * ret;
48378 }
48379
48380 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
48381 diff --git a/drivers/net/ethernet/altera/altera_tse_main.c b/drivers/net/ethernet/altera/altera_tse_main.c
48382 index 7330681..7e9e463 100644
48383 --- a/drivers/net/ethernet/altera/altera_tse_main.c
48384 +++ b/drivers/net/ethernet/altera/altera_tse_main.c
48385 @@ -1182,7 +1182,7 @@ static int tse_shutdown(struct net_device *dev)
48386 return 0;
48387 }
48388
48389 -static struct net_device_ops altera_tse_netdev_ops = {
48390 +static net_device_ops_no_const altera_tse_netdev_ops __read_only = {
48391 .ndo_open = tse_open,
48392 .ndo_stop = tse_shutdown,
48393 .ndo_start_xmit = tse_start_xmit,
48394 @@ -1439,11 +1439,13 @@ static int altera_tse_probe(struct platform_device *pdev)
48395 ndev->netdev_ops = &altera_tse_netdev_ops;
48396 altera_tse_set_ethtool_ops(ndev);
48397
48398 + pax_open_kernel();
48399 altera_tse_netdev_ops.ndo_set_rx_mode = tse_set_rx_mode;
48400
48401 if (priv->hash_filter)
48402 altera_tse_netdev_ops.ndo_set_rx_mode =
48403 tse_set_rx_mode_hashfilter;
48404 + pax_close_kernel();
48405
48406 /* Scatter/gather IO is not supported,
48407 * so it is turned off
48408 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-common.h b/drivers/net/ethernet/amd/xgbe/xgbe-common.h
48409 index cc25a3a..c8d72d3 100644
48410 --- a/drivers/net/ethernet/amd/xgbe/xgbe-common.h
48411 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-common.h
48412 @@ -1083,14 +1083,14 @@ do { \
48413 * operations, everything works on mask values.
48414 */
48415 #define XMDIO_READ(_pdata, _mmd, _reg) \
48416 - ((_pdata)->hw_if.read_mmd_regs((_pdata), 0, \
48417 + ((_pdata)->hw_if->read_mmd_regs((_pdata), 0, \
48418 MII_ADDR_C45 | (_mmd << 16) | ((_reg) & 0xffff)))
48419
48420 #define XMDIO_READ_BITS(_pdata, _mmd, _reg, _mask) \
48421 (XMDIO_READ((_pdata), _mmd, _reg) & _mask)
48422
48423 #define XMDIO_WRITE(_pdata, _mmd, _reg, _val) \
48424 - ((_pdata)->hw_if.write_mmd_regs((_pdata), 0, \
48425 + ((_pdata)->hw_if->write_mmd_regs((_pdata), 0, \
48426 MII_ADDR_C45 | (_mmd << 16) | ((_reg) & 0xffff), (_val)))
48427
48428 #define XMDIO_WRITE_BITS(_pdata, _mmd, _reg, _mask, _val) \
48429 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-dcb.c b/drivers/net/ethernet/amd/xgbe/xgbe-dcb.c
48430 index 7d6a49b..e6d403b 100644
48431 --- a/drivers/net/ethernet/amd/xgbe/xgbe-dcb.c
48432 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-dcb.c
48433 @@ -188,7 +188,7 @@ static int xgbe_dcb_ieee_setets(struct net_device *netdev,
48434
48435 memcpy(pdata->ets, ets, sizeof(*pdata->ets));
48436
48437 - pdata->hw_if.config_dcb_tc(pdata);
48438 + pdata->hw_if->config_dcb_tc(pdata);
48439
48440 return 0;
48441 }
48442 @@ -227,7 +227,7 @@ static int xgbe_dcb_ieee_setpfc(struct net_device *netdev,
48443
48444 memcpy(pdata->pfc, pfc, sizeof(*pdata->pfc));
48445
48446 - pdata->hw_if.config_dcb_pfc(pdata);
48447 + pdata->hw_if->config_dcb_pfc(pdata);
48448
48449 return 0;
48450 }
48451 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-desc.c b/drivers/net/ethernet/amd/xgbe/xgbe-desc.c
48452 index 1c5d62e..8e14d54 100644
48453 --- a/drivers/net/ethernet/amd/xgbe/xgbe-desc.c
48454 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-desc.c
48455 @@ -236,7 +236,7 @@ err_ring:
48456
48457 static void xgbe_wrapper_tx_descriptor_init(struct xgbe_prv_data *pdata)
48458 {
48459 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48460 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48461 struct xgbe_channel *channel;
48462 struct xgbe_ring *ring;
48463 struct xgbe_ring_data *rdata;
48464 @@ -277,7 +277,7 @@ static void xgbe_wrapper_tx_descriptor_init(struct xgbe_prv_data *pdata)
48465
48466 static void xgbe_wrapper_rx_descriptor_init(struct xgbe_prv_data *pdata)
48467 {
48468 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48469 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48470 struct xgbe_channel *channel;
48471 struct xgbe_ring *ring;
48472 struct xgbe_ring_desc *rdesc;
48473 @@ -506,7 +506,7 @@ err_out:
48474 static void xgbe_realloc_skb(struct xgbe_channel *channel)
48475 {
48476 struct xgbe_prv_data *pdata = channel->pdata;
48477 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48478 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48479 struct xgbe_ring *ring = channel->rx_ring;
48480 struct xgbe_ring_data *rdata;
48481 struct sk_buff *skb = NULL;
48482 @@ -550,17 +550,12 @@ static void xgbe_realloc_skb(struct xgbe_channel *channel)
48483 DBGPR("<--xgbe_realloc_skb\n");
48484 }
48485
48486 -void xgbe_init_function_ptrs_desc(struct xgbe_desc_if *desc_if)
48487 -{
48488 - DBGPR("-->xgbe_init_function_ptrs_desc\n");
48489 -
48490 - desc_if->alloc_ring_resources = xgbe_alloc_ring_resources;
48491 - desc_if->free_ring_resources = xgbe_free_ring_resources;
48492 - desc_if->map_tx_skb = xgbe_map_tx_skb;
48493 - desc_if->realloc_skb = xgbe_realloc_skb;
48494 - desc_if->unmap_skb = xgbe_unmap_skb;
48495 - desc_if->wrapper_tx_desc_init = xgbe_wrapper_tx_descriptor_init;
48496 - desc_if->wrapper_rx_desc_init = xgbe_wrapper_rx_descriptor_init;
48497 -
48498 - DBGPR("<--xgbe_init_function_ptrs_desc\n");
48499 -}
48500 +const struct xgbe_desc_if default_xgbe_desc_if = {
48501 + .alloc_ring_resources = xgbe_alloc_ring_resources,
48502 + .free_ring_resources = xgbe_free_ring_resources,
48503 + .map_tx_skb = xgbe_map_tx_skb,
48504 + .realloc_skb = xgbe_realloc_skb,
48505 + .unmap_skb = xgbe_unmap_skb,
48506 + .wrapper_tx_desc_init = xgbe_wrapper_tx_descriptor_init,
48507 + .wrapper_rx_desc_init = xgbe_wrapper_rx_descriptor_init,
48508 +};
48509 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-dev.c b/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
48510 index ea27383..faa8936 100644
48511 --- a/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
48512 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
48513 @@ -2463,7 +2463,7 @@ static void xgbe_powerdown_rx(struct xgbe_prv_data *pdata)
48514
48515 static int xgbe_init(struct xgbe_prv_data *pdata)
48516 {
48517 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
48518 + struct xgbe_desc_if *desc_if = pdata->desc_if;
48519 int ret;
48520
48521 DBGPR("-->xgbe_init\n");
48522 @@ -2525,101 +2525,96 @@ static int xgbe_init(struct xgbe_prv_data *pdata)
48523 return 0;
48524 }
48525
48526 -void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *hw_if)
48527 -{
48528 - DBGPR("-->xgbe_init_function_ptrs\n");
48529 -
48530 - hw_if->tx_complete = xgbe_tx_complete;
48531 -
48532 - hw_if->set_promiscuous_mode = xgbe_set_promiscuous_mode;
48533 - hw_if->set_all_multicast_mode = xgbe_set_all_multicast_mode;
48534 - hw_if->add_mac_addresses = xgbe_add_mac_addresses;
48535 - hw_if->set_mac_address = xgbe_set_mac_address;
48536 -
48537 - hw_if->enable_rx_csum = xgbe_enable_rx_csum;
48538 - hw_if->disable_rx_csum = xgbe_disable_rx_csum;
48539 -
48540 - hw_if->enable_rx_vlan_stripping = xgbe_enable_rx_vlan_stripping;
48541 - hw_if->disable_rx_vlan_stripping = xgbe_disable_rx_vlan_stripping;
48542 - hw_if->enable_rx_vlan_filtering = xgbe_enable_rx_vlan_filtering;
48543 - hw_if->disable_rx_vlan_filtering = xgbe_disable_rx_vlan_filtering;
48544 - hw_if->update_vlan_hash_table = xgbe_update_vlan_hash_table;
48545 -
48546 - hw_if->read_mmd_regs = xgbe_read_mmd_regs;
48547 - hw_if->write_mmd_regs = xgbe_write_mmd_regs;
48548 -
48549 - hw_if->set_gmii_speed = xgbe_set_gmii_speed;
48550 - hw_if->set_gmii_2500_speed = xgbe_set_gmii_2500_speed;
48551 - hw_if->set_xgmii_speed = xgbe_set_xgmii_speed;
48552 -
48553 - hw_if->enable_tx = xgbe_enable_tx;
48554 - hw_if->disable_tx = xgbe_disable_tx;
48555 - hw_if->enable_rx = xgbe_enable_rx;
48556 - hw_if->disable_rx = xgbe_disable_rx;
48557 -
48558 - hw_if->powerup_tx = xgbe_powerup_tx;
48559 - hw_if->powerdown_tx = xgbe_powerdown_tx;
48560 - hw_if->powerup_rx = xgbe_powerup_rx;
48561 - hw_if->powerdown_rx = xgbe_powerdown_rx;
48562 -
48563 - hw_if->pre_xmit = xgbe_pre_xmit;
48564 - hw_if->dev_read = xgbe_dev_read;
48565 - hw_if->enable_int = xgbe_enable_int;
48566 - hw_if->disable_int = xgbe_disable_int;
48567 - hw_if->init = xgbe_init;
48568 - hw_if->exit = xgbe_exit;
48569 +const struct xgbe_hw_if default_xgbe_hw_if = {
48570 + .tx_complete = xgbe_tx_complete,
48571 +
48572 + .set_promiscuous_mode = xgbe_set_promiscuous_mode,
48573 + .set_all_multicast_mode = xgbe_set_all_multicast_mode,
48574 + .add_mac_addresses = xgbe_add_mac_addresses,
48575 + .set_mac_address = xgbe_set_mac_address,
48576 +
48577 + .enable_rx_csum = xgbe_enable_rx_csum,
48578 + .disable_rx_csum = xgbe_disable_rx_csum,
48579 +
48580 + .enable_rx_vlan_stripping = xgbe_enable_rx_vlan_stripping,
48581 + .disable_rx_vlan_stripping = xgbe_disable_rx_vlan_stripping,
48582 + .enable_rx_vlan_filtering = xgbe_enable_rx_vlan_filtering,
48583 + .disable_rx_vlan_filtering = xgbe_disable_rx_vlan_filtering,
48584 + .update_vlan_hash_table = xgbe_update_vlan_hash_table,
48585 +
48586 + .read_mmd_regs = xgbe_read_mmd_regs,
48587 + .write_mmd_regs = xgbe_write_mmd_regs,
48588 +
48589 + .set_gmii_speed = xgbe_set_gmii_speed,
48590 + .set_gmii_2500_speed = xgbe_set_gmii_2500_speed,
48591 + .set_xgmii_speed = xgbe_set_xgmii_speed,
48592 +
48593 + .enable_tx = xgbe_enable_tx,
48594 + .disable_tx = xgbe_disable_tx,
48595 + .enable_rx = xgbe_enable_rx,
48596 + .disable_rx = xgbe_disable_rx,
48597 +
48598 + .powerup_tx = xgbe_powerup_tx,
48599 + .powerdown_tx = xgbe_powerdown_tx,
48600 + .powerup_rx = xgbe_powerup_rx,
48601 + .powerdown_rx = xgbe_powerdown_rx,
48602 +
48603 + .pre_xmit = xgbe_pre_xmit,
48604 + .dev_read = xgbe_dev_read,
48605 + .enable_int = xgbe_enable_int,
48606 + .disable_int = xgbe_disable_int,
48607 + .init = xgbe_init,
48608 + .exit = xgbe_exit,
48609
48610 /* Descriptor related Sequences have to be initialized here */
48611 - hw_if->tx_desc_init = xgbe_tx_desc_init;
48612 - hw_if->rx_desc_init = xgbe_rx_desc_init;
48613 - hw_if->tx_desc_reset = xgbe_tx_desc_reset;
48614 - hw_if->rx_desc_reset = xgbe_rx_desc_reset;
48615 - hw_if->is_last_desc = xgbe_is_last_desc;
48616 - hw_if->is_context_desc = xgbe_is_context_desc;
48617 + .tx_desc_init = xgbe_tx_desc_init,
48618 + .rx_desc_init = xgbe_rx_desc_init,
48619 + .tx_desc_reset = xgbe_tx_desc_reset,
48620 + .rx_desc_reset = xgbe_rx_desc_reset,
48621 + .is_last_desc = xgbe_is_last_desc,
48622 + .is_context_desc = xgbe_is_context_desc,
48623
48624 /* For FLOW ctrl */
48625 - hw_if->config_tx_flow_control = xgbe_config_tx_flow_control;
48626 - hw_if->config_rx_flow_control = xgbe_config_rx_flow_control;
48627 + .config_tx_flow_control = xgbe_config_tx_flow_control,
48628 + .config_rx_flow_control = xgbe_config_rx_flow_control,
48629
48630 /* For RX coalescing */
48631 - hw_if->config_rx_coalesce = xgbe_config_rx_coalesce;
48632 - hw_if->config_tx_coalesce = xgbe_config_tx_coalesce;
48633 - hw_if->usec_to_riwt = xgbe_usec_to_riwt;
48634 - hw_if->riwt_to_usec = xgbe_riwt_to_usec;
48635 + .config_rx_coalesce = xgbe_config_rx_coalesce,
48636 + .config_tx_coalesce = xgbe_config_tx_coalesce,
48637 + .usec_to_riwt = xgbe_usec_to_riwt,
48638 + .riwt_to_usec = xgbe_riwt_to_usec,
48639
48640 /* For RX and TX threshold config */
48641 - hw_if->config_rx_threshold = xgbe_config_rx_threshold;
48642 - hw_if->config_tx_threshold = xgbe_config_tx_threshold;
48643 + .config_rx_threshold = xgbe_config_rx_threshold,
48644 + .config_tx_threshold = xgbe_config_tx_threshold,
48645
48646 /* For RX and TX Store and Forward Mode config */
48647 - hw_if->config_rsf_mode = xgbe_config_rsf_mode;
48648 - hw_if->config_tsf_mode = xgbe_config_tsf_mode;
48649 + .config_rsf_mode = xgbe_config_rsf_mode,
48650 + .config_tsf_mode = xgbe_config_tsf_mode,
48651
48652 /* For TX DMA Operating on Second Frame config */
48653 - hw_if->config_osp_mode = xgbe_config_osp_mode;
48654 + .config_osp_mode = xgbe_config_osp_mode,
48655
48656 /* For RX and TX PBL config */
48657 - hw_if->config_rx_pbl_val = xgbe_config_rx_pbl_val;
48658 - hw_if->get_rx_pbl_val = xgbe_get_rx_pbl_val;
48659 - hw_if->config_tx_pbl_val = xgbe_config_tx_pbl_val;
48660 - hw_if->get_tx_pbl_val = xgbe_get_tx_pbl_val;
48661 - hw_if->config_pblx8 = xgbe_config_pblx8;
48662 + .config_rx_pbl_val = xgbe_config_rx_pbl_val,
48663 + .get_rx_pbl_val = xgbe_get_rx_pbl_val,
48664 + .config_tx_pbl_val = xgbe_config_tx_pbl_val,
48665 + .get_tx_pbl_val = xgbe_get_tx_pbl_val,
48666 + .config_pblx8 = xgbe_config_pblx8,
48667
48668 /* For MMC statistics support */
48669 - hw_if->tx_mmc_int = xgbe_tx_mmc_int;
48670 - hw_if->rx_mmc_int = xgbe_rx_mmc_int;
48671 - hw_if->read_mmc_stats = xgbe_read_mmc_stats;
48672 + .tx_mmc_int = xgbe_tx_mmc_int,
48673 + .rx_mmc_int = xgbe_rx_mmc_int,
48674 + .read_mmc_stats = xgbe_read_mmc_stats,
48675
48676 /* For PTP config */
48677 - hw_if->config_tstamp = xgbe_config_tstamp;
48678 - hw_if->update_tstamp_addend = xgbe_update_tstamp_addend;
48679 - hw_if->set_tstamp_time = xgbe_set_tstamp_time;
48680 - hw_if->get_tstamp_time = xgbe_get_tstamp_time;
48681 - hw_if->get_tx_tstamp = xgbe_get_tx_tstamp;
48682 + .config_tstamp = xgbe_config_tstamp,
48683 + .update_tstamp_addend = xgbe_update_tstamp_addend,
48684 + .set_tstamp_time = xgbe_set_tstamp_time,
48685 + .get_tstamp_time = xgbe_get_tstamp_time,
48686 + .get_tx_tstamp = xgbe_get_tx_tstamp,
48687
48688 /* For Data Center Bridging config */
48689 - hw_if->config_dcb_tc = xgbe_config_dcb_tc;
48690 - hw_if->config_dcb_pfc = xgbe_config_dcb_pfc;
48691 -
48692 - DBGPR("<--xgbe_init_function_ptrs\n");
48693 -}
48694 + .config_dcb_tc = xgbe_config_dcb_tc,
48695 + .config_dcb_pfc = xgbe_config_dcb_pfc,
48696 +};
48697 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-drv.c b/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
48698 index b26d758..b0d1c3b 100644
48699 --- a/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
48700 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
48701 @@ -155,7 +155,7 @@ static int xgbe_calc_rx_buf_size(struct net_device *netdev, unsigned int mtu)
48702
48703 static void xgbe_enable_rx_tx_ints(struct xgbe_prv_data *pdata)
48704 {
48705 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48706 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48707 struct xgbe_channel *channel;
48708 enum xgbe_int int_id;
48709 unsigned int i;
48710 @@ -177,7 +177,7 @@ static void xgbe_enable_rx_tx_ints(struct xgbe_prv_data *pdata)
48711
48712 static void xgbe_disable_rx_tx_ints(struct xgbe_prv_data *pdata)
48713 {
48714 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48715 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48716 struct xgbe_channel *channel;
48717 enum xgbe_int int_id;
48718 unsigned int i;
48719 @@ -200,7 +200,7 @@ static void xgbe_disable_rx_tx_ints(struct xgbe_prv_data *pdata)
48720 static irqreturn_t xgbe_isr(int irq, void *data)
48721 {
48722 struct xgbe_prv_data *pdata = data;
48723 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48724 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48725 struct xgbe_channel *channel;
48726 unsigned int dma_isr, dma_ch_isr;
48727 unsigned int mac_isr, mac_tssr;
48728 @@ -447,7 +447,7 @@ static void xgbe_napi_disable(struct xgbe_prv_data *pdata, unsigned int del)
48729
48730 void xgbe_init_tx_coalesce(struct xgbe_prv_data *pdata)
48731 {
48732 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48733 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48734
48735 DBGPR("-->xgbe_init_tx_coalesce\n");
48736
48737 @@ -461,7 +461,7 @@ void xgbe_init_tx_coalesce(struct xgbe_prv_data *pdata)
48738
48739 void xgbe_init_rx_coalesce(struct xgbe_prv_data *pdata)
48740 {
48741 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48742 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48743
48744 DBGPR("-->xgbe_init_rx_coalesce\n");
48745
48746 @@ -475,7 +475,7 @@ void xgbe_init_rx_coalesce(struct xgbe_prv_data *pdata)
48747
48748 static void xgbe_free_tx_skbuff(struct xgbe_prv_data *pdata)
48749 {
48750 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
48751 + struct xgbe_desc_if *desc_if = pdata->desc_if;
48752 struct xgbe_channel *channel;
48753 struct xgbe_ring *ring;
48754 struct xgbe_ring_data *rdata;
48755 @@ -500,7 +500,7 @@ static void xgbe_free_tx_skbuff(struct xgbe_prv_data *pdata)
48756
48757 static void xgbe_free_rx_skbuff(struct xgbe_prv_data *pdata)
48758 {
48759 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
48760 + struct xgbe_desc_if *desc_if = pdata->desc_if;
48761 struct xgbe_channel *channel;
48762 struct xgbe_ring *ring;
48763 struct xgbe_ring_data *rdata;
48764 @@ -526,7 +526,7 @@ static void xgbe_free_rx_skbuff(struct xgbe_prv_data *pdata)
48765 static void xgbe_adjust_link(struct net_device *netdev)
48766 {
48767 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48768 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48769 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48770 struct phy_device *phydev = pdata->phydev;
48771 int new_state = 0;
48772
48773 @@ -634,7 +634,7 @@ static void xgbe_phy_exit(struct xgbe_prv_data *pdata)
48774 int xgbe_powerdown(struct net_device *netdev, unsigned int caller)
48775 {
48776 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48777 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48778 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48779 unsigned long flags;
48780
48781 DBGPR("-->xgbe_powerdown\n");
48782 @@ -672,7 +672,7 @@ int xgbe_powerdown(struct net_device *netdev, unsigned int caller)
48783 int xgbe_powerup(struct net_device *netdev, unsigned int caller)
48784 {
48785 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48786 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48787 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48788 unsigned long flags;
48789
48790 DBGPR("-->xgbe_powerup\n");
48791 @@ -709,7 +709,7 @@ int xgbe_powerup(struct net_device *netdev, unsigned int caller)
48792
48793 static int xgbe_start(struct xgbe_prv_data *pdata)
48794 {
48795 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48796 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48797 struct net_device *netdev = pdata->netdev;
48798
48799 DBGPR("-->xgbe_start\n");
48800 @@ -735,7 +735,7 @@ static int xgbe_start(struct xgbe_prv_data *pdata)
48801
48802 static void xgbe_stop(struct xgbe_prv_data *pdata)
48803 {
48804 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48805 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48806 struct net_device *netdev = pdata->netdev;
48807
48808 DBGPR("-->xgbe_stop\n");
48809 @@ -755,7 +755,7 @@ static void xgbe_stop(struct xgbe_prv_data *pdata)
48810
48811 static void xgbe_restart_dev(struct xgbe_prv_data *pdata, unsigned int reset)
48812 {
48813 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48814 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48815
48816 DBGPR("-->xgbe_restart_dev\n");
48817
48818 @@ -952,7 +952,7 @@ static int xgbe_set_hwtstamp_settings(struct xgbe_prv_data *pdata,
48819 return -ERANGE;
48820 }
48821
48822 - pdata->hw_if.config_tstamp(pdata, mac_tscr);
48823 + pdata->hw_if->config_tstamp(pdata, mac_tscr);
48824
48825 memcpy(&pdata->tstamp_config, &config, sizeof(config));
48826
48827 @@ -1090,8 +1090,8 @@ static void xgbe_packet_info(struct xgbe_prv_data *pdata,
48828 static int xgbe_open(struct net_device *netdev)
48829 {
48830 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48831 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48832 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
48833 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48834 + struct xgbe_desc_if *desc_if = pdata->desc_if;
48835 int ret;
48836
48837 DBGPR("-->xgbe_open\n");
48838 @@ -1171,8 +1171,8 @@ err_phy_init:
48839 static int xgbe_close(struct net_device *netdev)
48840 {
48841 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48842 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48843 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
48844 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48845 + struct xgbe_desc_if *desc_if = pdata->desc_if;
48846
48847 DBGPR("-->xgbe_close\n");
48848
48849 @@ -1206,8 +1206,8 @@ static int xgbe_close(struct net_device *netdev)
48850 static int xgbe_xmit(struct sk_buff *skb, struct net_device *netdev)
48851 {
48852 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48853 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48854 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
48855 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48856 + struct xgbe_desc_if *desc_if = pdata->desc_if;
48857 struct xgbe_channel *channel;
48858 struct xgbe_ring *ring;
48859 struct xgbe_packet_data *packet;
48860 @@ -1276,7 +1276,7 @@ tx_netdev_return:
48861 static void xgbe_set_rx_mode(struct net_device *netdev)
48862 {
48863 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48864 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48865 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48866 unsigned int pr_mode, am_mode;
48867
48868 DBGPR("-->xgbe_set_rx_mode\n");
48869 @@ -1295,7 +1295,7 @@ static void xgbe_set_rx_mode(struct net_device *netdev)
48870 static int xgbe_set_mac_address(struct net_device *netdev, void *addr)
48871 {
48872 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48873 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48874 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48875 struct sockaddr *saddr = addr;
48876
48877 DBGPR("-->xgbe_set_mac_address\n");
48878 @@ -1362,7 +1362,7 @@ static struct rtnl_link_stats64 *xgbe_get_stats64(struct net_device *netdev,
48879
48880 DBGPR("-->%s\n", __func__);
48881
48882 - pdata->hw_if.read_mmc_stats(pdata);
48883 + pdata->hw_if->read_mmc_stats(pdata);
48884
48885 s->rx_packets = pstats->rxframecount_gb;
48886 s->rx_bytes = pstats->rxoctetcount_gb;
48887 @@ -1389,7 +1389,7 @@ static int xgbe_vlan_rx_add_vid(struct net_device *netdev, __be16 proto,
48888 u16 vid)
48889 {
48890 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48891 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48892 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48893
48894 DBGPR("-->%s\n", __func__);
48895
48896 @@ -1405,7 +1405,7 @@ static int xgbe_vlan_rx_kill_vid(struct net_device *netdev, __be16 proto,
48897 u16 vid)
48898 {
48899 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48900 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48901 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48902
48903 DBGPR("-->%s\n", __func__);
48904
48905 @@ -1465,7 +1465,7 @@ static int xgbe_set_features(struct net_device *netdev,
48906 netdev_features_t features)
48907 {
48908 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48909 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48910 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48911 unsigned int rxcsum, rxvlan, rxvlan_filter;
48912
48913 rxcsum = pdata->netdev_features & NETIF_F_RXCSUM;
48914 @@ -1521,7 +1521,7 @@ struct net_device_ops *xgbe_get_netdev_ops(void)
48915 static void xgbe_rx_refresh(struct xgbe_channel *channel)
48916 {
48917 struct xgbe_prv_data *pdata = channel->pdata;
48918 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
48919 + struct xgbe_desc_if *desc_if = pdata->desc_if;
48920 struct xgbe_ring *ring = channel->rx_ring;
48921 struct xgbe_ring_data *rdata;
48922
48923 @@ -1537,8 +1537,8 @@ static void xgbe_rx_refresh(struct xgbe_channel *channel)
48924 static int xgbe_tx_poll(struct xgbe_channel *channel)
48925 {
48926 struct xgbe_prv_data *pdata = channel->pdata;
48927 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48928 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
48929 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48930 + struct xgbe_desc_if *desc_if = pdata->desc_if;
48931 struct xgbe_ring *ring = channel->tx_ring;
48932 struct xgbe_ring_data *rdata;
48933 struct xgbe_ring_desc *rdesc;
48934 @@ -1590,7 +1590,7 @@ static int xgbe_tx_poll(struct xgbe_channel *channel)
48935 static int xgbe_rx_poll(struct xgbe_channel *channel, int budget)
48936 {
48937 struct xgbe_prv_data *pdata = channel->pdata;
48938 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48939 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48940 struct xgbe_ring *ring = channel->rx_ring;
48941 struct xgbe_ring_data *rdata;
48942 struct xgbe_packet_data *packet;
48943 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c b/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
48944 index 46f6130..f37dde3 100644
48945 --- a/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
48946 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
48947 @@ -203,7 +203,7 @@ static void xgbe_get_ethtool_stats(struct net_device *netdev,
48948
48949 DBGPR("-->%s\n", __func__);
48950
48951 - pdata->hw_if.read_mmc_stats(pdata);
48952 + pdata->hw_if->read_mmc_stats(pdata);
48953 for (i = 0; i < XGBE_STATS_COUNT; i++) {
48954 stat = (u8 *)pdata + xgbe_gstring_stats[i].stat_offset;
48955 *data++ = *(u64 *)stat;
48956 @@ -378,7 +378,7 @@ static int xgbe_get_coalesce(struct net_device *netdev,
48957 struct ethtool_coalesce *ec)
48958 {
48959 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48960 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48961 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48962 unsigned int riwt;
48963
48964 DBGPR("-->xgbe_get_coalesce\n");
48965 @@ -401,7 +401,7 @@ static int xgbe_set_coalesce(struct net_device *netdev,
48966 struct ethtool_coalesce *ec)
48967 {
48968 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48969 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48970 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48971 unsigned int rx_frames, rx_riwt, rx_usecs;
48972 unsigned int tx_frames, tx_usecs;
48973
48974 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-main.c b/drivers/net/ethernet/amd/xgbe/xgbe-main.c
48975 index bdf9cfa..340aea1 100644
48976 --- a/drivers/net/ethernet/amd/xgbe/xgbe-main.c
48977 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-main.c
48978 @@ -210,12 +210,6 @@ static void xgbe_default_config(struct xgbe_prv_data *pdata)
48979 DBGPR("<--xgbe_default_config\n");
48980 }
48981
48982 -static void xgbe_init_all_fptrs(struct xgbe_prv_data *pdata)
48983 -{
48984 - xgbe_init_function_ptrs_dev(&pdata->hw_if);
48985 - xgbe_init_function_ptrs_desc(&pdata->desc_if);
48986 -}
48987 -
48988 static int xgbe_probe(struct platform_device *pdev)
48989 {
48990 struct xgbe_prv_data *pdata;
48991 @@ -328,9 +322,8 @@ static int xgbe_probe(struct platform_device *pdev)
48992 netdev->base_addr = (unsigned long)pdata->xgmac_regs;
48993
48994 /* Set all the function pointers */
48995 - xgbe_init_all_fptrs(pdata);
48996 - hw_if = &pdata->hw_if;
48997 - desc_if = &pdata->desc_if;
48998 + hw_if = pdata->hw_if = &default_xgbe_hw_if;
48999 + desc_if = pdata->desc_if = &default_xgbe_desc_if;
49000
49001 /* Issue software reset to device */
49002 hw_if->exit(pdata);
49003 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c b/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c
49004 index 6d2221e..47d1325 100644
49005 --- a/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c
49006 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c
49007 @@ -127,7 +127,7 @@
49008 static int xgbe_mdio_read(struct mii_bus *mii, int prtad, int mmd_reg)
49009 {
49010 struct xgbe_prv_data *pdata = mii->priv;
49011 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
49012 + struct xgbe_hw_if *hw_if = pdata->hw_if;
49013 int mmd_data;
49014
49015 DBGPR_MDIO("-->xgbe_mdio_read: prtad=%#x mmd_reg=%#x\n",
49016 @@ -144,7 +144,7 @@ static int xgbe_mdio_write(struct mii_bus *mii, int prtad, int mmd_reg,
49017 u16 mmd_val)
49018 {
49019 struct xgbe_prv_data *pdata = mii->priv;
49020 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
49021 + struct xgbe_hw_if *hw_if = pdata->hw_if;
49022 int mmd_data = mmd_val;
49023
49024 DBGPR_MDIO("-->xgbe_mdio_write: prtad=%#x mmd_reg=%#x mmd_data=%#x\n",
49025 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c b/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
49026 index 37e64cf..c3b61cf 100644
49027 --- a/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
49028 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
49029 @@ -130,7 +130,7 @@ static cycle_t xgbe_cc_read(const struct cyclecounter *cc)
49030 tstamp_cc);
49031 u64 nsec;
49032
49033 - nsec = pdata->hw_if.get_tstamp_time(pdata);
49034 + nsec = pdata->hw_if->get_tstamp_time(pdata);
49035
49036 return nsec;
49037 }
49038 @@ -159,7 +159,7 @@ static int xgbe_adjfreq(struct ptp_clock_info *info, s32 delta)
49039
49040 spin_lock_irqsave(&pdata->tstamp_lock, flags);
49041
49042 - pdata->hw_if.update_tstamp_addend(pdata, addend);
49043 + pdata->hw_if->update_tstamp_addend(pdata, addend);
49044
49045 spin_unlock_irqrestore(&pdata->tstamp_lock, flags);
49046
49047 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe.h b/drivers/net/ethernet/amd/xgbe/xgbe.h
49048 index e9fe6e6..875fbaf 100644
49049 --- a/drivers/net/ethernet/amd/xgbe/xgbe.h
49050 +++ b/drivers/net/ethernet/amd/xgbe/xgbe.h
49051 @@ -585,8 +585,8 @@ struct xgbe_prv_data {
49052
49053 int irq_number;
49054
49055 - struct xgbe_hw_if hw_if;
49056 - struct xgbe_desc_if desc_if;
49057 + const struct xgbe_hw_if *hw_if;
49058 + const struct xgbe_desc_if *desc_if;
49059
49060 /* AXI DMA settings */
49061 unsigned int axdomain;
49062 @@ -699,6 +699,9 @@ struct xgbe_prv_data {
49063 #endif
49064 };
49065
49066 +extern const struct xgbe_hw_if default_xgbe_hw_if;
49067 +extern const struct xgbe_desc_if default_xgbe_desc_if;
49068 +
49069 /* Function prototypes*/
49070
49071 void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *);
49072 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
49073 index 571427c..e9fe9e7 100644
49074 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
49075 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
49076 @@ -1058,7 +1058,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
49077 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
49078 {
49079 /* RX_MODE controlling object */
49080 - bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
49081 + bnx2x_init_rx_mode_obj(bp);
49082
49083 /* multicast configuration controlling object */
49084 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
49085 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
49086 index b193604..8873bfd 100644
49087 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
49088 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
49089 @@ -2329,15 +2329,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
49090 return rc;
49091 }
49092
49093 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
49094 - struct bnx2x_rx_mode_obj *o)
49095 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
49096 {
49097 if (CHIP_IS_E1x(bp)) {
49098 - o->wait_comp = bnx2x_empty_rx_mode_wait;
49099 - o->config_rx_mode = bnx2x_set_rx_mode_e1x;
49100 + bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
49101 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
49102 } else {
49103 - o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
49104 - o->config_rx_mode = bnx2x_set_rx_mode_e2;
49105 + bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
49106 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
49107 }
49108 }
49109
49110 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
49111 index 718ecd2..2183b2f 100644
49112 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
49113 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
49114 @@ -1340,8 +1340,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
49115
49116 /********************* RX MODE ****************/
49117
49118 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
49119 - struct bnx2x_rx_mode_obj *o);
49120 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
49121
49122 /**
49123 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
49124 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
49125 index 31c9f82..e65e986 100644
49126 --- a/drivers/net/ethernet/broadcom/tg3.h
49127 +++ b/drivers/net/ethernet/broadcom/tg3.h
49128 @@ -150,6 +150,7 @@
49129 #define CHIPREV_ID_5750_A0 0x4000
49130 #define CHIPREV_ID_5750_A1 0x4001
49131 #define CHIPREV_ID_5750_A3 0x4003
49132 +#define CHIPREV_ID_5750_C1 0x4201
49133 #define CHIPREV_ID_5750_C2 0x4202
49134 #define CHIPREV_ID_5752_A0_HW 0x5000
49135 #define CHIPREV_ID_5752_A0 0x6000
49136 diff --git a/drivers/net/ethernet/brocade/bna/bna_enet.c b/drivers/net/ethernet/brocade/bna/bna_enet.c
49137 index 13f9636..228040f 100644
49138 --- a/drivers/net/ethernet/brocade/bna/bna_enet.c
49139 +++ b/drivers/net/ethernet/brocade/bna/bna_enet.c
49140 @@ -1690,10 +1690,10 @@ bna_cb_ioceth_reset(void *arg)
49141 }
49142
49143 static struct bfa_ioc_cbfn bna_ioceth_cbfn = {
49144 - bna_cb_ioceth_enable,
49145 - bna_cb_ioceth_disable,
49146 - bna_cb_ioceth_hbfail,
49147 - bna_cb_ioceth_reset
49148 + .enable_cbfn = bna_cb_ioceth_enable,
49149 + .disable_cbfn = bna_cb_ioceth_disable,
49150 + .hbfail_cbfn = bna_cb_ioceth_hbfail,
49151 + .reset_cbfn = bna_cb_ioceth_reset
49152 };
49153
49154 static void bna_attr_init(struct bna_ioceth *ioceth)
49155 diff --git a/drivers/net/ethernet/brocade/bna/bnad.c b/drivers/net/ethernet/brocade/bna/bnad.c
49156 index ffc92a4..40edc77 100644
49157 --- a/drivers/net/ethernet/brocade/bna/bnad.c
49158 +++ b/drivers/net/ethernet/brocade/bna/bnad.c
49159 @@ -552,6 +552,7 @@ bnad_cq_setup_skb_frags(struct bna_rcb *rcb, struct sk_buff *skb,
49160
49161 len = (vec == nvecs) ?
49162 last_fraglen : unmap->vector.len;
49163 + skb->truesize += unmap->vector.len;
49164 totlen += len;
49165
49166 skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags,
49167 @@ -563,7 +564,6 @@ bnad_cq_setup_skb_frags(struct bna_rcb *rcb, struct sk_buff *skb,
49168
49169 skb->len += totlen;
49170 skb->data_len += totlen;
49171 - skb->truesize += totlen;
49172 }
49173
49174 static inline void
49175 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
49176 index 8cffcdf..aadf043 100644
49177 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
49178 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
49179 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
49180 */
49181 struct l2t_skb_cb {
49182 arp_failure_handler_func arp_failure_handler;
49183 -};
49184 +} __no_const;
49185
49186 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
49187
49188 diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
49189 index 9f5f3c3..86d21a6 100644
49190 --- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
49191 +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
49192 @@ -2359,7 +2359,7 @@ static void get_regs(struct net_device *dev, struct ethtool_regs *regs,
49193
49194 int i;
49195 struct adapter *ap = netdev2adap(dev);
49196 - static const unsigned int *reg_ranges;
49197 + const unsigned int *reg_ranges;
49198 int arr_size = 0, buf_size = 0;
49199
49200 if (is_t4(ap->params.chip)) {
49201 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
49202 index cf8b6ff..274271e 100644
49203 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
49204 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
49205 @@ -5387,7 +5387,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
49206 for (i=0; i<ETH_ALEN; i++) {
49207 tmp.addr[i] = dev->dev_addr[i];
49208 }
49209 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
49210 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
49211 break;
49212
49213 case DE4X5_SET_HWADDR: /* Set the hardware address */
49214 @@ -5427,7 +5427,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
49215 spin_lock_irqsave(&lp->lock, flags);
49216 memcpy(&statbuf, &lp->pktStats, ioc->len);
49217 spin_unlock_irqrestore(&lp->lock, flags);
49218 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
49219 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
49220 return -EFAULT;
49221 break;
49222 }
49223 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
49224 index 93ff8ef..39c64dd 100644
49225 --- a/drivers/net/ethernet/emulex/benet/be_main.c
49226 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
49227 @@ -533,7 +533,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
49228
49229 if (wrapped)
49230 newacc += 65536;
49231 - ACCESS_ONCE(*acc) = newacc;
49232 + ACCESS_ONCE_RW(*acc) = newacc;
49233 }
49234
49235 static void populate_erx_stats(struct be_adapter *adapter,
49236 @@ -4286,6 +4286,9 @@ static int be_ndo_bridge_setlink(struct net_device *dev, struct nlmsghdr *nlh)
49237 if (nla_type(attr) != IFLA_BRIDGE_MODE)
49238 continue;
49239
49240 + if (nla_len(attr) < sizeof(mode))
49241 + return -EINVAL;
49242 +
49243 mode = nla_get_u16(attr);
49244 if (mode != BRIDGE_MODE_VEPA && mode != BRIDGE_MODE_VEB)
49245 return -EINVAL;
49246 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
49247 index c77fa4a..7fd42fc 100644
49248 --- a/drivers/net/ethernet/faraday/ftgmac100.c
49249 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
49250 @@ -30,6 +30,8 @@
49251 #include <linux/netdevice.h>
49252 #include <linux/phy.h>
49253 #include <linux/platform_device.h>
49254 +#include <linux/interrupt.h>
49255 +#include <linux/irqreturn.h>
49256 #include <net/ip.h>
49257
49258 #include "ftgmac100.h"
49259 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
49260 index 4ff1adc..0ea6bf4 100644
49261 --- a/drivers/net/ethernet/faraday/ftmac100.c
49262 +++ b/drivers/net/ethernet/faraday/ftmac100.c
49263 @@ -31,6 +31,8 @@
49264 #include <linux/module.h>
49265 #include <linux/netdevice.h>
49266 #include <linux/platform_device.h>
49267 +#include <linux/interrupt.h>
49268 +#include <linux/irqreturn.h>
49269
49270 #include "ftmac100.h"
49271
49272 diff --git a/drivers/net/ethernet/intel/i40e/i40e_ptp.c b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
49273 index 537b621..07f87ce 100644
49274 --- a/drivers/net/ethernet/intel/i40e/i40e_ptp.c
49275 +++ b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
49276 @@ -401,7 +401,7 @@ void i40e_ptp_set_increment(struct i40e_pf *pf)
49277 wr32(hw, I40E_PRTTSYN_INC_H, incval >> 32);
49278
49279 /* Update the base adjustement value. */
49280 - ACCESS_ONCE(pf->ptp_base_adj) = incval;
49281 + ACCESS_ONCE_RW(pf->ptp_base_adj) = incval;
49282 smp_mb(); /* Force the above update. */
49283 }
49284
49285 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
49286 index e82821f..c7dd0af 100644
49287 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
49288 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
49289 @@ -7789,6 +7789,9 @@ static int ixgbe_ndo_bridge_setlink(struct net_device *dev,
49290 if (nla_type(attr) != IFLA_BRIDGE_MODE)
49291 continue;
49292
49293 + if (nla_len(attr) < sizeof(mode))
49294 + return -EINVAL;
49295 +
49296 mode = nla_get_u16(attr);
49297 if (mode == BRIDGE_MODE_VEPA) {
49298 reg = 0;
49299 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
49300 index 5fd4b52..87aa34b 100644
49301 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
49302 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
49303 @@ -794,7 +794,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
49304 }
49305
49306 /* update the base incval used to calculate frequency adjustment */
49307 - ACCESS_ONCE(adapter->base_incval) = incval;
49308 + ACCESS_ONCE_RW(adapter->base_incval) = incval;
49309 smp_mb();
49310
49311 /* need lock to prevent incorrect read while modifying cyclecounter */
49312 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c
49313 index c14d4d8..66da603 100644
49314 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c
49315 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c
49316 @@ -1259,6 +1259,9 @@ int ixgbe_ndo_set_vf_spoofchk(struct net_device *netdev, int vf, bool setting)
49317 struct ixgbe_hw *hw = &adapter->hw;
49318 u32 regval;
49319
49320 + if (vf >= adapter->num_vfs)
49321 + return -EINVAL;
49322 +
49323 adapter->vfinfo[vf].spoofchk_enabled = setting;
49324
49325 regval = IXGBE_READ_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg));
49326 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
49327 index 2bbd01f..e8baa64 100644
49328 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
49329 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
49330 @@ -3457,7 +3457,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
49331 struct __vxge_hw_fifo *fifo;
49332 struct vxge_hw_fifo_config *config;
49333 u32 txdl_size, txdl_per_memblock;
49334 - struct vxge_hw_mempool_cbs fifo_mp_callback;
49335 + static struct vxge_hw_mempool_cbs fifo_mp_callback = {
49336 + .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
49337 + };
49338 +
49339 struct __vxge_hw_virtualpath *vpath;
49340
49341 if ((vp == NULL) || (attr == NULL)) {
49342 @@ -3540,8 +3543,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
49343 goto exit;
49344 }
49345
49346 - fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
49347 -
49348 fifo->mempool =
49349 __vxge_hw_mempool_create(vpath->hldev,
49350 fifo->config->memblock_size,
49351 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
49352 index 3172cdf..d01ab34 100644
49353 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
49354 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
49355 @@ -2190,7 +2190,9 @@ int qlcnic_83xx_configure_opmode(struct qlcnic_adapter *adapter)
49356 max_tx_rings = QLCNIC_MAX_VNIC_TX_RINGS;
49357 } else if (ret == QLC_83XX_DEFAULT_OPMODE) {
49358 ahw->nic_mode = QLCNIC_DEFAULT_MODE;
49359 - adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
49360 + pax_open_kernel();
49361 + *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
49362 + pax_close_kernel();
49363 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
49364 max_sds_rings = QLCNIC_MAX_SDS_RINGS;
49365 max_tx_rings = QLCNIC_MAX_TX_RINGS;
49366 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
49367 index be7d7a6..a8983f8 100644
49368 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
49369 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
49370 @@ -207,17 +207,23 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
49371 case QLCNIC_NON_PRIV_FUNC:
49372 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
49373 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
49374 - nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
49375 + pax_open_kernel();
49376 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
49377 + pax_close_kernel();
49378 break;
49379 case QLCNIC_PRIV_FUNC:
49380 ahw->op_mode = QLCNIC_PRIV_FUNC;
49381 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
49382 - nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
49383 + pax_open_kernel();
49384 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
49385 + pax_close_kernel();
49386 break;
49387 case QLCNIC_MGMT_FUNC:
49388 ahw->op_mode = QLCNIC_MGMT_FUNC;
49389 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
49390 - nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
49391 + pax_open_kernel();
49392 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
49393 + pax_close_kernel();
49394 break;
49395 default:
49396 dev_err(&adapter->pdev->dev, "Invalid Virtual NIC opmode\n");
49397 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
49398 index c9f57fb..208bdc1 100644
49399 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
49400 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
49401 @@ -1285,7 +1285,7 @@ flash_temp:
49402 int qlcnic_dump_fw(struct qlcnic_adapter *adapter)
49403 {
49404 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
49405 - static const struct qlcnic_dump_operations *fw_dump_ops;
49406 + const struct qlcnic_dump_operations *fw_dump_ops;
49407 struct qlcnic_83xx_dump_template_hdr *hdr_83xx;
49408 u32 entry_offset, dump, no_entries, buf_offset = 0;
49409 int i, k, ops_cnt, ops_index, dump_size = 0;
49410 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
49411 index 0921302..927f761 100644
49412 --- a/drivers/net/ethernet/realtek/r8169.c
49413 +++ b/drivers/net/ethernet/realtek/r8169.c
49414 @@ -744,22 +744,22 @@ struct rtl8169_private {
49415 struct mdio_ops {
49416 void (*write)(struct rtl8169_private *, int, int);
49417 int (*read)(struct rtl8169_private *, int);
49418 - } mdio_ops;
49419 + } __no_const mdio_ops;
49420
49421 struct pll_power_ops {
49422 void (*down)(struct rtl8169_private *);
49423 void (*up)(struct rtl8169_private *);
49424 - } pll_power_ops;
49425 + } __no_const pll_power_ops;
49426
49427 struct jumbo_ops {
49428 void (*enable)(struct rtl8169_private *);
49429 void (*disable)(struct rtl8169_private *);
49430 - } jumbo_ops;
49431 + } __no_const jumbo_ops;
49432
49433 struct csi_ops {
49434 void (*write)(struct rtl8169_private *, int, int);
49435 u32 (*read)(struct rtl8169_private *, int);
49436 - } csi_ops;
49437 + } __no_const csi_ops;
49438
49439 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
49440 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
49441 diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
49442 index 6b861e3..204ac86 100644
49443 --- a/drivers/net/ethernet/sfc/ptp.c
49444 +++ b/drivers/net/ethernet/sfc/ptp.c
49445 @@ -822,7 +822,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
49446 ptp->start.dma_addr);
49447
49448 /* Clear flag that signals MC ready */
49449 - ACCESS_ONCE(*start) = 0;
49450 + ACCESS_ONCE_RW(*start) = 0;
49451 rc = efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
49452 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
49453 EFX_BUG_ON_PARANOID(rc);
49454 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
49455 index 08c483b..2c4a553 100644
49456 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
49457 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
49458 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
49459
49460 writel(value, ioaddr + MMC_CNTRL);
49461
49462 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
49463 - MMC_CNTRL, value);
49464 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
49465 +// MMC_CNTRL, value);
49466 }
49467
49468 /* To mask all all interrupts.*/
49469 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
49470 index d5e07de..e3bf20a 100644
49471 --- a/drivers/net/hyperv/hyperv_net.h
49472 +++ b/drivers/net/hyperv/hyperv_net.h
49473 @@ -171,7 +171,7 @@ struct rndis_device {
49474 enum rndis_device_state state;
49475 bool link_state;
49476 bool link_change;
49477 - atomic_t new_req_id;
49478 + atomic_unchecked_t new_req_id;
49479
49480 spinlock_t request_lock;
49481 struct list_head req_list;
49482 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
49483 index 2b86f0b..ecc996f 100644
49484 --- a/drivers/net/hyperv/rndis_filter.c
49485 +++ b/drivers/net/hyperv/rndis_filter.c
49486 @@ -102,7 +102,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
49487 * template
49488 */
49489 set = &rndis_msg->msg.set_req;
49490 - set->req_id = atomic_inc_return(&dev->new_req_id);
49491 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
49492
49493 /* Add to the request list */
49494 spin_lock_irqsave(&dev->request_lock, flags);
49495 @@ -911,7 +911,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
49496
49497 /* Setup the rndis set */
49498 halt = &request->request_msg.msg.halt_req;
49499 - halt->req_id = atomic_inc_return(&dev->new_req_id);
49500 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
49501
49502 /* Ignore return since this msg is optional. */
49503 rndis_filter_send_request(dev, request);
49504 diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
49505 index 6cbc56a..5f7e6c8 100644
49506 --- a/drivers/net/ieee802154/fakehard.c
49507 +++ b/drivers/net/ieee802154/fakehard.c
49508 @@ -365,7 +365,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
49509 phy->transmit_power = 0xbf;
49510
49511 dev->netdev_ops = &fake_ops;
49512 - dev->ml_priv = &fake_mlme;
49513 + dev->ml_priv = (void *)&fake_mlme;
49514
49515 priv = netdev_priv(dev);
49516 priv->phy = phy;
49517 diff --git a/drivers/net/ifb.c b/drivers/net/ifb.c
49518 index d2d4a3d..8b7a1be 100644
49519 --- a/drivers/net/ifb.c
49520 +++ b/drivers/net/ifb.c
49521 @@ -252,7 +252,7 @@ static int ifb_validate(struct nlattr *tb[], struct nlattr *data[])
49522 return 0;
49523 }
49524
49525 -static struct rtnl_link_ops ifb_link_ops __read_mostly = {
49526 +static struct rtnl_link_ops ifb_link_ops = {
49527 .kind = "ifb",
49528 .priv_size = sizeof(struct ifb_private),
49529 .setup = ifb_setup,
49530 diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
49531 index 5f17ad0..e0463c8 100644
49532 --- a/drivers/net/macvlan.c
49533 +++ b/drivers/net/macvlan.c
49534 @@ -264,7 +264,7 @@ static void macvlan_broadcast_enqueue(struct macvlan_port *port,
49535 free_nskb:
49536 kfree_skb(nskb);
49537 err:
49538 - atomic_long_inc(&skb->dev->rx_dropped);
49539 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
49540 }
49541
49542 /* called under rcu_read_lock() from netif_receive_skb */
49543 @@ -1150,13 +1150,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
49544 int macvlan_link_register(struct rtnl_link_ops *ops)
49545 {
49546 /* common fields */
49547 - ops->priv_size = sizeof(struct macvlan_dev);
49548 - ops->validate = macvlan_validate;
49549 - ops->maxtype = IFLA_MACVLAN_MAX;
49550 - ops->policy = macvlan_policy;
49551 - ops->changelink = macvlan_changelink;
49552 - ops->get_size = macvlan_get_size;
49553 - ops->fill_info = macvlan_fill_info;
49554 + pax_open_kernel();
49555 + *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
49556 + *(void **)&ops->validate = macvlan_validate;
49557 + *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
49558 + *(const void **)&ops->policy = macvlan_policy;
49559 + *(void **)&ops->changelink = macvlan_changelink;
49560 + *(void **)&ops->get_size = macvlan_get_size;
49561 + *(void **)&ops->fill_info = macvlan_fill_info;
49562 + pax_close_kernel();
49563
49564 return rtnl_link_register(ops);
49565 };
49566 @@ -1236,7 +1238,7 @@ static int macvlan_device_event(struct notifier_block *unused,
49567 return NOTIFY_DONE;
49568 }
49569
49570 -static struct notifier_block macvlan_notifier_block __read_mostly = {
49571 +static struct notifier_block macvlan_notifier_block = {
49572 .notifier_call = macvlan_device_event,
49573 };
49574
49575 diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
49576 index 07c942b..bce8b8a 100644
49577 --- a/drivers/net/macvtap.c
49578 +++ b/drivers/net/macvtap.c
49579 @@ -422,7 +422,7 @@ static void macvtap_setup(struct net_device *dev)
49580 dev->tx_queue_len = TUN_READQ_SIZE;
49581 }
49582
49583 -static struct rtnl_link_ops macvtap_link_ops __read_mostly = {
49584 +static struct rtnl_link_ops macvtap_link_ops = {
49585 .kind = "macvtap",
49586 .setup = macvtap_setup,
49587 .newlink = macvtap_newlink,
49588 @@ -1023,7 +1023,7 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd,
49589 }
49590
49591 ret = 0;
49592 - if (copy_to_user(&ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
49593 + if (copy_to_user(ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
49594 put_user(q->flags, &ifr->ifr_flags))
49595 ret = -EFAULT;
49596 macvtap_put_vlan(vlan);
49597 @@ -1193,7 +1193,7 @@ static int macvtap_device_event(struct notifier_block *unused,
49598 return NOTIFY_DONE;
49599 }
49600
49601 -static struct notifier_block macvtap_notifier_block __read_mostly = {
49602 +static struct notifier_block macvtap_notifier_block = {
49603 .notifier_call = macvtap_device_event,
49604 };
49605
49606 diff --git a/drivers/net/nlmon.c b/drivers/net/nlmon.c
49607 index 34924df..a747360 100644
49608 --- a/drivers/net/nlmon.c
49609 +++ b/drivers/net/nlmon.c
49610 @@ -154,7 +154,7 @@ static int nlmon_validate(struct nlattr *tb[], struct nlattr *data[])
49611 return 0;
49612 }
49613
49614 -static struct rtnl_link_ops nlmon_link_ops __read_mostly = {
49615 +static struct rtnl_link_ops nlmon_link_ops = {
49616 .kind = "nlmon",
49617 .priv_size = sizeof(struct nlmon),
49618 .setup = nlmon_setup,
49619 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
49620 index 17ecdd6..79ad848 100644
49621 --- a/drivers/net/ppp/ppp_generic.c
49622 +++ b/drivers/net/ppp/ppp_generic.c
49623 @@ -1020,7 +1020,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
49624 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
49625 struct ppp_stats stats;
49626 struct ppp_comp_stats cstats;
49627 - char *vers;
49628
49629 switch (cmd) {
49630 case SIOCGPPPSTATS:
49631 @@ -1042,8 +1041,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
49632 break;
49633
49634 case SIOCGPPPVER:
49635 - vers = PPP_VERSION;
49636 - if (copy_to_user(addr, vers, strlen(vers) + 1))
49637 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
49638 break;
49639 err = 0;
49640 break;
49641 diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
49642 index 079f7ad..b2a2bfa7 100644
49643 --- a/drivers/net/slip/slhc.c
49644 +++ b/drivers/net/slip/slhc.c
49645 @@ -487,7 +487,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
49646 register struct tcphdr *thp;
49647 register struct iphdr *ip;
49648 register struct cstate *cs;
49649 - int len, hdrlen;
49650 + long len, hdrlen;
49651 unsigned char *cp = icp;
49652
49653 /* We've got a compressed packet; read the change byte */
49654 diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
49655 index 1f76c2ea..997760b 100644
49656 --- a/drivers/net/team/team.c
49657 +++ b/drivers/net/team/team.c
49658 @@ -2072,7 +2072,7 @@ static unsigned int team_get_num_rx_queues(void)
49659 return TEAM_DEFAULT_NUM_RX_QUEUES;
49660 }
49661
49662 -static struct rtnl_link_ops team_link_ops __read_mostly = {
49663 +static struct rtnl_link_ops team_link_ops = {
49664 .kind = DRV_NAME,
49665 .priv_size = sizeof(struct team),
49666 .setup = team_setup,
49667 @@ -2862,7 +2862,7 @@ static int team_device_event(struct notifier_block *unused,
49668 return NOTIFY_DONE;
49669 }
49670
49671 -static struct notifier_block team_notifier_block __read_mostly = {
49672 +static struct notifier_block team_notifier_block = {
49673 .notifier_call = team_device_event,
49674 };
49675
49676 diff --git a/drivers/net/tun.c b/drivers/net/tun.c
49677 index d965e8a..6226000 100644
49678 --- a/drivers/net/tun.c
49679 +++ b/drivers/net/tun.c
49680 @@ -1414,7 +1414,7 @@ static int tun_validate(struct nlattr *tb[], struct nlattr *data[])
49681 return -EINVAL;
49682 }
49683
49684 -static struct rtnl_link_ops tun_link_ops __read_mostly = {
49685 +static struct rtnl_link_ops tun_link_ops = {
49686 .kind = DRV_NAME,
49687 .priv_size = sizeof(struct tun_struct),
49688 .setup = tun_setup,
49689 @@ -1861,7 +1861,7 @@ unlock:
49690 }
49691
49692 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
49693 - unsigned long arg, int ifreq_len)
49694 + unsigned long arg, size_t ifreq_len)
49695 {
49696 struct tun_file *tfile = file->private_data;
49697 struct tun_struct *tun;
49698 @@ -1874,6 +1874,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
49699 unsigned int ifindex;
49700 int ret;
49701
49702 + if (ifreq_len > sizeof ifr)
49703 + return -EFAULT;
49704 +
49705 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
49706 if (copy_from_user(&ifr, argp, ifreq_len))
49707 return -EFAULT;
49708 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
49709 index babda7d..e40c90a 100644
49710 --- a/drivers/net/usb/hso.c
49711 +++ b/drivers/net/usb/hso.c
49712 @@ -71,7 +71,7 @@
49713 #include <asm/byteorder.h>
49714 #include <linux/serial_core.h>
49715 #include <linux/serial.h>
49716 -
49717 +#include <asm/local.h>
49718
49719 #define MOD_AUTHOR "Option Wireless"
49720 #define MOD_DESCRIPTION "USB High Speed Option driver"
49721 @@ -1178,7 +1178,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
49722 struct urb *urb;
49723
49724 urb = serial->rx_urb[0];
49725 - if (serial->port.count > 0) {
49726 + if (atomic_read(&serial->port.count) > 0) {
49727 count = put_rxbuf_data(urb, serial);
49728 if (count == -1)
49729 return;
49730 @@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
49731 DUMP1(urb->transfer_buffer, urb->actual_length);
49732
49733 /* Anyone listening? */
49734 - if (serial->port.count == 0)
49735 + if (atomic_read(&serial->port.count) == 0)
49736 return;
49737
49738 if (serial->parent->port_spec & HSO_INFO_CRC_BUG)
49739 @@ -1278,8 +1278,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
49740 tty_port_tty_set(&serial->port, tty);
49741
49742 /* check for port already opened, if not set the termios */
49743 - serial->port.count++;
49744 - if (serial->port.count == 1) {
49745 + if (atomic_inc_return(&serial->port.count) == 1) {
49746 serial->rx_state = RX_IDLE;
49747 /* Force default termio settings */
49748 _hso_serial_set_termios(tty, NULL);
49749 @@ -1289,7 +1288,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
49750 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
49751 if (result) {
49752 hso_stop_serial_device(serial->parent);
49753 - serial->port.count--;
49754 + atomic_dec(&serial->port.count);
49755 kref_put(&serial->parent->ref, hso_serial_ref_free);
49756 }
49757 } else {
49758 @@ -1326,10 +1325,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
49759
49760 /* reset the rts and dtr */
49761 /* do the actual close */
49762 - serial->port.count--;
49763 + atomic_dec(&serial->port.count);
49764
49765 - if (serial->port.count <= 0) {
49766 - serial->port.count = 0;
49767 + if (atomic_read(&serial->port.count) <= 0) {
49768 + atomic_set(&serial->port.count, 0);
49769 tty_port_tty_set(&serial->port, NULL);
49770 if (!usb_gone)
49771 hso_stop_serial_device(serial->parent);
49772 @@ -1404,7 +1403,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
49773
49774 /* the actual setup */
49775 spin_lock_irqsave(&serial->serial_lock, flags);
49776 - if (serial->port.count)
49777 + if (atomic_read(&serial->port.count))
49778 _hso_serial_set_termios(tty, old);
49779 else
49780 tty->termios = *old;
49781 @@ -1873,7 +1872,7 @@ static void intr_callback(struct urb *urb)
49782 D1("Pending read interrupt on port %d\n", i);
49783 spin_lock(&serial->serial_lock);
49784 if (serial->rx_state == RX_IDLE &&
49785 - serial->port.count > 0) {
49786 + atomic_read(&serial->port.count) > 0) {
49787 /* Setup and send a ctrl req read on
49788 * port i */
49789 if (!serial->rx_urb_filled[0]) {
49790 @@ -3047,7 +3046,7 @@ static int hso_resume(struct usb_interface *iface)
49791 /* Start all serial ports */
49792 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
49793 if (serial_table[i] && (serial_table[i]->interface == iface)) {
49794 - if (dev2ser(serial_table[i])->port.count) {
49795 + if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
49796 result =
49797 hso_start_serial_device(serial_table[i], GFP_NOIO);
49798 hso_kick_transmit(dev2ser(serial_table[i]));
49799 diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
49800 index 604ef21..d1f49a1 100644
49801 --- a/drivers/net/usb/r8152.c
49802 +++ b/drivers/net/usb/r8152.c
49803 @@ -575,7 +575,7 @@ struct r8152 {
49804 void (*up)(struct r8152 *);
49805 void (*down)(struct r8152 *);
49806 void (*unload)(struct r8152 *);
49807 - } rtl_ops;
49808 + } __no_const rtl_ops;
49809
49810 int intr_interval;
49811 u32 saved_wolopts;
49812 diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
49813 index a2515887..6d13233 100644
49814 --- a/drivers/net/usb/sierra_net.c
49815 +++ b/drivers/net/usb/sierra_net.c
49816 @@ -51,7 +51,7 @@ static const char driver_name[] = "sierra_net";
49817 /* atomic counter partially included in MAC address to make sure 2 devices
49818 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
49819 */
49820 -static atomic_t iface_counter = ATOMIC_INIT(0);
49821 +static atomic_unchecked_t iface_counter = ATOMIC_INIT(0);
49822
49823 /*
49824 * SYNC Timer Delay definition used to set the expiry time
49825 @@ -697,7 +697,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
49826 dev->net->netdev_ops = &sierra_net_device_ops;
49827
49828 /* change MAC addr to include, ifacenum, and to be unique */
49829 - dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
49830 + dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return_unchecked(&iface_counter);
49831 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
49832
49833 /* we will have to manufacture ethernet headers, prepare template */
49834 diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
49835 index 59caa06..de191b3 100644
49836 --- a/drivers/net/virtio_net.c
49837 +++ b/drivers/net/virtio_net.c
49838 @@ -48,7 +48,7 @@ module_param(gso, bool, 0444);
49839 #define RECEIVE_AVG_WEIGHT 64
49840
49841 /* Minimum alignment for mergeable packet buffers. */
49842 -#define MERGEABLE_BUFFER_ALIGN max(L1_CACHE_BYTES, 256)
49843 +#define MERGEABLE_BUFFER_ALIGN max(L1_CACHE_BYTES, 256UL)
49844
49845 #define VIRTNET_DRIVER_VERSION "1.0.0"
49846
49847 diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
49848 index 2aa3a8d..d15e3c4 100644
49849 --- a/drivers/net/vxlan.c
49850 +++ b/drivers/net/vxlan.c
49851 @@ -2758,7 +2758,7 @@ nla_put_failure:
49852 return -EMSGSIZE;
49853 }
49854
49855 -static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
49856 +static struct rtnl_link_ops vxlan_link_ops = {
49857 .kind = "vxlan",
49858 .maxtype = IFLA_VXLAN_MAX,
49859 .policy = vxlan_policy,
49860 @@ -2805,7 +2805,7 @@ static int vxlan_lowerdev_event(struct notifier_block *unused,
49861 return NOTIFY_DONE;
49862 }
49863
49864 -static struct notifier_block vxlan_notifier_block __read_mostly = {
49865 +static struct notifier_block vxlan_notifier_block = {
49866 .notifier_call = vxlan_lowerdev_event,
49867 };
49868
49869 diff --git a/drivers/net/wan/lmc/lmc_media.c b/drivers/net/wan/lmc/lmc_media.c
49870 index 5920c99..ff2e4a5 100644
49871 --- a/drivers/net/wan/lmc/lmc_media.c
49872 +++ b/drivers/net/wan/lmc/lmc_media.c
49873 @@ -95,62 +95,63 @@ static inline void write_av9110_bit (lmc_softc_t *, int);
49874 static void write_av9110(lmc_softc_t *, u32, u32, u32, u32, u32);
49875
49876 lmc_media_t lmc_ds3_media = {
49877 - lmc_ds3_init, /* special media init stuff */
49878 - lmc_ds3_default, /* reset to default state */
49879 - lmc_ds3_set_status, /* reset status to state provided */
49880 - lmc_dummy_set_1, /* set clock source */
49881 - lmc_dummy_set2_1, /* set line speed */
49882 - lmc_ds3_set_100ft, /* set cable length */
49883 - lmc_ds3_set_scram, /* set scrambler */
49884 - lmc_ds3_get_link_status, /* get link status */
49885 - lmc_dummy_set_1, /* set link status */
49886 - lmc_ds3_set_crc_length, /* set CRC length */
49887 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
49888 - lmc_ds3_watchdog
49889 + .init = lmc_ds3_init, /* special media init stuff */
49890 + .defaults = lmc_ds3_default, /* reset to default state */
49891 + .set_status = lmc_ds3_set_status, /* reset status to state provided */
49892 + .set_clock_source = lmc_dummy_set_1, /* set clock source */
49893 + .set_speed = lmc_dummy_set2_1, /* set line speed */
49894 + .set_cable_length = lmc_ds3_set_100ft, /* set cable length */
49895 + .set_scrambler = lmc_ds3_set_scram, /* set scrambler */
49896 + .get_link_status = lmc_ds3_get_link_status, /* get link status */
49897 + .set_link_status = lmc_dummy_set_1, /* set link status */
49898 + .set_crc_length = lmc_ds3_set_crc_length, /* set CRC length */
49899 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
49900 + .watchdog = lmc_ds3_watchdog
49901 };
49902
49903 lmc_media_t lmc_hssi_media = {
49904 - lmc_hssi_init, /* special media init stuff */
49905 - lmc_hssi_default, /* reset to default state */
49906 - lmc_hssi_set_status, /* reset status to state provided */
49907 - lmc_hssi_set_clock, /* set clock source */
49908 - lmc_dummy_set2_1, /* set line speed */
49909 - lmc_dummy_set_1, /* set cable length */
49910 - lmc_dummy_set_1, /* set scrambler */
49911 - lmc_hssi_get_link_status, /* get link status */
49912 - lmc_hssi_set_link_status, /* set link status */
49913 - lmc_hssi_set_crc_length, /* set CRC length */
49914 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
49915 - lmc_hssi_watchdog
49916 + .init = lmc_hssi_init, /* special media init stuff */
49917 + .defaults = lmc_hssi_default, /* reset to default state */
49918 + .set_status = lmc_hssi_set_status, /* reset status to state provided */
49919 + .set_clock_source = lmc_hssi_set_clock, /* set clock source */
49920 + .set_speed = lmc_dummy_set2_1, /* set line speed */
49921 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
49922 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
49923 + .get_link_status = lmc_hssi_get_link_status, /* get link status */
49924 + .set_link_status = lmc_hssi_set_link_status, /* set link status */
49925 + .set_crc_length = lmc_hssi_set_crc_length, /* set CRC length */
49926 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
49927 + .watchdog = lmc_hssi_watchdog
49928 };
49929
49930 -lmc_media_t lmc_ssi_media = { lmc_ssi_init, /* special media init stuff */
49931 - lmc_ssi_default, /* reset to default state */
49932 - lmc_ssi_set_status, /* reset status to state provided */
49933 - lmc_ssi_set_clock, /* set clock source */
49934 - lmc_ssi_set_speed, /* set line speed */
49935 - lmc_dummy_set_1, /* set cable length */
49936 - lmc_dummy_set_1, /* set scrambler */
49937 - lmc_ssi_get_link_status, /* get link status */
49938 - lmc_ssi_set_link_status, /* set link status */
49939 - lmc_ssi_set_crc_length, /* set CRC length */
49940 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
49941 - lmc_ssi_watchdog
49942 +lmc_media_t lmc_ssi_media = {
49943 + .init = lmc_ssi_init, /* special media init stuff */
49944 + .defaults = lmc_ssi_default, /* reset to default state */
49945 + .set_status = lmc_ssi_set_status, /* reset status to state provided */
49946 + .set_clock_source = lmc_ssi_set_clock, /* set clock source */
49947 + .set_speed = lmc_ssi_set_speed, /* set line speed */
49948 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
49949 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
49950 + .get_link_status = lmc_ssi_get_link_status, /* get link status */
49951 + .set_link_status = lmc_ssi_set_link_status, /* set link status */
49952 + .set_crc_length = lmc_ssi_set_crc_length, /* set CRC length */
49953 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
49954 + .watchdog = lmc_ssi_watchdog
49955 };
49956
49957 lmc_media_t lmc_t1_media = {
49958 - lmc_t1_init, /* special media init stuff */
49959 - lmc_t1_default, /* reset to default state */
49960 - lmc_t1_set_status, /* reset status to state provided */
49961 - lmc_t1_set_clock, /* set clock source */
49962 - lmc_dummy_set2_1, /* set line speed */
49963 - lmc_dummy_set_1, /* set cable length */
49964 - lmc_dummy_set_1, /* set scrambler */
49965 - lmc_t1_get_link_status, /* get link status */
49966 - lmc_dummy_set_1, /* set link status */
49967 - lmc_t1_set_crc_length, /* set CRC length */
49968 - lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
49969 - lmc_t1_watchdog
49970 + .init = lmc_t1_init, /* special media init stuff */
49971 + .defaults = lmc_t1_default, /* reset to default state */
49972 + .set_status = lmc_t1_set_status, /* reset status to state provided */
49973 + .set_clock_source = lmc_t1_set_clock, /* set clock source */
49974 + .set_speed = lmc_dummy_set2_1, /* set line speed */
49975 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
49976 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
49977 + .get_link_status = lmc_t1_get_link_status, /* get link status */
49978 + .set_link_status = lmc_dummy_set_1, /* set link status */
49979 + .set_crc_length = lmc_t1_set_crc_length, /* set CRC length */
49980 + .set_circuit_type = lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
49981 + .watchdog = lmc_t1_watchdog
49982 };
49983
49984 static void
49985 diff --git a/drivers/net/wan/z85230.c b/drivers/net/wan/z85230.c
49986 index feacc3b..5bac0de 100644
49987 --- a/drivers/net/wan/z85230.c
49988 +++ b/drivers/net/wan/z85230.c
49989 @@ -485,9 +485,9 @@ static void z8530_status(struct z8530_channel *chan)
49990
49991 struct z8530_irqhandler z8530_sync =
49992 {
49993 - z8530_rx,
49994 - z8530_tx,
49995 - z8530_status
49996 + .rx = z8530_rx,
49997 + .tx = z8530_tx,
49998 + .status = z8530_status
49999 };
50000
50001 EXPORT_SYMBOL(z8530_sync);
50002 @@ -605,15 +605,15 @@ static void z8530_dma_status(struct z8530_channel *chan)
50003 }
50004
50005 static struct z8530_irqhandler z8530_dma_sync = {
50006 - z8530_dma_rx,
50007 - z8530_dma_tx,
50008 - z8530_dma_status
50009 + .rx = z8530_dma_rx,
50010 + .tx = z8530_dma_tx,
50011 + .status = z8530_dma_status
50012 };
50013
50014 static struct z8530_irqhandler z8530_txdma_sync = {
50015 - z8530_rx,
50016 - z8530_dma_tx,
50017 - z8530_dma_status
50018 + .rx = z8530_rx,
50019 + .tx = z8530_dma_tx,
50020 + .status = z8530_dma_status
50021 };
50022
50023 /**
50024 @@ -680,9 +680,9 @@ static void z8530_status_clear(struct z8530_channel *chan)
50025
50026 struct z8530_irqhandler z8530_nop=
50027 {
50028 - z8530_rx_clear,
50029 - z8530_tx_clear,
50030 - z8530_status_clear
50031 + .rx = z8530_rx_clear,
50032 + .tx = z8530_tx_clear,
50033 + .status = z8530_status_clear
50034 };
50035
50036
50037 diff --git a/drivers/net/wimax/i2400m/rx.c b/drivers/net/wimax/i2400m/rx.c
50038 index 0b60295..b8bfa5b 100644
50039 --- a/drivers/net/wimax/i2400m/rx.c
50040 +++ b/drivers/net/wimax/i2400m/rx.c
50041 @@ -1359,7 +1359,7 @@ int i2400m_rx_setup(struct i2400m *i2400m)
50042 if (i2400m->rx_roq == NULL)
50043 goto error_roq_alloc;
50044
50045 - rd = kcalloc(I2400M_RO_CIN + 1, sizeof(*i2400m->rx_roq[0].log),
50046 + rd = kcalloc(sizeof(*i2400m->rx_roq[0].log), I2400M_RO_CIN + 1,
50047 GFP_KERNEL);
50048 if (rd == NULL) {
50049 result = -ENOMEM;
50050 diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
50051 index e71a2ce..2268d61 100644
50052 --- a/drivers/net/wireless/airo.c
50053 +++ b/drivers/net/wireless/airo.c
50054 @@ -7846,7 +7846,7 @@ static int writerids(struct net_device *dev, aironet_ioctl *comp) {
50055 struct airo_info *ai = dev->ml_priv;
50056 int ridcode;
50057 int enabled;
50058 - static int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
50059 + int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
50060 unsigned char *iobuf;
50061
50062 /* Only super-user can write RIDs */
50063 diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
50064 index da92bfa..5a9001a 100644
50065 --- a/drivers/net/wireless/at76c50x-usb.c
50066 +++ b/drivers/net/wireless/at76c50x-usb.c
50067 @@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
50068 }
50069
50070 /* Convert timeout from the DFU status to jiffies */
50071 -static inline unsigned long at76_get_timeout(struct dfu_status *s)
50072 +static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
50073 {
50074 return msecs_to_jiffies((s->poll_timeout[2] << 16)
50075 | (s->poll_timeout[1] << 8)
50076 diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
50077 index 5fdc40d..3975205 100644
50078 --- a/drivers/net/wireless/ath/ath10k/htc.c
50079 +++ b/drivers/net/wireless/ath/ath10k/htc.c
50080 @@ -856,7 +856,10 @@ void ath10k_htc_stop(struct ath10k_htc *htc)
50081 /* registered target arrival callback from the HIF layer */
50082 int ath10k_htc_init(struct ath10k *ar)
50083 {
50084 - struct ath10k_hif_cb htc_callbacks;
50085 + static struct ath10k_hif_cb htc_callbacks = {
50086 + .rx_completion = ath10k_htc_rx_completion_handler,
50087 + .tx_completion = ath10k_htc_tx_completion_handler,
50088 + };
50089 struct ath10k_htc_ep *ep = NULL;
50090 struct ath10k_htc *htc = &ar->htc;
50091
50092 @@ -866,8 +869,6 @@ int ath10k_htc_init(struct ath10k *ar)
50093 ath10k_htc_reset_endpoint_states(htc);
50094
50095 /* setup HIF layer callbacks */
50096 - htc_callbacks.rx_completion = ath10k_htc_rx_completion_handler;
50097 - htc_callbacks.tx_completion = ath10k_htc_tx_completion_handler;
50098 htc->ar = ar;
50099
50100 /* Get HIF default pipe for HTC message exchange */
50101 diff --git a/drivers/net/wireless/ath/ath10k/htc.h b/drivers/net/wireless/ath/ath10k/htc.h
50102 index 4716d33..a688310 100644
50103 --- a/drivers/net/wireless/ath/ath10k/htc.h
50104 +++ b/drivers/net/wireless/ath/ath10k/htc.h
50105 @@ -271,13 +271,13 @@ enum ath10k_htc_ep_id {
50106
50107 struct ath10k_htc_ops {
50108 void (*target_send_suspend_complete)(struct ath10k *ar);
50109 -};
50110 +} __no_const;
50111
50112 struct ath10k_htc_ep_ops {
50113 void (*ep_tx_complete)(struct ath10k *, struct sk_buff *);
50114 void (*ep_rx_complete)(struct ath10k *, struct sk_buff *);
50115 void (*ep_tx_credits)(struct ath10k *);
50116 -};
50117 +} __no_const;
50118
50119 /* service connection information */
50120 struct ath10k_htc_svc_conn_req {
50121 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
50122 index 59af9f9..5f3564f 100644
50123 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
50124 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
50125 @@ -220,8 +220,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
50126 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
50127 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
50128
50129 - ACCESS_ONCE(ads->ds_link) = i->link;
50130 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
50131 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
50132 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
50133
50134 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
50135 ctl6 = SM(i->keytype, AR_EncrType);
50136 @@ -235,26 +235,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
50137
50138 if ((i->is_first || i->is_last) &&
50139 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
50140 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
50141 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
50142 | set11nTries(i->rates, 1)
50143 | set11nTries(i->rates, 2)
50144 | set11nTries(i->rates, 3)
50145 | (i->dur_update ? AR_DurUpdateEna : 0)
50146 | SM(0, AR_BurstDur);
50147
50148 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
50149 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
50150 | set11nRate(i->rates, 1)
50151 | set11nRate(i->rates, 2)
50152 | set11nRate(i->rates, 3);
50153 } else {
50154 - ACCESS_ONCE(ads->ds_ctl2) = 0;
50155 - ACCESS_ONCE(ads->ds_ctl3) = 0;
50156 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
50157 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
50158 }
50159
50160 if (!i->is_first) {
50161 - ACCESS_ONCE(ads->ds_ctl0) = 0;
50162 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
50163 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
50164 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
50165 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
50166 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
50167 return;
50168 }
50169
50170 @@ -279,7 +279,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
50171 break;
50172 }
50173
50174 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
50175 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
50176 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
50177 | SM(i->txpower, AR_XmitPower0)
50178 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
50179 @@ -289,27 +289,27 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
50180 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
50181 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
50182
50183 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
50184 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
50185 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
50186 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
50187
50188 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
50189 return;
50190
50191 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
50192 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
50193 | set11nPktDurRTSCTS(i->rates, 1);
50194
50195 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
50196 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
50197 | set11nPktDurRTSCTS(i->rates, 3);
50198
50199 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
50200 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
50201 | set11nRateFlags(i->rates, 1)
50202 | set11nRateFlags(i->rates, 2)
50203 | set11nRateFlags(i->rates, 3)
50204 | SM(i->rtscts_rate, AR_RTSCTSRate);
50205
50206 - ACCESS_ONCE(ads->ds_ctl9) = SM(i->txpower, AR_XmitPower1);
50207 - ACCESS_ONCE(ads->ds_ctl10) = SM(i->txpower, AR_XmitPower2);
50208 - ACCESS_ONCE(ads->ds_ctl11) = SM(i->txpower, AR_XmitPower3);
50209 + ACCESS_ONCE_RW(ads->ds_ctl9) = SM(i->txpower, AR_XmitPower1);
50210 + ACCESS_ONCE_RW(ads->ds_ctl10) = SM(i->txpower, AR_XmitPower2);
50211 + ACCESS_ONCE_RW(ads->ds_ctl11) = SM(i->txpower, AR_XmitPower3);
50212 }
50213
50214 static int ar9002_hw_proc_txdesc(struct ath_hw *ah, void *ds,
50215 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
50216 index 71e38e8..5ac96ca 100644
50217 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
50218 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
50219 @@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
50220 (i->qcu << AR_TxQcuNum_S) | desc_len;
50221
50222 checksum += val;
50223 - ACCESS_ONCE(ads->info) = val;
50224 + ACCESS_ONCE_RW(ads->info) = val;
50225
50226 checksum += i->link;
50227 - ACCESS_ONCE(ads->link) = i->link;
50228 + ACCESS_ONCE_RW(ads->link) = i->link;
50229
50230 checksum += i->buf_addr[0];
50231 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
50232 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
50233 checksum += i->buf_addr[1];
50234 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
50235 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
50236 checksum += i->buf_addr[2];
50237 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
50238 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
50239 checksum += i->buf_addr[3];
50240 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
50241 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
50242
50243 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
50244 - ACCESS_ONCE(ads->ctl3) = val;
50245 + ACCESS_ONCE_RW(ads->ctl3) = val;
50246 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
50247 - ACCESS_ONCE(ads->ctl5) = val;
50248 + ACCESS_ONCE_RW(ads->ctl5) = val;
50249 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
50250 - ACCESS_ONCE(ads->ctl7) = val;
50251 + ACCESS_ONCE_RW(ads->ctl7) = val;
50252 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
50253 - ACCESS_ONCE(ads->ctl9) = val;
50254 + ACCESS_ONCE_RW(ads->ctl9) = val;
50255
50256 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
50257 - ACCESS_ONCE(ads->ctl10) = checksum;
50258 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
50259
50260 if (i->is_first || i->is_last) {
50261 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
50262 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
50263 | set11nTries(i->rates, 1)
50264 | set11nTries(i->rates, 2)
50265 | set11nTries(i->rates, 3)
50266 | (i->dur_update ? AR_DurUpdateEna : 0)
50267 | SM(0, AR_BurstDur);
50268
50269 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
50270 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
50271 | set11nRate(i->rates, 1)
50272 | set11nRate(i->rates, 2)
50273 | set11nRate(i->rates, 3);
50274 } else {
50275 - ACCESS_ONCE(ads->ctl13) = 0;
50276 - ACCESS_ONCE(ads->ctl14) = 0;
50277 + ACCESS_ONCE_RW(ads->ctl13) = 0;
50278 + ACCESS_ONCE_RW(ads->ctl14) = 0;
50279 }
50280
50281 ads->ctl20 = 0;
50282 @@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
50283
50284 ctl17 = SM(i->keytype, AR_EncrType);
50285 if (!i->is_first) {
50286 - ACCESS_ONCE(ads->ctl11) = 0;
50287 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
50288 - ACCESS_ONCE(ads->ctl15) = 0;
50289 - ACCESS_ONCE(ads->ctl16) = 0;
50290 - ACCESS_ONCE(ads->ctl17) = ctl17;
50291 - ACCESS_ONCE(ads->ctl18) = 0;
50292 - ACCESS_ONCE(ads->ctl19) = 0;
50293 + ACCESS_ONCE_RW(ads->ctl11) = 0;
50294 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
50295 + ACCESS_ONCE_RW(ads->ctl15) = 0;
50296 + ACCESS_ONCE_RW(ads->ctl16) = 0;
50297 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
50298 + ACCESS_ONCE_RW(ads->ctl18) = 0;
50299 + ACCESS_ONCE_RW(ads->ctl19) = 0;
50300 return;
50301 }
50302
50303 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
50304 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
50305 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
50306 | SM(i->txpower, AR_XmitPower0)
50307 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
50308 @@ -135,26 +135,26 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
50309 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
50310 ctl12 |= SM(val, AR_PAPRDChainMask);
50311
50312 - ACCESS_ONCE(ads->ctl12) = ctl12;
50313 - ACCESS_ONCE(ads->ctl17) = ctl17;
50314 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
50315 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
50316
50317 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
50318 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
50319 | set11nPktDurRTSCTS(i->rates, 1);
50320
50321 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
50322 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
50323 | set11nPktDurRTSCTS(i->rates, 3);
50324
50325 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
50326 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
50327 | set11nRateFlags(i->rates, 1)
50328 | set11nRateFlags(i->rates, 2)
50329 | set11nRateFlags(i->rates, 3)
50330 | SM(i->rtscts_rate, AR_RTSCTSRate);
50331
50332 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
50333 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
50334
50335 - ACCESS_ONCE(ads->ctl20) = SM(i->txpower, AR_XmitPower1);
50336 - ACCESS_ONCE(ads->ctl21) = SM(i->txpower, AR_XmitPower2);
50337 - ACCESS_ONCE(ads->ctl22) = SM(i->txpower, AR_XmitPower3);
50338 + ACCESS_ONCE_RW(ads->ctl20) = SM(i->txpower, AR_XmitPower1);
50339 + ACCESS_ONCE_RW(ads->ctl21) = SM(i->txpower, AR_XmitPower2);
50340 + ACCESS_ONCE_RW(ads->ctl22) = SM(i->txpower, AR_XmitPower3);
50341 }
50342
50343 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
50344 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
50345 index 51b4ebe..d1929dd 100644
50346 --- a/drivers/net/wireless/ath/ath9k/hw.h
50347 +++ b/drivers/net/wireless/ath/ath9k/hw.h
50348 @@ -629,7 +629,7 @@ struct ath_hw_private_ops {
50349
50350 /* ANI */
50351 void (*ani_cache_ini_regs)(struct ath_hw *ah);
50352 -};
50353 +} __no_const;
50354
50355 /**
50356 * struct ath_spec_scan - parameters for Atheros spectral scan
50357 @@ -706,7 +706,7 @@ struct ath_hw_ops {
50358 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
50359 void (*set_bt_ant_diversity)(struct ath_hw *hw, bool enable);
50360 #endif
50361 -};
50362 +} __no_const;
50363
50364 struct ath_nf_limits {
50365 s16 max;
50366 diff --git a/drivers/net/wireless/ath/ath9k/main.c b/drivers/net/wireless/ath/ath9k/main.c
50367 index 4b148bb..ac738fa 100644
50368 --- a/drivers/net/wireless/ath/ath9k/main.c
50369 +++ b/drivers/net/wireless/ath/ath9k/main.c
50370 @@ -2592,16 +2592,18 @@ void ath9k_fill_chanctx_ops(void)
50371 if (!ath9k_use_chanctx)
50372 return;
50373
50374 - ath9k_ops.hw_scan = ath9k_hw_scan;
50375 - ath9k_ops.cancel_hw_scan = ath9k_cancel_hw_scan;
50376 - ath9k_ops.remain_on_channel = ath9k_remain_on_channel;
50377 - ath9k_ops.cancel_remain_on_channel = ath9k_cancel_remain_on_channel;
50378 - ath9k_ops.add_chanctx = ath9k_add_chanctx;
50379 - ath9k_ops.remove_chanctx = ath9k_remove_chanctx;
50380 - ath9k_ops.change_chanctx = ath9k_change_chanctx;
50381 - ath9k_ops.assign_vif_chanctx = ath9k_assign_vif_chanctx;
50382 - ath9k_ops.unassign_vif_chanctx = ath9k_unassign_vif_chanctx;
50383 - ath9k_ops.mgd_prepare_tx = ath9k_chanctx_force_active;
50384 + pax_open_kernel();
50385 + *(void **)&ath9k_ops.hw_scan = ath9k_hw_scan;
50386 + *(void **)&ath9k_ops.cancel_hw_scan = ath9k_cancel_hw_scan;
50387 + *(void **)&ath9k_ops.remain_on_channel = ath9k_remain_on_channel;
50388 + *(void **)&ath9k_ops.cancel_remain_on_channel = ath9k_cancel_remain_on_channel;
50389 + *(void **)&ath9k_ops.add_chanctx = ath9k_add_chanctx;
50390 + *(void **)&ath9k_ops.remove_chanctx = ath9k_remove_chanctx;
50391 + *(void **)&ath9k_ops.change_chanctx = ath9k_change_chanctx;
50392 + *(void **)&ath9k_ops.assign_vif_chanctx = ath9k_assign_vif_chanctx;
50393 + *(void **)&ath9k_ops.unassign_vif_chanctx = ath9k_unassign_vif_chanctx;
50394 + *(void **)&ath9k_ops.mgd_prepare_tx = ath9k_chanctx_force_active;
50395 + pax_close_kernel();
50396 }
50397
50398 struct ieee80211_ops ath9k_ops = {
50399 diff --git a/drivers/net/wireless/b43/phy_lp.c b/drivers/net/wireless/b43/phy_lp.c
50400 index 92190da..f3a4c4c 100644
50401 --- a/drivers/net/wireless/b43/phy_lp.c
50402 +++ b/drivers/net/wireless/b43/phy_lp.c
50403 @@ -2514,7 +2514,7 @@ static int lpphy_b2063_tune(struct b43_wldev *dev,
50404 {
50405 struct ssb_bus *bus = dev->dev->sdev->bus;
50406
50407 - static const struct b206x_channel *chandata = NULL;
50408 + const struct b206x_channel *chandata = NULL;
50409 u32 crystal_freq = bus->chipco.pmu.crystalfreq * 1000;
50410 u32 freqref, vco_freq, val1, val2, val3, timeout, timeoutref, count;
50411 u16 old_comm15, scale;
50412 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
50413 index dc1d20c..f7a4f06 100644
50414 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
50415 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
50416 @@ -3633,7 +3633,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
50417 */
50418 if (il3945_mod_params.disable_hw_scan) {
50419 D_INFO("Disabling hw_scan\n");
50420 - il3945_mac_ops.hw_scan = NULL;
50421 + pax_open_kernel();
50422 + *(void **)&il3945_mac_ops.hw_scan = NULL;
50423 + pax_close_kernel();
50424 }
50425
50426 D_INFO("*** LOAD DRIVER ***\n");
50427 diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
50428 index 0ffb6ff..c0b7f0e 100644
50429 --- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
50430 +++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
50431 @@ -188,7 +188,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
50432 {
50433 struct iwl_priv *priv = file->private_data;
50434 char buf[64];
50435 - int buf_size;
50436 + size_t buf_size;
50437 u32 offset, len;
50438
50439 memset(buf, 0, sizeof(buf));
50440 @@ -458,7 +458,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
50441 struct iwl_priv *priv = file->private_data;
50442
50443 char buf[8];
50444 - int buf_size;
50445 + size_t buf_size;
50446 u32 reset_flag;
50447
50448 memset(buf, 0, sizeof(buf));
50449 @@ -539,7 +539,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
50450 {
50451 struct iwl_priv *priv = file->private_data;
50452 char buf[8];
50453 - int buf_size;
50454 + size_t buf_size;
50455 int ht40;
50456
50457 memset(buf, 0, sizeof(buf));
50458 @@ -591,7 +591,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
50459 {
50460 struct iwl_priv *priv = file->private_data;
50461 char buf[8];
50462 - int buf_size;
50463 + size_t buf_size;
50464 int value;
50465
50466 memset(buf, 0, sizeof(buf));
50467 @@ -683,10 +683,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
50468 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
50469 DEBUGFS_READ_FILE_OPS(current_sleep_command);
50470
50471 -static const char *fmt_value = " %-30s %10u\n";
50472 -static const char *fmt_hex = " %-30s 0x%02X\n";
50473 -static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
50474 -static const char *fmt_header =
50475 +static const char fmt_value[] = " %-30s %10u\n";
50476 +static const char fmt_hex[] = " %-30s 0x%02X\n";
50477 +static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
50478 +static const char fmt_header[] =
50479 "%-32s current cumulative delta max\n";
50480
50481 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
50482 @@ -1856,7 +1856,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
50483 {
50484 struct iwl_priv *priv = file->private_data;
50485 char buf[8];
50486 - int buf_size;
50487 + size_t buf_size;
50488 int clear;
50489
50490 memset(buf, 0, sizeof(buf));
50491 @@ -1901,7 +1901,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
50492 {
50493 struct iwl_priv *priv = file->private_data;
50494 char buf[8];
50495 - int buf_size;
50496 + size_t buf_size;
50497 int trace;
50498
50499 memset(buf, 0, sizeof(buf));
50500 @@ -1972,7 +1972,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
50501 {
50502 struct iwl_priv *priv = file->private_data;
50503 char buf[8];
50504 - int buf_size;
50505 + size_t buf_size;
50506 int missed;
50507
50508 memset(buf, 0, sizeof(buf));
50509 @@ -2013,7 +2013,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
50510
50511 struct iwl_priv *priv = file->private_data;
50512 char buf[8];
50513 - int buf_size;
50514 + size_t buf_size;
50515 int plcp;
50516
50517 memset(buf, 0, sizeof(buf));
50518 @@ -2073,7 +2073,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
50519
50520 struct iwl_priv *priv = file->private_data;
50521 char buf[8];
50522 - int buf_size;
50523 + size_t buf_size;
50524 int flush;
50525
50526 memset(buf, 0, sizeof(buf));
50527 @@ -2163,7 +2163,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
50528
50529 struct iwl_priv *priv = file->private_data;
50530 char buf[8];
50531 - int buf_size;
50532 + size_t buf_size;
50533 int rts;
50534
50535 if (!priv->cfg->ht_params)
50536 @@ -2204,7 +2204,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
50537 {
50538 struct iwl_priv *priv = file->private_data;
50539 char buf[8];
50540 - int buf_size;
50541 + size_t buf_size;
50542
50543 memset(buf, 0, sizeof(buf));
50544 buf_size = min(count, sizeof(buf) - 1);
50545 @@ -2238,7 +2238,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
50546 struct iwl_priv *priv = file->private_data;
50547 u32 event_log_flag;
50548 char buf[8];
50549 - int buf_size;
50550 + size_t buf_size;
50551
50552 /* check that the interface is up */
50553 if (!iwl_is_ready(priv))
50554 @@ -2292,7 +2292,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
50555 struct iwl_priv *priv = file->private_data;
50556 char buf[8];
50557 u32 calib_disabled;
50558 - int buf_size;
50559 + size_t buf_size;
50560
50561 memset(buf, 0, sizeof(buf));
50562 buf_size = min(count, sizeof(buf) - 1);
50563 diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
50564 index bb36d67..a43451e 100644
50565 --- a/drivers/net/wireless/iwlwifi/pcie/trans.c
50566 +++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
50567 @@ -1686,7 +1686,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
50568 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
50569
50570 char buf[8];
50571 - int buf_size;
50572 + size_t buf_size;
50573 u32 reset_flag;
50574
50575 memset(buf, 0, sizeof(buf));
50576 @@ -1707,7 +1707,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
50577 {
50578 struct iwl_trans *trans = file->private_data;
50579 char buf[8];
50580 - int buf_size;
50581 + size_t buf_size;
50582 int csr;
50583
50584 memset(buf, 0, sizeof(buf));
50585 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
50586 index 6b48c865..19646a7 100644
50587 --- a/drivers/net/wireless/mac80211_hwsim.c
50588 +++ b/drivers/net/wireless/mac80211_hwsim.c
50589 @@ -2577,20 +2577,20 @@ static int __init init_mac80211_hwsim(void)
50590 if (channels < 1)
50591 return -EINVAL;
50592
50593 - mac80211_hwsim_mchan_ops = mac80211_hwsim_ops;
50594 - mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
50595 - mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
50596 - mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
50597 - mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
50598 - mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
50599 - mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
50600 - mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
50601 - mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
50602 - mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
50603 - mac80211_hwsim_mchan_ops.assign_vif_chanctx =
50604 - mac80211_hwsim_assign_vif_chanctx;
50605 - mac80211_hwsim_mchan_ops.unassign_vif_chanctx =
50606 - mac80211_hwsim_unassign_vif_chanctx;
50607 + pax_open_kernel();
50608 + memcpy((void *)&mac80211_hwsim_mchan_ops, &mac80211_hwsim_ops, sizeof mac80211_hwsim_mchan_ops);
50609 + *(void **)&mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
50610 + *(void **)&mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
50611 + *(void **)&mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
50612 + *(void **)&mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
50613 + *(void **)&mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
50614 + *(void **)&mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
50615 + *(void **)&mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
50616 + *(void **)&mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
50617 + *(void **)&mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
50618 + *(void **)&mac80211_hwsim_mchan_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
50619 + *(void **)&mac80211_hwsim_mchan_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
50620 + pax_close_kernel();
50621
50622 spin_lock_init(&hwsim_radio_lock);
50623 INIT_LIST_HEAD(&hwsim_radios);
50624 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
50625 index d2a9a08..0cb175d 100644
50626 --- a/drivers/net/wireless/rndis_wlan.c
50627 +++ b/drivers/net/wireless/rndis_wlan.c
50628 @@ -1236,7 +1236,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
50629
50630 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
50631
50632 - if (rts_threshold < 0 || rts_threshold > 2347)
50633 + if (rts_threshold > 2347)
50634 rts_threshold = 2347;
50635
50636 tmp = cpu_to_le32(rts_threshold);
50637 diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
50638 index d13f25c..2573994 100644
50639 --- a/drivers/net/wireless/rt2x00/rt2x00.h
50640 +++ b/drivers/net/wireless/rt2x00/rt2x00.h
50641 @@ -375,7 +375,7 @@ struct rt2x00_intf {
50642 * for hardware which doesn't support hardware
50643 * sequence counting.
50644 */
50645 - atomic_t seqno;
50646 + atomic_unchecked_t seqno;
50647 };
50648
50649 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
50650 diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
50651 index 66ff364..3ce34f7 100644
50652 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
50653 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
50654 @@ -224,9 +224,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
50655 * sequence counter given by mac80211.
50656 */
50657 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
50658 - seqno = atomic_add_return(0x10, &intf->seqno);
50659 + seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
50660 else
50661 - seqno = atomic_read(&intf->seqno);
50662 + seqno = atomic_read_unchecked(&intf->seqno);
50663
50664 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
50665 hdr->seq_ctrl |= cpu_to_le16(seqno);
50666 diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
50667 index b661f896..ddf7d2b 100644
50668 --- a/drivers/net/wireless/ti/wl1251/sdio.c
50669 +++ b/drivers/net/wireless/ti/wl1251/sdio.c
50670 @@ -282,13 +282,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
50671
50672 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
50673
50674 - wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
50675 - wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
50676 + pax_open_kernel();
50677 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
50678 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
50679 + pax_close_kernel();
50680
50681 wl1251_info("using dedicated interrupt line");
50682 } else {
50683 - wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
50684 - wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
50685 + pax_open_kernel();
50686 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
50687 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
50688 + pax_close_kernel();
50689
50690 wl1251_info("using SDIO interrupt");
50691 }
50692 diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
50693 index 0bccf12..3d95068 100644
50694 --- a/drivers/net/wireless/ti/wl12xx/main.c
50695 +++ b/drivers/net/wireless/ti/wl12xx/main.c
50696 @@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
50697 sizeof(wl->conf.mem));
50698
50699 /* read data preparation is only needed by wl127x */
50700 - wl->ops->prepare_read = wl127x_prepare_read;
50701 + pax_open_kernel();
50702 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
50703 + pax_close_kernel();
50704
50705 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
50706 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
50707 @@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
50708 sizeof(wl->conf.mem));
50709
50710 /* read data preparation is only needed by wl127x */
50711 - wl->ops->prepare_read = wl127x_prepare_read;
50712 + pax_open_kernel();
50713 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
50714 + pax_close_kernel();
50715
50716 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
50717 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
50718 diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
50719 index 7af1936..128bb35 100644
50720 --- a/drivers/net/wireless/ti/wl18xx/main.c
50721 +++ b/drivers/net/wireless/ti/wl18xx/main.c
50722 @@ -1916,8 +1916,10 @@ static int wl18xx_setup(struct wl1271 *wl)
50723 }
50724
50725 if (!checksum_param) {
50726 - wl18xx_ops.set_rx_csum = NULL;
50727 - wl18xx_ops.init_vif = NULL;
50728 + pax_open_kernel();
50729 + *(void **)&wl18xx_ops.set_rx_csum = NULL;
50730 + *(void **)&wl18xx_ops.init_vif = NULL;
50731 + pax_close_kernel();
50732 }
50733
50734 /* Enable 11a Band only if we have 5G antennas */
50735 diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
50736 index a912dc0..a8225ba 100644
50737 --- a/drivers/net/wireless/zd1211rw/zd_usb.c
50738 +++ b/drivers/net/wireless/zd1211rw/zd_usb.c
50739 @@ -385,7 +385,7 @@ static inline void handle_regs_int(struct urb *urb)
50740 {
50741 struct zd_usb *usb = urb->context;
50742 struct zd_usb_interrupt *intr = &usb->intr;
50743 - int len;
50744 + unsigned int len;
50745 u16 int_num;
50746
50747 ZD_ASSERT(in_interrupt());
50748 diff --git a/drivers/nfc/nfcwilink.c b/drivers/nfc/nfcwilink.c
50749 index 683671a..4519fc2 100644
50750 --- a/drivers/nfc/nfcwilink.c
50751 +++ b/drivers/nfc/nfcwilink.c
50752 @@ -497,7 +497,7 @@ static struct nci_ops nfcwilink_ops = {
50753
50754 static int nfcwilink_probe(struct platform_device *pdev)
50755 {
50756 - static struct nfcwilink *drv;
50757 + struct nfcwilink *drv;
50758 int rc;
50759 __u32 protocols;
50760
50761 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
50762 index d93b2b6..ae50401 100644
50763 --- a/drivers/oprofile/buffer_sync.c
50764 +++ b/drivers/oprofile/buffer_sync.c
50765 @@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
50766 if (cookie == NO_COOKIE)
50767 offset = pc;
50768 if (cookie == INVALID_COOKIE) {
50769 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
50770 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
50771 offset = pc;
50772 }
50773 if (cookie != last_cookie) {
50774 @@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
50775 /* add userspace sample */
50776
50777 if (!mm) {
50778 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
50779 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
50780 return 0;
50781 }
50782
50783 cookie = lookup_dcookie(mm, s->eip, &offset);
50784
50785 if (cookie == INVALID_COOKIE) {
50786 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
50787 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
50788 return 0;
50789 }
50790
50791 @@ -552,7 +552,7 @@ void sync_buffer(int cpu)
50792 /* ignore backtraces if failed to add a sample */
50793 if (state == sb_bt_start) {
50794 state = sb_bt_ignore;
50795 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
50796 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
50797 }
50798 }
50799 release_mm(mm);
50800 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
50801 index c0cc4e7..44d4e54 100644
50802 --- a/drivers/oprofile/event_buffer.c
50803 +++ b/drivers/oprofile/event_buffer.c
50804 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
50805 }
50806
50807 if (buffer_pos == buffer_size) {
50808 - atomic_inc(&oprofile_stats.event_lost_overflow);
50809 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
50810 return;
50811 }
50812
50813 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
50814 index ed2c3ec..deda85a 100644
50815 --- a/drivers/oprofile/oprof.c
50816 +++ b/drivers/oprofile/oprof.c
50817 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
50818 if (oprofile_ops.switch_events())
50819 return;
50820
50821 - atomic_inc(&oprofile_stats.multiplex_counter);
50822 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
50823 start_switch_worker();
50824 }
50825
50826 diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
50827 index ee2cfce..7f8f699 100644
50828 --- a/drivers/oprofile/oprofile_files.c
50829 +++ b/drivers/oprofile/oprofile_files.c
50830 @@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
50831
50832 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
50833
50834 -static ssize_t timeout_read(struct file *file, char __user *buf,
50835 +static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
50836 size_t count, loff_t *offset)
50837 {
50838 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
50839 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
50840 index 59659ce..6c860a0 100644
50841 --- a/drivers/oprofile/oprofile_stats.c
50842 +++ b/drivers/oprofile/oprofile_stats.c
50843 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
50844 cpu_buf->sample_invalid_eip = 0;
50845 }
50846
50847 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
50848 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
50849 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
50850 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
50851 - atomic_set(&oprofile_stats.multiplex_counter, 0);
50852 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
50853 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
50854 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
50855 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
50856 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
50857 }
50858
50859
50860 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
50861 index 1fc622b..8c48fc3 100644
50862 --- a/drivers/oprofile/oprofile_stats.h
50863 +++ b/drivers/oprofile/oprofile_stats.h
50864 @@ -13,11 +13,11 @@
50865 #include <linux/atomic.h>
50866
50867 struct oprofile_stat_struct {
50868 - atomic_t sample_lost_no_mm;
50869 - atomic_t sample_lost_no_mapping;
50870 - atomic_t bt_lost_no_mapping;
50871 - atomic_t event_lost_overflow;
50872 - atomic_t multiplex_counter;
50873 + atomic_unchecked_t sample_lost_no_mm;
50874 + atomic_unchecked_t sample_lost_no_mapping;
50875 + atomic_unchecked_t bt_lost_no_mapping;
50876 + atomic_unchecked_t event_lost_overflow;
50877 + atomic_unchecked_t multiplex_counter;
50878 };
50879
50880 extern struct oprofile_stat_struct oprofile_stats;
50881 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
50882 index 3f49345..c750d0b 100644
50883 --- a/drivers/oprofile/oprofilefs.c
50884 +++ b/drivers/oprofile/oprofilefs.c
50885 @@ -176,8 +176,8 @@ int oprofilefs_create_ro_ulong(struct dentry *root,
50886
50887 static ssize_t atomic_read_file(struct file *file, char __user *buf, size_t count, loff_t *offset)
50888 {
50889 - atomic_t *val = file->private_data;
50890 - return oprofilefs_ulong_to_user(atomic_read(val), buf, count, offset);
50891 + atomic_unchecked_t *val = file->private_data;
50892 + return oprofilefs_ulong_to_user(atomic_read_unchecked(val), buf, count, offset);
50893 }
50894
50895
50896 @@ -189,7 +189,7 @@ static const struct file_operations atomic_ro_fops = {
50897
50898
50899 int oprofilefs_create_ro_atomic(struct dentry *root,
50900 - char const *name, atomic_t *val)
50901 + char const *name, atomic_unchecked_t *val)
50902 {
50903 return __oprofilefs_create_file(root, name,
50904 &atomic_ro_fops, 0444, val);
50905 diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
50906 index 61be1d9..dec05d7 100644
50907 --- a/drivers/oprofile/timer_int.c
50908 +++ b/drivers/oprofile/timer_int.c
50909 @@ -93,7 +93,7 @@ static int oprofile_cpu_notify(struct notifier_block *self,
50910 return NOTIFY_OK;
50911 }
50912
50913 -static struct notifier_block __refdata oprofile_cpu_notifier = {
50914 +static struct notifier_block oprofile_cpu_notifier = {
50915 .notifier_call = oprofile_cpu_notify,
50916 };
50917
50918 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
50919 index 3b47080..6cd05dd 100644
50920 --- a/drivers/parport/procfs.c
50921 +++ b/drivers/parport/procfs.c
50922 @@ -64,7 +64,7 @@ static int do_active_device(struct ctl_table *table, int write,
50923
50924 *ppos += len;
50925
50926 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
50927 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
50928 }
50929
50930 #ifdef CONFIG_PARPORT_1284
50931 @@ -106,7 +106,7 @@ static int do_autoprobe(struct ctl_table *table, int write,
50932
50933 *ppos += len;
50934
50935 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
50936 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
50937 }
50938 #endif /* IEEE1284.3 support. */
50939
50940 diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
50941 index 8dcccff..35d701d 100644
50942 --- a/drivers/pci/hotplug/acpiphp_ibm.c
50943 +++ b/drivers/pci/hotplug/acpiphp_ibm.c
50944 @@ -452,7 +452,9 @@ static int __init ibm_acpiphp_init(void)
50945 goto init_cleanup;
50946 }
50947
50948 - ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
50949 + pax_open_kernel();
50950 + *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
50951 + pax_close_kernel();
50952 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
50953
50954 return retval;
50955 diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
50956 index 04fcd78..39e83f1 100644
50957 --- a/drivers/pci/hotplug/cpcihp_generic.c
50958 +++ b/drivers/pci/hotplug/cpcihp_generic.c
50959 @@ -73,7 +73,6 @@ static u16 port;
50960 static unsigned int enum_bit;
50961 static u8 enum_mask;
50962
50963 -static struct cpci_hp_controller_ops generic_hpc_ops;
50964 static struct cpci_hp_controller generic_hpc;
50965
50966 static int __init validate_parameters(void)
50967 @@ -139,6 +138,10 @@ static int query_enum(void)
50968 return ((value & enum_mask) == enum_mask);
50969 }
50970
50971 +static struct cpci_hp_controller_ops generic_hpc_ops = {
50972 + .query_enum = query_enum,
50973 +};
50974 +
50975 static int __init cpcihp_generic_init(void)
50976 {
50977 int status;
50978 @@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
50979 pci_dev_put(dev);
50980
50981 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
50982 - generic_hpc_ops.query_enum = query_enum;
50983 generic_hpc.ops = &generic_hpc_ops;
50984
50985 status = cpci_hp_register_controller(&generic_hpc);
50986 diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
50987 index 6757b3e..d3bad62 100644
50988 --- a/drivers/pci/hotplug/cpcihp_zt5550.c
50989 +++ b/drivers/pci/hotplug/cpcihp_zt5550.c
50990 @@ -59,7 +59,6 @@
50991 /* local variables */
50992 static bool debug;
50993 static bool poll;
50994 -static struct cpci_hp_controller_ops zt5550_hpc_ops;
50995 static struct cpci_hp_controller zt5550_hpc;
50996
50997 /* Primary cPCI bus bridge device */
50998 @@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
50999 return 0;
51000 }
51001
51002 +static struct cpci_hp_controller_ops zt5550_hpc_ops = {
51003 + .query_enum = zt5550_hc_query_enum,
51004 +};
51005 +
51006 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
51007 {
51008 int status;
51009 @@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
51010 dbg("returned from zt5550_hc_config");
51011
51012 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
51013 - zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
51014 zt5550_hpc.ops = &zt5550_hpc_ops;
51015 if(!poll) {
51016 zt5550_hpc.irq = hc_dev->irq;
51017 zt5550_hpc.irq_flags = IRQF_SHARED;
51018 zt5550_hpc.dev_id = hc_dev;
51019
51020 - zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
51021 - zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
51022 - zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
51023 + pax_open_kernel();
51024 + *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
51025 + *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
51026 + *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
51027 + pax_open_kernel();
51028 } else {
51029 info("using ENUM# polling mode");
51030 }
51031 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
51032 index 0968a9b..5a00edf 100644
51033 --- a/drivers/pci/hotplug/cpqphp_nvram.c
51034 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
51035 @@ -427,9 +427,13 @@ static u32 store_HRT (void __iomem *rom_start)
51036
51037 void compaq_nvram_init (void __iomem *rom_start)
51038 {
51039 +
51040 +#ifndef CONFIG_PAX_KERNEXEC
51041 if (rom_start) {
51042 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
51043 }
51044 +#endif
51045 +
51046 dbg("int15 entry = %p\n", compaq_int15_entry_point);
51047
51048 /* initialize our int15 lock */
51049 diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
51050 index 56d8486..f26113f 100644
51051 --- a/drivers/pci/hotplug/pci_hotplug_core.c
51052 +++ b/drivers/pci/hotplug/pci_hotplug_core.c
51053 @@ -436,8 +436,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
51054 return -EINVAL;
51055 }
51056
51057 - slot->ops->owner = owner;
51058 - slot->ops->mod_name = mod_name;
51059 + pax_open_kernel();
51060 + *(struct module **)&slot->ops->owner = owner;
51061 + *(const char **)&slot->ops->mod_name = mod_name;
51062 + pax_close_kernel();
51063
51064 mutex_lock(&pci_hp_mutex);
51065 /*
51066 diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
51067 index 07aa722..84514b4 100644
51068 --- a/drivers/pci/hotplug/pciehp_core.c
51069 +++ b/drivers/pci/hotplug/pciehp_core.c
51070 @@ -92,7 +92,7 @@ static int init_slot(struct controller *ctrl)
51071 struct slot *slot = ctrl->slot;
51072 struct hotplug_slot *hotplug = NULL;
51073 struct hotplug_slot_info *info = NULL;
51074 - struct hotplug_slot_ops *ops = NULL;
51075 + hotplug_slot_ops_no_const *ops = NULL;
51076 char name[SLOT_NAME_SIZE];
51077 int retval = -ENOMEM;
51078
51079 diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
51080 index 6807edd..086a7dc 100644
51081 --- a/drivers/pci/msi.c
51082 +++ b/drivers/pci/msi.c
51083 @@ -507,8 +507,8 @@ static int populate_msi_sysfs(struct pci_dev *pdev)
51084 {
51085 struct attribute **msi_attrs;
51086 struct attribute *msi_attr;
51087 - struct device_attribute *msi_dev_attr;
51088 - struct attribute_group *msi_irq_group;
51089 + device_attribute_no_const *msi_dev_attr;
51090 + attribute_group_no_const *msi_irq_group;
51091 const struct attribute_group **msi_irq_groups;
51092 struct msi_desc *entry;
51093 int ret = -ENOMEM;
51094 @@ -568,7 +568,7 @@ error_attrs:
51095 count = 0;
51096 msi_attr = msi_attrs[count];
51097 while (msi_attr) {
51098 - msi_dev_attr = container_of(msi_attr, struct device_attribute, attr);
51099 + msi_dev_attr = container_of(msi_attr, device_attribute_no_const, attr);
51100 kfree(msi_attr->name);
51101 kfree(msi_dev_attr);
51102 ++count;
51103 diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
51104 index 6d04771..4126004 100644
51105 --- a/drivers/pci/pci-sysfs.c
51106 +++ b/drivers/pci/pci-sysfs.c
51107 @@ -1134,7 +1134,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
51108 {
51109 /* allocate attribute structure, piggyback attribute name */
51110 int name_len = write_combine ? 13 : 10;
51111 - struct bin_attribute *res_attr;
51112 + bin_attribute_no_const *res_attr;
51113 int retval;
51114
51115 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
51116 @@ -1311,7 +1311,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
51117 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
51118 {
51119 int retval;
51120 - struct bin_attribute *attr;
51121 + bin_attribute_no_const *attr;
51122
51123 /* If the device has VPD, try to expose it in sysfs. */
51124 if (dev->vpd) {
51125 @@ -1358,7 +1358,7 @@ int __must_check pci_create_sysfs_dev_files(struct pci_dev *pdev)
51126 {
51127 int retval;
51128 int rom_size = 0;
51129 - struct bin_attribute *attr;
51130 + bin_attribute_no_const *attr;
51131
51132 if (!sysfs_initialized)
51133 return -EACCES;
51134 diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
51135 index 0601890..dc15007 100644
51136 --- a/drivers/pci/pci.h
51137 +++ b/drivers/pci/pci.h
51138 @@ -91,7 +91,7 @@ struct pci_vpd_ops {
51139 struct pci_vpd {
51140 unsigned int len;
51141 const struct pci_vpd_ops *ops;
51142 - struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
51143 + bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
51144 };
51145
51146 int pci_vpd_pci22_init(struct pci_dev *dev);
51147 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
51148 index e1e7026..d28dd33 100644
51149 --- a/drivers/pci/pcie/aspm.c
51150 +++ b/drivers/pci/pcie/aspm.c
51151 @@ -27,9 +27,9 @@
51152 #define MODULE_PARAM_PREFIX "pcie_aspm."
51153
51154 /* Note: those are not register definitions */
51155 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
51156 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
51157 -#define ASPM_STATE_L1 (4) /* L1 state */
51158 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
51159 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
51160 +#define ASPM_STATE_L1 (4U) /* L1 state */
51161 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
51162 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
51163
51164 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
51165 index 9cce960..7c530f4 100644
51166 --- a/drivers/pci/probe.c
51167 +++ b/drivers/pci/probe.c
51168 @@ -176,7 +176,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
51169 struct pci_bus_region region, inverted_region;
51170 bool bar_too_big = false, bar_too_high = false, bar_invalid = false;
51171
51172 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
51173 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
51174
51175 /* No printks while decoding is disabled! */
51176 if (!dev->mmio_always_on) {
51177 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
51178 index 3f155e7..0f4b1f0 100644
51179 --- a/drivers/pci/proc.c
51180 +++ b/drivers/pci/proc.c
51181 @@ -434,7 +434,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
51182 static int __init pci_proc_init(void)
51183 {
51184 struct pci_dev *dev = NULL;
51185 +
51186 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
51187 +#ifdef CONFIG_GRKERNSEC_PROC_USER
51188 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
51189 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51190 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
51191 +#endif
51192 +#else
51193 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
51194 +#endif
51195 proc_create("devices", 0, proc_bus_pci_dir,
51196 &proc_bus_pci_dev_operations);
51197 proc_initialized = 1;
51198 diff --git a/drivers/platform/chrome/chromeos_laptop.c b/drivers/platform/chrome/chromeos_laptop.c
51199 index d866db8..c827d1f 100644
51200 --- a/drivers/platform/chrome/chromeos_laptop.c
51201 +++ b/drivers/platform/chrome/chromeos_laptop.c
51202 @@ -479,7 +479,7 @@ static struct chromeos_laptop cr48 = {
51203 .callback = chromeos_laptop_dmi_matched, \
51204 .driver_data = (void *)&board_
51205
51206 -static struct dmi_system_id chromeos_laptop_dmi_table[] __initdata = {
51207 +static struct dmi_system_id chromeos_laptop_dmi_table[] __initconst = {
51208 {
51209 .ident = "Samsung Series 5 550",
51210 .matches = {
51211 diff --git a/drivers/platform/x86/alienware-wmi.c b/drivers/platform/x86/alienware-wmi.c
51212 index c5af23b..3d62d5e 100644
51213 --- a/drivers/platform/x86/alienware-wmi.c
51214 +++ b/drivers/platform/x86/alienware-wmi.c
51215 @@ -150,7 +150,7 @@ struct wmax_led_args {
51216 } __packed;
51217
51218 static struct platform_device *platform_device;
51219 -static struct device_attribute *zone_dev_attrs;
51220 +static device_attribute_no_const *zone_dev_attrs;
51221 static struct attribute **zone_attrs;
51222 static struct platform_zone *zone_data;
51223
51224 @@ -161,7 +161,7 @@ static struct platform_driver platform_driver = {
51225 }
51226 };
51227
51228 -static struct attribute_group zone_attribute_group = {
51229 +static attribute_group_no_const zone_attribute_group = {
51230 .name = "rgb_zones",
51231 };
51232
51233 diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
51234 index 21fc932..ee9394a 100644
51235 --- a/drivers/platform/x86/asus-wmi.c
51236 +++ b/drivers/platform/x86/asus-wmi.c
51237 @@ -1590,6 +1590,10 @@ static int show_dsts(struct seq_file *m, void *data)
51238 int err;
51239 u32 retval = -1;
51240
51241 +#ifdef CONFIG_GRKERNSEC_KMEM
51242 + return -EPERM;
51243 +#endif
51244 +
51245 err = asus_wmi_get_devstate(asus, asus->debug.dev_id, &retval);
51246
51247 if (err < 0)
51248 @@ -1606,6 +1610,10 @@ static int show_devs(struct seq_file *m, void *data)
51249 int err;
51250 u32 retval = -1;
51251
51252 +#ifdef CONFIG_GRKERNSEC_KMEM
51253 + return -EPERM;
51254 +#endif
51255 +
51256 err = asus_wmi_set_devstate(asus->debug.dev_id, asus->debug.ctrl_param,
51257 &retval);
51258
51259 @@ -1630,6 +1638,10 @@ static int show_call(struct seq_file *m, void *data)
51260 union acpi_object *obj;
51261 acpi_status status;
51262
51263 +#ifdef CONFIG_GRKERNSEC_KMEM
51264 + return -EPERM;
51265 +#endif
51266 +
51267 status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID,
51268 1, asus->debug.method_id,
51269 &input, &output);
51270 diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
51271 index 62f8030..c7f2a45 100644
51272 --- a/drivers/platform/x86/msi-laptop.c
51273 +++ b/drivers/platform/x86/msi-laptop.c
51274 @@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
51275
51276 if (!quirks->ec_read_only) {
51277 /* allow userland write sysfs file */
51278 - dev_attr_bluetooth.store = store_bluetooth;
51279 - dev_attr_wlan.store = store_wlan;
51280 - dev_attr_threeg.store = store_threeg;
51281 - dev_attr_bluetooth.attr.mode |= S_IWUSR;
51282 - dev_attr_wlan.attr.mode |= S_IWUSR;
51283 - dev_attr_threeg.attr.mode |= S_IWUSR;
51284 + pax_open_kernel();
51285 + *(void **)&dev_attr_bluetooth.store = store_bluetooth;
51286 + *(void **)&dev_attr_wlan.store = store_wlan;
51287 + *(void **)&dev_attr_threeg.store = store_threeg;
51288 + *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
51289 + *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
51290 + *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
51291 + pax_close_kernel();
51292 }
51293
51294 /* disable hardware control by fn key */
51295 diff --git a/drivers/platform/x86/msi-wmi.c b/drivers/platform/x86/msi-wmi.c
51296 index 70222f2..8c8ce66 100644
51297 --- a/drivers/platform/x86/msi-wmi.c
51298 +++ b/drivers/platform/x86/msi-wmi.c
51299 @@ -183,7 +183,7 @@ static const struct backlight_ops msi_backlight_ops = {
51300 static void msi_wmi_notify(u32 value, void *context)
51301 {
51302 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
51303 - static struct key_entry *key;
51304 + struct key_entry *key;
51305 union acpi_object *obj;
51306 acpi_status status;
51307
51308 diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
51309 index 26ad9ff..7c52909 100644
51310 --- a/drivers/platform/x86/sony-laptop.c
51311 +++ b/drivers/platform/x86/sony-laptop.c
51312 @@ -2527,7 +2527,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
51313 }
51314
51315 /* High speed charging function */
51316 -static struct device_attribute *hsc_handle;
51317 +static device_attribute_no_const *hsc_handle;
51318
51319 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
51320 struct device_attribute *attr,
51321 @@ -2601,7 +2601,7 @@ static void sony_nc_highspeed_charging_cleanup(struct platform_device *pd)
51322 }
51323
51324 /* low battery function */
51325 -static struct device_attribute *lowbatt_handle;
51326 +static device_attribute_no_const *lowbatt_handle;
51327
51328 static ssize_t sony_nc_lowbatt_store(struct device *dev,
51329 struct device_attribute *attr,
51330 @@ -2667,7 +2667,7 @@ static void sony_nc_lowbatt_cleanup(struct platform_device *pd)
51331 }
51332
51333 /* fan speed function */
51334 -static struct device_attribute *fan_handle, *hsf_handle;
51335 +static device_attribute_no_const *fan_handle, *hsf_handle;
51336
51337 static ssize_t sony_nc_hsfan_store(struct device *dev,
51338 struct device_attribute *attr,
51339 @@ -2774,7 +2774,7 @@ static void sony_nc_fanspeed_cleanup(struct platform_device *pd)
51340 }
51341
51342 /* USB charge function */
51343 -static struct device_attribute *uc_handle;
51344 +static device_attribute_no_const *uc_handle;
51345
51346 static ssize_t sony_nc_usb_charge_store(struct device *dev,
51347 struct device_attribute *attr,
51348 @@ -2848,7 +2848,7 @@ static void sony_nc_usb_charge_cleanup(struct platform_device *pd)
51349 }
51350
51351 /* Panel ID function */
51352 -static struct device_attribute *panel_handle;
51353 +static device_attribute_no_const *panel_handle;
51354
51355 static ssize_t sony_nc_panelid_show(struct device *dev,
51356 struct device_attribute *attr, char *buffer)
51357 @@ -2895,7 +2895,7 @@ static void sony_nc_panelid_cleanup(struct platform_device *pd)
51358 }
51359
51360 /* smart connect function */
51361 -static struct device_attribute *sc_handle;
51362 +static device_attribute_no_const *sc_handle;
51363
51364 static ssize_t sony_nc_smart_conn_store(struct device *dev,
51365 struct device_attribute *attr,
51366 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
51367 index 3bbc6eb..7760460 100644
51368 --- a/drivers/platform/x86/thinkpad_acpi.c
51369 +++ b/drivers/platform/x86/thinkpad_acpi.c
51370 @@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
51371 return 0;
51372 }
51373
51374 -void static hotkey_mask_warn_incomplete_mask(void)
51375 +static void hotkey_mask_warn_incomplete_mask(void)
51376 {
51377 /* log only what the user can fix... */
51378 const u32 wantedmask = hotkey_driver_mask &
51379 @@ -2438,10 +2438,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
51380 && !tp_features.bright_unkfw)
51381 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
51382 }
51383 +}
51384
51385 #undef TPACPI_COMPARE_KEY
51386 #undef TPACPI_MAY_SEND_KEY
51387 -}
51388
51389 /*
51390 * Polling driver
51391 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
51392 index 438d4c7..ca8a2fb 100644
51393 --- a/drivers/pnp/pnpbios/bioscalls.c
51394 +++ b/drivers/pnp/pnpbios/bioscalls.c
51395 @@ -59,7 +59,7 @@ do { \
51396 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
51397 } while(0)
51398
51399 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
51400 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
51401 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
51402
51403 /*
51404 @@ -96,7 +96,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
51405
51406 cpu = get_cpu();
51407 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
51408 +
51409 + pax_open_kernel();
51410 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
51411 + pax_close_kernel();
51412
51413 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
51414 spin_lock_irqsave(&pnp_bios_lock, flags);
51415 @@ -134,7 +137,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
51416 :"memory");
51417 spin_unlock_irqrestore(&pnp_bios_lock, flags);
51418
51419 + pax_open_kernel();
51420 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
51421 + pax_close_kernel();
51422 +
51423 put_cpu();
51424
51425 /* If we get here and this is set then the PnP BIOS faulted on us. */
51426 @@ -468,7 +474,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
51427 return status;
51428 }
51429
51430 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
51431 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
51432 {
51433 int i;
51434
51435 @@ -476,6 +482,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
51436 pnp_bios_callpoint.offset = header->fields.pm16offset;
51437 pnp_bios_callpoint.segment = PNP_CS16;
51438
51439 + pax_open_kernel();
51440 +
51441 for_each_possible_cpu(i) {
51442 struct desc_struct *gdt = get_cpu_gdt_table(i);
51443 if (!gdt)
51444 @@ -487,4 +495,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
51445 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
51446 (unsigned long)__va(header->fields.pm16dseg));
51447 }
51448 +
51449 + pax_close_kernel();
51450 }
51451 diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
51452 index 0c52e2a..3421ab7 100644
51453 --- a/drivers/power/pda_power.c
51454 +++ b/drivers/power/pda_power.c
51455 @@ -37,7 +37,11 @@ static int polling;
51456
51457 #if IS_ENABLED(CONFIG_USB_PHY)
51458 static struct usb_phy *transceiver;
51459 -static struct notifier_block otg_nb;
51460 +static int otg_handle_notification(struct notifier_block *nb,
51461 + unsigned long event, void *unused);
51462 +static struct notifier_block otg_nb = {
51463 + .notifier_call = otg_handle_notification
51464 +};
51465 #endif
51466
51467 static struct regulator *ac_draw;
51468 @@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
51469
51470 #if IS_ENABLED(CONFIG_USB_PHY)
51471 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
51472 - otg_nb.notifier_call = otg_handle_notification;
51473 ret = usb_register_notifier(transceiver, &otg_nb);
51474 if (ret) {
51475 dev_err(dev, "failure to register otg notifier\n");
51476 diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
51477 index cc439fd..8fa30df 100644
51478 --- a/drivers/power/power_supply.h
51479 +++ b/drivers/power/power_supply.h
51480 @@ -16,12 +16,12 @@ struct power_supply;
51481
51482 #ifdef CONFIG_SYSFS
51483
51484 -extern void power_supply_init_attrs(struct device_type *dev_type);
51485 +extern void power_supply_init_attrs(void);
51486 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
51487
51488 #else
51489
51490 -static inline void power_supply_init_attrs(struct device_type *dev_type) {}
51491 +static inline void power_supply_init_attrs(void) {}
51492 #define power_supply_uevent NULL
51493
51494 #endif /* CONFIG_SYSFS */
51495 diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
51496 index 078afd6..fbac9da 100644
51497 --- a/drivers/power/power_supply_core.c
51498 +++ b/drivers/power/power_supply_core.c
51499 @@ -28,7 +28,10 @@ EXPORT_SYMBOL_GPL(power_supply_class);
51500 ATOMIC_NOTIFIER_HEAD(power_supply_notifier);
51501 EXPORT_SYMBOL_GPL(power_supply_notifier);
51502
51503 -static struct device_type power_supply_dev_type;
51504 +extern const struct attribute_group *power_supply_attr_groups[];
51505 +static struct device_type power_supply_dev_type = {
51506 + .groups = power_supply_attr_groups,
51507 +};
51508
51509 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
51510 struct power_supply *supply)
51511 @@ -640,7 +643,7 @@ static int __init power_supply_class_init(void)
51512 return PTR_ERR(power_supply_class);
51513
51514 power_supply_class->dev_uevent = power_supply_uevent;
51515 - power_supply_init_attrs(&power_supply_dev_type);
51516 + power_supply_init_attrs();
51517
51518 return 0;
51519 }
51520 diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
51521 index 750a202..99c8f4b 100644
51522 --- a/drivers/power/power_supply_sysfs.c
51523 +++ b/drivers/power/power_supply_sysfs.c
51524 @@ -234,17 +234,15 @@ static struct attribute_group power_supply_attr_group = {
51525 .is_visible = power_supply_attr_is_visible,
51526 };
51527
51528 -static const struct attribute_group *power_supply_attr_groups[] = {
51529 +const struct attribute_group *power_supply_attr_groups[] = {
51530 &power_supply_attr_group,
51531 NULL,
51532 };
51533
51534 -void power_supply_init_attrs(struct device_type *dev_type)
51535 +void power_supply_init_attrs(void)
51536 {
51537 int i;
51538
51539 - dev_type->groups = power_supply_attr_groups;
51540 -
51541 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
51542 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
51543 }
51544 diff --git a/drivers/powercap/powercap_sys.c b/drivers/powercap/powercap_sys.c
51545 index 84419af..268ede8 100644
51546 --- a/drivers/powercap/powercap_sys.c
51547 +++ b/drivers/powercap/powercap_sys.c
51548 @@ -154,8 +154,77 @@ struct powercap_constraint_attr {
51549 struct device_attribute name_attr;
51550 };
51551
51552 +static ssize_t show_constraint_name(struct device *dev,
51553 + struct device_attribute *dev_attr,
51554 + char *buf);
51555 +
51556 static struct powercap_constraint_attr
51557 - constraint_attrs[MAX_CONSTRAINTS_PER_ZONE];
51558 + constraint_attrs[MAX_CONSTRAINTS_PER_ZONE] = {
51559 + [0 ... MAX_CONSTRAINTS_PER_ZONE - 1] = {
51560 + .power_limit_attr = {
51561 + .attr = {
51562 + .name = NULL,
51563 + .mode = S_IWUSR | S_IRUGO
51564 + },
51565 + .show = show_constraint_power_limit_uw,
51566 + .store = store_constraint_power_limit_uw
51567 + },
51568 +
51569 + .time_window_attr = {
51570 + .attr = {
51571 + .name = NULL,
51572 + .mode = S_IWUSR | S_IRUGO
51573 + },
51574 + .show = show_constraint_time_window_us,
51575 + .store = store_constraint_time_window_us
51576 + },
51577 +
51578 + .max_power_attr = {
51579 + .attr = {
51580 + .name = NULL,
51581 + .mode = S_IRUGO
51582 + },
51583 + .show = show_constraint_max_power_uw,
51584 + .store = NULL
51585 + },
51586 +
51587 + .min_power_attr = {
51588 + .attr = {
51589 + .name = NULL,
51590 + .mode = S_IRUGO
51591 + },
51592 + .show = show_constraint_min_power_uw,
51593 + .store = NULL
51594 + },
51595 +
51596 + .max_time_window_attr = {
51597 + .attr = {
51598 + .name = NULL,
51599 + .mode = S_IRUGO
51600 + },
51601 + .show = show_constraint_max_time_window_us,
51602 + .store = NULL
51603 + },
51604 +
51605 + .min_time_window_attr = {
51606 + .attr = {
51607 + .name = NULL,
51608 + .mode = S_IRUGO
51609 + },
51610 + .show = show_constraint_min_time_window_us,
51611 + .store = NULL
51612 + },
51613 +
51614 + .name_attr = {
51615 + .attr = {
51616 + .name = NULL,
51617 + .mode = S_IRUGO
51618 + },
51619 + .show = show_constraint_name,
51620 + .store = NULL
51621 + }
51622 + }
51623 +};
51624
51625 /* A list of powercap control_types */
51626 static LIST_HEAD(powercap_cntrl_list);
51627 @@ -193,23 +262,16 @@ static ssize_t show_constraint_name(struct device *dev,
51628 }
51629
51630 static int create_constraint_attribute(int id, const char *name,
51631 - int mode,
51632 - struct device_attribute *dev_attr,
51633 - ssize_t (*show)(struct device *,
51634 - struct device_attribute *, char *),
51635 - ssize_t (*store)(struct device *,
51636 - struct device_attribute *,
51637 - const char *, size_t)
51638 - )
51639 + struct device_attribute *dev_attr)
51640 {
51641 + name = kasprintf(GFP_KERNEL, "constraint_%d_%s", id, name);
51642
51643 - dev_attr->attr.name = kasprintf(GFP_KERNEL, "constraint_%d_%s",
51644 - id, name);
51645 - if (!dev_attr->attr.name)
51646 + if (!name)
51647 return -ENOMEM;
51648 - dev_attr->attr.mode = mode;
51649 - dev_attr->show = show;
51650 - dev_attr->store = store;
51651 +
51652 + pax_open_kernel();
51653 + *(const char **)&dev_attr->attr.name = name;
51654 + pax_close_kernel();
51655
51656 return 0;
51657 }
51658 @@ -236,49 +298,31 @@ static int seed_constraint_attributes(void)
51659
51660 for (i = 0; i < MAX_CONSTRAINTS_PER_ZONE; ++i) {
51661 ret = create_constraint_attribute(i, "power_limit_uw",
51662 - S_IWUSR | S_IRUGO,
51663 - &constraint_attrs[i].power_limit_attr,
51664 - show_constraint_power_limit_uw,
51665 - store_constraint_power_limit_uw);
51666 + &constraint_attrs[i].power_limit_attr);
51667 if (ret)
51668 goto err_alloc;
51669 ret = create_constraint_attribute(i, "time_window_us",
51670 - S_IWUSR | S_IRUGO,
51671 - &constraint_attrs[i].time_window_attr,
51672 - show_constraint_time_window_us,
51673 - store_constraint_time_window_us);
51674 + &constraint_attrs[i].time_window_attr);
51675 if (ret)
51676 goto err_alloc;
51677 - ret = create_constraint_attribute(i, "name", S_IRUGO,
51678 - &constraint_attrs[i].name_attr,
51679 - show_constraint_name,
51680 - NULL);
51681 + ret = create_constraint_attribute(i, "name",
51682 + &constraint_attrs[i].name_attr);
51683 if (ret)
51684 goto err_alloc;
51685 - ret = create_constraint_attribute(i, "max_power_uw", S_IRUGO,
51686 - &constraint_attrs[i].max_power_attr,
51687 - show_constraint_max_power_uw,
51688 - NULL);
51689 + ret = create_constraint_attribute(i, "max_power_uw",
51690 + &constraint_attrs[i].max_power_attr);
51691 if (ret)
51692 goto err_alloc;
51693 - ret = create_constraint_attribute(i, "min_power_uw", S_IRUGO,
51694 - &constraint_attrs[i].min_power_attr,
51695 - show_constraint_min_power_uw,
51696 - NULL);
51697 + ret = create_constraint_attribute(i, "min_power_uw",
51698 + &constraint_attrs[i].min_power_attr);
51699 if (ret)
51700 goto err_alloc;
51701 ret = create_constraint_attribute(i, "max_time_window_us",
51702 - S_IRUGO,
51703 - &constraint_attrs[i].max_time_window_attr,
51704 - show_constraint_max_time_window_us,
51705 - NULL);
51706 + &constraint_attrs[i].max_time_window_attr);
51707 if (ret)
51708 goto err_alloc;
51709 ret = create_constraint_attribute(i, "min_time_window_us",
51710 - S_IRUGO,
51711 - &constraint_attrs[i].min_time_window_attr,
51712 - show_constraint_min_time_window_us,
51713 - NULL);
51714 + &constraint_attrs[i].min_time_window_attr);
51715 if (ret)
51716 goto err_alloc;
51717
51718 @@ -378,10 +422,12 @@ static void create_power_zone_common_attributes(
51719 power_zone->zone_dev_attrs[count++] =
51720 &dev_attr_max_energy_range_uj.attr;
51721 if (power_zone->ops->get_energy_uj) {
51722 + pax_open_kernel();
51723 if (power_zone->ops->reset_energy_uj)
51724 - dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
51725 + *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
51726 else
51727 - dev_attr_energy_uj.attr.mode = S_IRUGO;
51728 + *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IRUGO;
51729 + pax_close_kernel();
51730 power_zone->zone_dev_attrs[count++] =
51731 &dev_attr_energy_uj.attr;
51732 }
51733 diff --git a/drivers/ptp/ptp_private.h b/drivers/ptp/ptp_private.h
51734 index 9c5d414..c7900ce 100644
51735 --- a/drivers/ptp/ptp_private.h
51736 +++ b/drivers/ptp/ptp_private.h
51737 @@ -51,7 +51,7 @@ struct ptp_clock {
51738 struct mutex pincfg_mux; /* protect concurrent info->pin_config access */
51739 wait_queue_head_t tsev_wq;
51740 int defunct; /* tells readers to go away when clock is being removed */
51741 - struct device_attribute *pin_dev_attr;
51742 + device_attribute_no_const *pin_dev_attr;
51743 struct attribute **pin_attr;
51744 struct attribute_group pin_attr_group;
51745 };
51746 diff --git a/drivers/ptp/ptp_sysfs.c b/drivers/ptp/ptp_sysfs.c
51747 index 302e626..12579af 100644
51748 --- a/drivers/ptp/ptp_sysfs.c
51749 +++ b/drivers/ptp/ptp_sysfs.c
51750 @@ -280,7 +280,7 @@ static int ptp_populate_pins(struct ptp_clock *ptp)
51751 goto no_pin_attr;
51752
51753 for (i = 0; i < n_pins; i++) {
51754 - struct device_attribute *da = &ptp->pin_dev_attr[i];
51755 + device_attribute_no_const *da = &ptp->pin_dev_attr[i];
51756 sysfs_attr_init(&da->attr);
51757 da->attr.name = info->pin_config[i].name;
51758 da->attr.mode = 0644;
51759 diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
51760 index a3c3785..c901e3a 100644
51761 --- a/drivers/regulator/core.c
51762 +++ b/drivers/regulator/core.c
51763 @@ -3481,7 +3481,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
51764 {
51765 const struct regulation_constraints *constraints = NULL;
51766 const struct regulator_init_data *init_data;
51767 - static atomic_t regulator_no = ATOMIC_INIT(0);
51768 + static atomic_unchecked_t regulator_no = ATOMIC_INIT(0);
51769 struct regulator_dev *rdev;
51770 struct device *dev;
51771 int ret, i;
51772 @@ -3551,7 +3551,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
51773 rdev->dev.of_node = of_node_get(config->of_node);
51774 rdev->dev.parent = dev;
51775 dev_set_name(&rdev->dev, "regulator.%d",
51776 - atomic_inc_return(&regulator_no) - 1);
51777 + atomic_inc_return_unchecked(&regulator_no) - 1);
51778 ret = device_register(&rdev->dev);
51779 if (ret != 0) {
51780 put_device(&rdev->dev);
51781 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
51782 index 2fc4111..6aa88ca 100644
51783 --- a/drivers/regulator/max8660.c
51784 +++ b/drivers/regulator/max8660.c
51785 @@ -424,8 +424,10 @@ static int max8660_probe(struct i2c_client *client,
51786 max8660->shadow_regs[MAX8660_OVER1] = 5;
51787 } else {
51788 /* Otherwise devices can be toggled via software */
51789 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
51790 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
51791 + pax_open_kernel();
51792 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
51793 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
51794 + pax_close_kernel();
51795 }
51796
51797 /*
51798 diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
51799 index dbedf17..18ff6b7 100644
51800 --- a/drivers/regulator/max8973-regulator.c
51801 +++ b/drivers/regulator/max8973-regulator.c
51802 @@ -403,9 +403,11 @@ static int max8973_probe(struct i2c_client *client,
51803 if (!pdata || !pdata->enable_ext_control) {
51804 max->desc.enable_reg = MAX8973_VOUT;
51805 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
51806 - max->ops.enable = regulator_enable_regmap;
51807 - max->ops.disable = regulator_disable_regmap;
51808 - max->ops.is_enabled = regulator_is_enabled_regmap;
51809 + pax_open_kernel();
51810 + *(void **)&max->ops.enable = regulator_enable_regmap;
51811 + *(void **)&max->ops.disable = regulator_disable_regmap;
51812 + *(void **)&max->ops.is_enabled = regulator_is_enabled_regmap;
51813 + pax_close_kernel();
51814 }
51815
51816 if (pdata) {
51817 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
51818 index f374fa5..26f0683 100644
51819 --- a/drivers/regulator/mc13892-regulator.c
51820 +++ b/drivers/regulator/mc13892-regulator.c
51821 @@ -582,10 +582,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
51822 }
51823 mc13xxx_unlock(mc13892);
51824
51825 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
51826 + pax_open_kernel();
51827 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
51828 = mc13892_vcam_set_mode;
51829 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
51830 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
51831 = mc13892_vcam_get_mode;
51832 + pax_close_kernel();
51833
51834 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
51835 ARRAY_SIZE(mc13892_regulators));
51836 diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
51837 index 5b2e761..c8c8a4a 100644
51838 --- a/drivers/rtc/rtc-cmos.c
51839 +++ b/drivers/rtc/rtc-cmos.c
51840 @@ -789,7 +789,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
51841 hpet_rtc_timer_init();
51842
51843 /* export at least the first block of NVRAM */
51844 - nvram.size = address_space - NVRAM_OFFSET;
51845 + pax_open_kernel();
51846 + *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
51847 + pax_close_kernel();
51848 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
51849 if (retval < 0) {
51850 dev_dbg(dev, "can't create nvram file? %d\n", retval);
51851 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
51852 index d049393..bb20be0 100644
51853 --- a/drivers/rtc/rtc-dev.c
51854 +++ b/drivers/rtc/rtc-dev.c
51855 @@ -16,6 +16,7 @@
51856 #include <linux/module.h>
51857 #include <linux/rtc.h>
51858 #include <linux/sched.h>
51859 +#include <linux/grsecurity.h>
51860 #include "rtc-core.h"
51861
51862 static dev_t rtc_devt;
51863 @@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
51864 if (copy_from_user(&tm, uarg, sizeof(tm)))
51865 return -EFAULT;
51866
51867 + gr_log_timechange();
51868 +
51869 return rtc_set_time(rtc, &tm);
51870
51871 case RTC_PIE_ON:
51872 diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
51873 index f03d5ba..8325bf6 100644
51874 --- a/drivers/rtc/rtc-ds1307.c
51875 +++ b/drivers/rtc/rtc-ds1307.c
51876 @@ -107,7 +107,7 @@ struct ds1307 {
51877 u8 offset; /* register's offset */
51878 u8 regs[11];
51879 u16 nvram_offset;
51880 - struct bin_attribute *nvram;
51881 + bin_attribute_no_const *nvram;
51882 enum ds_type type;
51883 unsigned long flags;
51884 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
51885 diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
51886 index 11880c1..b823aa4 100644
51887 --- a/drivers/rtc/rtc-m48t59.c
51888 +++ b/drivers/rtc/rtc-m48t59.c
51889 @@ -483,7 +483,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
51890 if (IS_ERR(m48t59->rtc))
51891 return PTR_ERR(m48t59->rtc);
51892
51893 - m48t59_nvram_attr.size = pdata->offset;
51894 + pax_open_kernel();
51895 + *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
51896 + pax_close_kernel();
51897
51898 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
51899 if (ret)
51900 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
51901 index e693af6..2e525b6 100644
51902 --- a/drivers/scsi/bfa/bfa_fcpim.h
51903 +++ b/drivers/scsi/bfa/bfa_fcpim.h
51904 @@ -36,7 +36,7 @@ struct bfa_iotag_s {
51905
51906 struct bfa_itn_s {
51907 bfa_isr_func_t isr;
51908 -};
51909 +} __no_const;
51910
51911 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
51912 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
51913 diff --git a/drivers/scsi/bfa/bfa_fcs.c b/drivers/scsi/bfa/bfa_fcs.c
51914 index 0f19455..ef7adb5 100644
51915 --- a/drivers/scsi/bfa/bfa_fcs.c
51916 +++ b/drivers/scsi/bfa/bfa_fcs.c
51917 @@ -38,10 +38,21 @@ struct bfa_fcs_mod_s {
51918 #define BFA_FCS_MODULE(_mod) { _mod ## _modinit, _mod ## _modexit }
51919
51920 static struct bfa_fcs_mod_s fcs_modules[] = {
51921 - { bfa_fcs_port_attach, NULL, NULL },
51922 - { bfa_fcs_uf_attach, NULL, NULL },
51923 - { bfa_fcs_fabric_attach, bfa_fcs_fabric_modinit,
51924 - bfa_fcs_fabric_modexit },
51925 + {
51926 + .attach = bfa_fcs_port_attach,
51927 + .modinit = NULL,
51928 + .modexit = NULL
51929 + },
51930 + {
51931 + .attach = bfa_fcs_uf_attach,
51932 + .modinit = NULL,
51933 + .modexit = NULL
51934 + },
51935 + {
51936 + .attach = bfa_fcs_fabric_attach,
51937 + .modinit = bfa_fcs_fabric_modinit,
51938 + .modexit = bfa_fcs_fabric_modexit
51939 + },
51940 };
51941
51942 /*
51943 diff --git a/drivers/scsi/bfa/bfa_fcs_lport.c b/drivers/scsi/bfa/bfa_fcs_lport.c
51944 index ff75ef8..2dfe00a 100644
51945 --- a/drivers/scsi/bfa/bfa_fcs_lport.c
51946 +++ b/drivers/scsi/bfa/bfa_fcs_lport.c
51947 @@ -89,15 +89,26 @@ static struct {
51948 void (*offline) (struct bfa_fcs_lport_s *port);
51949 } __port_action[] = {
51950 {
51951 - bfa_fcs_lport_unknown_init, bfa_fcs_lport_unknown_online,
51952 - bfa_fcs_lport_unknown_offline}, {
51953 - bfa_fcs_lport_fab_init, bfa_fcs_lport_fab_online,
51954 - bfa_fcs_lport_fab_offline}, {
51955 - bfa_fcs_lport_n2n_init, bfa_fcs_lport_n2n_online,
51956 - bfa_fcs_lport_n2n_offline}, {
51957 - bfa_fcs_lport_loop_init, bfa_fcs_lport_loop_online,
51958 - bfa_fcs_lport_loop_offline},
51959 - };
51960 + .init = bfa_fcs_lport_unknown_init,
51961 + .online = bfa_fcs_lport_unknown_online,
51962 + .offline = bfa_fcs_lport_unknown_offline
51963 + },
51964 + {
51965 + .init = bfa_fcs_lport_fab_init,
51966 + .online = bfa_fcs_lport_fab_online,
51967 + .offline = bfa_fcs_lport_fab_offline
51968 + },
51969 + {
51970 + .init = bfa_fcs_lport_n2n_init,
51971 + .online = bfa_fcs_lport_n2n_online,
51972 + .offline = bfa_fcs_lport_n2n_offline
51973 + },
51974 + {
51975 + .init = bfa_fcs_lport_loop_init,
51976 + .online = bfa_fcs_lport_loop_online,
51977 + .offline = bfa_fcs_lport_loop_offline
51978 + },
51979 +};
51980
51981 /*
51982 * fcs_port_sm FCS logical port state machine
51983 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
51984 index a38aafa0..fe8f03b 100644
51985 --- a/drivers/scsi/bfa/bfa_ioc.h
51986 +++ b/drivers/scsi/bfa/bfa_ioc.h
51987 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
51988 bfa_ioc_disable_cbfn_t disable_cbfn;
51989 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
51990 bfa_ioc_reset_cbfn_t reset_cbfn;
51991 -};
51992 +} __no_const;
51993
51994 /*
51995 * IOC event notification mechanism.
51996 @@ -352,7 +352,7 @@ struct bfa_ioc_hwif_s {
51997 void (*ioc_set_alt_fwstate) (struct bfa_ioc_s *ioc,
51998 enum bfi_ioc_state fwstate);
51999 enum bfi_ioc_state (*ioc_get_alt_fwstate) (struct bfa_ioc_s *ioc);
52000 -};
52001 +} __no_const;
52002
52003 /*
52004 * Queue element to wait for room in request queue. FIFO order is
52005 diff --git a/drivers/scsi/bfa/bfa_modules.h b/drivers/scsi/bfa/bfa_modules.h
52006 index a14c784..6de6790 100644
52007 --- a/drivers/scsi/bfa/bfa_modules.h
52008 +++ b/drivers/scsi/bfa/bfa_modules.h
52009 @@ -78,12 +78,12 @@ enum {
52010 \
52011 extern struct bfa_module_s hal_mod_ ## __mod; \
52012 struct bfa_module_s hal_mod_ ## __mod = { \
52013 - bfa_ ## __mod ## _meminfo, \
52014 - bfa_ ## __mod ## _attach, \
52015 - bfa_ ## __mod ## _detach, \
52016 - bfa_ ## __mod ## _start, \
52017 - bfa_ ## __mod ## _stop, \
52018 - bfa_ ## __mod ## _iocdisable, \
52019 + .meminfo = bfa_ ## __mod ## _meminfo, \
52020 + .attach = bfa_ ## __mod ## _attach, \
52021 + .detach = bfa_ ## __mod ## _detach, \
52022 + .start = bfa_ ## __mod ## _start, \
52023 + .stop = bfa_ ## __mod ## _stop, \
52024 + .iocdisable = bfa_ ## __mod ## _iocdisable, \
52025 }
52026
52027 #define BFA_CACHELINE_SZ (256)
52028 diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
52029 index 045c4e1..13de803 100644
52030 --- a/drivers/scsi/fcoe/fcoe_sysfs.c
52031 +++ b/drivers/scsi/fcoe/fcoe_sysfs.c
52032 @@ -33,8 +33,8 @@
52033 */
52034 #include "libfcoe.h"
52035
52036 -static atomic_t ctlr_num;
52037 -static atomic_t fcf_num;
52038 +static atomic_unchecked_t ctlr_num;
52039 +static atomic_unchecked_t fcf_num;
52040
52041 /*
52042 * fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
52043 @@ -685,7 +685,7 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
52044 if (!ctlr)
52045 goto out;
52046
52047 - ctlr->id = atomic_inc_return(&ctlr_num) - 1;
52048 + ctlr->id = atomic_inc_return_unchecked(&ctlr_num) - 1;
52049 ctlr->f = f;
52050 ctlr->mode = FIP_CONN_TYPE_FABRIC;
52051 INIT_LIST_HEAD(&ctlr->fcfs);
52052 @@ -902,7 +902,7 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
52053 fcf->dev.parent = &ctlr->dev;
52054 fcf->dev.bus = &fcoe_bus_type;
52055 fcf->dev.type = &fcoe_fcf_device_type;
52056 - fcf->id = atomic_inc_return(&fcf_num) - 1;
52057 + fcf->id = atomic_inc_return_unchecked(&fcf_num) - 1;
52058 fcf->state = FCOE_FCF_STATE_UNKNOWN;
52059
52060 fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
52061 @@ -938,8 +938,8 @@ int __init fcoe_sysfs_setup(void)
52062 {
52063 int error;
52064
52065 - atomic_set(&ctlr_num, 0);
52066 - atomic_set(&fcf_num, 0);
52067 + atomic_set_unchecked(&ctlr_num, 0);
52068 + atomic_set_unchecked(&fcf_num, 0);
52069
52070 error = bus_register(&fcoe_bus_type);
52071 if (error)
52072 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
52073 index 6de80e3..a11e0ac 100644
52074 --- a/drivers/scsi/hosts.c
52075 +++ b/drivers/scsi/hosts.c
52076 @@ -42,7 +42,7 @@
52077 #include "scsi_logging.h"
52078
52079
52080 -static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
52081 +static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
52082
52083
52084 static void scsi_host_cls_release(struct device *dev)
52085 @@ -392,7 +392,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
52086 * subtract one because we increment first then return, but we need to
52087 * know what the next host number was before increment
52088 */
52089 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
52090 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
52091 shost->dma_channel = 0xff;
52092
52093 /* These three are default values which can be overridden */
52094 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
52095 index 6b35d0d..2880305 100644
52096 --- a/drivers/scsi/hpsa.c
52097 +++ b/drivers/scsi/hpsa.c
52098 @@ -701,10 +701,10 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
52099 unsigned long flags;
52100
52101 if (h->transMethod & CFGTBL_Trans_io_accel1)
52102 - return h->access.command_completed(h, q);
52103 + return h->access->command_completed(h, q);
52104
52105 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
52106 - return h->access.command_completed(h, q);
52107 + return h->access->command_completed(h, q);
52108
52109 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
52110 a = rq->head[rq->current_entry];
52111 @@ -5454,7 +5454,7 @@ static void start_io(struct ctlr_info *h, unsigned long *flags)
52112 while (!list_empty(&h->reqQ)) {
52113 c = list_entry(h->reqQ.next, struct CommandList, list);
52114 /* can't do anything if fifo is full */
52115 - if ((h->access.fifo_full(h))) {
52116 + if ((h->access->fifo_full(h))) {
52117 h->fifo_recently_full = 1;
52118 dev_warn(&h->pdev->dev, "fifo full\n");
52119 break;
52120 @@ -5476,7 +5476,7 @@ static void start_io(struct ctlr_info *h, unsigned long *flags)
52121
52122 /* Tell the controller execute command */
52123 spin_unlock_irqrestore(&h->lock, *flags);
52124 - h->access.submit_command(h, c);
52125 + h->access->submit_command(h, c);
52126 spin_lock_irqsave(&h->lock, *flags);
52127 }
52128 }
52129 @@ -5492,17 +5492,17 @@ static void lock_and_start_io(struct ctlr_info *h)
52130
52131 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
52132 {
52133 - return h->access.command_completed(h, q);
52134 + return h->access->command_completed(h, q);
52135 }
52136
52137 static inline bool interrupt_pending(struct ctlr_info *h)
52138 {
52139 - return h->access.intr_pending(h);
52140 + return h->access->intr_pending(h);
52141 }
52142
52143 static inline long interrupt_not_for_us(struct ctlr_info *h)
52144 {
52145 - return (h->access.intr_pending(h) == 0) ||
52146 + return (h->access->intr_pending(h) == 0) ||
52147 (h->interrupts_enabled == 0);
52148 }
52149
52150 @@ -6458,7 +6458,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
52151 if (prod_index < 0)
52152 return -ENODEV;
52153 h->product_name = products[prod_index].product_name;
52154 - h->access = *(products[prod_index].access);
52155 + h->access = products[prod_index].access;
52156
52157 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
52158 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
52159 @@ -6780,7 +6780,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
52160 unsigned long flags;
52161 u32 lockup_detected;
52162
52163 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
52164 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
52165 spin_lock_irqsave(&h->lock, flags);
52166 lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
52167 if (!lockup_detected) {
52168 @@ -7027,7 +7027,7 @@ reinit_after_soft_reset:
52169 }
52170
52171 /* make sure the board interrupts are off */
52172 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
52173 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
52174
52175 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
52176 goto clean2;
52177 @@ -7062,7 +7062,7 @@ reinit_after_soft_reset:
52178 * fake ones to scoop up any residual completions.
52179 */
52180 spin_lock_irqsave(&h->lock, flags);
52181 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
52182 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
52183 spin_unlock_irqrestore(&h->lock, flags);
52184 free_irqs(h);
52185 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
52186 @@ -7081,9 +7081,9 @@ reinit_after_soft_reset:
52187 dev_info(&h->pdev->dev, "Board READY.\n");
52188 dev_info(&h->pdev->dev,
52189 "Waiting for stale completions to drain.\n");
52190 - h->access.set_intr_mask(h, HPSA_INTR_ON);
52191 + h->access->set_intr_mask(h, HPSA_INTR_ON);
52192 msleep(10000);
52193 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
52194 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
52195
52196 rc = controller_reset_failed(h->cfgtable);
52197 if (rc)
52198 @@ -7109,7 +7109,7 @@ reinit_after_soft_reset:
52199 h->drv_req_rescan = 0;
52200
52201 /* Turn the interrupts on so we can service requests */
52202 - h->access.set_intr_mask(h, HPSA_INTR_ON);
52203 + h->access->set_intr_mask(h, HPSA_INTR_ON);
52204
52205 hpsa_hba_inquiry(h);
52206 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
52207 @@ -7174,7 +7174,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
52208 * To write all data in the battery backed cache to disks
52209 */
52210 hpsa_flush_cache(h);
52211 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
52212 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
52213 hpsa_free_irqs_and_disable_msix(h);
52214 }
52215
52216 @@ -7292,7 +7292,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
52217 CFGTBL_Trans_enable_directed_msix |
52218 (trans_support & (CFGTBL_Trans_io_accel1 |
52219 CFGTBL_Trans_io_accel2));
52220 - struct access_method access = SA5_performant_access;
52221 + struct access_method *access = &SA5_performant_access;
52222
52223 /* This is a bit complicated. There are 8 registers on
52224 * the controller which we write to to tell it 8 different
52225 @@ -7334,7 +7334,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
52226 * perform the superfluous readl() after each command submission.
52227 */
52228 if (trans_support & (CFGTBL_Trans_io_accel1 | CFGTBL_Trans_io_accel2))
52229 - access = SA5_performant_access_no_read;
52230 + access = &SA5_performant_access_no_read;
52231
52232 /* Controller spec: zero out this buffer. */
52233 for (i = 0; i < h->nreply_queues; i++)
52234 @@ -7364,12 +7364,12 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
52235 * enable outbound interrupt coalescing in accelerator mode;
52236 */
52237 if (trans_support & CFGTBL_Trans_io_accel1) {
52238 - access = SA5_ioaccel_mode1_access;
52239 + access = &SA5_ioaccel_mode1_access;
52240 writel(10, &h->cfgtable->HostWrite.CoalIntDelay);
52241 writel(4, &h->cfgtable->HostWrite.CoalIntCount);
52242 } else {
52243 if (trans_support & CFGTBL_Trans_io_accel2) {
52244 - access = SA5_ioaccel_mode2_access;
52245 + access = &SA5_ioaccel_mode2_access;
52246 writel(10, &h->cfgtable->HostWrite.CoalIntDelay);
52247 writel(4, &h->cfgtable->HostWrite.CoalIntCount);
52248 }
52249 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
52250 index 24472ce..8782caf 100644
52251 --- a/drivers/scsi/hpsa.h
52252 +++ b/drivers/scsi/hpsa.h
52253 @@ -127,7 +127,7 @@ struct ctlr_info {
52254 unsigned int msix_vector;
52255 unsigned int msi_vector;
52256 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
52257 - struct access_method access;
52258 + struct access_method *access;
52259 char hba_mode_enabled;
52260
52261 /* queue and queue Info */
52262 @@ -536,43 +536,43 @@ static unsigned long SA5_ioaccel_mode1_completed(struct ctlr_info *h, u8 q)
52263 }
52264
52265 static struct access_method SA5_access = {
52266 - SA5_submit_command,
52267 - SA5_intr_mask,
52268 - SA5_fifo_full,
52269 - SA5_intr_pending,
52270 - SA5_completed,
52271 + .submit_command = SA5_submit_command,
52272 + .set_intr_mask = SA5_intr_mask,
52273 + .fifo_full = SA5_fifo_full,
52274 + .intr_pending = SA5_intr_pending,
52275 + .command_completed = SA5_completed,
52276 };
52277
52278 static struct access_method SA5_ioaccel_mode1_access = {
52279 - SA5_submit_command,
52280 - SA5_performant_intr_mask,
52281 - SA5_fifo_full,
52282 - SA5_ioaccel_mode1_intr_pending,
52283 - SA5_ioaccel_mode1_completed,
52284 + .submit_command = SA5_submit_command,
52285 + .set_intr_mask = SA5_performant_intr_mask,
52286 + .fifo_full = SA5_fifo_full,
52287 + .intr_pending = SA5_ioaccel_mode1_intr_pending,
52288 + .command_completed = SA5_ioaccel_mode1_completed,
52289 };
52290
52291 static struct access_method SA5_ioaccel_mode2_access = {
52292 - SA5_submit_command_ioaccel2,
52293 - SA5_performant_intr_mask,
52294 - SA5_fifo_full,
52295 - SA5_performant_intr_pending,
52296 - SA5_performant_completed,
52297 + .submit_command = SA5_submit_command_ioaccel2,
52298 + .set_intr_mask = SA5_performant_intr_mask,
52299 + .fifo_full = SA5_fifo_full,
52300 + .intr_pending = SA5_performant_intr_pending,
52301 + .command_completed = SA5_performant_completed,
52302 };
52303
52304 static struct access_method SA5_performant_access = {
52305 - SA5_submit_command,
52306 - SA5_performant_intr_mask,
52307 - SA5_fifo_full,
52308 - SA5_performant_intr_pending,
52309 - SA5_performant_completed,
52310 + .submit_command = SA5_submit_command,
52311 + .set_intr_mask = SA5_performant_intr_mask,
52312 + .fifo_full = SA5_fifo_full,
52313 + .intr_pending = SA5_performant_intr_pending,
52314 + .command_completed = SA5_performant_completed,
52315 };
52316
52317 static struct access_method SA5_performant_access_no_read = {
52318 - SA5_submit_command_no_read,
52319 - SA5_performant_intr_mask,
52320 - SA5_fifo_full,
52321 - SA5_performant_intr_pending,
52322 - SA5_performant_completed,
52323 + .submit_command = SA5_submit_command_no_read,
52324 + .set_intr_mask = SA5_performant_intr_mask,
52325 + .fifo_full = SA5_fifo_full,
52326 + .intr_pending = SA5_performant_intr_pending,
52327 + .command_completed = SA5_performant_completed,
52328 };
52329
52330 struct board_type {
52331 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
52332 index 1b3a094..068e683 100644
52333 --- a/drivers/scsi/libfc/fc_exch.c
52334 +++ b/drivers/scsi/libfc/fc_exch.c
52335 @@ -101,12 +101,12 @@ struct fc_exch_mgr {
52336 u16 pool_max_index;
52337
52338 struct {
52339 - atomic_t no_free_exch;
52340 - atomic_t no_free_exch_xid;
52341 - atomic_t xid_not_found;
52342 - atomic_t xid_busy;
52343 - atomic_t seq_not_found;
52344 - atomic_t non_bls_resp;
52345 + atomic_unchecked_t no_free_exch;
52346 + atomic_unchecked_t no_free_exch_xid;
52347 + atomic_unchecked_t xid_not_found;
52348 + atomic_unchecked_t xid_busy;
52349 + atomic_unchecked_t seq_not_found;
52350 + atomic_unchecked_t non_bls_resp;
52351 } stats;
52352 };
52353
52354 @@ -811,7 +811,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
52355 /* allocate memory for exchange */
52356 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
52357 if (!ep) {
52358 - atomic_inc(&mp->stats.no_free_exch);
52359 + atomic_inc_unchecked(&mp->stats.no_free_exch);
52360 goto out;
52361 }
52362 memset(ep, 0, sizeof(*ep));
52363 @@ -874,7 +874,7 @@ out:
52364 return ep;
52365 err:
52366 spin_unlock_bh(&pool->lock);
52367 - atomic_inc(&mp->stats.no_free_exch_xid);
52368 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
52369 mempool_free(ep, mp->ep_pool);
52370 return NULL;
52371 }
52372 @@ -1023,7 +1023,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
52373 xid = ntohs(fh->fh_ox_id); /* we originated exch */
52374 ep = fc_exch_find(mp, xid);
52375 if (!ep) {
52376 - atomic_inc(&mp->stats.xid_not_found);
52377 + atomic_inc_unchecked(&mp->stats.xid_not_found);
52378 reject = FC_RJT_OX_ID;
52379 goto out;
52380 }
52381 @@ -1053,7 +1053,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
52382 ep = fc_exch_find(mp, xid);
52383 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
52384 if (ep) {
52385 - atomic_inc(&mp->stats.xid_busy);
52386 + atomic_inc_unchecked(&mp->stats.xid_busy);
52387 reject = FC_RJT_RX_ID;
52388 goto rel;
52389 }
52390 @@ -1064,7 +1064,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
52391 }
52392 xid = ep->xid; /* get our XID */
52393 } else if (!ep) {
52394 - atomic_inc(&mp->stats.xid_not_found);
52395 + atomic_inc_unchecked(&mp->stats.xid_not_found);
52396 reject = FC_RJT_RX_ID; /* XID not found */
52397 goto out;
52398 }
52399 @@ -1082,7 +1082,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
52400 } else {
52401 sp = &ep->seq;
52402 if (sp->id != fh->fh_seq_id) {
52403 - atomic_inc(&mp->stats.seq_not_found);
52404 + atomic_inc_unchecked(&mp->stats.seq_not_found);
52405 if (f_ctl & FC_FC_END_SEQ) {
52406 /*
52407 * Update sequence_id based on incoming last
52408 @@ -1533,22 +1533,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
52409
52410 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
52411 if (!ep) {
52412 - atomic_inc(&mp->stats.xid_not_found);
52413 + atomic_inc_unchecked(&mp->stats.xid_not_found);
52414 goto out;
52415 }
52416 if (ep->esb_stat & ESB_ST_COMPLETE) {
52417 - atomic_inc(&mp->stats.xid_not_found);
52418 + atomic_inc_unchecked(&mp->stats.xid_not_found);
52419 goto rel;
52420 }
52421 if (ep->rxid == FC_XID_UNKNOWN)
52422 ep->rxid = ntohs(fh->fh_rx_id);
52423 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
52424 - atomic_inc(&mp->stats.xid_not_found);
52425 + atomic_inc_unchecked(&mp->stats.xid_not_found);
52426 goto rel;
52427 }
52428 if (ep->did != ntoh24(fh->fh_s_id) &&
52429 ep->did != FC_FID_FLOGI) {
52430 - atomic_inc(&mp->stats.xid_not_found);
52431 + atomic_inc_unchecked(&mp->stats.xid_not_found);
52432 goto rel;
52433 }
52434 sof = fr_sof(fp);
52435 @@ -1557,7 +1557,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
52436 sp->ssb_stat |= SSB_ST_RESP;
52437 sp->id = fh->fh_seq_id;
52438 } else if (sp->id != fh->fh_seq_id) {
52439 - atomic_inc(&mp->stats.seq_not_found);
52440 + atomic_inc_unchecked(&mp->stats.seq_not_found);
52441 goto rel;
52442 }
52443
52444 @@ -1619,9 +1619,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
52445 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
52446
52447 if (!sp)
52448 - atomic_inc(&mp->stats.xid_not_found);
52449 + atomic_inc_unchecked(&mp->stats.xid_not_found);
52450 else
52451 - atomic_inc(&mp->stats.non_bls_resp);
52452 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
52453
52454 fc_frame_free(fp);
52455 }
52456 @@ -2261,13 +2261,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
52457
52458 list_for_each_entry(ema, &lport->ema_list, ema_list) {
52459 mp = ema->mp;
52460 - st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
52461 + st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
52462 st->fc_no_free_exch_xid +=
52463 - atomic_read(&mp->stats.no_free_exch_xid);
52464 - st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
52465 - st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
52466 - st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
52467 - st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
52468 + atomic_read_unchecked(&mp->stats.no_free_exch_xid);
52469 + st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
52470 + st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
52471 + st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
52472 + st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
52473 }
52474 }
52475 EXPORT_SYMBOL(fc_exch_update_stats);
52476 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
52477 index 766098a..1c6c971 100644
52478 --- a/drivers/scsi/libsas/sas_ata.c
52479 +++ b/drivers/scsi/libsas/sas_ata.c
52480 @@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
52481 .postreset = ata_std_postreset,
52482 .error_handler = ata_std_error_handler,
52483 .post_internal_cmd = sas_ata_post_internal,
52484 - .qc_defer = ata_std_qc_defer,
52485 + .qc_defer = ata_std_qc_defer,
52486 .qc_prep = ata_noop_qc_prep,
52487 .qc_issue = sas_ata_qc_issue,
52488 .qc_fill_rtf = sas_ata_qc_fill_rtf,
52489 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
52490 index 434e903..5a4a79b 100644
52491 --- a/drivers/scsi/lpfc/lpfc.h
52492 +++ b/drivers/scsi/lpfc/lpfc.h
52493 @@ -430,7 +430,7 @@ struct lpfc_vport {
52494 struct dentry *debug_nodelist;
52495 struct dentry *vport_debugfs_root;
52496 struct lpfc_debugfs_trc *disc_trc;
52497 - atomic_t disc_trc_cnt;
52498 + atomic_unchecked_t disc_trc_cnt;
52499 #endif
52500 uint8_t stat_data_enabled;
52501 uint8_t stat_data_blocked;
52502 @@ -880,8 +880,8 @@ struct lpfc_hba {
52503 struct timer_list fabric_block_timer;
52504 unsigned long bit_flags;
52505 #define FABRIC_COMANDS_BLOCKED 0
52506 - atomic_t num_rsrc_err;
52507 - atomic_t num_cmd_success;
52508 + atomic_unchecked_t num_rsrc_err;
52509 + atomic_unchecked_t num_cmd_success;
52510 unsigned long last_rsrc_error_time;
52511 unsigned long last_ramp_down_time;
52512 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
52513 @@ -916,7 +916,7 @@ struct lpfc_hba {
52514
52515 struct dentry *debug_slow_ring_trc;
52516 struct lpfc_debugfs_trc *slow_ring_trc;
52517 - atomic_t slow_ring_trc_cnt;
52518 + atomic_unchecked_t slow_ring_trc_cnt;
52519 /* iDiag debugfs sub-directory */
52520 struct dentry *idiag_root;
52521 struct dentry *idiag_pci_cfg;
52522 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
52523 index b0aedce..89c6ca6 100644
52524 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
52525 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
52526 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
52527
52528 #include <linux/debugfs.h>
52529
52530 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
52531 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
52532 static unsigned long lpfc_debugfs_start_time = 0L;
52533
52534 /* iDiag */
52535 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
52536 lpfc_debugfs_enable = 0;
52537
52538 len = 0;
52539 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
52540 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
52541 (lpfc_debugfs_max_disc_trc - 1);
52542 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
52543 dtp = vport->disc_trc + i;
52544 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
52545 lpfc_debugfs_enable = 0;
52546
52547 len = 0;
52548 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
52549 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
52550 (lpfc_debugfs_max_slow_ring_trc - 1);
52551 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
52552 dtp = phba->slow_ring_trc + i;
52553 @@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
52554 !vport || !vport->disc_trc)
52555 return;
52556
52557 - index = atomic_inc_return(&vport->disc_trc_cnt) &
52558 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
52559 (lpfc_debugfs_max_disc_trc - 1);
52560 dtp = vport->disc_trc + index;
52561 dtp->fmt = fmt;
52562 dtp->data1 = data1;
52563 dtp->data2 = data2;
52564 dtp->data3 = data3;
52565 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
52566 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
52567 dtp->jif = jiffies;
52568 #endif
52569 return;
52570 @@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
52571 !phba || !phba->slow_ring_trc)
52572 return;
52573
52574 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
52575 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
52576 (lpfc_debugfs_max_slow_ring_trc - 1);
52577 dtp = phba->slow_ring_trc + index;
52578 dtp->fmt = fmt;
52579 dtp->data1 = data1;
52580 dtp->data2 = data2;
52581 dtp->data3 = data3;
52582 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
52583 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
52584 dtp->jif = jiffies;
52585 #endif
52586 return;
52587 @@ -4268,7 +4268,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
52588 "slow_ring buffer\n");
52589 goto debug_failed;
52590 }
52591 - atomic_set(&phba->slow_ring_trc_cnt, 0);
52592 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
52593 memset(phba->slow_ring_trc, 0,
52594 (sizeof(struct lpfc_debugfs_trc) *
52595 lpfc_debugfs_max_slow_ring_trc));
52596 @@ -4314,7 +4314,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
52597 "buffer\n");
52598 goto debug_failed;
52599 }
52600 - atomic_set(&vport->disc_trc_cnt, 0);
52601 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
52602
52603 snprintf(name, sizeof(name), "discovery_trace");
52604 vport->debug_disc_trc =
52605 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
52606 index a5769a9..718ecc7 100644
52607 --- a/drivers/scsi/lpfc/lpfc_init.c
52608 +++ b/drivers/scsi/lpfc/lpfc_init.c
52609 @@ -11299,8 +11299,10 @@ lpfc_init(void)
52610 "misc_register returned with status %d", error);
52611
52612 if (lpfc_enable_npiv) {
52613 - lpfc_transport_functions.vport_create = lpfc_vport_create;
52614 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
52615 + pax_open_kernel();
52616 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
52617 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
52618 + pax_close_kernel();
52619 }
52620 lpfc_transport_template =
52621 fc_attach_transport(&lpfc_transport_functions);
52622 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
52623 index 7862c55..5aa65df 100644
52624 --- a/drivers/scsi/lpfc/lpfc_scsi.c
52625 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
52626 @@ -382,7 +382,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
52627 uint32_t evt_posted;
52628
52629 spin_lock_irqsave(&phba->hbalock, flags);
52630 - atomic_inc(&phba->num_rsrc_err);
52631 + atomic_inc_unchecked(&phba->num_rsrc_err);
52632 phba->last_rsrc_error_time = jiffies;
52633
52634 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
52635 @@ -423,8 +423,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
52636 unsigned long num_rsrc_err, num_cmd_success;
52637 int i;
52638
52639 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
52640 - num_cmd_success = atomic_read(&phba->num_cmd_success);
52641 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
52642 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
52643
52644 /*
52645 * The error and success command counters are global per
52646 @@ -452,8 +452,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
52647 }
52648 }
52649 lpfc_destroy_vport_work_array(phba, vports);
52650 - atomic_set(&phba->num_rsrc_err, 0);
52651 - atomic_set(&phba->num_cmd_success, 0);
52652 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
52653 + atomic_set_unchecked(&phba->num_cmd_success, 0);
52654 }
52655
52656 /**
52657 diff --git a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
52658 index dd46101..ca80eb9 100644
52659 --- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c
52660 +++ b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
52661 @@ -1559,7 +1559,7 @@ _scsih_get_resync(struct device *dev)
52662 {
52663 struct scsi_device *sdev = to_scsi_device(dev);
52664 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
52665 - static struct _raid_device *raid_device;
52666 + struct _raid_device *raid_device;
52667 unsigned long flags;
52668 Mpi2RaidVolPage0_t vol_pg0;
52669 Mpi2ConfigReply_t mpi_reply;
52670 @@ -1611,7 +1611,7 @@ _scsih_get_state(struct device *dev)
52671 {
52672 struct scsi_device *sdev = to_scsi_device(dev);
52673 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
52674 - static struct _raid_device *raid_device;
52675 + struct _raid_device *raid_device;
52676 unsigned long flags;
52677 Mpi2RaidVolPage0_t vol_pg0;
52678 Mpi2ConfigReply_t mpi_reply;
52679 @@ -6648,7 +6648,7 @@ _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
52680 Mpi2EventDataIrOperationStatus_t *event_data =
52681 (Mpi2EventDataIrOperationStatus_t *)
52682 fw_event->event_data;
52683 - static struct _raid_device *raid_device;
52684 + struct _raid_device *raid_device;
52685 unsigned long flags;
52686 u16 handle;
52687
52688 @@ -7119,7 +7119,7 @@ _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
52689 u64 sas_address;
52690 struct _sas_device *sas_device;
52691 struct _sas_node *expander_device;
52692 - static struct _raid_device *raid_device;
52693 + struct _raid_device *raid_device;
52694 u8 retry_count;
52695 unsigned long flags;
52696
52697 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
52698 index 6f3275d..fa5e6b6 100644
52699 --- a/drivers/scsi/pmcraid.c
52700 +++ b/drivers/scsi/pmcraid.c
52701 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
52702 res->scsi_dev = scsi_dev;
52703 scsi_dev->hostdata = res;
52704 res->change_detected = 0;
52705 - atomic_set(&res->read_failures, 0);
52706 - atomic_set(&res->write_failures, 0);
52707 + atomic_set_unchecked(&res->read_failures, 0);
52708 + atomic_set_unchecked(&res->write_failures, 0);
52709 rc = 0;
52710 }
52711 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
52712 @@ -2687,9 +2687,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
52713
52714 /* If this was a SCSI read/write command keep count of errors */
52715 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
52716 - atomic_inc(&res->read_failures);
52717 + atomic_inc_unchecked(&res->read_failures);
52718 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
52719 - atomic_inc(&res->write_failures);
52720 + atomic_inc_unchecked(&res->write_failures);
52721
52722 if (!RES_IS_GSCSI(res->cfg_entry) &&
52723 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
52724 @@ -3545,7 +3545,7 @@ static int pmcraid_queuecommand_lck(
52725 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
52726 * hrrq_id assigned here in queuecommand
52727 */
52728 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
52729 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
52730 pinstance->num_hrrq;
52731 cmd->cmd_done = pmcraid_io_done;
52732
52733 @@ -3857,7 +3857,7 @@ static long pmcraid_ioctl_passthrough(
52734 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
52735 * hrrq_id assigned here in queuecommand
52736 */
52737 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
52738 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
52739 pinstance->num_hrrq;
52740
52741 if (request_size) {
52742 @@ -4495,7 +4495,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
52743
52744 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
52745 /* add resources only after host is added into system */
52746 - if (!atomic_read(&pinstance->expose_resources))
52747 + if (!atomic_read_unchecked(&pinstance->expose_resources))
52748 return;
52749
52750 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
52751 @@ -5322,8 +5322,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
52752 init_waitqueue_head(&pinstance->reset_wait_q);
52753
52754 atomic_set(&pinstance->outstanding_cmds, 0);
52755 - atomic_set(&pinstance->last_message_id, 0);
52756 - atomic_set(&pinstance->expose_resources, 0);
52757 + atomic_set_unchecked(&pinstance->last_message_id, 0);
52758 + atomic_set_unchecked(&pinstance->expose_resources, 0);
52759
52760 INIT_LIST_HEAD(&pinstance->free_res_q);
52761 INIT_LIST_HEAD(&pinstance->used_res_q);
52762 @@ -6036,7 +6036,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
52763 /* Schedule worker thread to handle CCN and take care of adding and
52764 * removing devices to OS
52765 */
52766 - atomic_set(&pinstance->expose_resources, 1);
52767 + atomic_set_unchecked(&pinstance->expose_resources, 1);
52768 schedule_work(&pinstance->worker_q);
52769 return rc;
52770
52771 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
52772 index e1d150f..6c6df44 100644
52773 --- a/drivers/scsi/pmcraid.h
52774 +++ b/drivers/scsi/pmcraid.h
52775 @@ -748,7 +748,7 @@ struct pmcraid_instance {
52776 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
52777
52778 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
52779 - atomic_t last_message_id;
52780 + atomic_unchecked_t last_message_id;
52781
52782 /* configuration table */
52783 struct pmcraid_config_table *cfg_table;
52784 @@ -777,7 +777,7 @@ struct pmcraid_instance {
52785 atomic_t outstanding_cmds;
52786
52787 /* should add/delete resources to mid-layer now ?*/
52788 - atomic_t expose_resources;
52789 + atomic_unchecked_t expose_resources;
52790
52791
52792
52793 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
52794 struct pmcraid_config_table_entry_ext cfg_entry_ext;
52795 };
52796 struct scsi_device *scsi_dev; /* Link scsi_device structure */
52797 - atomic_t read_failures; /* count of failed READ commands */
52798 - atomic_t write_failures; /* count of failed WRITE commands */
52799 + atomic_unchecked_t read_failures; /* count of failed READ commands */
52800 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
52801
52802 /* To indicate add/delete/modify during CCN */
52803 u8 change_detected;
52804 diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
52805 index 16fe519..3b1ec82 100644
52806 --- a/drivers/scsi/qla2xxx/qla_attr.c
52807 +++ b/drivers/scsi/qla2xxx/qla_attr.c
52808 @@ -2188,7 +2188,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
52809 return 0;
52810 }
52811
52812 -struct fc_function_template qla2xxx_transport_functions = {
52813 +fc_function_template_no_const qla2xxx_transport_functions = {
52814
52815 .show_host_node_name = 1,
52816 .show_host_port_name = 1,
52817 @@ -2236,7 +2236,7 @@ struct fc_function_template qla2xxx_transport_functions = {
52818 .bsg_timeout = qla24xx_bsg_timeout,
52819 };
52820
52821 -struct fc_function_template qla2xxx_transport_vport_functions = {
52822 +fc_function_template_no_const qla2xxx_transport_vport_functions = {
52823
52824 .show_host_node_name = 1,
52825 .show_host_port_name = 1,
52826 diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
52827 index d646540..5b13554 100644
52828 --- a/drivers/scsi/qla2xxx/qla_gbl.h
52829 +++ b/drivers/scsi/qla2xxx/qla_gbl.h
52830 @@ -569,8 +569,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
52831 struct device_attribute;
52832 extern struct device_attribute *qla2x00_host_attrs[];
52833 struct fc_function_template;
52834 -extern struct fc_function_template qla2xxx_transport_functions;
52835 -extern struct fc_function_template qla2xxx_transport_vport_functions;
52836 +extern fc_function_template_no_const qla2xxx_transport_functions;
52837 +extern fc_function_template_no_const qla2xxx_transport_vport_functions;
52838 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
52839 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *, bool);
52840 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
52841 diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
52842 index 8252c0e..613adad 100644
52843 --- a/drivers/scsi/qla2xxx/qla_os.c
52844 +++ b/drivers/scsi/qla2xxx/qla_os.c
52845 @@ -1493,8 +1493,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
52846 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
52847 /* Ok, a 64bit DMA mask is applicable. */
52848 ha->flags.enable_64bit_addressing = 1;
52849 - ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
52850 - ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
52851 + pax_open_kernel();
52852 + *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
52853 + *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
52854 + pax_close_kernel();
52855 return;
52856 }
52857 }
52858 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
52859 index 8f6d0fb..1b21097 100644
52860 --- a/drivers/scsi/qla4xxx/ql4_def.h
52861 +++ b/drivers/scsi/qla4xxx/ql4_def.h
52862 @@ -305,7 +305,7 @@ struct ddb_entry {
52863 * (4000 only) */
52864 atomic_t relogin_timer; /* Max Time to wait for
52865 * relogin to complete */
52866 - atomic_t relogin_retry_count; /* Num of times relogin has been
52867 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
52868 * retried */
52869 uint32_t default_time2wait; /* Default Min time between
52870 * relogins (+aens) */
52871 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
52872 index 199fcf7..3c3a918 100644
52873 --- a/drivers/scsi/qla4xxx/ql4_os.c
52874 +++ b/drivers/scsi/qla4xxx/ql4_os.c
52875 @@ -4496,12 +4496,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
52876 */
52877 if (!iscsi_is_session_online(cls_sess)) {
52878 /* Reset retry relogin timer */
52879 - atomic_inc(&ddb_entry->relogin_retry_count);
52880 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
52881 DEBUG2(ql4_printk(KERN_INFO, ha,
52882 "%s: index[%d] relogin timed out-retrying"
52883 " relogin (%d), retry (%d)\n", __func__,
52884 ddb_entry->fw_ddb_index,
52885 - atomic_read(&ddb_entry->relogin_retry_count),
52886 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
52887 ddb_entry->default_time2wait + 4));
52888 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
52889 atomic_set(&ddb_entry->retry_relogin_timer,
52890 @@ -6609,7 +6609,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
52891
52892 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
52893 atomic_set(&ddb_entry->relogin_timer, 0);
52894 - atomic_set(&ddb_entry->relogin_retry_count, 0);
52895 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
52896 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
52897 ddb_entry->default_relogin_timeout =
52898 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
52899 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
52900 index d81f3cc..0093e5b 100644
52901 --- a/drivers/scsi/scsi.c
52902 +++ b/drivers/scsi/scsi.c
52903 @@ -645,7 +645,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
52904 struct Scsi_Host *host = cmd->device->host;
52905 int rtn = 0;
52906
52907 - atomic_inc(&cmd->device->iorequest_cnt);
52908 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
52909
52910 /* check if the device is still usable */
52911 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
52912 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
52913 index 7cb8c73..14561b5 100644
52914 --- a/drivers/scsi/scsi_lib.c
52915 +++ b/drivers/scsi/scsi_lib.c
52916 @@ -1581,7 +1581,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
52917 shost = sdev->host;
52918 scsi_init_cmd_errh(cmd);
52919 cmd->result = DID_NO_CONNECT << 16;
52920 - atomic_inc(&cmd->device->iorequest_cnt);
52921 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
52922
52923 /*
52924 * SCSI request completion path will do scsi_device_unbusy(),
52925 @@ -1604,9 +1604,9 @@ static void scsi_softirq_done(struct request *rq)
52926
52927 INIT_LIST_HEAD(&cmd->eh_entry);
52928
52929 - atomic_inc(&cmd->device->iodone_cnt);
52930 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
52931 if (cmd->result)
52932 - atomic_inc(&cmd->device->ioerr_cnt);
52933 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
52934
52935 disposition = scsi_decide_disposition(cmd);
52936 if (disposition != SUCCESS &&
52937 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
52938 index 8b4105a..1f58363 100644
52939 --- a/drivers/scsi/scsi_sysfs.c
52940 +++ b/drivers/scsi/scsi_sysfs.c
52941 @@ -805,7 +805,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
52942 char *buf) \
52943 { \
52944 struct scsi_device *sdev = to_scsi_device(dev); \
52945 - unsigned long long count = atomic_read(&sdev->field); \
52946 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
52947 return snprintf(buf, 20, "0x%llx\n", count); \
52948 } \
52949 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
52950 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
52951 index 5d6f348..18778a6b 100644
52952 --- a/drivers/scsi/scsi_transport_fc.c
52953 +++ b/drivers/scsi/scsi_transport_fc.c
52954 @@ -501,7 +501,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
52955 * Netlink Infrastructure
52956 */
52957
52958 -static atomic_t fc_event_seq;
52959 +static atomic_unchecked_t fc_event_seq;
52960
52961 /**
52962 * fc_get_event_number - Obtain the next sequential FC event number
52963 @@ -514,7 +514,7 @@ static atomic_t fc_event_seq;
52964 u32
52965 fc_get_event_number(void)
52966 {
52967 - return atomic_add_return(1, &fc_event_seq);
52968 + return atomic_add_return_unchecked(1, &fc_event_seq);
52969 }
52970 EXPORT_SYMBOL(fc_get_event_number);
52971
52972 @@ -658,7 +658,7 @@ static __init int fc_transport_init(void)
52973 {
52974 int error;
52975
52976 - atomic_set(&fc_event_seq, 0);
52977 + atomic_set_unchecked(&fc_event_seq, 0);
52978
52979 error = transport_class_register(&fc_host_class);
52980 if (error)
52981 @@ -848,7 +848,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
52982 char *cp;
52983
52984 *val = simple_strtoul(buf, &cp, 0);
52985 - if ((*cp && (*cp != '\n')) || (*val < 0))
52986 + if (*cp && (*cp != '\n'))
52987 return -EINVAL;
52988 /*
52989 * Check for overflow; dev_loss_tmo is u32
52990 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
52991 index 67d43e3..8cee73c 100644
52992 --- a/drivers/scsi/scsi_transport_iscsi.c
52993 +++ b/drivers/scsi/scsi_transport_iscsi.c
52994 @@ -79,7 +79,7 @@ struct iscsi_internal {
52995 struct transport_container session_cont;
52996 };
52997
52998 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
52999 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
53000 static struct workqueue_struct *iscsi_eh_timer_workq;
53001
53002 static DEFINE_IDA(iscsi_sess_ida);
53003 @@ -2071,7 +2071,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
53004 int err;
53005
53006 ihost = shost->shost_data;
53007 - session->sid = atomic_add_return(1, &iscsi_session_nr);
53008 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
53009
53010 if (target_id == ISCSI_MAX_TARGET) {
53011 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
53012 @@ -4515,7 +4515,7 @@ static __init int iscsi_transport_init(void)
53013 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
53014 ISCSI_TRANSPORT_VERSION);
53015
53016 - atomic_set(&iscsi_session_nr, 0);
53017 + atomic_set_unchecked(&iscsi_session_nr, 0);
53018
53019 err = class_register(&iscsi_transport_class);
53020 if (err)
53021 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
53022 index ae45bd9..c32a586 100644
53023 --- a/drivers/scsi/scsi_transport_srp.c
53024 +++ b/drivers/scsi/scsi_transport_srp.c
53025 @@ -35,7 +35,7 @@
53026 #include "scsi_priv.h"
53027
53028 struct srp_host_attrs {
53029 - atomic_t next_port_id;
53030 + atomic_unchecked_t next_port_id;
53031 };
53032 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
53033
53034 @@ -100,7 +100,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
53035 struct Scsi_Host *shost = dev_to_shost(dev);
53036 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
53037
53038 - atomic_set(&srp_host->next_port_id, 0);
53039 + atomic_set_unchecked(&srp_host->next_port_id, 0);
53040 return 0;
53041 }
53042
53043 @@ -734,7 +734,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
53044 rport_fast_io_fail_timedout);
53045 INIT_DELAYED_WORK(&rport->dev_loss_work, rport_dev_loss_timedout);
53046
53047 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
53048 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
53049 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
53050
53051 transport_setup_device(&rport->dev);
53052 diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
53053 index 2c2041c..9d94085 100644
53054 --- a/drivers/scsi/sd.c
53055 +++ b/drivers/scsi/sd.c
53056 @@ -3002,7 +3002,7 @@ static int sd_probe(struct device *dev)
53057 sdkp->disk = gd;
53058 sdkp->index = index;
53059 atomic_set(&sdkp->openers, 0);
53060 - atomic_set(&sdkp->device->ioerr_cnt, 0);
53061 + atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
53062
53063 if (!sdp->request_queue->rq_timeout) {
53064 if (sdp->type != TYPE_MOD)
53065 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
53066 index 01cf888..59e0475 100644
53067 --- a/drivers/scsi/sg.c
53068 +++ b/drivers/scsi/sg.c
53069 @@ -1138,7 +1138,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
53070 sdp->disk->disk_name,
53071 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
53072 NULL,
53073 - (char *)arg);
53074 + (char __user *)arg);
53075 case BLKTRACESTART:
53076 return blk_trace_startstop(sdp->device->request_queue, 1);
53077 case BLKTRACESTOP:
53078 diff --git a/drivers/soc/tegra/fuse/fuse-tegra.c b/drivers/soc/tegra/fuse/fuse-tegra.c
53079 index 11a5043..e36f04c 100644
53080 --- a/drivers/soc/tegra/fuse/fuse-tegra.c
53081 +++ b/drivers/soc/tegra/fuse/fuse-tegra.c
53082 @@ -70,7 +70,7 @@ static ssize_t fuse_read(struct file *fd, struct kobject *kobj,
53083 return i;
53084 }
53085
53086 -static struct bin_attribute fuse_bin_attr = {
53087 +static bin_attribute_no_const fuse_bin_attr = {
53088 .attr = { .name = "fuse", .mode = S_IRUGO, },
53089 .read = fuse_read,
53090 };
53091 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
53092 index 2bf2dfa..b4d9008 100644
53093 --- a/drivers/spi/spi.c
53094 +++ b/drivers/spi/spi.c
53095 @@ -2210,7 +2210,7 @@ int spi_bus_unlock(struct spi_master *master)
53096 EXPORT_SYMBOL_GPL(spi_bus_unlock);
53097
53098 /* portable code must never pass more than 32 bytes */
53099 -#define SPI_BUFSIZ max(32, SMP_CACHE_BYTES)
53100 +#define SPI_BUFSIZ max(32UL, SMP_CACHE_BYTES)
53101
53102 static u8 *buf;
53103
53104 diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
53105 index b41429f..2de5373 100644
53106 --- a/drivers/staging/android/timed_output.c
53107 +++ b/drivers/staging/android/timed_output.c
53108 @@ -25,7 +25,7 @@
53109 #include "timed_output.h"
53110
53111 static struct class *timed_output_class;
53112 -static atomic_t device_count;
53113 +static atomic_unchecked_t device_count;
53114
53115 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
53116 char *buf)
53117 @@ -65,7 +65,7 @@ static int create_timed_output_class(void)
53118 timed_output_class = class_create(THIS_MODULE, "timed_output");
53119 if (IS_ERR(timed_output_class))
53120 return PTR_ERR(timed_output_class);
53121 - atomic_set(&device_count, 0);
53122 + atomic_set_unchecked(&device_count, 0);
53123 timed_output_class->dev_groups = timed_output_groups;
53124 }
53125
53126 @@ -83,7 +83,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
53127 if (ret < 0)
53128 return ret;
53129
53130 - tdev->index = atomic_inc_return(&device_count);
53131 + tdev->index = atomic_inc_return_unchecked(&device_count);
53132 tdev->dev = device_create(timed_output_class, NULL,
53133 MKDEV(0, tdev->index), NULL, "%s", tdev->name);
53134 if (IS_ERR(tdev->dev))
53135 diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c
53136 index 001348c..cfaac8a 100644
53137 --- a/drivers/staging/gdm724x/gdm_tty.c
53138 +++ b/drivers/staging/gdm724x/gdm_tty.c
53139 @@ -44,7 +44,7 @@
53140 #define gdm_tty_send_control(n, r, v, d, l) (\
53141 n->tty_dev->send_control(n->tty_dev->priv_dev, r, v, d, l))
53142
53143 -#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && gdm->port.count)
53144 +#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && atomic_read(&gdm->port.count))
53145
53146 static struct tty_driver *gdm_driver[TTY_MAX_COUNT];
53147 static struct gdm *gdm_table[TTY_MAX_COUNT][GDM_TTY_MINOR];
53148 diff --git a/drivers/staging/imx-drm/imx-drm-core.c b/drivers/staging/imx-drm/imx-drm-core.c
53149 index 6b22106..6c6e641 100644
53150 --- a/drivers/staging/imx-drm/imx-drm-core.c
53151 +++ b/drivers/staging/imx-drm/imx-drm-core.c
53152 @@ -355,7 +355,7 @@ int imx_drm_add_crtc(struct drm_device *drm, struct drm_crtc *crtc,
53153 if (imxdrm->pipes >= MAX_CRTC)
53154 return -EINVAL;
53155
53156 - if (imxdrm->drm->open_count)
53157 + if (local_read(&imxdrm->drm->open_count))
53158 return -EBUSY;
53159
53160 imx_drm_crtc = kzalloc(sizeof(*imx_drm_crtc), GFP_KERNEL);
53161 diff --git a/drivers/staging/line6/driver.c b/drivers/staging/line6/driver.c
53162 index 503b2d7..c918745 100644
53163 --- a/drivers/staging/line6/driver.c
53164 +++ b/drivers/staging/line6/driver.c
53165 @@ -463,7 +463,7 @@ int line6_read_data(struct usb_line6 *line6, int address, void *data,
53166 {
53167 struct usb_device *usbdev = line6->usbdev;
53168 int ret;
53169 - unsigned char len;
53170 + unsigned char *plen;
53171
53172 /* query the serial number: */
53173 ret = usb_control_msg(usbdev, usb_sndctrlpipe(usbdev, 0), 0x67,
53174 @@ -476,27 +476,34 @@ int line6_read_data(struct usb_line6 *line6, int address, void *data,
53175 return ret;
53176 }
53177
53178 + plen = kmalloc(1, GFP_KERNEL);
53179 + if (plen == NULL)
53180 + return -ENOMEM;
53181 +
53182 /* Wait for data length. We'll get 0xff until length arrives. */
53183 do {
53184 ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0), 0x67,
53185 USB_TYPE_VENDOR | USB_RECIP_DEVICE |
53186 USB_DIR_IN,
53187 - 0x0012, 0x0000, &len, 1,
53188 + 0x0012, 0x0000, plen, 1,
53189 LINE6_TIMEOUT * HZ);
53190 if (ret < 0) {
53191 dev_err(line6->ifcdev,
53192 "receive length failed (error %d)\n", ret);
53193 + kfree(plen);
53194 return ret;
53195 }
53196 - } while (len == 0xff);
53197 + } while (*plen == 0xff);
53198
53199 - if (len != datalen) {
53200 + if (*plen != datalen) {
53201 /* should be equal or something went wrong */
53202 dev_err(line6->ifcdev,
53203 "length mismatch (expected %d, got %d)\n",
53204 - (int)datalen, (int)len);
53205 + (int)datalen, (int)*plen);
53206 + kfree(plen);
53207 return -EINVAL;
53208 }
53209 + kfree(plen);
53210
53211 /* receive the result: */
53212 ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0), 0x67,
53213 diff --git a/drivers/staging/lustre/lnet/selftest/brw_test.c b/drivers/staging/lustre/lnet/selftest/brw_test.c
53214 index bcce919..f30fcf9 100644
53215 --- a/drivers/staging/lustre/lnet/selftest/brw_test.c
53216 +++ b/drivers/staging/lustre/lnet/selftest/brw_test.c
53217 @@ -488,13 +488,11 @@ brw_server_handle(struct srpc_server_rpc *rpc)
53218 return 0;
53219 }
53220
53221 -sfw_test_client_ops_t brw_test_client;
53222 -void brw_init_test_client(void)
53223 -{
53224 - brw_test_client.tso_init = brw_client_init;
53225 - brw_test_client.tso_fini = brw_client_fini;
53226 - brw_test_client.tso_prep_rpc = brw_client_prep_rpc;
53227 - brw_test_client.tso_done_rpc = brw_client_done_rpc;
53228 +sfw_test_client_ops_t brw_test_client = {
53229 + .tso_init = brw_client_init,
53230 + .tso_fini = brw_client_fini,
53231 + .tso_prep_rpc = brw_client_prep_rpc,
53232 + .tso_done_rpc = brw_client_done_rpc,
53233 };
53234
53235 srpc_service_t brw_test_service;
53236 diff --git a/drivers/staging/lustre/lnet/selftest/framework.c b/drivers/staging/lustre/lnet/selftest/framework.c
53237 index 7e83dff..1f9a545 100644
53238 --- a/drivers/staging/lustre/lnet/selftest/framework.c
53239 +++ b/drivers/staging/lustre/lnet/selftest/framework.c
53240 @@ -1633,12 +1633,10 @@ static srpc_service_t sfw_services[] =
53241
53242 extern sfw_test_client_ops_t ping_test_client;
53243 extern srpc_service_t ping_test_service;
53244 -extern void ping_init_test_client(void);
53245 extern void ping_init_test_service(void);
53246
53247 extern sfw_test_client_ops_t brw_test_client;
53248 extern srpc_service_t brw_test_service;
53249 -extern void brw_init_test_client(void);
53250 extern void brw_init_test_service(void);
53251
53252
53253 @@ -1682,12 +1680,10 @@ sfw_startup (void)
53254 INIT_LIST_HEAD(&sfw_data.fw_zombie_rpcs);
53255 INIT_LIST_HEAD(&sfw_data.fw_zombie_sessions);
53256
53257 - brw_init_test_client();
53258 brw_init_test_service();
53259 rc = sfw_register_test(&brw_test_service, &brw_test_client);
53260 LASSERT (rc == 0);
53261
53262 - ping_init_test_client();
53263 ping_init_test_service();
53264 rc = sfw_register_test(&ping_test_service, &ping_test_client);
53265 LASSERT (rc == 0);
53266 diff --git a/drivers/staging/lustre/lnet/selftest/ping_test.c b/drivers/staging/lustre/lnet/selftest/ping_test.c
53267 index 750cac4..e4d751f 100644
53268 --- a/drivers/staging/lustre/lnet/selftest/ping_test.c
53269 +++ b/drivers/staging/lustre/lnet/selftest/ping_test.c
53270 @@ -211,14 +211,12 @@ ping_server_handle(struct srpc_server_rpc *rpc)
53271 return 0;
53272 }
53273
53274 -sfw_test_client_ops_t ping_test_client;
53275 -void ping_init_test_client(void)
53276 -{
53277 - ping_test_client.tso_init = ping_client_init;
53278 - ping_test_client.tso_fini = ping_client_fini;
53279 - ping_test_client.tso_prep_rpc = ping_client_prep_rpc;
53280 - ping_test_client.tso_done_rpc = ping_client_done_rpc;
53281 -}
53282 +sfw_test_client_ops_t ping_test_client = {
53283 + .tso_init = ping_client_init,
53284 + .tso_fini = ping_client_fini,
53285 + .tso_prep_rpc = ping_client_prep_rpc,
53286 + .tso_done_rpc = ping_client_done_rpc,
53287 +};
53288
53289 srpc_service_t ping_test_service;
53290 void ping_init_test_service(void)
53291 diff --git a/drivers/staging/lustre/lustre/include/lustre_dlm.h b/drivers/staging/lustre/lustre/include/lustre_dlm.h
53292 index 30b1812f..9e5bd0b 100644
53293 --- a/drivers/staging/lustre/lustre/include/lustre_dlm.h
53294 +++ b/drivers/staging/lustre/lustre/include/lustre_dlm.h
53295 @@ -1141,7 +1141,7 @@ struct ldlm_callback_suite {
53296 ldlm_completion_callback lcs_completion;
53297 ldlm_blocking_callback lcs_blocking;
53298 ldlm_glimpse_callback lcs_glimpse;
53299 -};
53300 +} __no_const;
53301
53302 /* ldlm_lockd.c */
53303 int ldlm_del_waiting_lock(struct ldlm_lock *lock);
53304 diff --git a/drivers/staging/lustre/lustre/include/obd.h b/drivers/staging/lustre/lustre/include/obd.h
53305 index 489bdd3..65058081 100644
53306 --- a/drivers/staging/lustre/lustre/include/obd.h
53307 +++ b/drivers/staging/lustre/lustre/include/obd.h
53308 @@ -1438,7 +1438,7 @@ struct md_ops {
53309 * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
53310 * wrapper function in include/linux/obd_class.h.
53311 */
53312 -};
53313 +} __no_const;
53314
53315 struct lsm_operations {
53316 void (*lsm_free)(struct lov_stripe_md *);
53317 diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
53318 index b798daa..b28ca8f 100644
53319 --- a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
53320 +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
53321 @@ -258,7 +258,7 @@ ldlm_process_flock_lock(struct ldlm_lock *req, __u64 *flags, int first_enq,
53322 int added = (mode == LCK_NL);
53323 int overlaps = 0;
53324 int splitted = 0;
53325 - const struct ldlm_callback_suite null_cbs = { NULL };
53326 + const struct ldlm_callback_suite null_cbs = { };
53327
53328 CDEBUG(D_DLMTRACE, "flags %#llx owner %llu pid %u mode %u start %llu end %llu\n",
53329 *flags, new->l_policy_data.l_flock.owner,
53330 diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
53331 index 13a9266..3439390 100644
53332 --- a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
53333 +++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
53334 @@ -235,7 +235,7 @@ int proc_console_max_delay_cs(struct ctl_table *table, int write,
53335 void __user *buffer, size_t *lenp, loff_t *ppos)
53336 {
53337 int rc, max_delay_cs;
53338 - struct ctl_table dummy = *table;
53339 + ctl_table_no_const dummy = *table;
53340 long d;
53341
53342 dummy.data = &max_delay_cs;
53343 @@ -267,7 +267,7 @@ int proc_console_min_delay_cs(struct ctl_table *table, int write,
53344 void __user *buffer, size_t *lenp, loff_t *ppos)
53345 {
53346 int rc, min_delay_cs;
53347 - struct ctl_table dummy = *table;
53348 + ctl_table_no_const dummy = *table;
53349 long d;
53350
53351 dummy.data = &min_delay_cs;
53352 @@ -299,7 +299,7 @@ int proc_console_backoff(struct ctl_table *table, int write,
53353 void __user *buffer, size_t *lenp, loff_t *ppos)
53354 {
53355 int rc, backoff;
53356 - struct ctl_table dummy = *table;
53357 + ctl_table_no_const dummy = *table;
53358
53359 dummy.data = &backoff;
53360 dummy.proc_handler = &proc_dointvec;
53361 diff --git a/drivers/staging/lustre/lustre/libcfs/module.c b/drivers/staging/lustre/lustre/libcfs/module.c
53362 index 3396858..c0bd996 100644
53363 --- a/drivers/staging/lustre/lustre/libcfs/module.c
53364 +++ b/drivers/staging/lustre/lustre/libcfs/module.c
53365 @@ -314,11 +314,11 @@ out:
53366
53367
53368 struct cfs_psdev_ops libcfs_psdev_ops = {
53369 - libcfs_psdev_open,
53370 - libcfs_psdev_release,
53371 - NULL,
53372 - NULL,
53373 - libcfs_ioctl
53374 + .p_open = libcfs_psdev_open,
53375 + .p_close = libcfs_psdev_release,
53376 + .p_read = NULL,
53377 + .p_write = NULL,
53378 + .p_ioctl = libcfs_ioctl
53379 };
53380
53381 extern int insert_proc(void);
53382 diff --git a/drivers/staging/lustre/lustre/llite/dir.c b/drivers/staging/lustre/lustre/llite/dir.c
53383 index efa2faf..03a9836 100644
53384 --- a/drivers/staging/lustre/lustre/llite/dir.c
53385 +++ b/drivers/staging/lustre/lustre/llite/dir.c
53386 @@ -659,7 +659,7 @@ int ll_dir_setdirstripe(struct inode *dir, struct lmv_user_md *lump,
53387 int mode;
53388 int err;
53389
53390 - mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current->fs->umask) | S_IFDIR;
53391 + mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current_umask()) | S_IFDIR;
53392 op_data = ll_prep_md_op_data(NULL, dir, NULL, filename,
53393 strlen(filename), mode, LUSTRE_OPC_MKDIR,
53394 lump);
53395 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
53396 index a0f4868..139f1fb 100644
53397 --- a/drivers/staging/octeon/ethernet-rx.c
53398 +++ b/drivers/staging/octeon/ethernet-rx.c
53399 @@ -417,11 +417,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
53400 /* Increment RX stats for virtual ports */
53401 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
53402 #ifdef CONFIG_64BIT
53403 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
53404 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
53405 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
53406 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
53407 #else
53408 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
53409 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
53410 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
53411 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
53412 #endif
53413 }
53414 netif_receive_skb(skb);
53415 @@ -432,9 +432,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
53416 dev->name);
53417 */
53418 #ifdef CONFIG_64BIT
53419 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
53420 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
53421 #else
53422 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
53423 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
53424 #endif
53425 dev_kfree_skb_irq(skb);
53426 }
53427 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
53428 index 2aa7235..ba3c205 100644
53429 --- a/drivers/staging/octeon/ethernet.c
53430 +++ b/drivers/staging/octeon/ethernet.c
53431 @@ -247,11 +247,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
53432 * since the RX tasklet also increments it.
53433 */
53434 #ifdef CONFIG_64BIT
53435 - atomic64_add(rx_status.dropped_packets,
53436 - (atomic64_t *)&priv->stats.rx_dropped);
53437 + atomic64_add_unchecked(rx_status.dropped_packets,
53438 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
53439 #else
53440 - atomic_add(rx_status.dropped_packets,
53441 - (atomic_t *)&priv->stats.rx_dropped);
53442 + atomic_add_unchecked(rx_status.dropped_packets,
53443 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
53444 #endif
53445 }
53446
53447 diff --git a/drivers/staging/rtl8188eu/include/hal_intf.h b/drivers/staging/rtl8188eu/include/hal_intf.h
53448 index 56d5c50..a14f4db 100644
53449 --- a/drivers/staging/rtl8188eu/include/hal_intf.h
53450 +++ b/drivers/staging/rtl8188eu/include/hal_intf.h
53451 @@ -234,7 +234,7 @@ struct hal_ops {
53452
53453 void (*hal_notch_filter)(struct adapter *adapter, bool enable);
53454 void (*hal_reset_security_engine)(struct adapter *adapter);
53455 -};
53456 +} __no_const;
53457
53458 enum rt_eeprom_type {
53459 EEPROM_93C46,
53460 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
53461 index dc23395..cf7e9b1 100644
53462 --- a/drivers/staging/rtl8712/rtl871x_io.h
53463 +++ b/drivers/staging/rtl8712/rtl871x_io.h
53464 @@ -108,7 +108,7 @@ struct _io_ops {
53465 u8 *pmem);
53466 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
53467 u8 *pmem);
53468 -};
53469 +} __no_const;
53470
53471 struct io_req {
53472 struct list_head list;
53473 diff --git a/drivers/staging/unisys/visorchipset/visorchipset.h b/drivers/staging/unisys/visorchipset/visorchipset.h
53474 index 2bf2e2f..84421c9 100644
53475 --- a/drivers/staging/unisys/visorchipset/visorchipset.h
53476 +++ b/drivers/staging/unisys/visorchipset/visorchipset.h
53477 @@ -228,7 +228,7 @@ typedef struct {
53478 void (*device_resume)(ulong busNo, ulong devNo);
53479 int (*get_channel_info)(uuid_le typeGuid, ulong *minSize,
53480 ulong *maxSize);
53481 -} VISORCHIPSET_BUSDEV_NOTIFIERS;
53482 +} __no_const VISORCHIPSET_BUSDEV_NOTIFIERS;
53483
53484 /* These functions live inside visorchipset, and will be called to indicate
53485 * responses to specific events (by code outside of visorchipset).
53486 @@ -243,7 +243,7 @@ typedef struct {
53487 void (*device_destroy)(ulong busNo, ulong devNo, int response);
53488 void (*device_pause)(ulong busNo, ulong devNo, int response);
53489 void (*device_resume)(ulong busNo, ulong devNo, int response);
53490 -} VISORCHIPSET_BUSDEV_RESPONDERS;
53491 +} __no_const VISORCHIPSET_BUSDEV_RESPONDERS;
53492
53493 /** Register functions (in the bus driver) to get called by visorchipset
53494 * whenever a bus or device appears for which this service partition is
53495 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
53496 index 164136b..7244df5 100644
53497 --- a/drivers/staging/vt6655/hostap.c
53498 +++ b/drivers/staging/vt6655/hostap.c
53499 @@ -68,14 +68,13 @@ static int msglevel = MSG_LEVEL_INFO;
53500 *
53501 */
53502
53503 +static net_device_ops_no_const apdev_netdev_ops;
53504 +
53505 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
53506 {
53507 PSDevice apdev_priv;
53508 struct net_device *dev = pDevice->dev;
53509 int ret;
53510 - const struct net_device_ops apdev_netdev_ops = {
53511 - .ndo_start_xmit = pDevice->tx_80211,
53512 - };
53513
53514 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
53515
53516 @@ -87,6 +86,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
53517 *apdev_priv = *pDevice;
53518 eth_hw_addr_inherit(pDevice->apdev, dev);
53519
53520 + /* only half broken now */
53521 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
53522 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
53523
53524 pDevice->apdev->type = ARPHRD_IEEE80211;
53525 diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
53526 index e7e9372..161f530 100644
53527 --- a/drivers/target/sbp/sbp_target.c
53528 +++ b/drivers/target/sbp/sbp_target.c
53529 @@ -62,7 +62,7 @@ static const u32 sbp_unit_directory_template[] = {
53530
53531 #define SESSION_MAINTENANCE_INTERVAL HZ
53532
53533 -static atomic_t login_id = ATOMIC_INIT(0);
53534 +static atomic_unchecked_t login_id = ATOMIC_INIT(0);
53535
53536 static void session_maintenance_work(struct work_struct *);
53537 static int sbp_run_transaction(struct fw_card *, int, int, int, int,
53538 @@ -444,7 +444,7 @@ static void sbp_management_request_login(
53539 login->lun = se_lun;
53540 login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo);
53541 login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc));
53542 - login->login_id = atomic_inc_return(&login_id);
53543 + login->login_id = atomic_inc_return_unchecked(&login_id);
53544
53545 login->tgt_agt = sbp_target_agent_register(login);
53546 if (IS_ERR(login->tgt_agt)) {
53547 diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
53548 index 15a1c13..6c9b96b 100644
53549 --- a/drivers/target/target_core_device.c
53550 +++ b/drivers/target/target_core_device.c
53551 @@ -1526,7 +1526,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
53552 spin_lock_init(&dev->se_tmr_lock);
53553 spin_lock_init(&dev->qf_cmd_lock);
53554 sema_init(&dev->caw_sem, 1);
53555 - atomic_set(&dev->dev_ordered_id, 0);
53556 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
53557 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
53558 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
53559 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
53560 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
53561 index a9c77b5..024a07d 100644
53562 --- a/drivers/target/target_core_transport.c
53563 +++ b/drivers/target/target_core_transport.c
53564 @@ -1165,7 +1165,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
53565 * Used to determine when ORDERED commands should go from
53566 * Dormant to Active status.
53567 */
53568 - cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
53569 + cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
53570 smp_mb__after_atomic();
53571 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
53572 cmd->se_ordered_id, cmd->sam_task_attr,
53573 diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c
53574 index 4b2b999..cad9fa5 100644
53575 --- a/drivers/thermal/of-thermal.c
53576 +++ b/drivers/thermal/of-thermal.c
53577 @@ -30,6 +30,7 @@
53578 #include <linux/err.h>
53579 #include <linux/export.h>
53580 #include <linux/string.h>
53581 +#include <linux/mm.h>
53582
53583 #include "thermal_core.h"
53584
53585 @@ -341,8 +342,10 @@ thermal_zone_of_add_sensor(struct device_node *zone,
53586 tz->get_trend = get_trend;
53587 tz->sensor_data = data;
53588
53589 - tzd->ops->get_temp = of_thermal_get_temp;
53590 - tzd->ops->get_trend = of_thermal_get_trend;
53591 + pax_open_kernel();
53592 + *(void **)&tzd->ops->get_temp = of_thermal_get_temp;
53593 + *(void **)&tzd->ops->get_trend = of_thermal_get_trend;
53594 + pax_close_kernel();
53595 mutex_unlock(&tzd->lock);
53596
53597 return tzd;
53598 @@ -461,8 +464,10 @@ void thermal_zone_of_sensor_unregister(struct device *dev,
53599 return;
53600
53601 mutex_lock(&tzd->lock);
53602 - tzd->ops->get_temp = NULL;
53603 - tzd->ops->get_trend = NULL;
53604 + pax_open_kernel();
53605 + *(void **)&tzd->ops->get_temp = NULL;
53606 + *(void **)&tzd->ops->get_trend = NULL;
53607 + pax_close_kernel();
53608
53609 tz->get_temp = NULL;
53610 tz->get_trend = NULL;
53611 diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
53612 index fd66f57..48e6376 100644
53613 --- a/drivers/tty/cyclades.c
53614 +++ b/drivers/tty/cyclades.c
53615 @@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
53616 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
53617 info->port.count);
53618 #endif
53619 - info->port.count++;
53620 + atomic_inc(&info->port.count);
53621 #ifdef CY_DEBUG_COUNT
53622 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
53623 - current->pid, info->port.count);
53624 + current->pid, atomic_read(&info->port.count));
53625 #endif
53626
53627 /*
53628 @@ -3974,7 +3974,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
53629 for (j = 0; j < cy_card[i].nports; j++) {
53630 info = &cy_card[i].ports[j];
53631
53632 - if (info->port.count) {
53633 + if (atomic_read(&info->port.count)) {
53634 /* XXX is the ldisc num worth this? */
53635 struct tty_struct *tty;
53636 struct tty_ldisc *ld;
53637 diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
53638 index 4fcec1d..5a036f7 100644
53639 --- a/drivers/tty/hvc/hvc_console.c
53640 +++ b/drivers/tty/hvc/hvc_console.c
53641 @@ -342,7 +342,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
53642
53643 spin_lock_irqsave(&hp->port.lock, flags);
53644 /* Check and then increment for fast path open. */
53645 - if (hp->port.count++ > 0) {
53646 + if (atomic_inc_return(&hp->port.count) > 1) {
53647 spin_unlock_irqrestore(&hp->port.lock, flags);
53648 hvc_kick();
53649 return 0;
53650 @@ -397,7 +397,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
53651
53652 spin_lock_irqsave(&hp->port.lock, flags);
53653
53654 - if (--hp->port.count == 0) {
53655 + if (atomic_dec_return(&hp->port.count) == 0) {
53656 spin_unlock_irqrestore(&hp->port.lock, flags);
53657 /* We are done with the tty pointer now. */
53658 tty_port_tty_set(&hp->port, NULL);
53659 @@ -419,9 +419,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
53660 */
53661 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
53662 } else {
53663 - if (hp->port.count < 0)
53664 + if (atomic_read(&hp->port.count) < 0)
53665 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
53666 - hp->vtermno, hp->port.count);
53667 + hp->vtermno, atomic_read(&hp->port.count));
53668 spin_unlock_irqrestore(&hp->port.lock, flags);
53669 }
53670 }
53671 @@ -451,12 +451,12 @@ static void hvc_hangup(struct tty_struct *tty)
53672 * open->hangup case this can be called after the final close so prevent
53673 * that from happening for now.
53674 */
53675 - if (hp->port.count <= 0) {
53676 + if (atomic_read(&hp->port.count) <= 0) {
53677 spin_unlock_irqrestore(&hp->port.lock, flags);
53678 return;
53679 }
53680
53681 - hp->port.count = 0;
53682 + atomic_set(&hp->port.count, 0);
53683 spin_unlock_irqrestore(&hp->port.lock, flags);
53684 tty_port_tty_set(&hp->port, NULL);
53685
53686 @@ -504,7 +504,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
53687 return -EPIPE;
53688
53689 /* FIXME what's this (unprotected) check for? */
53690 - if (hp->port.count <= 0)
53691 + if (atomic_read(&hp->port.count) <= 0)
53692 return -EIO;
53693
53694 spin_lock_irqsave(&hp->lock, flags);
53695 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
53696 index 81e939e..95ead10 100644
53697 --- a/drivers/tty/hvc/hvcs.c
53698 +++ b/drivers/tty/hvc/hvcs.c
53699 @@ -83,6 +83,7 @@
53700 #include <asm/hvcserver.h>
53701 #include <asm/uaccess.h>
53702 #include <asm/vio.h>
53703 +#include <asm/local.h>
53704
53705 /*
53706 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
53707 @@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
53708
53709 spin_lock_irqsave(&hvcsd->lock, flags);
53710
53711 - if (hvcsd->port.count > 0) {
53712 + if (atomic_read(&hvcsd->port.count) > 0) {
53713 spin_unlock_irqrestore(&hvcsd->lock, flags);
53714 printk(KERN_INFO "HVCS: vterm state unchanged. "
53715 "The hvcs device node is still in use.\n");
53716 @@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
53717 }
53718 }
53719
53720 - hvcsd->port.count = 0;
53721 + atomic_set(&hvcsd->port.count, 0);
53722 hvcsd->port.tty = tty;
53723 tty->driver_data = hvcsd;
53724
53725 @@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
53726 unsigned long flags;
53727
53728 spin_lock_irqsave(&hvcsd->lock, flags);
53729 - hvcsd->port.count++;
53730 + atomic_inc(&hvcsd->port.count);
53731 hvcsd->todo_mask |= HVCS_SCHED_READ;
53732 spin_unlock_irqrestore(&hvcsd->lock, flags);
53733
53734 @@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
53735 hvcsd = tty->driver_data;
53736
53737 spin_lock_irqsave(&hvcsd->lock, flags);
53738 - if (--hvcsd->port.count == 0) {
53739 + if (atomic_dec_and_test(&hvcsd->port.count)) {
53740
53741 vio_disable_interrupts(hvcsd->vdev);
53742
53743 @@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
53744
53745 free_irq(irq, hvcsd);
53746 return;
53747 - } else if (hvcsd->port.count < 0) {
53748 + } else if (atomic_read(&hvcsd->port.count) < 0) {
53749 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
53750 " is missmanaged.\n",
53751 - hvcsd->vdev->unit_address, hvcsd->port.count);
53752 + hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
53753 }
53754
53755 spin_unlock_irqrestore(&hvcsd->lock, flags);
53756 @@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
53757
53758 spin_lock_irqsave(&hvcsd->lock, flags);
53759 /* Preserve this so that we know how many kref refs to put */
53760 - temp_open_count = hvcsd->port.count;
53761 + temp_open_count = atomic_read(&hvcsd->port.count);
53762
53763 /*
53764 * Don't kref put inside the spinlock because the destruction
53765 @@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
53766 tty->driver_data = NULL;
53767 hvcsd->port.tty = NULL;
53768
53769 - hvcsd->port.count = 0;
53770 + atomic_set(&hvcsd->port.count, 0);
53771
53772 /* This will drop any buffered data on the floor which is OK in a hangup
53773 * scenario. */
53774 @@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
53775 * the middle of a write operation? This is a crummy place to do this
53776 * but we want to keep it all in the spinlock.
53777 */
53778 - if (hvcsd->port.count <= 0) {
53779 + if (atomic_read(&hvcsd->port.count) <= 0) {
53780 spin_unlock_irqrestore(&hvcsd->lock, flags);
53781 return -ENODEV;
53782 }
53783 @@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
53784 {
53785 struct hvcs_struct *hvcsd = tty->driver_data;
53786
53787 - if (!hvcsd || hvcsd->port.count <= 0)
53788 + if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
53789 return 0;
53790
53791 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
53792 diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
53793 index 4190199..06d5bfa 100644
53794 --- a/drivers/tty/hvc/hvsi.c
53795 +++ b/drivers/tty/hvc/hvsi.c
53796 @@ -85,7 +85,7 @@ struct hvsi_struct {
53797 int n_outbuf;
53798 uint32_t vtermno;
53799 uint32_t virq;
53800 - atomic_t seqno; /* HVSI packet sequence number */
53801 + atomic_unchecked_t seqno; /* HVSI packet sequence number */
53802 uint16_t mctrl;
53803 uint8_t state; /* HVSI protocol state */
53804 uint8_t flags;
53805 @@ -295,7 +295,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
53806
53807 packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
53808 packet.hdr.len = sizeof(struct hvsi_query_response);
53809 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
53810 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
53811 packet.verb = VSV_SEND_VERSION_NUMBER;
53812 packet.u.version = HVSI_VERSION;
53813 packet.query_seqno = query_seqno+1;
53814 @@ -555,7 +555,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
53815
53816 packet.hdr.type = VS_QUERY_PACKET_HEADER;
53817 packet.hdr.len = sizeof(struct hvsi_query);
53818 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
53819 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
53820 packet.verb = verb;
53821
53822 pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
53823 @@ -597,7 +597,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
53824 int wrote;
53825
53826 packet.hdr.type = VS_CONTROL_PACKET_HEADER,
53827 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
53828 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
53829 packet.hdr.len = sizeof(struct hvsi_control);
53830 packet.verb = VSV_SET_MODEM_CTL;
53831 packet.mask = HVSI_TSDTR;
53832 @@ -680,7 +680,7 @@ static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
53833 BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
53834
53835 packet.hdr.type = VS_DATA_PACKET_HEADER;
53836 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
53837 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
53838 packet.hdr.len = count + sizeof(struct hvsi_header);
53839 memcpy(&packet.data, buf, count);
53840
53841 @@ -697,7 +697,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
53842 struct hvsi_control packet __ALIGNED__;
53843
53844 packet.hdr.type = VS_CONTROL_PACKET_HEADER;
53845 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
53846 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
53847 packet.hdr.len = 6;
53848 packet.verb = VSV_CLOSE_PROTOCOL;
53849
53850 @@ -725,7 +725,7 @@ static int hvsi_open(struct tty_struct *tty, struct file *filp)
53851
53852 tty_port_tty_set(&hp->port, tty);
53853 spin_lock_irqsave(&hp->lock, flags);
53854 - hp->port.count++;
53855 + atomic_inc(&hp->port.count);
53856 atomic_set(&hp->seqno, 0);
53857 h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE);
53858 spin_unlock_irqrestore(&hp->lock, flags);
53859 @@ -782,7 +782,7 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
53860
53861 spin_lock_irqsave(&hp->lock, flags);
53862
53863 - if (--hp->port.count == 0) {
53864 + if (atomic_dec_return(&hp->port.count) == 0) {
53865 tty_port_tty_set(&hp->port, NULL);
53866 hp->inbuf_end = hp->inbuf; /* discard remaining partial packets */
53867
53868 @@ -815,9 +815,9 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
53869
53870 spin_lock_irqsave(&hp->lock, flags);
53871 }
53872 - } else if (hp->port.count < 0)
53873 + } else if (atomic_read(&hp->port.count) < 0)
53874 printk(KERN_ERR "hvsi_close %lu: oops, count is %d\n",
53875 - hp - hvsi_ports, hp->port.count);
53876 + hp - hvsi_ports, atomic_read(&hp->port.count));
53877
53878 spin_unlock_irqrestore(&hp->lock, flags);
53879 }
53880 @@ -832,7 +832,7 @@ static void hvsi_hangup(struct tty_struct *tty)
53881 tty_port_tty_set(&hp->port, NULL);
53882
53883 spin_lock_irqsave(&hp->lock, flags);
53884 - hp->port.count = 0;
53885 + atomic_set(&hp->port.count, 0);
53886 hp->n_outbuf = 0;
53887 spin_unlock_irqrestore(&hp->lock, flags);
53888 }
53889 diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
53890 index 7ae6c29..05c6dba 100644
53891 --- a/drivers/tty/hvc/hvsi_lib.c
53892 +++ b/drivers/tty/hvc/hvsi_lib.c
53893 @@ -8,7 +8,7 @@
53894
53895 static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
53896 {
53897 - packet->seqno = cpu_to_be16(atomic_inc_return(&pv->seqno));
53898 + packet->seqno = cpu_to_be16(atomic_inc_return_unchecked(&pv->seqno));
53899
53900 /* Assumes that always succeeds, works in practice */
53901 return pv->put_chars(pv->termno, (char *)packet, packet->len);
53902 @@ -20,7 +20,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)
53903
53904 /* Reset state */
53905 pv->established = 0;
53906 - atomic_set(&pv->seqno, 0);
53907 + atomic_set_unchecked(&pv->seqno, 0);
53908
53909 pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
53910
53911 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
53912 index 345cebb..d5a1e9e 100644
53913 --- a/drivers/tty/ipwireless/tty.c
53914 +++ b/drivers/tty/ipwireless/tty.c
53915 @@ -28,6 +28,7 @@
53916 #include <linux/tty_driver.h>
53917 #include <linux/tty_flip.h>
53918 #include <linux/uaccess.h>
53919 +#include <asm/local.h>
53920
53921 #include "tty.h"
53922 #include "network.h"
53923 @@ -93,10 +94,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
53924 return -ENODEV;
53925
53926 mutex_lock(&tty->ipw_tty_mutex);
53927 - if (tty->port.count == 0)
53928 + if (atomic_read(&tty->port.count) == 0)
53929 tty->tx_bytes_queued = 0;
53930
53931 - tty->port.count++;
53932 + atomic_inc(&tty->port.count);
53933
53934 tty->port.tty = linux_tty;
53935 linux_tty->driver_data = tty;
53936 @@ -112,9 +113,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
53937
53938 static void do_ipw_close(struct ipw_tty *tty)
53939 {
53940 - tty->port.count--;
53941 -
53942 - if (tty->port.count == 0) {
53943 + if (atomic_dec_return(&tty->port.count) == 0) {
53944 struct tty_struct *linux_tty = tty->port.tty;
53945
53946 if (linux_tty != NULL) {
53947 @@ -135,7 +134,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
53948 return;
53949
53950 mutex_lock(&tty->ipw_tty_mutex);
53951 - if (tty->port.count == 0) {
53952 + if (atomic_read(&tty->port.count) == 0) {
53953 mutex_unlock(&tty->ipw_tty_mutex);
53954 return;
53955 }
53956 @@ -158,7 +157,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
53957
53958 mutex_lock(&tty->ipw_tty_mutex);
53959
53960 - if (!tty->port.count) {
53961 + if (!atomic_read(&tty->port.count)) {
53962 mutex_unlock(&tty->ipw_tty_mutex);
53963 return;
53964 }
53965 @@ -197,7 +196,7 @@ static int ipw_write(struct tty_struct *linux_tty,
53966 return -ENODEV;
53967
53968 mutex_lock(&tty->ipw_tty_mutex);
53969 - if (!tty->port.count) {
53970 + if (!atomic_read(&tty->port.count)) {
53971 mutex_unlock(&tty->ipw_tty_mutex);
53972 return -EINVAL;
53973 }
53974 @@ -237,7 +236,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
53975 if (!tty)
53976 return -ENODEV;
53977
53978 - if (!tty->port.count)
53979 + if (!atomic_read(&tty->port.count))
53980 return -EINVAL;
53981
53982 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
53983 @@ -279,7 +278,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
53984 if (!tty)
53985 return 0;
53986
53987 - if (!tty->port.count)
53988 + if (!atomic_read(&tty->port.count))
53989 return 0;
53990
53991 return tty->tx_bytes_queued;
53992 @@ -360,7 +359,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
53993 if (!tty)
53994 return -ENODEV;
53995
53996 - if (!tty->port.count)
53997 + if (!atomic_read(&tty->port.count))
53998 return -EINVAL;
53999
54000 return get_control_lines(tty);
54001 @@ -376,7 +375,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
54002 if (!tty)
54003 return -ENODEV;
54004
54005 - if (!tty->port.count)
54006 + if (!atomic_read(&tty->port.count))
54007 return -EINVAL;
54008
54009 return set_control_lines(tty, set, clear);
54010 @@ -390,7 +389,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
54011 if (!tty)
54012 return -ENODEV;
54013
54014 - if (!tty->port.count)
54015 + if (!atomic_read(&tty->port.count))
54016 return -EINVAL;
54017
54018 /* FIXME: Exactly how is the tty object locked here .. */
54019 @@ -546,7 +545,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
54020 * are gone */
54021 mutex_lock(&ttyj->ipw_tty_mutex);
54022 }
54023 - while (ttyj->port.count)
54024 + while (atomic_read(&ttyj->port.count))
54025 do_ipw_close(ttyj);
54026 ipwireless_disassociate_network_ttys(network,
54027 ttyj->channel_idx);
54028 diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
54029 index 1deaca4..c8582d4 100644
54030 --- a/drivers/tty/moxa.c
54031 +++ b/drivers/tty/moxa.c
54032 @@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
54033 }
54034
54035 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
54036 - ch->port.count++;
54037 + atomic_inc(&ch->port.count);
54038 tty->driver_data = ch;
54039 tty_port_tty_set(&ch->port, tty);
54040 mutex_lock(&ch->port.mutex);
54041 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
54042 index c434376..114ce13 100644
54043 --- a/drivers/tty/n_gsm.c
54044 +++ b/drivers/tty/n_gsm.c
54045 @@ -1644,7 +1644,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
54046 spin_lock_init(&dlci->lock);
54047 mutex_init(&dlci->mutex);
54048 dlci->fifo = &dlci->_fifo;
54049 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
54050 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
54051 kfree(dlci);
54052 return NULL;
54053 }
54054 @@ -2958,7 +2958,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
54055 struct gsm_dlci *dlci = tty->driver_data;
54056 struct tty_port *port = &dlci->port;
54057
54058 - port->count++;
54059 + atomic_inc(&port->count);
54060 tty_port_tty_set(port, tty);
54061
54062 dlci->modem_rx = 0;
54063 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
54064 index f44f1ba..a8d5915 100644
54065 --- a/drivers/tty/n_tty.c
54066 +++ b/drivers/tty/n_tty.c
54067 @@ -115,7 +115,7 @@ struct n_tty_data {
54068 int minimum_to_wake;
54069
54070 /* consumer-published */
54071 - size_t read_tail;
54072 + size_t read_tail __intentional_overflow(-1);
54073 size_t line_start;
54074
54075 /* protected by output lock */
54076 @@ -2517,6 +2517,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
54077 {
54078 *ops = tty_ldisc_N_TTY;
54079 ops->owner = NULL;
54080 - ops->refcount = ops->flags = 0;
54081 + atomic_set(&ops->refcount, 0);
54082 + ops->flags = 0;
54083 }
54084 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
54085 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
54086 index 9bbdb1d..dc514ee 100644
54087 --- a/drivers/tty/pty.c
54088 +++ b/drivers/tty/pty.c
54089 @@ -789,8 +789,10 @@ static void __init unix98_pty_init(void)
54090 panic("Couldn't register Unix98 pts driver");
54091
54092 /* Now create the /dev/ptmx special device */
54093 + pax_open_kernel();
54094 tty_default_fops(&ptmx_fops);
54095 - ptmx_fops.open = ptmx_open;
54096 + *(void **)&ptmx_fops.open = ptmx_open;
54097 + pax_close_kernel();
54098
54099 cdev_init(&ptmx_cdev, &ptmx_fops);
54100 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
54101 diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
54102 index 383c4c7..d408e21 100644
54103 --- a/drivers/tty/rocket.c
54104 +++ b/drivers/tty/rocket.c
54105 @@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
54106 tty->driver_data = info;
54107 tty_port_tty_set(port, tty);
54108
54109 - if (port->count++ == 0) {
54110 + if (atomic_inc_return(&port->count) == 1) {
54111 atomic_inc(&rp_num_ports_open);
54112
54113 #ifdef ROCKET_DEBUG_OPEN
54114 @@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
54115 #endif
54116 }
54117 #ifdef ROCKET_DEBUG_OPEN
54118 - printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
54119 + printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
54120 #endif
54121
54122 /*
54123 @@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
54124 spin_unlock_irqrestore(&info->port.lock, flags);
54125 return;
54126 }
54127 - if (info->port.count)
54128 + if (atomic_read(&info->port.count))
54129 atomic_dec(&rp_num_ports_open);
54130 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
54131 spin_unlock_irqrestore(&info->port.lock, flags);
54132 diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
54133 index aa28209..e08fb85 100644
54134 --- a/drivers/tty/serial/ioc4_serial.c
54135 +++ b/drivers/tty/serial/ioc4_serial.c
54136 @@ -437,7 +437,7 @@ struct ioc4_soft {
54137 } is_intr_info[MAX_IOC4_INTR_ENTS];
54138
54139 /* Number of entries active in the above array */
54140 - atomic_t is_num_intrs;
54141 + atomic_unchecked_t is_num_intrs;
54142 } is_intr_type[IOC4_NUM_INTR_TYPES];
54143
54144 /* is_ir_lock must be held while
54145 @@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
54146 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
54147 || (type == IOC4_OTHER_INTR_TYPE)));
54148
54149 - i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1;
54150 + i = atomic_inc_return_unchecked(&soft-> is_intr_type[type].is_num_intrs) - 1;
54151 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
54152
54153 /* Save off the lower level interrupt handler */
54154 @@ -1001,7 +1001,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
54155
54156 soft = arg;
54157 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
54158 - num_intrs = (int)atomic_read(
54159 + num_intrs = (int)atomic_read_unchecked(
54160 &soft->is_intr_type[intr_type].is_num_intrs);
54161
54162 this_mir = this_ir = pending_intrs(soft, intr_type);
54163 diff --git a/drivers/tty/serial/kgdb_nmi.c b/drivers/tty/serial/kgdb_nmi.c
54164 index 6ec7501..265bcbf 100644
54165 --- a/drivers/tty/serial/kgdb_nmi.c
54166 +++ b/drivers/tty/serial/kgdb_nmi.c
54167 @@ -51,7 +51,9 @@ static int kgdb_nmi_console_setup(struct console *co, char *options)
54168 * I/O utilities that messages sent to the console will automatically
54169 * be displayed on the dbg_io.
54170 */
54171 - dbg_io_ops->is_console = true;
54172 + pax_open_kernel();
54173 + *(int *)&dbg_io_ops->is_console = true;
54174 + pax_close_kernel();
54175
54176 return 0;
54177 }
54178 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
54179 index a260cde..6b2b5ce 100644
54180 --- a/drivers/tty/serial/kgdboc.c
54181 +++ b/drivers/tty/serial/kgdboc.c
54182 @@ -24,8 +24,9 @@
54183 #define MAX_CONFIG_LEN 40
54184
54185 static struct kgdb_io kgdboc_io_ops;
54186 +static struct kgdb_io kgdboc_io_ops_console;
54187
54188 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
54189 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
54190 static int configured = -1;
54191
54192 static char config[MAX_CONFIG_LEN];
54193 @@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
54194 kgdboc_unregister_kbd();
54195 if (configured == 1)
54196 kgdb_unregister_io_module(&kgdboc_io_ops);
54197 + else if (configured == 2)
54198 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
54199 }
54200
54201 static int configure_kgdboc(void)
54202 @@ -160,13 +163,13 @@ static int configure_kgdboc(void)
54203 int err;
54204 char *cptr = config;
54205 struct console *cons;
54206 + int is_console = 0;
54207
54208 err = kgdboc_option_setup(config);
54209 if (err || !strlen(config) || isspace(config[0]))
54210 goto noconfig;
54211
54212 err = -ENODEV;
54213 - kgdboc_io_ops.is_console = 0;
54214 kgdb_tty_driver = NULL;
54215
54216 kgdboc_use_kms = 0;
54217 @@ -187,7 +190,7 @@ static int configure_kgdboc(void)
54218 int idx;
54219 if (cons->device && cons->device(cons, &idx) == p &&
54220 idx == tty_line) {
54221 - kgdboc_io_ops.is_console = 1;
54222 + is_console = 1;
54223 break;
54224 }
54225 cons = cons->next;
54226 @@ -197,7 +200,13 @@ static int configure_kgdboc(void)
54227 kgdb_tty_line = tty_line;
54228
54229 do_register:
54230 - err = kgdb_register_io_module(&kgdboc_io_ops);
54231 + if (is_console) {
54232 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
54233 + configured = 2;
54234 + } else {
54235 + err = kgdb_register_io_module(&kgdboc_io_ops);
54236 + configured = 1;
54237 + }
54238 if (err)
54239 goto noconfig;
54240
54241 @@ -205,8 +214,6 @@ do_register:
54242 if (err)
54243 goto nmi_con_failed;
54244
54245 - configured = 1;
54246 -
54247 return 0;
54248
54249 nmi_con_failed:
54250 @@ -223,7 +230,7 @@ noconfig:
54251 static int __init init_kgdboc(void)
54252 {
54253 /* Already configured? */
54254 - if (configured == 1)
54255 + if (configured >= 1)
54256 return 0;
54257
54258 return configure_kgdboc();
54259 @@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
54260 if (config[len - 1] == '\n')
54261 config[len - 1] = '\0';
54262
54263 - if (configured == 1)
54264 + if (configured >= 1)
54265 cleanup_kgdboc();
54266
54267 /* Go and configure with the new params. */
54268 @@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
54269 .post_exception = kgdboc_post_exp_handler,
54270 };
54271
54272 +static struct kgdb_io kgdboc_io_ops_console = {
54273 + .name = "kgdboc",
54274 + .read_char = kgdboc_get_char,
54275 + .write_char = kgdboc_put_char,
54276 + .pre_exception = kgdboc_pre_exp_handler,
54277 + .post_exception = kgdboc_post_exp_handler,
54278 + .is_console = 1
54279 +};
54280 +
54281 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
54282 /* This is only available if kgdboc is a built in for early debugging */
54283 static int __init kgdboc_early_init(char *opt)
54284 diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
54285 index 077570a..12550a9 100644
54286 --- a/drivers/tty/serial/msm_serial.c
54287 +++ b/drivers/tty/serial/msm_serial.c
54288 @@ -981,7 +981,7 @@ static struct uart_driver msm_uart_driver = {
54289 .cons = MSM_CONSOLE,
54290 };
54291
54292 -static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
54293 +static atomic_unchecked_t msm_uart_next_id = ATOMIC_INIT(0);
54294
54295 static const struct of_device_id msm_uartdm_table[] = {
54296 { .compatible = "qcom,msm-uartdm-v1.1", .data = (void *)UARTDM_1P1 },
54297 @@ -1000,7 +1000,7 @@ static int msm_serial_probe(struct platform_device *pdev)
54298 int irq;
54299
54300 if (pdev->id == -1)
54301 - pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
54302 + pdev->id = atomic_inc_return_unchecked(&msm_uart_next_id) - 1;
54303
54304 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
54305 return -ENXIO;
54306 diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
54307 index c78f43a..22b1dab 100644
54308 --- a/drivers/tty/serial/samsung.c
54309 +++ b/drivers/tty/serial/samsung.c
54310 @@ -478,11 +478,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
54311 }
54312 }
54313
54314 +static int s3c64xx_serial_startup(struct uart_port *port);
54315 static int s3c24xx_serial_startup(struct uart_port *port)
54316 {
54317 struct s3c24xx_uart_port *ourport = to_ourport(port);
54318 int ret;
54319
54320 + /* Startup sequence is different for s3c64xx and higher SoC's */
54321 + if (s3c24xx_serial_has_interrupt_mask(port))
54322 + return s3c64xx_serial_startup(port);
54323 +
54324 dbg("s3c24xx_serial_startup: port=%p (%08llx,%p)\n",
54325 port, (unsigned long long)port->mapbase, port->membase);
54326
54327 @@ -1155,10 +1160,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
54328 /* setup info for port */
54329 port->dev = &platdev->dev;
54330
54331 - /* Startup sequence is different for s3c64xx and higher SoC's */
54332 - if (s3c24xx_serial_has_interrupt_mask(port))
54333 - s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
54334 -
54335 port->uartclk = 1;
54336
54337 if (cfg->uart_flags & UPF_CONS_FLOW) {
54338 diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
54339 index 0f03988..8a8038d 100644
54340 --- a/drivers/tty/serial/serial_core.c
54341 +++ b/drivers/tty/serial/serial_core.c
54342 @@ -1343,7 +1343,7 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
54343
54344 pr_debug("uart_close(%d) called\n", uport ? uport->line : -1);
54345
54346 - if (!port->count || tty_port_close_start(port, tty, filp) == 0)
54347 + if (!atomic_read(&port->count) || tty_port_close_start(port, tty, filp) == 0)
54348 return;
54349
54350 /*
54351 @@ -1470,7 +1470,7 @@ static void uart_hangup(struct tty_struct *tty)
54352 uart_flush_buffer(tty);
54353 uart_shutdown(tty, state);
54354 spin_lock_irqsave(&port->lock, flags);
54355 - port->count = 0;
54356 + atomic_set(&port->count, 0);
54357 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
54358 spin_unlock_irqrestore(&port->lock, flags);
54359 tty_port_tty_set(port, NULL);
54360 @@ -1568,7 +1568,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
54361 goto end;
54362 }
54363
54364 - port->count++;
54365 + atomic_inc(&port->count);
54366 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
54367 retval = -ENXIO;
54368 goto err_dec_count;
54369 @@ -1600,7 +1600,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
54370 end:
54371 return retval;
54372 err_dec_count:
54373 - port->count--;
54374 + atomic_inc(&port->count);
54375 mutex_unlock(&port->mutex);
54376 goto end;
54377 }
54378 diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
54379 index b799170..87dafd5 100644
54380 --- a/drivers/tty/synclink.c
54381 +++ b/drivers/tty/synclink.c
54382 @@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
54383
54384 if (debug_level >= DEBUG_LEVEL_INFO)
54385 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
54386 - __FILE__,__LINE__, info->device_name, info->port.count);
54387 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
54388
54389 if (tty_port_close_start(&info->port, tty, filp) == 0)
54390 goto cleanup;
54391 @@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
54392 cleanup:
54393 if (debug_level >= DEBUG_LEVEL_INFO)
54394 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
54395 - tty->driver->name, info->port.count);
54396 + tty->driver->name, atomic_read(&info->port.count));
54397
54398 } /* end of mgsl_close() */
54399
54400 @@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
54401
54402 mgsl_flush_buffer(tty);
54403 shutdown(info);
54404 -
54405 - info->port.count = 0;
54406 +
54407 + atomic_set(&info->port.count, 0);
54408 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
54409 info->port.tty = NULL;
54410
54411 @@ -3296,10 +3296,10 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
54412
54413 if (debug_level >= DEBUG_LEVEL_INFO)
54414 printk("%s(%d):block_til_ready before block on %s count=%d\n",
54415 - __FILE__,__LINE__, tty->driver->name, port->count );
54416 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
54417
54418 spin_lock_irqsave(&info->irq_spinlock, flags);
54419 - port->count--;
54420 + atomic_dec(&port->count);
54421 spin_unlock_irqrestore(&info->irq_spinlock, flags);
54422 port->blocked_open++;
54423
54424 @@ -3327,7 +3327,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
54425
54426 if (debug_level >= DEBUG_LEVEL_INFO)
54427 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
54428 - __FILE__,__LINE__, tty->driver->name, port->count );
54429 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
54430
54431 tty_unlock(tty);
54432 schedule();
54433 @@ -3339,12 +3339,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
54434
54435 /* FIXME: Racy on hangup during close wait */
54436 if (!tty_hung_up_p(filp))
54437 - port->count++;
54438 + atomic_inc(&port->count);
54439 port->blocked_open--;
54440
54441 if (debug_level >= DEBUG_LEVEL_INFO)
54442 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
54443 - __FILE__,__LINE__, tty->driver->name, port->count );
54444 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
54445
54446 if (!retval)
54447 port->flags |= ASYNC_NORMAL_ACTIVE;
54448 @@ -3396,7 +3396,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
54449
54450 if (debug_level >= DEBUG_LEVEL_INFO)
54451 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
54452 - __FILE__,__LINE__,tty->driver->name, info->port.count);
54453 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
54454
54455 /* If port is closing, signal caller to try again */
54456 if (info->port.flags & ASYNC_CLOSING){
54457 @@ -3415,10 +3415,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
54458 spin_unlock_irqrestore(&info->netlock, flags);
54459 goto cleanup;
54460 }
54461 - info->port.count++;
54462 + atomic_inc(&info->port.count);
54463 spin_unlock_irqrestore(&info->netlock, flags);
54464
54465 - if (info->port.count == 1) {
54466 + if (atomic_read(&info->port.count) == 1) {
54467 /* 1st open on this device, init hardware */
54468 retval = startup(info);
54469 if (retval < 0)
54470 @@ -3442,8 +3442,8 @@ cleanup:
54471 if (retval) {
54472 if (tty->count == 1)
54473 info->port.tty = NULL; /* tty layer will release tty struct */
54474 - if(info->port.count)
54475 - info->port.count--;
54476 + if (atomic_read(&info->port.count))
54477 + atomic_dec(&info->port.count);
54478 }
54479
54480 return retval;
54481 @@ -7661,7 +7661,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
54482 unsigned short new_crctype;
54483
54484 /* return error if TTY interface open */
54485 - if (info->port.count)
54486 + if (atomic_read(&info->port.count))
54487 return -EBUSY;
54488
54489 switch (encoding)
54490 @@ -7756,7 +7756,7 @@ static int hdlcdev_open(struct net_device *dev)
54491
54492 /* arbitrate between network and tty opens */
54493 spin_lock_irqsave(&info->netlock, flags);
54494 - if (info->port.count != 0 || info->netcount != 0) {
54495 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
54496 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
54497 spin_unlock_irqrestore(&info->netlock, flags);
54498 return -EBUSY;
54499 @@ -7842,7 +7842,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
54500 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
54501
54502 /* return error if TTY interface open */
54503 - if (info->port.count)
54504 + if (atomic_read(&info->port.count))
54505 return -EBUSY;
54506
54507 if (cmd != SIOCWANDEV)
54508 diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
54509 index 0e8c39b..e0cb171 100644
54510 --- a/drivers/tty/synclink_gt.c
54511 +++ b/drivers/tty/synclink_gt.c
54512 @@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
54513 tty->driver_data = info;
54514 info->port.tty = tty;
54515
54516 - DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
54517 + DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
54518
54519 /* If port is closing, signal caller to try again */
54520 if (info->port.flags & ASYNC_CLOSING){
54521 @@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
54522 mutex_unlock(&info->port.mutex);
54523 goto cleanup;
54524 }
54525 - info->port.count++;
54526 + atomic_inc(&info->port.count);
54527 spin_unlock_irqrestore(&info->netlock, flags);
54528
54529 - if (info->port.count == 1) {
54530 + if (atomic_read(&info->port.count) == 1) {
54531 /* 1st open on this device, init hardware */
54532 retval = startup(info);
54533 if (retval < 0) {
54534 @@ -715,8 +715,8 @@ cleanup:
54535 if (retval) {
54536 if (tty->count == 1)
54537 info->port.tty = NULL; /* tty layer will release tty struct */
54538 - if(info->port.count)
54539 - info->port.count--;
54540 + if(atomic_read(&info->port.count))
54541 + atomic_dec(&info->port.count);
54542 }
54543
54544 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
54545 @@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
54546
54547 if (sanity_check(info, tty->name, "close"))
54548 return;
54549 - DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
54550 + DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
54551
54552 if (tty_port_close_start(&info->port, tty, filp) == 0)
54553 goto cleanup;
54554 @@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
54555 tty_port_close_end(&info->port, tty);
54556 info->port.tty = NULL;
54557 cleanup:
54558 - DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
54559 + DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
54560 }
54561
54562 static void hangup(struct tty_struct *tty)
54563 @@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
54564 shutdown(info);
54565
54566 spin_lock_irqsave(&info->port.lock, flags);
54567 - info->port.count = 0;
54568 + atomic_set(&info->port.count, 0);
54569 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
54570 info->port.tty = NULL;
54571 spin_unlock_irqrestore(&info->port.lock, flags);
54572 @@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
54573 unsigned short new_crctype;
54574
54575 /* return error if TTY interface open */
54576 - if (info->port.count)
54577 + if (atomic_read(&info->port.count))
54578 return -EBUSY;
54579
54580 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
54581 @@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
54582
54583 /* arbitrate between network and tty opens */
54584 spin_lock_irqsave(&info->netlock, flags);
54585 - if (info->port.count != 0 || info->netcount != 0) {
54586 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
54587 DBGINFO(("%s hdlc_open busy\n", dev->name));
54588 spin_unlock_irqrestore(&info->netlock, flags);
54589 return -EBUSY;
54590 @@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
54591 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
54592
54593 /* return error if TTY interface open */
54594 - if (info->port.count)
54595 + if (atomic_read(&info->port.count))
54596 return -EBUSY;
54597
54598 if (cmd != SIOCWANDEV)
54599 @@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
54600 if (port == NULL)
54601 continue;
54602 spin_lock(&port->lock);
54603 - if ((port->port.count || port->netcount) &&
54604 + if ((atomic_read(&port->port.count) || port->netcount) &&
54605 port->pending_bh && !port->bh_running &&
54606 !port->bh_requested) {
54607 DBGISR(("%s bh queued\n", port->device_name));
54608 @@ -3299,7 +3299,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
54609 add_wait_queue(&port->open_wait, &wait);
54610
54611 spin_lock_irqsave(&info->lock, flags);
54612 - port->count--;
54613 + atomic_dec(&port->count);
54614 spin_unlock_irqrestore(&info->lock, flags);
54615 port->blocked_open++;
54616
54617 @@ -3335,7 +3335,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
54618 remove_wait_queue(&port->open_wait, &wait);
54619
54620 if (!tty_hung_up_p(filp))
54621 - port->count++;
54622 + atomic_inc(&port->count);
54623 port->blocked_open--;
54624
54625 if (!retval)
54626 diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
54627 index c3f9091..abe4601 100644
54628 --- a/drivers/tty/synclinkmp.c
54629 +++ b/drivers/tty/synclinkmp.c
54630 @@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
54631
54632 if (debug_level >= DEBUG_LEVEL_INFO)
54633 printk("%s(%d):%s open(), old ref count = %d\n",
54634 - __FILE__,__LINE__,tty->driver->name, info->port.count);
54635 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
54636
54637 /* If port is closing, signal caller to try again */
54638 if (info->port.flags & ASYNC_CLOSING){
54639 @@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
54640 spin_unlock_irqrestore(&info->netlock, flags);
54641 goto cleanup;
54642 }
54643 - info->port.count++;
54644 + atomic_inc(&info->port.count);
54645 spin_unlock_irqrestore(&info->netlock, flags);
54646
54647 - if (info->port.count == 1) {
54648 + if (atomic_read(&info->port.count) == 1) {
54649 /* 1st open on this device, init hardware */
54650 retval = startup(info);
54651 if (retval < 0)
54652 @@ -796,8 +796,8 @@ cleanup:
54653 if (retval) {
54654 if (tty->count == 1)
54655 info->port.tty = NULL; /* tty layer will release tty struct */
54656 - if(info->port.count)
54657 - info->port.count--;
54658 + if(atomic_read(&info->port.count))
54659 + atomic_dec(&info->port.count);
54660 }
54661
54662 return retval;
54663 @@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
54664
54665 if (debug_level >= DEBUG_LEVEL_INFO)
54666 printk("%s(%d):%s close() entry, count=%d\n",
54667 - __FILE__,__LINE__, info->device_name, info->port.count);
54668 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
54669
54670 if (tty_port_close_start(&info->port, tty, filp) == 0)
54671 goto cleanup;
54672 @@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
54673 cleanup:
54674 if (debug_level >= DEBUG_LEVEL_INFO)
54675 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
54676 - tty->driver->name, info->port.count);
54677 + tty->driver->name, atomic_read(&info->port.count));
54678 }
54679
54680 /* Called by tty_hangup() when a hangup is signaled.
54681 @@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
54682 shutdown(info);
54683
54684 spin_lock_irqsave(&info->port.lock, flags);
54685 - info->port.count = 0;
54686 + atomic_set(&info->port.count, 0);
54687 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
54688 info->port.tty = NULL;
54689 spin_unlock_irqrestore(&info->port.lock, flags);
54690 @@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
54691 unsigned short new_crctype;
54692
54693 /* return error if TTY interface open */
54694 - if (info->port.count)
54695 + if (atomic_read(&info->port.count))
54696 return -EBUSY;
54697
54698 switch (encoding)
54699 @@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
54700
54701 /* arbitrate between network and tty opens */
54702 spin_lock_irqsave(&info->netlock, flags);
54703 - if (info->port.count != 0 || info->netcount != 0) {
54704 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
54705 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
54706 spin_unlock_irqrestore(&info->netlock, flags);
54707 return -EBUSY;
54708 @@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
54709 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
54710
54711 /* return error if TTY interface open */
54712 - if (info->port.count)
54713 + if (atomic_read(&info->port.count))
54714 return -EBUSY;
54715
54716 if (cmd != SIOCWANDEV)
54717 @@ -2621,7 +2621,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
54718 * do not request bottom half processing if the
54719 * device is not open in a normal mode.
54720 */
54721 - if ( port && (port->port.count || port->netcount) &&
54722 + if ( port && (atomic_read(&port->port.count) || port->netcount) &&
54723 port->pending_bh && !port->bh_running &&
54724 !port->bh_requested ) {
54725 if ( debug_level >= DEBUG_LEVEL_ISR )
54726 @@ -3318,10 +3318,10 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
54727
54728 if (debug_level >= DEBUG_LEVEL_INFO)
54729 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
54730 - __FILE__,__LINE__, tty->driver->name, port->count );
54731 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
54732
54733 spin_lock_irqsave(&info->lock, flags);
54734 - port->count--;
54735 + atomic_dec(&port->count);
54736 spin_unlock_irqrestore(&info->lock, flags);
54737 port->blocked_open++;
54738
54739 @@ -3349,7 +3349,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
54740
54741 if (debug_level >= DEBUG_LEVEL_INFO)
54742 printk("%s(%d):%s block_til_ready() count=%d\n",
54743 - __FILE__,__LINE__, tty->driver->name, port->count );
54744 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
54745
54746 tty_unlock(tty);
54747 schedule();
54748 @@ -3359,12 +3359,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
54749 set_current_state(TASK_RUNNING);
54750 remove_wait_queue(&port->open_wait, &wait);
54751 if (!tty_hung_up_p(filp))
54752 - port->count++;
54753 + atomic_inc(&port->count);
54754 port->blocked_open--;
54755
54756 if (debug_level >= DEBUG_LEVEL_INFO)
54757 printk("%s(%d):%s block_til_ready() after, count=%d\n",
54758 - __FILE__,__LINE__, tty->driver->name, port->count );
54759 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
54760
54761 if (!retval)
54762 port->flags |= ASYNC_NORMAL_ACTIVE;
54763 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
54764 index 42bad18..447d7a2 100644
54765 --- a/drivers/tty/sysrq.c
54766 +++ b/drivers/tty/sysrq.c
54767 @@ -1084,7 +1084,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
54768 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
54769 size_t count, loff_t *ppos)
54770 {
54771 - if (count) {
54772 + if (count && capable(CAP_SYS_ADMIN)) {
54773 char c;
54774
54775 if (get_user(c, buf))
54776 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
54777 index 848c17a..e930437 100644
54778 --- a/drivers/tty/tty_io.c
54779 +++ b/drivers/tty/tty_io.c
54780 @@ -3469,7 +3469,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
54781
54782 void tty_default_fops(struct file_operations *fops)
54783 {
54784 - *fops = tty_fops;
54785 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
54786 }
54787
54788 /*
54789 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
54790 index 2d822aa..a566234 100644
54791 --- a/drivers/tty/tty_ldisc.c
54792 +++ b/drivers/tty/tty_ldisc.c
54793 @@ -71,7 +71,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
54794 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
54795 tty_ldiscs[disc] = new_ldisc;
54796 new_ldisc->num = disc;
54797 - new_ldisc->refcount = 0;
54798 + atomic_set(&new_ldisc->refcount, 0);
54799 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
54800
54801 return ret;
54802 @@ -99,7 +99,7 @@ int tty_unregister_ldisc(int disc)
54803 return -EINVAL;
54804
54805 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
54806 - if (tty_ldiscs[disc]->refcount)
54807 + if (atomic_read(&tty_ldiscs[disc]->refcount))
54808 ret = -EBUSY;
54809 else
54810 tty_ldiscs[disc] = NULL;
54811 @@ -120,7 +120,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
54812 if (ldops) {
54813 ret = ERR_PTR(-EAGAIN);
54814 if (try_module_get(ldops->owner)) {
54815 - ldops->refcount++;
54816 + atomic_inc(&ldops->refcount);
54817 ret = ldops;
54818 }
54819 }
54820 @@ -133,7 +133,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
54821 unsigned long flags;
54822
54823 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
54824 - ldops->refcount--;
54825 + atomic_dec(&ldops->refcount);
54826 module_put(ldops->owner);
54827 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
54828 }
54829 diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
54830 index 1b93357..ea9f82c 100644
54831 --- a/drivers/tty/tty_port.c
54832 +++ b/drivers/tty/tty_port.c
54833 @@ -237,7 +237,7 @@ void tty_port_hangup(struct tty_port *port)
54834 unsigned long flags;
54835
54836 spin_lock_irqsave(&port->lock, flags);
54837 - port->count = 0;
54838 + atomic_set(&port->count, 0);
54839 port->flags &= ~ASYNC_NORMAL_ACTIVE;
54840 tty = port->tty;
54841 if (tty)
54842 @@ -399,7 +399,7 @@ int tty_port_block_til_ready(struct tty_port *port,
54843
54844 /* The port lock protects the port counts */
54845 spin_lock_irqsave(&port->lock, flags);
54846 - port->count--;
54847 + atomic_dec(&port->count);
54848 port->blocked_open++;
54849 spin_unlock_irqrestore(&port->lock, flags);
54850
54851 @@ -441,7 +441,7 @@ int tty_port_block_til_ready(struct tty_port *port,
54852 we must not mess that up further */
54853 spin_lock_irqsave(&port->lock, flags);
54854 if (!tty_hung_up_p(filp))
54855 - port->count++;
54856 + atomic_inc(&port->count);
54857 port->blocked_open--;
54858 if (retval == 0)
54859 port->flags |= ASYNC_NORMAL_ACTIVE;
54860 @@ -479,19 +479,19 @@ int tty_port_close_start(struct tty_port *port,
54861 return 0;
54862 }
54863
54864 - if (tty->count == 1 && port->count != 1) {
54865 + if (tty->count == 1 && atomic_read(&port->count) != 1) {
54866 printk(KERN_WARNING
54867 "tty_port_close_start: tty->count = 1 port count = %d.\n",
54868 - port->count);
54869 - port->count = 1;
54870 + atomic_read(&port->count));
54871 + atomic_set(&port->count, 1);
54872 }
54873 - if (--port->count < 0) {
54874 + if (atomic_dec_return(&port->count) < 0) {
54875 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
54876 - port->count);
54877 - port->count = 0;
54878 + atomic_read(&port->count));
54879 + atomic_set(&port->count, 0);
54880 }
54881
54882 - if (port->count) {
54883 + if (atomic_read(&port->count)) {
54884 spin_unlock_irqrestore(&port->lock, flags);
54885 return 0;
54886 }
54887 @@ -592,7 +592,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
54888 struct file *filp)
54889 {
54890 spin_lock_irq(&port->lock);
54891 - ++port->count;
54892 + atomic_inc(&port->count);
54893 spin_unlock_irq(&port->lock);
54894 tty_port_tty_set(port, tty);
54895
54896 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
54897 index d0e3a44..5f8b754 100644
54898 --- a/drivers/tty/vt/keyboard.c
54899 +++ b/drivers/tty/vt/keyboard.c
54900 @@ -641,6 +641,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
54901 kbd->kbdmode == VC_OFF) &&
54902 value != KVAL(K_SAK))
54903 return; /* SAK is allowed even in raw mode */
54904 +
54905 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
54906 + {
54907 + void *func = fn_handler[value];
54908 + if (func == fn_show_state || func == fn_show_ptregs ||
54909 + func == fn_show_mem)
54910 + return;
54911 + }
54912 +#endif
54913 +
54914 fn_handler[value](vc);
54915 }
54916
54917 @@ -1776,9 +1786,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
54918 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
54919 return -EFAULT;
54920
54921 - if (!capable(CAP_SYS_TTY_CONFIG))
54922 - perm = 0;
54923 -
54924 switch (cmd) {
54925 case KDGKBENT:
54926 /* Ensure another thread doesn't free it under us */
54927 @@ -1793,6 +1800,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
54928 spin_unlock_irqrestore(&kbd_event_lock, flags);
54929 return put_user(val, &user_kbe->kb_value);
54930 case KDSKBENT:
54931 + if (!capable(CAP_SYS_TTY_CONFIG))
54932 + perm = 0;
54933 +
54934 if (!perm)
54935 return -EPERM;
54936 if (!i && v == K_NOSUCHMAP) {
54937 @@ -1883,9 +1893,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
54938 int i, j, k;
54939 int ret;
54940
54941 - if (!capable(CAP_SYS_TTY_CONFIG))
54942 - perm = 0;
54943 -
54944 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
54945 if (!kbs) {
54946 ret = -ENOMEM;
54947 @@ -1919,6 +1926,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
54948 kfree(kbs);
54949 return ((p && *p) ? -EOVERFLOW : 0);
54950 case KDSKBSENT:
54951 + if (!capable(CAP_SYS_TTY_CONFIG))
54952 + perm = 0;
54953 +
54954 if (!perm) {
54955 ret = -EPERM;
54956 goto reterr;
54957 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
54958 index a673e5b..36e5d32 100644
54959 --- a/drivers/uio/uio.c
54960 +++ b/drivers/uio/uio.c
54961 @@ -25,6 +25,7 @@
54962 #include <linux/kobject.h>
54963 #include <linux/cdev.h>
54964 #include <linux/uio_driver.h>
54965 +#include <asm/local.h>
54966
54967 #define UIO_MAX_DEVICES (1U << MINORBITS)
54968
54969 @@ -32,7 +33,7 @@ struct uio_device {
54970 struct module *owner;
54971 struct device *dev;
54972 int minor;
54973 - atomic_t event;
54974 + atomic_unchecked_t event;
54975 struct fasync_struct *async_queue;
54976 wait_queue_head_t wait;
54977 struct uio_info *info;
54978 @@ -243,7 +244,7 @@ static ssize_t event_show(struct device *dev,
54979 struct device_attribute *attr, char *buf)
54980 {
54981 struct uio_device *idev = dev_get_drvdata(dev);
54982 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
54983 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
54984 }
54985 static DEVICE_ATTR_RO(event);
54986
54987 @@ -405,7 +406,7 @@ void uio_event_notify(struct uio_info *info)
54988 {
54989 struct uio_device *idev = info->uio_dev;
54990
54991 - atomic_inc(&idev->event);
54992 + atomic_inc_unchecked(&idev->event);
54993 wake_up_interruptible(&idev->wait);
54994 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
54995 }
54996 @@ -458,7 +459,7 @@ static int uio_open(struct inode *inode, struct file *filep)
54997 }
54998
54999 listener->dev = idev;
55000 - listener->event_count = atomic_read(&idev->event);
55001 + listener->event_count = atomic_read_unchecked(&idev->event);
55002 filep->private_data = listener;
55003
55004 if (idev->info->open) {
55005 @@ -509,7 +510,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
55006 return -EIO;
55007
55008 poll_wait(filep, &idev->wait, wait);
55009 - if (listener->event_count != atomic_read(&idev->event))
55010 + if (listener->event_count != atomic_read_unchecked(&idev->event))
55011 return POLLIN | POLLRDNORM;
55012 return 0;
55013 }
55014 @@ -534,7 +535,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
55015 do {
55016 set_current_state(TASK_INTERRUPTIBLE);
55017
55018 - event_count = atomic_read(&idev->event);
55019 + event_count = atomic_read_unchecked(&idev->event);
55020 if (event_count != listener->event_count) {
55021 if (copy_to_user(buf, &event_count, count))
55022 retval = -EFAULT;
55023 @@ -591,9 +592,13 @@ static ssize_t uio_write(struct file *filep, const char __user *buf,
55024 static int uio_find_mem_index(struct vm_area_struct *vma)
55025 {
55026 struct uio_device *idev = vma->vm_private_data;
55027 + unsigned long size;
55028
55029 if (vma->vm_pgoff < MAX_UIO_MAPS) {
55030 - if (idev->info->mem[vma->vm_pgoff].size == 0)
55031 + size = idev->info->mem[vma->vm_pgoff].size;
55032 + if (size == 0)
55033 + return -1;
55034 + if (vma->vm_end - vma->vm_start > size)
55035 return -1;
55036 return (int)vma->vm_pgoff;
55037 }
55038 @@ -825,7 +830,7 @@ int __uio_register_device(struct module *owner,
55039 idev->owner = owner;
55040 idev->info = info;
55041 init_waitqueue_head(&idev->wait);
55042 - atomic_set(&idev->event, 0);
55043 + atomic_set_unchecked(&idev->event, 0);
55044
55045 ret = uio_get_minor(idev);
55046 if (ret)
55047 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
55048 index 813d4d3..a71934f 100644
55049 --- a/drivers/usb/atm/cxacru.c
55050 +++ b/drivers/usb/atm/cxacru.c
55051 @@ -472,7 +472,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
55052 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
55053 if (ret < 2)
55054 return -EINVAL;
55055 - if (index < 0 || index > 0x7f)
55056 + if (index > 0x7f)
55057 return -EINVAL;
55058 pos += tmp;
55059
55060 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
55061 index dada014..1d0d517 100644
55062 --- a/drivers/usb/atm/usbatm.c
55063 +++ b/drivers/usb/atm/usbatm.c
55064 @@ -331,7 +331,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
55065 if (printk_ratelimit())
55066 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
55067 __func__, vpi, vci);
55068 - atomic_inc(&vcc->stats->rx_err);
55069 + atomic_inc_unchecked(&vcc->stats->rx_err);
55070 return;
55071 }
55072
55073 @@ -358,7 +358,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
55074 if (length > ATM_MAX_AAL5_PDU) {
55075 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
55076 __func__, length, vcc);
55077 - atomic_inc(&vcc->stats->rx_err);
55078 + atomic_inc_unchecked(&vcc->stats->rx_err);
55079 goto out;
55080 }
55081
55082 @@ -367,14 +367,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
55083 if (sarb->len < pdu_length) {
55084 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
55085 __func__, pdu_length, sarb->len, vcc);
55086 - atomic_inc(&vcc->stats->rx_err);
55087 + atomic_inc_unchecked(&vcc->stats->rx_err);
55088 goto out;
55089 }
55090
55091 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
55092 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
55093 __func__, vcc);
55094 - atomic_inc(&vcc->stats->rx_err);
55095 + atomic_inc_unchecked(&vcc->stats->rx_err);
55096 goto out;
55097 }
55098
55099 @@ -386,7 +386,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
55100 if (printk_ratelimit())
55101 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
55102 __func__, length);
55103 - atomic_inc(&vcc->stats->rx_drop);
55104 + atomic_inc_unchecked(&vcc->stats->rx_drop);
55105 goto out;
55106 }
55107
55108 @@ -414,7 +414,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
55109
55110 vcc->push(vcc, skb);
55111
55112 - atomic_inc(&vcc->stats->rx);
55113 + atomic_inc_unchecked(&vcc->stats->rx);
55114 out:
55115 skb_trim(sarb, 0);
55116 }
55117 @@ -612,7 +612,7 @@ static void usbatm_tx_process(unsigned long data)
55118 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
55119
55120 usbatm_pop(vcc, skb);
55121 - atomic_inc(&vcc->stats->tx);
55122 + atomic_inc_unchecked(&vcc->stats->tx);
55123
55124 skb = skb_dequeue(&instance->sndqueue);
55125 }
55126 @@ -756,11 +756,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t *pos, char *page
55127 if (!left--)
55128 return sprintf(page,
55129 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
55130 - atomic_read(&atm_dev->stats.aal5.tx),
55131 - atomic_read(&atm_dev->stats.aal5.tx_err),
55132 - atomic_read(&atm_dev->stats.aal5.rx),
55133 - atomic_read(&atm_dev->stats.aal5.rx_err),
55134 - atomic_read(&atm_dev->stats.aal5.rx_drop));
55135 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
55136 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
55137 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
55138 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
55139 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
55140
55141 if (!left--) {
55142 if (instance->disconnected)
55143 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
55144 index 2a3bbdf..91d72cf 100644
55145 --- a/drivers/usb/core/devices.c
55146 +++ b/drivers/usb/core/devices.c
55147 @@ -126,7 +126,7 @@ static const char format_endpt[] =
55148 * time it gets called.
55149 */
55150 static struct device_connect_event {
55151 - atomic_t count;
55152 + atomic_unchecked_t count;
55153 wait_queue_head_t wait;
55154 } device_event = {
55155 .count = ATOMIC_INIT(1),
55156 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
55157
55158 void usbfs_conn_disc_event(void)
55159 {
55160 - atomic_add(2, &device_event.count);
55161 + atomic_add_unchecked(2, &device_event.count);
55162 wake_up(&device_event.wait);
55163 }
55164
55165 @@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
55166
55167 poll_wait(file, &device_event.wait, wait);
55168
55169 - event_count = atomic_read(&device_event.count);
55170 + event_count = atomic_read_unchecked(&device_event.count);
55171 if (file->f_version != event_count) {
55172 file->f_version = event_count;
55173 return POLLIN | POLLRDNORM;
55174 diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
55175 index 0b59731..46ee7d1 100644
55176 --- a/drivers/usb/core/devio.c
55177 +++ b/drivers/usb/core/devio.c
55178 @@ -187,7 +187,7 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
55179 struct usb_dev_state *ps = file->private_data;
55180 struct usb_device *dev = ps->dev;
55181 ssize_t ret = 0;
55182 - unsigned len;
55183 + size_t len;
55184 loff_t pos;
55185 int i;
55186
55187 @@ -229,22 +229,22 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
55188 for (i = 0; nbytes && i < dev->descriptor.bNumConfigurations; i++) {
55189 struct usb_config_descriptor *config =
55190 (struct usb_config_descriptor *)dev->rawdescriptors[i];
55191 - unsigned int length = le16_to_cpu(config->wTotalLength);
55192 + size_t length = le16_to_cpu(config->wTotalLength);
55193
55194 if (*ppos < pos + length) {
55195
55196 /* The descriptor may claim to be longer than it
55197 * really is. Here is the actual allocated length. */
55198 - unsigned alloclen =
55199 + size_t alloclen =
55200 le16_to_cpu(dev->config[i].desc.wTotalLength);
55201
55202 - len = length - (*ppos - pos);
55203 + len = length + pos - *ppos;
55204 if (len > nbytes)
55205 len = nbytes;
55206
55207 /* Simply don't write (skip over) unallocated parts */
55208 if (alloclen > (*ppos - pos)) {
55209 - alloclen -= (*ppos - pos);
55210 + alloclen = alloclen + pos - *ppos;
55211 if (copy_to_user(buf,
55212 dev->rawdescriptors[i] + (*ppos - pos),
55213 min(len, alloclen))) {
55214 diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
55215 index 258e6fe..9ea48d7 100644
55216 --- a/drivers/usb/core/hcd.c
55217 +++ b/drivers/usb/core/hcd.c
55218 @@ -1550,7 +1550,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
55219 */
55220 usb_get_urb(urb);
55221 atomic_inc(&urb->use_count);
55222 - atomic_inc(&urb->dev->urbnum);
55223 + atomic_inc_unchecked(&urb->dev->urbnum);
55224 usbmon_urb_submit(&hcd->self, urb);
55225
55226 /* NOTE requirements on root-hub callers (usbfs and the hub
55227 @@ -1577,7 +1577,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
55228 urb->hcpriv = NULL;
55229 INIT_LIST_HEAD(&urb->urb_list);
55230 atomic_dec(&urb->use_count);
55231 - atomic_dec(&urb->dev->urbnum);
55232 + atomic_dec_unchecked(&urb->dev->urbnum);
55233 if (atomic_read(&urb->reject))
55234 wake_up(&usb_kill_urb_queue);
55235 usb_put_urb(urb);
55236 diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
55237 index 674c262..71fdd90 100644
55238 --- a/drivers/usb/core/hub.c
55239 +++ b/drivers/usb/core/hub.c
55240 @@ -27,6 +27,7 @@
55241 #include <linux/freezer.h>
55242 #include <linux/random.h>
55243 #include <linux/pm_qos.h>
55244 +#include <linux/grsecurity.h>
55245
55246 #include <asm/uaccess.h>
55247 #include <asm/byteorder.h>
55248 @@ -4665,6 +4666,10 @@ static void hub_port_connect(struct usb_hub *hub, int port1, u16 portstatus,
55249 goto done;
55250 return;
55251 }
55252 +
55253 + if (gr_handle_new_usb())
55254 + goto done;
55255 +
55256 if (hub_is_superspeed(hub->hdev))
55257 unit_load = 150;
55258 else
55259 diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
55260 index 0c8a7fc..c45b40a 100644
55261 --- a/drivers/usb/core/message.c
55262 +++ b/drivers/usb/core/message.c
55263 @@ -128,7 +128,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
55264 * Return: If successful, the number of bytes transferred. Otherwise, a negative
55265 * error number.
55266 */
55267 -int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
55268 +int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
55269 __u8 requesttype, __u16 value, __u16 index, void *data,
55270 __u16 size, int timeout)
55271 {
55272 @@ -180,7 +180,7 @@ EXPORT_SYMBOL_GPL(usb_control_msg);
55273 * If successful, 0. Otherwise a negative error number. The number of actual
55274 * bytes transferred will be stored in the @actual_length parameter.
55275 */
55276 -int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
55277 +int __intentional_overflow(-1) usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
55278 void *data, int len, int *actual_length, int timeout)
55279 {
55280 return usb_bulk_msg(usb_dev, pipe, data, len, actual_length, timeout);
55281 @@ -220,7 +220,7 @@ EXPORT_SYMBOL_GPL(usb_interrupt_msg);
55282 * bytes transferred will be stored in the @actual_length parameter.
55283 *
55284 */
55285 -int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
55286 +int __intentional_overflow(-1) usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
55287 void *data, int len, int *actual_length, int timeout)
55288 {
55289 struct urb *urb;
55290 diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
55291 index 1236c60..d47a51c 100644
55292 --- a/drivers/usb/core/sysfs.c
55293 +++ b/drivers/usb/core/sysfs.c
55294 @@ -244,7 +244,7 @@ static ssize_t urbnum_show(struct device *dev, struct device_attribute *attr,
55295 struct usb_device *udev;
55296
55297 udev = to_usb_device(dev);
55298 - return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
55299 + return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
55300 }
55301 static DEVICE_ATTR_RO(urbnum);
55302
55303 diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
55304 index 2dd2362..1135437 100644
55305 --- a/drivers/usb/core/usb.c
55306 +++ b/drivers/usb/core/usb.c
55307 @@ -433,7 +433,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
55308 set_dev_node(&dev->dev, dev_to_node(bus->controller));
55309 dev->state = USB_STATE_ATTACHED;
55310 dev->lpm_disable_count = 1;
55311 - atomic_set(&dev->urbnum, 0);
55312 + atomic_set_unchecked(&dev->urbnum, 0);
55313
55314 INIT_LIST_HEAD(&dev->ep0.urb_list);
55315 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
55316 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
55317 index 8cfc319..4868255 100644
55318 --- a/drivers/usb/early/ehci-dbgp.c
55319 +++ b/drivers/usb/early/ehci-dbgp.c
55320 @@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
55321
55322 #ifdef CONFIG_KGDB
55323 static struct kgdb_io kgdbdbgp_io_ops;
55324 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
55325 +static struct kgdb_io kgdbdbgp_io_ops_console;
55326 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
55327 #else
55328 #define dbgp_kgdb_mode (0)
55329 #endif
55330 @@ -1043,6 +1044,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
55331 .write_char = kgdbdbgp_write_char,
55332 };
55333
55334 +static struct kgdb_io kgdbdbgp_io_ops_console = {
55335 + .name = "kgdbdbgp",
55336 + .read_char = kgdbdbgp_read_char,
55337 + .write_char = kgdbdbgp_write_char,
55338 + .is_console = 1
55339 +};
55340 +
55341 static int kgdbdbgp_wait_time;
55342
55343 static int __init kgdbdbgp_parse_config(char *str)
55344 @@ -1058,8 +1066,10 @@ static int __init kgdbdbgp_parse_config(char *str)
55345 ptr++;
55346 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
55347 }
55348 - kgdb_register_io_module(&kgdbdbgp_io_ops);
55349 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
55350 + if (early_dbgp_console.index != -1)
55351 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
55352 + else
55353 + kgdb_register_io_module(&kgdbdbgp_io_ops);
55354
55355 return 0;
55356 }
55357 diff --git a/drivers/usb/gadget/function/f_uac1.c b/drivers/usb/gadget/function/f_uac1.c
55358 index 2b4c82d..06a8ee6 100644
55359 --- a/drivers/usb/gadget/function/f_uac1.c
55360 +++ b/drivers/usb/gadget/function/f_uac1.c
55361 @@ -13,6 +13,7 @@
55362 #include <linux/kernel.h>
55363 #include <linux/device.h>
55364 #include <linux/atomic.h>
55365 +#include <linux/module.h>
55366
55367 #include "u_uac1.h"
55368
55369 diff --git a/drivers/usb/gadget/function/u_serial.c b/drivers/usb/gadget/function/u_serial.c
55370 index ad0aca8..8ff84865 100644
55371 --- a/drivers/usb/gadget/function/u_serial.c
55372 +++ b/drivers/usb/gadget/function/u_serial.c
55373 @@ -733,9 +733,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
55374 spin_lock_irq(&port->port_lock);
55375
55376 /* already open? Great. */
55377 - if (port->port.count) {
55378 + if (atomic_read(&port->port.count)) {
55379 status = 0;
55380 - port->port.count++;
55381 + atomic_inc(&port->port.count);
55382
55383 /* currently opening/closing? wait ... */
55384 } else if (port->openclose) {
55385 @@ -794,7 +794,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
55386 tty->driver_data = port;
55387 port->port.tty = tty;
55388
55389 - port->port.count = 1;
55390 + atomic_set(&port->port.count, 1);
55391 port->openclose = false;
55392
55393 /* if connected, start the I/O stream */
55394 @@ -836,11 +836,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
55395
55396 spin_lock_irq(&port->port_lock);
55397
55398 - if (port->port.count != 1) {
55399 - if (port->port.count == 0)
55400 + if (atomic_read(&port->port.count) != 1) {
55401 + if (atomic_read(&port->port.count) == 0)
55402 WARN_ON(1);
55403 else
55404 - --port->port.count;
55405 + atomic_dec(&port->port.count);
55406 goto exit;
55407 }
55408
55409 @@ -850,7 +850,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
55410 * and sleep if necessary
55411 */
55412 port->openclose = true;
55413 - port->port.count = 0;
55414 + atomic_set(&port->port.count, 0);
55415
55416 gser = port->port_usb;
55417 if (gser && gser->disconnect)
55418 @@ -1066,7 +1066,7 @@ static int gs_closed(struct gs_port *port)
55419 int cond;
55420
55421 spin_lock_irq(&port->port_lock);
55422 - cond = (port->port.count == 0) && !port->openclose;
55423 + cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
55424 spin_unlock_irq(&port->port_lock);
55425 return cond;
55426 }
55427 @@ -1209,7 +1209,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
55428 /* if it's already open, start I/O ... and notify the serial
55429 * protocol about open/close status (connect/disconnect).
55430 */
55431 - if (port->port.count) {
55432 + if (atomic_read(&port->port.count)) {
55433 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
55434 gs_start_io(port);
55435 if (gser->connect)
55436 @@ -1256,7 +1256,7 @@ void gserial_disconnect(struct gserial *gser)
55437
55438 port->port_usb = NULL;
55439 gser->ioport = NULL;
55440 - if (port->port.count > 0 || port->openclose) {
55441 + if (atomic_read(&port->port.count) > 0 || port->openclose) {
55442 wake_up_interruptible(&port->drain_wait);
55443 if (port->port.tty)
55444 tty_hangup(port->port.tty);
55445 @@ -1272,7 +1272,7 @@ void gserial_disconnect(struct gserial *gser)
55446
55447 /* finally, free any unused/unusable I/O buffers */
55448 spin_lock_irqsave(&port->port_lock, flags);
55449 - if (port->port.count == 0 && !port->openclose)
55450 + if (atomic_read(&port->port.count) == 0 && !port->openclose)
55451 gs_buf_free(&port->port_write_buf);
55452 gs_free_requests(gser->out, &port->read_pool, NULL);
55453 gs_free_requests(gser->out, &port->read_queue, NULL);
55454 diff --git a/drivers/usb/gadget/function/u_uac1.c b/drivers/usb/gadget/function/u_uac1.c
55455 index 7a55fea..cc0ed4f 100644
55456 --- a/drivers/usb/gadget/function/u_uac1.c
55457 +++ b/drivers/usb/gadget/function/u_uac1.c
55458 @@ -16,6 +16,7 @@
55459 #include <linux/ctype.h>
55460 #include <linux/random.h>
55461 #include <linux/syscalls.h>
55462 +#include <linux/module.h>
55463
55464 #include "u_uac1.h"
55465
55466 diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
55467 index 6130b75..3b60008 100644
55468 --- a/drivers/usb/host/ehci-hub.c
55469 +++ b/drivers/usb/host/ehci-hub.c
55470 @@ -771,7 +771,7 @@ static struct urb *request_single_step_set_feature_urb(
55471 urb->transfer_flags = URB_DIR_IN;
55472 usb_get_urb(urb);
55473 atomic_inc(&urb->use_count);
55474 - atomic_inc(&urb->dev->urbnum);
55475 + atomic_inc_unchecked(&urb->dev->urbnum);
55476 urb->setup_dma = dma_map_single(
55477 hcd->self.controller,
55478 urb->setup_packet,
55479 @@ -838,7 +838,7 @@ static int ehset_single_step_set_feature(struct usb_hcd *hcd, int port)
55480 urb->status = -EINPROGRESS;
55481 usb_get_urb(urb);
55482 atomic_inc(&urb->use_count);
55483 - atomic_inc(&urb->dev->urbnum);
55484 + atomic_inc_unchecked(&urb->dev->urbnum);
55485 retval = submit_single_step_set_feature(hcd, urb, 0);
55486 if (!retval && !wait_for_completion_timeout(&done,
55487 msecs_to_jiffies(2000))) {
55488 diff --git a/drivers/usb/host/hwa-hc.c b/drivers/usb/host/hwa-hc.c
55489 index d0d8fad..668ef7b 100644
55490 --- a/drivers/usb/host/hwa-hc.c
55491 +++ b/drivers/usb/host/hwa-hc.c
55492 @@ -337,7 +337,10 @@ static int __hwahc_op_bwa_set(struct wusbhc *wusbhc, s8 stream_index,
55493 struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc);
55494 struct wahc *wa = &hwahc->wa;
55495 struct device *dev = &wa->usb_iface->dev;
55496 - u8 mas_le[UWB_NUM_MAS/8];
55497 + u8 *mas_le = kmalloc(UWB_NUM_MAS/8, GFP_KERNEL);
55498 +
55499 + if (mas_le == NULL)
55500 + return -ENOMEM;
55501
55502 /* Set the stream index */
55503 result = usb_control_msg(wa->usb_dev, usb_sndctrlpipe(wa->usb_dev, 0),
55504 @@ -356,10 +359,12 @@ static int __hwahc_op_bwa_set(struct wusbhc *wusbhc, s8 stream_index,
55505 WUSB_REQ_SET_WUSB_MAS,
55506 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
55507 0, wa->usb_iface->cur_altsetting->desc.bInterfaceNumber,
55508 - mas_le, 32, USB_CTRL_SET_TIMEOUT);
55509 + mas_le, UWB_NUM_MAS/8, USB_CTRL_SET_TIMEOUT);
55510 if (result < 0)
55511 dev_err(dev, "Cannot set WUSB MAS allocation: %d\n", result);
55512 out:
55513 + kfree(mas_le);
55514 +
55515 return result;
55516 }
55517
55518 diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
55519 index b3d245e..99549ed 100644
55520 --- a/drivers/usb/misc/appledisplay.c
55521 +++ b/drivers/usb/misc/appledisplay.c
55522 @@ -84,7 +84,7 @@ struct appledisplay {
55523 struct mutex sysfslock; /* concurrent read and write */
55524 };
55525
55526 -static atomic_t count_displays = ATOMIC_INIT(0);
55527 +static atomic_unchecked_t count_displays = ATOMIC_INIT(0);
55528 static struct workqueue_struct *wq;
55529
55530 static void appledisplay_complete(struct urb *urb)
55531 @@ -288,7 +288,7 @@ static int appledisplay_probe(struct usb_interface *iface,
55532
55533 /* Register backlight device */
55534 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
55535 - atomic_inc_return(&count_displays) - 1);
55536 + atomic_inc_return_unchecked(&count_displays) - 1);
55537 memset(&props, 0, sizeof(struct backlight_properties));
55538 props.type = BACKLIGHT_RAW;
55539 props.max_brightness = 0xff;
55540 diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
55541 index 8d7fc48..01c4986 100644
55542 --- a/drivers/usb/serial/console.c
55543 +++ b/drivers/usb/serial/console.c
55544 @@ -123,7 +123,7 @@ static int usb_console_setup(struct console *co, char *options)
55545
55546 info->port = port;
55547
55548 - ++port->port.count;
55549 + atomic_inc(&port->port.count);
55550 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
55551 if (serial->type->set_termios) {
55552 /*
55553 @@ -167,7 +167,7 @@ static int usb_console_setup(struct console *co, char *options)
55554 }
55555 /* Now that any required fake tty operations are completed restore
55556 * the tty port count */
55557 - --port->port.count;
55558 + atomic_dec(&port->port.count);
55559 /* The console is special in terms of closing the device so
55560 * indicate this port is now acting as a system console. */
55561 port->port.console = 1;
55562 @@ -180,7 +180,7 @@ static int usb_console_setup(struct console *co, char *options)
55563 free_tty:
55564 kfree(tty);
55565 reset_open_count:
55566 - port->port.count = 0;
55567 + atomic_set(&port->port.count, 0);
55568 usb_autopm_put_interface(serial->interface);
55569 error_get_interface:
55570 usb_serial_put(serial);
55571 @@ -191,7 +191,7 @@ static int usb_console_setup(struct console *co, char *options)
55572 static void usb_console_write(struct console *co,
55573 const char *buf, unsigned count)
55574 {
55575 - static struct usbcons_info *info = &usbcons_info;
55576 + struct usbcons_info *info = &usbcons_info;
55577 struct usb_serial_port *port = info->port;
55578 struct usb_serial *serial;
55579 int retval = -ENODEV;
55580 diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
55581 index 307e339..6aa97cb 100644
55582 --- a/drivers/usb/storage/usb.h
55583 +++ b/drivers/usb/storage/usb.h
55584 @@ -63,7 +63,7 @@ struct us_unusual_dev {
55585 __u8 useProtocol;
55586 __u8 useTransport;
55587 int (*initFunction)(struct us_data *);
55588 -};
55589 +} __do_const;
55590
55591
55592 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
55593 diff --git a/drivers/usb/usbip/vhci.h b/drivers/usb/usbip/vhci.h
55594 index a863a98..d272795 100644
55595 --- a/drivers/usb/usbip/vhci.h
55596 +++ b/drivers/usb/usbip/vhci.h
55597 @@ -83,7 +83,7 @@ struct vhci_hcd {
55598 unsigned resuming:1;
55599 unsigned long re_timeout;
55600
55601 - atomic_t seqnum;
55602 + atomic_unchecked_t seqnum;
55603
55604 /*
55605 * NOTE:
55606 diff --git a/drivers/usb/usbip/vhci_hcd.c b/drivers/usb/usbip/vhci_hcd.c
55607 index c02374b..32d47a9 100644
55608 --- a/drivers/usb/usbip/vhci_hcd.c
55609 +++ b/drivers/usb/usbip/vhci_hcd.c
55610 @@ -439,7 +439,7 @@ static void vhci_tx_urb(struct urb *urb)
55611
55612 spin_lock(&vdev->priv_lock);
55613
55614 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
55615 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
55616 if (priv->seqnum == 0xffff)
55617 dev_info(&urb->dev->dev, "seqnum max\n");
55618
55619 @@ -686,7 +686,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
55620 return -ENOMEM;
55621 }
55622
55623 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
55624 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
55625 if (unlink->seqnum == 0xffff)
55626 pr_info("seqnum max\n");
55627
55628 @@ -891,7 +891,7 @@ static int vhci_start(struct usb_hcd *hcd)
55629 vdev->rhport = rhport;
55630 }
55631
55632 - atomic_set(&vhci->seqnum, 0);
55633 + atomic_set_unchecked(&vhci->seqnum, 0);
55634 spin_lock_init(&vhci->lock);
55635
55636 hcd->power_budget = 0; /* no limit */
55637 diff --git a/drivers/usb/usbip/vhci_rx.c b/drivers/usb/usbip/vhci_rx.c
55638 index 00e4a54..d676f85 100644
55639 --- a/drivers/usb/usbip/vhci_rx.c
55640 +++ b/drivers/usb/usbip/vhci_rx.c
55641 @@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
55642 if (!urb) {
55643 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
55644 pr_info("max seqnum %d\n",
55645 - atomic_read(&the_controller->seqnum));
55646 + atomic_read_unchecked(&the_controller->seqnum));
55647 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
55648 return;
55649 }
55650 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
55651 index f2a8d29..7bc3fe7 100644
55652 --- a/drivers/usb/wusbcore/wa-hc.h
55653 +++ b/drivers/usb/wusbcore/wa-hc.h
55654 @@ -240,7 +240,7 @@ struct wahc {
55655 spinlock_t xfer_list_lock;
55656 struct work_struct xfer_enqueue_work;
55657 struct work_struct xfer_error_work;
55658 - atomic_t xfer_id_count;
55659 + atomic_unchecked_t xfer_id_count;
55660
55661 kernel_ulong_t quirks;
55662 };
55663 @@ -305,7 +305,7 @@ static inline void wa_init(struct wahc *wa)
55664 INIT_WORK(&wa->xfer_enqueue_work, wa_urb_enqueue_run);
55665 INIT_WORK(&wa->xfer_error_work, wa_process_errored_transfers_run);
55666 wa->dto_in_use = 0;
55667 - atomic_set(&wa->xfer_id_count, 1);
55668 + atomic_set_unchecked(&wa->xfer_id_count, 1);
55669 /* init the buf in URBs */
55670 for (index = 0; index < WA_MAX_BUF_IN_URBS; ++index)
55671 usb_init_urb(&(wa->buf_in_urbs[index]));
55672 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
55673 index e279015..c2d0dae 100644
55674 --- a/drivers/usb/wusbcore/wa-xfer.c
55675 +++ b/drivers/usb/wusbcore/wa-xfer.c
55676 @@ -314,7 +314,7 @@ static void wa_xfer_completion(struct wa_xfer *xfer)
55677 */
55678 static void wa_xfer_id_init(struct wa_xfer *xfer)
55679 {
55680 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
55681 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
55682 }
55683
55684 /* Return the xfer's ID. */
55685 diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
55686 index f018d8d..ccab63f 100644
55687 --- a/drivers/vfio/vfio.c
55688 +++ b/drivers/vfio/vfio.c
55689 @@ -481,7 +481,7 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
55690 return 0;
55691
55692 /* TODO Prevent device auto probing */
55693 - WARN("Device %s added to live group %d!\n", dev_name(dev),
55694 + WARN(1, "Device %s added to live group %d!\n", dev_name(dev),
55695 iommu_group_id(group->iommu_group));
55696
55697 return 0;
55698 diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
55699 index 5174eba..451e6bc 100644
55700 --- a/drivers/vhost/vringh.c
55701 +++ b/drivers/vhost/vringh.c
55702 @@ -530,17 +530,17 @@ static inline void __vringh_notify_disable(struct vringh *vrh,
55703 /* Userspace access helpers: in this case, addresses are really userspace. */
55704 static inline int getu16_user(u16 *val, const u16 *p)
55705 {
55706 - return get_user(*val, (__force u16 __user *)p);
55707 + return get_user(*val, (u16 __force_user *)p);
55708 }
55709
55710 static inline int putu16_user(u16 *p, u16 val)
55711 {
55712 - return put_user(val, (__force u16 __user *)p);
55713 + return put_user(val, (u16 __force_user *)p);
55714 }
55715
55716 static inline int copydesc_user(void *dst, const void *src, size_t len)
55717 {
55718 - return copy_from_user(dst, (__force void __user *)src, len) ?
55719 + return copy_from_user(dst, (void __force_user *)src, len) ?
55720 -EFAULT : 0;
55721 }
55722
55723 @@ -548,19 +548,19 @@ static inline int putused_user(struct vring_used_elem *dst,
55724 const struct vring_used_elem *src,
55725 unsigned int num)
55726 {
55727 - return copy_to_user((__force void __user *)dst, src,
55728 + return copy_to_user((void __force_user *)dst, src,
55729 sizeof(*dst) * num) ? -EFAULT : 0;
55730 }
55731
55732 static inline int xfer_from_user(void *src, void *dst, size_t len)
55733 {
55734 - return copy_from_user(dst, (__force void __user *)src, len) ?
55735 + return copy_from_user(dst, (void __force_user *)src, len) ?
55736 -EFAULT : 0;
55737 }
55738
55739 static inline int xfer_to_user(void *dst, void *src, size_t len)
55740 {
55741 - return copy_to_user((__force void __user *)dst, src, len) ?
55742 + return copy_to_user((void __force_user *)dst, src, len) ?
55743 -EFAULT : 0;
55744 }
55745
55746 @@ -596,9 +596,9 @@ int vringh_init_user(struct vringh *vrh, u32 features,
55747 vrh->last_used_idx = 0;
55748 vrh->vring.num = num;
55749 /* vring expects kernel addresses, but only used via accessors. */
55750 - vrh->vring.desc = (__force struct vring_desc *)desc;
55751 - vrh->vring.avail = (__force struct vring_avail *)avail;
55752 - vrh->vring.used = (__force struct vring_used *)used;
55753 + vrh->vring.desc = (__force_kernel struct vring_desc *)desc;
55754 + vrh->vring.avail = (__force_kernel struct vring_avail *)avail;
55755 + vrh->vring.used = (__force_kernel struct vring_used *)used;
55756 return 0;
55757 }
55758 EXPORT_SYMBOL(vringh_init_user);
55759 @@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
55760
55761 static inline int putu16_kern(u16 *p, u16 val)
55762 {
55763 - ACCESS_ONCE(*p) = val;
55764 + ACCESS_ONCE_RW(*p) = val;
55765 return 0;
55766 }
55767
55768 diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
55769 index 84a110a..96312c3 100644
55770 --- a/drivers/video/backlight/kb3886_bl.c
55771 +++ b/drivers/video/backlight/kb3886_bl.c
55772 @@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
55773 static unsigned long kb3886bl_flags;
55774 #define KB3886BL_SUSPENDED 0x01
55775
55776 -static struct dmi_system_id kb3886bl_device_table[] __initdata = {
55777 +static const struct dmi_system_id kb3886bl_device_table[] __initconst = {
55778 {
55779 .ident = "Sahara Touch-iT",
55780 .matches = {
55781 diff --git a/drivers/video/fbdev/arcfb.c b/drivers/video/fbdev/arcfb.c
55782 index 1b0b233..6f34c2c 100644
55783 --- a/drivers/video/fbdev/arcfb.c
55784 +++ b/drivers/video/fbdev/arcfb.c
55785 @@ -458,7 +458,7 @@ static ssize_t arcfb_write(struct fb_info *info, const char __user *buf,
55786 return -ENOSPC;
55787
55788 err = 0;
55789 - if ((count + p) > fbmemlength) {
55790 + if (count > (fbmemlength - p)) {
55791 count = fbmemlength - p;
55792 err = -ENOSPC;
55793 }
55794 diff --git a/drivers/video/fbdev/aty/aty128fb.c b/drivers/video/fbdev/aty/aty128fb.c
55795 index ff60701..814b973 100644
55796 --- a/drivers/video/fbdev/aty/aty128fb.c
55797 +++ b/drivers/video/fbdev/aty/aty128fb.c
55798 @@ -149,7 +149,7 @@ enum {
55799 };
55800
55801 /* Must match above enum */
55802 -static char * const r128_family[] = {
55803 +static const char * const r128_family[] = {
55804 "AGP",
55805 "PCI",
55806 "PRO AGP",
55807 diff --git a/drivers/video/fbdev/aty/atyfb_base.c b/drivers/video/fbdev/aty/atyfb_base.c
55808 index 37ec09b..98f8862 100644
55809 --- a/drivers/video/fbdev/aty/atyfb_base.c
55810 +++ b/drivers/video/fbdev/aty/atyfb_base.c
55811 @@ -1326,10 +1326,14 @@ static int atyfb_set_par(struct fb_info *info)
55812 par->accel_flags = var->accel_flags; /* hack */
55813
55814 if (var->accel_flags) {
55815 - info->fbops->fb_sync = atyfb_sync;
55816 + pax_open_kernel();
55817 + *(void **)&info->fbops->fb_sync = atyfb_sync;
55818 + pax_close_kernel();
55819 info->flags &= ~FBINFO_HWACCEL_DISABLED;
55820 } else {
55821 - info->fbops->fb_sync = NULL;
55822 + pax_open_kernel();
55823 + *(void **)&info->fbops->fb_sync = NULL;
55824 + pax_close_kernel();
55825 info->flags |= FBINFO_HWACCEL_DISABLED;
55826 }
55827
55828 diff --git a/drivers/video/fbdev/aty/mach64_cursor.c b/drivers/video/fbdev/aty/mach64_cursor.c
55829 index 2fa0317..4983f2a 100644
55830 --- a/drivers/video/fbdev/aty/mach64_cursor.c
55831 +++ b/drivers/video/fbdev/aty/mach64_cursor.c
55832 @@ -8,6 +8,7 @@
55833 #include "../core/fb_draw.h"
55834
55835 #include <asm/io.h>
55836 +#include <asm/pgtable.h>
55837
55838 #ifdef __sparc__
55839 #include <asm/fbio.h>
55840 @@ -218,7 +219,9 @@ int aty_init_cursor(struct fb_info *info)
55841 info->sprite.buf_align = 16; /* and 64 lines tall. */
55842 info->sprite.flags = FB_PIXMAP_IO;
55843
55844 - info->fbops->fb_cursor = atyfb_cursor;
55845 + pax_open_kernel();
55846 + *(void **)&info->fbops->fb_cursor = atyfb_cursor;
55847 + pax_close_kernel();
55848
55849 return 0;
55850 }
55851 diff --git a/drivers/video/fbdev/core/fb_defio.c b/drivers/video/fbdev/core/fb_defio.c
55852 index 900aa4e..6d49418 100644
55853 --- a/drivers/video/fbdev/core/fb_defio.c
55854 +++ b/drivers/video/fbdev/core/fb_defio.c
55855 @@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
55856
55857 BUG_ON(!fbdefio);
55858 mutex_init(&fbdefio->lock);
55859 - info->fbops->fb_mmap = fb_deferred_io_mmap;
55860 + pax_open_kernel();
55861 + *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
55862 + pax_close_kernel();
55863 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
55864 INIT_LIST_HEAD(&fbdefio->pagelist);
55865 if (fbdefio->delay == 0) /* set a default of 1 s */
55866 @@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
55867 page->mapping = NULL;
55868 }
55869
55870 - info->fbops->fb_mmap = NULL;
55871 + *(void **)&info->fbops->fb_mmap = NULL;
55872 mutex_destroy(&fbdefio->lock);
55873 }
55874 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
55875 diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fbmem.c
55876 index b5e85f6..290f8c7 100644
55877 --- a/drivers/video/fbdev/core/fbmem.c
55878 +++ b/drivers/video/fbdev/core/fbmem.c
55879 @@ -1301,7 +1301,7 @@ static int do_fscreeninfo_to_user(struct fb_fix_screeninfo *fix,
55880 __u32 data;
55881 int err;
55882
55883 - err = copy_to_user(&fix32->id, &fix->id, sizeof(fix32->id));
55884 + err = copy_to_user(fix32->id, &fix->id, sizeof(fix32->id));
55885
55886 data = (__u32) (unsigned long) fix->smem_start;
55887 err |= put_user(data, &fix32->smem_start);
55888 diff --git a/drivers/video/fbdev/hyperv_fb.c b/drivers/video/fbdev/hyperv_fb.c
55889 index 4254336..282567e 100644
55890 --- a/drivers/video/fbdev/hyperv_fb.c
55891 +++ b/drivers/video/fbdev/hyperv_fb.c
55892 @@ -240,7 +240,7 @@ static uint screen_fb_size;
55893 static inline int synthvid_send(struct hv_device *hdev,
55894 struct synthvid_msg *msg)
55895 {
55896 - static atomic64_t request_id = ATOMIC64_INIT(0);
55897 + static atomic64_unchecked_t request_id = ATOMIC64_INIT(0);
55898 int ret;
55899
55900 msg->pipe_hdr.type = PIPE_MSG_DATA;
55901 @@ -248,7 +248,7 @@ static inline int synthvid_send(struct hv_device *hdev,
55902
55903 ret = vmbus_sendpacket(hdev->channel, msg,
55904 msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
55905 - atomic64_inc_return(&request_id),
55906 + atomic64_inc_return_unchecked(&request_id),
55907 VM_PKT_DATA_INBAND, 0);
55908
55909 if (ret)
55910 diff --git a/drivers/video/fbdev/i810/i810_accel.c b/drivers/video/fbdev/i810/i810_accel.c
55911 index 7672d2e..b56437f 100644
55912 --- a/drivers/video/fbdev/i810/i810_accel.c
55913 +++ b/drivers/video/fbdev/i810/i810_accel.c
55914 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
55915 }
55916 }
55917 printk("ringbuffer lockup!!!\n");
55918 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
55919 i810_report_error(mmio);
55920 par->dev_flags |= LOCKUP;
55921 info->pixmap.scan_align = 1;
55922 diff --git a/drivers/video/fbdev/matrox/matroxfb_DAC1064.c b/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
55923 index a01147f..5d896f8 100644
55924 --- a/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
55925 +++ b/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
55926 @@ -1088,14 +1088,20 @@ static void MGAG100_restore(struct matrox_fb_info *minfo)
55927
55928 #ifdef CONFIG_FB_MATROX_MYSTIQUE
55929 struct matrox_switch matrox_mystique = {
55930 - MGA1064_preinit, MGA1064_reset, MGA1064_init, MGA1064_restore,
55931 + .preinit = MGA1064_preinit,
55932 + .reset = MGA1064_reset,
55933 + .init = MGA1064_init,
55934 + .restore = MGA1064_restore,
55935 };
55936 EXPORT_SYMBOL(matrox_mystique);
55937 #endif
55938
55939 #ifdef CONFIG_FB_MATROX_G
55940 struct matrox_switch matrox_G100 = {
55941 - MGAG100_preinit, MGAG100_reset, MGAG100_init, MGAG100_restore,
55942 + .preinit = MGAG100_preinit,
55943 + .reset = MGAG100_reset,
55944 + .init = MGAG100_init,
55945 + .restore = MGAG100_restore,
55946 };
55947 EXPORT_SYMBOL(matrox_G100);
55948 #endif
55949 diff --git a/drivers/video/fbdev/matrox/matroxfb_Ti3026.c b/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
55950 index 195ad7c..09743fc 100644
55951 --- a/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
55952 +++ b/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
55953 @@ -738,7 +738,10 @@ static int Ti3026_preinit(struct matrox_fb_info *minfo)
55954 }
55955
55956 struct matrox_switch matrox_millennium = {
55957 - Ti3026_preinit, Ti3026_reset, Ti3026_init, Ti3026_restore
55958 + .preinit = Ti3026_preinit,
55959 + .reset = Ti3026_reset,
55960 + .init = Ti3026_init,
55961 + .restore = Ti3026_restore
55962 };
55963 EXPORT_SYMBOL(matrox_millennium);
55964 #endif
55965 diff --git a/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c b/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
55966 index fe92eed..106e085 100644
55967 --- a/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
55968 +++ b/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
55969 @@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
55970 struct mb862xxfb_par *par = info->par;
55971
55972 if (info->var.bits_per_pixel == 32) {
55973 - info->fbops->fb_fillrect = cfb_fillrect;
55974 - info->fbops->fb_copyarea = cfb_copyarea;
55975 - info->fbops->fb_imageblit = cfb_imageblit;
55976 + pax_open_kernel();
55977 + *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
55978 + *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
55979 + *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
55980 + pax_close_kernel();
55981 } else {
55982 outreg(disp, GC_L0EM, 3);
55983 - info->fbops->fb_fillrect = mb86290fb_fillrect;
55984 - info->fbops->fb_copyarea = mb86290fb_copyarea;
55985 - info->fbops->fb_imageblit = mb86290fb_imageblit;
55986 + pax_open_kernel();
55987 + *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
55988 + *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
55989 + *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
55990 + pax_close_kernel();
55991 }
55992 outreg(draw, GDC_REG_DRAW_BASE, 0);
55993 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
55994 diff --git a/drivers/video/fbdev/nvidia/nvidia.c b/drivers/video/fbdev/nvidia/nvidia.c
55995 index def0412..fed6529 100644
55996 --- a/drivers/video/fbdev/nvidia/nvidia.c
55997 +++ b/drivers/video/fbdev/nvidia/nvidia.c
55998 @@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
55999 info->fix.line_length = (info->var.xres_virtual *
56000 info->var.bits_per_pixel) >> 3;
56001 if (info->var.accel_flags) {
56002 - info->fbops->fb_imageblit = nvidiafb_imageblit;
56003 - info->fbops->fb_fillrect = nvidiafb_fillrect;
56004 - info->fbops->fb_copyarea = nvidiafb_copyarea;
56005 - info->fbops->fb_sync = nvidiafb_sync;
56006 + pax_open_kernel();
56007 + *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
56008 + *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
56009 + *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
56010 + *(void **)&info->fbops->fb_sync = nvidiafb_sync;
56011 + pax_close_kernel();
56012 info->pixmap.scan_align = 4;
56013 info->flags &= ~FBINFO_HWACCEL_DISABLED;
56014 info->flags |= FBINFO_READS_FAST;
56015 NVResetGraphics(info);
56016 } else {
56017 - info->fbops->fb_imageblit = cfb_imageblit;
56018 - info->fbops->fb_fillrect = cfb_fillrect;
56019 - info->fbops->fb_copyarea = cfb_copyarea;
56020 - info->fbops->fb_sync = NULL;
56021 + pax_open_kernel();
56022 + *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
56023 + *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
56024 + *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
56025 + *(void **)&info->fbops->fb_sync = NULL;
56026 + pax_close_kernel();
56027 info->pixmap.scan_align = 1;
56028 info->flags |= FBINFO_HWACCEL_DISABLED;
56029 info->flags &= ~FBINFO_READS_FAST;
56030 @@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
56031 info->pixmap.size = 8 * 1024;
56032 info->pixmap.flags = FB_PIXMAP_SYSTEM;
56033
56034 - if (!hwcur)
56035 - info->fbops->fb_cursor = NULL;
56036 + if (!hwcur) {
56037 + pax_open_kernel();
56038 + *(void **)&info->fbops->fb_cursor = NULL;
56039 + pax_close_kernel();
56040 + }
56041
56042 info->var.accel_flags = (!noaccel);
56043
56044 diff --git a/drivers/video/fbdev/omap2/dss/display.c b/drivers/video/fbdev/omap2/dss/display.c
56045 index 2412a0d..294215b 100644
56046 --- a/drivers/video/fbdev/omap2/dss/display.c
56047 +++ b/drivers/video/fbdev/omap2/dss/display.c
56048 @@ -161,12 +161,14 @@ int omapdss_register_display(struct omap_dss_device *dssdev)
56049 if (dssdev->name == NULL)
56050 dssdev->name = dssdev->alias;
56051
56052 + pax_open_kernel();
56053 if (drv && drv->get_resolution == NULL)
56054 - drv->get_resolution = omapdss_default_get_resolution;
56055 + *(void **)&drv->get_resolution = omapdss_default_get_resolution;
56056 if (drv && drv->get_recommended_bpp == NULL)
56057 - drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
56058 + *(void **)&drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
56059 if (drv && drv->get_timings == NULL)
56060 - drv->get_timings = omapdss_default_get_timings;
56061 + *(void **)&drv->get_timings = omapdss_default_get_timings;
56062 + pax_close_kernel();
56063
56064 mutex_lock(&panel_list_mutex);
56065 list_add_tail(&dssdev->panel_list, &panel_list);
56066 diff --git a/drivers/video/fbdev/s1d13xxxfb.c b/drivers/video/fbdev/s1d13xxxfb.c
56067 index 83433cb..71e9b98 100644
56068 --- a/drivers/video/fbdev/s1d13xxxfb.c
56069 +++ b/drivers/video/fbdev/s1d13xxxfb.c
56070 @@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
56071
56072 switch(prod_id) {
56073 case S1D13506_PROD_ID: /* activate acceleration */
56074 - s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
56075 - s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
56076 + pax_open_kernel();
56077 + *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
56078 + *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
56079 + pax_close_kernel();
56080 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
56081 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
56082 break;
56083 diff --git a/drivers/video/fbdev/sh_mobile_lcdcfb.c b/drivers/video/fbdev/sh_mobile_lcdcfb.c
56084 index 2bcc84a..29dd1ea 100644
56085 --- a/drivers/video/fbdev/sh_mobile_lcdcfb.c
56086 +++ b/drivers/video/fbdev/sh_mobile_lcdcfb.c
56087 @@ -439,9 +439,9 @@ static unsigned long lcdc_sys_read_data(void *handle)
56088 }
56089
56090 static struct sh_mobile_lcdc_sys_bus_ops sh_mobile_lcdc_sys_bus_ops = {
56091 - lcdc_sys_write_index,
56092 - lcdc_sys_write_data,
56093 - lcdc_sys_read_data,
56094 + .write_index = lcdc_sys_write_index,
56095 + .write_data = lcdc_sys_write_data,
56096 + .read_data = lcdc_sys_read_data,
56097 };
56098
56099 static int sh_mobile_lcdc_sginit(struct fb_info *info,
56100 diff --git a/drivers/video/fbdev/smscufx.c b/drivers/video/fbdev/smscufx.c
56101 index d513ed6..90b0de9 100644
56102 --- a/drivers/video/fbdev/smscufx.c
56103 +++ b/drivers/video/fbdev/smscufx.c
56104 @@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
56105 fb_deferred_io_cleanup(info);
56106 kfree(info->fbdefio);
56107 info->fbdefio = NULL;
56108 - info->fbops->fb_mmap = ufx_ops_mmap;
56109 + pax_open_kernel();
56110 + *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
56111 + pax_close_kernel();
56112 }
56113
56114 pr_debug("released /dev/fb%d user=%d count=%d",
56115 diff --git a/drivers/video/fbdev/udlfb.c b/drivers/video/fbdev/udlfb.c
56116 index 77b890e..458e666 100644
56117 --- a/drivers/video/fbdev/udlfb.c
56118 +++ b/drivers/video/fbdev/udlfb.c
56119 @@ -623,11 +623,11 @@ static int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
56120 dlfb_urb_completion(urb);
56121
56122 error:
56123 - atomic_add(bytes_sent, &dev->bytes_sent);
56124 - atomic_add(bytes_identical, &dev->bytes_identical);
56125 - atomic_add(width*height*2, &dev->bytes_rendered);
56126 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
56127 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
56128 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
56129 end_cycles = get_cycles();
56130 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
56131 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
56132 >> 10)), /* Kcycles */
56133 &dev->cpu_kcycles_used);
56134
56135 @@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
56136 dlfb_urb_completion(urb);
56137
56138 error:
56139 - atomic_add(bytes_sent, &dev->bytes_sent);
56140 - atomic_add(bytes_identical, &dev->bytes_identical);
56141 - atomic_add(bytes_rendered, &dev->bytes_rendered);
56142 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
56143 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
56144 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
56145 end_cycles = get_cycles();
56146 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
56147 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
56148 >> 10)), /* Kcycles */
56149 &dev->cpu_kcycles_used);
56150 }
56151 @@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
56152 fb_deferred_io_cleanup(info);
56153 kfree(info->fbdefio);
56154 info->fbdefio = NULL;
56155 - info->fbops->fb_mmap = dlfb_ops_mmap;
56156 + pax_open_kernel();
56157 + *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
56158 + pax_close_kernel();
56159 }
56160
56161 pr_warn("released /dev/fb%d user=%d count=%d\n",
56162 @@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
56163 struct fb_info *fb_info = dev_get_drvdata(fbdev);
56164 struct dlfb_data *dev = fb_info->par;
56165 return snprintf(buf, PAGE_SIZE, "%u\n",
56166 - atomic_read(&dev->bytes_rendered));
56167 + atomic_read_unchecked(&dev->bytes_rendered));
56168 }
56169
56170 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
56171 @@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
56172 struct fb_info *fb_info = dev_get_drvdata(fbdev);
56173 struct dlfb_data *dev = fb_info->par;
56174 return snprintf(buf, PAGE_SIZE, "%u\n",
56175 - atomic_read(&dev->bytes_identical));
56176 + atomic_read_unchecked(&dev->bytes_identical));
56177 }
56178
56179 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
56180 @@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
56181 struct fb_info *fb_info = dev_get_drvdata(fbdev);
56182 struct dlfb_data *dev = fb_info->par;
56183 return snprintf(buf, PAGE_SIZE, "%u\n",
56184 - atomic_read(&dev->bytes_sent));
56185 + atomic_read_unchecked(&dev->bytes_sent));
56186 }
56187
56188 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
56189 @@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
56190 struct fb_info *fb_info = dev_get_drvdata(fbdev);
56191 struct dlfb_data *dev = fb_info->par;
56192 return snprintf(buf, PAGE_SIZE, "%u\n",
56193 - atomic_read(&dev->cpu_kcycles_used));
56194 + atomic_read_unchecked(&dev->cpu_kcycles_used));
56195 }
56196
56197 static ssize_t edid_show(
56198 @@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
56199 struct fb_info *fb_info = dev_get_drvdata(fbdev);
56200 struct dlfb_data *dev = fb_info->par;
56201
56202 - atomic_set(&dev->bytes_rendered, 0);
56203 - atomic_set(&dev->bytes_identical, 0);
56204 - atomic_set(&dev->bytes_sent, 0);
56205 - atomic_set(&dev->cpu_kcycles_used, 0);
56206 + atomic_set_unchecked(&dev->bytes_rendered, 0);
56207 + atomic_set_unchecked(&dev->bytes_identical, 0);
56208 + atomic_set_unchecked(&dev->bytes_sent, 0);
56209 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
56210
56211 return count;
56212 }
56213 diff --git a/drivers/video/fbdev/uvesafb.c b/drivers/video/fbdev/uvesafb.c
56214 index 509d452..7c9d2de 100644
56215 --- a/drivers/video/fbdev/uvesafb.c
56216 +++ b/drivers/video/fbdev/uvesafb.c
56217 @@ -19,6 +19,7 @@
56218 #include <linux/io.h>
56219 #include <linux/mutex.h>
56220 #include <linux/slab.h>
56221 +#include <linux/moduleloader.h>
56222 #include <video/edid.h>
56223 #include <video/uvesafb.h>
56224 #ifdef CONFIG_X86
56225 @@ -565,10 +566,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
56226 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
56227 par->pmi_setpal = par->ypan = 0;
56228 } else {
56229 +
56230 +#ifdef CONFIG_PAX_KERNEXEC
56231 +#ifdef CONFIG_MODULES
56232 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
56233 +#endif
56234 + if (!par->pmi_code) {
56235 + par->pmi_setpal = par->ypan = 0;
56236 + return 0;
56237 + }
56238 +#endif
56239 +
56240 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
56241 + task->t.regs.edi);
56242 +
56243 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56244 + pax_open_kernel();
56245 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
56246 + pax_close_kernel();
56247 +
56248 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
56249 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
56250 +#else
56251 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
56252 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
56253 +#endif
56254 +
56255 printk(KERN_INFO "uvesafb: protected mode interface info at "
56256 "%04x:%04x\n",
56257 (u16)task->t.regs.es, (u16)task->t.regs.edi);
56258 @@ -813,13 +836,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
56259 par->ypan = ypan;
56260
56261 if (par->pmi_setpal || par->ypan) {
56262 +#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
56263 if (__supported_pte_mask & _PAGE_NX) {
56264 par->pmi_setpal = par->ypan = 0;
56265 printk(KERN_WARNING "uvesafb: NX protection is active, "
56266 "better not use the PMI.\n");
56267 - } else {
56268 + } else
56269 +#endif
56270 uvesafb_vbe_getpmi(task, par);
56271 - }
56272 }
56273 #else
56274 /* The protected mode interface is not available on non-x86. */
56275 @@ -1453,8 +1477,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
56276 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
56277
56278 /* Disable blanking if the user requested so. */
56279 - if (!blank)
56280 - info->fbops->fb_blank = NULL;
56281 + if (!blank) {
56282 + pax_open_kernel();
56283 + *(void **)&info->fbops->fb_blank = NULL;
56284 + pax_close_kernel();
56285 + }
56286
56287 /*
56288 * Find out how much IO memory is required for the mode with
56289 @@ -1525,8 +1552,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
56290 info->flags = FBINFO_FLAG_DEFAULT |
56291 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
56292
56293 - if (!par->ypan)
56294 - info->fbops->fb_pan_display = NULL;
56295 + if (!par->ypan) {
56296 + pax_open_kernel();
56297 + *(void **)&info->fbops->fb_pan_display = NULL;
56298 + pax_close_kernel();
56299 + }
56300 }
56301
56302 static void uvesafb_init_mtrr(struct fb_info *info)
56303 @@ -1787,6 +1817,11 @@ out_mode:
56304 out:
56305 kfree(par->vbe_modes);
56306
56307 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56308 + if (par->pmi_code)
56309 + module_free_exec(NULL, par->pmi_code);
56310 +#endif
56311 +
56312 framebuffer_release(info);
56313 return err;
56314 }
56315 @@ -1811,6 +1846,11 @@ static int uvesafb_remove(struct platform_device *dev)
56316 kfree(par->vbe_state_orig);
56317 kfree(par->vbe_state_saved);
56318
56319 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56320 + if (par->pmi_code)
56321 + module_free_exec(NULL, par->pmi_code);
56322 +#endif
56323 +
56324 framebuffer_release(info);
56325 }
56326 return 0;
56327 diff --git a/drivers/video/fbdev/vesafb.c b/drivers/video/fbdev/vesafb.c
56328 index 6170e7f..dd63031 100644
56329 --- a/drivers/video/fbdev/vesafb.c
56330 +++ b/drivers/video/fbdev/vesafb.c
56331 @@ -9,6 +9,7 @@
56332 */
56333
56334 #include <linux/module.h>
56335 +#include <linux/moduleloader.h>
56336 #include <linux/kernel.h>
56337 #include <linux/errno.h>
56338 #include <linux/string.h>
56339 @@ -52,8 +53,8 @@ static int vram_remap; /* Set amount of memory to be used */
56340 static int vram_total; /* Set total amount of memory */
56341 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
56342 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
56343 -static void (*pmi_start)(void) __read_mostly;
56344 -static void (*pmi_pal) (void) __read_mostly;
56345 +static void (*pmi_start)(void) __read_only;
56346 +static void (*pmi_pal) (void) __read_only;
56347 static int depth __read_mostly;
56348 static int vga_compat __read_mostly;
56349 /* --------------------------------------------------------------------- */
56350 @@ -233,6 +234,7 @@ static int vesafb_probe(struct platform_device *dev)
56351 unsigned int size_remap;
56352 unsigned int size_total;
56353 char *option = NULL;
56354 + void *pmi_code = NULL;
56355
56356 /* ignore error return of fb_get_options */
56357 fb_get_options("vesafb", &option);
56358 @@ -279,10 +281,6 @@ static int vesafb_probe(struct platform_device *dev)
56359 size_remap = size_total;
56360 vesafb_fix.smem_len = size_remap;
56361
56362 -#ifndef __i386__
56363 - screen_info.vesapm_seg = 0;
56364 -#endif
56365 -
56366 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
56367 printk(KERN_WARNING
56368 "vesafb: cannot reserve video memory at 0x%lx\n",
56369 @@ -312,9 +310,21 @@ static int vesafb_probe(struct platform_device *dev)
56370 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
56371 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
56372
56373 +#ifdef __i386__
56374 +
56375 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56376 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
56377 + if (!pmi_code)
56378 +#elif !defined(CONFIG_PAX_KERNEXEC)
56379 + if (0)
56380 +#endif
56381 +
56382 +#endif
56383 + screen_info.vesapm_seg = 0;
56384 +
56385 if (screen_info.vesapm_seg) {
56386 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
56387 - screen_info.vesapm_seg,screen_info.vesapm_off);
56388 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
56389 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
56390 }
56391
56392 if (screen_info.vesapm_seg < 0xc000)
56393 @@ -322,9 +332,25 @@ static int vesafb_probe(struct platform_device *dev)
56394
56395 if (ypan || pmi_setpal) {
56396 unsigned short *pmi_base;
56397 +
56398 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
56399 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
56400 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
56401 +
56402 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56403 + pax_open_kernel();
56404 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
56405 +#else
56406 + pmi_code = pmi_base;
56407 +#endif
56408 +
56409 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
56410 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
56411 +
56412 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56413 + pmi_start = ktva_ktla(pmi_start);
56414 + pmi_pal = ktva_ktla(pmi_pal);
56415 + pax_close_kernel();
56416 +#endif
56417 +
56418 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
56419 if (pmi_base[3]) {
56420 printk(KERN_INFO "vesafb: pmi: ports = ");
56421 @@ -477,8 +503,11 @@ static int vesafb_probe(struct platform_device *dev)
56422 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
56423 (ypan ? FBINFO_HWACCEL_YPAN : 0);
56424
56425 - if (!ypan)
56426 - info->fbops->fb_pan_display = NULL;
56427 + if (!ypan) {
56428 + pax_open_kernel();
56429 + *(void **)&info->fbops->fb_pan_display = NULL;
56430 + pax_close_kernel();
56431 + }
56432
56433 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
56434 err = -ENOMEM;
56435 @@ -492,6 +521,11 @@ static int vesafb_probe(struct platform_device *dev)
56436 fb_info(info, "%s frame buffer device\n", info->fix.id);
56437 return 0;
56438 err:
56439 +
56440 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56441 + module_free_exec(NULL, pmi_code);
56442 +#endif
56443 +
56444 if (info->screen_base)
56445 iounmap(info->screen_base);
56446 framebuffer_release(info);
56447 diff --git a/drivers/video/fbdev/via/via_clock.h b/drivers/video/fbdev/via/via_clock.h
56448 index 88714ae..16c2e11 100644
56449 --- a/drivers/video/fbdev/via/via_clock.h
56450 +++ b/drivers/video/fbdev/via/via_clock.h
56451 @@ -56,7 +56,7 @@ struct via_clock {
56452
56453 void (*set_engine_pll_state)(u8 state);
56454 void (*set_engine_pll)(struct via_pll_config config);
56455 -};
56456 +} __no_const;
56457
56458
56459 static inline u32 get_pll_internal_frequency(u32 ref_freq,
56460 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
56461 index 3c14e43..2630570 100644
56462 --- a/drivers/video/logo/logo_linux_clut224.ppm
56463 +++ b/drivers/video/logo/logo_linux_clut224.ppm
56464 @@ -2,1603 +2,1123 @@ P3
56465 # Standard 224-color Linux logo
56466 80 80
56467 255
56468 - 0 0 0 0 0 0 0 0 0 0 0 0
56469 - 0 0 0 0 0 0 0 0 0 0 0 0
56470 - 0 0 0 0 0 0 0 0 0 0 0 0
56471 - 0 0 0 0 0 0 0 0 0 0 0 0
56472 - 0 0 0 0 0 0 0 0 0 0 0 0
56473 - 0 0 0 0 0 0 0 0 0 0 0 0
56474 - 0 0 0 0 0 0 0 0 0 0 0 0
56475 - 0 0 0 0 0 0 0 0 0 0 0 0
56476 - 0 0 0 0 0 0 0 0 0 0 0 0
56477 - 6 6 6 6 6 6 10 10 10 10 10 10
56478 - 10 10 10 6 6 6 6 6 6 6 6 6
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 0 0 0 0 0 0 0 0 0
56486 - 0 0 0 0 0 0 0 0 0 0 0 0
56487 - 0 0 0 0 0 0 0 0 0 0 0 0
56488 - 0 0 0 0 0 0 0 0 0 0 0 0
56489 - 0 0 0 0 0 0 0 0 0 0 0 0
56490 - 0 0 0 0 0 0 0 0 0 0 0 0
56491 - 0 0 0 0 0 0 0 0 0 0 0 0
56492 - 0 0 0 0 0 0 0 0 0 0 0 0
56493 - 0 0 0 0 0 0 0 0 0 0 0 0
56494 - 0 0 0 0 0 0 0 0 0 0 0 0
56495 - 0 0 0 0 0 0 0 0 0 0 0 0
56496 - 0 0 0 6 6 6 10 10 10 14 14 14
56497 - 22 22 22 26 26 26 30 30 30 34 34 34
56498 - 30 30 30 30 30 30 26 26 26 18 18 18
56499 - 14 14 14 10 10 10 6 6 6 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 - 0 0 0 0 0 0 0 0 0 0 0 0
56506 - 0 0 0 0 0 0 0 0 0 0 0 0
56507 - 0 0 0 0 0 0 0 0 0 0 0 0
56508 - 0 0 0 0 0 0 0 0 0 0 0 0
56509 - 0 0 0 0 0 1 0 0 1 0 0 0
56510 - 0 0 0 0 0 0 0 0 0 0 0 0
56511 - 0 0 0 0 0 0 0 0 0 0 0 0
56512 - 0 0 0 0 0 0 0 0 0 0 0 0
56513 - 0 0 0 0 0 0 0 0 0 0 0 0
56514 - 0 0 0 0 0 0 0 0 0 0 0 0
56515 - 0 0 0 0 0 0 0 0 0 0 0 0
56516 - 6 6 6 14 14 14 26 26 26 42 42 42
56517 - 54 54 54 66 66 66 78 78 78 78 78 78
56518 - 78 78 78 74 74 74 66 66 66 54 54 54
56519 - 42 42 42 26 26 26 18 18 18 10 10 10
56520 - 6 6 6 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 - 0 0 0 0 0 0 0 0 0 0 0 0
56526 - 0 0 0 0 0 0 0 0 0 0 0 0
56527 - 0 0 0 0 0 0 0 0 0 0 0 0
56528 - 0 0 0 0 0 0 0 0 0 0 0 0
56529 - 0 0 1 0 0 0 0 0 0 0 0 0
56530 - 0 0 0 0 0 0 0 0 0 0 0 0
56531 - 0 0 0 0 0 0 0 0 0 0 0 0
56532 - 0 0 0 0 0 0 0 0 0 0 0 0
56533 - 0 0 0 0 0 0 0 0 0 0 0 0
56534 - 0 0 0 0 0 0 0 0 0 0 0 0
56535 - 0 0 0 0 0 0 0 0 0 10 10 10
56536 - 22 22 22 42 42 42 66 66 66 86 86 86
56537 - 66 66 66 38 38 38 38 38 38 22 22 22
56538 - 26 26 26 34 34 34 54 54 54 66 66 66
56539 - 86 86 86 70 70 70 46 46 46 26 26 26
56540 - 14 14 14 6 6 6 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 0 0 0
56545 - 0 0 0 0 0 0 0 0 0 0 0 0
56546 - 0 0 0 0 0 0 0 0 0 0 0 0
56547 - 0 0 0 0 0 0 0 0 0 0 0 0
56548 - 0 0 0 0 0 0 0 0 0 0 0 0
56549 - 0 0 1 0 0 1 0 0 1 0 0 0
56550 - 0 0 0 0 0 0 0 0 0 0 0 0
56551 - 0 0 0 0 0 0 0 0 0 0 0 0
56552 - 0 0 0 0 0 0 0 0 0 0 0 0
56553 - 0 0 0 0 0 0 0 0 0 0 0 0
56554 - 0 0 0 0 0 0 0 0 0 0 0 0
56555 - 0 0 0 0 0 0 10 10 10 26 26 26
56556 - 50 50 50 82 82 82 58 58 58 6 6 6
56557 - 2 2 6 2 2 6 2 2 6 2 2 6
56558 - 2 2 6 2 2 6 2 2 6 2 2 6
56559 - 6 6 6 54 54 54 86 86 86 66 66 66
56560 - 38 38 38 18 18 18 6 6 6 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 0 0 0
56565 - 0 0 0 0 0 0 0 0 0 0 0 0
56566 - 0 0 0 0 0 0 0 0 0 0 0 0
56567 - 0 0 0 0 0 0 0 0 0 0 0 0
56568 - 0 0 0 0 0 0 0 0 0 0 0 0
56569 - 0 0 0 0 0 0 0 0 0 0 0 0
56570 - 0 0 0 0 0 0 0 0 0 0 0 0
56571 - 0 0 0 0 0 0 0 0 0 0 0 0
56572 - 0 0 0 0 0 0 0 0 0 0 0 0
56573 - 0 0 0 0 0 0 0 0 0 0 0 0
56574 - 0 0 0 0 0 0 0 0 0 0 0 0
56575 - 0 0 0 6 6 6 22 22 22 50 50 50
56576 - 78 78 78 34 34 34 2 2 6 2 2 6
56577 - 2 2 6 2 2 6 2 2 6 2 2 6
56578 - 2 2 6 2 2 6 2 2 6 2 2 6
56579 - 2 2 6 2 2 6 6 6 6 70 70 70
56580 - 78 78 78 46 46 46 22 22 22 6 6 6
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 0 0 0
56585 - 0 0 0 0 0 0 0 0 0 0 0 0
56586 - 0 0 0 0 0 0 0 0 0 0 0 0
56587 - 0 0 0 0 0 0 0 0 0 0 0 0
56588 - 0 0 0 0 0 0 0 0 0 0 0 0
56589 - 0 0 1 0 0 1 0 0 1 0 0 0
56590 - 0 0 0 0 0 0 0 0 0 0 0 0
56591 - 0 0 0 0 0 0 0 0 0 0 0 0
56592 - 0 0 0 0 0 0 0 0 0 0 0 0
56593 - 0 0 0 0 0 0 0 0 0 0 0 0
56594 - 0 0 0 0 0 0 0 0 0 0 0 0
56595 - 6 6 6 18 18 18 42 42 42 82 82 82
56596 - 26 26 26 2 2 6 2 2 6 2 2 6
56597 - 2 2 6 2 2 6 2 2 6 2 2 6
56598 - 2 2 6 2 2 6 2 2 6 14 14 14
56599 - 46 46 46 34 34 34 6 6 6 2 2 6
56600 - 42 42 42 78 78 78 42 42 42 18 18 18
56601 - 6 6 6 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 0 0 0 0 0 0
56605 - 0 0 0 0 0 0 0 0 0 0 0 0
56606 - 0 0 0 0 0 0 0 0 0 0 0 0
56607 - 0 0 0 0 0 0 0 0 0 0 0 0
56608 - 0 0 0 0 0 0 0 0 0 0 0 0
56609 - 0 0 1 0 0 0 0 0 1 0 0 0
56610 - 0 0 0 0 0 0 0 0 0 0 0 0
56611 - 0 0 0 0 0 0 0 0 0 0 0 0
56612 - 0 0 0 0 0 0 0 0 0 0 0 0
56613 - 0 0 0 0 0 0 0 0 0 0 0 0
56614 - 0 0 0 0 0 0 0 0 0 0 0 0
56615 - 10 10 10 30 30 30 66 66 66 58 58 58
56616 - 2 2 6 2 2 6 2 2 6 2 2 6
56617 - 2 2 6 2 2 6 2 2 6 2 2 6
56618 - 2 2 6 2 2 6 2 2 6 26 26 26
56619 - 86 86 86 101 101 101 46 46 46 10 10 10
56620 - 2 2 6 58 58 58 70 70 70 34 34 34
56621 - 10 10 10 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 0 0 0 0 0 0
56625 - 0 0 0 0 0 0 0 0 0 0 0 0
56626 - 0 0 0 0 0 0 0 0 0 0 0 0
56627 - 0 0 0 0 0 0 0 0 0 0 0 0
56628 - 0 0 0 0 0 0 0 0 0 0 0 0
56629 - 0 0 1 0 0 1 0 0 1 0 0 0
56630 - 0 0 0 0 0 0 0 0 0 0 0 0
56631 - 0 0 0 0 0 0 0 0 0 0 0 0
56632 - 0 0 0 0 0 0 0 0 0 0 0 0
56633 - 0 0 0 0 0 0 0 0 0 0 0 0
56634 - 0 0 0 0 0 0 0 0 0 0 0 0
56635 - 14 14 14 42 42 42 86 86 86 10 10 10
56636 - 2 2 6 2 2 6 2 2 6 2 2 6
56637 - 2 2 6 2 2 6 2 2 6 2 2 6
56638 - 2 2 6 2 2 6 2 2 6 30 30 30
56639 - 94 94 94 94 94 94 58 58 58 26 26 26
56640 - 2 2 6 6 6 6 78 78 78 54 54 54
56641 - 22 22 22 6 6 6 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 0 0 0 0 0 0
56645 - 0 0 0 0 0 0 0 0 0 0 0 0
56646 - 0 0 0 0 0 0 0 0 0 0 0 0
56647 - 0 0 0 0 0 0 0 0 0 0 0 0
56648 - 0 0 0 0 0 0 0 0 0 0 0 0
56649 - 0 0 0 0 0 0 0 0 0 0 0 0
56650 - 0 0 0 0 0 0 0 0 0 0 0 0
56651 - 0 0 0 0 0 0 0 0 0 0 0 0
56652 - 0 0 0 0 0 0 0 0 0 0 0 0
56653 - 0 0 0 0 0 0 0 0 0 0 0 0
56654 - 0 0 0 0 0 0 0 0 0 6 6 6
56655 - 22 22 22 62 62 62 62 62 62 2 2 6
56656 - 2 2 6 2 2 6 2 2 6 2 2 6
56657 - 2 2 6 2 2 6 2 2 6 2 2 6
56658 - 2 2 6 2 2 6 2 2 6 26 26 26
56659 - 54 54 54 38 38 38 18 18 18 10 10 10
56660 - 2 2 6 2 2 6 34 34 34 82 82 82
56661 - 38 38 38 14 14 14 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 0 0 0 0 0 0
56665 - 0 0 0 0 0 0 0 0 0 0 0 0
56666 - 0 0 0 0 0 0 0 0 0 0 0 0
56667 - 0 0 0 0 0 0 0 0 0 0 0 0
56668 - 0 0 0 0 0 0 0 0 0 0 0 0
56669 - 0 0 0 0 0 1 0 0 1 0 0 0
56670 - 0 0 0 0 0 0 0 0 0 0 0 0
56671 - 0 0 0 0 0 0 0 0 0 0 0 0
56672 - 0 0 0 0 0 0 0 0 0 0 0 0
56673 - 0 0 0 0 0 0 0 0 0 0 0 0
56674 - 0 0 0 0 0 0 0 0 0 6 6 6
56675 - 30 30 30 78 78 78 30 30 30 2 2 6
56676 - 2 2 6 2 2 6 2 2 6 2 2 6
56677 - 2 2 6 2 2 6 2 2 6 2 2 6
56678 - 2 2 6 2 2 6 2 2 6 10 10 10
56679 - 10 10 10 2 2 6 2 2 6 2 2 6
56680 - 2 2 6 2 2 6 2 2 6 78 78 78
56681 - 50 50 50 18 18 18 6 6 6 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 0 0 0
56684 - 0 0 0 0 0 0 0 0 0 0 0 0
56685 - 0 0 0 0 0 0 0 0 0 0 0 0
56686 - 0 0 0 0 0 0 0 0 0 0 0 0
56687 - 0 0 0 0 0 0 0 0 0 0 0 0
56688 - 0 0 0 0 0 0 0 0 0 0 0 0
56689 - 0 0 1 0 0 0 0 0 0 0 0 0
56690 - 0 0 0 0 0 0 0 0 0 0 0 0
56691 - 0 0 0 0 0 0 0 0 0 0 0 0
56692 - 0 0 0 0 0 0 0 0 0 0 0 0
56693 - 0 0 0 0 0 0 0 0 0 0 0 0
56694 - 0 0 0 0 0 0 0 0 0 10 10 10
56695 - 38 38 38 86 86 86 14 14 14 2 2 6
56696 - 2 2 6 2 2 6 2 2 6 2 2 6
56697 - 2 2 6 2 2 6 2 2 6 2 2 6
56698 - 2 2 6 2 2 6 2 2 6 2 2 6
56699 - 2 2 6 2 2 6 2 2 6 2 2 6
56700 - 2 2 6 2 2 6 2 2 6 54 54 54
56701 - 66 66 66 26 26 26 6 6 6 0 0 0
56702 - 0 0 0 0 0 0 0 0 0 0 0 0
56703 - 0 0 0 0 0 0 0 0 0 0 0 0
56704 - 0 0 0 0 0 0 0 0 0 0 0 0
56705 - 0 0 0 0 0 0 0 0 0 0 0 0
56706 - 0 0 0 0 0 0 0 0 0 0 0 0
56707 - 0 0 0 0 0 0 0 0 0 0 0 0
56708 - 0 0 0 0 0 0 0 0 0 0 0 0
56709 - 0 0 0 0 0 1 0 0 1 0 0 0
56710 - 0 0 0 0 0 0 0 0 0 0 0 0
56711 - 0 0 0 0 0 0 0 0 0 0 0 0
56712 - 0 0 0 0 0 0 0 0 0 0 0 0
56713 - 0 0 0 0 0 0 0 0 0 0 0 0
56714 - 0 0 0 0 0 0 0 0 0 14 14 14
56715 - 42 42 42 82 82 82 2 2 6 2 2 6
56716 - 2 2 6 6 6 6 10 10 10 2 2 6
56717 - 2 2 6 2 2 6 2 2 6 2 2 6
56718 - 2 2 6 2 2 6 2 2 6 6 6 6
56719 - 14 14 14 10 10 10 2 2 6 2 2 6
56720 - 2 2 6 2 2 6 2 2 6 18 18 18
56721 - 82 82 82 34 34 34 10 10 10 0 0 0
56722 - 0 0 0 0 0 0 0 0 0 0 0 0
56723 - 0 0 0 0 0 0 0 0 0 0 0 0
56724 - 0 0 0 0 0 0 0 0 0 0 0 0
56725 - 0 0 0 0 0 0 0 0 0 0 0 0
56726 - 0 0 0 0 0 0 0 0 0 0 0 0
56727 - 0 0 0 0 0 0 0 0 0 0 0 0
56728 - 0 0 0 0 0 0 0 0 0 0 0 0
56729 - 0 0 1 0 0 0 0 0 0 0 0 0
56730 - 0 0 0 0 0 0 0 0 0 0 0 0
56731 - 0 0 0 0 0 0 0 0 0 0 0 0
56732 - 0 0 0 0 0 0 0 0 0 0 0 0
56733 - 0 0 0 0 0 0 0 0 0 0 0 0
56734 - 0 0 0 0 0 0 0 0 0 14 14 14
56735 - 46 46 46 86 86 86 2 2 6 2 2 6
56736 - 6 6 6 6 6 6 22 22 22 34 34 34
56737 - 6 6 6 2 2 6 2 2 6 2 2 6
56738 - 2 2 6 2 2 6 18 18 18 34 34 34
56739 - 10 10 10 50 50 50 22 22 22 2 2 6
56740 - 2 2 6 2 2 6 2 2 6 10 10 10
56741 - 86 86 86 42 42 42 14 14 14 0 0 0
56742 - 0 0 0 0 0 0 0 0 0 0 0 0
56743 - 0 0 0 0 0 0 0 0 0 0 0 0
56744 - 0 0 0 0 0 0 0 0 0 0 0 0
56745 - 0 0 0 0 0 0 0 0 0 0 0 0
56746 - 0 0 0 0 0 0 0 0 0 0 0 0
56747 - 0 0 0 0 0 0 0 0 0 0 0 0
56748 - 0 0 0 0 0 0 0 0 0 0 0 0
56749 - 0 0 1 0 0 1 0 0 1 0 0 0
56750 - 0 0 0 0 0 0 0 0 0 0 0 0
56751 - 0 0 0 0 0 0 0 0 0 0 0 0
56752 - 0 0 0 0 0 0 0 0 0 0 0 0
56753 - 0 0 0 0 0 0 0 0 0 0 0 0
56754 - 0 0 0 0 0 0 0 0 0 14 14 14
56755 - 46 46 46 86 86 86 2 2 6 2 2 6
56756 - 38 38 38 116 116 116 94 94 94 22 22 22
56757 - 22 22 22 2 2 6 2 2 6 2 2 6
56758 - 14 14 14 86 86 86 138 138 138 162 162 162
56759 -154 154 154 38 38 38 26 26 26 6 6 6
56760 - 2 2 6 2 2 6 2 2 6 2 2 6
56761 - 86 86 86 46 46 46 14 14 14 0 0 0
56762 - 0 0 0 0 0 0 0 0 0 0 0 0
56763 - 0 0 0 0 0 0 0 0 0 0 0 0
56764 - 0 0 0 0 0 0 0 0 0 0 0 0
56765 - 0 0 0 0 0 0 0 0 0 0 0 0
56766 - 0 0 0 0 0 0 0 0 0 0 0 0
56767 - 0 0 0 0 0 0 0 0 0 0 0 0
56768 - 0 0 0 0 0 0 0 0 0 0 0 0
56769 - 0 0 0 0 0 0 0 0 0 0 0 0
56770 - 0 0 0 0 0 0 0 0 0 0 0 0
56771 - 0 0 0 0 0 0 0 0 0 0 0 0
56772 - 0 0 0 0 0 0 0 0 0 0 0 0
56773 - 0 0 0 0 0 0 0 0 0 0 0 0
56774 - 0 0 0 0 0 0 0 0 0 14 14 14
56775 - 46 46 46 86 86 86 2 2 6 14 14 14
56776 -134 134 134 198 198 198 195 195 195 116 116 116
56777 - 10 10 10 2 2 6 2 2 6 6 6 6
56778 -101 98 89 187 187 187 210 210 210 218 218 218
56779 -214 214 214 134 134 134 14 14 14 6 6 6
56780 - 2 2 6 2 2 6 2 2 6 2 2 6
56781 - 86 86 86 50 50 50 18 18 18 6 6 6
56782 - 0 0 0 0 0 0 0 0 0 0 0 0
56783 - 0 0 0 0 0 0 0 0 0 0 0 0
56784 - 0 0 0 0 0 0 0 0 0 0 0 0
56785 - 0 0 0 0 0 0 0 0 0 0 0 0
56786 - 0 0 0 0 0 0 0 0 0 0 0 0
56787 - 0 0 0 0 0 0 0 0 0 0 0 0
56788 - 0 0 0 0 0 0 0 0 1 0 0 0
56789 - 0 0 1 0 0 1 0 0 1 0 0 0
56790 - 0 0 0 0 0 0 0 0 0 0 0 0
56791 - 0 0 0 0 0 0 0 0 0 0 0 0
56792 - 0 0 0 0 0 0 0 0 0 0 0 0
56793 - 0 0 0 0 0 0 0 0 0 0 0 0
56794 - 0 0 0 0 0 0 0 0 0 14 14 14
56795 - 46 46 46 86 86 86 2 2 6 54 54 54
56796 -218 218 218 195 195 195 226 226 226 246 246 246
56797 - 58 58 58 2 2 6 2 2 6 30 30 30
56798 -210 210 210 253 253 253 174 174 174 123 123 123
56799 -221 221 221 234 234 234 74 74 74 2 2 6
56800 - 2 2 6 2 2 6 2 2 6 2 2 6
56801 - 70 70 70 58 58 58 22 22 22 6 6 6
56802 - 0 0 0 0 0 0 0 0 0 0 0 0
56803 - 0 0 0 0 0 0 0 0 0 0 0 0
56804 - 0 0 0 0 0 0 0 0 0 0 0 0
56805 - 0 0 0 0 0 0 0 0 0 0 0 0
56806 - 0 0 0 0 0 0 0 0 0 0 0 0
56807 - 0 0 0 0 0 0 0 0 0 0 0 0
56808 - 0 0 0 0 0 0 0 0 0 0 0 0
56809 - 0 0 0 0 0 0 0 0 0 0 0 0
56810 - 0 0 0 0 0 0 0 0 0 0 0 0
56811 - 0 0 0 0 0 0 0 0 0 0 0 0
56812 - 0 0 0 0 0 0 0 0 0 0 0 0
56813 - 0 0 0 0 0 0 0 0 0 0 0 0
56814 - 0 0 0 0 0 0 0 0 0 14 14 14
56815 - 46 46 46 82 82 82 2 2 6 106 106 106
56816 -170 170 170 26 26 26 86 86 86 226 226 226
56817 -123 123 123 10 10 10 14 14 14 46 46 46
56818 -231 231 231 190 190 190 6 6 6 70 70 70
56819 - 90 90 90 238 238 238 158 158 158 2 2 6
56820 - 2 2 6 2 2 6 2 2 6 2 2 6
56821 - 70 70 70 58 58 58 22 22 22 6 6 6
56822 - 0 0 0 0 0 0 0 0 0 0 0 0
56823 - 0 0 0 0 0 0 0 0 0 0 0 0
56824 - 0 0 0 0 0 0 0 0 0 0 0 0
56825 - 0 0 0 0 0 0 0 0 0 0 0 0
56826 - 0 0 0 0 0 0 0 0 0 0 0 0
56827 - 0 0 0 0 0 0 0 0 0 0 0 0
56828 - 0 0 0 0 0 0 0 0 1 0 0 0
56829 - 0 0 1 0 0 1 0 0 1 0 0 0
56830 - 0 0 0 0 0 0 0 0 0 0 0 0
56831 - 0 0 0 0 0 0 0 0 0 0 0 0
56832 - 0 0 0 0 0 0 0 0 0 0 0 0
56833 - 0 0 0 0 0 0 0 0 0 0 0 0
56834 - 0 0 0 0 0 0 0 0 0 14 14 14
56835 - 42 42 42 86 86 86 6 6 6 116 116 116
56836 -106 106 106 6 6 6 70 70 70 149 149 149
56837 -128 128 128 18 18 18 38 38 38 54 54 54
56838 -221 221 221 106 106 106 2 2 6 14 14 14
56839 - 46 46 46 190 190 190 198 198 198 2 2 6
56840 - 2 2 6 2 2 6 2 2 6 2 2 6
56841 - 74 74 74 62 62 62 22 22 22 6 6 6
56842 - 0 0 0 0 0 0 0 0 0 0 0 0
56843 - 0 0 0 0 0 0 0 0 0 0 0 0
56844 - 0 0 0 0 0 0 0 0 0 0 0 0
56845 - 0 0 0 0 0 0 0 0 0 0 0 0
56846 - 0 0 0 0 0 0 0 0 0 0 0 0
56847 - 0 0 0 0 0 0 0 0 0 0 0 0
56848 - 0 0 0 0 0 0 0 0 1 0 0 0
56849 - 0 0 1 0 0 0 0 0 1 0 0 0
56850 - 0 0 0 0 0 0 0 0 0 0 0 0
56851 - 0 0 0 0 0 0 0 0 0 0 0 0
56852 - 0 0 0 0 0 0 0 0 0 0 0 0
56853 - 0 0 0 0 0 0 0 0 0 0 0 0
56854 - 0 0 0 0 0 0 0 0 0 14 14 14
56855 - 42 42 42 94 94 94 14 14 14 101 101 101
56856 -128 128 128 2 2 6 18 18 18 116 116 116
56857 -118 98 46 121 92 8 121 92 8 98 78 10
56858 -162 162 162 106 106 106 2 2 6 2 2 6
56859 - 2 2 6 195 195 195 195 195 195 6 6 6
56860 - 2 2 6 2 2 6 2 2 6 2 2 6
56861 - 74 74 74 62 62 62 22 22 22 6 6 6
56862 - 0 0 0 0 0 0 0 0 0 0 0 0
56863 - 0 0 0 0 0 0 0 0 0 0 0 0
56864 - 0 0 0 0 0 0 0 0 0 0 0 0
56865 - 0 0 0 0 0 0 0 0 0 0 0 0
56866 - 0 0 0 0 0 0 0 0 0 0 0 0
56867 - 0 0 0 0 0 0 0 0 0 0 0 0
56868 - 0 0 0 0 0 0 0 0 1 0 0 1
56869 - 0 0 1 0 0 0 0 0 1 0 0 0
56870 - 0 0 0 0 0 0 0 0 0 0 0 0
56871 - 0 0 0 0 0 0 0 0 0 0 0 0
56872 - 0 0 0 0 0 0 0 0 0 0 0 0
56873 - 0 0 0 0 0 0 0 0 0 0 0 0
56874 - 0 0 0 0 0 0 0 0 0 10 10 10
56875 - 38 38 38 90 90 90 14 14 14 58 58 58
56876 -210 210 210 26 26 26 54 38 6 154 114 10
56877 -226 170 11 236 186 11 225 175 15 184 144 12
56878 -215 174 15 175 146 61 37 26 9 2 2 6
56879 - 70 70 70 246 246 246 138 138 138 2 2 6
56880 - 2 2 6 2 2 6 2 2 6 2 2 6
56881 - 70 70 70 66 66 66 26 26 26 6 6 6
56882 - 0 0 0 0 0 0 0 0 0 0 0 0
56883 - 0 0 0 0 0 0 0 0 0 0 0 0
56884 - 0 0 0 0 0 0 0 0 0 0 0 0
56885 - 0 0 0 0 0 0 0 0 0 0 0 0
56886 - 0 0 0 0 0 0 0 0 0 0 0 0
56887 - 0 0 0 0 0 0 0 0 0 0 0 0
56888 - 0 0 0 0 0 0 0 0 0 0 0 0
56889 - 0 0 0 0 0 0 0 0 0 0 0 0
56890 - 0 0 0 0 0 0 0 0 0 0 0 0
56891 - 0 0 0 0 0 0 0 0 0 0 0 0
56892 - 0 0 0 0 0 0 0 0 0 0 0 0
56893 - 0 0 0 0 0 0 0 0 0 0 0 0
56894 - 0 0 0 0 0 0 0 0 0 10 10 10
56895 - 38 38 38 86 86 86 14 14 14 10 10 10
56896 -195 195 195 188 164 115 192 133 9 225 175 15
56897 -239 182 13 234 190 10 232 195 16 232 200 30
56898 -245 207 45 241 208 19 232 195 16 184 144 12
56899 -218 194 134 211 206 186 42 42 42 2 2 6
56900 - 2 2 6 2 2 6 2 2 6 2 2 6
56901 - 50 50 50 74 74 74 30 30 30 6 6 6
56902 - 0 0 0 0 0 0 0 0 0 0 0 0
56903 - 0 0 0 0 0 0 0 0 0 0 0 0
56904 - 0 0 0 0 0 0 0 0 0 0 0 0
56905 - 0 0 0 0 0 0 0 0 0 0 0 0
56906 - 0 0 0 0 0 0 0 0 0 0 0 0
56907 - 0 0 0 0 0 0 0 0 0 0 0 0
56908 - 0 0 0 0 0 0 0 0 0 0 0 0
56909 - 0 0 0 0 0 0 0 0 0 0 0 0
56910 - 0 0 0 0 0 0 0 0 0 0 0 0
56911 - 0 0 0 0 0 0 0 0 0 0 0 0
56912 - 0 0 0 0 0 0 0 0 0 0 0 0
56913 - 0 0 0 0 0 0 0 0 0 0 0 0
56914 - 0 0 0 0 0 0 0 0 0 10 10 10
56915 - 34 34 34 86 86 86 14 14 14 2 2 6
56916 -121 87 25 192 133 9 219 162 10 239 182 13
56917 -236 186 11 232 195 16 241 208 19 244 214 54
56918 -246 218 60 246 218 38 246 215 20 241 208 19
56919 -241 208 19 226 184 13 121 87 25 2 2 6
56920 - 2 2 6 2 2 6 2 2 6 2 2 6
56921 - 50 50 50 82 82 82 34 34 34 10 10 10
56922 - 0 0 0 0 0 0 0 0 0 0 0 0
56923 - 0 0 0 0 0 0 0 0 0 0 0 0
56924 - 0 0 0 0 0 0 0 0 0 0 0 0
56925 - 0 0 0 0 0 0 0 0 0 0 0 0
56926 - 0 0 0 0 0 0 0 0 0 0 0 0
56927 - 0 0 0 0 0 0 0 0 0 0 0 0
56928 - 0 0 0 0 0 0 0 0 0 0 0 0
56929 - 0 0 0 0 0 0 0 0 0 0 0 0
56930 - 0 0 0 0 0 0 0 0 0 0 0 0
56931 - 0 0 0 0 0 0 0 0 0 0 0 0
56932 - 0 0 0 0 0 0 0 0 0 0 0 0
56933 - 0 0 0 0 0 0 0 0 0 0 0 0
56934 - 0 0 0 0 0 0 0 0 0 10 10 10
56935 - 34 34 34 82 82 82 30 30 30 61 42 6
56936 -180 123 7 206 145 10 230 174 11 239 182 13
56937 -234 190 10 238 202 15 241 208 19 246 218 74
56938 -246 218 38 246 215 20 246 215 20 246 215 20
56939 -226 184 13 215 174 15 184 144 12 6 6 6
56940 - 2 2 6 2 2 6 2 2 6 2 2 6
56941 - 26 26 26 94 94 94 42 42 42 14 14 14
56942 - 0 0 0 0 0 0 0 0 0 0 0 0
56943 - 0 0 0 0 0 0 0 0 0 0 0 0
56944 - 0 0 0 0 0 0 0 0 0 0 0 0
56945 - 0 0 0 0 0 0 0 0 0 0 0 0
56946 - 0 0 0 0 0 0 0 0 0 0 0 0
56947 - 0 0 0 0 0 0 0 0 0 0 0 0
56948 - 0 0 0 0 0 0 0 0 0 0 0 0
56949 - 0 0 0 0 0 0 0 0 0 0 0 0
56950 - 0 0 0 0 0 0 0 0 0 0 0 0
56951 - 0 0 0 0 0 0 0 0 0 0 0 0
56952 - 0 0 0 0 0 0 0 0 0 0 0 0
56953 - 0 0 0 0 0 0 0 0 0 0 0 0
56954 - 0 0 0 0 0 0 0 0 0 10 10 10
56955 - 30 30 30 78 78 78 50 50 50 104 69 6
56956 -192 133 9 216 158 10 236 178 12 236 186 11
56957 -232 195 16 241 208 19 244 214 54 245 215 43
56958 -246 215 20 246 215 20 241 208 19 198 155 10
56959 -200 144 11 216 158 10 156 118 10 2 2 6
56960 - 2 2 6 2 2 6 2 2 6 2 2 6
56961 - 6 6 6 90 90 90 54 54 54 18 18 18
56962 - 6 6 6 0 0 0 0 0 0 0 0 0
56963 - 0 0 0 0 0 0 0 0 0 0 0 0
56964 - 0 0 0 0 0 0 0 0 0 0 0 0
56965 - 0 0 0 0 0 0 0 0 0 0 0 0
56966 - 0 0 0 0 0 0 0 0 0 0 0 0
56967 - 0 0 0 0 0 0 0 0 0 0 0 0
56968 - 0 0 0 0 0 0 0 0 0 0 0 0
56969 - 0 0 0 0 0 0 0 0 0 0 0 0
56970 - 0 0 0 0 0 0 0 0 0 0 0 0
56971 - 0 0 0 0 0 0 0 0 0 0 0 0
56972 - 0 0 0 0 0 0 0 0 0 0 0 0
56973 - 0 0 0 0 0 0 0 0 0 0 0 0
56974 - 0 0 0 0 0 0 0 0 0 10 10 10
56975 - 30 30 30 78 78 78 46 46 46 22 22 22
56976 -137 92 6 210 162 10 239 182 13 238 190 10
56977 -238 202 15 241 208 19 246 215 20 246 215 20
56978 -241 208 19 203 166 17 185 133 11 210 150 10
56979 -216 158 10 210 150 10 102 78 10 2 2 6
56980 - 6 6 6 54 54 54 14 14 14 2 2 6
56981 - 2 2 6 62 62 62 74 74 74 30 30 30
56982 - 10 10 10 0 0 0 0 0 0 0 0 0
56983 - 0 0 0 0 0 0 0 0 0 0 0 0
56984 - 0 0 0 0 0 0 0 0 0 0 0 0
56985 - 0 0 0 0 0 0 0 0 0 0 0 0
56986 - 0 0 0 0 0 0 0 0 0 0 0 0
56987 - 0 0 0 0 0 0 0 0 0 0 0 0
56988 - 0 0 0 0 0 0 0 0 0 0 0 0
56989 - 0 0 0 0 0 0 0 0 0 0 0 0
56990 - 0 0 0 0 0 0 0 0 0 0 0 0
56991 - 0 0 0 0 0 0 0 0 0 0 0 0
56992 - 0 0 0 0 0 0 0 0 0 0 0 0
56993 - 0 0 0 0 0 0 0 0 0 0 0 0
56994 - 0 0 0 0 0 0 0 0 0 10 10 10
56995 - 34 34 34 78 78 78 50 50 50 6 6 6
56996 - 94 70 30 139 102 15 190 146 13 226 184 13
56997 -232 200 30 232 195 16 215 174 15 190 146 13
56998 -168 122 10 192 133 9 210 150 10 213 154 11
56999 -202 150 34 182 157 106 101 98 89 2 2 6
57000 - 2 2 6 78 78 78 116 116 116 58 58 58
57001 - 2 2 6 22 22 22 90 90 90 46 46 46
57002 - 18 18 18 6 6 6 0 0 0 0 0 0
57003 - 0 0 0 0 0 0 0 0 0 0 0 0
57004 - 0 0 0 0 0 0 0 0 0 0 0 0
57005 - 0 0 0 0 0 0 0 0 0 0 0 0
57006 - 0 0 0 0 0 0 0 0 0 0 0 0
57007 - 0 0 0 0 0 0 0 0 0 0 0 0
57008 - 0 0 0 0 0 0 0 0 0 0 0 0
57009 - 0 0 0 0 0 0 0 0 0 0 0 0
57010 - 0 0 0 0 0 0 0 0 0 0 0 0
57011 - 0 0 0 0 0 0 0 0 0 0 0 0
57012 - 0 0 0 0 0 0 0 0 0 0 0 0
57013 - 0 0 0 0 0 0 0 0 0 0 0 0
57014 - 0 0 0 0 0 0 0 0 0 10 10 10
57015 - 38 38 38 86 86 86 50 50 50 6 6 6
57016 -128 128 128 174 154 114 156 107 11 168 122 10
57017 -198 155 10 184 144 12 197 138 11 200 144 11
57018 -206 145 10 206 145 10 197 138 11 188 164 115
57019 -195 195 195 198 198 198 174 174 174 14 14 14
57020 - 2 2 6 22 22 22 116 116 116 116 116 116
57021 - 22 22 22 2 2 6 74 74 74 70 70 70
57022 - 30 30 30 10 10 10 0 0 0 0 0 0
57023 - 0 0 0 0 0 0 0 0 0 0 0 0
57024 - 0 0 0 0 0 0 0 0 0 0 0 0
57025 - 0 0 0 0 0 0 0 0 0 0 0 0
57026 - 0 0 0 0 0 0 0 0 0 0 0 0
57027 - 0 0 0 0 0 0 0 0 0 0 0 0
57028 - 0 0 0 0 0 0 0 0 0 0 0 0
57029 - 0 0 0 0 0 0 0 0 0 0 0 0
57030 - 0 0 0 0 0 0 0 0 0 0 0 0
57031 - 0 0 0 0 0 0 0 0 0 0 0 0
57032 - 0 0 0 0 0 0 0 0 0 0 0 0
57033 - 0 0 0 0 0 0 0 0 0 0 0 0
57034 - 0 0 0 0 0 0 6 6 6 18 18 18
57035 - 50 50 50 101 101 101 26 26 26 10 10 10
57036 -138 138 138 190 190 190 174 154 114 156 107 11
57037 -197 138 11 200 144 11 197 138 11 192 133 9
57038 -180 123 7 190 142 34 190 178 144 187 187 187
57039 -202 202 202 221 221 221 214 214 214 66 66 66
57040 - 2 2 6 2 2 6 50 50 50 62 62 62
57041 - 6 6 6 2 2 6 10 10 10 90 90 90
57042 - 50 50 50 18 18 18 6 6 6 0 0 0
57043 - 0 0 0 0 0 0 0 0 0 0 0 0
57044 - 0 0 0 0 0 0 0 0 0 0 0 0
57045 - 0 0 0 0 0 0 0 0 0 0 0 0
57046 - 0 0 0 0 0 0 0 0 0 0 0 0
57047 - 0 0 0 0 0 0 0 0 0 0 0 0
57048 - 0 0 0 0 0 0 0 0 0 0 0 0
57049 - 0 0 0 0 0 0 0 0 0 0 0 0
57050 - 0 0 0 0 0 0 0 0 0 0 0 0
57051 - 0 0 0 0 0 0 0 0 0 0 0 0
57052 - 0 0 0 0 0 0 0 0 0 0 0 0
57053 - 0 0 0 0 0 0 0 0 0 0 0 0
57054 - 0 0 0 0 0 0 10 10 10 34 34 34
57055 - 74 74 74 74 74 74 2 2 6 6 6 6
57056 -144 144 144 198 198 198 190 190 190 178 166 146
57057 -154 121 60 156 107 11 156 107 11 168 124 44
57058 -174 154 114 187 187 187 190 190 190 210 210 210
57059 -246 246 246 253 253 253 253 253 253 182 182 182
57060 - 6 6 6 2 2 6 2 2 6 2 2 6
57061 - 2 2 6 2 2 6 2 2 6 62 62 62
57062 - 74 74 74 34 34 34 14 14 14 0 0 0
57063 - 0 0 0 0 0 0 0 0 0 0 0 0
57064 - 0 0 0 0 0 0 0 0 0 0 0 0
57065 - 0 0 0 0 0 0 0 0 0 0 0 0
57066 - 0 0 0 0 0 0 0 0 0 0 0 0
57067 - 0 0 0 0 0 0 0 0 0 0 0 0
57068 - 0 0 0 0 0 0 0 0 0 0 0 0
57069 - 0 0 0 0 0 0 0 0 0 0 0 0
57070 - 0 0 0 0 0 0 0 0 0 0 0 0
57071 - 0 0 0 0 0 0 0 0 0 0 0 0
57072 - 0 0 0 0 0 0 0 0 0 0 0 0
57073 - 0 0 0 0 0 0 0 0 0 0 0 0
57074 - 0 0 0 10 10 10 22 22 22 54 54 54
57075 - 94 94 94 18 18 18 2 2 6 46 46 46
57076 -234 234 234 221 221 221 190 190 190 190 190 190
57077 -190 190 190 187 187 187 187 187 187 190 190 190
57078 -190 190 190 195 195 195 214 214 214 242 242 242
57079 -253 253 253 253 253 253 253 253 253 253 253 253
57080 - 82 82 82 2 2 6 2 2 6 2 2 6
57081 - 2 2 6 2 2 6 2 2 6 14 14 14
57082 - 86 86 86 54 54 54 22 22 22 6 6 6
57083 - 0 0 0 0 0 0 0 0 0 0 0 0
57084 - 0 0 0 0 0 0 0 0 0 0 0 0
57085 - 0 0 0 0 0 0 0 0 0 0 0 0
57086 - 0 0 0 0 0 0 0 0 0 0 0 0
57087 - 0 0 0 0 0 0 0 0 0 0 0 0
57088 - 0 0 0 0 0 0 0 0 0 0 0 0
57089 - 0 0 0 0 0 0 0 0 0 0 0 0
57090 - 0 0 0 0 0 0 0 0 0 0 0 0
57091 - 0 0 0 0 0 0 0 0 0 0 0 0
57092 - 0 0 0 0 0 0 0 0 0 0 0 0
57093 - 0 0 0 0 0 0 0 0 0 0 0 0
57094 - 6 6 6 18 18 18 46 46 46 90 90 90
57095 - 46 46 46 18 18 18 6 6 6 182 182 182
57096 -253 253 253 246 246 246 206 206 206 190 190 190
57097 -190 190 190 190 190 190 190 190 190 190 190 190
57098 -206 206 206 231 231 231 250 250 250 253 253 253
57099 -253 253 253 253 253 253 253 253 253 253 253 253
57100 -202 202 202 14 14 14 2 2 6 2 2 6
57101 - 2 2 6 2 2 6 2 2 6 2 2 6
57102 - 42 42 42 86 86 86 42 42 42 18 18 18
57103 - 6 6 6 0 0 0 0 0 0 0 0 0
57104 - 0 0 0 0 0 0 0 0 0 0 0 0
57105 - 0 0 0 0 0 0 0 0 0 0 0 0
57106 - 0 0 0 0 0 0 0 0 0 0 0 0
57107 - 0 0 0 0 0 0 0 0 0 0 0 0
57108 - 0 0 0 0 0 0 0 0 0 0 0 0
57109 - 0 0 0 0 0 0 0 0 0 0 0 0
57110 - 0 0 0 0 0 0 0 0 0 0 0 0
57111 - 0 0 0 0 0 0 0 0 0 0 0 0
57112 - 0 0 0 0 0 0 0 0 0 0 0 0
57113 - 0 0 0 0 0 0 0 0 0 6 6 6
57114 - 14 14 14 38 38 38 74 74 74 66 66 66
57115 - 2 2 6 6 6 6 90 90 90 250 250 250
57116 -253 253 253 253 253 253 238 238 238 198 198 198
57117 -190 190 190 190 190 190 195 195 195 221 221 221
57118 -246 246 246 253 253 253 253 253 253 253 253 253
57119 -253 253 253 253 253 253 253 253 253 253 253 253
57120 -253 253 253 82 82 82 2 2 6 2 2 6
57121 - 2 2 6 2 2 6 2 2 6 2 2 6
57122 - 2 2 6 78 78 78 70 70 70 34 34 34
57123 - 14 14 14 6 6 6 0 0 0 0 0 0
57124 - 0 0 0 0 0 0 0 0 0 0 0 0
57125 - 0 0 0 0 0 0 0 0 0 0 0 0
57126 - 0 0 0 0 0 0 0 0 0 0 0 0
57127 - 0 0 0 0 0 0 0 0 0 0 0 0
57128 - 0 0 0 0 0 0 0 0 0 0 0 0
57129 - 0 0 0 0 0 0 0 0 0 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 - 0 0 0 0 0 0 0 0 0 14 14 14
57134 - 34 34 34 66 66 66 78 78 78 6 6 6
57135 - 2 2 6 18 18 18 218 218 218 253 253 253
57136 -253 253 253 253 253 253 253 253 253 246 246 246
57137 -226 226 226 231 231 231 246 246 246 253 253 253
57138 -253 253 253 253 253 253 253 253 253 253 253 253
57139 -253 253 253 253 253 253 253 253 253 253 253 253
57140 -253 253 253 178 178 178 2 2 6 2 2 6
57141 - 2 2 6 2 2 6 2 2 6 2 2 6
57142 - 2 2 6 18 18 18 90 90 90 62 62 62
57143 - 30 30 30 10 10 10 0 0 0 0 0 0
57144 - 0 0 0 0 0 0 0 0 0 0 0 0
57145 - 0 0 0 0 0 0 0 0 0 0 0 0
57146 - 0 0 0 0 0 0 0 0 0 0 0 0
57147 - 0 0 0 0 0 0 0 0 0 0 0 0
57148 - 0 0 0 0 0 0 0 0 0 0 0 0
57149 - 0 0 0 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 0 0 0 10 10 10 26 26 26
57154 - 58 58 58 90 90 90 18 18 18 2 2 6
57155 - 2 2 6 110 110 110 253 253 253 253 253 253
57156 -253 253 253 253 253 253 253 253 253 253 253 253
57157 -250 250 250 253 253 253 253 253 253 253 253 253
57158 -253 253 253 253 253 253 253 253 253 253 253 253
57159 -253 253 253 253 253 253 253 253 253 253 253 253
57160 -253 253 253 231 231 231 18 18 18 2 2 6
57161 - 2 2 6 2 2 6 2 2 6 2 2 6
57162 - 2 2 6 2 2 6 18 18 18 94 94 94
57163 - 54 54 54 26 26 26 10 10 10 0 0 0
57164 - 0 0 0 0 0 0 0 0 0 0 0 0
57165 - 0 0 0 0 0 0 0 0 0 0 0 0
57166 - 0 0 0 0 0 0 0 0 0 0 0 0
57167 - 0 0 0 0 0 0 0 0 0 0 0 0
57168 - 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6 22 22 22 50 50 50
57174 - 90 90 90 26 26 26 2 2 6 2 2 6
57175 - 14 14 14 195 195 195 250 250 250 253 253 253
57176 -253 253 253 253 253 253 253 253 253 253 253 253
57177 -253 253 253 253 253 253 253 253 253 253 253 253
57178 -253 253 253 253 253 253 253 253 253 253 253 253
57179 -253 253 253 253 253 253 253 253 253 253 253 253
57180 -250 250 250 242 242 242 54 54 54 2 2 6
57181 - 2 2 6 2 2 6 2 2 6 2 2 6
57182 - 2 2 6 2 2 6 2 2 6 38 38 38
57183 - 86 86 86 50 50 50 22 22 22 6 6 6
57184 - 0 0 0 0 0 0 0 0 0 0 0 0
57185 - 0 0 0 0 0 0 0 0 0 0 0 0
57186 - 0 0 0 0 0 0 0 0 0 0 0 0
57187 - 0 0 0 0 0 0 0 0 0 0 0 0
57188 - 0 0 0 0 0 0 0 0 0 0 0 0
57189 - 0 0 0 0 0 0 0 0 0 0 0 0
57190 - 0 0 0 0 0 0 0 0 0 0 0 0
57191 - 0 0 0 0 0 0 0 0 0 0 0 0
57192 - 0 0 0 0 0 0 0 0 0 0 0 0
57193 - 6 6 6 14 14 14 38 38 38 82 82 82
57194 - 34 34 34 2 2 6 2 2 6 2 2 6
57195 - 42 42 42 195 195 195 246 246 246 253 253 253
57196 -253 253 253 253 253 253 253 253 253 250 250 250
57197 -242 242 242 242 242 242 250 250 250 253 253 253
57198 -253 253 253 253 253 253 253 253 253 253 253 253
57199 -253 253 253 250 250 250 246 246 246 238 238 238
57200 -226 226 226 231 231 231 101 101 101 6 6 6
57201 - 2 2 6 2 2 6 2 2 6 2 2 6
57202 - 2 2 6 2 2 6 2 2 6 2 2 6
57203 - 38 38 38 82 82 82 42 42 42 14 14 14
57204 - 6 6 6 0 0 0 0 0 0 0 0 0
57205 - 0 0 0 0 0 0 0 0 0 0 0 0
57206 - 0 0 0 0 0 0 0 0 0 0 0 0
57207 - 0 0 0 0 0 0 0 0 0 0 0 0
57208 - 0 0 0 0 0 0 0 0 0 0 0 0
57209 - 0 0 0 0 0 0 0 0 0 0 0 0
57210 - 0 0 0 0 0 0 0 0 0 0 0 0
57211 - 0 0 0 0 0 0 0 0 0 0 0 0
57212 - 0 0 0 0 0 0 0 0 0 0 0 0
57213 - 10 10 10 26 26 26 62 62 62 66 66 66
57214 - 2 2 6 2 2 6 2 2 6 6 6 6
57215 - 70 70 70 170 170 170 206 206 206 234 234 234
57216 -246 246 246 250 250 250 250 250 250 238 238 238
57217 -226 226 226 231 231 231 238 238 238 250 250 250
57218 -250 250 250 250 250 250 246 246 246 231 231 231
57219 -214 214 214 206 206 206 202 202 202 202 202 202
57220 -198 198 198 202 202 202 182 182 182 18 18 18
57221 - 2 2 6 2 2 6 2 2 6 2 2 6
57222 - 2 2 6 2 2 6 2 2 6 2 2 6
57223 - 2 2 6 62 62 62 66 66 66 30 30 30
57224 - 10 10 10 0 0 0 0 0 0 0 0 0
57225 - 0 0 0 0 0 0 0 0 0 0 0 0
57226 - 0 0 0 0 0 0 0 0 0 0 0 0
57227 - 0 0 0 0 0 0 0 0 0 0 0 0
57228 - 0 0 0 0 0 0 0 0 0 0 0 0
57229 - 0 0 0 0 0 0 0 0 0 0 0 0
57230 - 0 0 0 0 0 0 0 0 0 0 0 0
57231 - 0 0 0 0 0 0 0 0 0 0 0 0
57232 - 0 0 0 0 0 0 0 0 0 0 0 0
57233 - 14 14 14 42 42 42 82 82 82 18 18 18
57234 - 2 2 6 2 2 6 2 2 6 10 10 10
57235 - 94 94 94 182 182 182 218 218 218 242 242 242
57236 -250 250 250 253 253 253 253 253 253 250 250 250
57237 -234 234 234 253 253 253 253 253 253 253 253 253
57238 -253 253 253 253 253 253 253 253 253 246 246 246
57239 -238 238 238 226 226 226 210 210 210 202 202 202
57240 -195 195 195 195 195 195 210 210 210 158 158 158
57241 - 6 6 6 14 14 14 50 50 50 14 14 14
57242 - 2 2 6 2 2 6 2 2 6 2 2 6
57243 - 2 2 6 6 6 6 86 86 86 46 46 46
57244 - 18 18 18 6 6 6 0 0 0 0 0 0
57245 - 0 0 0 0 0 0 0 0 0 0 0 0
57246 - 0 0 0 0 0 0 0 0 0 0 0 0
57247 - 0 0 0 0 0 0 0 0 0 0 0 0
57248 - 0 0 0 0 0 0 0 0 0 0 0 0
57249 - 0 0 0 0 0 0 0 0 0 0 0 0
57250 - 0 0 0 0 0 0 0 0 0 0 0 0
57251 - 0 0 0 0 0 0 0 0 0 0 0 0
57252 - 0 0 0 0 0 0 0 0 0 6 6 6
57253 - 22 22 22 54 54 54 70 70 70 2 2 6
57254 - 2 2 6 10 10 10 2 2 6 22 22 22
57255 -166 166 166 231 231 231 250 250 250 253 253 253
57256 -253 253 253 253 253 253 253 253 253 250 250 250
57257 -242 242 242 253 253 253 253 253 253 253 253 253
57258 -253 253 253 253 253 253 253 253 253 253 253 253
57259 -253 253 253 253 253 253 253 253 253 246 246 246
57260 -231 231 231 206 206 206 198 198 198 226 226 226
57261 - 94 94 94 2 2 6 6 6 6 38 38 38
57262 - 30 30 30 2 2 6 2 2 6 2 2 6
57263 - 2 2 6 2 2 6 62 62 62 66 66 66
57264 - 26 26 26 10 10 10 0 0 0 0 0 0
57265 - 0 0 0 0 0 0 0 0 0 0 0 0
57266 - 0 0 0 0 0 0 0 0 0 0 0 0
57267 - 0 0 0 0 0 0 0 0 0 0 0 0
57268 - 0 0 0 0 0 0 0 0 0 0 0 0
57269 - 0 0 0 0 0 0 0 0 0 0 0 0
57270 - 0 0 0 0 0 0 0 0 0 0 0 0
57271 - 0 0 0 0 0 0 0 0 0 0 0 0
57272 - 0 0 0 0 0 0 0 0 0 10 10 10
57273 - 30 30 30 74 74 74 50 50 50 2 2 6
57274 - 26 26 26 26 26 26 2 2 6 106 106 106
57275 -238 238 238 253 253 253 253 253 253 253 253 253
57276 -253 253 253 253 253 253 253 253 253 253 253 253
57277 -253 253 253 253 253 253 253 253 253 253 253 253
57278 -253 253 253 253 253 253 253 253 253 253 253 253
57279 -253 253 253 253 253 253 253 253 253 253 253 253
57280 -253 253 253 246 246 246 218 218 218 202 202 202
57281 -210 210 210 14 14 14 2 2 6 2 2 6
57282 - 30 30 30 22 22 22 2 2 6 2 2 6
57283 - 2 2 6 2 2 6 18 18 18 86 86 86
57284 - 42 42 42 14 14 14 0 0 0 0 0 0
57285 - 0 0 0 0 0 0 0 0 0 0 0 0
57286 - 0 0 0 0 0 0 0 0 0 0 0 0
57287 - 0 0 0 0 0 0 0 0 0 0 0 0
57288 - 0 0 0 0 0 0 0 0 0 0 0 0
57289 - 0 0 0 0 0 0 0 0 0 0 0 0
57290 - 0 0 0 0 0 0 0 0 0 0 0 0
57291 - 0 0 0 0 0 0 0 0 0 0 0 0
57292 - 0 0 0 0 0 0 0 0 0 14 14 14
57293 - 42 42 42 90 90 90 22 22 22 2 2 6
57294 - 42 42 42 2 2 6 18 18 18 218 218 218
57295 -253 253 253 253 253 253 253 253 253 253 253 253
57296 -253 253 253 253 253 253 253 253 253 253 253 253
57297 -253 253 253 253 253 253 253 253 253 253 253 253
57298 -253 253 253 253 253 253 253 253 253 253 253 253
57299 -253 253 253 253 253 253 253 253 253 253 253 253
57300 -253 253 253 253 253 253 250 250 250 221 221 221
57301 -218 218 218 101 101 101 2 2 6 14 14 14
57302 - 18 18 18 38 38 38 10 10 10 2 2 6
57303 - 2 2 6 2 2 6 2 2 6 78 78 78
57304 - 58 58 58 22 22 22 6 6 6 0 0 0
57305 - 0 0 0 0 0 0 0 0 0 0 0 0
57306 - 0 0 0 0 0 0 0 0 0 0 0 0
57307 - 0 0 0 0 0 0 0 0 0 0 0 0
57308 - 0 0 0 0 0 0 0 0 0 0 0 0
57309 - 0 0 0 0 0 0 0 0 0 0 0 0
57310 - 0 0 0 0 0 0 0 0 0 0 0 0
57311 - 0 0 0 0 0 0 0 0 0 0 0 0
57312 - 0 0 0 0 0 0 6 6 6 18 18 18
57313 - 54 54 54 82 82 82 2 2 6 26 26 26
57314 - 22 22 22 2 2 6 123 123 123 253 253 253
57315 -253 253 253 253 253 253 253 253 253 253 253 253
57316 -253 253 253 253 253 253 253 253 253 253 253 253
57317 -253 253 253 253 253 253 253 253 253 253 253 253
57318 -253 253 253 253 253 253 253 253 253 253 253 253
57319 -253 253 253 253 253 253 253 253 253 253 253 253
57320 -253 253 253 253 253 253 253 253 253 250 250 250
57321 -238 238 238 198 198 198 6 6 6 38 38 38
57322 - 58 58 58 26 26 26 38 38 38 2 2 6
57323 - 2 2 6 2 2 6 2 2 6 46 46 46
57324 - 78 78 78 30 30 30 10 10 10 0 0 0
57325 - 0 0 0 0 0 0 0 0 0 0 0 0
57326 - 0 0 0 0 0 0 0 0 0 0 0 0
57327 - 0 0 0 0 0 0 0 0 0 0 0 0
57328 - 0 0 0 0 0 0 0 0 0 0 0 0
57329 - 0 0 0 0 0 0 0 0 0 0 0 0
57330 - 0 0 0 0 0 0 0 0 0 0 0 0
57331 - 0 0 0 0 0 0 0 0 0 0 0 0
57332 - 0 0 0 0 0 0 10 10 10 30 30 30
57333 - 74 74 74 58 58 58 2 2 6 42 42 42
57334 - 2 2 6 22 22 22 231 231 231 253 253 253
57335 -253 253 253 253 253 253 253 253 253 253 253 253
57336 -253 253 253 253 253 253 253 253 253 250 250 250
57337 -253 253 253 253 253 253 253 253 253 253 253 253
57338 -253 253 253 253 253 253 253 253 253 253 253 253
57339 -253 253 253 253 253 253 253 253 253 253 253 253
57340 -253 253 253 253 253 253 253 253 253 253 253 253
57341 -253 253 253 246 246 246 46 46 46 38 38 38
57342 - 42 42 42 14 14 14 38 38 38 14 14 14
57343 - 2 2 6 2 2 6 2 2 6 6 6 6
57344 - 86 86 86 46 46 46 14 14 14 0 0 0
57345 - 0 0 0 0 0 0 0 0 0 0 0 0
57346 - 0 0 0 0 0 0 0 0 0 0 0 0
57347 - 0 0 0 0 0 0 0 0 0 0 0 0
57348 - 0 0 0 0 0 0 0 0 0 0 0 0
57349 - 0 0 0 0 0 0 0 0 0 0 0 0
57350 - 0 0 0 0 0 0 0 0 0 0 0 0
57351 - 0 0 0 0 0 0 0 0 0 0 0 0
57352 - 0 0 0 6 6 6 14 14 14 42 42 42
57353 - 90 90 90 18 18 18 18 18 18 26 26 26
57354 - 2 2 6 116 116 116 253 253 253 253 253 253
57355 -253 253 253 253 253 253 253 253 253 253 253 253
57356 -253 253 253 253 253 253 250 250 250 238 238 238
57357 -253 253 253 253 253 253 253 253 253 253 253 253
57358 -253 253 253 253 253 253 253 253 253 253 253 253
57359 -253 253 253 253 253 253 253 253 253 253 253 253
57360 -253 253 253 253 253 253 253 253 253 253 253 253
57361 -253 253 253 253 253 253 94 94 94 6 6 6
57362 - 2 2 6 2 2 6 10 10 10 34 34 34
57363 - 2 2 6 2 2 6 2 2 6 2 2 6
57364 - 74 74 74 58 58 58 22 22 22 6 6 6
57365 - 0 0 0 0 0 0 0 0 0 0 0 0
57366 - 0 0 0 0 0 0 0 0 0 0 0 0
57367 - 0 0 0 0 0 0 0 0 0 0 0 0
57368 - 0 0 0 0 0 0 0 0 0 0 0 0
57369 - 0 0 0 0 0 0 0 0 0 0 0 0
57370 - 0 0 0 0 0 0 0 0 0 0 0 0
57371 - 0 0 0 0 0 0 0 0 0 0 0 0
57372 - 0 0 0 10 10 10 26 26 26 66 66 66
57373 - 82 82 82 2 2 6 38 38 38 6 6 6
57374 - 14 14 14 210 210 210 253 253 253 253 253 253
57375 -253 253 253 253 253 253 253 253 253 253 253 253
57376 -253 253 253 253 253 253 246 246 246 242 242 242
57377 -253 253 253 253 253 253 253 253 253 253 253 253
57378 -253 253 253 253 253 253 253 253 253 253 253 253
57379 -253 253 253 253 253 253 253 253 253 253 253 253
57380 -253 253 253 253 253 253 253 253 253 253 253 253
57381 -253 253 253 253 253 253 144 144 144 2 2 6
57382 - 2 2 6 2 2 6 2 2 6 46 46 46
57383 - 2 2 6 2 2 6 2 2 6 2 2 6
57384 - 42 42 42 74 74 74 30 30 30 10 10 10
57385 - 0 0 0 0 0 0 0 0 0 0 0 0
57386 - 0 0 0 0 0 0 0 0 0 0 0 0
57387 - 0 0 0 0 0 0 0 0 0 0 0 0
57388 - 0 0 0 0 0 0 0 0 0 0 0 0
57389 - 0 0 0 0 0 0 0 0 0 0 0 0
57390 - 0 0 0 0 0 0 0 0 0 0 0 0
57391 - 0 0 0 0 0 0 0 0 0 0 0 0
57392 - 6 6 6 14 14 14 42 42 42 90 90 90
57393 - 26 26 26 6 6 6 42 42 42 2 2 6
57394 - 74 74 74 250 250 250 253 253 253 253 253 253
57395 -253 253 253 253 253 253 253 253 253 253 253 253
57396 -253 253 253 253 253 253 242 242 242 242 242 242
57397 -253 253 253 253 253 253 253 253 253 253 253 253
57398 -253 253 253 253 253 253 253 253 253 253 253 253
57399 -253 253 253 253 253 253 253 253 253 253 253 253
57400 -253 253 253 253 253 253 253 253 253 253 253 253
57401 -253 253 253 253 253 253 182 182 182 2 2 6
57402 - 2 2 6 2 2 6 2 2 6 46 46 46
57403 - 2 2 6 2 2 6 2 2 6 2 2 6
57404 - 10 10 10 86 86 86 38 38 38 10 10 10
57405 - 0 0 0 0 0 0 0 0 0 0 0 0
57406 - 0 0 0 0 0 0 0 0 0 0 0 0
57407 - 0 0 0 0 0 0 0 0 0 0 0 0
57408 - 0 0 0 0 0 0 0 0 0 0 0 0
57409 - 0 0 0 0 0 0 0 0 0 0 0 0
57410 - 0 0 0 0 0 0 0 0 0 0 0 0
57411 - 0 0 0 0 0 0 0 0 0 0 0 0
57412 - 10 10 10 26 26 26 66 66 66 82 82 82
57413 - 2 2 6 22 22 22 18 18 18 2 2 6
57414 -149 149 149 253 253 253 253 253 253 253 253 253
57415 -253 253 253 253 253 253 253 253 253 253 253 253
57416 -253 253 253 253 253 253 234 234 234 242 242 242
57417 -253 253 253 253 253 253 253 253 253 253 253 253
57418 -253 253 253 253 253 253 253 253 253 253 253 253
57419 -253 253 253 253 253 253 253 253 253 253 253 253
57420 -253 253 253 253 253 253 253 253 253 253 253 253
57421 -253 253 253 253 253 253 206 206 206 2 2 6
57422 - 2 2 6 2 2 6 2 2 6 38 38 38
57423 - 2 2 6 2 2 6 2 2 6 2 2 6
57424 - 6 6 6 86 86 86 46 46 46 14 14 14
57425 - 0 0 0 0 0 0 0 0 0 0 0 0
57426 - 0 0 0 0 0 0 0 0 0 0 0 0
57427 - 0 0 0 0 0 0 0 0 0 0 0 0
57428 - 0 0 0 0 0 0 0 0 0 0 0 0
57429 - 0 0 0 0 0 0 0 0 0 0 0 0
57430 - 0 0 0 0 0 0 0 0 0 0 0 0
57431 - 0 0 0 0 0 0 0 0 0 6 6 6
57432 - 18 18 18 46 46 46 86 86 86 18 18 18
57433 - 2 2 6 34 34 34 10 10 10 6 6 6
57434 -210 210 210 253 253 253 253 253 253 253 253 253
57435 -253 253 253 253 253 253 253 253 253 253 253 253
57436 -253 253 253 253 253 253 234 234 234 242 242 242
57437 -253 253 253 253 253 253 253 253 253 253 253 253
57438 -253 253 253 253 253 253 253 253 253 253 253 253
57439 -253 253 253 253 253 253 253 253 253 253 253 253
57440 -253 253 253 253 253 253 253 253 253 253 253 253
57441 -253 253 253 253 253 253 221 221 221 6 6 6
57442 - 2 2 6 2 2 6 6 6 6 30 30 30
57443 - 2 2 6 2 2 6 2 2 6 2 2 6
57444 - 2 2 6 82 82 82 54 54 54 18 18 18
57445 - 6 6 6 0 0 0 0 0 0 0 0 0
57446 - 0 0 0 0 0 0 0 0 0 0 0 0
57447 - 0 0 0 0 0 0 0 0 0 0 0 0
57448 - 0 0 0 0 0 0 0 0 0 0 0 0
57449 - 0 0 0 0 0 0 0 0 0 0 0 0
57450 - 0 0 0 0 0 0 0 0 0 0 0 0
57451 - 0 0 0 0 0 0 0 0 0 10 10 10
57452 - 26 26 26 66 66 66 62 62 62 2 2 6
57453 - 2 2 6 38 38 38 10 10 10 26 26 26
57454 -238 238 238 253 253 253 253 253 253 253 253 253
57455 -253 253 253 253 253 253 253 253 253 253 253 253
57456 -253 253 253 253 253 253 231 231 231 238 238 238
57457 -253 253 253 253 253 253 253 253 253 253 253 253
57458 -253 253 253 253 253 253 253 253 253 253 253 253
57459 -253 253 253 253 253 253 253 253 253 253 253 253
57460 -253 253 253 253 253 253 253 253 253 253 253 253
57461 -253 253 253 253 253 253 231 231 231 6 6 6
57462 - 2 2 6 2 2 6 10 10 10 30 30 30
57463 - 2 2 6 2 2 6 2 2 6 2 2 6
57464 - 2 2 6 66 66 66 58 58 58 22 22 22
57465 - 6 6 6 0 0 0 0 0 0 0 0 0
57466 - 0 0 0 0 0 0 0 0 0 0 0 0
57467 - 0 0 0 0 0 0 0 0 0 0 0 0
57468 - 0 0 0 0 0 0 0 0 0 0 0 0
57469 - 0 0 0 0 0 0 0 0 0 0 0 0
57470 - 0 0 0 0 0 0 0 0 0 0 0 0
57471 - 0 0 0 0 0 0 0 0 0 10 10 10
57472 - 38 38 38 78 78 78 6 6 6 2 2 6
57473 - 2 2 6 46 46 46 14 14 14 42 42 42
57474 -246 246 246 253 253 253 253 253 253 253 253 253
57475 -253 253 253 253 253 253 253 253 253 253 253 253
57476 -253 253 253 253 253 253 231 231 231 242 242 242
57477 -253 253 253 253 253 253 253 253 253 253 253 253
57478 -253 253 253 253 253 253 253 253 253 253 253 253
57479 -253 253 253 253 253 253 253 253 253 253 253 253
57480 -253 253 253 253 253 253 253 253 253 253 253 253
57481 -253 253 253 253 253 253 234 234 234 10 10 10
57482 - 2 2 6 2 2 6 22 22 22 14 14 14
57483 - 2 2 6 2 2 6 2 2 6 2 2 6
57484 - 2 2 6 66 66 66 62 62 62 22 22 22
57485 - 6 6 6 0 0 0 0 0 0 0 0 0
57486 - 0 0 0 0 0 0 0 0 0 0 0 0
57487 - 0 0 0 0 0 0 0 0 0 0 0 0
57488 - 0 0 0 0 0 0 0 0 0 0 0 0
57489 - 0 0 0 0 0 0 0 0 0 0 0 0
57490 - 0 0 0 0 0 0 0 0 0 0 0 0
57491 - 0 0 0 0 0 0 6 6 6 18 18 18
57492 - 50 50 50 74 74 74 2 2 6 2 2 6
57493 - 14 14 14 70 70 70 34 34 34 62 62 62
57494 -250 250 250 253 253 253 253 253 253 253 253 253
57495 -253 253 253 253 253 253 253 253 253 253 253 253
57496 -253 253 253 253 253 253 231 231 231 246 246 246
57497 -253 253 253 253 253 253 253 253 253 253 253 253
57498 -253 253 253 253 253 253 253 253 253 253 253 253
57499 -253 253 253 253 253 253 253 253 253 253 253 253
57500 -253 253 253 253 253 253 253 253 253 253 253 253
57501 -253 253 253 253 253 253 234 234 234 14 14 14
57502 - 2 2 6 2 2 6 30 30 30 2 2 6
57503 - 2 2 6 2 2 6 2 2 6 2 2 6
57504 - 2 2 6 66 66 66 62 62 62 22 22 22
57505 - 6 6 6 0 0 0 0 0 0 0 0 0
57506 - 0 0 0 0 0 0 0 0 0 0 0 0
57507 - 0 0 0 0 0 0 0 0 0 0 0 0
57508 - 0 0 0 0 0 0 0 0 0 0 0 0
57509 - 0 0 0 0 0 0 0 0 0 0 0 0
57510 - 0 0 0 0 0 0 0 0 0 0 0 0
57511 - 0 0 0 0 0 0 6 6 6 18 18 18
57512 - 54 54 54 62 62 62 2 2 6 2 2 6
57513 - 2 2 6 30 30 30 46 46 46 70 70 70
57514 -250 250 250 253 253 253 253 253 253 253 253 253
57515 -253 253 253 253 253 253 253 253 253 253 253 253
57516 -253 253 253 253 253 253 231 231 231 246 246 246
57517 -253 253 253 253 253 253 253 253 253 253 253 253
57518 -253 253 253 253 253 253 253 253 253 253 253 253
57519 -253 253 253 253 253 253 253 253 253 253 253 253
57520 -253 253 253 253 253 253 253 253 253 253 253 253
57521 -253 253 253 253 253 253 226 226 226 10 10 10
57522 - 2 2 6 6 6 6 30 30 30 2 2 6
57523 - 2 2 6 2 2 6 2 2 6 2 2 6
57524 - 2 2 6 66 66 66 58 58 58 22 22 22
57525 - 6 6 6 0 0 0 0 0 0 0 0 0
57526 - 0 0 0 0 0 0 0 0 0 0 0 0
57527 - 0 0 0 0 0 0 0 0 0 0 0 0
57528 - 0 0 0 0 0 0 0 0 0 0 0 0
57529 - 0 0 0 0 0 0 0 0 0 0 0 0
57530 - 0 0 0 0 0 0 0 0 0 0 0 0
57531 - 0 0 0 0 0 0 6 6 6 22 22 22
57532 - 58 58 58 62 62 62 2 2 6 2 2 6
57533 - 2 2 6 2 2 6 30 30 30 78 78 78
57534 -250 250 250 253 253 253 253 253 253 253 253 253
57535 -253 253 253 253 253 253 253 253 253 253 253 253
57536 -253 253 253 253 253 253 231 231 231 246 246 246
57537 -253 253 253 253 253 253 253 253 253 253 253 253
57538 -253 253 253 253 253 253 253 253 253 253 253 253
57539 -253 253 253 253 253 253 253 253 253 253 253 253
57540 -253 253 253 253 253 253 253 253 253 253 253 253
57541 -253 253 253 253 253 253 206 206 206 2 2 6
57542 - 22 22 22 34 34 34 18 14 6 22 22 22
57543 - 26 26 26 18 18 18 6 6 6 2 2 6
57544 - 2 2 6 82 82 82 54 54 54 18 18 18
57545 - 6 6 6 0 0 0 0 0 0 0 0 0
57546 - 0 0 0 0 0 0 0 0 0 0 0 0
57547 - 0 0 0 0 0 0 0 0 0 0 0 0
57548 - 0 0 0 0 0 0 0 0 0 0 0 0
57549 - 0 0 0 0 0 0 0 0 0 0 0 0
57550 - 0 0 0 0 0 0 0 0 0 0 0 0
57551 - 0 0 0 0 0 0 6 6 6 26 26 26
57552 - 62 62 62 106 106 106 74 54 14 185 133 11
57553 -210 162 10 121 92 8 6 6 6 62 62 62
57554 -238 238 238 253 253 253 253 253 253 253 253 253
57555 -253 253 253 253 253 253 253 253 253 253 253 253
57556 -253 253 253 253 253 253 231 231 231 246 246 246
57557 -253 253 253 253 253 253 253 253 253 253 253 253
57558 -253 253 253 253 253 253 253 253 253 253 253 253
57559 -253 253 253 253 253 253 253 253 253 253 253 253
57560 -253 253 253 253 253 253 253 253 253 253 253 253
57561 -253 253 253 253 253 253 158 158 158 18 18 18
57562 - 14 14 14 2 2 6 2 2 6 2 2 6
57563 - 6 6 6 18 18 18 66 66 66 38 38 38
57564 - 6 6 6 94 94 94 50 50 50 18 18 18
57565 - 6 6 6 0 0 0 0 0 0 0 0 0
57566 - 0 0 0 0 0 0 0 0 0 0 0 0
57567 - 0 0 0 0 0 0 0 0 0 0 0 0
57568 - 0 0 0 0 0 0 0 0 0 0 0 0
57569 - 0 0 0 0 0 0 0 0 0 0 0 0
57570 - 0 0 0 0 0 0 0 0 0 6 6 6
57571 - 10 10 10 10 10 10 18 18 18 38 38 38
57572 - 78 78 78 142 134 106 216 158 10 242 186 14
57573 -246 190 14 246 190 14 156 118 10 10 10 10
57574 - 90 90 90 238 238 238 253 253 253 253 253 253
57575 -253 253 253 253 253 253 253 253 253 253 253 253
57576 -253 253 253 253 253 253 231 231 231 250 250 250
57577 -253 253 253 253 253 253 253 253 253 253 253 253
57578 -253 253 253 253 253 253 253 253 253 253 253 253
57579 -253 253 253 253 253 253 253 253 253 253 253 253
57580 -253 253 253 253 253 253 253 253 253 246 230 190
57581 -238 204 91 238 204 91 181 142 44 37 26 9
57582 - 2 2 6 2 2 6 2 2 6 2 2 6
57583 - 2 2 6 2 2 6 38 38 38 46 46 46
57584 - 26 26 26 106 106 106 54 54 54 18 18 18
57585 - 6 6 6 0 0 0 0 0 0 0 0 0
57586 - 0 0 0 0 0 0 0 0 0 0 0 0
57587 - 0 0 0 0 0 0 0 0 0 0 0 0
57588 - 0 0 0 0 0 0 0 0 0 0 0 0
57589 - 0 0 0 0 0 0 0 0 0 0 0 0
57590 - 0 0 0 6 6 6 14 14 14 22 22 22
57591 - 30 30 30 38 38 38 50 50 50 70 70 70
57592 -106 106 106 190 142 34 226 170 11 242 186 14
57593 -246 190 14 246 190 14 246 190 14 154 114 10
57594 - 6 6 6 74 74 74 226 226 226 253 253 253
57595 -253 253 253 253 253 253 253 253 253 253 253 253
57596 -253 253 253 253 253 253 231 231 231 250 250 250
57597 -253 253 253 253 253 253 253 253 253 253 253 253
57598 -253 253 253 253 253 253 253 253 253 253 253 253
57599 -253 253 253 253 253 253 253 253 253 253 253 253
57600 -253 253 253 253 253 253 253 253 253 228 184 62
57601 -241 196 14 241 208 19 232 195 16 38 30 10
57602 - 2 2 6 2 2 6 2 2 6 2 2 6
57603 - 2 2 6 6 6 6 30 30 30 26 26 26
57604 -203 166 17 154 142 90 66 66 66 26 26 26
57605 - 6 6 6 0 0 0 0 0 0 0 0 0
57606 - 0 0 0 0 0 0 0 0 0 0 0 0
57607 - 0 0 0 0 0 0 0 0 0 0 0 0
57608 - 0 0 0 0 0 0 0 0 0 0 0 0
57609 - 0 0 0 0 0 0 0 0 0 0 0 0
57610 - 6 6 6 18 18 18 38 38 38 58 58 58
57611 - 78 78 78 86 86 86 101 101 101 123 123 123
57612 -175 146 61 210 150 10 234 174 13 246 186 14
57613 -246 190 14 246 190 14 246 190 14 238 190 10
57614 -102 78 10 2 2 6 46 46 46 198 198 198
57615 -253 253 253 253 253 253 253 253 253 253 253 253
57616 -253 253 253 253 253 253 234 234 234 242 242 242
57617 -253 253 253 253 253 253 253 253 253 253 253 253
57618 -253 253 253 253 253 253 253 253 253 253 253 253
57619 -253 253 253 253 253 253 253 253 253 253 253 253
57620 -253 253 253 253 253 253 253 253 253 224 178 62
57621 -242 186 14 241 196 14 210 166 10 22 18 6
57622 - 2 2 6 2 2 6 2 2 6 2 2 6
57623 - 2 2 6 2 2 6 6 6 6 121 92 8
57624 -238 202 15 232 195 16 82 82 82 34 34 34
57625 - 10 10 10 0 0 0 0 0 0 0 0 0
57626 - 0 0 0 0 0 0 0 0 0 0 0 0
57627 - 0 0 0 0 0 0 0 0 0 0 0 0
57628 - 0 0 0 0 0 0 0 0 0 0 0 0
57629 - 0 0 0 0 0 0 0 0 0 0 0 0
57630 - 14 14 14 38 38 38 70 70 70 154 122 46
57631 -190 142 34 200 144 11 197 138 11 197 138 11
57632 -213 154 11 226 170 11 242 186 14 246 190 14
57633 -246 190 14 246 190 14 246 190 14 246 190 14
57634 -225 175 15 46 32 6 2 2 6 22 22 22
57635 -158 158 158 250 250 250 253 253 253 253 253 253
57636 -253 253 253 253 253 253 253 253 253 253 253 253
57637 -253 253 253 253 253 253 253 253 253 253 253 253
57638 -253 253 253 253 253 253 253 253 253 253 253 253
57639 -253 253 253 253 253 253 253 253 253 253 253 253
57640 -253 253 253 250 250 250 242 242 242 224 178 62
57641 -239 182 13 236 186 11 213 154 11 46 32 6
57642 - 2 2 6 2 2 6 2 2 6 2 2 6
57643 - 2 2 6 2 2 6 61 42 6 225 175 15
57644 -238 190 10 236 186 11 112 100 78 42 42 42
57645 - 14 14 14 0 0 0 0 0 0 0 0 0
57646 - 0 0 0 0 0 0 0 0 0 0 0 0
57647 - 0 0 0 0 0 0 0 0 0 0 0 0
57648 - 0 0 0 0 0 0 0 0 0 0 0 0
57649 - 0 0 0 0 0 0 0 0 0 6 6 6
57650 - 22 22 22 54 54 54 154 122 46 213 154 11
57651 -226 170 11 230 174 11 226 170 11 226 170 11
57652 -236 178 12 242 186 14 246 190 14 246 190 14
57653 -246 190 14 246 190 14 246 190 14 246 190 14
57654 -241 196 14 184 144 12 10 10 10 2 2 6
57655 - 6 6 6 116 116 116 242 242 242 253 253 253
57656 -253 253 253 253 253 253 253 253 253 253 253 253
57657 -253 253 253 253 253 253 253 253 253 253 253 253
57658 -253 253 253 253 253 253 253 253 253 253 253 253
57659 -253 253 253 253 253 253 253 253 253 253 253 253
57660 -253 253 253 231 231 231 198 198 198 214 170 54
57661 -236 178 12 236 178 12 210 150 10 137 92 6
57662 - 18 14 6 2 2 6 2 2 6 2 2 6
57663 - 6 6 6 70 47 6 200 144 11 236 178 12
57664 -239 182 13 239 182 13 124 112 88 58 58 58
57665 - 22 22 22 6 6 6 0 0 0 0 0 0
57666 - 0 0 0 0 0 0 0 0 0 0 0 0
57667 - 0 0 0 0 0 0 0 0 0 0 0 0
57668 - 0 0 0 0 0 0 0 0 0 0 0 0
57669 - 0 0 0 0 0 0 0 0 0 10 10 10
57670 - 30 30 30 70 70 70 180 133 36 226 170 11
57671 -239 182 13 242 186 14 242 186 14 246 186 14
57672 -246 190 14 246 190 14 246 190 14 246 190 14
57673 -246 190 14 246 190 14 246 190 14 246 190 14
57674 -246 190 14 232 195 16 98 70 6 2 2 6
57675 - 2 2 6 2 2 6 66 66 66 221 221 221
57676 -253 253 253 253 253 253 253 253 253 253 253 253
57677 -253 253 253 253 253 253 253 253 253 253 253 253
57678 -253 253 253 253 253 253 253 253 253 253 253 253
57679 -253 253 253 253 253 253 253 253 253 253 253 253
57680 -253 253 253 206 206 206 198 198 198 214 166 58
57681 -230 174 11 230 174 11 216 158 10 192 133 9
57682 -163 110 8 116 81 8 102 78 10 116 81 8
57683 -167 114 7 197 138 11 226 170 11 239 182 13
57684 -242 186 14 242 186 14 162 146 94 78 78 78
57685 - 34 34 34 14 14 14 6 6 6 0 0 0
57686 - 0 0 0 0 0 0 0 0 0 0 0 0
57687 - 0 0 0 0 0 0 0 0 0 0 0 0
57688 - 0 0 0 0 0 0 0 0 0 0 0 0
57689 - 0 0 0 0 0 0 0 0 0 6 6 6
57690 - 30 30 30 78 78 78 190 142 34 226 170 11
57691 -239 182 13 246 190 14 246 190 14 246 190 14
57692 -246 190 14 246 190 14 246 190 14 246 190 14
57693 -246 190 14 246 190 14 246 190 14 246 190 14
57694 -246 190 14 241 196 14 203 166 17 22 18 6
57695 - 2 2 6 2 2 6 2 2 6 38 38 38
57696 -218 218 218 253 253 253 253 253 253 253 253 253
57697 -253 253 253 253 253 253 253 253 253 253 253 253
57698 -253 253 253 253 253 253 253 253 253 253 253 253
57699 -253 253 253 253 253 253 253 253 253 253 253 253
57700 -250 250 250 206 206 206 198 198 198 202 162 69
57701 -226 170 11 236 178 12 224 166 10 210 150 10
57702 -200 144 11 197 138 11 192 133 9 197 138 11
57703 -210 150 10 226 170 11 242 186 14 246 190 14
57704 -246 190 14 246 186 14 225 175 15 124 112 88
57705 - 62 62 62 30 30 30 14 14 14 6 6 6
57706 - 0 0 0 0 0 0 0 0 0 0 0 0
57707 - 0 0 0 0 0 0 0 0 0 0 0 0
57708 - 0 0 0 0 0 0 0 0 0 0 0 0
57709 - 0 0 0 0 0 0 0 0 0 10 10 10
57710 - 30 30 30 78 78 78 174 135 50 224 166 10
57711 -239 182 13 246 190 14 246 190 14 246 190 14
57712 -246 190 14 246 190 14 246 190 14 246 190 14
57713 -246 190 14 246 190 14 246 190 14 246 190 14
57714 -246 190 14 246 190 14 241 196 14 139 102 15
57715 - 2 2 6 2 2 6 2 2 6 2 2 6
57716 - 78 78 78 250 250 250 253 253 253 253 253 253
57717 -253 253 253 253 253 253 253 253 253 253 253 253
57718 -253 253 253 253 253 253 253 253 253 253 253 253
57719 -253 253 253 253 253 253 253 253 253 253 253 253
57720 -250 250 250 214 214 214 198 198 198 190 150 46
57721 -219 162 10 236 178 12 234 174 13 224 166 10
57722 -216 158 10 213 154 11 213 154 11 216 158 10
57723 -226 170 11 239 182 13 246 190 14 246 190 14
57724 -246 190 14 246 190 14 242 186 14 206 162 42
57725 -101 101 101 58 58 58 30 30 30 14 14 14
57726 - 6 6 6 0 0 0 0 0 0 0 0 0
57727 - 0 0 0 0 0 0 0 0 0 0 0 0
57728 - 0 0 0 0 0 0 0 0 0 0 0 0
57729 - 0 0 0 0 0 0 0 0 0 10 10 10
57730 - 30 30 30 74 74 74 174 135 50 216 158 10
57731 -236 178 12 246 190 14 246 190 14 246 190 14
57732 -246 190 14 246 190 14 246 190 14 246 190 14
57733 -246 190 14 246 190 14 246 190 14 246 190 14
57734 -246 190 14 246 190 14 241 196 14 226 184 13
57735 - 61 42 6 2 2 6 2 2 6 2 2 6
57736 - 22 22 22 238 238 238 253 253 253 253 253 253
57737 -253 253 253 253 253 253 253 253 253 253 253 253
57738 -253 253 253 253 253 253 253 253 253 253 253 253
57739 -253 253 253 253 253 253 253 253 253 253 253 253
57740 -253 253 253 226 226 226 187 187 187 180 133 36
57741 -216 158 10 236 178 12 239 182 13 236 178 12
57742 -230 174 11 226 170 11 226 170 11 230 174 11
57743 -236 178 12 242 186 14 246 190 14 246 190 14
57744 -246 190 14 246 190 14 246 186 14 239 182 13
57745 -206 162 42 106 106 106 66 66 66 34 34 34
57746 - 14 14 14 6 6 6 0 0 0 0 0 0
57747 - 0 0 0 0 0 0 0 0 0 0 0 0
57748 - 0 0 0 0 0 0 0 0 0 0 0 0
57749 - 0 0 0 0 0 0 0 0 0 6 6 6
57750 - 26 26 26 70 70 70 163 133 67 213 154 11
57751 -236 178 12 246 190 14 246 190 14 246 190 14
57752 -246 190 14 246 190 14 246 190 14 246 190 14
57753 -246 190 14 246 190 14 246 190 14 246 190 14
57754 -246 190 14 246 190 14 246 190 14 241 196 14
57755 -190 146 13 18 14 6 2 2 6 2 2 6
57756 - 46 46 46 246 246 246 253 253 253 253 253 253
57757 -253 253 253 253 253 253 253 253 253 253 253 253
57758 -253 253 253 253 253 253 253 253 253 253 253 253
57759 -253 253 253 253 253 253 253 253 253 253 253 253
57760 -253 253 253 221 221 221 86 86 86 156 107 11
57761 -216 158 10 236 178 12 242 186 14 246 186 14
57762 -242 186 14 239 182 13 239 182 13 242 186 14
57763 -242 186 14 246 186 14 246 190 14 246 190 14
57764 -246 190 14 246 190 14 246 190 14 246 190 14
57765 -242 186 14 225 175 15 142 122 72 66 66 66
57766 - 30 30 30 10 10 10 0 0 0 0 0 0
57767 - 0 0 0 0 0 0 0 0 0 0 0 0
57768 - 0 0 0 0 0 0 0 0 0 0 0 0
57769 - 0 0 0 0 0 0 0 0 0 6 6 6
57770 - 26 26 26 70 70 70 163 133 67 210 150 10
57771 -236 178 12 246 190 14 246 190 14 246 190 14
57772 -246 190 14 246 190 14 246 190 14 246 190 14
57773 -246 190 14 246 190 14 246 190 14 246 190 14
57774 -246 190 14 246 190 14 246 190 14 246 190 14
57775 -232 195 16 121 92 8 34 34 34 106 106 106
57776 -221 221 221 253 253 253 253 253 253 253 253 253
57777 -253 253 253 253 253 253 253 253 253 253 253 253
57778 -253 253 253 253 253 253 253 253 253 253 253 253
57779 -253 253 253 253 253 253 253 253 253 253 253 253
57780 -242 242 242 82 82 82 18 14 6 163 110 8
57781 -216 158 10 236 178 12 242 186 14 246 190 14
57782 -246 190 14 246 190 14 246 190 14 246 190 14
57783 -246 190 14 246 190 14 246 190 14 246 190 14
57784 -246 190 14 246 190 14 246 190 14 246 190 14
57785 -246 190 14 246 190 14 242 186 14 163 133 67
57786 - 46 46 46 18 18 18 6 6 6 0 0 0
57787 - 0 0 0 0 0 0 0 0 0 0 0 0
57788 - 0 0 0 0 0 0 0 0 0 0 0 0
57789 - 0 0 0 0 0 0 0 0 0 10 10 10
57790 - 30 30 30 78 78 78 163 133 67 210 150 10
57791 -236 178 12 246 186 14 246 190 14 246 190 14
57792 -246 190 14 246 190 14 246 190 14 246 190 14
57793 -246 190 14 246 190 14 246 190 14 246 190 14
57794 -246 190 14 246 190 14 246 190 14 246 190 14
57795 -241 196 14 215 174 15 190 178 144 253 253 253
57796 -253 253 253 253 253 253 253 253 253 253 253 253
57797 -253 253 253 253 253 253 253 253 253 253 253 253
57798 -253 253 253 253 253 253 253 253 253 253 253 253
57799 -253 253 253 253 253 253 253 253 253 218 218 218
57800 - 58 58 58 2 2 6 22 18 6 167 114 7
57801 -216 158 10 236 178 12 246 186 14 246 190 14
57802 -246 190 14 246 190 14 246 190 14 246 190 14
57803 -246 190 14 246 190 14 246 190 14 246 190 14
57804 -246 190 14 246 190 14 246 190 14 246 190 14
57805 -246 190 14 246 186 14 242 186 14 190 150 46
57806 - 54 54 54 22 22 22 6 6 6 0 0 0
57807 - 0 0 0 0 0 0 0 0 0 0 0 0
57808 - 0 0 0 0 0 0 0 0 0 0 0 0
57809 - 0 0 0 0 0 0 0 0 0 14 14 14
57810 - 38 38 38 86 86 86 180 133 36 213 154 11
57811 -236 178 12 246 186 14 246 190 14 246 190 14
57812 -246 190 14 246 190 14 246 190 14 246 190 14
57813 -246 190 14 246 190 14 246 190 14 246 190 14
57814 -246 190 14 246 190 14 246 190 14 246 190 14
57815 -246 190 14 232 195 16 190 146 13 214 214 214
57816 -253 253 253 253 253 253 253 253 253 253 253 253
57817 -253 253 253 253 253 253 253 253 253 253 253 253
57818 -253 253 253 253 253 253 253 253 253 253 253 253
57819 -253 253 253 250 250 250 170 170 170 26 26 26
57820 - 2 2 6 2 2 6 37 26 9 163 110 8
57821 -219 162 10 239 182 13 246 186 14 246 190 14
57822 -246 190 14 246 190 14 246 190 14 246 190 14
57823 -246 190 14 246 190 14 246 190 14 246 190 14
57824 -246 190 14 246 190 14 246 190 14 246 190 14
57825 -246 186 14 236 178 12 224 166 10 142 122 72
57826 - 46 46 46 18 18 18 6 6 6 0 0 0
57827 - 0 0 0 0 0 0 0 0 0 0 0 0
57828 - 0 0 0 0 0 0 0 0 0 0 0 0
57829 - 0 0 0 0 0 0 6 6 6 18 18 18
57830 - 50 50 50 109 106 95 192 133 9 224 166 10
57831 -242 186 14 246 190 14 246 190 14 246 190 14
57832 -246 190 14 246 190 14 246 190 14 246 190 14
57833 -246 190 14 246 190 14 246 190 14 246 190 14
57834 -246 190 14 246 190 14 246 190 14 246 190 14
57835 -242 186 14 226 184 13 210 162 10 142 110 46
57836 -226 226 226 253 253 253 253 253 253 253 253 253
57837 -253 253 253 253 253 253 253 253 253 253 253 253
57838 -253 253 253 253 253 253 253 253 253 253 253 253
57839 -198 198 198 66 66 66 2 2 6 2 2 6
57840 - 2 2 6 2 2 6 50 34 6 156 107 11
57841 -219 162 10 239 182 13 246 186 14 246 190 14
57842 -246 190 14 246 190 14 246 190 14 246 190 14
57843 -246 190 14 246 190 14 246 190 14 246 190 14
57844 -246 190 14 246 190 14 246 190 14 242 186 14
57845 -234 174 13 213 154 11 154 122 46 66 66 66
57846 - 30 30 30 10 10 10 0 0 0 0 0 0
57847 - 0 0 0 0 0 0 0 0 0 0 0 0
57848 - 0 0 0 0 0 0 0 0 0 0 0 0
57849 - 0 0 0 0 0 0 6 6 6 22 22 22
57850 - 58 58 58 154 121 60 206 145 10 234 174 13
57851 -242 186 14 246 186 14 246 190 14 246 190 14
57852 -246 190 14 246 190 14 246 190 14 246 190 14
57853 -246 190 14 246 190 14 246 190 14 246 190 14
57854 -246 190 14 246 190 14 246 190 14 246 190 14
57855 -246 186 14 236 178 12 210 162 10 163 110 8
57856 - 61 42 6 138 138 138 218 218 218 250 250 250
57857 -253 253 253 253 253 253 253 253 253 250 250 250
57858 -242 242 242 210 210 210 144 144 144 66 66 66
57859 - 6 6 6 2 2 6 2 2 6 2 2 6
57860 - 2 2 6 2 2 6 61 42 6 163 110 8
57861 -216 158 10 236 178 12 246 190 14 246 190 14
57862 -246 190 14 246 190 14 246 190 14 246 190 14
57863 -246 190 14 246 190 14 246 190 14 246 190 14
57864 -246 190 14 239 182 13 230 174 11 216 158 10
57865 -190 142 34 124 112 88 70 70 70 38 38 38
57866 - 18 18 18 6 6 6 0 0 0 0 0 0
57867 - 0 0 0 0 0 0 0 0 0 0 0 0
57868 - 0 0 0 0 0 0 0 0 0 0 0 0
57869 - 0 0 0 0 0 0 6 6 6 22 22 22
57870 - 62 62 62 168 124 44 206 145 10 224 166 10
57871 -236 178 12 239 182 13 242 186 14 242 186 14
57872 -246 186 14 246 190 14 246 190 14 246 190 14
57873 -246 190 14 246 190 14 246 190 14 246 190 14
57874 -246 190 14 246 190 14 246 190 14 246 190 14
57875 -246 190 14 236 178 12 216 158 10 175 118 6
57876 - 80 54 7 2 2 6 6 6 6 30 30 30
57877 - 54 54 54 62 62 62 50 50 50 38 38 38
57878 - 14 14 14 2 2 6 2 2 6 2 2 6
57879 - 2 2 6 2 2 6 2 2 6 2 2 6
57880 - 2 2 6 6 6 6 80 54 7 167 114 7
57881 -213 154 11 236 178 12 246 190 14 246 190 14
57882 -246 190 14 246 190 14 246 190 14 246 190 14
57883 -246 190 14 242 186 14 239 182 13 239 182 13
57884 -230 174 11 210 150 10 174 135 50 124 112 88
57885 - 82 82 82 54 54 54 34 34 34 18 18 18
57886 - 6 6 6 0 0 0 0 0 0 0 0 0
57887 - 0 0 0 0 0 0 0 0 0 0 0 0
57888 - 0 0 0 0 0 0 0 0 0 0 0 0
57889 - 0 0 0 0 0 0 6 6 6 18 18 18
57890 - 50 50 50 158 118 36 192 133 9 200 144 11
57891 -216 158 10 219 162 10 224 166 10 226 170 11
57892 -230 174 11 236 178 12 239 182 13 239 182 13
57893 -242 186 14 246 186 14 246 190 14 246 190 14
57894 -246 190 14 246 190 14 246 190 14 246 190 14
57895 -246 186 14 230 174 11 210 150 10 163 110 8
57896 -104 69 6 10 10 10 2 2 6 2 2 6
57897 - 2 2 6 2 2 6 2 2 6 2 2 6
57898 - 2 2 6 2 2 6 2 2 6 2 2 6
57899 - 2 2 6 2 2 6 2 2 6 2 2 6
57900 - 2 2 6 6 6 6 91 60 6 167 114 7
57901 -206 145 10 230 174 11 242 186 14 246 190 14
57902 -246 190 14 246 190 14 246 186 14 242 186 14
57903 -239 182 13 230 174 11 224 166 10 213 154 11
57904 -180 133 36 124 112 88 86 86 86 58 58 58
57905 - 38 38 38 22 22 22 10 10 10 6 6 6
57906 - 0 0 0 0 0 0 0 0 0 0 0 0
57907 - 0 0 0 0 0 0 0 0 0 0 0 0
57908 - 0 0 0 0 0 0 0 0 0 0 0 0
57909 - 0 0 0 0 0 0 0 0 0 14 14 14
57910 - 34 34 34 70 70 70 138 110 50 158 118 36
57911 -167 114 7 180 123 7 192 133 9 197 138 11
57912 -200 144 11 206 145 10 213 154 11 219 162 10
57913 -224 166 10 230 174 11 239 182 13 242 186 14
57914 -246 186 14 246 186 14 246 186 14 246 186 14
57915 -239 182 13 216 158 10 185 133 11 152 99 6
57916 -104 69 6 18 14 6 2 2 6 2 2 6
57917 - 2 2 6 2 2 6 2 2 6 2 2 6
57918 - 2 2 6 2 2 6 2 2 6 2 2 6
57919 - 2 2 6 2 2 6 2 2 6 2 2 6
57920 - 2 2 6 6 6 6 80 54 7 152 99 6
57921 -192 133 9 219 162 10 236 178 12 239 182 13
57922 -246 186 14 242 186 14 239 182 13 236 178 12
57923 -224 166 10 206 145 10 192 133 9 154 121 60
57924 - 94 94 94 62 62 62 42 42 42 22 22 22
57925 - 14 14 14 6 6 6 0 0 0 0 0 0
57926 - 0 0 0 0 0 0 0 0 0 0 0 0
57927 - 0 0 0 0 0 0 0 0 0 0 0 0
57928 - 0 0 0 0 0 0 0 0 0 0 0 0
57929 - 0 0 0 0 0 0 0 0 0 6 6 6
57930 - 18 18 18 34 34 34 58 58 58 78 78 78
57931 -101 98 89 124 112 88 142 110 46 156 107 11
57932 -163 110 8 167 114 7 175 118 6 180 123 7
57933 -185 133 11 197 138 11 210 150 10 219 162 10
57934 -226 170 11 236 178 12 236 178 12 234 174 13
57935 -219 162 10 197 138 11 163 110 8 130 83 6
57936 - 91 60 6 10 10 10 2 2 6 2 2 6
57937 - 18 18 18 38 38 38 38 38 38 38 38 38
57938 - 38 38 38 38 38 38 38 38 38 38 38 38
57939 - 38 38 38 38 38 38 26 26 26 2 2 6
57940 - 2 2 6 6 6 6 70 47 6 137 92 6
57941 -175 118 6 200 144 11 219 162 10 230 174 11
57942 -234 174 13 230 174 11 219 162 10 210 150 10
57943 -192 133 9 163 110 8 124 112 88 82 82 82
57944 - 50 50 50 30 30 30 14 14 14 6 6 6
57945 - 0 0 0 0 0 0 0 0 0 0 0 0
57946 - 0 0 0 0 0 0 0 0 0 0 0 0
57947 - 0 0 0 0 0 0 0 0 0 0 0 0
57948 - 0 0 0 0 0 0 0 0 0 0 0 0
57949 - 0 0 0 0 0 0 0 0 0 0 0 0
57950 - 6 6 6 14 14 14 22 22 22 34 34 34
57951 - 42 42 42 58 58 58 74 74 74 86 86 86
57952 -101 98 89 122 102 70 130 98 46 121 87 25
57953 -137 92 6 152 99 6 163 110 8 180 123 7
57954 -185 133 11 197 138 11 206 145 10 200 144 11
57955 -180 123 7 156 107 11 130 83 6 104 69 6
57956 - 50 34 6 54 54 54 110 110 110 101 98 89
57957 - 86 86 86 82 82 82 78 78 78 78 78 78
57958 - 78 78 78 78 78 78 78 78 78 78 78 78
57959 - 78 78 78 82 82 82 86 86 86 94 94 94
57960 -106 106 106 101 101 101 86 66 34 124 80 6
57961 -156 107 11 180 123 7 192 133 9 200 144 11
57962 -206 145 10 200 144 11 192 133 9 175 118 6
57963 -139 102 15 109 106 95 70 70 70 42 42 42
57964 - 22 22 22 10 10 10 0 0 0 0 0 0
57965 - 0 0 0 0 0 0 0 0 0 0 0 0
57966 - 0 0 0 0 0 0 0 0 0 0 0 0
57967 - 0 0 0 0 0 0 0 0 0 0 0 0
57968 - 0 0 0 0 0 0 0 0 0 0 0 0
57969 - 0 0 0 0 0 0 0 0 0 0 0 0
57970 - 0 0 0 0 0 0 6 6 6 10 10 10
57971 - 14 14 14 22 22 22 30 30 30 38 38 38
57972 - 50 50 50 62 62 62 74 74 74 90 90 90
57973 -101 98 89 112 100 78 121 87 25 124 80 6
57974 -137 92 6 152 99 6 152 99 6 152 99 6
57975 -138 86 6 124 80 6 98 70 6 86 66 30
57976 -101 98 89 82 82 82 58 58 58 46 46 46
57977 - 38 38 38 34 34 34 34 34 34 34 34 34
57978 - 34 34 34 34 34 34 34 34 34 34 34 34
57979 - 34 34 34 34 34 34 38 38 38 42 42 42
57980 - 54 54 54 82 82 82 94 86 76 91 60 6
57981 -134 86 6 156 107 11 167 114 7 175 118 6
57982 -175 118 6 167 114 7 152 99 6 121 87 25
57983 -101 98 89 62 62 62 34 34 34 18 18 18
57984 - 6 6 6 0 0 0 0 0 0 0 0 0
57985 - 0 0 0 0 0 0 0 0 0 0 0 0
57986 - 0 0 0 0 0 0 0 0 0 0 0 0
57987 - 0 0 0 0 0 0 0 0 0 0 0 0
57988 - 0 0 0 0 0 0 0 0 0 0 0 0
57989 - 0 0 0 0 0 0 0 0 0 0 0 0
57990 - 0 0 0 0 0 0 0 0 0 0 0 0
57991 - 0 0 0 6 6 6 6 6 6 10 10 10
57992 - 18 18 18 22 22 22 30 30 30 42 42 42
57993 - 50 50 50 66 66 66 86 86 86 101 98 89
57994 -106 86 58 98 70 6 104 69 6 104 69 6
57995 -104 69 6 91 60 6 82 62 34 90 90 90
57996 - 62 62 62 38 38 38 22 22 22 14 14 14
57997 - 10 10 10 10 10 10 10 10 10 10 10 10
57998 - 10 10 10 10 10 10 6 6 6 10 10 10
57999 - 10 10 10 10 10 10 10 10 10 14 14 14
58000 - 22 22 22 42 42 42 70 70 70 89 81 66
58001 - 80 54 7 104 69 6 124 80 6 137 92 6
58002 -134 86 6 116 81 8 100 82 52 86 86 86
58003 - 58 58 58 30 30 30 14 14 14 6 6 6
58004 - 0 0 0 0 0 0 0 0 0 0 0 0
58005 - 0 0 0 0 0 0 0 0 0 0 0 0
58006 - 0 0 0 0 0 0 0 0 0 0 0 0
58007 - 0 0 0 0 0 0 0 0 0 0 0 0
58008 - 0 0 0 0 0 0 0 0 0 0 0 0
58009 - 0 0 0 0 0 0 0 0 0 0 0 0
58010 - 0 0 0 0 0 0 0 0 0 0 0 0
58011 - 0 0 0 0 0 0 0 0 0 0 0 0
58012 - 0 0 0 6 6 6 10 10 10 14 14 14
58013 - 18 18 18 26 26 26 38 38 38 54 54 54
58014 - 70 70 70 86 86 86 94 86 76 89 81 66
58015 - 89 81 66 86 86 86 74 74 74 50 50 50
58016 - 30 30 30 14 14 14 6 6 6 0 0 0
58017 - 0 0 0 0 0 0 0 0 0 0 0 0
58018 - 0 0 0 0 0 0 0 0 0 0 0 0
58019 - 0 0 0 0 0 0 0 0 0 0 0 0
58020 - 6 6 6 18 18 18 34 34 34 58 58 58
58021 - 82 82 82 89 81 66 89 81 66 89 81 66
58022 - 94 86 66 94 86 76 74 74 74 50 50 50
58023 - 26 26 26 14 14 14 6 6 6 0 0 0
58024 - 0 0 0 0 0 0 0 0 0 0 0 0
58025 - 0 0 0 0 0 0 0 0 0 0 0 0
58026 - 0 0 0 0 0 0 0 0 0 0 0 0
58027 - 0 0 0 0 0 0 0 0 0 0 0 0
58028 - 0 0 0 0 0 0 0 0 0 0 0 0
58029 - 0 0 0 0 0 0 0 0 0 0 0 0
58030 - 0 0 0 0 0 0 0 0 0 0 0 0
58031 - 0 0 0 0 0 0 0 0 0 0 0 0
58032 - 0 0 0 0 0 0 0 0 0 0 0 0
58033 - 6 6 6 6 6 6 14 14 14 18 18 18
58034 - 30 30 30 38 38 38 46 46 46 54 54 54
58035 - 50 50 50 42 42 42 30 30 30 18 18 18
58036 - 10 10 10 0 0 0 0 0 0 0 0 0
58037 - 0 0 0 0 0 0 0 0 0 0 0 0
58038 - 0 0 0 0 0 0 0 0 0 0 0 0
58039 - 0 0 0 0 0 0 0 0 0 0 0 0
58040 - 0 0 0 6 6 6 14 14 14 26 26 26
58041 - 38 38 38 50 50 50 58 58 58 58 58 58
58042 - 54 54 54 42 42 42 30 30 30 18 18 18
58043 - 10 10 10 0 0 0 0 0 0 0 0 0
58044 - 0 0 0 0 0 0 0 0 0 0 0 0
58045 - 0 0 0 0 0 0 0 0 0 0 0 0
58046 - 0 0 0 0 0 0 0 0 0 0 0 0
58047 - 0 0 0 0 0 0 0 0 0 0 0 0
58048 - 0 0 0 0 0 0 0 0 0 0 0 0
58049 - 0 0 0 0 0 0 0 0 0 0 0 0
58050 - 0 0 0 0 0 0 0 0 0 0 0 0
58051 - 0 0 0 0 0 0 0 0 0 0 0 0
58052 - 0 0 0 0 0 0 0 0 0 0 0 0
58053 - 0 0 0 0 0 0 0 0 0 6 6 6
58054 - 6 6 6 10 10 10 14 14 14 18 18 18
58055 - 18 18 18 14 14 14 10 10 10 6 6 6
58056 - 0 0 0 0 0 0 0 0 0 0 0 0
58057 - 0 0 0 0 0 0 0 0 0 0 0 0
58058 - 0 0 0 0 0 0 0 0 0 0 0 0
58059 - 0 0 0 0 0 0 0 0 0 0 0 0
58060 - 0 0 0 0 0 0 0 0 0 6 6 6
58061 - 14 14 14 18 18 18 22 22 22 22 22 22
58062 - 18 18 18 14 14 14 10 10 10 6 6 6
58063 - 0 0 0 0 0 0 0 0 0 0 0 0
58064 - 0 0 0 0 0 0 0 0 0 0 0 0
58065 - 0 0 0 0 0 0 0 0 0 0 0 0
58066 - 0 0 0 0 0 0 0 0 0 0 0 0
58067 - 0 0 0 0 0 0 0 0 0 0 0 0
58068 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58069 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58070 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58071 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58072 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58073 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58074 +4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
58077 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58078 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58079 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58080 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58081 +4 4 4 4 4 4
58082 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58083 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58084 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58085 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58086 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58087 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58088 +4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
58091 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58092 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58093 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58094 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58095 +4 4 4 4 4 4
58096 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58097 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58098 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58099 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58100 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58101 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58102 +4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
58105 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58106 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58107 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58108 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58109 +4 4 4 4 4 4
58110 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58111 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58112 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58113 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58114 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58115 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58116 +4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
58119 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58120 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58121 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58122 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58123 +4 4 4 4 4 4
58124 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58125 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58126 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58127 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58128 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58129 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58130 +4 4 4 4 4 4 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 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58135 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58136 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58137 +4 4 4 4 4 4
58138 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58139 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58140 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58141 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58142 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58143 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58144 +4 4 4 4 4 4 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 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4
58149 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58150 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58151 +4 4 4 4 4 4
58152 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58153 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58154 +4 4 4 4 4 4 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 3 3 3 0 0 0 0 0 0
58157 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 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 4 4 4 4 4 4 4 4 4 4 4 4
58161 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
58162 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
58163 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
58164 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58165 +4 4 4 4 4 4
58166 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58167 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58168 +4 4 4 4 4 4 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 2 2 2 0 0 0 3 4 3 26 28 28
58171 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
58172 +5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
58175 +4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
58176 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
58177 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
58178 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58179 +4 4 4 4 4 4
58180 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58181 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58182 +4 4 4 4 4 4 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 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
58185 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
58186 +0 0 0 3 3 3 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 4 4 4 4 4 4 4 4 4 4 4 4
58189 +4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
58190 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
58191 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
58192 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
58193 +4 4 4 4 4 4
58194 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58195 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58196 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58197 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
58198 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
58199 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
58200 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
58201 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58202 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
58203 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
58204 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
58205 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
58206 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
58207 +4 4 4 4 4 4
58208 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58209 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58210 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58211 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
58212 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
58213 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
58214 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
58215 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
58216 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
58217 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
58218 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
58219 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
58220 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
58221 +4 4 4 4 4 4
58222 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58223 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58224 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
58225 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
58226 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
58227 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
58228 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
58229 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
58230 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
58231 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
58232 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
58233 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
58234 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
58235 +4 4 4 4 4 4
58236 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58237 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58238 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
58239 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
58240 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
58241 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
58242 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
58243 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
58244 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
58245 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
58246 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
58247 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
58248 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
58249 +4 4 4 4 4 4
58250 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58251 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58252 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
58253 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
58254 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
58255 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
58256 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
58257 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
58258 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
58259 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
58260 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
58261 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
58262 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
58263 +4 4 4 4 4 4
58264 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58265 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58266 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
58267 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
58268 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
58269 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
58270 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
58271 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
58272 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
58273 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
58274 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
58275 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
58276 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
58277 +4 4 4 4 4 4
58278 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58279 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58280 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
58281 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
58282 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
58283 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
58284 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
58285 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
58286 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
58287 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
58288 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
58289 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
58290 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
58291 +4 4 4 4 4 4
58292 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58293 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
58294 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
58295 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
58296 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
58297 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
58298 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
58299 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
58300 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
58301 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
58302 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
58303 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
58304 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
58305 +4 4 4 4 4 4
58306 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58307 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
58308 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
58309 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
58310 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
58311 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
58312 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
58313 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
58314 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
58315 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
58316 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
58317 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
58318 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
58319 +0 0 0 4 4 4
58320 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
58321 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
58322 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
58323 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
58324 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
58325 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
58326 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
58327 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
58328 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
58329 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
58330 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
58331 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
58332 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
58333 +2 0 0 0 0 0
58334 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
58335 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
58336 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
58337 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
58338 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
58339 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
58340 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
58341 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
58342 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
58343 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
58344 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
58345 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
58346 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
58347 +37 38 37 0 0 0
58348 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
58349 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
58350 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
58351 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
58352 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
58353 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
58354 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
58355 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
58356 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
58357 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
58358 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
58359 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
58360 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
58361 +85 115 134 4 0 0
58362 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
58363 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
58364 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
58365 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
58366 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
58367 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
58368 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
58369 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
58370 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
58371 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
58372 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
58373 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
58374 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
58375 +60 73 81 4 0 0
58376 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
58377 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
58378 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
58379 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
58380 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
58381 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
58382 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
58383 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
58384 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
58385 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
58386 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
58387 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
58388 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
58389 +16 19 21 4 0 0
58390 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
58391 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
58392 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
58393 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
58394 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
58395 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
58396 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
58397 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
58398 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
58399 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
58400 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
58401 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
58402 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
58403 +4 0 0 4 3 3
58404 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
58405 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
58406 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
58407 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
58408 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
58409 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
58410 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
58411 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
58412 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
58413 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
58414 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
58415 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
58416 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
58417 +3 2 2 4 4 4
58418 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
58419 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
58420 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
58421 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
58422 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
58423 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
58424 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
58425 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
58426 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
58427 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
58428 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
58429 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
58430 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
58431 +4 4 4 4 4 4
58432 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
58433 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
58434 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
58435 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
58436 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
58437 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
58438 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
58439 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
58440 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
58441 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
58442 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
58443 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
58444 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
58445 +4 4 4 4 4 4
58446 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
58447 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
58448 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
58449 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
58450 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
58451 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
58452 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
58453 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
58454 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
58455 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
58456 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
58457 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
58458 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
58459 +5 5 5 5 5 5
58460 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
58461 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
58462 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
58463 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
58464 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
58465 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
58466 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
58467 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
58468 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
58469 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
58470 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
58471 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
58472 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
58473 +5 5 5 4 4 4
58474 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
58475 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
58476 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
58477 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
58478 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
58479 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
58480 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
58481 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
58482 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
58483 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
58484 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
58485 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
58486 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58487 +4 4 4 4 4 4
58488 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
58489 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
58490 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
58491 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
58492 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
58493 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
58494 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
58495 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
58496 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
58497 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
58498 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
58499 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
58500 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58501 +4 4 4 4 4 4
58502 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
58503 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
58504 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
58505 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
58506 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
58507 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
58508 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
58509 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
58510 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
58511 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
58512 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
58513 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58514 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58515 +4 4 4 4 4 4
58516 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
58517 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
58518 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
58519 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
58520 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
58521 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
58522 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
58523 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
58524 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
58525 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
58526 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
58527 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58528 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58529 +4 4 4 4 4 4
58530 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
58531 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
58532 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
58533 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
58534 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
58535 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
58536 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
58537 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
58538 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
58539 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
58540 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58541 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58542 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58543 +4 4 4 4 4 4
58544 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
58545 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
58546 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
58547 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
58548 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
58549 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
58550 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
58551 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
58552 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
58553 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
58554 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
58555 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58556 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58557 +4 4 4 4 4 4
58558 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
58559 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
58560 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
58561 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
58562 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
58563 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
58564 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
58565 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
58566 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
58567 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
58568 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
58569 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58570 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58571 +4 4 4 4 4 4
58572 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
58573 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
58574 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
58575 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
58576 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
58577 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
58578 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
58579 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
58580 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
58581 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
58582 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58583 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58584 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58585 +4 4 4 4 4 4
58586 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
58587 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
58588 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
58589 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
58590 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
58591 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
58592 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
58593 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
58594 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
58595 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
58596 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58597 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58598 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58599 +4 4 4 4 4 4
58600 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
58601 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
58602 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
58603 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
58604 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
58605 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
58606 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
58607 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
58608 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
58609 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
58610 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58611 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58612 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58613 +4 4 4 4 4 4
58614 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
58615 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
58616 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
58617 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
58618 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
58619 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
58620 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
58621 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
58622 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
58623 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58624 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58625 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58626 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58627 +4 4 4 4 4 4
58628 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
58629 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
58630 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
58631 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
58632 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
58633 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
58634 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
58635 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
58636 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
58637 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58638 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58639 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58640 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58641 +4 4 4 4 4 4
58642 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
58643 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
58644 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
58645 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
58646 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
58647 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
58648 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
58649 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
58650 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
58651 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58652 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58653 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58654 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58655 +4 4 4 4 4 4
58656 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
58657 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
58658 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
58659 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
58660 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
58661 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
58662 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
58663 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
58664 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
58665 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58666 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58667 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58668 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58669 +4 4 4 4 4 4
58670 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
58671 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
58672 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
58673 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
58674 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
58675 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
58676 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
58677 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
58678 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
58679 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58680 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58681 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58682 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58683 +4 4 4 4 4 4
58684 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
58685 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
58686 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
58687 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
58688 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
58689 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
58690 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
58691 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
58692 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
58693 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58694 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58695 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58696 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58697 +4 4 4 4 4 4
58698 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
58699 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
58700 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
58701 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
58702 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
58703 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
58704 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
58705 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
58706 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
58707 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58708 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58709 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58710 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58711 +4 4 4 4 4 4
58712 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
58713 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
58714 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
58715 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
58716 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
58717 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
58718 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
58719 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
58720 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
58721 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58722 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58723 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58724 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58725 +4 4 4 4 4 4
58726 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
58727 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
58728 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
58729 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
58730 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
58731 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
58732 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
58733 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
58734 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
58735 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58736 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58737 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58738 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58739 +4 4 4 4 4 4
58740 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
58741 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
58742 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
58743 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
58744 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
58745 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
58746 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
58747 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
58748 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
58749 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58750 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58751 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58752 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58753 +4 4 4 4 4 4
58754 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
58755 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
58756 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
58757 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
58758 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
58759 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
58760 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
58761 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
58762 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
58763 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58764 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58765 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58766 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58767 +4 4 4 4 4 4
58768 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
58769 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
58770 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
58771 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
58772 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
58773 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
58774 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
58775 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
58776 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
58777 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58778 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58779 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58780 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58781 +4 4 4 4 4 4
58782 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
58783 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
58784 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
58785 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
58786 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
58787 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
58788 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
58789 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
58790 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
58791 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58792 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58793 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58794 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58795 +4 4 4 4 4 4
58796 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
58797 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
58798 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
58799 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
58800 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
58801 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
58802 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
58803 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
58804 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
58805 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58806 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58807 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58808 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58809 +4 4 4 4 4 4
58810 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
58811 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
58812 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
58813 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
58814 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
58815 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
58816 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
58817 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
58818 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
58819 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58820 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58821 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58822 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58823 +4 4 4 4 4 4
58824 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
58825 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
58826 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
58827 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
58828 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
58829 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
58830 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
58831 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
58832 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
58833 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
58834 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58835 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58836 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58837 +4 4 4 4 4 4
58838 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
58839 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
58840 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
58841 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
58842 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
58843 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
58844 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
58845 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
58846 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
58847 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
58848 +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58849 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58850 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58851 +4 4 4 4 4 4
58852 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
58853 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
58854 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
58855 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
58856 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
58857 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
58858 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58859 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
58860 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
58861 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
58862 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
58863 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58864 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58865 +4 4 4 4 4 4
58866 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
58867 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
58868 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
58869 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
58870 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
58871 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
58872 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
58873 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
58874 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
58875 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
58876 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58877 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58878 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58879 +4 4 4 4 4 4
58880 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
58881 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
58882 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
58883 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
58884 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
58885 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
58886 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
58887 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
58888 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
58889 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
58890 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58891 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58892 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58893 +4 4 4 4 4 4
58894 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
58895 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
58896 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
58897 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
58898 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
58899 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
58900 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
58901 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
58902 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
58903 +13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
58904 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58905 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58906 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58907 +4 4 4 4 4 4
58908 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
58909 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
58910 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
58911 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
58912 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
58913 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
58914 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
58915 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
58916 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
58917 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
58918 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58919 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58920 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58921 +4 4 4 4 4 4
58922 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
58923 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
58924 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
58925 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
58926 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
58927 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
58928 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
58929 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
58930 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
58931 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
58932 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58933 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58934 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58935 +4 4 4 4 4 4
58936 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
58937 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
58938 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
58939 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
58940 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
58941 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
58942 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
58943 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
58944 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
58945 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58946 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58947 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58948 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58949 +4 4 4 4 4 4
58950 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
58951 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
58952 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
58953 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
58954 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
58955 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
58956 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
58957 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
58958 +4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
58959 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58960 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58961 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58962 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58963 +4 4 4 4 4 4
58964 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
58965 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
58966 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
58967 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
58968 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
58969 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
58970 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
58971 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
58972 +4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58973 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58974 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58975 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58976 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58977 +4 4 4 4 4 4
58978 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
58979 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
58980 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
58981 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
58982 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
58983 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
58984 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
58985 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
58986 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58987 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58988 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58989 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58990 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58991 +4 4 4 4 4 4
58992 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
58993 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
58994 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
58995 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
58996 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
58997 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
58998 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
58999 +6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
59000 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59001 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59002 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59003 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59004 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59005 +4 4 4 4 4 4
59006 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
59007 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
59008 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
59009 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
59010 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
59011 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
59012 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
59013 +4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
59014 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59015 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59016 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59017 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59018 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59019 +4 4 4 4 4 4
59020 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59021 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
59022 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
59023 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
59024 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
59025 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
59026 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
59027 +6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
59028 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59029 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59030 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59031 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59032 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59033 +4 4 4 4 4 4
59034 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59035 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
59036 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
59037 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
59038 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
59039 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
59040 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
59041 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
59042 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59043 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59044 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59045 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59046 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59047 +4 4 4 4 4 4
59048 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59049 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59050 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
59051 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
59052 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
59053 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
59054 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
59055 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
59056 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59057 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59058 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59059 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59060 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59061 +4 4 4 4 4 4
59062 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59063 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59064 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
59065 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
59066 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
59067 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
59068 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
59069 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59070 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59071 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59072 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59073 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59074 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59075 +4 4 4 4 4 4
59076 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59077 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59078 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59079 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
59080 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
59081 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
59082 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
59083 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59084 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59085 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59086 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59087 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59088 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59089 +4 4 4 4 4 4
59090 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59091 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59092 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59093 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
59094 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
59095 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
59096 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
59097 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59098 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59099 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59100 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59101 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59102 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59103 +4 4 4 4 4 4
59104 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59105 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59106 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59107 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
59108 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
59109 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
59110 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
59111 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59112 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59113 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59114 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59115 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59116 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59117 +4 4 4 4 4 4
59118 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59119 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59120 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59121 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
59122 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
59123 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
59124 +6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
59125 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59126 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59127 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59128 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59129 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59130 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59131 +4 4 4 4 4 4
59132 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59133 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59134 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59135 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59136 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
59137 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
59138 +4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
59139 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59140 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59141 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59142 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59143 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59144 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59145 +4 4 4 4 4 4
59146 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59147 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59148 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59149 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59150 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
59151 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
59152 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59153 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59154 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59155 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59156 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59157 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59158 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59159 +4 4 4 4 4 4
59160 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59161 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59162 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59163 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59164 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
59165 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
59166 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59167 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59168 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59169 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59170 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59171 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59172 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59173 +4 4 4 4 4 4
59174 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59175 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59176 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59177 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59178 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
59179 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
59180 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59181 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59182 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59183 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59184 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59185 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59186 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59187 +4 4 4 4 4 4
59188 diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
59189 index fef20db..d28b1ab 100644
59190 --- a/drivers/xen/xenfs/xenstored.c
59191 +++ b/drivers/xen/xenfs/xenstored.c
59192 @@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
59193 static int xsd_kva_open(struct inode *inode, struct file *file)
59194 {
59195 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
59196 +#ifdef CONFIG_GRKERNSEC_HIDESYM
59197 + NULL);
59198 +#else
59199 xen_store_interface);
59200 +#endif
59201 +
59202 if (!file->private_data)
59203 return -ENOMEM;
59204 return 0;
59205 diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
59206 index cc1cfae..41158ad 100644
59207 --- a/fs/9p/vfs_addr.c
59208 +++ b/fs/9p/vfs_addr.c
59209 @@ -187,7 +187,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
59210
59211 retval = v9fs_file_write_internal(inode,
59212 v9inode->writeback_fid,
59213 - (__force const char __user *)buffer,
59214 + (const char __force_user *)buffer,
59215 len, &offset, 0);
59216 if (retval > 0)
59217 retval = 0;
59218 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
59219 index 7fa4f7a..a7ebf8c 100644
59220 --- a/fs/9p/vfs_inode.c
59221 +++ b/fs/9p/vfs_inode.c
59222 @@ -1312,7 +1312,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
59223 void
59224 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
59225 {
59226 - char *s = nd_get_link(nd);
59227 + const char *s = nd_get_link(nd);
59228
59229 p9_debug(P9_DEBUG_VFS, " %s %s\n",
59230 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
59231 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
59232 index 370b24c..ff0be7b 100644
59233 --- a/fs/Kconfig.binfmt
59234 +++ b/fs/Kconfig.binfmt
59235 @@ -103,7 +103,7 @@ config HAVE_AOUT
59236
59237 config BINFMT_AOUT
59238 tristate "Kernel support for a.out and ECOFF binaries"
59239 - depends on HAVE_AOUT
59240 + depends on HAVE_AOUT && BROKEN
59241 ---help---
59242 A.out (Assembler.OUTput) is a set of formats for libraries and
59243 executables used in the earliest versions of UNIX. Linux used
59244 diff --git a/fs/afs/inode.c b/fs/afs/inode.c
59245 index 2946712..f737435 100644
59246 --- a/fs/afs/inode.c
59247 +++ b/fs/afs/inode.c
59248 @@ -141,7 +141,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
59249 struct afs_vnode *vnode;
59250 struct super_block *sb;
59251 struct inode *inode;
59252 - static atomic_t afs_autocell_ino;
59253 + static atomic_unchecked_t afs_autocell_ino;
59254
59255 _enter("{%x:%u},%*.*s,",
59256 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
59257 @@ -154,7 +154,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
59258 data.fid.unique = 0;
59259 data.fid.vnode = 0;
59260
59261 - inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
59262 + inode = iget5_locked(sb, atomic_inc_return_unchecked(&afs_autocell_ino),
59263 afs_iget5_autocell_test, afs_iget5_set,
59264 &data);
59265 if (!inode) {
59266 diff --git a/fs/aio.c b/fs/aio.c
59267 index 0ff7c46..7f5d132 100644
59268 --- a/fs/aio.c
59269 +++ b/fs/aio.c
59270 @@ -388,7 +388,7 @@ static int aio_setup_ring(struct kioctx *ctx)
59271 size += sizeof(struct io_event) * nr_events;
59272
59273 nr_pages = PFN_UP(size);
59274 - if (nr_pages < 0)
59275 + if (nr_pages <= 0)
59276 return -EINVAL;
59277
59278 file = aio_private_file(ctx, nr_pages);
59279 diff --git a/fs/attr.c b/fs/attr.c
59280 index 6530ced..4a827e2 100644
59281 --- a/fs/attr.c
59282 +++ b/fs/attr.c
59283 @@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
59284 unsigned long limit;
59285
59286 limit = rlimit(RLIMIT_FSIZE);
59287 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
59288 if (limit != RLIM_INFINITY && offset > limit)
59289 goto out_sig;
59290 if (offset > inode->i_sb->s_maxbytes)
59291 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
59292 index 116fd38..c04182da 100644
59293 --- a/fs/autofs4/waitq.c
59294 +++ b/fs/autofs4/waitq.c
59295 @@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
59296 {
59297 unsigned long sigpipe, flags;
59298 mm_segment_t fs;
59299 - const char *data = (const char *)addr;
59300 + const char __user *data = (const char __force_user *)addr;
59301 ssize_t wr = 0;
59302
59303 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
59304 @@ -340,6 +340,10 @@ static int validate_request(struct autofs_wait_queue **wait,
59305 return 1;
59306 }
59307
59308 +#ifdef CONFIG_GRKERNSEC_HIDESYM
59309 +static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
59310 +#endif
59311 +
59312 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
59313 enum autofs_notify notify)
59314 {
59315 @@ -385,7 +389,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
59316
59317 /* If this is a direct mount request create a dummy name */
59318 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
59319 +#ifdef CONFIG_GRKERNSEC_HIDESYM
59320 + /* this name does get written to userland via autofs4_write() */
59321 + qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
59322 +#else
59323 qstr.len = sprintf(name, "%p", dentry);
59324 +#endif
59325 else {
59326 qstr.len = autofs4_getpath(sbi, dentry, &name);
59327 if (!qstr.len) {
59328 diff --git a/fs/befs/endian.h b/fs/befs/endian.h
59329 index 2722387..56059b5 100644
59330 --- a/fs/befs/endian.h
59331 +++ b/fs/befs/endian.h
59332 @@ -11,7 +11,7 @@
59333
59334 #include <asm/byteorder.h>
59335
59336 -static inline u64
59337 +static inline u64 __intentional_overflow(-1)
59338 fs64_to_cpu(const struct super_block *sb, fs64 n)
59339 {
59340 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
59341 @@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
59342 return (__force fs64)cpu_to_be64(n);
59343 }
59344
59345 -static inline u32
59346 +static inline u32 __intentional_overflow(-1)
59347 fs32_to_cpu(const struct super_block *sb, fs32 n)
59348 {
59349 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
59350 @@ -47,7 +47,7 @@ cpu_to_fs32(const struct super_block *sb, u32 n)
59351 return (__force fs32)cpu_to_be32(n);
59352 }
59353
59354 -static inline u16
59355 +static inline u16 __intentional_overflow(-1)
59356 fs16_to_cpu(const struct super_block *sb, fs16 n)
59357 {
59358 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
59359 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
59360 index ca0ba15..0fa3257 100644
59361 --- a/fs/binfmt_aout.c
59362 +++ b/fs/binfmt_aout.c
59363 @@ -16,6 +16,7 @@
59364 #include <linux/string.h>
59365 #include <linux/fs.h>
59366 #include <linux/file.h>
59367 +#include <linux/security.h>
59368 #include <linux/stat.h>
59369 #include <linux/fcntl.h>
59370 #include <linux/ptrace.h>
59371 @@ -58,6 +59,8 @@ static int aout_core_dump(struct coredump_params *cprm)
59372 #endif
59373 # define START_STACK(u) ((void __user *)u.start_stack)
59374
59375 + memset(&dump, 0, sizeof(dump));
59376 +
59377 fs = get_fs();
59378 set_fs(KERNEL_DS);
59379 has_dumped = 1;
59380 @@ -68,10 +71,12 @@ static int aout_core_dump(struct coredump_params *cprm)
59381
59382 /* If the size of the dump file exceeds the rlimit, then see what would happen
59383 if we wrote the stack, but not the data area. */
59384 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
59385 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
59386 dump.u_dsize = 0;
59387
59388 /* Make sure we have enough room to write the stack and data areas. */
59389 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
59390 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
59391 dump.u_ssize = 0;
59392
59393 @@ -232,6 +237,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
59394 rlim = rlimit(RLIMIT_DATA);
59395 if (rlim >= RLIM_INFINITY)
59396 rlim = ~0;
59397 +
59398 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
59399 if (ex.a_data + ex.a_bss > rlim)
59400 return -ENOMEM;
59401
59402 @@ -264,6 +271,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
59403
59404 install_exec_creds(bprm);
59405
59406 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
59407 + current->mm->pax_flags = 0UL;
59408 +#endif
59409 +
59410 +#ifdef CONFIG_PAX_PAGEEXEC
59411 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
59412 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
59413 +
59414 +#ifdef CONFIG_PAX_EMUTRAMP
59415 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
59416 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
59417 +#endif
59418 +
59419 +#ifdef CONFIG_PAX_MPROTECT
59420 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
59421 + current->mm->pax_flags |= MF_PAX_MPROTECT;
59422 +#endif
59423 +
59424 + }
59425 +#endif
59426 +
59427 if (N_MAGIC(ex) == OMAGIC) {
59428 unsigned long text_addr, map_size;
59429 loff_t pos;
59430 @@ -321,7 +349,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
59431 }
59432
59433 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
59434 - PROT_READ | PROT_WRITE | PROT_EXEC,
59435 + PROT_READ | PROT_WRITE,
59436 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
59437 fd_offset + ex.a_text);
59438 if (error != N_DATADDR(ex)) {
59439 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
59440 index 3892c1a..4e27c04 100644
59441 --- a/fs/binfmt_elf.c
59442 +++ b/fs/binfmt_elf.c
59443 @@ -34,6 +34,7 @@
59444 #include <linux/utsname.h>
59445 #include <linux/coredump.h>
59446 #include <linux/sched.h>
59447 +#include <linux/xattr.h>
59448 #include <asm/uaccess.h>
59449 #include <asm/param.h>
59450 #include <asm/page.h>
59451 @@ -47,7 +48,7 @@
59452
59453 static int load_elf_binary(struct linux_binprm *bprm);
59454 static unsigned long elf_map(struct file *, unsigned long, struct elf_phdr *,
59455 - int, int, unsigned long);
59456 + int, int, unsigned long) __intentional_overflow(-1);
59457
59458 #ifdef CONFIG_USELIB
59459 static int load_elf_library(struct file *);
59460 @@ -65,6 +66,14 @@ static int elf_core_dump(struct coredump_params *cprm);
59461 #define elf_core_dump NULL
59462 #endif
59463
59464 +#ifdef CONFIG_PAX_MPROTECT
59465 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
59466 +#endif
59467 +
59468 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59469 +static void elf_handle_mmap(struct file *file);
59470 +#endif
59471 +
59472 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
59473 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
59474 #else
59475 @@ -84,6 +93,15 @@ static struct linux_binfmt elf_format = {
59476 .load_binary = load_elf_binary,
59477 .load_shlib = load_elf_library,
59478 .core_dump = elf_core_dump,
59479 +
59480 +#ifdef CONFIG_PAX_MPROTECT
59481 + .handle_mprotect= elf_handle_mprotect,
59482 +#endif
59483 +
59484 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59485 + .handle_mmap = elf_handle_mmap,
59486 +#endif
59487 +
59488 .min_coredump = ELF_EXEC_PAGESIZE,
59489 };
59490
59491 @@ -91,6 +109,8 @@ static struct linux_binfmt elf_format = {
59492
59493 static int set_brk(unsigned long start, unsigned long end)
59494 {
59495 + unsigned long e = end;
59496 +
59497 start = ELF_PAGEALIGN(start);
59498 end = ELF_PAGEALIGN(end);
59499 if (end > start) {
59500 @@ -99,7 +119,7 @@ static int set_brk(unsigned long start, unsigned long end)
59501 if (BAD_ADDR(addr))
59502 return addr;
59503 }
59504 - current->mm->start_brk = current->mm->brk = end;
59505 + current->mm->start_brk = current->mm->brk = e;
59506 return 0;
59507 }
59508
59509 @@ -160,12 +180,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
59510 elf_addr_t __user *u_rand_bytes;
59511 const char *k_platform = ELF_PLATFORM;
59512 const char *k_base_platform = ELF_BASE_PLATFORM;
59513 - unsigned char k_rand_bytes[16];
59514 + u32 k_rand_bytes[4];
59515 int items;
59516 elf_addr_t *elf_info;
59517 int ei_index = 0;
59518 const struct cred *cred = current_cred();
59519 struct vm_area_struct *vma;
59520 + unsigned long saved_auxv[AT_VECTOR_SIZE];
59521
59522 /*
59523 * In some cases (e.g. Hyper-Threading), we want to avoid L1
59524 @@ -207,8 +228,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
59525 * Generate 16 random bytes for userspace PRNG seeding.
59526 */
59527 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
59528 - u_rand_bytes = (elf_addr_t __user *)
59529 - STACK_ALLOC(p, sizeof(k_rand_bytes));
59530 + prandom_seed(k_rand_bytes[0] ^ prandom_u32());
59531 + prandom_seed(k_rand_bytes[1] ^ prandom_u32());
59532 + prandom_seed(k_rand_bytes[2] ^ prandom_u32());
59533 + prandom_seed(k_rand_bytes[3] ^ prandom_u32());
59534 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
59535 + u_rand_bytes = (elf_addr_t __user *) p;
59536 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
59537 return -EFAULT;
59538
59539 @@ -323,9 +348,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
59540 return -EFAULT;
59541 current->mm->env_end = p;
59542
59543 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
59544 +
59545 /* Put the elf_info on the stack in the right place. */
59546 sp = (elf_addr_t __user *)envp + 1;
59547 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
59548 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
59549 return -EFAULT;
59550 return 0;
59551 }
59552 @@ -393,15 +420,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
59553 an ELF header */
59554
59555 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
59556 - struct file *interpreter, unsigned long *interp_map_addr,
59557 - unsigned long no_base)
59558 + struct file *interpreter, unsigned long no_base)
59559 {
59560 struct elf_phdr *elf_phdata;
59561 struct elf_phdr *eppnt;
59562 - unsigned long load_addr = 0;
59563 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
59564 int load_addr_set = 0;
59565 unsigned long last_bss = 0, elf_bss = 0;
59566 - unsigned long error = ~0UL;
59567 + unsigned long error = -EINVAL;
59568 unsigned long total_size;
59569 int retval, i, size;
59570
59571 @@ -447,6 +473,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
59572 goto out_close;
59573 }
59574
59575 +#ifdef CONFIG_PAX_SEGMEXEC
59576 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
59577 + pax_task_size = SEGMEXEC_TASK_SIZE;
59578 +#endif
59579 +
59580 eppnt = elf_phdata;
59581 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
59582 if (eppnt->p_type == PT_LOAD) {
59583 @@ -470,8 +501,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
59584 map_addr = elf_map(interpreter, load_addr + vaddr,
59585 eppnt, elf_prot, elf_type, total_size);
59586 total_size = 0;
59587 - if (!*interp_map_addr)
59588 - *interp_map_addr = map_addr;
59589 error = map_addr;
59590 if (BAD_ADDR(map_addr))
59591 goto out_close;
59592 @@ -490,8 +519,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
59593 k = load_addr + eppnt->p_vaddr;
59594 if (BAD_ADDR(k) ||
59595 eppnt->p_filesz > eppnt->p_memsz ||
59596 - eppnt->p_memsz > TASK_SIZE ||
59597 - TASK_SIZE - eppnt->p_memsz < k) {
59598 + eppnt->p_memsz > pax_task_size ||
59599 + pax_task_size - eppnt->p_memsz < k) {
59600 error = -ENOMEM;
59601 goto out_close;
59602 }
59603 @@ -530,9 +559,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
59604 elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1);
59605
59606 /* Map the last of the bss segment */
59607 - error = vm_brk(elf_bss, last_bss - elf_bss);
59608 - if (BAD_ADDR(error))
59609 - goto out_close;
59610 + if (last_bss > elf_bss) {
59611 + error = vm_brk(elf_bss, last_bss - elf_bss);
59612 + if (BAD_ADDR(error))
59613 + goto out_close;
59614 + }
59615 }
59616
59617 error = load_addr;
59618 @@ -543,6 +574,336 @@ out:
59619 return error;
59620 }
59621
59622 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
59623 +#ifdef CONFIG_PAX_SOFTMODE
59624 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
59625 +{
59626 + unsigned long pax_flags = 0UL;
59627 +
59628 +#ifdef CONFIG_PAX_PAGEEXEC
59629 + if (elf_phdata->p_flags & PF_PAGEEXEC)
59630 + pax_flags |= MF_PAX_PAGEEXEC;
59631 +#endif
59632 +
59633 +#ifdef CONFIG_PAX_SEGMEXEC
59634 + if (elf_phdata->p_flags & PF_SEGMEXEC)
59635 + pax_flags |= MF_PAX_SEGMEXEC;
59636 +#endif
59637 +
59638 +#ifdef CONFIG_PAX_EMUTRAMP
59639 + if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
59640 + pax_flags |= MF_PAX_EMUTRAMP;
59641 +#endif
59642 +
59643 +#ifdef CONFIG_PAX_MPROTECT
59644 + if (elf_phdata->p_flags & PF_MPROTECT)
59645 + pax_flags |= MF_PAX_MPROTECT;
59646 +#endif
59647 +
59648 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
59649 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
59650 + pax_flags |= MF_PAX_RANDMMAP;
59651 +#endif
59652 +
59653 + return pax_flags;
59654 +}
59655 +#endif
59656 +
59657 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
59658 +{
59659 + unsigned long pax_flags = 0UL;
59660 +
59661 +#ifdef CONFIG_PAX_PAGEEXEC
59662 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
59663 + pax_flags |= MF_PAX_PAGEEXEC;
59664 +#endif
59665 +
59666 +#ifdef CONFIG_PAX_SEGMEXEC
59667 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
59668 + pax_flags |= MF_PAX_SEGMEXEC;
59669 +#endif
59670 +
59671 +#ifdef CONFIG_PAX_EMUTRAMP
59672 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
59673 + pax_flags |= MF_PAX_EMUTRAMP;
59674 +#endif
59675 +
59676 +#ifdef CONFIG_PAX_MPROTECT
59677 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
59678 + pax_flags |= MF_PAX_MPROTECT;
59679 +#endif
59680 +
59681 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
59682 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
59683 + pax_flags |= MF_PAX_RANDMMAP;
59684 +#endif
59685 +
59686 + return pax_flags;
59687 +}
59688 +#endif
59689 +
59690 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
59691 +#ifdef CONFIG_PAX_SOFTMODE
59692 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
59693 +{
59694 + unsigned long pax_flags = 0UL;
59695 +
59696 +#ifdef CONFIG_PAX_PAGEEXEC
59697 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
59698 + pax_flags |= MF_PAX_PAGEEXEC;
59699 +#endif
59700 +
59701 +#ifdef CONFIG_PAX_SEGMEXEC
59702 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
59703 + pax_flags |= MF_PAX_SEGMEXEC;
59704 +#endif
59705 +
59706 +#ifdef CONFIG_PAX_EMUTRAMP
59707 + if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
59708 + pax_flags |= MF_PAX_EMUTRAMP;
59709 +#endif
59710 +
59711 +#ifdef CONFIG_PAX_MPROTECT
59712 + if (pax_flags_softmode & MF_PAX_MPROTECT)
59713 + pax_flags |= MF_PAX_MPROTECT;
59714 +#endif
59715 +
59716 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
59717 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
59718 + pax_flags |= MF_PAX_RANDMMAP;
59719 +#endif
59720 +
59721 + return pax_flags;
59722 +}
59723 +#endif
59724 +
59725 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
59726 +{
59727 + unsigned long pax_flags = 0UL;
59728 +
59729 +#ifdef CONFIG_PAX_PAGEEXEC
59730 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
59731 + pax_flags |= MF_PAX_PAGEEXEC;
59732 +#endif
59733 +
59734 +#ifdef CONFIG_PAX_SEGMEXEC
59735 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
59736 + pax_flags |= MF_PAX_SEGMEXEC;
59737 +#endif
59738 +
59739 +#ifdef CONFIG_PAX_EMUTRAMP
59740 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
59741 + pax_flags |= MF_PAX_EMUTRAMP;
59742 +#endif
59743 +
59744 +#ifdef CONFIG_PAX_MPROTECT
59745 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
59746 + pax_flags |= MF_PAX_MPROTECT;
59747 +#endif
59748 +
59749 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
59750 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
59751 + pax_flags |= MF_PAX_RANDMMAP;
59752 +#endif
59753 +
59754 + return pax_flags;
59755 +}
59756 +#endif
59757 +
59758 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
59759 +static unsigned long pax_parse_defaults(void)
59760 +{
59761 + unsigned long pax_flags = 0UL;
59762 +
59763 +#ifdef CONFIG_PAX_SOFTMODE
59764 + if (pax_softmode)
59765 + return pax_flags;
59766 +#endif
59767 +
59768 +#ifdef CONFIG_PAX_PAGEEXEC
59769 + pax_flags |= MF_PAX_PAGEEXEC;
59770 +#endif
59771 +
59772 +#ifdef CONFIG_PAX_SEGMEXEC
59773 + pax_flags |= MF_PAX_SEGMEXEC;
59774 +#endif
59775 +
59776 +#ifdef CONFIG_PAX_MPROTECT
59777 + pax_flags |= MF_PAX_MPROTECT;
59778 +#endif
59779 +
59780 +#ifdef CONFIG_PAX_RANDMMAP
59781 + if (randomize_va_space)
59782 + pax_flags |= MF_PAX_RANDMMAP;
59783 +#endif
59784 +
59785 + return pax_flags;
59786 +}
59787 +
59788 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
59789 +{
59790 + unsigned long pax_flags = PAX_PARSE_FLAGS_FALLBACK;
59791 +
59792 +#ifdef CONFIG_PAX_EI_PAX
59793 +
59794 +#ifdef CONFIG_PAX_SOFTMODE
59795 + if (pax_softmode)
59796 + return pax_flags;
59797 +#endif
59798 +
59799 + pax_flags = 0UL;
59800 +
59801 +#ifdef CONFIG_PAX_PAGEEXEC
59802 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
59803 + pax_flags |= MF_PAX_PAGEEXEC;
59804 +#endif
59805 +
59806 +#ifdef CONFIG_PAX_SEGMEXEC
59807 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
59808 + pax_flags |= MF_PAX_SEGMEXEC;
59809 +#endif
59810 +
59811 +#ifdef CONFIG_PAX_EMUTRAMP
59812 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
59813 + pax_flags |= MF_PAX_EMUTRAMP;
59814 +#endif
59815 +
59816 +#ifdef CONFIG_PAX_MPROTECT
59817 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
59818 + pax_flags |= MF_PAX_MPROTECT;
59819 +#endif
59820 +
59821 +#ifdef CONFIG_PAX_ASLR
59822 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
59823 + pax_flags |= MF_PAX_RANDMMAP;
59824 +#endif
59825 +
59826 +#endif
59827 +
59828 + return pax_flags;
59829 +
59830 +}
59831 +
59832 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
59833 +{
59834 +
59835 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
59836 + unsigned long i;
59837 +
59838 + for (i = 0UL; i < elf_ex->e_phnum; i++)
59839 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
59840 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
59841 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
59842 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
59843 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
59844 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
59845 + return PAX_PARSE_FLAGS_FALLBACK;
59846 +
59847 +#ifdef CONFIG_PAX_SOFTMODE
59848 + if (pax_softmode)
59849 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
59850 + else
59851 +#endif
59852 +
59853 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
59854 + break;
59855 + }
59856 +#endif
59857 +
59858 + return PAX_PARSE_FLAGS_FALLBACK;
59859 +}
59860 +
59861 +static unsigned long pax_parse_xattr_pax(struct file * const file)
59862 +{
59863 +
59864 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
59865 + ssize_t xattr_size, i;
59866 + unsigned char xattr_value[sizeof("pemrs") - 1];
59867 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
59868 +
59869 + xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
59870 + if (xattr_size < 0 || xattr_size > sizeof xattr_value)
59871 + return PAX_PARSE_FLAGS_FALLBACK;
59872 +
59873 + for (i = 0; i < xattr_size; i++)
59874 + switch (xattr_value[i]) {
59875 + default:
59876 + return PAX_PARSE_FLAGS_FALLBACK;
59877 +
59878 +#define parse_flag(option1, option2, flag) \
59879 + case option1: \
59880 + if (pax_flags_hardmode & MF_PAX_##flag) \
59881 + return PAX_PARSE_FLAGS_FALLBACK;\
59882 + pax_flags_hardmode |= MF_PAX_##flag; \
59883 + break; \
59884 + case option2: \
59885 + if (pax_flags_softmode & MF_PAX_##flag) \
59886 + return PAX_PARSE_FLAGS_FALLBACK;\
59887 + pax_flags_softmode |= MF_PAX_##flag; \
59888 + break;
59889 +
59890 + parse_flag('p', 'P', PAGEEXEC);
59891 + parse_flag('e', 'E', EMUTRAMP);
59892 + parse_flag('m', 'M', MPROTECT);
59893 + parse_flag('r', 'R', RANDMMAP);
59894 + parse_flag('s', 'S', SEGMEXEC);
59895 +
59896 +#undef parse_flag
59897 + }
59898 +
59899 + if (pax_flags_hardmode & pax_flags_softmode)
59900 + return PAX_PARSE_FLAGS_FALLBACK;
59901 +
59902 +#ifdef CONFIG_PAX_SOFTMODE
59903 + if (pax_softmode)
59904 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
59905 + else
59906 +#endif
59907 +
59908 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
59909 +#else
59910 + return PAX_PARSE_FLAGS_FALLBACK;
59911 +#endif
59912 +
59913 +}
59914 +
59915 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
59916 +{
59917 + unsigned long pax_flags, ei_pax_flags, pt_pax_flags, xattr_pax_flags;
59918 +
59919 + pax_flags = pax_parse_defaults();
59920 + ei_pax_flags = pax_parse_ei_pax(elf_ex);
59921 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
59922 + xattr_pax_flags = pax_parse_xattr_pax(file);
59923 +
59924 + if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
59925 + xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
59926 + pt_pax_flags != xattr_pax_flags)
59927 + return -EINVAL;
59928 + if (xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
59929 + pax_flags = xattr_pax_flags;
59930 + else if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
59931 + pax_flags = pt_pax_flags;
59932 + else if (ei_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
59933 + pax_flags = ei_pax_flags;
59934 +
59935 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
59936 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
59937 + if ((__supported_pte_mask & _PAGE_NX))
59938 + pax_flags &= ~MF_PAX_SEGMEXEC;
59939 + else
59940 + pax_flags &= ~MF_PAX_PAGEEXEC;
59941 + }
59942 +#endif
59943 +
59944 + if (0 > pax_check_flags(&pax_flags))
59945 + return -EINVAL;
59946 +
59947 + current->mm->pax_flags = pax_flags;
59948 + return 0;
59949 +}
59950 +#endif
59951 +
59952 /*
59953 * These are the functions used to load ELF style executables and shared
59954 * libraries. There is no binary dependent code anywhere else.
59955 @@ -556,6 +917,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
59956 {
59957 unsigned int random_variable = 0;
59958
59959 +#ifdef CONFIG_PAX_RANDUSTACK
59960 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
59961 + return stack_top - current->mm->delta_stack;
59962 +#endif
59963 +
59964 if ((current->flags & PF_RANDOMIZE) &&
59965 !(current->personality & ADDR_NO_RANDOMIZE)) {
59966 random_variable = get_random_int() & STACK_RND_MASK;
59967 @@ -574,7 +940,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
59968 unsigned long load_addr = 0, load_bias = 0;
59969 int load_addr_set = 0;
59970 char * elf_interpreter = NULL;
59971 - unsigned long error;
59972 + unsigned long error = 0;
59973 struct elf_phdr *elf_ppnt, *elf_phdata;
59974 unsigned long elf_bss, elf_brk;
59975 int retval, i;
59976 @@ -589,6 +955,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
59977 struct elfhdr elf_ex;
59978 struct elfhdr interp_elf_ex;
59979 } *loc;
59980 + unsigned long pax_task_size;
59981
59982 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
59983 if (!loc) {
59984 @@ -726,6 +1093,77 @@ static int load_elf_binary(struct linux_binprm *bprm)
59985 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
59986 may depend on the personality. */
59987 SET_PERSONALITY(loc->elf_ex);
59988 +
59989 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
59990 + current->mm->pax_flags = 0UL;
59991 +#endif
59992 +
59993 +#ifdef CONFIG_PAX_DLRESOLVE
59994 + current->mm->call_dl_resolve = 0UL;
59995 +#endif
59996 +
59997 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
59998 + current->mm->call_syscall = 0UL;
59999 +#endif
60000 +
60001 +#ifdef CONFIG_PAX_ASLR
60002 + current->mm->delta_mmap = 0UL;
60003 + current->mm->delta_stack = 0UL;
60004 +#endif
60005 +
60006 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
60007 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
60008 + send_sig(SIGKILL, current, 0);
60009 + goto out_free_dentry;
60010 + }
60011 +#endif
60012 +
60013 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
60014 + pax_set_initial_flags(bprm);
60015 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
60016 + if (pax_set_initial_flags_func)
60017 + (pax_set_initial_flags_func)(bprm);
60018 +#endif
60019 +
60020 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
60021 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
60022 + current->mm->context.user_cs_limit = PAGE_SIZE;
60023 + current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
60024 + }
60025 +#endif
60026 +
60027 +#ifdef CONFIG_PAX_SEGMEXEC
60028 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
60029 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
60030 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
60031 + pax_task_size = SEGMEXEC_TASK_SIZE;
60032 + current->mm->def_flags |= VM_NOHUGEPAGE;
60033 + } else
60034 +#endif
60035 +
60036 + pax_task_size = TASK_SIZE;
60037 +
60038 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
60039 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
60040 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
60041 + put_cpu();
60042 + }
60043 +#endif
60044 +
60045 +#ifdef CONFIG_PAX_ASLR
60046 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
60047 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
60048 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
60049 + }
60050 +#endif
60051 +
60052 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
60053 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
60054 + executable_stack = EXSTACK_DISABLE_X;
60055 + current->personality &= ~READ_IMPLIES_EXEC;
60056 + } else
60057 +#endif
60058 +
60059 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
60060 current->personality |= READ_IMPLIES_EXEC;
60061
60062 @@ -815,6 +1253,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
60063 #else
60064 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
60065 #endif
60066 +
60067 +#ifdef CONFIG_PAX_RANDMMAP
60068 + /* PaX: randomize base address at the default exe base if requested */
60069 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
60070 +#ifdef CONFIG_SPARC64
60071 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
60072 +#else
60073 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
60074 +#endif
60075 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
60076 + elf_flags |= MAP_FIXED;
60077 + }
60078 +#endif
60079 +
60080 }
60081
60082 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
60083 @@ -847,9 +1299,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
60084 * allowed task size. Note that p_filesz must always be
60085 * <= p_memsz so it is only necessary to check p_memsz.
60086 */
60087 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
60088 - elf_ppnt->p_memsz > TASK_SIZE ||
60089 - TASK_SIZE - elf_ppnt->p_memsz < k) {
60090 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
60091 + elf_ppnt->p_memsz > pax_task_size ||
60092 + pax_task_size - elf_ppnt->p_memsz < k) {
60093 /* set_brk can never work. Avoid overflows. */
60094 send_sig(SIGKILL, current, 0);
60095 retval = -EINVAL;
60096 @@ -888,17 +1340,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
60097 goto out_free_dentry;
60098 }
60099 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
60100 - send_sig(SIGSEGV, current, 0);
60101 - retval = -EFAULT; /* Nobody gets to see this, but.. */
60102 - goto out_free_dentry;
60103 + /*
60104 + * This bss-zeroing can fail if the ELF
60105 + * file specifies odd protections. So
60106 + * we don't check the return value
60107 + */
60108 }
60109
60110 +#ifdef CONFIG_PAX_RANDMMAP
60111 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
60112 + unsigned long start, size, flags;
60113 + vm_flags_t vm_flags;
60114 +
60115 + start = ELF_PAGEALIGN(elf_brk);
60116 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
60117 + flags = MAP_FIXED | MAP_PRIVATE;
60118 + vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
60119 +
60120 + down_write(&current->mm->mmap_sem);
60121 + start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
60122 + retval = -ENOMEM;
60123 + if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
60124 +// if (current->personality & ADDR_NO_RANDOMIZE)
60125 +// vm_flags |= VM_READ | VM_MAYREAD;
60126 + start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
60127 + retval = IS_ERR_VALUE(start) ? start : 0;
60128 + }
60129 + up_write(&current->mm->mmap_sem);
60130 + if (retval == 0)
60131 + retval = set_brk(start + size, start + size + PAGE_SIZE);
60132 + if (retval < 0) {
60133 + send_sig(SIGKILL, current, 0);
60134 + goto out_free_dentry;
60135 + }
60136 + }
60137 +#endif
60138 +
60139 if (elf_interpreter) {
60140 - unsigned long interp_map_addr = 0;
60141 -
60142 elf_entry = load_elf_interp(&loc->interp_elf_ex,
60143 interpreter,
60144 - &interp_map_addr,
60145 load_bias);
60146 if (!IS_ERR((void *)elf_entry)) {
60147 /*
60148 @@ -1130,7 +1610,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
60149 * Decide what to dump of a segment, part, all or none.
60150 */
60151 static unsigned long vma_dump_size(struct vm_area_struct *vma,
60152 - unsigned long mm_flags)
60153 + unsigned long mm_flags, long signr)
60154 {
60155 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
60156
60157 @@ -1168,7 +1648,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
60158 if (vma->vm_file == NULL)
60159 return 0;
60160
60161 - if (FILTER(MAPPED_PRIVATE))
60162 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
60163 goto whole;
60164
60165 /*
60166 @@ -1375,9 +1855,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
60167 {
60168 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
60169 int i = 0;
60170 - do
60171 + do {
60172 i += 2;
60173 - while (auxv[i - 2] != AT_NULL);
60174 + } while (auxv[i - 2] != AT_NULL);
60175 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
60176 }
60177
60178 @@ -1386,7 +1866,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
60179 {
60180 mm_segment_t old_fs = get_fs();
60181 set_fs(KERNEL_DS);
60182 - copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
60183 + copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
60184 set_fs(old_fs);
60185 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
60186 }
60187 @@ -2010,14 +2490,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
60188 }
60189
60190 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
60191 - unsigned long mm_flags)
60192 + struct coredump_params *cprm)
60193 {
60194 struct vm_area_struct *vma;
60195 size_t size = 0;
60196
60197 for (vma = first_vma(current, gate_vma); vma != NULL;
60198 vma = next_vma(vma, gate_vma))
60199 - size += vma_dump_size(vma, mm_flags);
60200 + size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
60201 return size;
60202 }
60203
60204 @@ -2108,7 +2588,7 @@ static int elf_core_dump(struct coredump_params *cprm)
60205
60206 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
60207
60208 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
60209 + offset += elf_core_vma_data_size(gate_vma, cprm);
60210 offset += elf_core_extra_data_size();
60211 e_shoff = offset;
60212
60213 @@ -2136,7 +2616,7 @@ static int elf_core_dump(struct coredump_params *cprm)
60214 phdr.p_offset = offset;
60215 phdr.p_vaddr = vma->vm_start;
60216 phdr.p_paddr = 0;
60217 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
60218 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
60219 phdr.p_memsz = vma->vm_end - vma->vm_start;
60220 offset += phdr.p_filesz;
60221 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
60222 @@ -2169,7 +2649,7 @@ static int elf_core_dump(struct coredump_params *cprm)
60223 unsigned long addr;
60224 unsigned long end;
60225
60226 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
60227 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
60228
60229 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
60230 struct page *page;
60231 @@ -2210,6 +2690,167 @@ out:
60232
60233 #endif /* CONFIG_ELF_CORE */
60234
60235 +#ifdef CONFIG_PAX_MPROTECT
60236 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
60237 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
60238 + * we'll remove VM_MAYWRITE for good on RELRO segments.
60239 + *
60240 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
60241 + * basis because we want to allow the common case and not the special ones.
60242 + */
60243 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
60244 +{
60245 + struct elfhdr elf_h;
60246 + struct elf_phdr elf_p;
60247 + unsigned long i;
60248 + unsigned long oldflags;
60249 + bool is_textrel_rw, is_textrel_rx, is_relro;
60250 +
60251 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
60252 + return;
60253 +
60254 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
60255 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
60256 +
60257 +#ifdef CONFIG_PAX_ELFRELOCS
60258 + /* possible TEXTREL */
60259 + is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
60260 + is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
60261 +#else
60262 + is_textrel_rw = false;
60263 + is_textrel_rx = false;
60264 +#endif
60265 +
60266 + /* possible RELRO */
60267 + is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
60268 +
60269 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
60270 + return;
60271 +
60272 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
60273 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
60274 +
60275 +#ifdef CONFIG_PAX_ETEXECRELOCS
60276 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
60277 +#else
60278 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
60279 +#endif
60280 +
60281 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
60282 + !elf_check_arch(&elf_h) ||
60283 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
60284 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
60285 + return;
60286 +
60287 + for (i = 0UL; i < elf_h.e_phnum; i++) {
60288 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
60289 + return;
60290 + switch (elf_p.p_type) {
60291 + case PT_DYNAMIC:
60292 + if (!is_textrel_rw && !is_textrel_rx)
60293 + continue;
60294 + i = 0UL;
60295 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
60296 + elf_dyn dyn;
60297 +
60298 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
60299 + break;
60300 + if (dyn.d_tag == DT_NULL)
60301 + break;
60302 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
60303 + gr_log_textrel(vma);
60304 + if (is_textrel_rw)
60305 + vma->vm_flags |= VM_MAYWRITE;
60306 + else
60307 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
60308 + vma->vm_flags &= ~VM_MAYWRITE;
60309 + break;
60310 + }
60311 + i++;
60312 + }
60313 + is_textrel_rw = false;
60314 + is_textrel_rx = false;
60315 + continue;
60316 +
60317 + case PT_GNU_RELRO:
60318 + if (!is_relro)
60319 + continue;
60320 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
60321 + vma->vm_flags &= ~VM_MAYWRITE;
60322 + is_relro = false;
60323 + continue;
60324 +
60325 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
60326 + case PT_PAX_FLAGS: {
60327 + const char *msg_mprotect = "", *msg_emutramp = "";
60328 + char *buffer_lib, *buffer_exe;
60329 +
60330 + if (elf_p.p_flags & PF_NOMPROTECT)
60331 + msg_mprotect = "MPROTECT disabled";
60332 +
60333 +#ifdef CONFIG_PAX_EMUTRAMP
60334 + if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
60335 + msg_emutramp = "EMUTRAMP enabled";
60336 +#endif
60337 +
60338 + if (!msg_mprotect[0] && !msg_emutramp[0])
60339 + continue;
60340 +
60341 + if (!printk_ratelimit())
60342 + continue;
60343 +
60344 + buffer_lib = (char *)__get_free_page(GFP_KERNEL);
60345 + buffer_exe = (char *)__get_free_page(GFP_KERNEL);
60346 + if (buffer_lib && buffer_exe) {
60347 + char *path_lib, *path_exe;
60348 +
60349 + path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
60350 + path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
60351 +
60352 + pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
60353 + (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
60354 +
60355 + }
60356 + free_page((unsigned long)buffer_exe);
60357 + free_page((unsigned long)buffer_lib);
60358 + continue;
60359 + }
60360 +#endif
60361 +
60362 + }
60363 + }
60364 +}
60365 +#endif
60366 +
60367 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
60368 +
60369 +extern int grsec_enable_log_rwxmaps;
60370 +
60371 +static void elf_handle_mmap(struct file *file)
60372 +{
60373 + struct elfhdr elf_h;
60374 + struct elf_phdr elf_p;
60375 + unsigned long i;
60376 +
60377 + if (!grsec_enable_log_rwxmaps)
60378 + return;
60379 +
60380 + if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
60381 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
60382 + (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
60383 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
60384 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
60385 + return;
60386 +
60387 + for (i = 0UL; i < elf_h.e_phnum; i++) {
60388 + if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
60389 + return;
60390 + if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
60391 + gr_log_ptgnustack(file);
60392 + }
60393 +}
60394 +#endif
60395 +
60396 static int __init init_elf_binfmt(void)
60397 {
60398 register_binfmt(&elf_format);
60399 diff --git a/fs/block_dev.c b/fs/block_dev.c
60400 index 6d72746..536d1db 100644
60401 --- a/fs/block_dev.c
60402 +++ b/fs/block_dev.c
60403 @@ -701,7 +701,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
60404 else if (bdev->bd_contains == bdev)
60405 return true; /* is a whole device which isn't held */
60406
60407 - else if (whole->bd_holder == bd_may_claim)
60408 + else if (whole->bd_holder == (void *)bd_may_claim)
60409 return true; /* is a partition of a device that is being partitioned */
60410 else if (whole->bd_holder != NULL)
60411 return false; /* is a partition of a held device */
60412 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
60413 index 8bbcc24..6f10d78 100644
60414 --- a/fs/btrfs/ctree.c
60415 +++ b/fs/btrfs/ctree.c
60416 @@ -1174,9 +1174,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
60417 free_extent_buffer(buf);
60418 add_root_to_dirty_list(root);
60419 } else {
60420 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
60421 - parent_start = parent->start;
60422 - else
60423 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
60424 + if (parent)
60425 + parent_start = parent->start;
60426 + else
60427 + parent_start = 0;
60428 + } else
60429 parent_start = 0;
60430
60431 WARN_ON(trans->transid != btrfs_header_generation(parent));
60432 diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
60433 index a2e90f8..5135e5f 100644
60434 --- a/fs/btrfs/delayed-inode.c
60435 +++ b/fs/btrfs/delayed-inode.c
60436 @@ -462,7 +462,7 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
60437
60438 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
60439 {
60440 - int seq = atomic_inc_return(&delayed_root->items_seq);
60441 + int seq = atomic_inc_return_unchecked(&delayed_root->items_seq);
60442 if ((atomic_dec_return(&delayed_root->items) <
60443 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
60444 waitqueue_active(&delayed_root->wait))
60445 @@ -1412,7 +1412,7 @@ void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
60446
60447 static int could_end_wait(struct btrfs_delayed_root *delayed_root, int seq)
60448 {
60449 - int val = atomic_read(&delayed_root->items_seq);
60450 + int val = atomic_read_unchecked(&delayed_root->items_seq);
60451
60452 if (val < seq || val >= seq + BTRFS_DELAYED_BATCH)
60453 return 1;
60454 @@ -1436,7 +1436,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
60455 int seq;
60456 int ret;
60457
60458 - seq = atomic_read(&delayed_root->items_seq);
60459 + seq = atomic_read_unchecked(&delayed_root->items_seq);
60460
60461 ret = btrfs_wq_run_delayed_node(delayed_root, root, 0);
60462 if (ret)
60463 diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
60464 index f70119f..ab5894d 100644
60465 --- a/fs/btrfs/delayed-inode.h
60466 +++ b/fs/btrfs/delayed-inode.h
60467 @@ -43,7 +43,7 @@ struct btrfs_delayed_root {
60468 */
60469 struct list_head prepare_list;
60470 atomic_t items; /* for delayed items */
60471 - atomic_t items_seq; /* for delayed items */
60472 + atomic_unchecked_t items_seq; /* for delayed items */
60473 int nodes; /* for delayed nodes */
60474 wait_queue_head_t wait;
60475 };
60476 @@ -90,7 +90,7 @@ static inline void btrfs_init_delayed_root(
60477 struct btrfs_delayed_root *delayed_root)
60478 {
60479 atomic_set(&delayed_root->items, 0);
60480 - atomic_set(&delayed_root->items_seq, 0);
60481 + atomic_set_unchecked(&delayed_root->items_seq, 0);
60482 delayed_root->nodes = 0;
60483 spin_lock_init(&delayed_root->lock);
60484 init_waitqueue_head(&delayed_root->wait);
60485 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
60486 index b765d41..5a8b0c3 100644
60487 --- a/fs/btrfs/ioctl.c
60488 +++ b/fs/btrfs/ioctl.c
60489 @@ -3975,9 +3975,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
60490 for (i = 0; i < num_types; i++) {
60491 struct btrfs_space_info *tmp;
60492
60493 + /* Don't copy in more than we allocated */
60494 if (!slot_count)
60495 break;
60496
60497 + slot_count--;
60498 +
60499 info = NULL;
60500 rcu_read_lock();
60501 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
60502 @@ -3999,10 +4002,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
60503 memcpy(dest, &space, sizeof(space));
60504 dest++;
60505 space_args.total_spaces++;
60506 - slot_count--;
60507 }
60508 - if (!slot_count)
60509 - break;
60510 }
60511 up_read(&info->groups_sem);
60512 }
60513 diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
60514 index c4124de..d7613eb6 100644
60515 --- a/fs/btrfs/super.c
60516 +++ b/fs/btrfs/super.c
60517 @@ -270,7 +270,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
60518 function, line, errstr);
60519 return;
60520 }
60521 - ACCESS_ONCE(trans->transaction->aborted) = errno;
60522 + ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
60523 /* Wake up anybody who may be waiting on this transaction */
60524 wake_up(&root->fs_info->transaction_wait);
60525 wake_up(&root->fs_info->transaction_blocked_wait);
60526 diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
60527 index 12e5355..cdf30c6 100644
60528 --- a/fs/btrfs/sysfs.c
60529 +++ b/fs/btrfs/sysfs.c
60530 @@ -475,7 +475,7 @@ static int addrm_unknown_feature_attrs(struct btrfs_fs_info *fs_info, bool add)
60531 for (set = 0; set < FEAT_MAX; set++) {
60532 int i;
60533 struct attribute *attrs[2];
60534 - struct attribute_group agroup = {
60535 + attribute_group_no_const agroup = {
60536 .name = "features",
60537 .attrs = attrs,
60538 };
60539 diff --git a/fs/btrfs/tree-log.h b/fs/btrfs/tree-log.h
60540 index e2e798a..f454c18 100644
60541 --- a/fs/btrfs/tree-log.h
60542 +++ b/fs/btrfs/tree-log.h
60543 @@ -41,7 +41,7 @@ static inline void btrfs_init_log_ctx(struct btrfs_log_ctx *ctx)
60544 static inline void btrfs_set_log_full_commit(struct btrfs_fs_info *fs_info,
60545 struct btrfs_trans_handle *trans)
60546 {
60547 - ACCESS_ONCE(fs_info->last_trans_log_full_commit) = trans->transid;
60548 + ACCESS_ONCE_RW(fs_info->last_trans_log_full_commit) = trans->transid;
60549 }
60550
60551 static inline int btrfs_need_log_full_commit(struct btrfs_fs_info *fs_info,
60552 diff --git a/fs/buffer.c b/fs/buffer.c
60553 index 72daaa5..60ffeb9 100644
60554 --- a/fs/buffer.c
60555 +++ b/fs/buffer.c
60556 @@ -3432,7 +3432,7 @@ void __init buffer_init(void)
60557 bh_cachep = kmem_cache_create("buffer_head",
60558 sizeof(struct buffer_head), 0,
60559 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
60560 - SLAB_MEM_SPREAD),
60561 + SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
60562 NULL);
60563
60564 /*
60565 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
60566 index fbb08e9..0fda764 100644
60567 --- a/fs/cachefiles/bind.c
60568 +++ b/fs/cachefiles/bind.c
60569 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
60570 args);
60571
60572 /* start by checking things over */
60573 - ASSERT(cache->fstop_percent >= 0 &&
60574 - cache->fstop_percent < cache->fcull_percent &&
60575 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
60576 cache->fcull_percent < cache->frun_percent &&
60577 cache->frun_percent < 100);
60578
60579 - ASSERT(cache->bstop_percent >= 0 &&
60580 - cache->bstop_percent < cache->bcull_percent &&
60581 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
60582 cache->bcull_percent < cache->brun_percent &&
60583 cache->brun_percent < 100);
60584
60585 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
60586 index ce1b115..4a6852c 100644
60587 --- a/fs/cachefiles/daemon.c
60588 +++ b/fs/cachefiles/daemon.c
60589 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
60590 if (n > buflen)
60591 return -EMSGSIZE;
60592
60593 - if (copy_to_user(_buffer, buffer, n) != 0)
60594 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
60595 return -EFAULT;
60596
60597 return n;
60598 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
60599 if (test_bit(CACHEFILES_DEAD, &cache->flags))
60600 return -EIO;
60601
60602 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
60603 + if (datalen > PAGE_SIZE - 1)
60604 return -EOPNOTSUPP;
60605
60606 /* drag the command string into the kernel so we can parse it */
60607 @@ -385,7 +385,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
60608 if (args[0] != '%' || args[1] != '\0')
60609 return -EINVAL;
60610
60611 - if (fstop < 0 || fstop >= cache->fcull_percent)
60612 + if (fstop >= cache->fcull_percent)
60613 return cachefiles_daemon_range_error(cache, args);
60614
60615 cache->fstop_percent = fstop;
60616 @@ -457,7 +457,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
60617 if (args[0] != '%' || args[1] != '\0')
60618 return -EINVAL;
60619
60620 - if (bstop < 0 || bstop >= cache->bcull_percent)
60621 + if (bstop >= cache->bcull_percent)
60622 return cachefiles_daemon_range_error(cache, args);
60623
60624 cache->bstop_percent = bstop;
60625 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
60626 index 8c52472..c4e3a69 100644
60627 --- a/fs/cachefiles/internal.h
60628 +++ b/fs/cachefiles/internal.h
60629 @@ -66,7 +66,7 @@ struct cachefiles_cache {
60630 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
60631 struct rb_root active_nodes; /* active nodes (can't be culled) */
60632 rwlock_t active_lock; /* lock for active_nodes */
60633 - atomic_t gravecounter; /* graveyard uniquifier */
60634 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
60635 unsigned frun_percent; /* when to stop culling (% files) */
60636 unsigned fcull_percent; /* when to start culling (% files) */
60637 unsigned fstop_percent; /* when to stop allocating (% files) */
60638 @@ -178,19 +178,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
60639 * proc.c
60640 */
60641 #ifdef CONFIG_CACHEFILES_HISTOGRAM
60642 -extern atomic_t cachefiles_lookup_histogram[HZ];
60643 -extern atomic_t cachefiles_mkdir_histogram[HZ];
60644 -extern atomic_t cachefiles_create_histogram[HZ];
60645 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
60646 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
60647 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
60648
60649 extern int __init cachefiles_proc_init(void);
60650 extern void cachefiles_proc_cleanup(void);
60651 static inline
60652 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
60653 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
60654 {
60655 unsigned long jif = jiffies - start_jif;
60656 if (jif >= HZ)
60657 jif = HZ - 1;
60658 - atomic_inc(&histogram[jif]);
60659 + atomic_inc_unchecked(&histogram[jif]);
60660 }
60661
60662 #else
60663 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
60664 index dad7d95..07475af 100644
60665 --- a/fs/cachefiles/namei.c
60666 +++ b/fs/cachefiles/namei.c
60667 @@ -312,7 +312,7 @@ try_again:
60668 /* first step is to make up a grave dentry in the graveyard */
60669 sprintf(nbuffer, "%08x%08x",
60670 (uint32_t) get_seconds(),
60671 - (uint32_t) atomic_inc_return(&cache->gravecounter));
60672 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
60673
60674 /* do the multiway lock magic */
60675 trap = lock_rename(cache->graveyard, dir);
60676 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
60677 index eccd339..4c1d995 100644
60678 --- a/fs/cachefiles/proc.c
60679 +++ b/fs/cachefiles/proc.c
60680 @@ -14,9 +14,9 @@
60681 #include <linux/seq_file.h>
60682 #include "internal.h"
60683
60684 -atomic_t cachefiles_lookup_histogram[HZ];
60685 -atomic_t cachefiles_mkdir_histogram[HZ];
60686 -atomic_t cachefiles_create_histogram[HZ];
60687 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
60688 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
60689 +atomic_unchecked_t cachefiles_create_histogram[HZ];
60690
60691 /*
60692 * display the latency histogram
60693 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
60694 return 0;
60695 default:
60696 index = (unsigned long) v - 3;
60697 - x = atomic_read(&cachefiles_lookup_histogram[index]);
60698 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
60699 - z = atomic_read(&cachefiles_create_histogram[index]);
60700 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
60701 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
60702 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
60703 if (x == 0 && y == 0 && z == 0)
60704 return 0;
60705
60706 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
60707 index 25e745b..220e604 100644
60708 --- a/fs/cachefiles/rdwr.c
60709 +++ b/fs/cachefiles/rdwr.c
60710 @@ -937,7 +937,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
60711 old_fs = get_fs();
60712 set_fs(KERNEL_DS);
60713 ret = file->f_op->write(
60714 - file, (const void __user *) data, len, &pos);
60715 + file, (const void __force_user *) data, len, &pos);
60716 set_fs(old_fs);
60717 kunmap(page);
60718 file_end_write(file);
60719 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
60720 index c29d6ae..719b9bb 100644
60721 --- a/fs/ceph/dir.c
60722 +++ b/fs/ceph/dir.c
60723 @@ -129,6 +129,8 @@ static int __dcache_readdir(struct file *file, struct dir_context *ctx,
60724 struct dentry *dentry, *last;
60725 struct ceph_dentry_info *di;
60726 int err = 0;
60727 + char d_name[DNAME_INLINE_LEN];
60728 + const unsigned char *name;
60729
60730 /* claim ref on last dentry we returned */
60731 last = fi->dentry;
60732 @@ -192,7 +194,12 @@ more:
60733
60734 dout(" %llu (%llu) dentry %p %.*s %p\n", di->offset, ctx->pos,
60735 dentry, dentry->d_name.len, dentry->d_name.name, dentry->d_inode);
60736 - if (!dir_emit(ctx, dentry->d_name.name,
60737 + name = dentry->d_name.name;
60738 + if (name == dentry->d_iname) {
60739 + memcpy(d_name, name, dentry->d_name.len);
60740 + name = d_name;
60741 + }
60742 + if (!dir_emit(ctx, name,
60743 dentry->d_name.len,
60744 ceph_translate_ino(dentry->d_sb, dentry->d_inode->i_ino),
60745 dentry->d_inode->i_mode >> 12)) {
60746 @@ -250,7 +257,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
60747 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
60748 struct ceph_mds_client *mdsc = fsc->mdsc;
60749 unsigned frag = fpos_frag(ctx->pos);
60750 - int off = fpos_off(ctx->pos);
60751 + unsigned int off = fpos_off(ctx->pos);
60752 int err;
60753 u32 ftype;
60754 struct ceph_mds_reply_info_parsed *rinfo;
60755 diff --git a/fs/ceph/ioctl.c b/fs/ceph/ioctl.c
60756 index a822a6e..4644256 100644
60757 --- a/fs/ceph/ioctl.c
60758 +++ b/fs/ceph/ioctl.c
60759 @@ -41,7 +41,7 @@ static long __validate_layout(struct ceph_mds_client *mdsc,
60760 /* validate striping parameters */
60761 if ((l->object_size & ~PAGE_MASK) ||
60762 (l->stripe_unit & ~PAGE_MASK) ||
60763 - (l->stripe_unit != 0 &&
60764 + ((unsigned)l->stripe_unit != 0 &&
60765 ((unsigned)l->object_size % (unsigned)l->stripe_unit)))
60766 return -EINVAL;
60767
60768 diff --git a/fs/ceph/super.c b/fs/ceph/super.c
60769 index f6e1237..796ffd1 100644
60770 --- a/fs/ceph/super.c
60771 +++ b/fs/ceph/super.c
60772 @@ -895,7 +895,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
60773 /*
60774 * construct our own bdi so we can control readahead, etc.
60775 */
60776 -static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
60777 +static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
60778
60779 static int ceph_register_bdi(struct super_block *sb,
60780 struct ceph_fs_client *fsc)
60781 @@ -912,7 +912,7 @@ static int ceph_register_bdi(struct super_block *sb,
60782 default_backing_dev_info.ra_pages;
60783
60784 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
60785 - atomic_long_inc_return(&bdi_seq));
60786 + atomic_long_inc_return_unchecked(&bdi_seq));
60787 if (!err)
60788 sb->s_bdi = &fsc->backing_dev_info;
60789 return err;
60790 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
60791 index 44ec726..bcb06a3 100644
60792 --- a/fs/cifs/cifs_debug.c
60793 +++ b/fs/cifs/cifs_debug.c
60794 @@ -286,8 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
60795
60796 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
60797 #ifdef CONFIG_CIFS_STATS2
60798 - atomic_set(&totBufAllocCount, 0);
60799 - atomic_set(&totSmBufAllocCount, 0);
60800 + atomic_set_unchecked(&totBufAllocCount, 0);
60801 + atomic_set_unchecked(&totSmBufAllocCount, 0);
60802 #endif /* CONFIG_CIFS_STATS2 */
60803 spin_lock(&cifs_tcp_ses_lock);
60804 list_for_each(tmp1, &cifs_tcp_ses_list) {
60805 @@ -300,7 +300,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
60806 tcon = list_entry(tmp3,
60807 struct cifs_tcon,
60808 tcon_list);
60809 - atomic_set(&tcon->num_smbs_sent, 0);
60810 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
60811 if (server->ops->clear_stats)
60812 server->ops->clear_stats(tcon);
60813 }
60814 @@ -332,8 +332,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
60815 smBufAllocCount.counter, cifs_min_small);
60816 #ifdef CONFIG_CIFS_STATS2
60817 seq_printf(m, "Total Large %d Small %d Allocations\n",
60818 - atomic_read(&totBufAllocCount),
60819 - atomic_read(&totSmBufAllocCount));
60820 + atomic_read_unchecked(&totBufAllocCount),
60821 + atomic_read_unchecked(&totSmBufAllocCount));
60822 #endif /* CONFIG_CIFS_STATS2 */
60823
60824 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
60825 @@ -362,7 +362,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
60826 if (tcon->need_reconnect)
60827 seq_puts(m, "\tDISCONNECTED ");
60828 seq_printf(m, "\nSMBs: %d",
60829 - atomic_read(&tcon->num_smbs_sent));
60830 + atomic_read_unchecked(&tcon->num_smbs_sent));
60831 if (server->ops->print_stats)
60832 server->ops->print_stats(m, tcon);
60833 }
60834 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
60835 index 889b984..fcb8431 100644
60836 --- a/fs/cifs/cifsfs.c
60837 +++ b/fs/cifs/cifsfs.c
60838 @@ -1092,7 +1092,7 @@ cifs_init_request_bufs(void)
60839 */
60840 cifs_req_cachep = kmem_cache_create("cifs_request",
60841 CIFSMaxBufSize + max_hdr_size, 0,
60842 - SLAB_HWCACHE_ALIGN, NULL);
60843 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
60844 if (cifs_req_cachep == NULL)
60845 return -ENOMEM;
60846
60847 @@ -1119,7 +1119,7 @@ cifs_init_request_bufs(void)
60848 efficient to alloc 1 per page off the slab compared to 17K (5page)
60849 alloc of large cifs buffers even when page debugging is on */
60850 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
60851 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
60852 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
60853 NULL);
60854 if (cifs_sm_req_cachep == NULL) {
60855 mempool_destroy(cifs_req_poolp);
60856 @@ -1204,8 +1204,8 @@ init_cifs(void)
60857 atomic_set(&bufAllocCount, 0);
60858 atomic_set(&smBufAllocCount, 0);
60859 #ifdef CONFIG_CIFS_STATS2
60860 - atomic_set(&totBufAllocCount, 0);
60861 - atomic_set(&totSmBufAllocCount, 0);
60862 + atomic_set_unchecked(&totBufAllocCount, 0);
60863 + atomic_set_unchecked(&totSmBufAllocCount, 0);
60864 #endif /* CONFIG_CIFS_STATS2 */
60865
60866 atomic_set(&midCount, 0);
60867 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
60868 index 25b8392..01e46dc 100644
60869 --- a/fs/cifs/cifsglob.h
60870 +++ b/fs/cifs/cifsglob.h
60871 @@ -821,35 +821,35 @@ struct cifs_tcon {
60872 __u16 Flags; /* optional support bits */
60873 enum statusEnum tidStatus;
60874 #ifdef CONFIG_CIFS_STATS
60875 - atomic_t num_smbs_sent;
60876 + atomic_unchecked_t num_smbs_sent;
60877 union {
60878 struct {
60879 - atomic_t num_writes;
60880 - atomic_t num_reads;
60881 - atomic_t num_flushes;
60882 - atomic_t num_oplock_brks;
60883 - atomic_t num_opens;
60884 - atomic_t num_closes;
60885 - atomic_t num_deletes;
60886 - atomic_t num_mkdirs;
60887 - atomic_t num_posixopens;
60888 - atomic_t num_posixmkdirs;
60889 - atomic_t num_rmdirs;
60890 - atomic_t num_renames;
60891 - atomic_t num_t2renames;
60892 - atomic_t num_ffirst;
60893 - atomic_t num_fnext;
60894 - atomic_t num_fclose;
60895 - atomic_t num_hardlinks;
60896 - atomic_t num_symlinks;
60897 - atomic_t num_locks;
60898 - atomic_t num_acl_get;
60899 - atomic_t num_acl_set;
60900 + atomic_unchecked_t num_writes;
60901 + atomic_unchecked_t num_reads;
60902 + atomic_unchecked_t num_flushes;
60903 + atomic_unchecked_t num_oplock_brks;
60904 + atomic_unchecked_t num_opens;
60905 + atomic_unchecked_t num_closes;
60906 + atomic_unchecked_t num_deletes;
60907 + atomic_unchecked_t num_mkdirs;
60908 + atomic_unchecked_t num_posixopens;
60909 + atomic_unchecked_t num_posixmkdirs;
60910 + atomic_unchecked_t num_rmdirs;
60911 + atomic_unchecked_t num_renames;
60912 + atomic_unchecked_t num_t2renames;
60913 + atomic_unchecked_t num_ffirst;
60914 + atomic_unchecked_t num_fnext;
60915 + atomic_unchecked_t num_fclose;
60916 + atomic_unchecked_t num_hardlinks;
60917 + atomic_unchecked_t num_symlinks;
60918 + atomic_unchecked_t num_locks;
60919 + atomic_unchecked_t num_acl_get;
60920 + atomic_unchecked_t num_acl_set;
60921 } cifs_stats;
60922 #ifdef CONFIG_CIFS_SMB2
60923 struct {
60924 - atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
60925 - atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
60926 + atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
60927 + atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
60928 } smb2_stats;
60929 #endif /* CONFIG_CIFS_SMB2 */
60930 } stats;
60931 @@ -1190,7 +1190,7 @@ convert_delimiter(char *path, char delim)
60932 }
60933
60934 #ifdef CONFIG_CIFS_STATS
60935 -#define cifs_stats_inc atomic_inc
60936 +#define cifs_stats_inc atomic_inc_unchecked
60937
60938 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
60939 unsigned int bytes)
60940 @@ -1557,8 +1557,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
60941 /* Various Debug counters */
60942 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
60943 #ifdef CONFIG_CIFS_STATS2
60944 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
60945 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
60946 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
60947 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
60948 #endif
60949 GLOBAL_EXTERN atomic_t smBufAllocCount;
60950 GLOBAL_EXTERN atomic_t midCount;
60951 diff --git a/fs/cifs/file.c b/fs/cifs/file.c
60952 index 5f29354..359bc0d 100644
60953 --- a/fs/cifs/file.c
60954 +++ b/fs/cifs/file.c
60955 @@ -2056,10 +2056,14 @@ static int cifs_writepages(struct address_space *mapping,
60956 index = mapping->writeback_index; /* Start from prev offset */
60957 end = -1;
60958 } else {
60959 - index = wbc->range_start >> PAGE_CACHE_SHIFT;
60960 - end = wbc->range_end >> PAGE_CACHE_SHIFT;
60961 - if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
60962 + if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) {
60963 range_whole = true;
60964 + index = 0;
60965 + end = ULONG_MAX;
60966 + } else {
60967 + index = wbc->range_start >> PAGE_CACHE_SHIFT;
60968 + end = wbc->range_end >> PAGE_CACHE_SHIFT;
60969 + }
60970 scanned = true;
60971 }
60972 server = cifs_sb_master_tcon(cifs_sb)->ses->server;
60973 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
60974 index b7415d5..3984ec0 100644
60975 --- a/fs/cifs/misc.c
60976 +++ b/fs/cifs/misc.c
60977 @@ -170,7 +170,7 @@ cifs_buf_get(void)
60978 memset(ret_buf, 0, buf_size + 3);
60979 atomic_inc(&bufAllocCount);
60980 #ifdef CONFIG_CIFS_STATS2
60981 - atomic_inc(&totBufAllocCount);
60982 + atomic_inc_unchecked(&totBufAllocCount);
60983 #endif /* CONFIG_CIFS_STATS2 */
60984 }
60985
60986 @@ -205,7 +205,7 @@ cifs_small_buf_get(void)
60987 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
60988 atomic_inc(&smBufAllocCount);
60989 #ifdef CONFIG_CIFS_STATS2
60990 - atomic_inc(&totSmBufAllocCount);
60991 + atomic_inc_unchecked(&totSmBufAllocCount);
60992 #endif /* CONFIG_CIFS_STATS2 */
60993
60994 }
60995 diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
60996 index 52131d8..fd79e97 100644
60997 --- a/fs/cifs/smb1ops.c
60998 +++ b/fs/cifs/smb1ops.c
60999 @@ -626,27 +626,27 @@ static void
61000 cifs_clear_stats(struct cifs_tcon *tcon)
61001 {
61002 #ifdef CONFIG_CIFS_STATS
61003 - atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
61004 - atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
61005 - atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
61006 - atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
61007 - atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
61008 - atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
61009 - atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
61010 - atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
61011 - atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
61012 - atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
61013 - atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
61014 - atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
61015 - atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
61016 - atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
61017 - atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
61018 - atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
61019 - atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
61020 - atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
61021 - atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
61022 - atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
61023 - atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
61024 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
61025 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
61026 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
61027 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
61028 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
61029 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
61030 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
61031 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
61032 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
61033 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
61034 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
61035 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
61036 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
61037 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
61038 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
61039 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
61040 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
61041 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
61042 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
61043 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
61044 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
61045 #endif
61046 }
61047
61048 @@ -655,36 +655,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
61049 {
61050 #ifdef CONFIG_CIFS_STATS
61051 seq_printf(m, " Oplocks breaks: %d",
61052 - atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
61053 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
61054 seq_printf(m, "\nReads: %d Bytes: %llu",
61055 - atomic_read(&tcon->stats.cifs_stats.num_reads),
61056 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
61057 (long long)(tcon->bytes_read));
61058 seq_printf(m, "\nWrites: %d Bytes: %llu",
61059 - atomic_read(&tcon->stats.cifs_stats.num_writes),
61060 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
61061 (long long)(tcon->bytes_written));
61062 seq_printf(m, "\nFlushes: %d",
61063 - atomic_read(&tcon->stats.cifs_stats.num_flushes));
61064 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
61065 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
61066 - atomic_read(&tcon->stats.cifs_stats.num_locks),
61067 - atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
61068 - atomic_read(&tcon->stats.cifs_stats.num_symlinks));
61069 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
61070 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
61071 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
61072 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
61073 - atomic_read(&tcon->stats.cifs_stats.num_opens),
61074 - atomic_read(&tcon->stats.cifs_stats.num_closes),
61075 - atomic_read(&tcon->stats.cifs_stats.num_deletes));
61076 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
61077 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
61078 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
61079 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
61080 - atomic_read(&tcon->stats.cifs_stats.num_posixopens),
61081 - atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
61082 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
61083 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
61084 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
61085 - atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
61086 - atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
61087 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
61088 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
61089 seq_printf(m, "\nRenames: %d T2 Renames %d",
61090 - atomic_read(&tcon->stats.cifs_stats.num_renames),
61091 - atomic_read(&tcon->stats.cifs_stats.num_t2renames));
61092 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
61093 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
61094 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
61095 - atomic_read(&tcon->stats.cifs_stats.num_ffirst),
61096 - atomic_read(&tcon->stats.cifs_stats.num_fnext),
61097 - atomic_read(&tcon->stats.cifs_stats.num_fclose));
61098 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
61099 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
61100 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
61101 #endif
61102 }
61103
61104 diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
61105 index f522193..586121b 100644
61106 --- a/fs/cifs/smb2ops.c
61107 +++ b/fs/cifs/smb2ops.c
61108 @@ -414,8 +414,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
61109 #ifdef CONFIG_CIFS_STATS
61110 int i;
61111 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
61112 - atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
61113 - atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
61114 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
61115 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
61116 }
61117 #endif
61118 }
61119 @@ -455,65 +455,65 @@ static void
61120 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
61121 {
61122 #ifdef CONFIG_CIFS_STATS
61123 - atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
61124 - atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
61125 + atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
61126 + atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
61127 seq_printf(m, "\nNegotiates: %d sent %d failed",
61128 - atomic_read(&sent[SMB2_NEGOTIATE_HE]),
61129 - atomic_read(&failed[SMB2_NEGOTIATE_HE]));
61130 + atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
61131 + atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
61132 seq_printf(m, "\nSessionSetups: %d sent %d failed",
61133 - atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
61134 - atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
61135 + atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
61136 + atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
61137 seq_printf(m, "\nLogoffs: %d sent %d failed",
61138 - atomic_read(&sent[SMB2_LOGOFF_HE]),
61139 - atomic_read(&failed[SMB2_LOGOFF_HE]));
61140 + atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
61141 + atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
61142 seq_printf(m, "\nTreeConnects: %d sent %d failed",
61143 - atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
61144 - atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
61145 + atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
61146 + atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
61147 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
61148 - atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
61149 - atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
61150 + atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
61151 + atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
61152 seq_printf(m, "\nCreates: %d sent %d failed",
61153 - atomic_read(&sent[SMB2_CREATE_HE]),
61154 - atomic_read(&failed[SMB2_CREATE_HE]));
61155 + atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
61156 + atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
61157 seq_printf(m, "\nCloses: %d sent %d failed",
61158 - atomic_read(&sent[SMB2_CLOSE_HE]),
61159 - atomic_read(&failed[SMB2_CLOSE_HE]));
61160 + atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
61161 + atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
61162 seq_printf(m, "\nFlushes: %d sent %d failed",
61163 - atomic_read(&sent[SMB2_FLUSH_HE]),
61164 - atomic_read(&failed[SMB2_FLUSH_HE]));
61165 + atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
61166 + atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
61167 seq_printf(m, "\nReads: %d sent %d failed",
61168 - atomic_read(&sent[SMB2_READ_HE]),
61169 - atomic_read(&failed[SMB2_READ_HE]));
61170 + atomic_read_unchecked(&sent[SMB2_READ_HE]),
61171 + atomic_read_unchecked(&failed[SMB2_READ_HE]));
61172 seq_printf(m, "\nWrites: %d sent %d failed",
61173 - atomic_read(&sent[SMB2_WRITE_HE]),
61174 - atomic_read(&failed[SMB2_WRITE_HE]));
61175 + atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
61176 + atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
61177 seq_printf(m, "\nLocks: %d sent %d failed",
61178 - atomic_read(&sent[SMB2_LOCK_HE]),
61179 - atomic_read(&failed[SMB2_LOCK_HE]));
61180 + atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
61181 + atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
61182 seq_printf(m, "\nIOCTLs: %d sent %d failed",
61183 - atomic_read(&sent[SMB2_IOCTL_HE]),
61184 - atomic_read(&failed[SMB2_IOCTL_HE]));
61185 + atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
61186 + atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
61187 seq_printf(m, "\nCancels: %d sent %d failed",
61188 - atomic_read(&sent[SMB2_CANCEL_HE]),
61189 - atomic_read(&failed[SMB2_CANCEL_HE]));
61190 + atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
61191 + atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
61192 seq_printf(m, "\nEchos: %d sent %d failed",
61193 - atomic_read(&sent[SMB2_ECHO_HE]),
61194 - atomic_read(&failed[SMB2_ECHO_HE]));
61195 + atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
61196 + atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
61197 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
61198 - atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
61199 - atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
61200 + atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
61201 + atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
61202 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
61203 - atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
61204 - atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
61205 + atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
61206 + atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
61207 seq_printf(m, "\nQueryInfos: %d sent %d failed",
61208 - atomic_read(&sent[SMB2_QUERY_INFO_HE]),
61209 - atomic_read(&failed[SMB2_QUERY_INFO_HE]));
61210 + atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
61211 + atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
61212 seq_printf(m, "\nSetInfos: %d sent %d failed",
61213 - atomic_read(&sent[SMB2_SET_INFO_HE]),
61214 - atomic_read(&failed[SMB2_SET_INFO_HE]));
61215 + atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
61216 + atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
61217 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
61218 - atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
61219 - atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
61220 + atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
61221 + atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
61222 #endif
61223 }
61224
61225 diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
61226 index 74b3a66..0c709f3 100644
61227 --- a/fs/cifs/smb2pdu.c
61228 +++ b/fs/cifs/smb2pdu.c
61229 @@ -2143,8 +2143,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
61230 default:
61231 cifs_dbg(VFS, "info level %u isn't supported\n",
61232 srch_inf->info_level);
61233 - rc = -EINVAL;
61234 - goto qdir_exit;
61235 + return -EINVAL;
61236 }
61237
61238 req->FileIndex = cpu_to_le32(index);
61239 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
61240 index 278f8fd..e69c52d 100644
61241 --- a/fs/coda/cache.c
61242 +++ b/fs/coda/cache.c
61243 @@ -24,7 +24,7 @@
61244 #include "coda_linux.h"
61245 #include "coda_cache.h"
61246
61247 -static atomic_t permission_epoch = ATOMIC_INIT(0);
61248 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
61249
61250 /* replace or extend an acl cache hit */
61251 void coda_cache_enter(struct inode *inode, int mask)
61252 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
61253 struct coda_inode_info *cii = ITOC(inode);
61254
61255 spin_lock(&cii->c_lock);
61256 - cii->c_cached_epoch = atomic_read(&permission_epoch);
61257 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
61258 if (!uid_eq(cii->c_uid, current_fsuid())) {
61259 cii->c_uid = current_fsuid();
61260 cii->c_cached_perm = mask;
61261 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
61262 {
61263 struct coda_inode_info *cii = ITOC(inode);
61264 spin_lock(&cii->c_lock);
61265 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
61266 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
61267 spin_unlock(&cii->c_lock);
61268 }
61269
61270 /* remove all acl caches */
61271 void coda_cache_clear_all(struct super_block *sb)
61272 {
61273 - atomic_inc(&permission_epoch);
61274 + atomic_inc_unchecked(&permission_epoch);
61275 }
61276
61277
61278 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
61279 spin_lock(&cii->c_lock);
61280 hit = (mask & cii->c_cached_perm) == mask &&
61281 uid_eq(cii->c_uid, current_fsuid()) &&
61282 - cii->c_cached_epoch == atomic_read(&permission_epoch);
61283 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
61284 spin_unlock(&cii->c_lock);
61285
61286 return hit;
61287 diff --git a/fs/compat.c b/fs/compat.c
61288 index 66d3d3c..9c10175 100644
61289 --- a/fs/compat.c
61290 +++ b/fs/compat.c
61291 @@ -54,7 +54,7 @@
61292 #include <asm/ioctls.h>
61293 #include "internal.h"
61294
61295 -int compat_log = 1;
61296 +int compat_log = 0;
61297
61298 int compat_printk(const char *fmt, ...)
61299 {
61300 @@ -512,7 +512,7 @@ COMPAT_SYSCALL_DEFINE2(io_setup, unsigned, nr_reqs, u32 __user *, ctx32p)
61301
61302 set_fs(KERNEL_DS);
61303 /* The __user pointer cast is valid because of the set_fs() */
61304 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
61305 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
61306 set_fs(oldfs);
61307 /* truncating is ok because it's a user address */
61308 if (!ret)
61309 @@ -562,7 +562,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
61310 goto out;
61311
61312 ret = -EINVAL;
61313 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
61314 + if (nr_segs > UIO_MAXIOV)
61315 goto out;
61316 if (nr_segs > fast_segs) {
61317 ret = -ENOMEM;
61318 @@ -850,6 +850,7 @@ struct compat_old_linux_dirent {
61319 struct compat_readdir_callback {
61320 struct dir_context ctx;
61321 struct compat_old_linux_dirent __user *dirent;
61322 + struct file * file;
61323 int result;
61324 };
61325
61326 @@ -867,6 +868,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
61327 buf->result = -EOVERFLOW;
61328 return -EOVERFLOW;
61329 }
61330 +
61331 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
61332 + return 0;
61333 +
61334 buf->result++;
61335 dirent = buf->dirent;
61336 if (!access_ok(VERIFY_WRITE, dirent,
61337 @@ -898,6 +903,7 @@ COMPAT_SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
61338 if (!f.file)
61339 return -EBADF;
61340
61341 + buf.file = f.file;
61342 error = iterate_dir(f.file, &buf.ctx);
61343 if (buf.result)
61344 error = buf.result;
61345 @@ -917,6 +923,7 @@ struct compat_getdents_callback {
61346 struct dir_context ctx;
61347 struct compat_linux_dirent __user *current_dir;
61348 struct compat_linux_dirent __user *previous;
61349 + struct file * file;
61350 int count;
61351 int error;
61352 };
61353 @@ -938,6 +945,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
61354 buf->error = -EOVERFLOW;
61355 return -EOVERFLOW;
61356 }
61357 +
61358 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
61359 + return 0;
61360 +
61361 dirent = buf->previous;
61362 if (dirent) {
61363 if (__put_user(offset, &dirent->d_off))
61364 @@ -983,6 +994,7 @@ COMPAT_SYSCALL_DEFINE3(getdents, unsigned int, fd,
61365 if (!f.file)
61366 return -EBADF;
61367
61368 + buf.file = f.file;
61369 error = iterate_dir(f.file, &buf.ctx);
61370 if (error >= 0)
61371 error = buf.error;
61372 @@ -1003,6 +1015,7 @@ struct compat_getdents_callback64 {
61373 struct dir_context ctx;
61374 struct linux_dirent64 __user *current_dir;
61375 struct linux_dirent64 __user *previous;
61376 + struct file * file;
61377 int count;
61378 int error;
61379 };
61380 @@ -1019,6 +1032,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
61381 buf->error = -EINVAL; /* only used if we fail.. */
61382 if (reclen > buf->count)
61383 return -EINVAL;
61384 +
61385 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
61386 + return 0;
61387 +
61388 dirent = buf->previous;
61389
61390 if (dirent) {
61391 @@ -1068,6 +1085,7 @@ COMPAT_SYSCALL_DEFINE3(getdents64, unsigned int, fd,
61392 if (!f.file)
61393 return -EBADF;
61394
61395 + buf.file = f.file;
61396 error = iterate_dir(f.file, &buf.ctx);
61397 if (error >= 0)
61398 error = buf.error;
61399 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
61400 index 4d24d17..4f8c09e 100644
61401 --- a/fs/compat_binfmt_elf.c
61402 +++ b/fs/compat_binfmt_elf.c
61403 @@ -30,11 +30,13 @@
61404 #undef elf_phdr
61405 #undef elf_shdr
61406 #undef elf_note
61407 +#undef elf_dyn
61408 #undef elf_addr_t
61409 #define elfhdr elf32_hdr
61410 #define elf_phdr elf32_phdr
61411 #define elf_shdr elf32_shdr
61412 #define elf_note elf32_note
61413 +#define elf_dyn Elf32_Dyn
61414 #define elf_addr_t Elf32_Addr
61415
61416 /*
61417 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
61418 index afec645..9c65620 100644
61419 --- a/fs/compat_ioctl.c
61420 +++ b/fs/compat_ioctl.c
61421 @@ -621,7 +621,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
61422 return -EFAULT;
61423 if (__get_user(udata, &ss32->iomem_base))
61424 return -EFAULT;
61425 - ss.iomem_base = compat_ptr(udata);
61426 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
61427 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
61428 __get_user(ss.port_high, &ss32->port_high))
61429 return -EFAULT;
61430 @@ -703,8 +703,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
61431 for (i = 0; i < nmsgs; i++) {
61432 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
61433 return -EFAULT;
61434 - if (get_user(datap, &umsgs[i].buf) ||
61435 - put_user(compat_ptr(datap), &tmsgs[i].buf))
61436 + if (get_user(datap, (compat_caddr_t __user *)&umsgs[i].buf) ||
61437 + put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
61438 return -EFAULT;
61439 }
61440 return sys_ioctl(fd, cmd, (unsigned long)tdata);
61441 @@ -797,7 +797,7 @@ static int compat_ioctl_preallocate(struct file *file,
61442 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
61443 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
61444 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
61445 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
61446 + copy_in_user(p->l_pad, p32->l_pad, 4*sizeof(u32)))
61447 return -EFAULT;
61448
61449 return ioctl_preallocate(file, p);
61450 @@ -1618,8 +1618,8 @@ COMPAT_SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd,
61451 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
61452 {
61453 unsigned int a, b;
61454 - a = *(unsigned int *)p;
61455 - b = *(unsigned int *)q;
61456 + a = *(const unsigned int *)p;
61457 + b = *(const unsigned int *)q;
61458 if (a > b)
61459 return 1;
61460 if (a < b)
61461 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
61462 index 668dcab..daebcd6 100644
61463 --- a/fs/configfs/dir.c
61464 +++ b/fs/configfs/dir.c
61465 @@ -1548,7 +1548,8 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
61466 }
61467 for (p = q->next; p != &parent_sd->s_children; p = p->next) {
61468 struct configfs_dirent *next;
61469 - const char *name;
61470 + const unsigned char * name;
61471 + char d_name[sizeof(next->s_dentry->d_iname)];
61472 int len;
61473 struct inode *inode = NULL;
61474
61475 @@ -1557,7 +1558,12 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
61476 continue;
61477
61478 name = configfs_get_name(next);
61479 - len = strlen(name);
61480 + if (next->s_dentry && name == next->s_dentry->d_iname) {
61481 + len = next->s_dentry->d_name.len;
61482 + memcpy(d_name, name, len);
61483 + name = d_name;
61484 + } else
61485 + len = strlen(name);
61486
61487 /*
61488 * We'll have a dentry and an inode for
61489 diff --git a/fs/coredump.c b/fs/coredump.c
61490 index a93f7e6..d58bcbe 100644
61491 --- a/fs/coredump.c
61492 +++ b/fs/coredump.c
61493 @@ -442,8 +442,8 @@ static void wait_for_dump_helpers(struct file *file)
61494 struct pipe_inode_info *pipe = file->private_data;
61495
61496 pipe_lock(pipe);
61497 - pipe->readers++;
61498 - pipe->writers--;
61499 + atomic_inc(&pipe->readers);
61500 + atomic_dec(&pipe->writers);
61501 wake_up_interruptible_sync(&pipe->wait);
61502 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
61503 pipe_unlock(pipe);
61504 @@ -452,11 +452,11 @@ static void wait_for_dump_helpers(struct file *file)
61505 * We actually want wait_event_freezable() but then we need
61506 * to clear TIF_SIGPENDING and improve dump_interrupted().
61507 */
61508 - wait_event_interruptible(pipe->wait, pipe->readers == 1);
61509 + wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
61510
61511 pipe_lock(pipe);
61512 - pipe->readers--;
61513 - pipe->writers++;
61514 + atomic_dec(&pipe->readers);
61515 + atomic_inc(&pipe->writers);
61516 pipe_unlock(pipe);
61517 }
61518
61519 @@ -503,7 +503,9 @@ void do_coredump(const siginfo_t *siginfo)
61520 struct files_struct *displaced;
61521 bool need_nonrelative = false;
61522 bool core_dumped = false;
61523 - static atomic_t core_dump_count = ATOMIC_INIT(0);
61524 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
61525 + long signr = siginfo->si_signo;
61526 + int dumpable;
61527 struct coredump_params cprm = {
61528 .siginfo = siginfo,
61529 .regs = signal_pt_regs(),
61530 @@ -516,12 +518,17 @@ void do_coredump(const siginfo_t *siginfo)
61531 .mm_flags = mm->flags,
61532 };
61533
61534 - audit_core_dumps(siginfo->si_signo);
61535 + audit_core_dumps(signr);
61536 +
61537 + dumpable = __get_dumpable(cprm.mm_flags);
61538 +
61539 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
61540 + gr_handle_brute_attach(dumpable);
61541
61542 binfmt = mm->binfmt;
61543 if (!binfmt || !binfmt->core_dump)
61544 goto fail;
61545 - if (!__get_dumpable(cprm.mm_flags))
61546 + if (!dumpable)
61547 goto fail;
61548
61549 cred = prepare_creds();
61550 @@ -540,7 +547,7 @@ void do_coredump(const siginfo_t *siginfo)
61551 need_nonrelative = true;
61552 }
61553
61554 - retval = coredump_wait(siginfo->si_signo, &core_state);
61555 + retval = coredump_wait(signr, &core_state);
61556 if (retval < 0)
61557 goto fail_creds;
61558
61559 @@ -583,7 +590,7 @@ void do_coredump(const siginfo_t *siginfo)
61560 }
61561 cprm.limit = RLIM_INFINITY;
61562
61563 - dump_count = atomic_inc_return(&core_dump_count);
61564 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
61565 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
61566 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
61567 task_tgid_vnr(current), current->comm);
61568 @@ -615,6 +622,8 @@ void do_coredump(const siginfo_t *siginfo)
61569 } else {
61570 struct inode *inode;
61571
61572 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
61573 +
61574 if (cprm.limit < binfmt->min_coredump)
61575 goto fail_unlock;
61576
61577 @@ -673,7 +682,7 @@ close_fail:
61578 filp_close(cprm.file, NULL);
61579 fail_dropcount:
61580 if (ispipe)
61581 - atomic_dec(&core_dump_count);
61582 + atomic_dec_unchecked(&core_dump_count);
61583 fail_unlock:
61584 kfree(cn.corename);
61585 coredump_finish(mm, core_dumped);
61586 @@ -694,6 +703,8 @@ int dump_emit(struct coredump_params *cprm, const void *addr, int nr)
61587 struct file *file = cprm->file;
61588 loff_t pos = file->f_pos;
61589 ssize_t n;
61590 +
61591 + gr_learn_resource(current, RLIMIT_CORE, cprm->written + nr, 1);
61592 if (cprm->written + nr > cprm->limit)
61593 return 0;
61594 while (nr) {
61595 diff --git a/fs/dcache.c b/fs/dcache.c
61596 index 34b40be8..2003532 100644
61597 --- a/fs/dcache.c
61598 +++ b/fs/dcache.c
61599 @@ -478,7 +478,7 @@ static void __dentry_kill(struct dentry *dentry)
61600 * dentry_iput drops the locks, at which point nobody (except
61601 * transient RCU lookups) can reach this dentry.
61602 */
61603 - BUG_ON((int)dentry->d_lockref.count > 0);
61604 + BUG_ON((int)__lockref_read(&dentry->d_lockref) > 0);
61605 this_cpu_dec(nr_dentry);
61606 if (dentry->d_op && dentry->d_op->d_release)
61607 dentry->d_op->d_release(dentry);
61608 @@ -531,7 +531,7 @@ static inline struct dentry *lock_parent(struct dentry *dentry)
61609 struct dentry *parent = dentry->d_parent;
61610 if (IS_ROOT(dentry))
61611 return NULL;
61612 - if (unlikely((int)dentry->d_lockref.count < 0))
61613 + if (unlikely((int)__lockref_read(&dentry->d_lockref) < 0))
61614 return NULL;
61615 if (likely(spin_trylock(&parent->d_lock)))
61616 return parent;
61617 @@ -608,7 +608,7 @@ repeat:
61618 dentry->d_flags |= DCACHE_REFERENCED;
61619 dentry_lru_add(dentry);
61620
61621 - dentry->d_lockref.count--;
61622 + __lockref_dec(&dentry->d_lockref);
61623 spin_unlock(&dentry->d_lock);
61624 return;
61625
61626 @@ -663,7 +663,7 @@ int d_invalidate(struct dentry * dentry)
61627 * We also need to leave mountpoints alone,
61628 * directory or not.
61629 */
61630 - if (dentry->d_lockref.count > 1 && dentry->d_inode) {
61631 + if (__lockref_read(&dentry->d_lockref) > 1 && dentry->d_inode) {
61632 if (S_ISDIR(dentry->d_inode->i_mode) || d_mountpoint(dentry)) {
61633 spin_unlock(&dentry->d_lock);
61634 return -EBUSY;
61635 @@ -679,7 +679,7 @@ EXPORT_SYMBOL(d_invalidate);
61636 /* This must be called with d_lock held */
61637 static inline void __dget_dlock(struct dentry *dentry)
61638 {
61639 - dentry->d_lockref.count++;
61640 + __lockref_inc(&dentry->d_lockref);
61641 }
61642
61643 static inline void __dget(struct dentry *dentry)
61644 @@ -720,8 +720,8 @@ repeat:
61645 goto repeat;
61646 }
61647 rcu_read_unlock();
61648 - BUG_ON(!ret->d_lockref.count);
61649 - ret->d_lockref.count++;
61650 + BUG_ON(!__lockref_read(&ret->d_lockref));
61651 + __lockref_inc(&ret->d_lockref);
61652 spin_unlock(&ret->d_lock);
61653 return ret;
61654 }
61655 @@ -798,7 +798,7 @@ restart:
61656 spin_lock(&inode->i_lock);
61657 hlist_for_each_entry(dentry, &inode->i_dentry, d_alias) {
61658 spin_lock(&dentry->d_lock);
61659 - if (!dentry->d_lockref.count) {
61660 + if (!__lockref_read(&dentry->d_lockref)) {
61661 /*
61662 * inform the fs via d_prune that this dentry
61663 * is about to be unhashed and destroyed.
61664 @@ -841,7 +841,7 @@ static void shrink_dentry_list(struct list_head *list)
61665 * We found an inuse dentry which was not removed from
61666 * the LRU because of laziness during lookup. Do not free it.
61667 */
61668 - if ((int)dentry->d_lockref.count > 0) {
61669 + if ((int)__lockref_read(&dentry->d_lockref) > 0) {
61670 spin_unlock(&dentry->d_lock);
61671 if (parent)
61672 spin_unlock(&parent->d_lock);
61673 @@ -879,8 +879,8 @@ static void shrink_dentry_list(struct list_head *list)
61674 dentry = parent;
61675 while (dentry && !lockref_put_or_lock(&dentry->d_lockref)) {
61676 parent = lock_parent(dentry);
61677 - if (dentry->d_lockref.count != 1) {
61678 - dentry->d_lockref.count--;
61679 + if (__lockref_read(&dentry->d_lockref) != 1) {
61680 + __lockref_inc(&dentry->d_lockref);
61681 spin_unlock(&dentry->d_lock);
61682 if (parent)
61683 spin_unlock(&parent->d_lock);
61684 @@ -920,7 +920,7 @@ dentry_lru_isolate(struct list_head *item, spinlock_t *lru_lock, void *arg)
61685 * counts, just remove them from the LRU. Otherwise give them
61686 * another pass through the LRU.
61687 */
61688 - if (dentry->d_lockref.count) {
61689 + if (__lockref_read(&dentry->d_lockref) > 0) {
61690 d_lru_isolate(dentry);
61691 spin_unlock(&dentry->d_lock);
61692 return LRU_REMOVED;
61693 @@ -1149,6 +1149,7 @@ out_unlock:
61694 return;
61695
61696 rename_retry:
61697 + done_seqretry(&rename_lock, seq);
61698 if (!retry)
61699 return;
61700 seq = 1;
61701 @@ -1255,7 +1256,7 @@ static enum d_walk_ret select_collect(void *_data, struct dentry *dentry)
61702 } else {
61703 if (dentry->d_flags & DCACHE_LRU_LIST)
61704 d_lru_del(dentry);
61705 - if (!dentry->d_lockref.count) {
61706 + if (!__lockref_read(&dentry->d_lockref)) {
61707 d_shrink_add(dentry, &data->dispose);
61708 data->found++;
61709 }
61710 @@ -1303,7 +1304,7 @@ static enum d_walk_ret umount_check(void *_data, struct dentry *dentry)
61711 return D_WALK_CONTINUE;
61712
61713 /* root with refcount 1 is fine */
61714 - if (dentry == _data && dentry->d_lockref.count == 1)
61715 + if (dentry == _data && __lockref_read(&dentry->d_lockref) == 1)
61716 return D_WALK_CONTINUE;
61717
61718 printk(KERN_ERR "BUG: Dentry %p{i=%lx,n=%pd} "
61719 @@ -1312,7 +1313,7 @@ static enum d_walk_ret umount_check(void *_data, struct dentry *dentry)
61720 dentry->d_inode ?
61721 dentry->d_inode->i_ino : 0UL,
61722 dentry,
61723 - dentry->d_lockref.count,
61724 + __lockref_read(&dentry->d_lockref),
61725 dentry->d_sb->s_type->name,
61726 dentry->d_sb->s_id);
61727 WARN_ON(1);
61728 @@ -1438,7 +1439,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
61729 */
61730 dentry->d_iname[DNAME_INLINE_LEN-1] = 0;
61731 if (name->len > DNAME_INLINE_LEN-1) {
61732 - dname = kmalloc(name->len + 1, GFP_KERNEL);
61733 + dname = kmalloc(round_up(name->len + 1, sizeof(unsigned long)), GFP_KERNEL);
61734 if (!dname) {
61735 kmem_cache_free(dentry_cache, dentry);
61736 return NULL;
61737 @@ -1456,7 +1457,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
61738 smp_wmb();
61739 dentry->d_name.name = dname;
61740
61741 - dentry->d_lockref.count = 1;
61742 + __lockref_set(&dentry->d_lockref, 1);
61743 dentry->d_flags = 0;
61744 spin_lock_init(&dentry->d_lock);
61745 seqcount_init(&dentry->d_seq);
61746 @@ -2196,7 +2197,7 @@ struct dentry *__d_lookup(const struct dentry *parent, const struct qstr *name)
61747 goto next;
61748 }
61749
61750 - dentry->d_lockref.count++;
61751 + __lockref_inc(&dentry->d_lockref);
61752 found = dentry;
61753 spin_unlock(&dentry->d_lock);
61754 break;
61755 @@ -2295,7 +2296,7 @@ again:
61756 spin_lock(&dentry->d_lock);
61757 inode = dentry->d_inode;
61758 isdir = S_ISDIR(inode->i_mode);
61759 - if (dentry->d_lockref.count == 1) {
61760 + if (__lockref_read(&dentry->d_lockref) == 1) {
61761 if (!spin_trylock(&inode->i_lock)) {
61762 spin_unlock(&dentry->d_lock);
61763 cpu_relax();
61764 @@ -3307,7 +3308,7 @@ static enum d_walk_ret d_genocide_kill(void *data, struct dentry *dentry)
61765
61766 if (!(dentry->d_flags & DCACHE_GENOCIDE)) {
61767 dentry->d_flags |= DCACHE_GENOCIDE;
61768 - dentry->d_lockref.count--;
61769 + __lockref_dec(&dentry->d_lockref);
61770 }
61771 }
61772 return D_WALK_CONTINUE;
61773 @@ -3423,7 +3424,8 @@ void __init vfs_caches_init(unsigned long mempages)
61774 mempages -= reserve;
61775
61776 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
61777 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
61778 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
61779 + SLAB_NO_SANITIZE, NULL);
61780
61781 dcache_init();
61782 inode_init();
61783 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
61784 index 1e3b99d..6512101 100644
61785 --- a/fs/debugfs/inode.c
61786 +++ b/fs/debugfs/inode.c
61787 @@ -416,7 +416,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
61788 */
61789 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
61790 {
61791 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
61792 + return __create_file(name, S_IFDIR | S_IRWXU,
61793 +#else
61794 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
61795 +#endif
61796 parent, NULL, NULL);
61797 }
61798 EXPORT_SYMBOL_GPL(debugfs_create_dir);
61799 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
61800 index 57ee4c5..ecb13b0 100644
61801 --- a/fs/ecryptfs/inode.c
61802 +++ b/fs/ecryptfs/inode.c
61803 @@ -673,7 +673,7 @@ static char *ecryptfs_readlink_lower(struct dentry *dentry, size_t *bufsiz)
61804 old_fs = get_fs();
61805 set_fs(get_ds());
61806 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
61807 - (char __user *)lower_buf,
61808 + (char __force_user *)lower_buf,
61809 PATH_MAX);
61810 set_fs(old_fs);
61811 if (rc < 0)
61812 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
61813 index e4141f2..d8263e8 100644
61814 --- a/fs/ecryptfs/miscdev.c
61815 +++ b/fs/ecryptfs/miscdev.c
61816 @@ -304,7 +304,7 @@ check_list:
61817 goto out_unlock_msg_ctx;
61818 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
61819 if (msg_ctx->msg) {
61820 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
61821 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
61822 goto out_unlock_msg_ctx;
61823 i += packet_length_size;
61824 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
61825 diff --git a/fs/exec.c b/fs/exec.c
61826 index a2b42a9..1e924b3 100644
61827 --- a/fs/exec.c
61828 +++ b/fs/exec.c
61829 @@ -56,8 +56,20 @@
61830 #include <linux/pipe_fs_i.h>
61831 #include <linux/oom.h>
61832 #include <linux/compat.h>
61833 +#include <linux/random.h>
61834 +#include <linux/seq_file.h>
61835 +#include <linux/coredump.h>
61836 +#include <linux/mman.h>
61837 +
61838 +#ifdef CONFIG_PAX_REFCOUNT
61839 +#include <linux/kallsyms.h>
61840 +#include <linux/kdebug.h>
61841 +#endif
61842 +
61843 +#include <trace/events/fs.h>
61844
61845 #include <asm/uaccess.h>
61846 +#include <asm/sections.h>
61847 #include <asm/mmu_context.h>
61848 #include <asm/tlb.h>
61849
61850 @@ -66,19 +78,34 @@
61851
61852 #include <trace/events/sched.h>
61853
61854 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
61855 +void __weak pax_set_initial_flags(struct linux_binprm *bprm)
61856 +{
61857 + 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");
61858 +}
61859 +#endif
61860 +
61861 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
61862 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
61863 +EXPORT_SYMBOL(pax_set_initial_flags_func);
61864 +#endif
61865 +
61866 int suid_dumpable = 0;
61867
61868 static LIST_HEAD(formats);
61869 static DEFINE_RWLOCK(binfmt_lock);
61870
61871 +extern int gr_process_kernel_exec_ban(void);
61872 +extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
61873 +
61874 void __register_binfmt(struct linux_binfmt * fmt, int insert)
61875 {
61876 BUG_ON(!fmt);
61877 if (WARN_ON(!fmt->load_binary))
61878 return;
61879 write_lock(&binfmt_lock);
61880 - insert ? list_add(&fmt->lh, &formats) :
61881 - list_add_tail(&fmt->lh, &formats);
61882 + insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
61883 + pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
61884 write_unlock(&binfmt_lock);
61885 }
61886
61887 @@ -87,7 +114,7 @@ EXPORT_SYMBOL(__register_binfmt);
61888 void unregister_binfmt(struct linux_binfmt * fmt)
61889 {
61890 write_lock(&binfmt_lock);
61891 - list_del(&fmt->lh);
61892 + pax_list_del((struct list_head *)&fmt->lh);
61893 write_unlock(&binfmt_lock);
61894 }
61895
61896 @@ -183,18 +210,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
61897 int write)
61898 {
61899 struct page *page;
61900 - int ret;
61901
61902 -#ifdef CONFIG_STACK_GROWSUP
61903 - if (write) {
61904 - ret = expand_downwards(bprm->vma, pos);
61905 - if (ret < 0)
61906 - return NULL;
61907 - }
61908 -#endif
61909 - ret = get_user_pages(current, bprm->mm, pos,
61910 - 1, write, 1, &page, NULL);
61911 - if (ret <= 0)
61912 + if (0 > expand_downwards(bprm->vma, pos))
61913 + return NULL;
61914 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
61915 return NULL;
61916
61917 if (write) {
61918 @@ -210,6 +229,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
61919 if (size <= ARG_MAX)
61920 return page;
61921
61922 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61923 + // only allow 512KB for argv+env on suid/sgid binaries
61924 + // to prevent easy ASLR exhaustion
61925 + if (((!uid_eq(bprm->cred->euid, current_euid())) ||
61926 + (!gid_eq(bprm->cred->egid, current_egid()))) &&
61927 + (size > (512 * 1024))) {
61928 + put_page(page);
61929 + return NULL;
61930 + }
61931 +#endif
61932 +
61933 /*
61934 * Limit to 1/4-th the stack size for the argv+env strings.
61935 * This ensures that:
61936 @@ -269,6 +299,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
61937 vma->vm_end = STACK_TOP_MAX;
61938 vma->vm_start = vma->vm_end - PAGE_SIZE;
61939 vma->vm_flags = VM_SOFTDIRTY | VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
61940 +
61941 +#ifdef CONFIG_PAX_SEGMEXEC
61942 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
61943 +#endif
61944 +
61945 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
61946 INIT_LIST_HEAD(&vma->anon_vma_chain);
61947
61948 @@ -279,6 +314,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
61949 mm->stack_vm = mm->total_vm = 1;
61950 up_write(&mm->mmap_sem);
61951 bprm->p = vma->vm_end - sizeof(void *);
61952 +
61953 +#ifdef CONFIG_PAX_RANDUSTACK
61954 + if (randomize_va_space)
61955 + bprm->p ^= prandom_u32() & ~PAGE_MASK;
61956 +#endif
61957 +
61958 return 0;
61959 err:
61960 up_write(&mm->mmap_sem);
61961 @@ -395,7 +436,7 @@ struct user_arg_ptr {
61962 } ptr;
61963 };
61964
61965 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
61966 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
61967 {
61968 const char __user *native;
61969
61970 @@ -404,14 +445,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
61971 compat_uptr_t compat;
61972
61973 if (get_user(compat, argv.ptr.compat + nr))
61974 - return ERR_PTR(-EFAULT);
61975 + return (const char __force_user *)ERR_PTR(-EFAULT);
61976
61977 return compat_ptr(compat);
61978 }
61979 #endif
61980
61981 if (get_user(native, argv.ptr.native + nr))
61982 - return ERR_PTR(-EFAULT);
61983 + return (const char __force_user *)ERR_PTR(-EFAULT);
61984
61985 return native;
61986 }
61987 @@ -430,7 +471,7 @@ static int count(struct user_arg_ptr argv, int max)
61988 if (!p)
61989 break;
61990
61991 - if (IS_ERR(p))
61992 + if (IS_ERR((const char __force_kernel *)p))
61993 return -EFAULT;
61994
61995 if (i >= max)
61996 @@ -465,7 +506,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
61997
61998 ret = -EFAULT;
61999 str = get_user_arg_ptr(argv, argc);
62000 - if (IS_ERR(str))
62001 + if (IS_ERR((const char __force_kernel *)str))
62002 goto out;
62003
62004 len = strnlen_user(str, MAX_ARG_STRLEN);
62005 @@ -547,7 +588,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
62006 int r;
62007 mm_segment_t oldfs = get_fs();
62008 struct user_arg_ptr argv = {
62009 - .ptr.native = (const char __user *const __user *)__argv,
62010 + .ptr.native = (const char __user * const __force_user *)__argv,
62011 };
62012
62013 set_fs(KERNEL_DS);
62014 @@ -582,7 +623,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
62015 unsigned long new_end = old_end - shift;
62016 struct mmu_gather tlb;
62017
62018 - BUG_ON(new_start > new_end);
62019 + if (new_start >= new_end || new_start < mmap_min_addr)
62020 + return -ENOMEM;
62021
62022 /*
62023 * ensure there are no vmas between where we want to go
62024 @@ -591,6 +633,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
62025 if (vma != find_vma(mm, new_start))
62026 return -EFAULT;
62027
62028 +#ifdef CONFIG_PAX_SEGMEXEC
62029 + BUG_ON(pax_find_mirror_vma(vma));
62030 +#endif
62031 +
62032 /*
62033 * cover the whole range: [new_start, old_end)
62034 */
62035 @@ -671,10 +717,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
62036 stack_top = arch_align_stack(stack_top);
62037 stack_top = PAGE_ALIGN(stack_top);
62038
62039 - if (unlikely(stack_top < mmap_min_addr) ||
62040 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
62041 - return -ENOMEM;
62042 -
62043 stack_shift = vma->vm_end - stack_top;
62044
62045 bprm->p -= stack_shift;
62046 @@ -686,8 +728,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
62047 bprm->exec -= stack_shift;
62048
62049 down_write(&mm->mmap_sem);
62050 +
62051 + /* Move stack pages down in memory. */
62052 + if (stack_shift) {
62053 + ret = shift_arg_pages(vma, stack_shift);
62054 + if (ret)
62055 + goto out_unlock;
62056 + }
62057 +
62058 vm_flags = VM_STACK_FLAGS;
62059
62060 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
62061 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
62062 + vm_flags &= ~VM_EXEC;
62063 +
62064 +#ifdef CONFIG_PAX_MPROTECT
62065 + if (mm->pax_flags & MF_PAX_MPROTECT)
62066 + vm_flags &= ~VM_MAYEXEC;
62067 +#endif
62068 +
62069 + }
62070 +#endif
62071 +
62072 /*
62073 * Adjust stack execute permissions; explicitly enable for
62074 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
62075 @@ -706,13 +768,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
62076 goto out_unlock;
62077 BUG_ON(prev != vma);
62078
62079 - /* Move stack pages down in memory. */
62080 - if (stack_shift) {
62081 - ret = shift_arg_pages(vma, stack_shift);
62082 - if (ret)
62083 - goto out_unlock;
62084 - }
62085 -
62086 /* mprotect_fixup is overkill to remove the temporary stack flags */
62087 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
62088
62089 @@ -736,6 +791,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
62090 #endif
62091 current->mm->start_stack = bprm->p;
62092 ret = expand_stack(vma, stack_base);
62093 +
62094 +#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
62095 + if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
62096 + unsigned long size;
62097 + vm_flags_t vm_flags;
62098 +
62099 + size = STACK_TOP - vma->vm_end;
62100 + vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
62101 +
62102 + ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
62103 +
62104 +#ifdef CONFIG_X86
62105 + if (!ret) {
62106 + size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
62107 + ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
62108 + }
62109 +#endif
62110 +
62111 + }
62112 +#endif
62113 +
62114 if (ret)
62115 ret = -EFAULT;
62116
62117 @@ -771,6 +847,8 @@ static struct file *do_open_exec(struct filename *name)
62118
62119 fsnotify_open(file);
62120
62121 + trace_open_exec(name->name);
62122 +
62123 err = deny_write_access(file);
62124 if (err)
62125 goto exit;
62126 @@ -800,7 +878,7 @@ int kernel_read(struct file *file, loff_t offset,
62127 old_fs = get_fs();
62128 set_fs(get_ds());
62129 /* The cast to a user pointer is valid due to the set_fs() */
62130 - result = vfs_read(file, (void __user *)addr, count, &pos);
62131 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
62132 set_fs(old_fs);
62133 return result;
62134 }
62135 @@ -845,6 +923,7 @@ static int exec_mmap(struct mm_struct *mm)
62136 tsk->mm = mm;
62137 tsk->active_mm = mm;
62138 activate_mm(active_mm, mm);
62139 + populate_stack();
62140 tsk->mm->vmacache_seqnum = 0;
62141 vmacache_flush(tsk);
62142 task_unlock(tsk);
62143 @@ -1243,7 +1322,7 @@ static void check_unsafe_exec(struct linux_binprm *bprm)
62144 }
62145 rcu_read_unlock();
62146
62147 - if (p->fs->users > n_fs)
62148 + if (atomic_read(&p->fs->users) > n_fs)
62149 bprm->unsafe |= LSM_UNSAFE_SHARE;
62150 else
62151 p->fs->in_exec = 1;
62152 @@ -1419,6 +1498,31 @@ static int exec_binprm(struct linux_binprm *bprm)
62153 return ret;
62154 }
62155
62156 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62157 +static DEFINE_PER_CPU(u64, exec_counter);
62158 +static int __init init_exec_counters(void)
62159 +{
62160 + unsigned int cpu;
62161 +
62162 + for_each_possible_cpu(cpu) {
62163 + per_cpu(exec_counter, cpu) = (u64)cpu;
62164 + }
62165 +
62166 + return 0;
62167 +}
62168 +early_initcall(init_exec_counters);
62169 +static inline void increment_exec_counter(void)
62170 +{
62171 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
62172 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
62173 +}
62174 +#else
62175 +static inline void increment_exec_counter(void) {}
62176 +#endif
62177 +
62178 +extern void gr_handle_exec_args(struct linux_binprm *bprm,
62179 + struct user_arg_ptr argv);
62180 +
62181 /*
62182 * sys_execve() executes a new program.
62183 */
62184 @@ -1426,6 +1530,11 @@ static int do_execve_common(struct filename *filename,
62185 struct user_arg_ptr argv,
62186 struct user_arg_ptr envp)
62187 {
62188 +#ifdef CONFIG_GRKERNSEC
62189 + struct file *old_exec_file;
62190 + struct acl_subject_label *old_acl;
62191 + struct rlimit old_rlim[RLIM_NLIMITS];
62192 +#endif
62193 struct linux_binprm *bprm;
62194 struct file *file;
62195 struct files_struct *displaced;
62196 @@ -1434,6 +1543,8 @@ static int do_execve_common(struct filename *filename,
62197 if (IS_ERR(filename))
62198 return PTR_ERR(filename);
62199
62200 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current_user()->processes), 1);
62201 +
62202 /*
62203 * We move the actual failure in case of RLIMIT_NPROC excess from
62204 * set*uid() to execve() because too many poorly written programs
62205 @@ -1471,11 +1582,21 @@ static int do_execve_common(struct filename *filename,
62206 if (IS_ERR(file))
62207 goto out_unmark;
62208
62209 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
62210 + retval = -EPERM;
62211 + goto out_unmark;
62212 + }
62213 +
62214 sched_exec();
62215
62216 bprm->file = file;
62217 bprm->filename = bprm->interp = filename->name;
62218
62219 + if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
62220 + retval = -EACCES;
62221 + goto out_unmark;
62222 + }
62223 +
62224 retval = bprm_mm_init(bprm);
62225 if (retval)
62226 goto out_unmark;
62227 @@ -1492,24 +1613,70 @@ static int do_execve_common(struct filename *filename,
62228 if (retval < 0)
62229 goto out;
62230
62231 +#ifdef CONFIG_GRKERNSEC
62232 + old_acl = current->acl;
62233 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
62234 + old_exec_file = current->exec_file;
62235 + get_file(file);
62236 + current->exec_file = file;
62237 +#endif
62238 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62239 + /* limit suid stack to 8MB
62240 + * we saved the old limits above and will restore them if this exec fails
62241 + */
62242 + if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
62243 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
62244 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
62245 +#endif
62246 +
62247 + if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
62248 + retval = -EPERM;
62249 + goto out_fail;
62250 + }
62251 +
62252 + if (!gr_tpe_allow(file)) {
62253 + retval = -EACCES;
62254 + goto out_fail;
62255 + }
62256 +
62257 + if (gr_check_crash_exec(file)) {
62258 + retval = -EACCES;
62259 + goto out_fail;
62260 + }
62261 +
62262 + retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
62263 + bprm->unsafe);
62264 + if (retval < 0)
62265 + goto out_fail;
62266 +
62267 retval = copy_strings_kernel(1, &bprm->filename, bprm);
62268 if (retval < 0)
62269 - goto out;
62270 + goto out_fail;
62271
62272 bprm->exec = bprm->p;
62273 retval = copy_strings(bprm->envc, envp, bprm);
62274 if (retval < 0)
62275 - goto out;
62276 + goto out_fail;
62277
62278 retval = copy_strings(bprm->argc, argv, bprm);
62279 if (retval < 0)
62280 - goto out;
62281 + goto out_fail;
62282 +
62283 + gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
62284 +
62285 + gr_handle_exec_args(bprm, argv);
62286
62287 retval = exec_binprm(bprm);
62288 if (retval < 0)
62289 - goto out;
62290 + goto out_fail;
62291 +#ifdef CONFIG_GRKERNSEC
62292 + if (old_exec_file)
62293 + fput(old_exec_file);
62294 +#endif
62295
62296 /* execve succeeded */
62297 +
62298 + increment_exec_counter();
62299 current->fs->in_exec = 0;
62300 current->in_execve = 0;
62301 acct_update_integrals(current);
62302 @@ -1520,6 +1687,14 @@ static int do_execve_common(struct filename *filename,
62303 put_files_struct(displaced);
62304 return retval;
62305
62306 +out_fail:
62307 +#ifdef CONFIG_GRKERNSEC
62308 + current->acl = old_acl;
62309 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
62310 + fput(current->exec_file);
62311 + current->exec_file = old_exec_file;
62312 +#endif
62313 +
62314 out:
62315 if (bprm->mm) {
62316 acct_arg_size(bprm, 0);
62317 @@ -1611,3 +1786,312 @@ COMPAT_SYSCALL_DEFINE3(execve, const char __user *, filename,
62318 return compat_do_execve(getname(filename), argv, envp);
62319 }
62320 #endif
62321 +
62322 +int pax_check_flags(unsigned long *flags)
62323 +{
62324 + int retval = 0;
62325 +
62326 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
62327 + if (*flags & MF_PAX_SEGMEXEC)
62328 + {
62329 + *flags &= ~MF_PAX_SEGMEXEC;
62330 + retval = -EINVAL;
62331 + }
62332 +#endif
62333 +
62334 + if ((*flags & MF_PAX_PAGEEXEC)
62335 +
62336 +#ifdef CONFIG_PAX_PAGEEXEC
62337 + && (*flags & MF_PAX_SEGMEXEC)
62338 +#endif
62339 +
62340 + )
62341 + {
62342 + *flags &= ~MF_PAX_PAGEEXEC;
62343 + retval = -EINVAL;
62344 + }
62345 +
62346 + if ((*flags & MF_PAX_MPROTECT)
62347 +
62348 +#ifdef CONFIG_PAX_MPROTECT
62349 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
62350 +#endif
62351 +
62352 + )
62353 + {
62354 + *flags &= ~MF_PAX_MPROTECT;
62355 + retval = -EINVAL;
62356 + }
62357 +
62358 + if ((*flags & MF_PAX_EMUTRAMP)
62359 +
62360 +#ifdef CONFIG_PAX_EMUTRAMP
62361 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
62362 +#endif
62363 +
62364 + )
62365 + {
62366 + *flags &= ~MF_PAX_EMUTRAMP;
62367 + retval = -EINVAL;
62368 + }
62369 +
62370 + return retval;
62371 +}
62372 +
62373 +EXPORT_SYMBOL(pax_check_flags);
62374 +
62375 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
62376 +char *pax_get_path(const struct path *path, char *buf, int buflen)
62377 +{
62378 + char *pathname = d_path(path, buf, buflen);
62379 +
62380 + if (IS_ERR(pathname))
62381 + goto toolong;
62382 +
62383 + pathname = mangle_path(buf, pathname, "\t\n\\");
62384 + if (!pathname)
62385 + goto toolong;
62386 +
62387 + *pathname = 0;
62388 + return buf;
62389 +
62390 +toolong:
62391 + return "<path too long>";
62392 +}
62393 +EXPORT_SYMBOL(pax_get_path);
62394 +
62395 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
62396 +{
62397 + struct task_struct *tsk = current;
62398 + struct mm_struct *mm = current->mm;
62399 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
62400 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
62401 + char *path_exec = NULL;
62402 + char *path_fault = NULL;
62403 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
62404 + siginfo_t info = { };
62405 +
62406 + if (buffer_exec && buffer_fault) {
62407 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
62408 +
62409 + down_read(&mm->mmap_sem);
62410 + vma = mm->mmap;
62411 + while (vma && (!vma_exec || !vma_fault)) {
62412 + if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
62413 + vma_exec = vma;
62414 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
62415 + vma_fault = vma;
62416 + vma = vma->vm_next;
62417 + }
62418 + if (vma_exec)
62419 + path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
62420 + if (vma_fault) {
62421 + start = vma_fault->vm_start;
62422 + end = vma_fault->vm_end;
62423 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
62424 + if (vma_fault->vm_file)
62425 + path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
62426 + else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
62427 + path_fault = "<heap>";
62428 + else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
62429 + path_fault = "<stack>";
62430 + else
62431 + path_fault = "<anonymous mapping>";
62432 + }
62433 + up_read(&mm->mmap_sem);
62434 + }
62435 + if (tsk->signal->curr_ip)
62436 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
62437 + else
62438 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
62439 + 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),
62440 + from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
62441 + free_page((unsigned long)buffer_exec);
62442 + free_page((unsigned long)buffer_fault);
62443 + pax_report_insns(regs, pc, sp);
62444 + info.si_signo = SIGKILL;
62445 + info.si_errno = 0;
62446 + info.si_code = SI_KERNEL;
62447 + info.si_pid = 0;
62448 + info.si_uid = 0;
62449 + do_coredump(&info);
62450 +}
62451 +#endif
62452 +
62453 +#ifdef CONFIG_PAX_REFCOUNT
62454 +void pax_report_refcount_overflow(struct pt_regs *regs)
62455 +{
62456 + if (current->signal->curr_ip)
62457 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
62458 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
62459 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
62460 + else
62461 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
62462 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
62463 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
62464 + preempt_disable();
62465 + show_regs(regs);
62466 + preempt_enable();
62467 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
62468 +}
62469 +#endif
62470 +
62471 +#ifdef CONFIG_PAX_USERCOPY
62472 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
62473 +static noinline int check_stack_object(const void *obj, unsigned long len)
62474 +{
62475 + const void * const stack = task_stack_page(current);
62476 + const void * const stackend = stack + THREAD_SIZE;
62477 +
62478 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
62479 + const void *frame = NULL;
62480 + const void *oldframe;
62481 +#endif
62482 +
62483 + if (obj + len < obj)
62484 + return -1;
62485 +
62486 + if (obj + len <= stack || stackend <= obj)
62487 + return 0;
62488 +
62489 + if (obj < stack || stackend < obj + len)
62490 + return -1;
62491 +
62492 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
62493 + oldframe = __builtin_frame_address(1);
62494 + if (oldframe)
62495 + frame = __builtin_frame_address(2);
62496 + /*
62497 + low ----------------------------------------------> high
62498 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
62499 + ^----------------^
62500 + allow copies only within here
62501 + */
62502 + while (stack <= frame && frame < stackend) {
62503 + /* if obj + len extends past the last frame, this
62504 + check won't pass and the next frame will be 0,
62505 + causing us to bail out and correctly report
62506 + the copy as invalid
62507 + */
62508 + if (obj + len <= frame)
62509 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
62510 + oldframe = frame;
62511 + frame = *(const void * const *)frame;
62512 + }
62513 + return -1;
62514 +#else
62515 + return 1;
62516 +#endif
62517 +}
62518 +
62519 +static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
62520 +{
62521 + if (current->signal->curr_ip)
62522 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
62523 + &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
62524 + else
62525 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
62526 + to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
62527 + dump_stack();
62528 + gr_handle_kernel_exploit();
62529 + do_group_exit(SIGKILL);
62530 +}
62531 +#endif
62532 +
62533 +#ifdef CONFIG_PAX_USERCOPY
62534 +
62535 +static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
62536 +{
62537 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
62538 + unsigned long textlow = ktla_ktva((unsigned long)_stext);
62539 +#ifdef CONFIG_MODULES
62540 + unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
62541 +#else
62542 + unsigned long texthigh = ktla_ktva((unsigned long)_etext);
62543 +#endif
62544 +
62545 +#else
62546 + unsigned long textlow = (unsigned long)_stext;
62547 + unsigned long texthigh = (unsigned long)_etext;
62548 +
62549 +#ifdef CONFIG_X86_64
62550 + /* check against linear mapping as well */
62551 + if (high > (unsigned long)__va(__pa(textlow)) &&
62552 + low < (unsigned long)__va(__pa(texthigh)))
62553 + return true;
62554 +#endif
62555 +
62556 +#endif
62557 +
62558 + if (high <= textlow || low >= texthigh)
62559 + return false;
62560 + else
62561 + return true;
62562 +}
62563 +#endif
62564 +
62565 +void __check_object_size(const void *ptr, unsigned long n, bool to_user, bool const_size)
62566 +{
62567 +#ifdef CONFIG_PAX_USERCOPY
62568 + const char *type;
62569 +#endif
62570 +
62571 +#ifndef CONFIG_STACK_GROWSUP
62572 + unsigned long stackstart = (unsigned long)task_stack_page(current);
62573 + unsigned long currentsp = (unsigned long)&stackstart;
62574 + if (unlikely((currentsp < stackstart + 512 ||
62575 + currentsp >= stackstart + THREAD_SIZE) && !in_interrupt()))
62576 + BUG();
62577 +#endif
62578 +
62579 +#ifndef CONFIG_PAX_USERCOPY_DEBUG
62580 + if (const_size)
62581 + return;
62582 +#endif
62583 +
62584 +#ifdef CONFIG_PAX_USERCOPY
62585 + if (!n)
62586 + return;
62587 +
62588 + type = check_heap_object(ptr, n);
62589 + if (!type) {
62590 + int ret = check_stack_object(ptr, n);
62591 + if (ret == 1 || ret == 2)
62592 + return;
62593 + if (ret == 0) {
62594 + if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
62595 + type = "<kernel text>";
62596 + else
62597 + return;
62598 + } else
62599 + type = "<process stack>";
62600 + }
62601 +
62602 + pax_report_usercopy(ptr, n, to_user, type);
62603 +#endif
62604 +
62605 +}
62606 +EXPORT_SYMBOL(__check_object_size);
62607 +
62608 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
62609 +void pax_track_stack(void)
62610 +{
62611 + unsigned long sp = (unsigned long)&sp;
62612 + if (sp < current_thread_info()->lowest_stack &&
62613 + sp > (unsigned long)task_stack_page(current))
62614 + current_thread_info()->lowest_stack = sp;
62615 + if (unlikely((sp & ~(THREAD_SIZE - 1)) < (THREAD_SIZE/16)))
62616 + BUG();
62617 +}
62618 +EXPORT_SYMBOL(pax_track_stack);
62619 +#endif
62620 +
62621 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
62622 +void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
62623 +{
62624 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
62625 + dump_stack();
62626 + do_group_exit(SIGKILL);
62627 +}
62628 +EXPORT_SYMBOL(report_size_overflow);
62629 +#endif
62630 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
62631 index 9f9992b..8b59411 100644
62632 --- a/fs/ext2/balloc.c
62633 +++ b/fs/ext2/balloc.c
62634 @@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
62635
62636 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
62637 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
62638 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
62639 + if (free_blocks < root_blocks + 1 &&
62640 !uid_eq(sbi->s_resuid, current_fsuid()) &&
62641 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
62642 - !in_group_p (sbi->s_resgid))) {
62643 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
62644 return 0;
62645 }
62646 return 1;
62647 diff --git a/fs/ext2/super.c b/fs/ext2/super.c
62648 index b88edc0..c4088ab 100644
62649 --- a/fs/ext2/super.c
62650 +++ b/fs/ext2/super.c
62651 @@ -264,10 +264,8 @@ static int ext2_show_options(struct seq_file *seq, struct dentry *root)
62652 #ifdef CONFIG_EXT2_FS_XATTR
62653 if (test_opt(sb, XATTR_USER))
62654 seq_puts(seq, ",user_xattr");
62655 - if (!test_opt(sb, XATTR_USER) &&
62656 - (def_mount_opts & EXT2_DEFM_XATTR_USER)) {
62657 + if (!test_opt(sb, XATTR_USER))
62658 seq_puts(seq, ",nouser_xattr");
62659 - }
62660 #endif
62661
62662 #ifdef CONFIG_EXT2_FS_POSIX_ACL
62663 @@ -841,8 +839,8 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent)
62664 if (def_mount_opts & EXT2_DEFM_UID16)
62665 set_opt(sbi->s_mount_opt, NO_UID32);
62666 #ifdef CONFIG_EXT2_FS_XATTR
62667 - if (def_mount_opts & EXT2_DEFM_XATTR_USER)
62668 - set_opt(sbi->s_mount_opt, XATTR_USER);
62669 + /* always enable user xattrs */
62670 + set_opt(sbi->s_mount_opt, XATTR_USER);
62671 #endif
62672 #ifdef CONFIG_EXT2_FS_POSIX_ACL
62673 if (def_mount_opts & EXT2_DEFM_ACL)
62674 diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
62675 index 9142614..97484fa 100644
62676 --- a/fs/ext2/xattr.c
62677 +++ b/fs/ext2/xattr.c
62678 @@ -247,7 +247,7 @@ ext2_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
62679 struct buffer_head *bh = NULL;
62680 struct ext2_xattr_entry *entry;
62681 char *end;
62682 - size_t rest = buffer_size;
62683 + size_t rest = buffer_size, total_size = 0;
62684 int error;
62685
62686 ea_idebug(inode, "buffer=%p, buffer_size=%ld",
62687 @@ -305,9 +305,10 @@ bad_block: ext2_error(inode->i_sb, "ext2_xattr_list",
62688 buffer += size;
62689 }
62690 rest -= size;
62691 + total_size += size;
62692 }
62693 }
62694 - error = buffer_size - rest; /* total size */
62695 + error = total_size;
62696
62697 cleanup:
62698 brelse(bh);
62699 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
62700 index 158b5d4..2432610 100644
62701 --- a/fs/ext3/balloc.c
62702 +++ b/fs/ext3/balloc.c
62703 @@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
62704
62705 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
62706 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
62707 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
62708 + if (free_blocks < root_blocks + 1 &&
62709 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
62710 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
62711 - !in_group_p (sbi->s_resgid))) {
62712 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
62713 return 0;
62714 }
62715 return 1;
62716 diff --git a/fs/ext3/super.c b/fs/ext3/super.c
62717 index 2c42e73..cf5b892 100644
62718 --- a/fs/ext3/super.c
62719 +++ b/fs/ext3/super.c
62720 @@ -649,10 +649,8 @@ static int ext3_show_options(struct seq_file *seq, struct dentry *root)
62721 #ifdef CONFIG_EXT3_FS_XATTR
62722 if (test_opt(sb, XATTR_USER))
62723 seq_puts(seq, ",user_xattr");
62724 - if (!test_opt(sb, XATTR_USER) &&
62725 - (def_mount_opts & EXT3_DEFM_XATTR_USER)) {
62726 + if (!test_opt(sb, XATTR_USER))
62727 seq_puts(seq, ",nouser_xattr");
62728 - }
62729 #endif
62730 #ifdef CONFIG_EXT3_FS_POSIX_ACL
62731 if (test_opt(sb, POSIX_ACL))
62732 @@ -1749,8 +1747,8 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent)
62733 if (def_mount_opts & EXT3_DEFM_UID16)
62734 set_opt(sbi->s_mount_opt, NO_UID32);
62735 #ifdef CONFIG_EXT3_FS_XATTR
62736 - if (def_mount_opts & EXT3_DEFM_XATTR_USER)
62737 - set_opt(sbi->s_mount_opt, XATTR_USER);
62738 + /* always enable user xattrs */
62739 + set_opt(sbi->s_mount_opt, XATTR_USER);
62740 #endif
62741 #ifdef CONFIG_EXT3_FS_POSIX_ACL
62742 if (def_mount_opts & EXT3_DEFM_ACL)
62743 diff --git a/fs/ext3/xattr.c b/fs/ext3/xattr.c
62744 index c6874be..f8a6ae8 100644
62745 --- a/fs/ext3/xattr.c
62746 +++ b/fs/ext3/xattr.c
62747 @@ -330,7 +330,7 @@ static int
62748 ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
62749 char *buffer, size_t buffer_size)
62750 {
62751 - size_t rest = buffer_size;
62752 + size_t rest = buffer_size, total_size = 0;
62753
62754 for (; !IS_LAST_ENTRY(entry); entry = EXT3_XATTR_NEXT(entry)) {
62755 const struct xattr_handler *handler =
62756 @@ -347,9 +347,10 @@ ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
62757 buffer += size;
62758 }
62759 rest -= size;
62760 + total_size += size;
62761 }
62762 }
62763 - return buffer_size - rest;
62764 + return total_size;
62765 }
62766
62767 static int
62768 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
62769 index e069155..b825b08 100644
62770 --- a/fs/ext4/balloc.c
62771 +++ b/fs/ext4/balloc.c
62772 @@ -557,8 +557,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
62773 /* Hm, nope. Are (enough) root reserved clusters available? */
62774 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
62775 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
62776 - capable(CAP_SYS_RESOURCE) ||
62777 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
62778 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
62779 + capable_nolog(CAP_SYS_RESOURCE)) {
62780
62781 if (free_clusters >= (nclusters + dirty_clusters +
62782 resv_clusters))
62783 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
62784 index 96ac9d3..1c30e7e6 100644
62785 --- a/fs/ext4/ext4.h
62786 +++ b/fs/ext4/ext4.h
62787 @@ -1275,19 +1275,19 @@ struct ext4_sb_info {
62788 unsigned long s_mb_last_start;
62789
62790 /* stats for buddy allocator */
62791 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
62792 - atomic_t s_bal_success; /* we found long enough chunks */
62793 - atomic_t s_bal_allocated; /* in blocks */
62794 - atomic_t s_bal_ex_scanned; /* total extents scanned */
62795 - atomic_t s_bal_goals; /* goal hits */
62796 - atomic_t s_bal_breaks; /* too long searches */
62797 - atomic_t s_bal_2orders; /* 2^order hits */
62798 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
62799 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
62800 + atomic_unchecked_t s_bal_allocated; /* in blocks */
62801 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
62802 + atomic_unchecked_t s_bal_goals; /* goal hits */
62803 + atomic_unchecked_t s_bal_breaks; /* too long searches */
62804 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
62805 spinlock_t s_bal_lock;
62806 unsigned long s_mb_buddies_generated;
62807 unsigned long long s_mb_generation_time;
62808 - atomic_t s_mb_lost_chunks;
62809 - atomic_t s_mb_preallocated;
62810 - atomic_t s_mb_discarded;
62811 + atomic_unchecked_t s_mb_lost_chunks;
62812 + atomic_unchecked_t s_mb_preallocated;
62813 + atomic_unchecked_t s_mb_discarded;
62814 atomic_t s_lock_busy;
62815
62816 /* locality groups */
62817 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
62818 index 8b0f9ef..cb9f620 100644
62819 --- a/fs/ext4/mballoc.c
62820 +++ b/fs/ext4/mballoc.c
62821 @@ -1901,7 +1901,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
62822 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
62823
62824 if (EXT4_SB(sb)->s_mb_stats)
62825 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
62826 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
62827
62828 break;
62829 }
62830 @@ -2211,7 +2211,7 @@ repeat:
62831 ac->ac_status = AC_STATUS_CONTINUE;
62832 ac->ac_flags |= EXT4_MB_HINT_FIRST;
62833 cr = 3;
62834 - atomic_inc(&sbi->s_mb_lost_chunks);
62835 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
62836 goto repeat;
62837 }
62838 }
62839 @@ -2717,25 +2717,25 @@ int ext4_mb_release(struct super_block *sb)
62840 if (sbi->s_mb_stats) {
62841 ext4_msg(sb, KERN_INFO,
62842 "mballoc: %u blocks %u reqs (%u success)",
62843 - atomic_read(&sbi->s_bal_allocated),
62844 - atomic_read(&sbi->s_bal_reqs),
62845 - atomic_read(&sbi->s_bal_success));
62846 + atomic_read_unchecked(&sbi->s_bal_allocated),
62847 + atomic_read_unchecked(&sbi->s_bal_reqs),
62848 + atomic_read_unchecked(&sbi->s_bal_success));
62849 ext4_msg(sb, KERN_INFO,
62850 "mballoc: %u extents scanned, %u goal hits, "
62851 "%u 2^N hits, %u breaks, %u lost",
62852 - atomic_read(&sbi->s_bal_ex_scanned),
62853 - atomic_read(&sbi->s_bal_goals),
62854 - atomic_read(&sbi->s_bal_2orders),
62855 - atomic_read(&sbi->s_bal_breaks),
62856 - atomic_read(&sbi->s_mb_lost_chunks));
62857 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
62858 + atomic_read_unchecked(&sbi->s_bal_goals),
62859 + atomic_read_unchecked(&sbi->s_bal_2orders),
62860 + atomic_read_unchecked(&sbi->s_bal_breaks),
62861 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
62862 ext4_msg(sb, KERN_INFO,
62863 "mballoc: %lu generated and it took %Lu",
62864 sbi->s_mb_buddies_generated,
62865 sbi->s_mb_generation_time);
62866 ext4_msg(sb, KERN_INFO,
62867 "mballoc: %u preallocated, %u discarded",
62868 - atomic_read(&sbi->s_mb_preallocated),
62869 - atomic_read(&sbi->s_mb_discarded));
62870 + atomic_read_unchecked(&sbi->s_mb_preallocated),
62871 + atomic_read_unchecked(&sbi->s_mb_discarded));
62872 }
62873
62874 free_percpu(sbi->s_locality_groups);
62875 @@ -3192,16 +3192,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
62876 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
62877
62878 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
62879 - atomic_inc(&sbi->s_bal_reqs);
62880 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
62881 + atomic_inc_unchecked(&sbi->s_bal_reqs);
62882 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
62883 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
62884 - atomic_inc(&sbi->s_bal_success);
62885 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
62886 + atomic_inc_unchecked(&sbi->s_bal_success);
62887 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
62888 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
62889 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
62890 - atomic_inc(&sbi->s_bal_goals);
62891 + atomic_inc_unchecked(&sbi->s_bal_goals);
62892 if (ac->ac_found > sbi->s_mb_max_to_scan)
62893 - atomic_inc(&sbi->s_bal_breaks);
62894 + atomic_inc_unchecked(&sbi->s_bal_breaks);
62895 }
62896
62897 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
62898 @@ -3628,7 +3628,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
62899 trace_ext4_mb_new_inode_pa(ac, pa);
62900
62901 ext4_mb_use_inode_pa(ac, pa);
62902 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
62903 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
62904
62905 ei = EXT4_I(ac->ac_inode);
62906 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
62907 @@ -3688,7 +3688,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
62908 trace_ext4_mb_new_group_pa(ac, pa);
62909
62910 ext4_mb_use_group_pa(ac, pa);
62911 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
62912 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
62913
62914 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
62915 lg = ac->ac_lg;
62916 @@ -3777,7 +3777,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
62917 * from the bitmap and continue.
62918 */
62919 }
62920 - atomic_add(free, &sbi->s_mb_discarded);
62921 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
62922
62923 return err;
62924 }
62925 @@ -3795,7 +3795,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
62926 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
62927 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
62928 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
62929 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
62930 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
62931 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
62932
62933 return 0;
62934 diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
62935 index 8313ca3..8a37d08 100644
62936 --- a/fs/ext4/mmp.c
62937 +++ b/fs/ext4/mmp.c
62938 @@ -111,7 +111,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
62939 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
62940 const char *function, unsigned int line, const char *msg)
62941 {
62942 - __ext4_warning(sb, function, line, msg);
62943 + __ext4_warning(sb, function, line, "%s", msg);
62944 __ext4_warning(sb, function, line,
62945 "MMP failure info: last update time: %llu, last update "
62946 "node: %s, last update device: %s\n",
62947 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
62948 index b1f0ac7..77e9a05 100644
62949 --- a/fs/ext4/super.c
62950 +++ b/fs/ext4/super.c
62951 @@ -1274,7 +1274,7 @@ static ext4_fsblk_t get_sb_block(void **data)
62952 }
62953
62954 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
62955 -static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
62956 +static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
62957 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
62958
62959 #ifdef CONFIG_QUOTA
62960 @@ -2454,7 +2454,7 @@ struct ext4_attr {
62961 int offset;
62962 int deprecated_val;
62963 } u;
62964 -};
62965 +} __do_const;
62966
62967 static int parse_strtoull(const char *buf,
62968 unsigned long long max, unsigned long long *value)
62969 diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
62970 index 2d1e5803..1b082d415 100644
62971 --- a/fs/ext4/xattr.c
62972 +++ b/fs/ext4/xattr.c
62973 @@ -399,7 +399,7 @@ static int
62974 ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
62975 char *buffer, size_t buffer_size)
62976 {
62977 - size_t rest = buffer_size;
62978 + size_t rest = buffer_size, total_size = 0;
62979
62980 for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
62981 const struct xattr_handler *handler =
62982 @@ -416,9 +416,10 @@ ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
62983 buffer += size;
62984 }
62985 rest -= size;
62986 + total_size += size;
62987 }
62988 }
62989 - return buffer_size - rest;
62990 + return total_size;
62991 }
62992
62993 static int
62994 diff --git a/fs/fcntl.c b/fs/fcntl.c
62995 index 22d1c3d..600cf7e 100644
62996 --- a/fs/fcntl.c
62997 +++ b/fs/fcntl.c
62998 @@ -107,6 +107,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
62999 if (err)
63000 return err;
63001
63002 + if (gr_handle_chroot_fowner(pid, type))
63003 + return -ENOENT;
63004 + if (gr_check_protected_task_fowner(pid, type))
63005 + return -EACCES;
63006 +
63007 f_modown(filp, pid, type, force);
63008 return 0;
63009 }
63010 diff --git a/fs/fhandle.c b/fs/fhandle.c
63011 index 999ff5c..ac037c9 100644
63012 --- a/fs/fhandle.c
63013 +++ b/fs/fhandle.c
63014 @@ -8,6 +8,7 @@
63015 #include <linux/fs_struct.h>
63016 #include <linux/fsnotify.h>
63017 #include <linux/personality.h>
63018 +#include <linux/grsecurity.h>
63019 #include <asm/uaccess.h>
63020 #include "internal.h"
63021 #include "mount.h"
63022 @@ -67,8 +68,7 @@ static long do_sys_name_to_handle(struct path *path,
63023 } else
63024 retval = 0;
63025 /* copy the mount id */
63026 - if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
63027 - sizeof(*mnt_id)) ||
63028 + if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
63029 copy_to_user(ufh, handle,
63030 sizeof(struct file_handle) + handle_bytes))
63031 retval = -EFAULT;
63032 @@ -175,7 +175,7 @@ static int handle_to_path(int mountdirfd, struct file_handle __user *ufh,
63033 * the directory. Ideally we would like CAP_DAC_SEARCH.
63034 * But we don't have that
63035 */
63036 - if (!capable(CAP_DAC_READ_SEARCH)) {
63037 + if (!capable(CAP_DAC_READ_SEARCH) || !gr_chroot_fhandle()) {
63038 retval = -EPERM;
63039 goto out_err;
63040 }
63041 diff --git a/fs/file.c b/fs/file.c
63042 index 66923fe..2849783 100644
63043 --- a/fs/file.c
63044 +++ b/fs/file.c
63045 @@ -16,6 +16,7 @@
63046 #include <linux/slab.h>
63047 #include <linux/vmalloc.h>
63048 #include <linux/file.h>
63049 +#include <linux/security.h>
63050 #include <linux/fdtable.h>
63051 #include <linux/bitops.h>
63052 #include <linux/interrupt.h>
63053 @@ -139,7 +140,7 @@ out:
63054 * Return <0 error code on error; 1 on successful completion.
63055 * The files->file_lock should be held on entry, and will be held on exit.
63056 */
63057 -static int expand_fdtable(struct files_struct *files, int nr)
63058 +static int expand_fdtable(struct files_struct *files, unsigned int nr)
63059 __releases(files->file_lock)
63060 __acquires(files->file_lock)
63061 {
63062 @@ -184,7 +185,7 @@ static int expand_fdtable(struct files_struct *files, int nr)
63063 * expanded and execution may have blocked.
63064 * The files->file_lock should be held on entry, and will be held on exit.
63065 */
63066 -static int expand_files(struct files_struct *files, int nr)
63067 +static int expand_files(struct files_struct *files, unsigned int nr)
63068 {
63069 struct fdtable *fdt;
63070
63071 @@ -799,6 +800,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
63072 if (!file)
63073 return __close_fd(files, fd);
63074
63075 + gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
63076 if (fd >= rlimit(RLIMIT_NOFILE))
63077 return -EBADF;
63078
63079 @@ -825,6 +827,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
63080 if (unlikely(oldfd == newfd))
63081 return -EINVAL;
63082
63083 + gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
63084 if (newfd >= rlimit(RLIMIT_NOFILE))
63085 return -EBADF;
63086
63087 @@ -880,6 +883,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
63088 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
63089 {
63090 int err;
63091 + gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
63092 if (from >= rlimit(RLIMIT_NOFILE))
63093 return -EINVAL;
63094 err = alloc_fd(from, flags);
63095 diff --git a/fs/filesystems.c b/fs/filesystems.c
63096 index 5797d45..7d7d79a 100644
63097 --- a/fs/filesystems.c
63098 +++ b/fs/filesystems.c
63099 @@ -275,7 +275,11 @@ struct file_system_type *get_fs_type(const char *name)
63100 int len = dot ? dot - name : strlen(name);
63101
63102 fs = __get_fs_type(name, len);
63103 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
63104 + if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
63105 +#else
63106 if (!fs && (request_module("fs-%.*s", len, name) == 0))
63107 +#endif
63108 fs = __get_fs_type(name, len);
63109
63110 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
63111 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
63112 index 7dca743..543d620 100644
63113 --- a/fs/fs_struct.c
63114 +++ b/fs/fs_struct.c
63115 @@ -4,6 +4,7 @@
63116 #include <linux/path.h>
63117 #include <linux/slab.h>
63118 #include <linux/fs_struct.h>
63119 +#include <linux/grsecurity.h>
63120 #include "internal.h"
63121
63122 /*
63123 @@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
63124 write_seqcount_begin(&fs->seq);
63125 old_root = fs->root;
63126 fs->root = *path;
63127 + gr_set_chroot_entries(current, path);
63128 write_seqcount_end(&fs->seq);
63129 spin_unlock(&fs->lock);
63130 if (old_root.dentry)
63131 @@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
63132 int hits = 0;
63133 spin_lock(&fs->lock);
63134 write_seqcount_begin(&fs->seq);
63135 + /* this root replacement is only done by pivot_root,
63136 + leave grsec's chroot tagging alone for this task
63137 + so that a pivoted root isn't treated as a chroot
63138 + */
63139 hits += replace_path(&fs->root, old_root, new_root);
63140 hits += replace_path(&fs->pwd, old_root, new_root);
63141 write_seqcount_end(&fs->seq);
63142 @@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
63143 task_lock(tsk);
63144 spin_lock(&fs->lock);
63145 tsk->fs = NULL;
63146 - kill = !--fs->users;
63147 + gr_clear_chroot_entries(tsk);
63148 + kill = !atomic_dec_return(&fs->users);
63149 spin_unlock(&fs->lock);
63150 task_unlock(tsk);
63151 if (kill)
63152 @@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
63153 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
63154 /* We don't need to lock fs - think why ;-) */
63155 if (fs) {
63156 - fs->users = 1;
63157 + atomic_set(&fs->users, 1);
63158 fs->in_exec = 0;
63159 spin_lock_init(&fs->lock);
63160 seqcount_init(&fs->seq);
63161 @@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
63162 spin_lock(&old->lock);
63163 fs->root = old->root;
63164 path_get(&fs->root);
63165 + /* instead of calling gr_set_chroot_entries here,
63166 + we call it from every caller of this function
63167 + */
63168 fs->pwd = old->pwd;
63169 path_get(&fs->pwd);
63170 spin_unlock(&old->lock);
63171 @@ -139,8 +149,9 @@ int unshare_fs_struct(void)
63172
63173 task_lock(current);
63174 spin_lock(&fs->lock);
63175 - kill = !--fs->users;
63176 + kill = !atomic_dec_return(&fs->users);
63177 current->fs = new_fs;
63178 + gr_set_chroot_entries(current, &new_fs->root);
63179 spin_unlock(&fs->lock);
63180 task_unlock(current);
63181
63182 @@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
63183
63184 int current_umask(void)
63185 {
63186 - return current->fs->umask;
63187 + return current->fs->umask | gr_acl_umask();
63188 }
63189 EXPORT_SYMBOL(current_umask);
63190
63191 /* to be mentioned only in INIT_TASK */
63192 struct fs_struct init_fs = {
63193 - .users = 1,
63194 + .users = ATOMIC_INIT(1),
63195 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
63196 .seq = SEQCNT_ZERO(init_fs.seq),
63197 .umask = 0022,
63198 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
63199 index 89acec7..a575262 100644
63200 --- a/fs/fscache/cookie.c
63201 +++ b/fs/fscache/cookie.c
63202 @@ -19,7 +19,7 @@
63203
63204 struct kmem_cache *fscache_cookie_jar;
63205
63206 -static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
63207 +static atomic_unchecked_t fscache_object_debug_id = ATOMIC_INIT(0);
63208
63209 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
63210 static int fscache_alloc_object(struct fscache_cache *cache,
63211 @@ -69,11 +69,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
63212 parent ? (char *) parent->def->name : "<no-parent>",
63213 def->name, netfs_data, enable);
63214
63215 - fscache_stat(&fscache_n_acquires);
63216 + fscache_stat_unchecked(&fscache_n_acquires);
63217
63218 /* if there's no parent cookie, then we don't create one here either */
63219 if (!parent) {
63220 - fscache_stat(&fscache_n_acquires_null);
63221 + fscache_stat_unchecked(&fscache_n_acquires_null);
63222 _leave(" [no parent]");
63223 return NULL;
63224 }
63225 @@ -88,7 +88,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
63226 /* allocate and initialise a cookie */
63227 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
63228 if (!cookie) {
63229 - fscache_stat(&fscache_n_acquires_oom);
63230 + fscache_stat_unchecked(&fscache_n_acquires_oom);
63231 _leave(" [ENOMEM]");
63232 return NULL;
63233 }
63234 @@ -115,13 +115,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
63235
63236 switch (cookie->def->type) {
63237 case FSCACHE_COOKIE_TYPE_INDEX:
63238 - fscache_stat(&fscache_n_cookie_index);
63239 + fscache_stat_unchecked(&fscache_n_cookie_index);
63240 break;
63241 case FSCACHE_COOKIE_TYPE_DATAFILE:
63242 - fscache_stat(&fscache_n_cookie_data);
63243 + fscache_stat_unchecked(&fscache_n_cookie_data);
63244 break;
63245 default:
63246 - fscache_stat(&fscache_n_cookie_special);
63247 + fscache_stat_unchecked(&fscache_n_cookie_special);
63248 break;
63249 }
63250
63251 @@ -135,7 +135,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
63252 } else {
63253 atomic_dec(&parent->n_children);
63254 __fscache_cookie_put(cookie);
63255 - fscache_stat(&fscache_n_acquires_nobufs);
63256 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
63257 _leave(" = NULL");
63258 return NULL;
63259 }
63260 @@ -144,7 +144,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
63261 }
63262 }
63263
63264 - fscache_stat(&fscache_n_acquires_ok);
63265 + fscache_stat_unchecked(&fscache_n_acquires_ok);
63266 _leave(" = %p", cookie);
63267 return cookie;
63268 }
63269 @@ -213,7 +213,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
63270 cache = fscache_select_cache_for_object(cookie->parent);
63271 if (!cache) {
63272 up_read(&fscache_addremove_sem);
63273 - fscache_stat(&fscache_n_acquires_no_cache);
63274 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
63275 _leave(" = -ENOMEDIUM [no cache]");
63276 return -ENOMEDIUM;
63277 }
63278 @@ -297,14 +297,14 @@ static int fscache_alloc_object(struct fscache_cache *cache,
63279 object = cache->ops->alloc_object(cache, cookie);
63280 fscache_stat_d(&fscache_n_cop_alloc_object);
63281 if (IS_ERR(object)) {
63282 - fscache_stat(&fscache_n_object_no_alloc);
63283 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
63284 ret = PTR_ERR(object);
63285 goto error;
63286 }
63287
63288 - fscache_stat(&fscache_n_object_alloc);
63289 + fscache_stat_unchecked(&fscache_n_object_alloc);
63290
63291 - object->debug_id = atomic_inc_return(&fscache_object_debug_id);
63292 + object->debug_id = atomic_inc_return_unchecked(&fscache_object_debug_id);
63293
63294 _debug("ALLOC OBJ%x: %s {%lx}",
63295 object->debug_id, cookie->def->name, object->events);
63296 @@ -418,7 +418,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
63297
63298 _enter("{%s}", cookie->def->name);
63299
63300 - fscache_stat(&fscache_n_invalidates);
63301 + fscache_stat_unchecked(&fscache_n_invalidates);
63302
63303 /* Only permit invalidation of data files. Invalidating an index will
63304 * require the caller to release all its attachments to the tree rooted
63305 @@ -476,10 +476,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
63306 {
63307 struct fscache_object *object;
63308
63309 - fscache_stat(&fscache_n_updates);
63310 + fscache_stat_unchecked(&fscache_n_updates);
63311
63312 if (!cookie) {
63313 - fscache_stat(&fscache_n_updates_null);
63314 + fscache_stat_unchecked(&fscache_n_updates_null);
63315 _leave(" [no cookie]");
63316 return;
63317 }
63318 @@ -580,12 +580,12 @@ EXPORT_SYMBOL(__fscache_disable_cookie);
63319 */
63320 void __fscache_relinquish_cookie(struct fscache_cookie *cookie, bool retire)
63321 {
63322 - fscache_stat(&fscache_n_relinquishes);
63323 + fscache_stat_unchecked(&fscache_n_relinquishes);
63324 if (retire)
63325 - fscache_stat(&fscache_n_relinquishes_retire);
63326 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
63327
63328 if (!cookie) {
63329 - fscache_stat(&fscache_n_relinquishes_null);
63330 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
63331 _leave(" [no cookie]");
63332 return;
63333 }
63334 @@ -686,7 +686,7 @@ int __fscache_check_consistency(struct fscache_cookie *cookie)
63335 if (test_bit(FSCACHE_IOERROR, &object->cache->flags))
63336 goto inconsistent;
63337
63338 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
63339 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
63340
63341 __fscache_use_cookie(cookie);
63342 if (fscache_submit_op(object, op) < 0)
63343 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
63344 index 7872a62..d91b19f 100644
63345 --- a/fs/fscache/internal.h
63346 +++ b/fs/fscache/internal.h
63347 @@ -137,8 +137,8 @@ extern void fscache_operation_gc(struct work_struct *);
63348 extern int fscache_wait_for_deferred_lookup(struct fscache_cookie *);
63349 extern int fscache_wait_for_operation_activation(struct fscache_object *,
63350 struct fscache_operation *,
63351 - atomic_t *,
63352 - atomic_t *,
63353 + atomic_unchecked_t *,
63354 + atomic_unchecked_t *,
63355 void (*)(struct fscache_operation *));
63356 extern void fscache_invalidate_writes(struct fscache_cookie *);
63357
63358 @@ -157,101 +157,101 @@ extern void fscache_proc_cleanup(void);
63359 * stats.c
63360 */
63361 #ifdef CONFIG_FSCACHE_STATS
63362 -extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
63363 -extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
63364 +extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
63365 +extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
63366
63367 -extern atomic_t fscache_n_op_pend;
63368 -extern atomic_t fscache_n_op_run;
63369 -extern atomic_t fscache_n_op_enqueue;
63370 -extern atomic_t fscache_n_op_deferred_release;
63371 -extern atomic_t fscache_n_op_release;
63372 -extern atomic_t fscache_n_op_gc;
63373 -extern atomic_t fscache_n_op_cancelled;
63374 -extern atomic_t fscache_n_op_rejected;
63375 +extern atomic_unchecked_t fscache_n_op_pend;
63376 +extern atomic_unchecked_t fscache_n_op_run;
63377 +extern atomic_unchecked_t fscache_n_op_enqueue;
63378 +extern atomic_unchecked_t fscache_n_op_deferred_release;
63379 +extern atomic_unchecked_t fscache_n_op_release;
63380 +extern atomic_unchecked_t fscache_n_op_gc;
63381 +extern atomic_unchecked_t fscache_n_op_cancelled;
63382 +extern atomic_unchecked_t fscache_n_op_rejected;
63383
63384 -extern atomic_t fscache_n_attr_changed;
63385 -extern atomic_t fscache_n_attr_changed_ok;
63386 -extern atomic_t fscache_n_attr_changed_nobufs;
63387 -extern atomic_t fscache_n_attr_changed_nomem;
63388 -extern atomic_t fscache_n_attr_changed_calls;
63389 +extern atomic_unchecked_t fscache_n_attr_changed;
63390 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
63391 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
63392 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
63393 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
63394
63395 -extern atomic_t fscache_n_allocs;
63396 -extern atomic_t fscache_n_allocs_ok;
63397 -extern atomic_t fscache_n_allocs_wait;
63398 -extern atomic_t fscache_n_allocs_nobufs;
63399 -extern atomic_t fscache_n_allocs_intr;
63400 -extern atomic_t fscache_n_allocs_object_dead;
63401 -extern atomic_t fscache_n_alloc_ops;
63402 -extern atomic_t fscache_n_alloc_op_waits;
63403 +extern atomic_unchecked_t fscache_n_allocs;
63404 +extern atomic_unchecked_t fscache_n_allocs_ok;
63405 +extern atomic_unchecked_t fscache_n_allocs_wait;
63406 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
63407 +extern atomic_unchecked_t fscache_n_allocs_intr;
63408 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
63409 +extern atomic_unchecked_t fscache_n_alloc_ops;
63410 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
63411
63412 -extern atomic_t fscache_n_retrievals;
63413 -extern atomic_t fscache_n_retrievals_ok;
63414 -extern atomic_t fscache_n_retrievals_wait;
63415 -extern atomic_t fscache_n_retrievals_nodata;
63416 -extern atomic_t fscache_n_retrievals_nobufs;
63417 -extern atomic_t fscache_n_retrievals_intr;
63418 -extern atomic_t fscache_n_retrievals_nomem;
63419 -extern atomic_t fscache_n_retrievals_object_dead;
63420 -extern atomic_t fscache_n_retrieval_ops;
63421 -extern atomic_t fscache_n_retrieval_op_waits;
63422 +extern atomic_unchecked_t fscache_n_retrievals;
63423 +extern atomic_unchecked_t fscache_n_retrievals_ok;
63424 +extern atomic_unchecked_t fscache_n_retrievals_wait;
63425 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
63426 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
63427 +extern atomic_unchecked_t fscache_n_retrievals_intr;
63428 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
63429 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
63430 +extern atomic_unchecked_t fscache_n_retrieval_ops;
63431 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
63432
63433 -extern atomic_t fscache_n_stores;
63434 -extern atomic_t fscache_n_stores_ok;
63435 -extern atomic_t fscache_n_stores_again;
63436 -extern atomic_t fscache_n_stores_nobufs;
63437 -extern atomic_t fscache_n_stores_oom;
63438 -extern atomic_t fscache_n_store_ops;
63439 -extern atomic_t fscache_n_store_calls;
63440 -extern atomic_t fscache_n_store_pages;
63441 -extern atomic_t fscache_n_store_radix_deletes;
63442 -extern atomic_t fscache_n_store_pages_over_limit;
63443 +extern atomic_unchecked_t fscache_n_stores;
63444 +extern atomic_unchecked_t fscache_n_stores_ok;
63445 +extern atomic_unchecked_t fscache_n_stores_again;
63446 +extern atomic_unchecked_t fscache_n_stores_nobufs;
63447 +extern atomic_unchecked_t fscache_n_stores_oom;
63448 +extern atomic_unchecked_t fscache_n_store_ops;
63449 +extern atomic_unchecked_t fscache_n_store_calls;
63450 +extern atomic_unchecked_t fscache_n_store_pages;
63451 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
63452 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
63453
63454 -extern atomic_t fscache_n_store_vmscan_not_storing;
63455 -extern atomic_t fscache_n_store_vmscan_gone;
63456 -extern atomic_t fscache_n_store_vmscan_busy;
63457 -extern atomic_t fscache_n_store_vmscan_cancelled;
63458 -extern atomic_t fscache_n_store_vmscan_wait;
63459 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
63460 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
63461 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
63462 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
63463 +extern atomic_unchecked_t fscache_n_store_vmscan_wait;
63464
63465 -extern atomic_t fscache_n_marks;
63466 -extern atomic_t fscache_n_uncaches;
63467 +extern atomic_unchecked_t fscache_n_marks;
63468 +extern atomic_unchecked_t fscache_n_uncaches;
63469
63470 -extern atomic_t fscache_n_acquires;
63471 -extern atomic_t fscache_n_acquires_null;
63472 -extern atomic_t fscache_n_acquires_no_cache;
63473 -extern atomic_t fscache_n_acquires_ok;
63474 -extern atomic_t fscache_n_acquires_nobufs;
63475 -extern atomic_t fscache_n_acquires_oom;
63476 +extern atomic_unchecked_t fscache_n_acquires;
63477 +extern atomic_unchecked_t fscache_n_acquires_null;
63478 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
63479 +extern atomic_unchecked_t fscache_n_acquires_ok;
63480 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
63481 +extern atomic_unchecked_t fscache_n_acquires_oom;
63482
63483 -extern atomic_t fscache_n_invalidates;
63484 -extern atomic_t fscache_n_invalidates_run;
63485 +extern atomic_unchecked_t fscache_n_invalidates;
63486 +extern atomic_unchecked_t fscache_n_invalidates_run;
63487
63488 -extern atomic_t fscache_n_updates;
63489 -extern atomic_t fscache_n_updates_null;
63490 -extern atomic_t fscache_n_updates_run;
63491 +extern atomic_unchecked_t fscache_n_updates;
63492 +extern atomic_unchecked_t fscache_n_updates_null;
63493 +extern atomic_unchecked_t fscache_n_updates_run;
63494
63495 -extern atomic_t fscache_n_relinquishes;
63496 -extern atomic_t fscache_n_relinquishes_null;
63497 -extern atomic_t fscache_n_relinquishes_waitcrt;
63498 -extern atomic_t fscache_n_relinquishes_retire;
63499 +extern atomic_unchecked_t fscache_n_relinquishes;
63500 +extern atomic_unchecked_t fscache_n_relinquishes_null;
63501 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
63502 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
63503
63504 -extern atomic_t fscache_n_cookie_index;
63505 -extern atomic_t fscache_n_cookie_data;
63506 -extern atomic_t fscache_n_cookie_special;
63507 +extern atomic_unchecked_t fscache_n_cookie_index;
63508 +extern atomic_unchecked_t fscache_n_cookie_data;
63509 +extern atomic_unchecked_t fscache_n_cookie_special;
63510
63511 -extern atomic_t fscache_n_object_alloc;
63512 -extern atomic_t fscache_n_object_no_alloc;
63513 -extern atomic_t fscache_n_object_lookups;
63514 -extern atomic_t fscache_n_object_lookups_negative;
63515 -extern atomic_t fscache_n_object_lookups_positive;
63516 -extern atomic_t fscache_n_object_lookups_timed_out;
63517 -extern atomic_t fscache_n_object_created;
63518 -extern atomic_t fscache_n_object_avail;
63519 -extern atomic_t fscache_n_object_dead;
63520 +extern atomic_unchecked_t fscache_n_object_alloc;
63521 +extern atomic_unchecked_t fscache_n_object_no_alloc;
63522 +extern atomic_unchecked_t fscache_n_object_lookups;
63523 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
63524 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
63525 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
63526 +extern atomic_unchecked_t fscache_n_object_created;
63527 +extern atomic_unchecked_t fscache_n_object_avail;
63528 +extern atomic_unchecked_t fscache_n_object_dead;
63529
63530 -extern atomic_t fscache_n_checkaux_none;
63531 -extern atomic_t fscache_n_checkaux_okay;
63532 -extern atomic_t fscache_n_checkaux_update;
63533 -extern atomic_t fscache_n_checkaux_obsolete;
63534 +extern atomic_unchecked_t fscache_n_checkaux_none;
63535 +extern atomic_unchecked_t fscache_n_checkaux_okay;
63536 +extern atomic_unchecked_t fscache_n_checkaux_update;
63537 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
63538
63539 extern atomic_t fscache_n_cop_alloc_object;
63540 extern atomic_t fscache_n_cop_lookup_object;
63541 @@ -276,6 +276,11 @@ static inline void fscache_stat(atomic_t *stat)
63542 atomic_inc(stat);
63543 }
63544
63545 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
63546 +{
63547 + atomic_inc_unchecked(stat);
63548 +}
63549 +
63550 static inline void fscache_stat_d(atomic_t *stat)
63551 {
63552 atomic_dec(stat);
63553 @@ -288,6 +293,7 @@ extern const struct file_operations fscache_stats_fops;
63554
63555 #define __fscache_stat(stat) (NULL)
63556 #define fscache_stat(stat) do {} while (0)
63557 +#define fscache_stat_unchecked(stat) do {} while (0)
63558 #define fscache_stat_d(stat) do {} while (0)
63559 #endif
63560
63561 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
63562 index da032da..0076ce7 100644
63563 --- a/fs/fscache/object.c
63564 +++ b/fs/fscache/object.c
63565 @@ -454,7 +454,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
63566 _debug("LOOKUP \"%s\" in \"%s\"",
63567 cookie->def->name, object->cache->tag->name);
63568
63569 - fscache_stat(&fscache_n_object_lookups);
63570 + fscache_stat_unchecked(&fscache_n_object_lookups);
63571 fscache_stat(&fscache_n_cop_lookup_object);
63572 ret = object->cache->ops->lookup_object(object);
63573 fscache_stat_d(&fscache_n_cop_lookup_object);
63574 @@ -464,7 +464,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
63575 if (ret == -ETIMEDOUT) {
63576 /* probably stuck behind another object, so move this one to
63577 * the back of the queue */
63578 - fscache_stat(&fscache_n_object_lookups_timed_out);
63579 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
63580 _leave(" [timeout]");
63581 return NO_TRANSIT;
63582 }
63583 @@ -492,7 +492,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
63584 _enter("{OBJ%x,%s}", object->debug_id, object->state->name);
63585
63586 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
63587 - fscache_stat(&fscache_n_object_lookups_negative);
63588 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
63589
63590 /* Allow write requests to begin stacking up and read requests to begin
63591 * returning ENODATA.
63592 @@ -527,7 +527,7 @@ void fscache_obtained_object(struct fscache_object *object)
63593 /* if we were still looking up, then we must have a positive lookup
63594 * result, in which case there may be data available */
63595 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
63596 - fscache_stat(&fscache_n_object_lookups_positive);
63597 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
63598
63599 /* We do (presumably) have data */
63600 clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
63601 @@ -539,7 +539,7 @@ void fscache_obtained_object(struct fscache_object *object)
63602 clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
63603 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP);
63604 } else {
63605 - fscache_stat(&fscache_n_object_created);
63606 + fscache_stat_unchecked(&fscache_n_object_created);
63607 }
63608
63609 set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
63610 @@ -575,7 +575,7 @@ static const struct fscache_state *fscache_object_available(struct fscache_objec
63611 fscache_stat_d(&fscache_n_cop_lookup_complete);
63612
63613 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
63614 - fscache_stat(&fscache_n_object_avail);
63615 + fscache_stat_unchecked(&fscache_n_object_avail);
63616
63617 _leave("");
63618 return transit_to(JUMPSTART_DEPS);
63619 @@ -722,7 +722,7 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
63620
63621 /* this just shifts the object release to the work processor */
63622 fscache_put_object(object);
63623 - fscache_stat(&fscache_n_object_dead);
63624 + fscache_stat_unchecked(&fscache_n_object_dead);
63625
63626 _leave("");
63627 return transit_to(OBJECT_DEAD);
63628 @@ -887,7 +887,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
63629 enum fscache_checkaux result;
63630
63631 if (!object->cookie->def->check_aux) {
63632 - fscache_stat(&fscache_n_checkaux_none);
63633 + fscache_stat_unchecked(&fscache_n_checkaux_none);
63634 return FSCACHE_CHECKAUX_OKAY;
63635 }
63636
63637 @@ -896,17 +896,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
63638 switch (result) {
63639 /* entry okay as is */
63640 case FSCACHE_CHECKAUX_OKAY:
63641 - fscache_stat(&fscache_n_checkaux_okay);
63642 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
63643 break;
63644
63645 /* entry requires update */
63646 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
63647 - fscache_stat(&fscache_n_checkaux_update);
63648 + fscache_stat_unchecked(&fscache_n_checkaux_update);
63649 break;
63650
63651 /* entry requires deletion */
63652 case FSCACHE_CHECKAUX_OBSOLETE:
63653 - fscache_stat(&fscache_n_checkaux_obsolete);
63654 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
63655 break;
63656
63657 default:
63658 @@ -993,7 +993,7 @@ static const struct fscache_state *fscache_invalidate_object(struct fscache_obje
63659 {
63660 const struct fscache_state *s;
63661
63662 - fscache_stat(&fscache_n_invalidates_run);
63663 + fscache_stat_unchecked(&fscache_n_invalidates_run);
63664 fscache_stat(&fscache_n_cop_invalidate_object);
63665 s = _fscache_invalidate_object(object, event);
63666 fscache_stat_d(&fscache_n_cop_invalidate_object);
63667 @@ -1008,7 +1008,7 @@ static const struct fscache_state *fscache_update_object(struct fscache_object *
63668 {
63669 _enter("{OBJ%x},%d", object->debug_id, event);
63670
63671 - fscache_stat(&fscache_n_updates_run);
63672 + fscache_stat_unchecked(&fscache_n_updates_run);
63673 fscache_stat(&fscache_n_cop_update_object);
63674 object->cache->ops->update_object(object);
63675 fscache_stat_d(&fscache_n_cop_update_object);
63676 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
63677 index e7b87a0..a85d47a 100644
63678 --- a/fs/fscache/operation.c
63679 +++ b/fs/fscache/operation.c
63680 @@ -17,7 +17,7 @@
63681 #include <linux/slab.h>
63682 #include "internal.h"
63683
63684 -atomic_t fscache_op_debug_id;
63685 +atomic_unchecked_t fscache_op_debug_id;
63686 EXPORT_SYMBOL(fscache_op_debug_id);
63687
63688 /**
63689 @@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
63690 ASSERTCMP(atomic_read(&op->usage), >, 0);
63691 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
63692
63693 - fscache_stat(&fscache_n_op_enqueue);
63694 + fscache_stat_unchecked(&fscache_n_op_enqueue);
63695 switch (op->flags & FSCACHE_OP_TYPE) {
63696 case FSCACHE_OP_ASYNC:
63697 _debug("queue async");
63698 @@ -72,7 +72,7 @@ static void fscache_run_op(struct fscache_object *object,
63699 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
63700 if (op->processor)
63701 fscache_enqueue_operation(op);
63702 - fscache_stat(&fscache_n_op_run);
63703 + fscache_stat_unchecked(&fscache_n_op_run);
63704 }
63705
63706 /*
63707 @@ -104,11 +104,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
63708 if (object->n_in_progress > 0) {
63709 atomic_inc(&op->usage);
63710 list_add_tail(&op->pend_link, &object->pending_ops);
63711 - fscache_stat(&fscache_n_op_pend);
63712 + fscache_stat_unchecked(&fscache_n_op_pend);
63713 } else if (!list_empty(&object->pending_ops)) {
63714 atomic_inc(&op->usage);
63715 list_add_tail(&op->pend_link, &object->pending_ops);
63716 - fscache_stat(&fscache_n_op_pend);
63717 + fscache_stat_unchecked(&fscache_n_op_pend);
63718 fscache_start_operations(object);
63719 } else {
63720 ASSERTCMP(object->n_in_progress, ==, 0);
63721 @@ -124,7 +124,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
63722 object->n_exclusive++; /* reads and writes must wait */
63723 atomic_inc(&op->usage);
63724 list_add_tail(&op->pend_link, &object->pending_ops);
63725 - fscache_stat(&fscache_n_op_pend);
63726 + fscache_stat_unchecked(&fscache_n_op_pend);
63727 ret = 0;
63728 } else {
63729 /* If we're in any other state, there must have been an I/O
63730 @@ -211,11 +211,11 @@ int fscache_submit_op(struct fscache_object *object,
63731 if (object->n_exclusive > 0) {
63732 atomic_inc(&op->usage);
63733 list_add_tail(&op->pend_link, &object->pending_ops);
63734 - fscache_stat(&fscache_n_op_pend);
63735 + fscache_stat_unchecked(&fscache_n_op_pend);
63736 } else if (!list_empty(&object->pending_ops)) {
63737 atomic_inc(&op->usage);
63738 list_add_tail(&op->pend_link, &object->pending_ops);
63739 - fscache_stat(&fscache_n_op_pend);
63740 + fscache_stat_unchecked(&fscache_n_op_pend);
63741 fscache_start_operations(object);
63742 } else {
63743 ASSERTCMP(object->n_exclusive, ==, 0);
63744 @@ -227,10 +227,10 @@ int fscache_submit_op(struct fscache_object *object,
63745 object->n_ops++;
63746 atomic_inc(&op->usage);
63747 list_add_tail(&op->pend_link, &object->pending_ops);
63748 - fscache_stat(&fscache_n_op_pend);
63749 + fscache_stat_unchecked(&fscache_n_op_pend);
63750 ret = 0;
63751 } else if (fscache_object_is_dying(object)) {
63752 - fscache_stat(&fscache_n_op_rejected);
63753 + fscache_stat_unchecked(&fscache_n_op_rejected);
63754 op->state = FSCACHE_OP_ST_CANCELLED;
63755 ret = -ENOBUFS;
63756 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
63757 @@ -309,7 +309,7 @@ int fscache_cancel_op(struct fscache_operation *op,
63758 ret = -EBUSY;
63759 if (op->state == FSCACHE_OP_ST_PENDING) {
63760 ASSERT(!list_empty(&op->pend_link));
63761 - fscache_stat(&fscache_n_op_cancelled);
63762 + fscache_stat_unchecked(&fscache_n_op_cancelled);
63763 list_del_init(&op->pend_link);
63764 if (do_cancel)
63765 do_cancel(op);
63766 @@ -341,7 +341,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
63767 while (!list_empty(&object->pending_ops)) {
63768 op = list_entry(object->pending_ops.next,
63769 struct fscache_operation, pend_link);
63770 - fscache_stat(&fscache_n_op_cancelled);
63771 + fscache_stat_unchecked(&fscache_n_op_cancelled);
63772 list_del_init(&op->pend_link);
63773
63774 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
63775 @@ -413,7 +413,7 @@ void fscache_put_operation(struct fscache_operation *op)
63776 op->state, ==, FSCACHE_OP_ST_CANCELLED);
63777 op->state = FSCACHE_OP_ST_DEAD;
63778
63779 - fscache_stat(&fscache_n_op_release);
63780 + fscache_stat_unchecked(&fscache_n_op_release);
63781
63782 if (op->release) {
63783 op->release(op);
63784 @@ -432,7 +432,7 @@ void fscache_put_operation(struct fscache_operation *op)
63785 * lock, and defer it otherwise */
63786 if (!spin_trylock(&object->lock)) {
63787 _debug("defer put");
63788 - fscache_stat(&fscache_n_op_deferred_release);
63789 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
63790
63791 cache = object->cache;
63792 spin_lock(&cache->op_gc_list_lock);
63793 @@ -485,7 +485,7 @@ void fscache_operation_gc(struct work_struct *work)
63794
63795 _debug("GC DEFERRED REL OBJ%x OP%x",
63796 object->debug_id, op->debug_id);
63797 - fscache_stat(&fscache_n_op_gc);
63798 + fscache_stat_unchecked(&fscache_n_op_gc);
63799
63800 ASSERTCMP(atomic_read(&op->usage), ==, 0);
63801 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
63802 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
63803 index de33b3f..8be4d29 100644
63804 --- a/fs/fscache/page.c
63805 +++ b/fs/fscache/page.c
63806 @@ -74,7 +74,7 @@ try_again:
63807 val = radix_tree_lookup(&cookie->stores, page->index);
63808 if (!val) {
63809 rcu_read_unlock();
63810 - fscache_stat(&fscache_n_store_vmscan_not_storing);
63811 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
63812 __fscache_uncache_page(cookie, page);
63813 return true;
63814 }
63815 @@ -104,11 +104,11 @@ try_again:
63816 spin_unlock(&cookie->stores_lock);
63817
63818 if (xpage) {
63819 - fscache_stat(&fscache_n_store_vmscan_cancelled);
63820 - fscache_stat(&fscache_n_store_radix_deletes);
63821 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
63822 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
63823 ASSERTCMP(xpage, ==, page);
63824 } else {
63825 - fscache_stat(&fscache_n_store_vmscan_gone);
63826 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
63827 }
63828
63829 wake_up_bit(&cookie->flags, 0);
63830 @@ -123,11 +123,11 @@ page_busy:
63831 * sleeping on memory allocation, so we may need to impose a timeout
63832 * too. */
63833 if (!(gfp & __GFP_WAIT) || !(gfp & __GFP_FS)) {
63834 - fscache_stat(&fscache_n_store_vmscan_busy);
63835 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
63836 return false;
63837 }
63838
63839 - fscache_stat(&fscache_n_store_vmscan_wait);
63840 + fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
63841 if (!release_page_wait_timeout(cookie, page))
63842 _debug("fscache writeout timeout page: %p{%lx}",
63843 page, page->index);
63844 @@ -156,7 +156,7 @@ static void fscache_end_page_write(struct fscache_object *object,
63845 FSCACHE_COOKIE_STORING_TAG);
63846 if (!radix_tree_tag_get(&cookie->stores, page->index,
63847 FSCACHE_COOKIE_PENDING_TAG)) {
63848 - fscache_stat(&fscache_n_store_radix_deletes);
63849 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
63850 xpage = radix_tree_delete(&cookie->stores, page->index);
63851 }
63852 spin_unlock(&cookie->stores_lock);
63853 @@ -177,7 +177,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
63854
63855 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
63856
63857 - fscache_stat(&fscache_n_attr_changed_calls);
63858 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
63859
63860 if (fscache_object_is_active(object)) {
63861 fscache_stat(&fscache_n_cop_attr_changed);
63862 @@ -204,11 +204,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
63863
63864 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
63865
63866 - fscache_stat(&fscache_n_attr_changed);
63867 + fscache_stat_unchecked(&fscache_n_attr_changed);
63868
63869 op = kzalloc(sizeof(*op), GFP_KERNEL);
63870 if (!op) {
63871 - fscache_stat(&fscache_n_attr_changed_nomem);
63872 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
63873 _leave(" = -ENOMEM");
63874 return -ENOMEM;
63875 }
63876 @@ -230,7 +230,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
63877 if (fscache_submit_exclusive_op(object, op) < 0)
63878 goto nobufs_dec;
63879 spin_unlock(&cookie->lock);
63880 - fscache_stat(&fscache_n_attr_changed_ok);
63881 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
63882 fscache_put_operation(op);
63883 _leave(" = 0");
63884 return 0;
63885 @@ -242,7 +242,7 @@ nobufs:
63886 kfree(op);
63887 if (wake_cookie)
63888 __fscache_wake_unused_cookie(cookie);
63889 - fscache_stat(&fscache_n_attr_changed_nobufs);
63890 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
63891 _leave(" = %d", -ENOBUFS);
63892 return -ENOBUFS;
63893 }
63894 @@ -281,7 +281,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
63895 /* allocate a retrieval operation and attempt to submit it */
63896 op = kzalloc(sizeof(*op), GFP_NOIO);
63897 if (!op) {
63898 - fscache_stat(&fscache_n_retrievals_nomem);
63899 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
63900 return NULL;
63901 }
63902
63903 @@ -311,12 +311,12 @@ int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
63904 return 0;
63905 }
63906
63907 - fscache_stat(&fscache_n_retrievals_wait);
63908 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
63909
63910 jif = jiffies;
63911 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
63912 TASK_INTERRUPTIBLE) != 0) {
63913 - fscache_stat(&fscache_n_retrievals_intr);
63914 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
63915 _leave(" = -ERESTARTSYS");
63916 return -ERESTARTSYS;
63917 }
63918 @@ -345,8 +345,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
63919 */
63920 int fscache_wait_for_operation_activation(struct fscache_object *object,
63921 struct fscache_operation *op,
63922 - atomic_t *stat_op_waits,
63923 - atomic_t *stat_object_dead,
63924 + atomic_unchecked_t *stat_op_waits,
63925 + atomic_unchecked_t *stat_object_dead,
63926 void (*do_cancel)(struct fscache_operation *))
63927 {
63928 int ret;
63929 @@ -356,7 +356,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
63930
63931 _debug(">>> WT");
63932 if (stat_op_waits)
63933 - fscache_stat(stat_op_waits);
63934 + fscache_stat_unchecked(stat_op_waits);
63935 if (wait_on_bit(&op->flags, FSCACHE_OP_WAITING,
63936 TASK_INTERRUPTIBLE) != 0) {
63937 ret = fscache_cancel_op(op, do_cancel);
63938 @@ -373,7 +373,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
63939 check_if_dead:
63940 if (op->state == FSCACHE_OP_ST_CANCELLED) {
63941 if (stat_object_dead)
63942 - fscache_stat(stat_object_dead);
63943 + fscache_stat_unchecked(stat_object_dead);
63944 _leave(" = -ENOBUFS [cancelled]");
63945 return -ENOBUFS;
63946 }
63947 @@ -381,7 +381,7 @@ check_if_dead:
63948 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->state);
63949 fscache_cancel_op(op, do_cancel);
63950 if (stat_object_dead)
63951 - fscache_stat(stat_object_dead);
63952 + fscache_stat_unchecked(stat_object_dead);
63953 return -ENOBUFS;
63954 }
63955 return 0;
63956 @@ -409,7 +409,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
63957
63958 _enter("%p,%p,,,", cookie, page);
63959
63960 - fscache_stat(&fscache_n_retrievals);
63961 + fscache_stat_unchecked(&fscache_n_retrievals);
63962
63963 if (hlist_empty(&cookie->backing_objects))
63964 goto nobufs;
63965 @@ -451,7 +451,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
63966 goto nobufs_unlock_dec;
63967 spin_unlock(&cookie->lock);
63968
63969 - fscache_stat(&fscache_n_retrieval_ops);
63970 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
63971
63972 /* pin the netfs read context in case we need to do the actual netfs
63973 * read because we've encountered a cache read failure */
63974 @@ -482,15 +482,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
63975
63976 error:
63977 if (ret == -ENOMEM)
63978 - fscache_stat(&fscache_n_retrievals_nomem);
63979 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
63980 else if (ret == -ERESTARTSYS)
63981 - fscache_stat(&fscache_n_retrievals_intr);
63982 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
63983 else if (ret == -ENODATA)
63984 - fscache_stat(&fscache_n_retrievals_nodata);
63985 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
63986 else if (ret < 0)
63987 - fscache_stat(&fscache_n_retrievals_nobufs);
63988 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
63989 else
63990 - fscache_stat(&fscache_n_retrievals_ok);
63991 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
63992
63993 fscache_put_retrieval(op);
63994 _leave(" = %d", ret);
63995 @@ -505,7 +505,7 @@ nobufs_unlock:
63996 __fscache_wake_unused_cookie(cookie);
63997 kfree(op);
63998 nobufs:
63999 - fscache_stat(&fscache_n_retrievals_nobufs);
64000 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
64001 _leave(" = -ENOBUFS");
64002 return -ENOBUFS;
64003 }
64004 @@ -544,7 +544,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
64005
64006 _enter("%p,,%d,,,", cookie, *nr_pages);
64007
64008 - fscache_stat(&fscache_n_retrievals);
64009 + fscache_stat_unchecked(&fscache_n_retrievals);
64010
64011 if (hlist_empty(&cookie->backing_objects))
64012 goto nobufs;
64013 @@ -582,7 +582,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
64014 goto nobufs_unlock_dec;
64015 spin_unlock(&cookie->lock);
64016
64017 - fscache_stat(&fscache_n_retrieval_ops);
64018 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
64019
64020 /* pin the netfs read context in case we need to do the actual netfs
64021 * read because we've encountered a cache read failure */
64022 @@ -613,15 +613,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
64023
64024 error:
64025 if (ret == -ENOMEM)
64026 - fscache_stat(&fscache_n_retrievals_nomem);
64027 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
64028 else if (ret == -ERESTARTSYS)
64029 - fscache_stat(&fscache_n_retrievals_intr);
64030 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
64031 else if (ret == -ENODATA)
64032 - fscache_stat(&fscache_n_retrievals_nodata);
64033 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
64034 else if (ret < 0)
64035 - fscache_stat(&fscache_n_retrievals_nobufs);
64036 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
64037 else
64038 - fscache_stat(&fscache_n_retrievals_ok);
64039 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
64040
64041 fscache_put_retrieval(op);
64042 _leave(" = %d", ret);
64043 @@ -636,7 +636,7 @@ nobufs_unlock:
64044 if (wake_cookie)
64045 __fscache_wake_unused_cookie(cookie);
64046 nobufs:
64047 - fscache_stat(&fscache_n_retrievals_nobufs);
64048 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
64049 _leave(" = -ENOBUFS");
64050 return -ENOBUFS;
64051 }
64052 @@ -661,7 +661,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
64053
64054 _enter("%p,%p,,,", cookie, page);
64055
64056 - fscache_stat(&fscache_n_allocs);
64057 + fscache_stat_unchecked(&fscache_n_allocs);
64058
64059 if (hlist_empty(&cookie->backing_objects))
64060 goto nobufs;
64061 @@ -695,7 +695,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
64062 goto nobufs_unlock_dec;
64063 spin_unlock(&cookie->lock);
64064
64065 - fscache_stat(&fscache_n_alloc_ops);
64066 + fscache_stat_unchecked(&fscache_n_alloc_ops);
64067
64068 ret = fscache_wait_for_operation_activation(
64069 object, &op->op,
64070 @@ -712,11 +712,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
64071
64072 error:
64073 if (ret == -ERESTARTSYS)
64074 - fscache_stat(&fscache_n_allocs_intr);
64075 + fscache_stat_unchecked(&fscache_n_allocs_intr);
64076 else if (ret < 0)
64077 - fscache_stat(&fscache_n_allocs_nobufs);
64078 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
64079 else
64080 - fscache_stat(&fscache_n_allocs_ok);
64081 + fscache_stat_unchecked(&fscache_n_allocs_ok);
64082
64083 fscache_put_retrieval(op);
64084 _leave(" = %d", ret);
64085 @@ -730,7 +730,7 @@ nobufs_unlock:
64086 if (wake_cookie)
64087 __fscache_wake_unused_cookie(cookie);
64088 nobufs:
64089 - fscache_stat(&fscache_n_allocs_nobufs);
64090 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
64091 _leave(" = -ENOBUFS");
64092 return -ENOBUFS;
64093 }
64094 @@ -806,7 +806,7 @@ static void fscache_write_op(struct fscache_operation *_op)
64095
64096 spin_lock(&cookie->stores_lock);
64097
64098 - fscache_stat(&fscache_n_store_calls);
64099 + fscache_stat_unchecked(&fscache_n_store_calls);
64100
64101 /* find a page to store */
64102 page = NULL;
64103 @@ -817,7 +817,7 @@ static void fscache_write_op(struct fscache_operation *_op)
64104 page = results[0];
64105 _debug("gang %d [%lx]", n, page->index);
64106 if (page->index > op->store_limit) {
64107 - fscache_stat(&fscache_n_store_pages_over_limit);
64108 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
64109 goto superseded;
64110 }
64111
64112 @@ -829,7 +829,7 @@ static void fscache_write_op(struct fscache_operation *_op)
64113 spin_unlock(&cookie->stores_lock);
64114 spin_unlock(&object->lock);
64115
64116 - fscache_stat(&fscache_n_store_pages);
64117 + fscache_stat_unchecked(&fscache_n_store_pages);
64118 fscache_stat(&fscache_n_cop_write_page);
64119 ret = object->cache->ops->write_page(op, page);
64120 fscache_stat_d(&fscache_n_cop_write_page);
64121 @@ -933,7 +933,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
64122 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
64123 ASSERT(PageFsCache(page));
64124
64125 - fscache_stat(&fscache_n_stores);
64126 + fscache_stat_unchecked(&fscache_n_stores);
64127
64128 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
64129 _leave(" = -ENOBUFS [invalidating]");
64130 @@ -992,7 +992,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
64131 spin_unlock(&cookie->stores_lock);
64132 spin_unlock(&object->lock);
64133
64134 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
64135 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
64136 op->store_limit = object->store_limit;
64137
64138 __fscache_use_cookie(cookie);
64139 @@ -1001,8 +1001,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
64140
64141 spin_unlock(&cookie->lock);
64142 radix_tree_preload_end();
64143 - fscache_stat(&fscache_n_store_ops);
64144 - fscache_stat(&fscache_n_stores_ok);
64145 + fscache_stat_unchecked(&fscache_n_store_ops);
64146 + fscache_stat_unchecked(&fscache_n_stores_ok);
64147
64148 /* the work queue now carries its own ref on the object */
64149 fscache_put_operation(&op->op);
64150 @@ -1010,14 +1010,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
64151 return 0;
64152
64153 already_queued:
64154 - fscache_stat(&fscache_n_stores_again);
64155 + fscache_stat_unchecked(&fscache_n_stores_again);
64156 already_pending:
64157 spin_unlock(&cookie->stores_lock);
64158 spin_unlock(&object->lock);
64159 spin_unlock(&cookie->lock);
64160 radix_tree_preload_end();
64161 kfree(op);
64162 - fscache_stat(&fscache_n_stores_ok);
64163 + fscache_stat_unchecked(&fscache_n_stores_ok);
64164 _leave(" = 0");
64165 return 0;
64166
64167 @@ -1039,14 +1039,14 @@ nobufs:
64168 kfree(op);
64169 if (wake_cookie)
64170 __fscache_wake_unused_cookie(cookie);
64171 - fscache_stat(&fscache_n_stores_nobufs);
64172 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
64173 _leave(" = -ENOBUFS");
64174 return -ENOBUFS;
64175
64176 nomem_free:
64177 kfree(op);
64178 nomem:
64179 - fscache_stat(&fscache_n_stores_oom);
64180 + fscache_stat_unchecked(&fscache_n_stores_oom);
64181 _leave(" = -ENOMEM");
64182 return -ENOMEM;
64183 }
64184 @@ -1064,7 +1064,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
64185 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
64186 ASSERTCMP(page, !=, NULL);
64187
64188 - fscache_stat(&fscache_n_uncaches);
64189 + fscache_stat_unchecked(&fscache_n_uncaches);
64190
64191 /* cache withdrawal may beat us to it */
64192 if (!PageFsCache(page))
64193 @@ -1115,7 +1115,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
64194 struct fscache_cookie *cookie = op->op.object->cookie;
64195
64196 #ifdef CONFIG_FSCACHE_STATS
64197 - atomic_inc(&fscache_n_marks);
64198 + atomic_inc_unchecked(&fscache_n_marks);
64199 #endif
64200
64201 _debug("- mark %p{%lx}", page, page->index);
64202 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
64203 index 40d13c7..ddf52b9 100644
64204 --- a/fs/fscache/stats.c
64205 +++ b/fs/fscache/stats.c
64206 @@ -18,99 +18,99 @@
64207 /*
64208 * operation counters
64209 */
64210 -atomic_t fscache_n_op_pend;
64211 -atomic_t fscache_n_op_run;
64212 -atomic_t fscache_n_op_enqueue;
64213 -atomic_t fscache_n_op_requeue;
64214 -atomic_t fscache_n_op_deferred_release;
64215 -atomic_t fscache_n_op_release;
64216 -atomic_t fscache_n_op_gc;
64217 -atomic_t fscache_n_op_cancelled;
64218 -atomic_t fscache_n_op_rejected;
64219 +atomic_unchecked_t fscache_n_op_pend;
64220 +atomic_unchecked_t fscache_n_op_run;
64221 +atomic_unchecked_t fscache_n_op_enqueue;
64222 +atomic_unchecked_t fscache_n_op_requeue;
64223 +atomic_unchecked_t fscache_n_op_deferred_release;
64224 +atomic_unchecked_t fscache_n_op_release;
64225 +atomic_unchecked_t fscache_n_op_gc;
64226 +atomic_unchecked_t fscache_n_op_cancelled;
64227 +atomic_unchecked_t fscache_n_op_rejected;
64228
64229 -atomic_t fscache_n_attr_changed;
64230 -atomic_t fscache_n_attr_changed_ok;
64231 -atomic_t fscache_n_attr_changed_nobufs;
64232 -atomic_t fscache_n_attr_changed_nomem;
64233 -atomic_t fscache_n_attr_changed_calls;
64234 +atomic_unchecked_t fscache_n_attr_changed;
64235 +atomic_unchecked_t fscache_n_attr_changed_ok;
64236 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
64237 +atomic_unchecked_t fscache_n_attr_changed_nomem;
64238 +atomic_unchecked_t fscache_n_attr_changed_calls;
64239
64240 -atomic_t fscache_n_allocs;
64241 -atomic_t fscache_n_allocs_ok;
64242 -atomic_t fscache_n_allocs_wait;
64243 -atomic_t fscache_n_allocs_nobufs;
64244 -atomic_t fscache_n_allocs_intr;
64245 -atomic_t fscache_n_allocs_object_dead;
64246 -atomic_t fscache_n_alloc_ops;
64247 -atomic_t fscache_n_alloc_op_waits;
64248 +atomic_unchecked_t fscache_n_allocs;
64249 +atomic_unchecked_t fscache_n_allocs_ok;
64250 +atomic_unchecked_t fscache_n_allocs_wait;
64251 +atomic_unchecked_t fscache_n_allocs_nobufs;
64252 +atomic_unchecked_t fscache_n_allocs_intr;
64253 +atomic_unchecked_t fscache_n_allocs_object_dead;
64254 +atomic_unchecked_t fscache_n_alloc_ops;
64255 +atomic_unchecked_t fscache_n_alloc_op_waits;
64256
64257 -atomic_t fscache_n_retrievals;
64258 -atomic_t fscache_n_retrievals_ok;
64259 -atomic_t fscache_n_retrievals_wait;
64260 -atomic_t fscache_n_retrievals_nodata;
64261 -atomic_t fscache_n_retrievals_nobufs;
64262 -atomic_t fscache_n_retrievals_intr;
64263 -atomic_t fscache_n_retrievals_nomem;
64264 -atomic_t fscache_n_retrievals_object_dead;
64265 -atomic_t fscache_n_retrieval_ops;
64266 -atomic_t fscache_n_retrieval_op_waits;
64267 +atomic_unchecked_t fscache_n_retrievals;
64268 +atomic_unchecked_t fscache_n_retrievals_ok;
64269 +atomic_unchecked_t fscache_n_retrievals_wait;
64270 +atomic_unchecked_t fscache_n_retrievals_nodata;
64271 +atomic_unchecked_t fscache_n_retrievals_nobufs;
64272 +atomic_unchecked_t fscache_n_retrievals_intr;
64273 +atomic_unchecked_t fscache_n_retrievals_nomem;
64274 +atomic_unchecked_t fscache_n_retrievals_object_dead;
64275 +atomic_unchecked_t fscache_n_retrieval_ops;
64276 +atomic_unchecked_t fscache_n_retrieval_op_waits;
64277
64278 -atomic_t fscache_n_stores;
64279 -atomic_t fscache_n_stores_ok;
64280 -atomic_t fscache_n_stores_again;
64281 -atomic_t fscache_n_stores_nobufs;
64282 -atomic_t fscache_n_stores_oom;
64283 -atomic_t fscache_n_store_ops;
64284 -atomic_t fscache_n_store_calls;
64285 -atomic_t fscache_n_store_pages;
64286 -atomic_t fscache_n_store_radix_deletes;
64287 -atomic_t fscache_n_store_pages_over_limit;
64288 +atomic_unchecked_t fscache_n_stores;
64289 +atomic_unchecked_t fscache_n_stores_ok;
64290 +atomic_unchecked_t fscache_n_stores_again;
64291 +atomic_unchecked_t fscache_n_stores_nobufs;
64292 +atomic_unchecked_t fscache_n_stores_oom;
64293 +atomic_unchecked_t fscache_n_store_ops;
64294 +atomic_unchecked_t fscache_n_store_calls;
64295 +atomic_unchecked_t fscache_n_store_pages;
64296 +atomic_unchecked_t fscache_n_store_radix_deletes;
64297 +atomic_unchecked_t fscache_n_store_pages_over_limit;
64298
64299 -atomic_t fscache_n_store_vmscan_not_storing;
64300 -atomic_t fscache_n_store_vmscan_gone;
64301 -atomic_t fscache_n_store_vmscan_busy;
64302 -atomic_t fscache_n_store_vmscan_cancelled;
64303 -atomic_t fscache_n_store_vmscan_wait;
64304 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
64305 +atomic_unchecked_t fscache_n_store_vmscan_gone;
64306 +atomic_unchecked_t fscache_n_store_vmscan_busy;
64307 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
64308 +atomic_unchecked_t fscache_n_store_vmscan_wait;
64309
64310 -atomic_t fscache_n_marks;
64311 -atomic_t fscache_n_uncaches;
64312 +atomic_unchecked_t fscache_n_marks;
64313 +atomic_unchecked_t fscache_n_uncaches;
64314
64315 -atomic_t fscache_n_acquires;
64316 -atomic_t fscache_n_acquires_null;
64317 -atomic_t fscache_n_acquires_no_cache;
64318 -atomic_t fscache_n_acquires_ok;
64319 -atomic_t fscache_n_acquires_nobufs;
64320 -atomic_t fscache_n_acquires_oom;
64321 +atomic_unchecked_t fscache_n_acquires;
64322 +atomic_unchecked_t fscache_n_acquires_null;
64323 +atomic_unchecked_t fscache_n_acquires_no_cache;
64324 +atomic_unchecked_t fscache_n_acquires_ok;
64325 +atomic_unchecked_t fscache_n_acquires_nobufs;
64326 +atomic_unchecked_t fscache_n_acquires_oom;
64327
64328 -atomic_t fscache_n_invalidates;
64329 -atomic_t fscache_n_invalidates_run;
64330 +atomic_unchecked_t fscache_n_invalidates;
64331 +atomic_unchecked_t fscache_n_invalidates_run;
64332
64333 -atomic_t fscache_n_updates;
64334 -atomic_t fscache_n_updates_null;
64335 -atomic_t fscache_n_updates_run;
64336 +atomic_unchecked_t fscache_n_updates;
64337 +atomic_unchecked_t fscache_n_updates_null;
64338 +atomic_unchecked_t fscache_n_updates_run;
64339
64340 -atomic_t fscache_n_relinquishes;
64341 -atomic_t fscache_n_relinquishes_null;
64342 -atomic_t fscache_n_relinquishes_waitcrt;
64343 -atomic_t fscache_n_relinquishes_retire;
64344 +atomic_unchecked_t fscache_n_relinquishes;
64345 +atomic_unchecked_t fscache_n_relinquishes_null;
64346 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
64347 +atomic_unchecked_t fscache_n_relinquishes_retire;
64348
64349 -atomic_t fscache_n_cookie_index;
64350 -atomic_t fscache_n_cookie_data;
64351 -atomic_t fscache_n_cookie_special;
64352 +atomic_unchecked_t fscache_n_cookie_index;
64353 +atomic_unchecked_t fscache_n_cookie_data;
64354 +atomic_unchecked_t fscache_n_cookie_special;
64355
64356 -atomic_t fscache_n_object_alloc;
64357 -atomic_t fscache_n_object_no_alloc;
64358 -atomic_t fscache_n_object_lookups;
64359 -atomic_t fscache_n_object_lookups_negative;
64360 -atomic_t fscache_n_object_lookups_positive;
64361 -atomic_t fscache_n_object_lookups_timed_out;
64362 -atomic_t fscache_n_object_created;
64363 -atomic_t fscache_n_object_avail;
64364 -atomic_t fscache_n_object_dead;
64365 +atomic_unchecked_t fscache_n_object_alloc;
64366 +atomic_unchecked_t fscache_n_object_no_alloc;
64367 +atomic_unchecked_t fscache_n_object_lookups;
64368 +atomic_unchecked_t fscache_n_object_lookups_negative;
64369 +atomic_unchecked_t fscache_n_object_lookups_positive;
64370 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
64371 +atomic_unchecked_t fscache_n_object_created;
64372 +atomic_unchecked_t fscache_n_object_avail;
64373 +atomic_unchecked_t fscache_n_object_dead;
64374
64375 -atomic_t fscache_n_checkaux_none;
64376 -atomic_t fscache_n_checkaux_okay;
64377 -atomic_t fscache_n_checkaux_update;
64378 -atomic_t fscache_n_checkaux_obsolete;
64379 +atomic_unchecked_t fscache_n_checkaux_none;
64380 +atomic_unchecked_t fscache_n_checkaux_okay;
64381 +atomic_unchecked_t fscache_n_checkaux_update;
64382 +atomic_unchecked_t fscache_n_checkaux_obsolete;
64383
64384 atomic_t fscache_n_cop_alloc_object;
64385 atomic_t fscache_n_cop_lookup_object;
64386 @@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
64387 seq_puts(m, "FS-Cache statistics\n");
64388
64389 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
64390 - atomic_read(&fscache_n_cookie_index),
64391 - atomic_read(&fscache_n_cookie_data),
64392 - atomic_read(&fscache_n_cookie_special));
64393 + atomic_read_unchecked(&fscache_n_cookie_index),
64394 + atomic_read_unchecked(&fscache_n_cookie_data),
64395 + atomic_read_unchecked(&fscache_n_cookie_special));
64396
64397 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
64398 - atomic_read(&fscache_n_object_alloc),
64399 - atomic_read(&fscache_n_object_no_alloc),
64400 - atomic_read(&fscache_n_object_avail),
64401 - atomic_read(&fscache_n_object_dead));
64402 + atomic_read_unchecked(&fscache_n_object_alloc),
64403 + atomic_read_unchecked(&fscache_n_object_no_alloc),
64404 + atomic_read_unchecked(&fscache_n_object_avail),
64405 + atomic_read_unchecked(&fscache_n_object_dead));
64406 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
64407 - atomic_read(&fscache_n_checkaux_none),
64408 - atomic_read(&fscache_n_checkaux_okay),
64409 - atomic_read(&fscache_n_checkaux_update),
64410 - atomic_read(&fscache_n_checkaux_obsolete));
64411 + atomic_read_unchecked(&fscache_n_checkaux_none),
64412 + atomic_read_unchecked(&fscache_n_checkaux_okay),
64413 + atomic_read_unchecked(&fscache_n_checkaux_update),
64414 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
64415
64416 seq_printf(m, "Pages : mrk=%u unc=%u\n",
64417 - atomic_read(&fscache_n_marks),
64418 - atomic_read(&fscache_n_uncaches));
64419 + atomic_read_unchecked(&fscache_n_marks),
64420 + atomic_read_unchecked(&fscache_n_uncaches));
64421
64422 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
64423 " oom=%u\n",
64424 - atomic_read(&fscache_n_acquires),
64425 - atomic_read(&fscache_n_acquires_null),
64426 - atomic_read(&fscache_n_acquires_no_cache),
64427 - atomic_read(&fscache_n_acquires_ok),
64428 - atomic_read(&fscache_n_acquires_nobufs),
64429 - atomic_read(&fscache_n_acquires_oom));
64430 + atomic_read_unchecked(&fscache_n_acquires),
64431 + atomic_read_unchecked(&fscache_n_acquires_null),
64432 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
64433 + atomic_read_unchecked(&fscache_n_acquires_ok),
64434 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
64435 + atomic_read_unchecked(&fscache_n_acquires_oom));
64436
64437 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
64438 - atomic_read(&fscache_n_object_lookups),
64439 - atomic_read(&fscache_n_object_lookups_negative),
64440 - atomic_read(&fscache_n_object_lookups_positive),
64441 - atomic_read(&fscache_n_object_created),
64442 - atomic_read(&fscache_n_object_lookups_timed_out));
64443 + atomic_read_unchecked(&fscache_n_object_lookups),
64444 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
64445 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
64446 + atomic_read_unchecked(&fscache_n_object_created),
64447 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
64448
64449 seq_printf(m, "Invals : n=%u run=%u\n",
64450 - atomic_read(&fscache_n_invalidates),
64451 - atomic_read(&fscache_n_invalidates_run));
64452 + atomic_read_unchecked(&fscache_n_invalidates),
64453 + atomic_read_unchecked(&fscache_n_invalidates_run));
64454
64455 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
64456 - atomic_read(&fscache_n_updates),
64457 - atomic_read(&fscache_n_updates_null),
64458 - atomic_read(&fscache_n_updates_run));
64459 + atomic_read_unchecked(&fscache_n_updates),
64460 + atomic_read_unchecked(&fscache_n_updates_null),
64461 + atomic_read_unchecked(&fscache_n_updates_run));
64462
64463 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
64464 - atomic_read(&fscache_n_relinquishes),
64465 - atomic_read(&fscache_n_relinquishes_null),
64466 - atomic_read(&fscache_n_relinquishes_waitcrt),
64467 - atomic_read(&fscache_n_relinquishes_retire));
64468 + atomic_read_unchecked(&fscache_n_relinquishes),
64469 + atomic_read_unchecked(&fscache_n_relinquishes_null),
64470 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
64471 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
64472
64473 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
64474 - atomic_read(&fscache_n_attr_changed),
64475 - atomic_read(&fscache_n_attr_changed_ok),
64476 - atomic_read(&fscache_n_attr_changed_nobufs),
64477 - atomic_read(&fscache_n_attr_changed_nomem),
64478 - atomic_read(&fscache_n_attr_changed_calls));
64479 + atomic_read_unchecked(&fscache_n_attr_changed),
64480 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
64481 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
64482 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
64483 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
64484
64485 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
64486 - atomic_read(&fscache_n_allocs),
64487 - atomic_read(&fscache_n_allocs_ok),
64488 - atomic_read(&fscache_n_allocs_wait),
64489 - atomic_read(&fscache_n_allocs_nobufs),
64490 - atomic_read(&fscache_n_allocs_intr));
64491 + atomic_read_unchecked(&fscache_n_allocs),
64492 + atomic_read_unchecked(&fscache_n_allocs_ok),
64493 + atomic_read_unchecked(&fscache_n_allocs_wait),
64494 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
64495 + atomic_read_unchecked(&fscache_n_allocs_intr));
64496 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
64497 - atomic_read(&fscache_n_alloc_ops),
64498 - atomic_read(&fscache_n_alloc_op_waits),
64499 - atomic_read(&fscache_n_allocs_object_dead));
64500 + atomic_read_unchecked(&fscache_n_alloc_ops),
64501 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
64502 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
64503
64504 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
64505 " int=%u oom=%u\n",
64506 - atomic_read(&fscache_n_retrievals),
64507 - atomic_read(&fscache_n_retrievals_ok),
64508 - atomic_read(&fscache_n_retrievals_wait),
64509 - atomic_read(&fscache_n_retrievals_nodata),
64510 - atomic_read(&fscache_n_retrievals_nobufs),
64511 - atomic_read(&fscache_n_retrievals_intr),
64512 - atomic_read(&fscache_n_retrievals_nomem));
64513 + atomic_read_unchecked(&fscache_n_retrievals),
64514 + atomic_read_unchecked(&fscache_n_retrievals_ok),
64515 + atomic_read_unchecked(&fscache_n_retrievals_wait),
64516 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
64517 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
64518 + atomic_read_unchecked(&fscache_n_retrievals_intr),
64519 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
64520 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
64521 - atomic_read(&fscache_n_retrieval_ops),
64522 - atomic_read(&fscache_n_retrieval_op_waits),
64523 - atomic_read(&fscache_n_retrievals_object_dead));
64524 + atomic_read_unchecked(&fscache_n_retrieval_ops),
64525 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
64526 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
64527
64528 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
64529 - atomic_read(&fscache_n_stores),
64530 - atomic_read(&fscache_n_stores_ok),
64531 - atomic_read(&fscache_n_stores_again),
64532 - atomic_read(&fscache_n_stores_nobufs),
64533 - atomic_read(&fscache_n_stores_oom));
64534 + atomic_read_unchecked(&fscache_n_stores),
64535 + atomic_read_unchecked(&fscache_n_stores_ok),
64536 + atomic_read_unchecked(&fscache_n_stores_again),
64537 + atomic_read_unchecked(&fscache_n_stores_nobufs),
64538 + atomic_read_unchecked(&fscache_n_stores_oom));
64539 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
64540 - atomic_read(&fscache_n_store_ops),
64541 - atomic_read(&fscache_n_store_calls),
64542 - atomic_read(&fscache_n_store_pages),
64543 - atomic_read(&fscache_n_store_radix_deletes),
64544 - atomic_read(&fscache_n_store_pages_over_limit));
64545 + atomic_read_unchecked(&fscache_n_store_ops),
64546 + atomic_read_unchecked(&fscache_n_store_calls),
64547 + atomic_read_unchecked(&fscache_n_store_pages),
64548 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
64549 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
64550
64551 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
64552 - atomic_read(&fscache_n_store_vmscan_not_storing),
64553 - atomic_read(&fscache_n_store_vmscan_gone),
64554 - atomic_read(&fscache_n_store_vmscan_busy),
64555 - atomic_read(&fscache_n_store_vmscan_cancelled),
64556 - atomic_read(&fscache_n_store_vmscan_wait));
64557 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
64558 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
64559 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
64560 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
64561 + atomic_read_unchecked(&fscache_n_store_vmscan_wait));
64562
64563 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
64564 - atomic_read(&fscache_n_op_pend),
64565 - atomic_read(&fscache_n_op_run),
64566 - atomic_read(&fscache_n_op_enqueue),
64567 - atomic_read(&fscache_n_op_cancelled),
64568 - atomic_read(&fscache_n_op_rejected));
64569 + atomic_read_unchecked(&fscache_n_op_pend),
64570 + atomic_read_unchecked(&fscache_n_op_run),
64571 + atomic_read_unchecked(&fscache_n_op_enqueue),
64572 + atomic_read_unchecked(&fscache_n_op_cancelled),
64573 + atomic_read_unchecked(&fscache_n_op_rejected));
64574 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
64575 - atomic_read(&fscache_n_op_deferred_release),
64576 - atomic_read(&fscache_n_op_release),
64577 - atomic_read(&fscache_n_op_gc));
64578 + atomic_read_unchecked(&fscache_n_op_deferred_release),
64579 + atomic_read_unchecked(&fscache_n_op_release),
64580 + atomic_read_unchecked(&fscache_n_op_gc));
64581
64582 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
64583 atomic_read(&fscache_n_cop_alloc_object),
64584 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
64585 index 966ace8..030a03a 100644
64586 --- a/fs/fuse/cuse.c
64587 +++ b/fs/fuse/cuse.c
64588 @@ -611,10 +611,12 @@ static int __init cuse_init(void)
64589 INIT_LIST_HEAD(&cuse_conntbl[i]);
64590
64591 /* inherit and extend fuse_dev_operations */
64592 - cuse_channel_fops = fuse_dev_operations;
64593 - cuse_channel_fops.owner = THIS_MODULE;
64594 - cuse_channel_fops.open = cuse_channel_open;
64595 - cuse_channel_fops.release = cuse_channel_release;
64596 + pax_open_kernel();
64597 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
64598 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
64599 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
64600 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
64601 + pax_close_kernel();
64602
64603 cuse_class = class_create(THIS_MODULE, "cuse");
64604 if (IS_ERR(cuse_class))
64605 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
64606 index ca88731..8e9c55d 100644
64607 --- a/fs/fuse/dev.c
64608 +++ b/fs/fuse/dev.c
64609 @@ -1318,7 +1318,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
64610 ret = 0;
64611 pipe_lock(pipe);
64612
64613 - if (!pipe->readers) {
64614 + if (!atomic_read(&pipe->readers)) {
64615 send_sig(SIGPIPE, current, 0);
64616 if (!ret)
64617 ret = -EPIPE;
64618 @@ -1347,7 +1347,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
64619 page_nr++;
64620 ret += buf->len;
64621
64622 - if (pipe->files)
64623 + if (atomic_read(&pipe->files))
64624 do_wakeup = 1;
64625 }
64626
64627 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
64628 index de1d84a..fd69c0c 100644
64629 --- a/fs/fuse/dir.c
64630 +++ b/fs/fuse/dir.c
64631 @@ -1479,7 +1479,7 @@ static char *read_link(struct dentry *dentry)
64632 return link;
64633 }
64634
64635 -static void free_link(char *link)
64636 +static void free_link(const char *link)
64637 {
64638 if (!IS_ERR(link))
64639 free_page((unsigned long) link);
64640 diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
64641 index fd62cae..3494dfa 100644
64642 --- a/fs/hostfs/hostfs_kern.c
64643 +++ b/fs/hostfs/hostfs_kern.c
64644 @@ -908,7 +908,7 @@ static void *hostfs_follow_link(struct dentry *dentry, struct nameidata *nd)
64645
64646 static void hostfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
64647 {
64648 - char *s = nd_get_link(nd);
64649 + const char *s = nd_get_link(nd);
64650 if (!IS_ERR(s))
64651 __putname(s);
64652 }
64653 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
64654 index 1e2872b..7aea000 100644
64655 --- a/fs/hugetlbfs/inode.c
64656 +++ b/fs/hugetlbfs/inode.c
64657 @@ -154,6 +154,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
64658 struct mm_struct *mm = current->mm;
64659 struct vm_area_struct *vma;
64660 struct hstate *h = hstate_file(file);
64661 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
64662 struct vm_unmapped_area_info info;
64663
64664 if (len & ~huge_page_mask(h))
64665 @@ -167,17 +168,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
64666 return addr;
64667 }
64668
64669 +#ifdef CONFIG_PAX_RANDMMAP
64670 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
64671 +#endif
64672 +
64673 if (addr) {
64674 addr = ALIGN(addr, huge_page_size(h));
64675 vma = find_vma(mm, addr);
64676 - if (TASK_SIZE - len >= addr &&
64677 - (!vma || addr + len <= vma->vm_start))
64678 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
64679 return addr;
64680 }
64681
64682 info.flags = 0;
64683 info.length = len;
64684 info.low_limit = TASK_UNMAPPED_BASE;
64685 +
64686 +#ifdef CONFIG_PAX_RANDMMAP
64687 + if (mm->pax_flags & MF_PAX_RANDMMAP)
64688 + info.low_limit += mm->delta_mmap;
64689 +#endif
64690 +
64691 info.high_limit = TASK_SIZE;
64692 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
64693 info.align_offset = 0;
64694 @@ -919,7 +929,7 @@ static struct file_system_type hugetlbfs_fs_type = {
64695 };
64696 MODULE_ALIAS_FS("hugetlbfs");
64697
64698 -static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
64699 +struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
64700
64701 static int can_do_hugetlb_shm(void)
64702 {
64703 diff --git a/fs/inode.c b/fs/inode.c
64704 index 26753ba..d19eb34 100644
64705 --- a/fs/inode.c
64706 +++ b/fs/inode.c
64707 @@ -840,16 +840,20 @@ unsigned int get_next_ino(void)
64708 unsigned int *p = &get_cpu_var(last_ino);
64709 unsigned int res = *p;
64710
64711 +start:
64712 +
64713 #ifdef CONFIG_SMP
64714 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
64715 - static atomic_t shared_last_ino;
64716 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
64717 + static atomic_unchecked_t shared_last_ino;
64718 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
64719
64720 res = next - LAST_INO_BATCH;
64721 }
64722 #endif
64723
64724 - *p = ++res;
64725 + if (unlikely(!++res))
64726 + goto start; /* never zero */
64727 + *p = res;
64728 put_cpu_var(last_ino);
64729 return res;
64730 }
64731 diff --git a/fs/isofs/rock.c b/fs/isofs/rock.c
64732 index f488bba..bb63254 100644
64733 --- a/fs/isofs/rock.c
64734 +++ b/fs/isofs/rock.c
64735 @@ -30,6 +30,7 @@ struct rock_state {
64736 int cont_size;
64737 int cont_extent;
64738 int cont_offset;
64739 + int cont_loops;
64740 struct inode *inode;
64741 };
64742
64743 @@ -73,6 +74,9 @@ static void init_rock_state(struct rock_state *rs, struct inode *inode)
64744 rs->inode = inode;
64745 }
64746
64747 +/* Maximum number of Rock Ridge continuation entries */
64748 +#define RR_MAX_CE_ENTRIES 32
64749 +
64750 /*
64751 * Returns 0 if the caller should continue scanning, 1 if the scan must end
64752 * and -ve on error.
64753 @@ -105,6 +109,8 @@ static int rock_continue(struct rock_state *rs)
64754 goto out;
64755 }
64756 ret = -EIO;
64757 + if (++rs->cont_loops >= RR_MAX_CE_ENTRIES)
64758 + goto out;
64759 bh = sb_bread(rs->inode->i_sb, rs->cont_extent);
64760 if (bh) {
64761 memcpy(rs->buffer, bh->b_data + rs->cont_offset,
64762 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
64763 index 4a6cf28..d3a29d3 100644
64764 --- a/fs/jffs2/erase.c
64765 +++ b/fs/jffs2/erase.c
64766 @@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
64767 struct jffs2_unknown_node marker = {
64768 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
64769 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
64770 - .totlen = cpu_to_je32(c->cleanmarker_size)
64771 + .totlen = cpu_to_je32(c->cleanmarker_size),
64772 + .hdr_crc = cpu_to_je32(0)
64773 };
64774
64775 jffs2_prealloc_raw_node_refs(c, jeb, 1);
64776 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
64777 index 09ed551..45684f8 100644
64778 --- a/fs/jffs2/wbuf.c
64779 +++ b/fs/jffs2/wbuf.c
64780 @@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
64781 {
64782 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
64783 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
64784 - .totlen = constant_cpu_to_je32(8)
64785 + .totlen = constant_cpu_to_je32(8),
64786 + .hdr_crc = constant_cpu_to_je32(0)
64787 };
64788
64789 /*
64790 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
64791 index adf8cb0..bb935fa 100644
64792 --- a/fs/jfs/super.c
64793 +++ b/fs/jfs/super.c
64794 @@ -893,7 +893,7 @@ static int __init init_jfs_fs(void)
64795
64796 jfs_inode_cachep =
64797 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
64798 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
64799 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
64800 init_once);
64801 if (jfs_inode_cachep == NULL)
64802 return -ENOMEM;
64803 diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
64804 index a693f5b..82276a1 100644
64805 --- a/fs/kernfs/dir.c
64806 +++ b/fs/kernfs/dir.c
64807 @@ -182,7 +182,7 @@ struct kernfs_node *kernfs_get_parent(struct kernfs_node *kn)
64808 *
64809 * Returns 31 bit hash of ns + name (so it fits in an off_t )
64810 */
64811 -static unsigned int kernfs_name_hash(const char *name, const void *ns)
64812 +static unsigned int kernfs_name_hash(const unsigned char *name, const void *ns)
64813 {
64814 unsigned long hash = init_name_hash();
64815 unsigned int len = strlen(name);
64816 diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c
64817 index 4429d6d..9831f52 100644
64818 --- a/fs/kernfs/file.c
64819 +++ b/fs/kernfs/file.c
64820 @@ -34,7 +34,7 @@ static DEFINE_MUTEX(kernfs_open_file_mutex);
64821
64822 struct kernfs_open_node {
64823 atomic_t refcnt;
64824 - atomic_t event;
64825 + atomic_unchecked_t event;
64826 wait_queue_head_t poll;
64827 struct list_head files; /* goes through kernfs_open_file.list */
64828 };
64829 @@ -163,7 +163,7 @@ static int kernfs_seq_show(struct seq_file *sf, void *v)
64830 {
64831 struct kernfs_open_file *of = sf->private;
64832
64833 - of->event = atomic_read(&of->kn->attr.open->event);
64834 + of->event = atomic_read_unchecked(&of->kn->attr.open->event);
64835
64836 return of->kn->attr.ops->seq_show(sf, v);
64837 }
64838 @@ -375,12 +375,12 @@ static int kernfs_vma_page_mkwrite(struct vm_area_struct *vma,
64839 return ret;
64840 }
64841
64842 -static int kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
64843 - void *buf, int len, int write)
64844 +static ssize_t kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
64845 + void *buf, size_t len, int write)
64846 {
64847 struct file *file = vma->vm_file;
64848 struct kernfs_open_file *of = kernfs_of(file);
64849 - int ret;
64850 + ssize_t ret;
64851
64852 if (!of->vm_ops)
64853 return -EINVAL;
64854 @@ -581,7 +581,7 @@ static int kernfs_get_open_node(struct kernfs_node *kn,
64855 return -ENOMEM;
64856
64857 atomic_set(&new_on->refcnt, 0);
64858 - atomic_set(&new_on->event, 1);
64859 + atomic_set_unchecked(&new_on->event, 1);
64860 init_waitqueue_head(&new_on->poll);
64861 INIT_LIST_HEAD(&new_on->files);
64862 goto retry;
64863 @@ -787,7 +787,7 @@ static unsigned int kernfs_fop_poll(struct file *filp, poll_table *wait)
64864
64865 kernfs_put_active(kn);
64866
64867 - if (of->event != atomic_read(&on->event))
64868 + if (of->event != atomic_read_unchecked(&on->event))
64869 goto trigger;
64870
64871 return DEFAULT_POLLMASK;
64872 @@ -818,7 +818,7 @@ repeat:
64873
64874 on = kn->attr.open;
64875 if (on) {
64876 - atomic_inc(&on->event);
64877 + atomic_inc_unchecked(&on->event);
64878 wake_up_interruptible(&on->poll);
64879 }
64880
64881 diff --git a/fs/kernfs/symlink.c b/fs/kernfs/symlink.c
64882 index 8a19889..4c3069a 100644
64883 --- a/fs/kernfs/symlink.c
64884 +++ b/fs/kernfs/symlink.c
64885 @@ -128,7 +128,7 @@ static void *kernfs_iop_follow_link(struct dentry *dentry, struct nameidata *nd)
64886 static void kernfs_iop_put_link(struct dentry *dentry, struct nameidata *nd,
64887 void *cookie)
64888 {
64889 - char *page = nd_get_link(nd);
64890 + const char *page = nd_get_link(nd);
64891 if (!IS_ERR(page))
64892 free_page((unsigned long)page);
64893 }
64894 diff --git a/fs/libfs.c b/fs/libfs.c
64895 index 88e3e00..979c262 100644
64896 --- a/fs/libfs.c
64897 +++ b/fs/libfs.c
64898 @@ -160,6 +160,9 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
64899
64900 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
64901 struct dentry *next = list_entry(p, struct dentry, d_u.d_child);
64902 + char d_name[sizeof(next->d_iname)];
64903 + const unsigned char *name;
64904 +
64905 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
64906 if (!simple_positive(next)) {
64907 spin_unlock(&next->d_lock);
64908 @@ -168,7 +171,12 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
64909
64910 spin_unlock(&next->d_lock);
64911 spin_unlock(&dentry->d_lock);
64912 - if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
64913 + name = next->d_name.name;
64914 + if (name == next->d_iname) {
64915 + memcpy(d_name, name, next->d_name.len);
64916 + name = d_name;
64917 + }
64918 + if (!dir_emit(ctx, name, next->d_name.len,
64919 next->d_inode->i_ino, dt_type(next->d_inode)))
64920 return 0;
64921 spin_lock(&dentry->d_lock);
64922 @@ -1027,7 +1035,7 @@ EXPORT_SYMBOL(noop_fsync);
64923 void kfree_put_link(struct dentry *dentry, struct nameidata *nd,
64924 void *cookie)
64925 {
64926 - char *s = nd_get_link(nd);
64927 + const char *s = nd_get_link(nd);
64928 if (!IS_ERR(s))
64929 kfree(s);
64930 }
64931 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
64932 index acd3947..1f896e2 100644
64933 --- a/fs/lockd/clntproc.c
64934 +++ b/fs/lockd/clntproc.c
64935 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
64936 /*
64937 * Cookie counter for NLM requests
64938 */
64939 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
64940 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
64941
64942 void nlmclnt_next_cookie(struct nlm_cookie *c)
64943 {
64944 - u32 cookie = atomic_inc_return(&nlm_cookie);
64945 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
64946
64947 memcpy(c->data, &cookie, 4);
64948 c->len=4;
64949 diff --git a/fs/locks.c b/fs/locks.c
64950 index bb08857..f65e8bf 100644
64951 --- a/fs/locks.c
64952 +++ b/fs/locks.c
64953 @@ -2350,7 +2350,7 @@ void locks_remove_file(struct file *filp)
64954 locks_remove_posix(filp, filp);
64955
64956 if (filp->f_op->flock) {
64957 - struct file_lock fl = {
64958 + struct file_lock flock = {
64959 .fl_owner = filp,
64960 .fl_pid = current->tgid,
64961 .fl_file = filp,
64962 @@ -2358,9 +2358,9 @@ void locks_remove_file(struct file *filp)
64963 .fl_type = F_UNLCK,
64964 .fl_end = OFFSET_MAX,
64965 };
64966 - filp->f_op->flock(filp, F_SETLKW, &fl);
64967 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
64968 - fl.fl_ops->fl_release_private(&fl);
64969 + filp->f_op->flock(filp, F_SETLKW, &flock);
64970 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
64971 + flock.fl_ops->fl_release_private(&flock);
64972 }
64973
64974 spin_lock(&inode->i_lock);
64975 diff --git a/fs/mount.h b/fs/mount.h
64976 index 6740a62..ccb472f 100644
64977 --- a/fs/mount.h
64978 +++ b/fs/mount.h
64979 @@ -11,7 +11,7 @@ struct mnt_namespace {
64980 u64 seq; /* Sequence number to prevent loops */
64981 wait_queue_head_t poll;
64982 u64 event;
64983 -};
64984 +} __randomize_layout;
64985
64986 struct mnt_pcp {
64987 int mnt_count;
64988 @@ -57,7 +57,7 @@ struct mount {
64989 int mnt_expiry_mark; /* true if marked for expiry */
64990 struct hlist_head mnt_pins;
64991 struct path mnt_ex_mountpoint;
64992 -};
64993 +} __randomize_layout;
64994
64995 #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
64996
64997 diff --git a/fs/namei.c b/fs/namei.c
64998 index bb02687..79cba2c 100644
64999 --- a/fs/namei.c
65000 +++ b/fs/namei.c
65001 @@ -331,17 +331,32 @@ int generic_permission(struct inode *inode, int mask)
65002 if (ret != -EACCES)
65003 return ret;
65004
65005 +#ifdef CONFIG_GRKERNSEC
65006 + /* we'll block if we have to log due to a denied capability use */
65007 + if (mask & MAY_NOT_BLOCK)
65008 + return -ECHILD;
65009 +#endif
65010 +
65011 if (S_ISDIR(inode->i_mode)) {
65012 /* DACs are overridable for directories */
65013 - if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
65014 - return 0;
65015 if (!(mask & MAY_WRITE))
65016 - if (capable_wrt_inode_uidgid(inode,
65017 - CAP_DAC_READ_SEARCH))
65018 + if (capable_wrt_inode_uidgid_nolog(inode, CAP_DAC_OVERRIDE) ||
65019 + capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
65020 return 0;
65021 + if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
65022 + return 0;
65023 return -EACCES;
65024 }
65025 /*
65026 + * Searching includes executable on directories, else just read.
65027 + */
65028 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
65029 + if (mask == MAY_READ)
65030 + if (capable_wrt_inode_uidgid_nolog(inode, CAP_DAC_OVERRIDE) ||
65031 + capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
65032 + return 0;
65033 +
65034 + /*
65035 * Read/write DACs are always overridable.
65036 * Executable DACs are overridable when there is
65037 * at least one exec bit set.
65038 @@ -350,14 +365,6 @@ int generic_permission(struct inode *inode, int mask)
65039 if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
65040 return 0;
65041
65042 - /*
65043 - * Searching includes executable on directories, else just read.
65044 - */
65045 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
65046 - if (mask == MAY_READ)
65047 - if (capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
65048 - return 0;
65049 -
65050 return -EACCES;
65051 }
65052 EXPORT_SYMBOL(generic_permission);
65053 @@ -823,7 +830,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
65054 {
65055 struct dentry *dentry = link->dentry;
65056 int error;
65057 - char *s;
65058 + const char *s;
65059
65060 BUG_ON(nd->flags & LOOKUP_RCU);
65061
65062 @@ -844,6 +851,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
65063 if (error)
65064 goto out_put_nd_path;
65065
65066 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
65067 + dentry->d_inode, dentry, nd->path.mnt)) {
65068 + error = -EACCES;
65069 + goto out_put_nd_path;
65070 + }
65071 +
65072 nd->last_type = LAST_BIND;
65073 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
65074 error = PTR_ERR(*p);
65075 @@ -1607,6 +1620,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
65076 if (res)
65077 break;
65078 res = walk_component(nd, path, LOOKUP_FOLLOW);
65079 + if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
65080 + res = -EACCES;
65081 put_link(nd, &link, cookie);
65082 } while (res > 0);
65083
65084 @@ -1679,7 +1694,7 @@ EXPORT_SYMBOL(full_name_hash);
65085 static inline u64 hash_name(const char *name)
65086 {
65087 unsigned long a, b, adata, bdata, mask, hash, len;
65088 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
65089 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
65090
65091 hash = a = 0;
65092 len = -sizeof(unsigned long);
65093 @@ -1968,6 +1983,8 @@ static int path_lookupat(int dfd, const char *name,
65094 if (err)
65095 break;
65096 err = lookup_last(nd, &path);
65097 + if (!err && gr_handle_symlink_owner(&link, nd->inode))
65098 + err = -EACCES;
65099 put_link(nd, &link, cookie);
65100 }
65101 }
65102 @@ -1975,6 +1992,13 @@ static int path_lookupat(int dfd, const char *name,
65103 if (!err)
65104 err = complete_walk(nd);
65105
65106 + if (!err && !(nd->flags & LOOKUP_PARENT)) {
65107 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
65108 + path_put(&nd->path);
65109 + err = -ENOENT;
65110 + }
65111 + }
65112 +
65113 if (!err && nd->flags & LOOKUP_DIRECTORY) {
65114 if (!d_can_lookup(nd->path.dentry)) {
65115 path_put(&nd->path);
65116 @@ -2002,8 +2026,15 @@ static int filename_lookup(int dfd, struct filename *name,
65117 retval = path_lookupat(dfd, name->name,
65118 flags | LOOKUP_REVAL, nd);
65119
65120 - if (likely(!retval))
65121 + if (likely(!retval)) {
65122 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
65123 + if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
65124 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
65125 + path_put(&nd->path);
65126 + return -ENOENT;
65127 + }
65128 + }
65129 + }
65130 return retval;
65131 }
65132
65133 @@ -2585,6 +2616,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
65134 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
65135 return -EPERM;
65136
65137 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
65138 + return -EPERM;
65139 + if (gr_handle_rawio(inode))
65140 + return -EPERM;
65141 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
65142 + return -EACCES;
65143 +
65144 return 0;
65145 }
65146
65147 @@ -2816,7 +2854,7 @@ looked_up:
65148 * cleared otherwise prior to returning.
65149 */
65150 static int lookup_open(struct nameidata *nd, struct path *path,
65151 - struct file *file,
65152 + struct path *link, struct file *file,
65153 const struct open_flags *op,
65154 bool got_write, int *opened)
65155 {
65156 @@ -2851,6 +2889,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
65157 /* Negative dentry, just create the file */
65158 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
65159 umode_t mode = op->mode;
65160 +
65161 + if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
65162 + error = -EACCES;
65163 + goto out_dput;
65164 + }
65165 +
65166 + if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
65167 + error = -EACCES;
65168 + goto out_dput;
65169 + }
65170 +
65171 if (!IS_POSIXACL(dir->d_inode))
65172 mode &= ~current_umask();
65173 /*
65174 @@ -2872,6 +2921,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
65175 nd->flags & LOOKUP_EXCL);
65176 if (error)
65177 goto out_dput;
65178 + else
65179 + gr_handle_create(dentry, nd->path.mnt);
65180 }
65181 out_no_open:
65182 path->dentry = dentry;
65183 @@ -2886,7 +2937,7 @@ out_dput:
65184 /*
65185 * Handle the last step of open()
65186 */
65187 -static int do_last(struct nameidata *nd, struct path *path,
65188 +static int do_last(struct nameidata *nd, struct path *path, struct path *link,
65189 struct file *file, const struct open_flags *op,
65190 int *opened, struct filename *name)
65191 {
65192 @@ -2936,6 +2987,15 @@ static int do_last(struct nameidata *nd, struct path *path,
65193 if (error)
65194 return error;
65195
65196 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
65197 + error = -ENOENT;
65198 + goto out;
65199 + }
65200 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
65201 + error = -EACCES;
65202 + goto out;
65203 + }
65204 +
65205 audit_inode(name, dir, LOOKUP_PARENT);
65206 error = -EISDIR;
65207 /* trailing slashes? */
65208 @@ -2955,7 +3015,7 @@ retry_lookup:
65209 */
65210 }
65211 mutex_lock(&dir->d_inode->i_mutex);
65212 - error = lookup_open(nd, path, file, op, got_write, opened);
65213 + error = lookup_open(nd, path, link, file, op, got_write, opened);
65214 mutex_unlock(&dir->d_inode->i_mutex);
65215
65216 if (error <= 0) {
65217 @@ -2979,11 +3039,28 @@ retry_lookup:
65218 goto finish_open_created;
65219 }
65220
65221 + if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
65222 + error = -ENOENT;
65223 + goto exit_dput;
65224 + }
65225 + if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
65226 + error = -EACCES;
65227 + goto exit_dput;
65228 + }
65229 +
65230 /*
65231 * create/update audit record if it already exists.
65232 */
65233 - if (d_is_positive(path->dentry))
65234 + if (d_is_positive(path->dentry)) {
65235 + /* only check if O_CREAT is specified, all other checks need to go
65236 + into may_open */
65237 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
65238 + error = -EACCES;
65239 + goto exit_dput;
65240 + }
65241 +
65242 audit_inode(name, path->dentry, 0);
65243 + }
65244
65245 /*
65246 * If atomic_open() acquired write access it is dropped now due to
65247 @@ -3024,6 +3101,11 @@ finish_lookup:
65248 }
65249 }
65250 BUG_ON(inode != path->dentry->d_inode);
65251 + /* if we're resolving a symlink to another symlink */
65252 + if (link && gr_handle_symlink_owner(link, inode)) {
65253 + error = -EACCES;
65254 + goto out;
65255 + }
65256 return 1;
65257 }
65258
65259 @@ -3033,7 +3115,6 @@ finish_lookup:
65260 save_parent.dentry = nd->path.dentry;
65261 save_parent.mnt = mntget(path->mnt);
65262 nd->path.dentry = path->dentry;
65263 -
65264 }
65265 nd->inode = inode;
65266 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
65267 @@ -3043,7 +3124,18 @@ finish_open:
65268 path_put(&save_parent);
65269 return error;
65270 }
65271 +
65272 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
65273 + error = -ENOENT;
65274 + goto out;
65275 + }
65276 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
65277 + error = -EACCES;
65278 + goto out;
65279 + }
65280 +
65281 audit_inode(name, nd->path.dentry, 0);
65282 +
65283 error = -EISDIR;
65284 if ((open_flag & O_CREAT) && d_is_dir(nd->path.dentry))
65285 goto out;
65286 @@ -3207,7 +3299,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
65287 if (unlikely(error))
65288 goto out;
65289
65290 - error = do_last(nd, &path, file, op, &opened, pathname);
65291 + error = do_last(nd, &path, NULL, file, op, &opened, pathname);
65292 while (unlikely(error > 0)) { /* trailing symlink */
65293 struct path link = path;
65294 void *cookie;
65295 @@ -3225,7 +3317,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
65296 error = follow_link(&link, nd, &cookie);
65297 if (unlikely(error))
65298 break;
65299 - error = do_last(nd, &path, file, op, &opened, pathname);
65300 + error = do_last(nd, &path, &link, file, op, &opened, pathname);
65301 put_link(nd, &link, cookie);
65302 }
65303 out:
65304 @@ -3325,9 +3417,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
65305 goto unlock;
65306
65307 error = -EEXIST;
65308 - if (d_is_positive(dentry))
65309 + if (d_is_positive(dentry)) {
65310 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt))
65311 + error = -ENOENT;
65312 goto fail;
65313 -
65314 + }
65315 /*
65316 * Special case - lookup gave negative, but... we had foo/bar/
65317 * From the vfs_mknod() POV we just have a negative dentry -
65318 @@ -3379,6 +3473,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
65319 }
65320 EXPORT_SYMBOL(user_path_create);
65321
65322 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
65323 +{
65324 + struct filename *tmp = getname(pathname);
65325 + struct dentry *res;
65326 + if (IS_ERR(tmp))
65327 + return ERR_CAST(tmp);
65328 + res = kern_path_create(dfd, tmp->name, path, lookup_flags);
65329 + if (IS_ERR(res))
65330 + putname(tmp);
65331 + else
65332 + *to = tmp;
65333 + return res;
65334 +}
65335 +
65336 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
65337 {
65338 int error = may_create(dir, dentry);
65339 @@ -3442,6 +3550,17 @@ retry:
65340
65341 if (!IS_POSIXACL(path.dentry->d_inode))
65342 mode &= ~current_umask();
65343 +
65344 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
65345 + error = -EPERM;
65346 + goto out;
65347 + }
65348 +
65349 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
65350 + error = -EACCES;
65351 + goto out;
65352 + }
65353 +
65354 error = security_path_mknod(&path, dentry, mode, dev);
65355 if (error)
65356 goto out;
65357 @@ -3457,6 +3576,8 @@ retry:
65358 error = vfs_mknod(path.dentry->d_inode,dentry,mode,0);
65359 break;
65360 }
65361 + if (!error)
65362 + gr_handle_create(dentry, path.mnt);
65363 out:
65364 done_path_create(&path, dentry);
65365 if (retry_estale(error, lookup_flags)) {
65366 @@ -3511,9 +3632,16 @@ retry:
65367
65368 if (!IS_POSIXACL(path.dentry->d_inode))
65369 mode &= ~current_umask();
65370 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
65371 + error = -EACCES;
65372 + goto out;
65373 + }
65374 error = security_path_mkdir(&path, dentry, mode);
65375 if (!error)
65376 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
65377 + if (!error)
65378 + gr_handle_create(dentry, path.mnt);
65379 +out:
65380 done_path_create(&path, dentry);
65381 if (retry_estale(error, lookup_flags)) {
65382 lookup_flags |= LOOKUP_REVAL;
65383 @@ -3596,6 +3724,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
65384 struct filename *name;
65385 struct dentry *dentry;
65386 struct nameidata nd;
65387 + ino_t saved_ino = 0;
65388 + dev_t saved_dev = 0;
65389 unsigned int lookup_flags = 0;
65390 retry:
65391 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
65392 @@ -3628,10 +3758,21 @@ retry:
65393 error = -ENOENT;
65394 goto exit3;
65395 }
65396 +
65397 + saved_ino = dentry->d_inode->i_ino;
65398 + saved_dev = gr_get_dev_from_dentry(dentry);
65399 +
65400 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
65401 + error = -EACCES;
65402 + goto exit3;
65403 + }
65404 +
65405 error = security_path_rmdir(&nd.path, dentry);
65406 if (error)
65407 goto exit3;
65408 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
65409 + if (!error && (saved_dev || saved_ino))
65410 + gr_handle_delete(saved_ino, saved_dev);
65411 exit3:
65412 dput(dentry);
65413 exit2:
65414 @@ -3722,6 +3863,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
65415 struct nameidata nd;
65416 struct inode *inode = NULL;
65417 struct inode *delegated_inode = NULL;
65418 + ino_t saved_ino = 0;
65419 + dev_t saved_dev = 0;
65420 unsigned int lookup_flags = 0;
65421 retry:
65422 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
65423 @@ -3748,10 +3891,22 @@ retry_deleg:
65424 if (d_is_negative(dentry))
65425 goto slashes;
65426 ihold(inode);
65427 +
65428 + if (inode->i_nlink <= 1) {
65429 + saved_ino = inode->i_ino;
65430 + saved_dev = gr_get_dev_from_dentry(dentry);
65431 + }
65432 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
65433 + error = -EACCES;
65434 + goto exit2;
65435 + }
65436 +
65437 error = security_path_unlink(&nd.path, dentry);
65438 if (error)
65439 goto exit2;
65440 error = vfs_unlink(nd.path.dentry->d_inode, dentry, &delegated_inode);
65441 + if (!error && (saved_ino || saved_dev))
65442 + gr_handle_delete(saved_ino, saved_dev);
65443 exit2:
65444 dput(dentry);
65445 }
65446 @@ -3840,9 +3995,17 @@ retry:
65447 if (IS_ERR(dentry))
65448 goto out_putname;
65449
65450 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
65451 + error = -EACCES;
65452 + goto out;
65453 + }
65454 +
65455 error = security_path_symlink(&path, dentry, from->name);
65456 if (!error)
65457 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
65458 + if (!error)
65459 + gr_handle_create(dentry, path.mnt);
65460 +out:
65461 done_path_create(&path, dentry);
65462 if (retry_estale(error, lookup_flags)) {
65463 lookup_flags |= LOOKUP_REVAL;
65464 @@ -3946,6 +4109,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
65465 struct dentry *new_dentry;
65466 struct path old_path, new_path;
65467 struct inode *delegated_inode = NULL;
65468 + struct filename *to = NULL;
65469 int how = 0;
65470 int error;
65471
65472 @@ -3969,7 +4133,7 @@ retry:
65473 if (error)
65474 return error;
65475
65476 - new_dentry = user_path_create(newdfd, newname, &new_path,
65477 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
65478 (how & LOOKUP_REVAL));
65479 error = PTR_ERR(new_dentry);
65480 if (IS_ERR(new_dentry))
65481 @@ -3981,11 +4145,28 @@ retry:
65482 error = may_linkat(&old_path);
65483 if (unlikely(error))
65484 goto out_dput;
65485 +
65486 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
65487 + old_path.dentry->d_inode,
65488 + old_path.dentry->d_inode->i_mode, to)) {
65489 + error = -EACCES;
65490 + goto out_dput;
65491 + }
65492 +
65493 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
65494 + old_path.dentry, old_path.mnt, to)) {
65495 + error = -EACCES;
65496 + goto out_dput;
65497 + }
65498 +
65499 error = security_path_link(old_path.dentry, &new_path, new_dentry);
65500 if (error)
65501 goto out_dput;
65502 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry, &delegated_inode);
65503 + if (!error)
65504 + gr_handle_create(new_dentry, new_path.mnt);
65505 out_dput:
65506 + putname(to);
65507 done_path_create(&new_path, new_dentry);
65508 if (delegated_inode) {
65509 error = break_deleg_wait(&delegated_inode);
65510 @@ -4296,6 +4477,12 @@ retry_deleg:
65511 if (new_dentry == trap)
65512 goto exit5;
65513
65514 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
65515 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
65516 + to, flags);
65517 + if (error)
65518 + goto exit5;
65519 +
65520 error = security_path_rename(&oldnd.path, old_dentry,
65521 &newnd.path, new_dentry, flags);
65522 if (error)
65523 @@ -4303,6 +4490,9 @@ retry_deleg:
65524 error = vfs_rename(old_dir->d_inode, old_dentry,
65525 new_dir->d_inode, new_dentry,
65526 &delegated_inode, flags);
65527 + if (!error)
65528 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
65529 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0, flags);
65530 exit5:
65531 dput(new_dentry);
65532 exit4:
65533 @@ -4345,14 +4535,24 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
65534
65535 int readlink_copy(char __user *buffer, int buflen, const char *link)
65536 {
65537 + char tmpbuf[64];
65538 + const char *newlink;
65539 int len = PTR_ERR(link);
65540 +
65541 if (IS_ERR(link))
65542 goto out;
65543
65544 len = strlen(link);
65545 if (len > (unsigned) buflen)
65546 len = buflen;
65547 - if (copy_to_user(buffer, link, len))
65548 +
65549 + if (len < sizeof(tmpbuf)) {
65550 + memcpy(tmpbuf, link, len);
65551 + newlink = tmpbuf;
65552 + } else
65553 + newlink = link;
65554 +
65555 + if (copy_to_user(buffer, newlink, len))
65556 len = -EFAULT;
65557 out:
65558 return len;
65559 diff --git a/fs/namespace.c b/fs/namespace.c
65560 index 550dbff..6c24d43 100644
65561 --- a/fs/namespace.c
65562 +++ b/fs/namespace.c
65563 @@ -1286,6 +1286,8 @@ void umount_tree(struct mount *mnt, int how)
65564 }
65565 if (last) {
65566 last->mnt_hash.next = unmounted.first;
65567 + if (unmounted.first)
65568 + unmounted.first->pprev = &last->mnt_hash.next;
65569 unmounted.first = tmp_list.first;
65570 unmounted.first->pprev = &unmounted.first;
65571 }
65572 @@ -1362,6 +1364,9 @@ static int do_umount(struct mount *mnt, int flags)
65573 if (!(sb->s_flags & MS_RDONLY))
65574 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
65575 up_write(&sb->s_umount);
65576 +
65577 + gr_log_remount(mnt->mnt_devname, retval);
65578 +
65579 return retval;
65580 }
65581
65582 @@ -1384,6 +1389,9 @@ static int do_umount(struct mount *mnt, int flags)
65583 }
65584 unlock_mount_hash();
65585 namespace_unlock();
65586 +
65587 + gr_log_unmount(mnt->mnt_devname, retval);
65588 +
65589 return retval;
65590 }
65591
65592 @@ -1403,7 +1411,7 @@ static inline bool may_mount(void)
65593 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
65594 */
65595
65596 -SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
65597 +SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
65598 {
65599 struct path path;
65600 struct mount *mnt;
65601 @@ -1445,7 +1453,7 @@ out:
65602 /*
65603 * The 2.0 compatible umount. No flags.
65604 */
65605 -SYSCALL_DEFINE1(oldumount, char __user *, name)
65606 +SYSCALL_DEFINE1(oldumount, const char __user *, name)
65607 {
65608 return sys_umount(name, 0);
65609 }
65610 @@ -2494,6 +2502,16 @@ long do_mount(const char *dev_name, const char *dir_name,
65611 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
65612 MS_STRICTATIME);
65613
65614 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
65615 + retval = -EPERM;
65616 + goto dput_out;
65617 + }
65618 +
65619 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
65620 + retval = -EPERM;
65621 + goto dput_out;
65622 + }
65623 +
65624 if (flags & MS_REMOUNT)
65625 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
65626 data_page);
65627 @@ -2508,6 +2526,9 @@ long do_mount(const char *dev_name, const char *dir_name,
65628 dev_name, data_page);
65629 dput_out:
65630 path_put(&path);
65631 +
65632 + gr_log_mount(dev_name, dir_name, retval);
65633 +
65634 return retval;
65635 }
65636
65637 @@ -2525,7 +2546,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
65638 * number incrementing at 10Ghz will take 12,427 years to wrap which
65639 * is effectively never, so we can ignore the possibility.
65640 */
65641 -static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
65642 +static atomic64_unchecked_t mnt_ns_seq = ATOMIC64_INIT(1);
65643
65644 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
65645 {
65646 @@ -2540,7 +2561,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
65647 kfree(new_ns);
65648 return ERR_PTR(ret);
65649 }
65650 - new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
65651 + new_ns->seq = atomic64_inc_return_unchecked(&mnt_ns_seq);
65652 atomic_set(&new_ns->count, 1);
65653 new_ns->root = NULL;
65654 INIT_LIST_HEAD(&new_ns->list);
65655 @@ -2550,7 +2571,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
65656 return new_ns;
65657 }
65658
65659 -struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
65660 +__latent_entropy struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
65661 struct user_namespace *user_ns, struct fs_struct *new_fs)
65662 {
65663 struct mnt_namespace *new_ns;
65664 @@ -2671,8 +2692,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
65665 }
65666 EXPORT_SYMBOL(mount_subtree);
65667
65668 -SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
65669 - char __user *, type, unsigned long, flags, void __user *, data)
65670 +SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
65671 + const char __user *, type, unsigned long, flags, void __user *, data)
65672 {
65673 int ret;
65674 char *kernel_type;
65675 @@ -2785,6 +2806,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
65676 if (error)
65677 goto out2;
65678
65679 + if (gr_handle_chroot_pivot()) {
65680 + error = -EPERM;
65681 + goto out2;
65682 + }
65683 +
65684 get_fs_root(current->fs, &root);
65685 old_mp = lock_mount(&old);
65686 error = PTR_ERR(old_mp);
65687 @@ -3056,7 +3082,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
65688 !ns_capable(current_user_ns(), CAP_SYS_ADMIN))
65689 return -EPERM;
65690
65691 - if (fs->users != 1)
65692 + if (atomic_read(&fs->users) != 1)
65693 return -EINVAL;
65694
65695 get_mnt_ns(mnt_ns);
65696 diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
65697 index f4ccfe6..a5cf064 100644
65698 --- a/fs/nfs/callback_xdr.c
65699 +++ b/fs/nfs/callback_xdr.c
65700 @@ -51,7 +51,7 @@ struct callback_op {
65701 callback_decode_arg_t decode_args;
65702 callback_encode_res_t encode_res;
65703 long res_maxsize;
65704 -};
65705 +} __do_const;
65706
65707 static struct callback_op callback_ops[];
65708
65709 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
65710 index 0689aa5..299386e 100644
65711 --- a/fs/nfs/inode.c
65712 +++ b/fs/nfs/inode.c
65713 @@ -1228,16 +1228,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
65714 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
65715 }
65716
65717 -static atomic_long_t nfs_attr_generation_counter;
65718 +static atomic_long_unchecked_t nfs_attr_generation_counter;
65719
65720 static unsigned long nfs_read_attr_generation_counter(void)
65721 {
65722 - return atomic_long_read(&nfs_attr_generation_counter);
65723 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
65724 }
65725
65726 unsigned long nfs_inc_attr_generation_counter(void)
65727 {
65728 - return atomic_long_inc_return(&nfs_attr_generation_counter);
65729 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
65730 }
65731
65732 void nfs_fattr_init(struct nfs_fattr *fattr)
65733 diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
65734 index 1d3cb47..2b8ed89 100644
65735 --- a/fs/nfsd/nfs4proc.c
65736 +++ b/fs/nfsd/nfs4proc.c
65737 @@ -1155,7 +1155,7 @@ struct nfsd4_operation {
65738 nfsd4op_rsize op_rsize_bop;
65739 stateid_getter op_get_currentstateid;
65740 stateid_setter op_set_currentstateid;
65741 -};
65742 +} __do_const;
65743
65744 static struct nfsd4_operation nfsd4_ops[];
65745
65746 diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
65747 index 353aac8..32035ee 100644
65748 --- a/fs/nfsd/nfs4xdr.c
65749 +++ b/fs/nfsd/nfs4xdr.c
65750 @@ -1534,7 +1534,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
65751
65752 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
65753
65754 -static nfsd4_dec nfsd4_dec_ops[] = {
65755 +static const nfsd4_dec nfsd4_dec_ops[] = {
65756 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
65757 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
65758 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
65759 diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
65760 index ff95676..96cf3f62 100644
65761 --- a/fs/nfsd/nfscache.c
65762 +++ b/fs/nfsd/nfscache.c
65763 @@ -527,17 +527,20 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
65764 {
65765 struct svc_cacherep *rp = rqstp->rq_cacherep;
65766 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
65767 - int len;
65768 + long len;
65769 size_t bufsize = 0;
65770
65771 if (!rp)
65772 return;
65773
65774 - len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
65775 - len >>= 2;
65776 + if (statp) {
65777 + len = (char*)statp - (char*)resv->iov_base;
65778 + len = resv->iov_len - len;
65779 + len >>= 2;
65780 + }
65781
65782 /* Don't cache excessive amounts of data and XDR failures */
65783 - if (!statp || len > (256 >> 2)) {
65784 + if (!statp || len > (256 >> 2) || len < 0) {
65785 nfsd_reply_cache_free(rp);
65786 return;
65787 }
65788 @@ -545,7 +548,7 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
65789 switch (cachetype) {
65790 case RC_REPLSTAT:
65791 if (len != 1)
65792 - printk("nfsd: RC_REPLSTAT/reply len %d!\n",len);
65793 + printk("nfsd: RC_REPLSTAT/reply len %ld!\n",len);
65794 rp->c_replstat = *statp;
65795 break;
65796 case RC_REPLBUFF:
65797 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
65798 index 6ab077b..5ac7f0b 100644
65799 --- a/fs/nfsd/vfs.c
65800 +++ b/fs/nfsd/vfs.c
65801 @@ -855,7 +855,7 @@ __be32 nfsd_readv(struct file *file, loff_t offset, struct kvec *vec, int vlen,
65802
65803 oldfs = get_fs();
65804 set_fs(KERNEL_DS);
65805 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
65806 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
65807 set_fs(oldfs);
65808 return nfsd_finish_read(file, count, host_err);
65809 }
65810 @@ -943,7 +943,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
65811
65812 /* Write the data. */
65813 oldfs = get_fs(); set_fs(KERNEL_DS);
65814 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
65815 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
65816 set_fs(oldfs);
65817 if (host_err < 0)
65818 goto out_nfserr;
65819 @@ -1485,7 +1485,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
65820 */
65821
65822 oldfs = get_fs(); set_fs(KERNEL_DS);
65823 - host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
65824 + host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
65825 set_fs(oldfs);
65826
65827 if (host_err < 0)
65828 diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
65829 index 52ccd34..7a6b202 100644
65830 --- a/fs/nls/nls_base.c
65831 +++ b/fs/nls/nls_base.c
65832 @@ -234,21 +234,25 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
65833
65834 int __register_nls(struct nls_table *nls, struct module *owner)
65835 {
65836 - struct nls_table ** tmp = &tables;
65837 + struct nls_table *tmp = tables;
65838
65839 if (nls->next)
65840 return -EBUSY;
65841
65842 - nls->owner = owner;
65843 + pax_open_kernel();
65844 + *(void **)&nls->owner = owner;
65845 + pax_close_kernel();
65846 spin_lock(&nls_lock);
65847 - while (*tmp) {
65848 - if (nls == *tmp) {
65849 + while (tmp) {
65850 + if (nls == tmp) {
65851 spin_unlock(&nls_lock);
65852 return -EBUSY;
65853 }
65854 - tmp = &(*tmp)->next;
65855 + tmp = tmp->next;
65856 }
65857 - nls->next = tables;
65858 + pax_open_kernel();
65859 + *(struct nls_table **)&nls->next = tables;
65860 + pax_close_kernel();
65861 tables = nls;
65862 spin_unlock(&nls_lock);
65863 return 0;
65864 @@ -257,12 +261,14 @@ EXPORT_SYMBOL(__register_nls);
65865
65866 int unregister_nls(struct nls_table * nls)
65867 {
65868 - struct nls_table ** tmp = &tables;
65869 + struct nls_table * const * tmp = &tables;
65870
65871 spin_lock(&nls_lock);
65872 while (*tmp) {
65873 if (nls == *tmp) {
65874 - *tmp = nls->next;
65875 + pax_open_kernel();
65876 + *(struct nls_table **)tmp = nls->next;
65877 + pax_close_kernel();
65878 spin_unlock(&nls_lock);
65879 return 0;
65880 }
65881 @@ -272,7 +278,7 @@ int unregister_nls(struct nls_table * nls)
65882 return -EINVAL;
65883 }
65884
65885 -static struct nls_table *find_nls(char *charset)
65886 +static struct nls_table *find_nls(const char *charset)
65887 {
65888 struct nls_table *nls;
65889 spin_lock(&nls_lock);
65890 @@ -288,7 +294,7 @@ static struct nls_table *find_nls(char *charset)
65891 return nls;
65892 }
65893
65894 -struct nls_table *load_nls(char *charset)
65895 +struct nls_table *load_nls(const char *charset)
65896 {
65897 return try_then_request_module(find_nls(charset), "nls_%s", charset);
65898 }
65899 diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
65900 index 162b3f1..6076a7c 100644
65901 --- a/fs/nls/nls_euc-jp.c
65902 +++ b/fs/nls/nls_euc-jp.c
65903 @@ -560,8 +560,10 @@ static int __init init_nls_euc_jp(void)
65904 p_nls = load_nls("cp932");
65905
65906 if (p_nls) {
65907 - table.charset2upper = p_nls->charset2upper;
65908 - table.charset2lower = p_nls->charset2lower;
65909 + pax_open_kernel();
65910 + *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
65911 + *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
65912 + pax_close_kernel();
65913 return register_nls(&table);
65914 }
65915
65916 diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
65917 index a80a741..7b96e1b 100644
65918 --- a/fs/nls/nls_koi8-ru.c
65919 +++ b/fs/nls/nls_koi8-ru.c
65920 @@ -62,8 +62,10 @@ static int __init init_nls_koi8_ru(void)
65921 p_nls = load_nls("koi8-u");
65922
65923 if (p_nls) {
65924 - table.charset2upper = p_nls->charset2upper;
65925 - table.charset2lower = p_nls->charset2lower;
65926 + pax_open_kernel();
65927 + *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
65928 + *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
65929 + pax_close_kernel();
65930 return register_nls(&table);
65931 }
65932
65933 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
65934 index c991616..5ae51af 100644
65935 --- a/fs/notify/fanotify/fanotify_user.c
65936 +++ b/fs/notify/fanotify/fanotify_user.c
65937 @@ -216,8 +216,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
65938
65939 fd = fanotify_event_metadata.fd;
65940 ret = -EFAULT;
65941 - if (copy_to_user(buf, &fanotify_event_metadata,
65942 - fanotify_event_metadata.event_len))
65943 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
65944 + copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
65945 goto out_close_fd;
65946
65947 #ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
65948 diff --git a/fs/notify/inotify/inotify_fsnotify.c b/fs/notify/inotify/inotify_fsnotify.c
65949 index 0f88bc0..7d888d7 100644
65950 --- a/fs/notify/inotify/inotify_fsnotify.c
65951 +++ b/fs/notify/inotify/inotify_fsnotify.c
65952 @@ -165,8 +165,10 @@ static void inotify_free_group_priv(struct fsnotify_group *group)
65953 /* ideally the idr is empty and we won't hit the BUG in the callback */
65954 idr_for_each(&group->inotify_data.idr, idr_callback, group);
65955 idr_destroy(&group->inotify_data.idr);
65956 - atomic_dec(&group->inotify_data.user->inotify_devs);
65957 - free_uid(group->inotify_data.user);
65958 + if (group->inotify_data.user) {
65959 + atomic_dec(&group->inotify_data.user->inotify_devs);
65960 + free_uid(group->inotify_data.user);
65961 + }
65962 }
65963
65964 static void inotify_free_event(struct fsnotify_event *fsn_event)
65965 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
65966 index a95d8e0..a91a5fd 100644
65967 --- a/fs/notify/notification.c
65968 +++ b/fs/notify/notification.c
65969 @@ -48,7 +48,7 @@
65970 #include <linux/fsnotify_backend.h>
65971 #include "fsnotify.h"
65972
65973 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
65974 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
65975
65976 /**
65977 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
65978 @@ -56,7 +56,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
65979 */
65980 u32 fsnotify_get_cookie(void)
65981 {
65982 - return atomic_inc_return(&fsnotify_sync_cookie);
65983 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
65984 }
65985 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
65986
65987 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
65988 index 9e38daf..5727cae 100644
65989 --- a/fs/ntfs/dir.c
65990 +++ b/fs/ntfs/dir.c
65991 @@ -1310,7 +1310,7 @@ find_next_index_buffer:
65992 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
65993 ~(s64)(ndir->itype.index.block_size - 1)));
65994 /* Bounds checks. */
65995 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
65996 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
65997 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
65998 "inode 0x%lx or driver bug.", vdir->i_ino);
65999 goto err_out;
66000 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
66001 index f5ec1ce..807fd78 100644
66002 --- a/fs/ntfs/file.c
66003 +++ b/fs/ntfs/file.c
66004 @@ -1279,7 +1279,7 @@ static inline size_t ntfs_copy_from_user(struct page **pages,
66005 char *addr;
66006 size_t total = 0;
66007 unsigned len;
66008 - int left;
66009 + unsigned left;
66010
66011 do {
66012 len = PAGE_CACHE_SIZE - ofs;
66013 diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
66014 index 6c3296e..c0b99f0 100644
66015 --- a/fs/ntfs/super.c
66016 +++ b/fs/ntfs/super.c
66017 @@ -688,7 +688,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
66018 if (!silent)
66019 ntfs_error(sb, "Primary boot sector is invalid.");
66020 } else if (!silent)
66021 - ntfs_error(sb, read_err_str, "primary");
66022 + ntfs_error(sb, read_err_str, "%s", "primary");
66023 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
66024 if (bh_primary)
66025 brelse(bh_primary);
66026 @@ -704,7 +704,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
66027 goto hotfix_primary_boot_sector;
66028 brelse(bh_backup);
66029 } else if (!silent)
66030 - ntfs_error(sb, read_err_str, "backup");
66031 + ntfs_error(sb, read_err_str, "%s", "backup");
66032 /* Try to read NT3.51- backup boot sector. */
66033 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
66034 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
66035 @@ -715,7 +715,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
66036 "sector.");
66037 brelse(bh_backup);
66038 } else if (!silent)
66039 - ntfs_error(sb, read_err_str, "backup");
66040 + ntfs_error(sb, read_err_str, "%s", "backup");
66041 /* We failed. Cleanup and return. */
66042 if (bh_primary)
66043 brelse(bh_primary);
66044 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
66045 index 0440134..d52c93a 100644
66046 --- a/fs/ocfs2/localalloc.c
66047 +++ b/fs/ocfs2/localalloc.c
66048 @@ -1320,7 +1320,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
66049 goto bail;
66050 }
66051
66052 - atomic_inc(&osb->alloc_stats.moves);
66053 + atomic_inc_unchecked(&osb->alloc_stats.moves);
66054
66055 bail:
66056 if (handle)
66057 diff --git a/fs/ocfs2/namei.c b/fs/ocfs2/namei.c
66058 index 8add6f1..b931e04 100644
66059 --- a/fs/ocfs2/namei.c
66060 +++ b/fs/ocfs2/namei.c
66061 @@ -158,7 +158,7 @@ bail_add:
66062 * NOTE: This dentry already has ->d_op set from
66063 * ocfs2_get_parent() and ocfs2_get_dentry()
66064 */
66065 - if (ret)
66066 + if (!IS_ERR_OR_NULL(ret))
66067 dentry = ret;
66068
66069 status = ocfs2_dentry_attach_lock(dentry, inode,
66070 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
66071 index bbec539..7b266d5 100644
66072 --- a/fs/ocfs2/ocfs2.h
66073 +++ b/fs/ocfs2/ocfs2.h
66074 @@ -236,11 +236,11 @@ enum ocfs2_vol_state
66075
66076 struct ocfs2_alloc_stats
66077 {
66078 - atomic_t moves;
66079 - atomic_t local_data;
66080 - atomic_t bitmap_data;
66081 - atomic_t bg_allocs;
66082 - atomic_t bg_extends;
66083 + atomic_unchecked_t moves;
66084 + atomic_unchecked_t local_data;
66085 + atomic_unchecked_t bitmap_data;
66086 + atomic_unchecked_t bg_allocs;
66087 + atomic_unchecked_t bg_extends;
66088 };
66089
66090 enum ocfs2_local_alloc_state
66091 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
66092 index 0cb889a..6a26b24 100644
66093 --- a/fs/ocfs2/suballoc.c
66094 +++ b/fs/ocfs2/suballoc.c
66095 @@ -867,7 +867,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
66096 mlog_errno(status);
66097 goto bail;
66098 }
66099 - atomic_inc(&osb->alloc_stats.bg_extends);
66100 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
66101
66102 /* You should never ask for this much metadata */
66103 BUG_ON(bits_wanted >
66104 @@ -2014,7 +2014,7 @@ int ocfs2_claim_metadata(handle_t *handle,
66105 mlog_errno(status);
66106 goto bail;
66107 }
66108 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
66109 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
66110
66111 *suballoc_loc = res.sr_bg_blkno;
66112 *suballoc_bit_start = res.sr_bit_offset;
66113 @@ -2180,7 +2180,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
66114 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
66115 res->sr_bits);
66116
66117 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
66118 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
66119
66120 BUG_ON(res->sr_bits != 1);
66121
66122 @@ -2222,7 +2222,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
66123 mlog_errno(status);
66124 goto bail;
66125 }
66126 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
66127 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
66128
66129 BUG_ON(res.sr_bits != 1);
66130
66131 @@ -2326,7 +2326,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
66132 cluster_start,
66133 num_clusters);
66134 if (!status)
66135 - atomic_inc(&osb->alloc_stats.local_data);
66136 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
66137 } else {
66138 if (min_clusters > (osb->bitmap_cpg - 1)) {
66139 /* The only paths asking for contiguousness
66140 @@ -2352,7 +2352,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
66141 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
66142 res.sr_bg_blkno,
66143 res.sr_bit_offset);
66144 - atomic_inc(&osb->alloc_stats.bitmap_data);
66145 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
66146 *num_clusters = res.sr_bits;
66147 }
66148 }
66149 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
66150 index 4142546..69375a9 100644
66151 --- a/fs/ocfs2/super.c
66152 +++ b/fs/ocfs2/super.c
66153 @@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
66154 "%10s => GlobalAllocs: %d LocalAllocs: %d "
66155 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
66156 "Stats",
66157 - atomic_read(&osb->alloc_stats.bitmap_data),
66158 - atomic_read(&osb->alloc_stats.local_data),
66159 - atomic_read(&osb->alloc_stats.bg_allocs),
66160 - atomic_read(&osb->alloc_stats.moves),
66161 - atomic_read(&osb->alloc_stats.bg_extends));
66162 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
66163 + atomic_read_unchecked(&osb->alloc_stats.local_data),
66164 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
66165 + atomic_read_unchecked(&osb->alloc_stats.moves),
66166 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
66167
66168 out += snprintf(buf + out, len - out,
66169 "%10s => State: %u Descriptor: %llu Size: %u bits "
66170 @@ -2100,11 +2100,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
66171
66172 mutex_init(&osb->system_file_mutex);
66173
66174 - atomic_set(&osb->alloc_stats.moves, 0);
66175 - atomic_set(&osb->alloc_stats.local_data, 0);
66176 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
66177 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
66178 - atomic_set(&osb->alloc_stats.bg_extends, 0);
66179 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
66180 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
66181 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
66182 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
66183 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
66184
66185 /* Copy the blockcheck stats from the superblock probe */
66186 osb->osb_ecc_stats = *stats;
66187 diff --git a/fs/open.c b/fs/open.c
66188 index d6fd3ac..6ccf474 100644
66189 --- a/fs/open.c
66190 +++ b/fs/open.c
66191 @@ -32,6 +32,8 @@
66192 #include <linux/dnotify.h>
66193 #include <linux/compat.h>
66194
66195 +#define CREATE_TRACE_POINTS
66196 +#include <trace/events/fs.h>
66197 #include "internal.h"
66198
66199 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
66200 @@ -103,6 +105,8 @@ long vfs_truncate(struct path *path, loff_t length)
66201 error = locks_verify_truncate(inode, NULL, length);
66202 if (!error)
66203 error = security_path_truncate(path);
66204 + if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
66205 + error = -EACCES;
66206 if (!error)
66207 error = do_truncate(path->dentry, length, 0, NULL);
66208
66209 @@ -187,6 +191,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
66210 error = locks_verify_truncate(inode, f.file, length);
66211 if (!error)
66212 error = security_path_truncate(&f.file->f_path);
66213 + if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
66214 + error = -EACCES;
66215 if (!error)
66216 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
66217 sb_end_write(inode->i_sb);
66218 @@ -380,6 +386,9 @@ retry:
66219 if (__mnt_is_readonly(path.mnt))
66220 res = -EROFS;
66221
66222 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
66223 + res = -EACCES;
66224 +
66225 out_path_release:
66226 path_put(&path);
66227 if (retry_estale(res, lookup_flags)) {
66228 @@ -411,6 +420,8 @@ retry:
66229 if (error)
66230 goto dput_and_out;
66231
66232 + gr_log_chdir(path.dentry, path.mnt);
66233 +
66234 set_fs_pwd(current->fs, &path);
66235
66236 dput_and_out:
66237 @@ -440,6 +451,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
66238 goto out_putf;
66239
66240 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
66241 +
66242 + if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
66243 + error = -EPERM;
66244 +
66245 + if (!error)
66246 + gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
66247 +
66248 if (!error)
66249 set_fs_pwd(current->fs, &f.file->f_path);
66250 out_putf:
66251 @@ -469,7 +487,13 @@ retry:
66252 if (error)
66253 goto dput_and_out;
66254
66255 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
66256 + goto dput_and_out;
66257 +
66258 set_fs_root(current->fs, &path);
66259 +
66260 + gr_handle_chroot_chdir(&path);
66261 +
66262 error = 0;
66263 dput_and_out:
66264 path_put(&path);
66265 @@ -493,6 +517,16 @@ static int chmod_common(struct path *path, umode_t mode)
66266 return error;
66267 retry_deleg:
66268 mutex_lock(&inode->i_mutex);
66269 +
66270 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
66271 + error = -EACCES;
66272 + goto out_unlock;
66273 + }
66274 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
66275 + error = -EACCES;
66276 + goto out_unlock;
66277 + }
66278 +
66279 error = security_path_chmod(path, mode);
66280 if (error)
66281 goto out_unlock;
66282 @@ -558,6 +592,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
66283 uid = make_kuid(current_user_ns(), user);
66284 gid = make_kgid(current_user_ns(), group);
66285
66286 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
66287 + return -EACCES;
66288 +
66289 newattrs.ia_valid = ATTR_CTIME;
66290 if (user != (uid_t) -1) {
66291 if (!uid_valid(uid))
66292 @@ -983,6 +1020,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
66293 } else {
66294 fsnotify_open(f);
66295 fd_install(fd, f);
66296 + trace_do_sys_open(tmp->name, flags, mode);
66297 }
66298 }
66299 putname(tmp);
66300 diff --git a/fs/pipe.c b/fs/pipe.c
66301 index 21981e5..3d5f55c 100644
66302 --- a/fs/pipe.c
66303 +++ b/fs/pipe.c
66304 @@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
66305
66306 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
66307 {
66308 - if (pipe->files)
66309 + if (atomic_read(&pipe->files))
66310 mutex_lock_nested(&pipe->mutex, subclass);
66311 }
66312
66313 @@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
66314
66315 void pipe_unlock(struct pipe_inode_info *pipe)
66316 {
66317 - if (pipe->files)
66318 + if (atomic_read(&pipe->files))
66319 mutex_unlock(&pipe->mutex);
66320 }
66321 EXPORT_SYMBOL(pipe_unlock);
66322 @@ -292,9 +292,9 @@ pipe_read(struct kiocb *iocb, struct iov_iter *to)
66323 }
66324 if (bufs) /* More to do? */
66325 continue;
66326 - if (!pipe->writers)
66327 + if (!atomic_read(&pipe->writers))
66328 break;
66329 - if (!pipe->waiting_writers) {
66330 + if (!atomic_read(&pipe->waiting_writers)) {
66331 /* syscall merging: Usually we must not sleep
66332 * if O_NONBLOCK is set, or if we got some data.
66333 * But if a writer sleeps in kernel space, then
66334 @@ -351,7 +351,7 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
66335
66336 __pipe_lock(pipe);
66337
66338 - if (!pipe->readers) {
66339 + if (!atomic_read(&pipe->readers)) {
66340 send_sig(SIGPIPE, current, 0);
66341 ret = -EPIPE;
66342 goto out;
66343 @@ -387,7 +387,7 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
66344 for (;;) {
66345 int bufs;
66346
66347 - if (!pipe->readers) {
66348 + if (!atomic_read(&pipe->readers)) {
66349 send_sig(SIGPIPE, current, 0);
66350 if (!ret)
66351 ret = -EPIPE;
66352 @@ -455,9 +455,9 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
66353 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
66354 do_wakeup = 0;
66355 }
66356 - pipe->waiting_writers++;
66357 + atomic_inc(&pipe->waiting_writers);
66358 pipe_wait(pipe);
66359 - pipe->waiting_writers--;
66360 + atomic_dec(&pipe->waiting_writers);
66361 }
66362 out:
66363 __pipe_unlock(pipe);
66364 @@ -512,7 +512,7 @@ pipe_poll(struct file *filp, poll_table *wait)
66365 mask = 0;
66366 if (filp->f_mode & FMODE_READ) {
66367 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
66368 - if (!pipe->writers && filp->f_version != pipe->w_counter)
66369 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
66370 mask |= POLLHUP;
66371 }
66372
66373 @@ -522,7 +522,7 @@ pipe_poll(struct file *filp, poll_table *wait)
66374 * Most Unices do not set POLLERR for FIFOs but on Linux they
66375 * behave exactly like pipes for poll().
66376 */
66377 - if (!pipe->readers)
66378 + if (!atomic_read(&pipe->readers))
66379 mask |= POLLERR;
66380 }
66381
66382 @@ -534,7 +534,7 @@ static void put_pipe_info(struct inode *inode, struct pipe_inode_info *pipe)
66383 int kill = 0;
66384
66385 spin_lock(&inode->i_lock);
66386 - if (!--pipe->files) {
66387 + if (atomic_dec_and_test(&pipe->files)) {
66388 inode->i_pipe = NULL;
66389 kill = 1;
66390 }
66391 @@ -551,11 +551,11 @@ pipe_release(struct inode *inode, struct file *file)
66392
66393 __pipe_lock(pipe);
66394 if (file->f_mode & FMODE_READ)
66395 - pipe->readers--;
66396 + atomic_dec(&pipe->readers);
66397 if (file->f_mode & FMODE_WRITE)
66398 - pipe->writers--;
66399 + atomic_dec(&pipe->writers);
66400
66401 - if (pipe->readers || pipe->writers) {
66402 + if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
66403 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
66404 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
66405 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
66406 @@ -620,7 +620,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
66407 kfree(pipe);
66408 }
66409
66410 -static struct vfsmount *pipe_mnt __read_mostly;
66411 +struct vfsmount *pipe_mnt __read_mostly;
66412
66413 /*
66414 * pipefs_dname() is called from d_path().
66415 @@ -650,8 +650,9 @@ static struct inode * get_pipe_inode(void)
66416 goto fail_iput;
66417
66418 inode->i_pipe = pipe;
66419 - pipe->files = 2;
66420 - pipe->readers = pipe->writers = 1;
66421 + atomic_set(&pipe->files, 2);
66422 + atomic_set(&pipe->readers, 1);
66423 + atomic_set(&pipe->writers, 1);
66424 inode->i_fop = &pipefifo_fops;
66425
66426 /*
66427 @@ -830,17 +831,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
66428 spin_lock(&inode->i_lock);
66429 if (inode->i_pipe) {
66430 pipe = inode->i_pipe;
66431 - pipe->files++;
66432 + atomic_inc(&pipe->files);
66433 spin_unlock(&inode->i_lock);
66434 } else {
66435 spin_unlock(&inode->i_lock);
66436 pipe = alloc_pipe_info();
66437 if (!pipe)
66438 return -ENOMEM;
66439 - pipe->files = 1;
66440 + atomic_set(&pipe->files, 1);
66441 spin_lock(&inode->i_lock);
66442 if (unlikely(inode->i_pipe)) {
66443 - inode->i_pipe->files++;
66444 + atomic_inc(&inode->i_pipe->files);
66445 spin_unlock(&inode->i_lock);
66446 free_pipe_info(pipe);
66447 pipe = inode->i_pipe;
66448 @@ -865,10 +866,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
66449 * opened, even when there is no process writing the FIFO.
66450 */
66451 pipe->r_counter++;
66452 - if (pipe->readers++ == 0)
66453 + if (atomic_inc_return(&pipe->readers) == 1)
66454 wake_up_partner(pipe);
66455
66456 - if (!is_pipe && !pipe->writers) {
66457 + if (!is_pipe && !atomic_read(&pipe->writers)) {
66458 if ((filp->f_flags & O_NONBLOCK)) {
66459 /* suppress POLLHUP until we have
66460 * seen a writer */
66461 @@ -887,14 +888,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
66462 * errno=ENXIO when there is no process reading the FIFO.
66463 */
66464 ret = -ENXIO;
66465 - if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
66466 + if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
66467 goto err;
66468
66469 pipe->w_counter++;
66470 - if (!pipe->writers++)
66471 + if (atomic_inc_return(&pipe->writers) == 1)
66472 wake_up_partner(pipe);
66473
66474 - if (!is_pipe && !pipe->readers) {
66475 + if (!is_pipe && !atomic_read(&pipe->readers)) {
66476 if (wait_for_partner(pipe, &pipe->r_counter))
66477 goto err_wr;
66478 }
66479 @@ -908,11 +909,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
66480 * the process can at least talk to itself.
66481 */
66482
66483 - pipe->readers++;
66484 - pipe->writers++;
66485 + atomic_inc(&pipe->readers);
66486 + atomic_inc(&pipe->writers);
66487 pipe->r_counter++;
66488 pipe->w_counter++;
66489 - if (pipe->readers == 1 || pipe->writers == 1)
66490 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
66491 wake_up_partner(pipe);
66492 break;
66493
66494 @@ -926,13 +927,13 @@ static int fifo_open(struct inode *inode, struct file *filp)
66495 return 0;
66496
66497 err_rd:
66498 - if (!--pipe->readers)
66499 + if (atomic_dec_and_test(&pipe->readers))
66500 wake_up_interruptible(&pipe->wait);
66501 ret = -ERESTARTSYS;
66502 goto err;
66503
66504 err_wr:
66505 - if (!--pipe->writers)
66506 + if (atomic_dec_and_test(&pipe->writers))
66507 wake_up_interruptible(&pipe->wait);
66508 ret = -ERESTARTSYS;
66509 goto err;
66510 diff --git a/fs/posix_acl.c b/fs/posix_acl.c
66511 index 0855f77..6787d50 100644
66512 --- a/fs/posix_acl.c
66513 +++ b/fs/posix_acl.c
66514 @@ -20,6 +20,7 @@
66515 #include <linux/xattr.h>
66516 #include <linux/export.h>
66517 #include <linux/user_namespace.h>
66518 +#include <linux/grsecurity.h>
66519
66520 struct posix_acl **acl_by_type(struct inode *inode, int type)
66521 {
66522 @@ -277,7 +278,7 @@ posix_acl_equiv_mode(const struct posix_acl *acl, umode_t *mode_p)
66523 }
66524 }
66525 if (mode_p)
66526 - *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
66527 + *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
66528 return not_equiv;
66529 }
66530 EXPORT_SYMBOL(posix_acl_equiv_mode);
66531 @@ -427,7 +428,7 @@ static int posix_acl_create_masq(struct posix_acl *acl, umode_t *mode_p)
66532 mode &= (group_obj->e_perm << 3) | ~S_IRWXG;
66533 }
66534
66535 - *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
66536 + *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
66537 return not_equiv;
66538 }
66539
66540 @@ -485,6 +486,8 @@ __posix_acl_create(struct posix_acl **acl, gfp_t gfp, umode_t *mode_p)
66541 struct posix_acl *clone = posix_acl_clone(*acl, gfp);
66542 int err = -ENOMEM;
66543 if (clone) {
66544 + *mode_p &= ~gr_acl_umask();
66545 +
66546 err = posix_acl_create_masq(clone, mode_p);
66547 if (err < 0) {
66548 posix_acl_release(clone);
66549 @@ -659,11 +662,12 @@ struct posix_acl *
66550 posix_acl_from_xattr(struct user_namespace *user_ns,
66551 const void *value, size_t size)
66552 {
66553 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
66554 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
66555 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
66556 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
66557 int count;
66558 struct posix_acl *acl;
66559 struct posix_acl_entry *acl_e;
66560 + umode_t umask = gr_acl_umask();
66561
66562 if (!value)
66563 return NULL;
66564 @@ -689,12 +693,18 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
66565
66566 switch(acl_e->e_tag) {
66567 case ACL_USER_OBJ:
66568 + acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
66569 + break;
66570 case ACL_GROUP_OBJ:
66571 case ACL_MASK:
66572 + acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
66573 + break;
66574 case ACL_OTHER:
66575 + acl_e->e_perm &= ~(umask & S_IRWXO);
66576 break;
66577
66578 case ACL_USER:
66579 + acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
66580 acl_e->e_uid =
66581 make_kuid(user_ns,
66582 le32_to_cpu(entry->e_id));
66583 @@ -702,6 +712,7 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
66584 goto fail;
66585 break;
66586 case ACL_GROUP:
66587 + acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
66588 acl_e->e_gid =
66589 make_kgid(user_ns,
66590 le32_to_cpu(entry->e_id));
66591 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
66592 index 2183fcf..3c32a98 100644
66593 --- a/fs/proc/Kconfig
66594 +++ b/fs/proc/Kconfig
66595 @@ -30,7 +30,7 @@ config PROC_FS
66596
66597 config PROC_KCORE
66598 bool "/proc/kcore support" if !ARM
66599 - depends on PROC_FS && MMU
66600 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
66601 help
66602 Provides a virtual ELF core file of the live kernel. This can
66603 be read with gdb and other ELF tools. No modifications can be
66604 @@ -38,8 +38,8 @@ config PROC_KCORE
66605
66606 config PROC_VMCORE
66607 bool "/proc/vmcore support"
66608 - depends on PROC_FS && CRASH_DUMP
66609 - default y
66610 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
66611 + default n
66612 help
66613 Exports the dump image of crashed kernel in ELF format.
66614
66615 @@ -63,8 +63,8 @@ config PROC_SYSCTL
66616 limited in memory.
66617
66618 config PROC_PAGE_MONITOR
66619 - default y
66620 - depends on PROC_FS && MMU
66621 + default n
66622 + depends on PROC_FS && MMU && !GRKERNSEC
66623 bool "Enable /proc page monitoring" if EXPERT
66624 help
66625 Various /proc files exist to monitor process memory utilization:
66626 diff --git a/fs/proc/array.c b/fs/proc/array.c
66627 index cd3653e..9b9b79a 100644
66628 --- a/fs/proc/array.c
66629 +++ b/fs/proc/array.c
66630 @@ -60,6 +60,7 @@
66631 #include <linux/tty.h>
66632 #include <linux/string.h>
66633 #include <linux/mman.h>
66634 +#include <linux/grsecurity.h>
66635 #include <linux/proc_fs.h>
66636 #include <linux/ioport.h>
66637 #include <linux/uaccess.h>
66638 @@ -347,6 +348,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
66639 seq_putc(m, '\n');
66640 }
66641
66642 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
66643 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
66644 +{
66645 + if (p->mm)
66646 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
66647 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
66648 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
66649 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
66650 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
66651 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
66652 + else
66653 + seq_printf(m, "PaX:\t-----\n");
66654 +}
66655 +#endif
66656 +
66657 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
66658 struct pid *pid, struct task_struct *task)
66659 {
66660 @@ -365,9 +381,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
66661 task_cpus_allowed(m, task);
66662 cpuset_task_status_allowed(m, task);
66663 task_context_switch_counts(m, task);
66664 +
66665 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
66666 + task_pax(m, task);
66667 +#endif
66668 +
66669 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
66670 + task_grsec_rbac(m, task);
66671 +#endif
66672 +
66673 return 0;
66674 }
66675
66676 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66677 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
66678 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
66679 + _mm->pax_flags & MF_PAX_SEGMEXEC))
66680 +#endif
66681 +
66682 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
66683 struct pid *pid, struct task_struct *task, int whole)
66684 {
66685 @@ -389,6 +420,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
66686 char tcomm[sizeof(task->comm)];
66687 unsigned long flags;
66688
66689 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66690 + if (current->exec_id != m->exec_id) {
66691 + gr_log_badprocpid("stat");
66692 + return 0;
66693 + }
66694 +#endif
66695 +
66696 state = *get_task_state(task);
66697 vsize = eip = esp = 0;
66698 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
66699 @@ -459,6 +497,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
66700 gtime = task_gtime(task);
66701 }
66702
66703 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66704 + if (PAX_RAND_FLAGS(mm)) {
66705 + eip = 0;
66706 + esp = 0;
66707 + wchan = 0;
66708 + }
66709 +#endif
66710 +#ifdef CONFIG_GRKERNSEC_HIDESYM
66711 + wchan = 0;
66712 + eip =0;
66713 + esp =0;
66714 +#endif
66715 +
66716 /* scale priority and nice values from timeslices to -20..20 */
66717 /* to make it look like a "normal" Unix priority/nice value */
66718 priority = task_prio(task);
66719 @@ -490,9 +541,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
66720 seq_put_decimal_ull(m, ' ', vsize);
66721 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
66722 seq_put_decimal_ull(m, ' ', rsslim);
66723 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66724 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
66725 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
66726 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
66727 +#else
66728 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
66729 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
66730 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
66731 +#endif
66732 seq_put_decimal_ull(m, ' ', esp);
66733 seq_put_decimal_ull(m, ' ', eip);
66734 /* The signal information here is obsolete.
66735 @@ -514,7 +571,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
66736 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
66737 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
66738
66739 - if (mm && permitted) {
66740 + if (mm && permitted
66741 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66742 + && !PAX_RAND_FLAGS(mm)
66743 +#endif
66744 + ) {
66745 seq_put_decimal_ull(m, ' ', mm->start_data);
66746 seq_put_decimal_ull(m, ' ', mm->end_data);
66747 seq_put_decimal_ull(m, ' ', mm->start_brk);
66748 @@ -552,8 +613,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
66749 struct pid *pid, struct task_struct *task)
66750 {
66751 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
66752 - struct mm_struct *mm = get_task_mm(task);
66753 + struct mm_struct *mm;
66754
66755 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66756 + if (current->exec_id != m->exec_id) {
66757 + gr_log_badprocpid("statm");
66758 + return 0;
66759 + }
66760 +#endif
66761 + mm = get_task_mm(task);
66762 if (mm) {
66763 size = task_statm(mm, &shared, &text, &data, &resident);
66764 mmput(mm);
66765 @@ -576,6 +644,20 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
66766 return 0;
66767 }
66768
66769 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
66770 +int proc_pid_ipaddr(struct seq_file *m, struct pid_namespace *ns, struct pid *pid, struct task_struct *task)
66771 +{
66772 + unsigned long flags;
66773 + u32 curr_ip = 0;
66774 +
66775 + if (lock_task_sighand(task, &flags)) {
66776 + curr_ip = task->signal->curr_ip;
66777 + unlock_task_sighand(task, &flags);
66778 + }
66779 + return seq_printf(m, "%pI4\n", &curr_ip);
66780 +}
66781 +#endif
66782 +
66783 #ifdef CONFIG_CHECKPOINT_RESTORE
66784 static struct pid *
66785 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
66786 diff --git a/fs/proc/base.c b/fs/proc/base.c
66787 index baf852b..03fe930 100644
66788 --- a/fs/proc/base.c
66789 +++ b/fs/proc/base.c
66790 @@ -113,6 +113,14 @@ struct pid_entry {
66791 union proc_op op;
66792 };
66793
66794 +struct getdents_callback {
66795 + struct linux_dirent __user * current_dir;
66796 + struct linux_dirent __user * previous;
66797 + struct file * file;
66798 + int count;
66799 + int error;
66800 +};
66801 +
66802 #define NOD(NAME, MODE, IOP, FOP, OP) { \
66803 .name = (NAME), \
66804 .len = sizeof(NAME) - 1, \
66805 @@ -208,12 +216,28 @@ static int proc_pid_cmdline(struct seq_file *m, struct pid_namespace *ns,
66806 return 0;
66807 }
66808
66809 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66810 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
66811 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
66812 + _mm->pax_flags & MF_PAX_SEGMEXEC))
66813 +#endif
66814 +
66815 static int proc_pid_auxv(struct seq_file *m, struct pid_namespace *ns,
66816 struct pid *pid, struct task_struct *task)
66817 {
66818 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
66819 if (mm && !IS_ERR(mm)) {
66820 unsigned int nwords = 0;
66821 +
66822 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66823 + /* allow if we're currently ptracing this task */
66824 + if (PAX_RAND_FLAGS(mm) &&
66825 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
66826 + mmput(mm);
66827 + return 0;
66828 + }
66829 +#endif
66830 +
66831 do {
66832 nwords += 2;
66833 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
66834 @@ -225,7 +249,7 @@ static int proc_pid_auxv(struct seq_file *m, struct pid_namespace *ns,
66835 }
66836
66837
66838 -#ifdef CONFIG_KALLSYMS
66839 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66840 /*
66841 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
66842 * Returns the resolved symbol. If that fails, simply return the address.
66843 @@ -265,7 +289,7 @@ static void unlock_trace(struct task_struct *task)
66844 mutex_unlock(&task->signal->cred_guard_mutex);
66845 }
66846
66847 -#ifdef CONFIG_STACKTRACE
66848 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66849
66850 #define MAX_STACK_TRACE_DEPTH 64
66851
66852 @@ -487,7 +511,7 @@ static int proc_pid_limits(struct seq_file *m, struct pid_namespace *ns,
66853 return 0;
66854 }
66855
66856 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
66857 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
66858 static int proc_pid_syscall(struct seq_file *m, struct pid_namespace *ns,
66859 struct pid *pid, struct task_struct *task)
66860 {
66861 @@ -517,7 +541,7 @@ static int proc_pid_syscall(struct seq_file *m, struct pid_namespace *ns,
66862 /************************************************************************/
66863
66864 /* permission checks */
66865 -static int proc_fd_access_allowed(struct inode *inode)
66866 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
66867 {
66868 struct task_struct *task;
66869 int allowed = 0;
66870 @@ -527,7 +551,10 @@ static int proc_fd_access_allowed(struct inode *inode)
66871 */
66872 task = get_proc_task(inode);
66873 if (task) {
66874 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
66875 + if (log)
66876 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
66877 + else
66878 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
66879 put_task_struct(task);
66880 }
66881 return allowed;
66882 @@ -558,10 +585,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
66883 struct task_struct *task,
66884 int hide_pid_min)
66885 {
66886 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
66887 + return false;
66888 +
66889 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66890 + rcu_read_lock();
66891 + {
66892 + const struct cred *tmpcred = current_cred();
66893 + const struct cred *cred = __task_cred(task);
66894 +
66895 + if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
66896 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66897 + || in_group_p(grsec_proc_gid)
66898 +#endif
66899 + ) {
66900 + rcu_read_unlock();
66901 + return true;
66902 + }
66903 + }
66904 + rcu_read_unlock();
66905 +
66906 + if (!pid->hide_pid)
66907 + return false;
66908 +#endif
66909 +
66910 if (pid->hide_pid < hide_pid_min)
66911 return true;
66912 if (in_group_p(pid->pid_gid))
66913 return true;
66914 +
66915 return ptrace_may_access(task, PTRACE_MODE_READ);
66916 }
66917
66918 @@ -579,7 +631,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
66919 put_task_struct(task);
66920
66921 if (!has_perms) {
66922 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66923 + {
66924 +#else
66925 if (pid->hide_pid == 2) {
66926 +#endif
66927 /*
66928 * Let's make getdents(), stat(), and open()
66929 * consistent with each other. If a process
66930 @@ -640,6 +696,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
66931 if (!task)
66932 return -ESRCH;
66933
66934 + if (gr_acl_handle_procpidmem(task)) {
66935 + put_task_struct(task);
66936 + return -EPERM;
66937 + }
66938 +
66939 mm = mm_access(task, mode);
66940 put_task_struct(task);
66941
66942 @@ -655,6 +716,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
66943
66944 file->private_data = mm;
66945
66946 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66947 + file->f_version = current->exec_id;
66948 +#endif
66949 +
66950 return 0;
66951 }
66952
66953 @@ -676,6 +741,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
66954 ssize_t copied;
66955 char *page;
66956
66957 +#ifdef CONFIG_GRKERNSEC
66958 + if (write)
66959 + return -EPERM;
66960 +#endif
66961 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66962 + if (file->f_version != current->exec_id) {
66963 + gr_log_badprocpid("mem");
66964 + return 0;
66965 + }
66966 +#endif
66967 +
66968 if (!mm)
66969 return 0;
66970
66971 @@ -688,7 +764,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
66972 goto free;
66973
66974 while (count > 0) {
66975 - int this_len = min_t(int, count, PAGE_SIZE);
66976 + ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
66977
66978 if (write && copy_from_user(page, buf, this_len)) {
66979 copied = -EFAULT;
66980 @@ -780,6 +856,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
66981 if (!mm)
66982 return 0;
66983
66984 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66985 + if (file->f_version != current->exec_id) {
66986 + gr_log_badprocpid("environ");
66987 + return 0;
66988 + }
66989 +#endif
66990 +
66991 page = (char *)__get_free_page(GFP_TEMPORARY);
66992 if (!page)
66993 return -ENOMEM;
66994 @@ -789,7 +872,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
66995 goto free;
66996 while (count > 0) {
66997 size_t this_len, max_len;
66998 - int retval;
66999 + ssize_t retval;
67000
67001 if (src >= (mm->env_end - mm->env_start))
67002 break;
67003 @@ -1403,7 +1486,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
67004 int error = -EACCES;
67005
67006 /* Are we allowed to snoop on the tasks file descriptors? */
67007 - if (!proc_fd_access_allowed(inode))
67008 + if (!proc_fd_access_allowed(inode, 0))
67009 goto out;
67010
67011 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
67012 @@ -1447,8 +1530,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
67013 struct path path;
67014
67015 /* Are we allowed to snoop on the tasks file descriptors? */
67016 - if (!proc_fd_access_allowed(inode))
67017 - goto out;
67018 + /* logging this is needed for learning on chromium to work properly,
67019 + but we don't want to flood the logs from 'ps' which does a readlink
67020 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
67021 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
67022 + */
67023 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
67024 + if (!proc_fd_access_allowed(inode,0))
67025 + goto out;
67026 + } else {
67027 + if (!proc_fd_access_allowed(inode,1))
67028 + goto out;
67029 + }
67030
67031 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
67032 if (error)
67033 @@ -1498,7 +1591,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
67034 rcu_read_lock();
67035 cred = __task_cred(task);
67036 inode->i_uid = cred->euid;
67037 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
67038 + inode->i_gid = grsec_proc_gid;
67039 +#else
67040 inode->i_gid = cred->egid;
67041 +#endif
67042 rcu_read_unlock();
67043 }
67044 security_task_to_inode(task, inode);
67045 @@ -1534,10 +1631,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
67046 return -ENOENT;
67047 }
67048 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
67049 +#ifdef CONFIG_GRKERNSEC_PROC_USER
67050 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
67051 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67052 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
67053 +#endif
67054 task_dumpable(task)) {
67055 cred = __task_cred(task);
67056 stat->uid = cred->euid;
67057 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
67058 + stat->gid = grsec_proc_gid;
67059 +#else
67060 stat->gid = cred->egid;
67061 +#endif
67062 }
67063 }
67064 rcu_read_unlock();
67065 @@ -1575,11 +1681,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
67066
67067 if (task) {
67068 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
67069 +#ifdef CONFIG_GRKERNSEC_PROC_USER
67070 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
67071 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67072 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
67073 +#endif
67074 task_dumpable(task)) {
67075 rcu_read_lock();
67076 cred = __task_cred(task);
67077 inode->i_uid = cred->euid;
67078 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
67079 + inode->i_gid = grsec_proc_gid;
67080 +#else
67081 inode->i_gid = cred->egid;
67082 +#endif
67083 rcu_read_unlock();
67084 } else {
67085 inode->i_uid = GLOBAL_ROOT_UID;
67086 @@ -2114,6 +2229,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
67087 if (!task)
67088 goto out_no_task;
67089
67090 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
67091 + goto out;
67092 +
67093 /*
67094 * Yes, it does not scale. And it should not. Don't add
67095 * new entries into /proc/<tgid>/ without very good reasons.
67096 @@ -2144,6 +2262,9 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
67097 if (!task)
67098 return -ENOENT;
67099
67100 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
67101 + goto out;
67102 +
67103 if (!dir_emit_dots(file, ctx))
67104 goto out;
67105
67106 @@ -2535,7 +2656,7 @@ static const struct pid_entry tgid_base_stuff[] = {
67107 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
67108 #endif
67109 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
67110 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
67111 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
67112 ONE("syscall", S_IRUSR, proc_pid_syscall),
67113 #endif
67114 ONE("cmdline", S_IRUGO, proc_pid_cmdline),
67115 @@ -2560,10 +2681,10 @@ static const struct pid_entry tgid_base_stuff[] = {
67116 #ifdef CONFIG_SECURITY
67117 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
67118 #endif
67119 -#ifdef CONFIG_KALLSYMS
67120 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
67121 ONE("wchan", S_IRUGO, proc_pid_wchan),
67122 #endif
67123 -#ifdef CONFIG_STACKTRACE
67124 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
67125 ONE("stack", S_IRUSR, proc_pid_stack),
67126 #endif
67127 #ifdef CONFIG_SCHEDSTATS
67128 @@ -2597,6 +2718,9 @@ static const struct pid_entry tgid_base_stuff[] = {
67129 #ifdef CONFIG_HARDWALL
67130 ONE("hardwall", S_IRUGO, proc_pid_hardwall),
67131 #endif
67132 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
67133 + ONE("ipaddr", S_IRUSR, proc_pid_ipaddr),
67134 +#endif
67135 #ifdef CONFIG_USER_NS
67136 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
67137 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
67138 @@ -2727,7 +2851,14 @@ static int proc_pid_instantiate(struct inode *dir,
67139 if (!inode)
67140 goto out;
67141
67142 +#ifdef CONFIG_GRKERNSEC_PROC_USER
67143 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
67144 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67145 + inode->i_gid = grsec_proc_gid;
67146 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
67147 +#else
67148 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
67149 +#endif
67150 inode->i_op = &proc_tgid_base_inode_operations;
67151 inode->i_fop = &proc_tgid_base_operations;
67152 inode->i_flags|=S_IMMUTABLE;
67153 @@ -2765,7 +2896,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
67154 if (!task)
67155 goto out;
67156
67157 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
67158 + goto out_put_task;
67159 +
67160 result = proc_pid_instantiate(dir, dentry, task, NULL);
67161 +out_put_task:
67162 put_task_struct(task);
67163 out:
67164 return ERR_PTR(result);
67165 @@ -2879,7 +3014,7 @@ static const struct pid_entry tid_base_stuff[] = {
67166 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
67167 #endif
67168 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
67169 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
67170 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
67171 ONE("syscall", S_IRUSR, proc_pid_syscall),
67172 #endif
67173 ONE("cmdline", S_IRUGO, proc_pid_cmdline),
67174 @@ -2906,10 +3041,10 @@ static const struct pid_entry tid_base_stuff[] = {
67175 #ifdef CONFIG_SECURITY
67176 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
67177 #endif
67178 -#ifdef CONFIG_KALLSYMS
67179 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
67180 ONE("wchan", S_IRUGO, proc_pid_wchan),
67181 #endif
67182 -#ifdef CONFIG_STACKTRACE
67183 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
67184 ONE("stack", S_IRUSR, proc_pid_stack),
67185 #endif
67186 #ifdef CONFIG_SCHEDSTATS
67187 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
67188 index cbd82df..c0407d2 100644
67189 --- a/fs/proc/cmdline.c
67190 +++ b/fs/proc/cmdline.c
67191 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
67192
67193 static int __init proc_cmdline_init(void)
67194 {
67195 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
67196 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
67197 +#else
67198 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
67199 +#endif
67200 return 0;
67201 }
67202 fs_initcall(proc_cmdline_init);
67203 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
67204 index 50493ed..248166b 100644
67205 --- a/fs/proc/devices.c
67206 +++ b/fs/proc/devices.c
67207 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
67208
67209 static int __init proc_devices_init(void)
67210 {
67211 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
67212 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
67213 +#else
67214 proc_create("devices", 0, NULL, &proc_devinfo_operations);
67215 +#endif
67216 return 0;
67217 }
67218 fs_initcall(proc_devices_init);
67219 diff --git a/fs/proc/fd.c b/fs/proc/fd.c
67220 index 955bb55..71948bd 100644
67221 --- a/fs/proc/fd.c
67222 +++ b/fs/proc/fd.c
67223 @@ -26,7 +26,8 @@ static int seq_show(struct seq_file *m, void *v)
67224 if (!task)
67225 return -ENOENT;
67226
67227 - files = get_files_struct(task);
67228 + if (!gr_acl_handle_procpidmem(task))
67229 + files = get_files_struct(task);
67230 put_task_struct(task);
67231
67232 if (files) {
67233 @@ -285,11 +286,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
67234 */
67235 int proc_fd_permission(struct inode *inode, int mask)
67236 {
67237 + struct task_struct *task;
67238 int rv = generic_permission(inode, mask);
67239 - if (rv == 0)
67240 - return 0;
67241 +
67242 if (task_tgid(current) == proc_pid(inode))
67243 rv = 0;
67244 +
67245 + task = get_proc_task(inode);
67246 + if (task == NULL)
67247 + return rv;
67248 +
67249 + if (gr_acl_handle_procpidmem(task))
67250 + rv = -EACCES;
67251 +
67252 + put_task_struct(task);
67253 +
67254 return rv;
67255 }
67256
67257 diff --git a/fs/proc/generic.c b/fs/proc/generic.c
67258 index 317b726..e329aed 100644
67259 --- a/fs/proc/generic.c
67260 +++ b/fs/proc/generic.c
67261 @@ -23,6 +23,7 @@
67262 #include <linux/bitops.h>
67263 #include <linux/spinlock.h>
67264 #include <linux/completion.h>
67265 +#include <linux/grsecurity.h>
67266 #include <asm/uaccess.h>
67267
67268 #include "internal.h"
67269 @@ -207,6 +208,15 @@ struct dentry *proc_lookup(struct inode *dir, struct dentry *dentry,
67270 return proc_lookup_de(PDE(dir), dir, dentry);
67271 }
67272
67273 +struct dentry *proc_lookup_restrict(struct inode *dir, struct dentry *dentry,
67274 + unsigned int flags)
67275 +{
67276 + if (gr_proc_is_restricted())
67277 + return ERR_PTR(-EACCES);
67278 +
67279 + return proc_lookup_de(PDE(dir), dir, dentry);
67280 +}
67281 +
67282 /*
67283 * This returns non-zero if at EOF, so that the /proc
67284 * root directory can use this and check if it should
67285 @@ -264,6 +274,16 @@ int proc_readdir(struct file *file, struct dir_context *ctx)
67286 return proc_readdir_de(PDE(inode), file, ctx);
67287 }
67288
67289 +int proc_readdir_restrict(struct file *file, struct dir_context *ctx)
67290 +{
67291 + struct inode *inode = file_inode(file);
67292 +
67293 + if (gr_proc_is_restricted())
67294 + return -EACCES;
67295 +
67296 + return proc_readdir_de(PDE(inode), file, ctx);
67297 +}
67298 +
67299 /*
67300 * These are the generic /proc directory operations. They
67301 * use the in-memory "struct proc_dir_entry" tree to parse
67302 @@ -275,6 +295,12 @@ static const struct file_operations proc_dir_operations = {
67303 .iterate = proc_readdir,
67304 };
67305
67306 +static const struct file_operations proc_dir_restricted_operations = {
67307 + .llseek = generic_file_llseek,
67308 + .read = generic_read_dir,
67309 + .iterate = proc_readdir_restrict,
67310 +};
67311 +
67312 /*
67313 * proc directories can do almost nothing..
67314 */
67315 @@ -284,6 +310,12 @@ static const struct inode_operations proc_dir_inode_operations = {
67316 .setattr = proc_notify_change,
67317 };
67318
67319 +static const struct inode_operations proc_dir_restricted_inode_operations = {
67320 + .lookup = proc_lookup_restrict,
67321 + .getattr = proc_getattr,
67322 + .setattr = proc_notify_change,
67323 +};
67324 +
67325 static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp)
67326 {
67327 struct proc_dir_entry *tmp;
67328 @@ -294,8 +326,13 @@ static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp
67329 return ret;
67330
67331 if (S_ISDIR(dp->mode)) {
67332 - dp->proc_fops = &proc_dir_operations;
67333 - dp->proc_iops = &proc_dir_inode_operations;
67334 + if (dp->restricted) {
67335 + dp->proc_fops = &proc_dir_restricted_operations;
67336 + dp->proc_iops = &proc_dir_restricted_inode_operations;
67337 + } else {
67338 + dp->proc_fops = &proc_dir_operations;
67339 + dp->proc_iops = &proc_dir_inode_operations;
67340 + }
67341 dir->nlink++;
67342 } else if (S_ISLNK(dp->mode)) {
67343 dp->proc_iops = &proc_link_inode_operations;
67344 @@ -407,6 +444,27 @@ struct proc_dir_entry *proc_mkdir_data(const char *name, umode_t mode,
67345 }
67346 EXPORT_SYMBOL_GPL(proc_mkdir_data);
67347
67348 +struct proc_dir_entry *proc_mkdir_data_restrict(const char *name, umode_t mode,
67349 + struct proc_dir_entry *parent, void *data)
67350 +{
67351 + struct proc_dir_entry *ent;
67352 +
67353 + if (mode == 0)
67354 + mode = S_IRUGO | S_IXUGO;
67355 +
67356 + ent = __proc_create(&parent, name, S_IFDIR | mode, 2);
67357 + if (ent) {
67358 + ent->data = data;
67359 + ent->restricted = 1;
67360 + if (proc_register(parent, ent) < 0) {
67361 + kfree(ent);
67362 + ent = NULL;
67363 + }
67364 + }
67365 + return ent;
67366 +}
67367 +EXPORT_SYMBOL_GPL(proc_mkdir_data_restrict);
67368 +
67369 struct proc_dir_entry *proc_mkdir_mode(const char *name, umode_t mode,
67370 struct proc_dir_entry *parent)
67371 {
67372 @@ -421,6 +479,13 @@ struct proc_dir_entry *proc_mkdir(const char *name,
67373 }
67374 EXPORT_SYMBOL(proc_mkdir);
67375
67376 +struct proc_dir_entry *proc_mkdir_restrict(const char *name,
67377 + struct proc_dir_entry *parent)
67378 +{
67379 + return proc_mkdir_data_restrict(name, 0, parent, NULL);
67380 +}
67381 +EXPORT_SYMBOL(proc_mkdir_restrict);
67382 +
67383 struct proc_dir_entry *proc_create_data(const char *name, umode_t mode,
67384 struct proc_dir_entry *parent,
67385 const struct file_operations *proc_fops,
67386 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
67387 index 333080d..0a35ec4 100644
67388 --- a/fs/proc/inode.c
67389 +++ b/fs/proc/inode.c
67390 @@ -23,11 +23,17 @@
67391 #include <linux/slab.h>
67392 #include <linux/mount.h>
67393 #include <linux/magic.h>
67394 +#include <linux/grsecurity.h>
67395
67396 #include <asm/uaccess.h>
67397
67398 #include "internal.h"
67399
67400 +#ifdef CONFIG_PROC_SYSCTL
67401 +extern const struct inode_operations proc_sys_inode_operations;
67402 +extern const struct inode_operations proc_sys_dir_operations;
67403 +#endif
67404 +
67405 static void proc_evict_inode(struct inode *inode)
67406 {
67407 struct proc_dir_entry *de;
67408 @@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
67409 ns = PROC_I(inode)->ns.ns;
67410 if (ns_ops && ns)
67411 ns_ops->put(ns);
67412 +
67413 +#ifdef CONFIG_PROC_SYSCTL
67414 + if (inode->i_op == &proc_sys_inode_operations ||
67415 + inode->i_op == &proc_sys_dir_operations)
67416 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
67417 +#endif
67418 +
67419 }
67420
67421 static struct kmem_cache * proc_inode_cachep;
67422 @@ -413,7 +426,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
67423 if (de->mode) {
67424 inode->i_mode = de->mode;
67425 inode->i_uid = de->uid;
67426 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
67427 + inode->i_gid = grsec_proc_gid;
67428 +#else
67429 inode->i_gid = de->gid;
67430 +#endif
67431 }
67432 if (de->size)
67433 inode->i_size = de->size;
67434 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
67435 index 7da13e4..68d0981 100644
67436 --- a/fs/proc/internal.h
67437 +++ b/fs/proc/internal.h
67438 @@ -46,9 +46,10 @@ struct proc_dir_entry {
67439 struct completion *pde_unload_completion;
67440 struct list_head pde_openers; /* who did ->open, but not ->release */
67441 spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
67442 + u8 restricted; /* a directory in /proc/net that should be restricted via GRKERNSEC_PROC */
67443 u8 namelen;
67444 char name[];
67445 -};
67446 +} __randomize_layout;
67447
67448 union proc_op {
67449 int (*proc_get_link)(struct dentry *, struct path *);
67450 @@ -66,7 +67,7 @@ struct proc_inode {
67451 struct ctl_table *sysctl_entry;
67452 struct proc_ns ns;
67453 struct inode vfs_inode;
67454 -};
67455 +} __randomize_layout;
67456
67457 /*
67458 * General functions
67459 @@ -154,6 +155,10 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
67460 struct pid *, struct task_struct *);
67461 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
67462 struct pid *, struct task_struct *);
67463 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
67464 +extern int proc_pid_ipaddr(struct seq_file *, struct pid_namespace *,
67465 + struct pid *, struct task_struct *);
67466 +#endif
67467
67468 /*
67469 * base.c
67470 @@ -178,9 +183,11 @@ extern bool proc_fill_cache(struct file *, struct dir_context *, const char *, i
67471 * generic.c
67472 */
67473 extern struct dentry *proc_lookup(struct inode *, struct dentry *, unsigned int);
67474 +extern struct dentry *proc_lookup_restrict(struct inode *, struct dentry *, unsigned int);
67475 extern struct dentry *proc_lookup_de(struct proc_dir_entry *, struct inode *,
67476 struct dentry *);
67477 extern int proc_readdir(struct file *, struct dir_context *);
67478 +extern int proc_readdir_restrict(struct file *, struct dir_context *);
67479 extern int proc_readdir_de(struct proc_dir_entry *, struct file *, struct dir_context *);
67480
67481 static inline struct proc_dir_entry *pde_get(struct proc_dir_entry *pde)
67482 diff --git a/fs/proc/interrupts.c b/fs/proc/interrupts.c
67483 index a352d57..cb94a5c 100644
67484 --- a/fs/proc/interrupts.c
67485 +++ b/fs/proc/interrupts.c
67486 @@ -47,7 +47,11 @@ static const struct file_operations proc_interrupts_operations = {
67487
67488 static int __init proc_interrupts_init(void)
67489 {
67490 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
67491 + proc_create_grsec("interrupts", 0, NULL, &proc_interrupts_operations);
67492 +#else
67493 proc_create("interrupts", 0, NULL, &proc_interrupts_operations);
67494 +#endif
67495 return 0;
67496 }
67497 fs_initcall(proc_interrupts_init);
67498 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
67499 index 6df8d07..3321060 100644
67500 --- a/fs/proc/kcore.c
67501 +++ b/fs/proc/kcore.c
67502 @@ -483,9 +483,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
67503 * the addresses in the elf_phdr on our list.
67504 */
67505 start = kc_offset_to_vaddr(*fpos - elf_buflen);
67506 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
67507 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
67508 + if (tsz > buflen)
67509 tsz = buflen;
67510 -
67511 +
67512 while (buflen) {
67513 struct kcore_list *m;
67514
67515 @@ -514,20 +515,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
67516 kfree(elf_buf);
67517 } else {
67518 if (kern_addr_valid(start)) {
67519 - unsigned long n;
67520 + char *elf_buf;
67521 + mm_segment_t oldfs;
67522
67523 - n = copy_to_user(buffer, (char *)start, tsz);
67524 - /*
67525 - * We cannot distinguish between fault on source
67526 - * and fault on destination. When this happens
67527 - * we clear too and hope it will trigger the
67528 - * EFAULT again.
67529 - */
67530 - if (n) {
67531 - if (clear_user(buffer + tsz - n,
67532 - n))
67533 + elf_buf = kmalloc(tsz, GFP_KERNEL);
67534 + if (!elf_buf)
67535 + return -ENOMEM;
67536 + oldfs = get_fs();
67537 + set_fs(KERNEL_DS);
67538 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
67539 + set_fs(oldfs);
67540 + if (copy_to_user(buffer, elf_buf, tsz)) {
67541 + kfree(elf_buf);
67542 return -EFAULT;
67543 + }
67544 }
67545 + set_fs(oldfs);
67546 + kfree(elf_buf);
67547 } else {
67548 if (clear_user(buffer, tsz))
67549 return -EFAULT;
67550 @@ -547,6 +551,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
67551
67552 static int open_kcore(struct inode *inode, struct file *filp)
67553 {
67554 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
67555 + return -EPERM;
67556 +#endif
67557 if (!capable(CAP_SYS_RAWIO))
67558 return -EPERM;
67559 if (kcore_need_update)
67560 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
67561 index aa1eee0..03dda72 100644
67562 --- a/fs/proc/meminfo.c
67563 +++ b/fs/proc/meminfo.c
67564 @@ -187,7 +187,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
67565 vmi.used >> 10,
67566 vmi.largest_chunk >> 10
67567 #ifdef CONFIG_MEMORY_FAILURE
67568 - ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
67569 + ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
67570 #endif
67571 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
67572 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
67573 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
67574 index d4a3574..b421ce9 100644
67575 --- a/fs/proc/nommu.c
67576 +++ b/fs/proc/nommu.c
67577 @@ -64,7 +64,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
67578
67579 if (file) {
67580 seq_pad(m, ' ');
67581 - seq_path(m, &file->f_path, "");
67582 + seq_path(m, &file->f_path, "\n\\");
67583 }
67584
67585 seq_putc(m, '\n');
67586 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
67587 index a63af3e..b4f262a 100644
67588 --- a/fs/proc/proc_net.c
67589 +++ b/fs/proc/proc_net.c
67590 @@ -23,9 +23,27 @@
67591 #include <linux/nsproxy.h>
67592 #include <net/net_namespace.h>
67593 #include <linux/seq_file.h>
67594 +#include <linux/grsecurity.h>
67595
67596 #include "internal.h"
67597
67598 +#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
67599 +static struct seq_operations *ipv6_seq_ops_addr;
67600 +
67601 +void register_ipv6_seq_ops_addr(struct seq_operations *addr)
67602 +{
67603 + ipv6_seq_ops_addr = addr;
67604 +}
67605 +
67606 +void unregister_ipv6_seq_ops_addr(void)
67607 +{
67608 + ipv6_seq_ops_addr = NULL;
67609 +}
67610 +
67611 +EXPORT_SYMBOL_GPL(register_ipv6_seq_ops_addr);
67612 +EXPORT_SYMBOL_GPL(unregister_ipv6_seq_ops_addr);
67613 +#endif
67614 +
67615 static inline struct net *PDE_NET(struct proc_dir_entry *pde)
67616 {
67617 return pde->parent->data;
67618 @@ -36,6 +54,8 @@ static struct net *get_proc_net(const struct inode *inode)
67619 return maybe_get_net(PDE_NET(PDE(inode)));
67620 }
67621
67622 +extern const struct seq_operations dev_seq_ops;
67623 +
67624 int seq_open_net(struct inode *ino, struct file *f,
67625 const struct seq_operations *ops, int size)
67626 {
67627 @@ -44,6 +64,14 @@ int seq_open_net(struct inode *ino, struct file *f,
67628
67629 BUG_ON(size < sizeof(*p));
67630
67631 + /* only permit access to /proc/net/dev */
67632 + if (
67633 +#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
67634 + ops != ipv6_seq_ops_addr &&
67635 +#endif
67636 + ops != &dev_seq_ops && gr_proc_is_restricted())
67637 + return -EACCES;
67638 +
67639 net = get_proc_net(ino);
67640 if (net == NULL)
67641 return -ENXIO;
67642 @@ -66,6 +94,9 @@ int single_open_net(struct inode *inode, struct file *file,
67643 int err;
67644 struct net *net;
67645
67646 + if (gr_proc_is_restricted())
67647 + return -EACCES;
67648 +
67649 err = -ENXIO;
67650 net = get_proc_net(inode);
67651 if (net == NULL)
67652 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
67653 index f92d5dd..26398ac 100644
67654 --- a/fs/proc/proc_sysctl.c
67655 +++ b/fs/proc/proc_sysctl.c
67656 @@ -11,13 +11,21 @@
67657 #include <linux/namei.h>
67658 #include <linux/mm.h>
67659 #include <linux/module.h>
67660 +#include <linux/nsproxy.h>
67661 +#ifdef CONFIG_GRKERNSEC
67662 +#include <net/net_namespace.h>
67663 +#endif
67664 #include "internal.h"
67665
67666 +extern int gr_handle_chroot_sysctl(const int op);
67667 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
67668 + const int op);
67669 +
67670 static const struct dentry_operations proc_sys_dentry_operations;
67671 static const struct file_operations proc_sys_file_operations;
67672 -static const struct inode_operations proc_sys_inode_operations;
67673 +const struct inode_operations proc_sys_inode_operations;
67674 static const struct file_operations proc_sys_dir_file_operations;
67675 -static const struct inode_operations proc_sys_dir_operations;
67676 +const struct inode_operations proc_sys_dir_operations;
67677
67678 void proc_sys_poll_notify(struct ctl_table_poll *poll)
67679 {
67680 @@ -467,6 +475,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
67681
67682 err = NULL;
67683 d_set_d_op(dentry, &proc_sys_dentry_operations);
67684 +
67685 + gr_handle_proc_create(dentry, inode);
67686 +
67687 d_add(dentry, inode);
67688
67689 out:
67690 @@ -482,6 +493,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
67691 struct inode *inode = file_inode(filp);
67692 struct ctl_table_header *head = grab_header(inode);
67693 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
67694 + int op = write ? MAY_WRITE : MAY_READ;
67695 ssize_t error;
67696 size_t res;
67697
67698 @@ -493,7 +505,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
67699 * and won't be until we finish.
67700 */
67701 error = -EPERM;
67702 - if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
67703 + if (sysctl_perm(head, table, op))
67704 goto out;
67705
67706 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
67707 @@ -501,6 +513,27 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
67708 if (!table->proc_handler)
67709 goto out;
67710
67711 +#ifdef CONFIG_GRKERNSEC
67712 + error = -EPERM;
67713 + if (gr_handle_chroot_sysctl(op))
67714 + goto out;
67715 + dget(filp->f_path.dentry);
67716 + if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
67717 + dput(filp->f_path.dentry);
67718 + goto out;
67719 + }
67720 + dput(filp->f_path.dentry);
67721 + if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
67722 + goto out;
67723 + if (write) {
67724 + if (current->nsproxy->net_ns != table->extra2) {
67725 + if (!capable(CAP_SYS_ADMIN))
67726 + goto out;
67727 + } else if (!ns_capable(current->nsproxy->net_ns->user_ns, CAP_NET_ADMIN))
67728 + goto out;
67729 + }
67730 +#endif
67731 +
67732 /* careful: calling conventions are nasty here */
67733 res = count;
67734 error = table->proc_handler(table, write, buf, &res, ppos);
67735 @@ -598,6 +631,9 @@ static bool proc_sys_fill_cache(struct file *file,
67736 return false;
67737 } else {
67738 d_set_d_op(child, &proc_sys_dentry_operations);
67739 +
67740 + gr_handle_proc_create(child, inode);
67741 +
67742 d_add(child, inode);
67743 }
67744 } else {
67745 @@ -641,6 +677,9 @@ static int scan(struct ctl_table_header *head, struct ctl_table *table,
67746 if ((*pos)++ < ctx->pos)
67747 return true;
67748
67749 + if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
67750 + return 0;
67751 +
67752 if (unlikely(S_ISLNK(table->mode)))
67753 res = proc_sys_link_fill_cache(file, ctx, head, table);
67754 else
67755 @@ -734,6 +773,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
67756 if (IS_ERR(head))
67757 return PTR_ERR(head);
67758
67759 + if (table && !gr_acl_handle_hidden_file(dentry, mnt))
67760 + return -ENOENT;
67761 +
67762 generic_fillattr(inode, stat);
67763 if (table)
67764 stat->mode = (stat->mode & S_IFMT) | table->mode;
67765 @@ -756,13 +798,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
67766 .llseek = generic_file_llseek,
67767 };
67768
67769 -static const struct inode_operations proc_sys_inode_operations = {
67770 +const struct inode_operations proc_sys_inode_operations = {
67771 .permission = proc_sys_permission,
67772 .setattr = proc_sys_setattr,
67773 .getattr = proc_sys_getattr,
67774 };
67775
67776 -static const struct inode_operations proc_sys_dir_operations = {
67777 +const struct inode_operations proc_sys_dir_operations = {
67778 .lookup = proc_sys_lookup,
67779 .permission = proc_sys_permission,
67780 .setattr = proc_sys_setattr,
67781 @@ -839,7 +881,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
67782 static struct ctl_dir *new_dir(struct ctl_table_set *set,
67783 const char *name, int namelen)
67784 {
67785 - struct ctl_table *table;
67786 + ctl_table_no_const *table;
67787 struct ctl_dir *new;
67788 struct ctl_node *node;
67789 char *new_name;
67790 @@ -851,7 +893,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
67791 return NULL;
67792
67793 node = (struct ctl_node *)(new + 1);
67794 - table = (struct ctl_table *)(node + 1);
67795 + table = (ctl_table_no_const *)(node + 1);
67796 new_name = (char *)(table + 2);
67797 memcpy(new_name, name, namelen);
67798 new_name[namelen] = '\0';
67799 @@ -1020,7 +1062,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
67800 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
67801 struct ctl_table_root *link_root)
67802 {
67803 - struct ctl_table *link_table, *entry, *link;
67804 + ctl_table_no_const *link_table, *link;
67805 + struct ctl_table *entry;
67806 struct ctl_table_header *links;
67807 struct ctl_node *node;
67808 char *link_name;
67809 @@ -1043,7 +1086,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
67810 return NULL;
67811
67812 node = (struct ctl_node *)(links + 1);
67813 - link_table = (struct ctl_table *)(node + nr_entries);
67814 + link_table = (ctl_table_no_const *)(node + nr_entries);
67815 link_name = (char *)&link_table[nr_entries + 1];
67816
67817 for (link = link_table, entry = table; entry->procname; link++, entry++) {
67818 @@ -1291,8 +1334,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
67819 struct ctl_table_header ***subheader, struct ctl_table_set *set,
67820 struct ctl_table *table)
67821 {
67822 - struct ctl_table *ctl_table_arg = NULL;
67823 - struct ctl_table *entry, *files;
67824 + ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
67825 + struct ctl_table *entry;
67826 int nr_files = 0;
67827 int nr_dirs = 0;
67828 int err = -ENOMEM;
67829 @@ -1304,10 +1347,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
67830 nr_files++;
67831 }
67832
67833 - files = table;
67834 /* If there are mixed files and directories we need a new table */
67835 if (nr_dirs && nr_files) {
67836 - struct ctl_table *new;
67837 + ctl_table_no_const *new;
67838 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
67839 GFP_KERNEL);
67840 if (!files)
67841 @@ -1325,7 +1367,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
67842 /* Register everything except a directory full of subdirectories */
67843 if (nr_files || !nr_dirs) {
67844 struct ctl_table_header *header;
67845 - header = __register_sysctl_table(set, path, files);
67846 + header = __register_sysctl_table(set, path, files ? files : table);
67847 if (!header) {
67848 kfree(ctl_table_arg);
67849 goto out;
67850 diff --git a/fs/proc/root.c b/fs/proc/root.c
67851 index 094e44d..085a877 100644
67852 --- a/fs/proc/root.c
67853 +++ b/fs/proc/root.c
67854 @@ -188,7 +188,15 @@ void __init proc_root_init(void)
67855 proc_mkdir("openprom", NULL);
67856 #endif
67857 proc_tty_init();
67858 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
67859 +#ifdef CONFIG_GRKERNSEC_PROC_USER
67860 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
67861 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67862 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
67863 +#endif
67864 +#else
67865 proc_mkdir("bus", NULL);
67866 +#endif
67867 proc_sys_init();
67868 }
67869
67870 diff --git a/fs/proc/stat.c b/fs/proc/stat.c
67871 index bf2d03f..f058f9c 100644
67872 --- a/fs/proc/stat.c
67873 +++ b/fs/proc/stat.c
67874 @@ -11,6 +11,7 @@
67875 #include <linux/irqnr.h>
67876 #include <linux/cputime.h>
67877 #include <linux/tick.h>
67878 +#include <linux/grsecurity.h>
67879
67880 #ifndef arch_irq_stat_cpu
67881 #define arch_irq_stat_cpu(cpu) 0
67882 @@ -87,6 +88,18 @@ static int show_stat(struct seq_file *p, void *v)
67883 u64 sum_softirq = 0;
67884 unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
67885 struct timespec boottime;
67886 + int unrestricted = 1;
67887 +
67888 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
67889 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67890 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
67891 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
67892 + && !in_group_p(grsec_proc_gid)
67893 +#endif
67894 + )
67895 + unrestricted = 0;
67896 +#endif
67897 +#endif
67898
67899 user = nice = system = idle = iowait =
67900 irq = softirq = steal = 0;
67901 @@ -99,23 +112,25 @@ static int show_stat(struct seq_file *p, void *v)
67902 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
67903 system += kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
67904 idle += get_idle_time(i);
67905 - iowait += get_iowait_time(i);
67906 - irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
67907 - softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
67908 - steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
67909 - guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
67910 - guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
67911 - sum += kstat_cpu_irqs_sum(i);
67912 - sum += arch_irq_stat_cpu(i);
67913 + if (unrestricted) {
67914 + iowait += get_iowait_time(i);
67915 + irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
67916 + softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
67917 + steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
67918 + guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
67919 + guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
67920 + sum += kstat_cpu_irqs_sum(i);
67921 + sum += arch_irq_stat_cpu(i);
67922 + for (j = 0; j < NR_SOFTIRQS; j++) {
67923 + unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
67924
67925 - for (j = 0; j < NR_SOFTIRQS; j++) {
67926 - unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
67927 -
67928 - per_softirq_sums[j] += softirq_stat;
67929 - sum_softirq += softirq_stat;
67930 + per_softirq_sums[j] += softirq_stat;
67931 + sum_softirq += softirq_stat;
67932 + }
67933 }
67934 }
67935 - sum += arch_irq_stat();
67936 + if (unrestricted)
67937 + sum += arch_irq_stat();
67938
67939 seq_puts(p, "cpu ");
67940 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
67941 @@ -136,12 +151,14 @@ static int show_stat(struct seq_file *p, void *v)
67942 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
67943 system = kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
67944 idle = get_idle_time(i);
67945 - iowait = get_iowait_time(i);
67946 - irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
67947 - softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
67948 - steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
67949 - guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
67950 - guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
67951 + if (unrestricted) {
67952 + iowait = get_iowait_time(i);
67953 + irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
67954 + softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
67955 + steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
67956 + guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
67957 + guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
67958 + }
67959 seq_printf(p, "cpu%d", i);
67960 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
67961 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(nice));
67962 @@ -159,7 +176,7 @@ static int show_stat(struct seq_file *p, void *v)
67963
67964 /* sum again ? it could be updated? */
67965 for_each_irq_nr(j)
67966 - seq_put_decimal_ull(p, ' ', kstat_irqs(j));
67967 + seq_put_decimal_ull(p, ' ', unrestricted ? kstat_irqs(j) : 0ULL);
67968
67969 seq_printf(p,
67970 "\nctxt %llu\n"
67971 @@ -167,11 +184,11 @@ static int show_stat(struct seq_file *p, void *v)
67972 "processes %lu\n"
67973 "procs_running %lu\n"
67974 "procs_blocked %lu\n",
67975 - nr_context_switches(),
67976 + unrestricted ? nr_context_switches() : 0ULL,
67977 (unsigned long)jif,
67978 - total_forks,
67979 - nr_running(),
67980 - nr_iowait());
67981 + unrestricted ? total_forks : 0UL,
67982 + unrestricted ? nr_running() : 0UL,
67983 + unrestricted ? nr_iowait() : 0UL);
67984
67985 seq_printf(p, "softirq %llu", (unsigned long long)sum_softirq);
67986
67987 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
67988 index c341568..75852a2 100644
67989 --- a/fs/proc/task_mmu.c
67990 +++ b/fs/proc/task_mmu.c
67991 @@ -13,12 +13,19 @@
67992 #include <linux/swap.h>
67993 #include <linux/swapops.h>
67994 #include <linux/mmu_notifier.h>
67995 +#include <linux/grsecurity.h>
67996
67997 #include <asm/elf.h>
67998 #include <asm/uaccess.h>
67999 #include <asm/tlbflush.h>
68000 #include "internal.h"
68001
68002 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
68003 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
68004 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
68005 + _mm->pax_flags & MF_PAX_SEGMEXEC))
68006 +#endif
68007 +
68008 void task_mem(struct seq_file *m, struct mm_struct *mm)
68009 {
68010 unsigned long data, text, lib, swap;
68011 @@ -54,8 +61,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
68012 "VmExe:\t%8lu kB\n"
68013 "VmLib:\t%8lu kB\n"
68014 "VmPTE:\t%8lu kB\n"
68015 - "VmSwap:\t%8lu kB\n",
68016 - hiwater_vm << (PAGE_SHIFT-10),
68017 + "VmSwap:\t%8lu kB\n"
68018 +
68019 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
68020 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
68021 +#endif
68022 +
68023 + ,hiwater_vm << (PAGE_SHIFT-10),
68024 total_vm << (PAGE_SHIFT-10),
68025 mm->locked_vm << (PAGE_SHIFT-10),
68026 mm->pinned_vm << (PAGE_SHIFT-10),
68027 @@ -65,7 +77,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
68028 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
68029 (PTRS_PER_PTE * sizeof(pte_t) *
68030 atomic_long_read(&mm->nr_ptes)) >> 10,
68031 - swap << (PAGE_SHIFT-10));
68032 + swap << (PAGE_SHIFT-10)
68033 +
68034 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
68035 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
68036 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
68037 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
68038 +#else
68039 + , mm->context.user_cs_base
68040 + , mm->context.user_cs_limit
68041 +#endif
68042 +#endif
68043 +
68044 + );
68045 }
68046
68047 unsigned long task_vsize(struct mm_struct *mm)
68048 @@ -271,13 +295,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
68049 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
68050 }
68051
68052 - /* We don't show the stack guard page in /proc/maps */
68053 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
68054 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
68055 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
68056 +#else
68057 start = vma->vm_start;
68058 - if (stack_guard_page_start(vma, start))
68059 - start += PAGE_SIZE;
68060 end = vma->vm_end;
68061 - if (stack_guard_page_end(vma, end))
68062 - end -= PAGE_SIZE;
68063 +#endif
68064
68065 seq_setwidth(m, 25 + sizeof(void *) * 6 - 1);
68066 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu ",
68067 @@ -287,7 +311,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
68068 flags & VM_WRITE ? 'w' : '-',
68069 flags & VM_EXEC ? 'x' : '-',
68070 flags & VM_MAYSHARE ? 's' : 'p',
68071 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
68072 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
68073 +#else
68074 pgoff,
68075 +#endif
68076 MAJOR(dev), MINOR(dev), ino);
68077
68078 /*
68079 @@ -296,7 +324,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
68080 */
68081 if (file) {
68082 seq_pad(m, ' ');
68083 - seq_path(m, &file->f_path, "\n");
68084 + seq_path(m, &file->f_path, "\n\\");
68085 goto done;
68086 }
68087
68088 @@ -328,8 +356,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
68089 * Thread stack in /proc/PID/task/TID/maps or
68090 * the main process stack.
68091 */
68092 - if (!is_pid || (vma->vm_start <= mm->start_stack &&
68093 - vma->vm_end >= mm->start_stack)) {
68094 + if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
68095 + (vma->vm_start <= mm->start_stack &&
68096 + vma->vm_end >= mm->start_stack)) {
68097 name = "[stack]";
68098 } else {
68099 /* Thread stack in /proc/PID/maps */
68100 @@ -353,6 +382,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
68101 struct proc_maps_private *priv = m->private;
68102 struct task_struct *task = priv->task;
68103
68104 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
68105 + if (current->exec_id != m->exec_id) {
68106 + gr_log_badprocpid("maps");
68107 + return 0;
68108 + }
68109 +#endif
68110 +
68111 show_map_vma(m, vma, is_pid);
68112
68113 if (m->count < m->size) /* vma is copied successfully */
68114 @@ -593,12 +629,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
68115 .private = &mss,
68116 };
68117
68118 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
68119 + if (current->exec_id != m->exec_id) {
68120 + gr_log_badprocpid("smaps");
68121 + return 0;
68122 + }
68123 +#endif
68124 memset(&mss, 0, sizeof mss);
68125 - mss.vma = vma;
68126 - /* mmap_sem is held in m_start */
68127 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
68128 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
68129 -
68130 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
68131 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
68132 +#endif
68133 + mss.vma = vma;
68134 + /* mmap_sem is held in m_start */
68135 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
68136 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
68137 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
68138 + }
68139 +#endif
68140 show_map_vma(m, vma, is_pid);
68141
68142 seq_printf(m,
68143 @@ -616,7 +663,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
68144 "KernelPageSize: %8lu kB\n"
68145 "MMUPageSize: %8lu kB\n"
68146 "Locked: %8lu kB\n",
68147 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
68148 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
68149 +#else
68150 (vma->vm_end - vma->vm_start) >> 10,
68151 +#endif
68152 mss.resident >> 10,
68153 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
68154 mss.shared_clean >> 10,
68155 @@ -1422,6 +1473,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
68156 char buffer[64];
68157 int nid;
68158
68159 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
68160 + if (current->exec_id != m->exec_id) {
68161 + gr_log_badprocpid("numa_maps");
68162 + return 0;
68163 + }
68164 +#endif
68165 +
68166 if (!mm)
68167 return 0;
68168
68169 @@ -1439,11 +1497,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
68170 mpol_to_str(buffer, sizeof(buffer), pol);
68171 mpol_cond_put(pol);
68172
68173 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
68174 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
68175 +#else
68176 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
68177 +#endif
68178
68179 if (file) {
68180 seq_puts(m, " file=");
68181 - seq_path(m, &file->f_path, "\n\t= ");
68182 + seq_path(m, &file->f_path, "\n\t\\= ");
68183 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
68184 seq_puts(m, " heap");
68185 } else {
68186 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
68187 index 678455d..ebd3245 100644
68188 --- a/fs/proc/task_nommu.c
68189 +++ b/fs/proc/task_nommu.c
68190 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
68191 else
68192 bytes += kobjsize(mm);
68193
68194 - if (current->fs && current->fs->users > 1)
68195 + if (current->fs && atomic_read(&current->fs->users) > 1)
68196 sbytes += kobjsize(current->fs);
68197 else
68198 bytes += kobjsize(current->fs);
68199 @@ -161,7 +161,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
68200
68201 if (file) {
68202 seq_pad(m, ' ');
68203 - seq_path(m, &file->f_path, "");
68204 + seq_path(m, &file->f_path, "\n\\");
68205 } else if (mm) {
68206 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
68207
68208 diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
68209 index a90d6d35..d08047c 100644
68210 --- a/fs/proc/vmcore.c
68211 +++ b/fs/proc/vmcore.c
68212 @@ -105,9 +105,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
68213 nr_bytes = count;
68214
68215 /* If pfn is not ram, return zeros for sparse dump files */
68216 - if (pfn_is_ram(pfn) == 0)
68217 - memset(buf, 0, nr_bytes);
68218 - else {
68219 + if (pfn_is_ram(pfn) == 0) {
68220 + if (userbuf) {
68221 + if (clear_user((char __force_user *)buf, nr_bytes))
68222 + return -EFAULT;
68223 + } else
68224 + memset(buf, 0, nr_bytes);
68225 + } else {
68226 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
68227 offset, userbuf);
68228 if (tmp < 0)
68229 @@ -170,7 +174,7 @@ int __weak remap_oldmem_pfn_range(struct vm_area_struct *vma,
68230 static int copy_to(void *target, void *src, size_t size, int userbuf)
68231 {
68232 if (userbuf) {
68233 - if (copy_to_user((char __user *) target, src, size))
68234 + if (copy_to_user((char __force_user *) target, src, size))
68235 return -EFAULT;
68236 } else {
68237 memcpy(target, src, size);
68238 @@ -233,7 +237,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
68239 if (*fpos < m->offset + m->size) {
68240 tsz = min_t(size_t, m->offset + m->size - *fpos, buflen);
68241 start = m->paddr + *fpos - m->offset;
68242 - tmp = read_from_oldmem(buffer, tsz, &start, userbuf);
68243 + tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, userbuf);
68244 if (tmp < 0)
68245 return tmp;
68246 buflen -= tsz;
68247 @@ -253,7 +257,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
68248 static ssize_t read_vmcore(struct file *file, char __user *buffer,
68249 size_t buflen, loff_t *fpos)
68250 {
68251 - return __read_vmcore((__force char *) buffer, buflen, fpos, 1);
68252 + return __read_vmcore((__force_kernel char *) buffer, buflen, fpos, 1);
68253 }
68254
68255 /*
68256 diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
68257 index d3fb2b6..43a8140 100644
68258 --- a/fs/qnx6/qnx6.h
68259 +++ b/fs/qnx6/qnx6.h
68260 @@ -74,7 +74,7 @@ enum {
68261 BYTESEX_BE,
68262 };
68263
68264 -static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
68265 +static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
68266 {
68267 if (sbi->s_bytesex == BYTESEX_LE)
68268 return le64_to_cpu((__force __le64)n);
68269 @@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
68270 return (__force __fs64)cpu_to_be64(n);
68271 }
68272
68273 -static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
68274 +static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
68275 {
68276 if (sbi->s_bytesex == BYTESEX_LE)
68277 return le32_to_cpu((__force __le32)n);
68278 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
68279 index bb2869f..d34ada8 100644
68280 --- a/fs/quota/netlink.c
68281 +++ b/fs/quota/netlink.c
68282 @@ -44,7 +44,7 @@ static struct genl_family quota_genl_family = {
68283 void quota_send_warning(struct kqid qid, dev_t dev,
68284 const char warntype)
68285 {
68286 - static atomic_t seq;
68287 + static atomic_unchecked_t seq;
68288 struct sk_buff *skb;
68289 void *msg_head;
68290 int ret;
68291 @@ -60,7 +60,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
68292 "VFS: Not enough memory to send quota warning.\n");
68293 return;
68294 }
68295 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
68296 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
68297 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
68298 if (!msg_head) {
68299 printk(KERN_ERR
68300 diff --git a/fs/read_write.c b/fs/read_write.c
68301 index 009d854..16ce214 100644
68302 --- a/fs/read_write.c
68303 +++ b/fs/read_write.c
68304 @@ -495,7 +495,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
68305
68306 old_fs = get_fs();
68307 set_fs(get_ds());
68308 - p = (__force const char __user *)buf;
68309 + p = (const char __force_user *)buf;
68310 if (count > MAX_RW_COUNT)
68311 count = MAX_RW_COUNT;
68312 if (file->f_op->write)
68313 diff --git a/fs/readdir.c b/fs/readdir.c
68314 index 33fd922..e0d6094 100644
68315 --- a/fs/readdir.c
68316 +++ b/fs/readdir.c
68317 @@ -18,6 +18,7 @@
68318 #include <linux/security.h>
68319 #include <linux/syscalls.h>
68320 #include <linux/unistd.h>
68321 +#include <linux/namei.h>
68322
68323 #include <asm/uaccess.h>
68324
68325 @@ -71,6 +72,7 @@ struct old_linux_dirent {
68326 struct readdir_callback {
68327 struct dir_context ctx;
68328 struct old_linux_dirent __user * dirent;
68329 + struct file * file;
68330 int result;
68331 };
68332
68333 @@ -88,6 +90,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
68334 buf->result = -EOVERFLOW;
68335 return -EOVERFLOW;
68336 }
68337 +
68338 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
68339 + return 0;
68340 +
68341 buf->result++;
68342 dirent = buf->dirent;
68343 if (!access_ok(VERIFY_WRITE, dirent,
68344 @@ -119,6 +125,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
68345 if (!f.file)
68346 return -EBADF;
68347
68348 + buf.file = f.file;
68349 error = iterate_dir(f.file, &buf.ctx);
68350 if (buf.result)
68351 error = buf.result;
68352 @@ -144,6 +151,7 @@ struct getdents_callback {
68353 struct dir_context ctx;
68354 struct linux_dirent __user * current_dir;
68355 struct linux_dirent __user * previous;
68356 + struct file * file;
68357 int count;
68358 int error;
68359 };
68360 @@ -165,6 +173,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
68361 buf->error = -EOVERFLOW;
68362 return -EOVERFLOW;
68363 }
68364 +
68365 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
68366 + return 0;
68367 +
68368 dirent = buf->previous;
68369 if (dirent) {
68370 if (__put_user(offset, &dirent->d_off))
68371 @@ -210,6 +222,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
68372 if (!f.file)
68373 return -EBADF;
68374
68375 + buf.file = f.file;
68376 error = iterate_dir(f.file, &buf.ctx);
68377 if (error >= 0)
68378 error = buf.error;
68379 @@ -228,6 +241,7 @@ struct getdents_callback64 {
68380 struct dir_context ctx;
68381 struct linux_dirent64 __user * current_dir;
68382 struct linux_dirent64 __user * previous;
68383 + struct file *file;
68384 int count;
68385 int error;
68386 };
68387 @@ -243,6 +257,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
68388 buf->error = -EINVAL; /* only used if we fail.. */
68389 if (reclen > buf->count)
68390 return -EINVAL;
68391 +
68392 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
68393 + return 0;
68394 +
68395 dirent = buf->previous;
68396 if (dirent) {
68397 if (__put_user(offset, &dirent->d_off))
68398 @@ -290,6 +308,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
68399 if (!f.file)
68400 return -EBADF;
68401
68402 + buf.file = f.file;
68403 error = iterate_dir(f.file, &buf.ctx);
68404 if (error >= 0)
68405 error = buf.error;
68406 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
68407 index 9c02d96..6562c10 100644
68408 --- a/fs/reiserfs/do_balan.c
68409 +++ b/fs/reiserfs/do_balan.c
68410 @@ -1887,7 +1887,7 @@ void do_balance(struct tree_balance *tb, struct item_head *ih,
68411 return;
68412 }
68413
68414 - atomic_inc(&fs_generation(tb->tb_sb));
68415 + atomic_inc_unchecked(&fs_generation(tb->tb_sb));
68416 do_balance_starts(tb);
68417
68418 /*
68419 diff --git a/fs/reiserfs/item_ops.c b/fs/reiserfs/item_ops.c
68420 index aca73dd..e3c558d 100644
68421 --- a/fs/reiserfs/item_ops.c
68422 +++ b/fs/reiserfs/item_ops.c
68423 @@ -724,18 +724,18 @@ static void errcatch_print_vi(struct virtual_item *vi)
68424 }
68425
68426 static struct item_operations errcatch_ops = {
68427 - errcatch_bytes_number,
68428 - errcatch_decrement_key,
68429 - errcatch_is_left_mergeable,
68430 - errcatch_print_item,
68431 - errcatch_check_item,
68432 + .bytes_number = errcatch_bytes_number,
68433 + .decrement_key = errcatch_decrement_key,
68434 + .is_left_mergeable = errcatch_is_left_mergeable,
68435 + .print_item = errcatch_print_item,
68436 + .check_item = errcatch_check_item,
68437
68438 - errcatch_create_vi,
68439 - errcatch_check_left,
68440 - errcatch_check_right,
68441 - errcatch_part_size,
68442 - errcatch_unit_num,
68443 - errcatch_print_vi
68444 + .create_vi = errcatch_create_vi,
68445 + .check_left = errcatch_check_left,
68446 + .check_right = errcatch_check_right,
68447 + .part_size = errcatch_part_size,
68448 + .unit_num = errcatch_unit_num,
68449 + .print_vi = errcatch_print_vi
68450 };
68451
68452 #if ! (TYPE_STAT_DATA == 0 && TYPE_INDIRECT == 1 && TYPE_DIRECT == 2 && TYPE_DIRENTRY == 3)
68453 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
68454 index 621b9f3..af527fd 100644
68455 --- a/fs/reiserfs/procfs.c
68456 +++ b/fs/reiserfs/procfs.c
68457 @@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
68458 "SMALL_TAILS " : "NO_TAILS ",
68459 replay_only(sb) ? "REPLAY_ONLY " : "",
68460 convert_reiserfs(sb) ? "CONV " : "",
68461 - atomic_read(&r->s_generation_counter),
68462 + atomic_read_unchecked(&r->s_generation_counter),
68463 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
68464 SF(s_do_balance), SF(s_unneeded_left_neighbor),
68465 SF(s_good_search_by_key_reada), SF(s_bmaps),
68466 diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
68467 index 735c2c2..81b91af 100644
68468 --- a/fs/reiserfs/reiserfs.h
68469 +++ b/fs/reiserfs/reiserfs.h
68470 @@ -573,7 +573,7 @@ struct reiserfs_sb_info {
68471 /* Comment? -Hans */
68472 wait_queue_head_t s_wait;
68473 /* increased by one every time the tree gets re-balanced */
68474 - atomic_t s_generation_counter;
68475 + atomic_unchecked_t s_generation_counter;
68476
68477 /* File system properties. Currently holds on-disk FS format */
68478 unsigned long s_properties;
68479 @@ -2294,7 +2294,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
68480 #define REISERFS_USER_MEM 1 /* user memory mode */
68481
68482 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
68483 -#define get_generation(s) atomic_read (&fs_generation(s))
68484 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
68485 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
68486 #define __fs_changed(gen,s) (gen != get_generation (s))
68487 #define fs_changed(gen,s) \
68488 diff --git a/fs/reiserfs/super.c b/fs/reiserfs/super.c
68489 index d46e88a..1a06a94 100644
68490 --- a/fs/reiserfs/super.c
68491 +++ b/fs/reiserfs/super.c
68492 @@ -1857,6 +1857,10 @@ static int reiserfs_fill_super(struct super_block *s, void *data, int silent)
68493 sbi->s_mount_opt |= (1 << REISERFS_SMALLTAIL);
68494 sbi->s_mount_opt |= (1 << REISERFS_ERROR_RO);
68495 sbi->s_mount_opt |= (1 << REISERFS_BARRIER_FLUSH);
68496 +#ifdef CONFIG_REISERFS_FS_XATTR
68497 + /* turn on user xattrs by default */
68498 + sbi->s_mount_opt |= (1 << REISERFS_XATTRS_USER);
68499 +#endif
68500 /* no preallocation minimum, be smart in reiserfs_file_write instead */
68501 sbi->s_alloc_options.preallocmin = 0;
68502 /* Preallocate by 16 blocks (17-1) at once */
68503 diff --git a/fs/select.c b/fs/select.c
68504 index 467bb1c..cf9d65a 100644
68505 --- a/fs/select.c
68506 +++ b/fs/select.c
68507 @@ -20,6 +20,7 @@
68508 #include <linux/export.h>
68509 #include <linux/slab.h>
68510 #include <linux/poll.h>
68511 +#include <linux/security.h>
68512 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
68513 #include <linux/file.h>
68514 #include <linux/fdtable.h>
68515 @@ -880,6 +881,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
68516 struct poll_list *walk = head;
68517 unsigned long todo = nfds;
68518
68519 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
68520 if (nfds > rlimit(RLIMIT_NOFILE))
68521 return -EINVAL;
68522
68523 diff --git a/fs/seq_file.c b/fs/seq_file.c
68524 index 3857b72..0b7281e 100644
68525 --- a/fs/seq_file.c
68526 +++ b/fs/seq_file.c
68527 @@ -12,6 +12,8 @@
68528 #include <linux/slab.h>
68529 #include <linux/cred.h>
68530 #include <linux/mm.h>
68531 +#include <linux/sched.h>
68532 +#include <linux/grsecurity.h>
68533
68534 #include <asm/uaccess.h>
68535 #include <asm/page.h>
68536 @@ -34,12 +36,7 @@ static void seq_set_overflow(struct seq_file *m)
68537
68538 static void *seq_buf_alloc(unsigned long size)
68539 {
68540 - void *buf;
68541 -
68542 - buf = kmalloc(size, GFP_KERNEL | __GFP_NOWARN);
68543 - if (!buf && size > PAGE_SIZE)
68544 - buf = vmalloc(size);
68545 - return buf;
68546 + return kmalloc(size, GFP_KERNEL | GFP_USERCOPY);
68547 }
68548
68549 /**
68550 @@ -72,6 +69,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
68551 #ifdef CONFIG_USER_NS
68552 p->user_ns = file->f_cred->user_ns;
68553 #endif
68554 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
68555 + p->exec_id = current->exec_id;
68556 +#endif
68557
68558 /*
68559 * Wrappers around seq_open(e.g. swaps_open) need to be
68560 @@ -94,6 +94,16 @@ int seq_open(struct file *file, const struct seq_operations *op)
68561 }
68562 EXPORT_SYMBOL(seq_open);
68563
68564 +
68565 +int seq_open_restrict(struct file *file, const struct seq_operations *op)
68566 +{
68567 + if (gr_proc_is_restricted())
68568 + return -EACCES;
68569 +
68570 + return seq_open(file, op);
68571 +}
68572 +EXPORT_SYMBOL(seq_open_restrict);
68573 +
68574 static int traverse(struct seq_file *m, loff_t offset)
68575 {
68576 loff_t pos = 0, index;
68577 @@ -165,7 +175,7 @@ Eoverflow:
68578 ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
68579 {
68580 struct seq_file *m = file->private_data;
68581 - size_t copied = 0;
68582 + ssize_t copied = 0;
68583 loff_t pos;
68584 size_t n;
68585 void *p;
68586 @@ -596,7 +606,7 @@ static void single_stop(struct seq_file *p, void *v)
68587 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
68588 void *data)
68589 {
68590 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
68591 + seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
68592 int res = -ENOMEM;
68593
68594 if (op) {
68595 @@ -632,6 +642,17 @@ int single_open_size(struct file *file, int (*show)(struct seq_file *, void *),
68596 }
68597 EXPORT_SYMBOL(single_open_size);
68598
68599 +int single_open_restrict(struct file *file, int (*show)(struct seq_file *, void *),
68600 + void *data)
68601 +{
68602 + if (gr_proc_is_restricted())
68603 + return -EACCES;
68604 +
68605 + return single_open(file, show, data);
68606 +}
68607 +EXPORT_SYMBOL(single_open_restrict);
68608 +
68609 +
68610 int single_release(struct inode *inode, struct file *file)
68611 {
68612 const struct seq_operations *op = ((struct seq_file *)file->private_data)->op;
68613 diff --git a/fs/splice.c b/fs/splice.c
68614 index f5cb9ba..8ddb1e9 100644
68615 --- a/fs/splice.c
68616 +++ b/fs/splice.c
68617 @@ -193,7 +193,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
68618 pipe_lock(pipe);
68619
68620 for (;;) {
68621 - if (!pipe->readers) {
68622 + if (!atomic_read(&pipe->readers)) {
68623 send_sig(SIGPIPE, current, 0);
68624 if (!ret)
68625 ret = -EPIPE;
68626 @@ -216,7 +216,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
68627 page_nr++;
68628 ret += buf->len;
68629
68630 - if (pipe->files)
68631 + if (atomic_read(&pipe->files))
68632 do_wakeup = 1;
68633
68634 if (!--spd->nr_pages)
68635 @@ -247,9 +247,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
68636 do_wakeup = 0;
68637 }
68638
68639 - pipe->waiting_writers++;
68640 + atomic_inc(&pipe->waiting_writers);
68641 pipe_wait(pipe);
68642 - pipe->waiting_writers--;
68643 + atomic_dec(&pipe->waiting_writers);
68644 }
68645
68646 pipe_unlock(pipe);
68647 @@ -576,7 +576,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
68648 old_fs = get_fs();
68649 set_fs(get_ds());
68650 /* The cast to a user pointer is valid due to the set_fs() */
68651 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
68652 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
68653 set_fs(old_fs);
68654
68655 return res;
68656 @@ -591,7 +591,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
68657 old_fs = get_fs();
68658 set_fs(get_ds());
68659 /* The cast to a user pointer is valid due to the set_fs() */
68660 - res = vfs_write(file, (__force const char __user *)buf, count, &pos);
68661 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
68662 set_fs(old_fs);
68663
68664 return res;
68665 @@ -644,7 +644,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
68666 goto err;
68667
68668 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
68669 - vec[i].iov_base = (void __user *) page_address(page);
68670 + vec[i].iov_base = (void __force_user *) page_address(page);
68671 vec[i].iov_len = this_len;
68672 spd.pages[i] = page;
68673 spd.nr_pages++;
68674 @@ -783,7 +783,7 @@ static int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_des
68675 ops->release(pipe, buf);
68676 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
68677 pipe->nrbufs--;
68678 - if (pipe->files)
68679 + if (atomic_read(&pipe->files))
68680 sd->need_wakeup = true;
68681 }
68682
68683 @@ -807,10 +807,10 @@ static int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_des
68684 static int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
68685 {
68686 while (!pipe->nrbufs) {
68687 - if (!pipe->writers)
68688 + if (!atomic_read(&pipe->writers))
68689 return 0;
68690
68691 - if (!pipe->waiting_writers && sd->num_spliced)
68692 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
68693 return 0;
68694
68695 if (sd->flags & SPLICE_F_NONBLOCK)
68696 @@ -1040,7 +1040,7 @@ iter_file_splice_write(struct pipe_inode_info *pipe, struct file *out,
68697 ops->release(pipe, buf);
68698 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
68699 pipe->nrbufs--;
68700 - if (pipe->files)
68701 + if (atomic_read(&pipe->files))
68702 sd.need_wakeup = true;
68703 } else {
68704 buf->offset += ret;
68705 @@ -1200,7 +1200,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
68706 * out of the pipe right after the splice_to_pipe(). So set
68707 * PIPE_READERS appropriately.
68708 */
68709 - pipe->readers = 1;
68710 + atomic_set(&pipe->readers, 1);
68711
68712 current->splice_pipe = pipe;
68713 }
68714 @@ -1496,6 +1496,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
68715
68716 partial[buffers].offset = off;
68717 partial[buffers].len = plen;
68718 + partial[buffers].private = 0;
68719
68720 off = 0;
68721 len -= plen;
68722 @@ -1732,9 +1733,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
68723 ret = -ERESTARTSYS;
68724 break;
68725 }
68726 - if (!pipe->writers)
68727 + if (!atomic_read(&pipe->writers))
68728 break;
68729 - if (!pipe->waiting_writers) {
68730 + if (!atomic_read(&pipe->waiting_writers)) {
68731 if (flags & SPLICE_F_NONBLOCK) {
68732 ret = -EAGAIN;
68733 break;
68734 @@ -1766,7 +1767,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
68735 pipe_lock(pipe);
68736
68737 while (pipe->nrbufs >= pipe->buffers) {
68738 - if (!pipe->readers) {
68739 + if (!atomic_read(&pipe->readers)) {
68740 send_sig(SIGPIPE, current, 0);
68741 ret = -EPIPE;
68742 break;
68743 @@ -1779,9 +1780,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
68744 ret = -ERESTARTSYS;
68745 break;
68746 }
68747 - pipe->waiting_writers++;
68748 + atomic_inc(&pipe->waiting_writers);
68749 pipe_wait(pipe);
68750 - pipe->waiting_writers--;
68751 + atomic_dec(&pipe->waiting_writers);
68752 }
68753
68754 pipe_unlock(pipe);
68755 @@ -1817,14 +1818,14 @@ retry:
68756 pipe_double_lock(ipipe, opipe);
68757
68758 do {
68759 - if (!opipe->readers) {
68760 + if (!atomic_read(&opipe->readers)) {
68761 send_sig(SIGPIPE, current, 0);
68762 if (!ret)
68763 ret = -EPIPE;
68764 break;
68765 }
68766
68767 - if (!ipipe->nrbufs && !ipipe->writers)
68768 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
68769 break;
68770
68771 /*
68772 @@ -1921,7 +1922,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
68773 pipe_double_lock(ipipe, opipe);
68774
68775 do {
68776 - if (!opipe->readers) {
68777 + if (!atomic_read(&opipe->readers)) {
68778 send_sig(SIGPIPE, current, 0);
68779 if (!ret)
68780 ret = -EPIPE;
68781 @@ -1966,7 +1967,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
68782 * return EAGAIN if we have the potential of some data in the
68783 * future, otherwise just return 0
68784 */
68785 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
68786 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
68787 ret = -EAGAIN;
68788
68789 pipe_unlock(ipipe);
68790 diff --git a/fs/stat.c b/fs/stat.c
68791 index ae0c3ce..9ee641c 100644
68792 --- a/fs/stat.c
68793 +++ b/fs/stat.c
68794 @@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
68795 stat->gid = inode->i_gid;
68796 stat->rdev = inode->i_rdev;
68797 stat->size = i_size_read(inode);
68798 - stat->atime = inode->i_atime;
68799 - stat->mtime = inode->i_mtime;
68800 + if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
68801 + stat->atime = inode->i_ctime;
68802 + stat->mtime = inode->i_ctime;
68803 + } else {
68804 + stat->atime = inode->i_atime;
68805 + stat->mtime = inode->i_mtime;
68806 + }
68807 stat->ctime = inode->i_ctime;
68808 stat->blksize = (1 << inode->i_blkbits);
68809 stat->blocks = inode->i_blocks;
68810 @@ -52,9 +57,16 @@ EXPORT_SYMBOL(generic_fillattr);
68811 int vfs_getattr_nosec(struct path *path, struct kstat *stat)
68812 {
68813 struct inode *inode = path->dentry->d_inode;
68814 + int retval;
68815
68816 - if (inode->i_op->getattr)
68817 - return inode->i_op->getattr(path->mnt, path->dentry, stat);
68818 + if (inode->i_op->getattr) {
68819 + retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
68820 + if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
68821 + stat->atime = stat->ctime;
68822 + stat->mtime = stat->ctime;
68823 + }
68824 + return retval;
68825 + }
68826
68827 generic_fillattr(inode, stat);
68828 return 0;
68829 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
68830 index 0b45ff4..847de5b 100644
68831 --- a/fs/sysfs/dir.c
68832 +++ b/fs/sysfs/dir.c
68833 @@ -41,9 +41,16 @@ void sysfs_warn_dup(struct kernfs_node *parent, const char *name)
68834 int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
68835 {
68836 struct kernfs_node *parent, *kn;
68837 + const char *name;
68838 + umode_t mode = S_IRWXU | S_IRUGO | S_IXUGO;
68839 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
68840 + const char *parent_name;
68841 +#endif
68842
68843 BUG_ON(!kobj);
68844
68845 + name = kobject_name(kobj);
68846 +
68847 if (kobj->parent)
68848 parent = kobj->parent->sd;
68849 else
68850 @@ -52,11 +59,22 @@ int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
68851 if (!parent)
68852 return -ENOENT;
68853
68854 - kn = kernfs_create_dir_ns(parent, kobject_name(kobj),
68855 - S_IRWXU | S_IRUGO | S_IXUGO, kobj, ns);
68856 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
68857 + parent_name = parent->name;
68858 + mode = S_IRWXU;
68859 +
68860 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
68861 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
68862 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
68863 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
68864 + mode = S_IRWXU | S_IRUGO | S_IXUGO;
68865 +#endif
68866 +
68867 + kn = kernfs_create_dir_ns(parent, name,
68868 + mode, kobj, ns);
68869 if (IS_ERR(kn)) {
68870 if (PTR_ERR(kn) == -EEXIST)
68871 - sysfs_warn_dup(parent, kobject_name(kobj));
68872 + sysfs_warn_dup(parent, name);
68873 return PTR_ERR(kn);
68874 }
68875
68876 diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
68877 index 69d4889..a810bd4 100644
68878 --- a/fs/sysv/sysv.h
68879 +++ b/fs/sysv/sysv.h
68880 @@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
68881 #endif
68882 }
68883
68884 -static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
68885 +static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
68886 {
68887 if (sbi->s_bytesex == BYTESEX_PDP)
68888 return PDP_swab((__force __u32)n);
68889 diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
68890 index fb08b0c..65fcc7e 100644
68891 --- a/fs/ubifs/io.c
68892 +++ b/fs/ubifs/io.c
68893 @@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
68894 return err;
68895 }
68896
68897 -int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
68898 +int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
68899 {
68900 int err;
68901
68902 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
68903 index c175b4d..8f36a16 100644
68904 --- a/fs/udf/misc.c
68905 +++ b/fs/udf/misc.c
68906 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
68907
68908 u8 udf_tag_checksum(const struct tag *t)
68909 {
68910 - u8 *data = (u8 *)t;
68911 + const u8 *data = (const u8 *)t;
68912 u8 checksum = 0;
68913 int i;
68914 for (i = 0; i < sizeof(struct tag); ++i)
68915 diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
68916 index 8d974c4..b82f6ec 100644
68917 --- a/fs/ufs/swab.h
68918 +++ b/fs/ufs/swab.h
68919 @@ -22,7 +22,7 @@ enum {
68920 BYTESEX_BE
68921 };
68922
68923 -static inline u64
68924 +static inline u64 __intentional_overflow(-1)
68925 fs64_to_cpu(struct super_block *sbp, __fs64 n)
68926 {
68927 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
68928 @@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
68929 return (__force __fs64)cpu_to_be64(n);
68930 }
68931
68932 -static inline u32
68933 +static inline u32 __intentional_overflow(-1)
68934 fs32_to_cpu(struct super_block *sbp, __fs32 n)
68935 {
68936 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
68937 diff --git a/fs/utimes.c b/fs/utimes.c
68938 index aa138d6..5f3a811 100644
68939 --- a/fs/utimes.c
68940 +++ b/fs/utimes.c
68941 @@ -1,6 +1,7 @@
68942 #include <linux/compiler.h>
68943 #include <linux/file.h>
68944 #include <linux/fs.h>
68945 +#include <linux/security.h>
68946 #include <linux/linkage.h>
68947 #include <linux/mount.h>
68948 #include <linux/namei.h>
68949 @@ -103,6 +104,12 @@ static int utimes_common(struct path *path, struct timespec *times)
68950 }
68951 }
68952 retry_deleg:
68953 +
68954 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
68955 + error = -EACCES;
68956 + goto mnt_drop_write_and_out;
68957 + }
68958 +
68959 mutex_lock(&inode->i_mutex);
68960 error = notify_change(path->dentry, &newattrs, &delegated_inode);
68961 mutex_unlock(&inode->i_mutex);
68962 diff --git a/fs/xattr.c b/fs/xattr.c
68963 index c69e6d4..cc56af5 100644
68964 --- a/fs/xattr.c
68965 +++ b/fs/xattr.c
68966 @@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
68967 return rc;
68968 }
68969
68970 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
68971 +ssize_t
68972 +pax_getxattr(struct dentry *dentry, void *value, size_t size)
68973 +{
68974 + struct inode *inode = dentry->d_inode;
68975 + ssize_t error;
68976 +
68977 + error = inode_permission(inode, MAY_EXEC);
68978 + if (error)
68979 + return error;
68980 +
68981 + if (inode->i_op->getxattr)
68982 + error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
68983 + else
68984 + error = -EOPNOTSUPP;
68985 +
68986 + return error;
68987 +}
68988 +EXPORT_SYMBOL(pax_getxattr);
68989 +#endif
68990 +
68991 ssize_t
68992 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
68993 {
68994 @@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
68995 * Extended attribute SET operations
68996 */
68997 static long
68998 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
68999 +setxattr(struct path *path, const char __user *name, const void __user *value,
69000 size_t size, int flags)
69001 {
69002 int error;
69003 @@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
69004 posix_acl_fix_xattr_from_user(kvalue, size);
69005 }
69006
69007 - error = vfs_setxattr(d, kname, kvalue, size, flags);
69008 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
69009 + error = -EACCES;
69010 + goto out;
69011 + }
69012 +
69013 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
69014 out:
69015 if (vvalue)
69016 vfree(vvalue);
69017 @@ -377,7 +403,7 @@ retry:
69018 return error;
69019 error = mnt_want_write(path.mnt);
69020 if (!error) {
69021 - error = setxattr(path.dentry, name, value, size, flags);
69022 + error = setxattr(&path, name, value, size, flags);
69023 mnt_drop_write(path.mnt);
69024 }
69025 path_put(&path);
69026 @@ -401,7 +427,7 @@ retry:
69027 return error;
69028 error = mnt_want_write(path.mnt);
69029 if (!error) {
69030 - error = setxattr(path.dentry, name, value, size, flags);
69031 + error = setxattr(&path, name, value, size, flags);
69032 mnt_drop_write(path.mnt);
69033 }
69034 path_put(&path);
69035 @@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
69036 const void __user *,value, size_t, size, int, flags)
69037 {
69038 struct fd f = fdget(fd);
69039 - struct dentry *dentry;
69040 int error = -EBADF;
69041
69042 if (!f.file)
69043 return error;
69044 - dentry = f.file->f_path.dentry;
69045 - audit_inode(NULL, dentry, 0);
69046 + audit_inode(NULL, f.file->f_path.dentry, 0);
69047 error = mnt_want_write_file(f.file);
69048 if (!error) {
69049 - error = setxattr(dentry, name, value, size, flags);
69050 + error = setxattr(&f.file->f_path, name, value, size, flags);
69051 mnt_drop_write_file(f.file);
69052 }
69053 fdput(f);
69054 @@ -626,7 +650,7 @@ SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size)
69055 * Extended attribute REMOVE operations
69056 */
69057 static long
69058 -removexattr(struct dentry *d, const char __user *name)
69059 +removexattr(struct path *path, const char __user *name)
69060 {
69061 int error;
69062 char kname[XATTR_NAME_MAX + 1];
69063 @@ -637,7 +661,10 @@ removexattr(struct dentry *d, const char __user *name)
69064 if (error < 0)
69065 return error;
69066
69067 - return vfs_removexattr(d, kname);
69068 + if (!gr_acl_handle_removexattr(path->dentry, path->mnt))
69069 + return -EACCES;
69070 +
69071 + return vfs_removexattr(path->dentry, kname);
69072 }
69073
69074 SYSCALL_DEFINE2(removexattr, const char __user *, pathname,
69075 @@ -652,7 +679,7 @@ retry:
69076 return error;
69077 error = mnt_want_write(path.mnt);
69078 if (!error) {
69079 - error = removexattr(path.dentry, name);
69080 + error = removexattr(&path, name);
69081 mnt_drop_write(path.mnt);
69082 }
69083 path_put(&path);
69084 @@ -675,7 +702,7 @@ retry:
69085 return error;
69086 error = mnt_want_write(path.mnt);
69087 if (!error) {
69088 - error = removexattr(path.dentry, name);
69089 + error = removexattr(&path, name);
69090 mnt_drop_write(path.mnt);
69091 }
69092 path_put(&path);
69093 @@ -689,16 +716,16 @@ retry:
69094 SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name)
69095 {
69096 struct fd f = fdget(fd);
69097 - struct dentry *dentry;
69098 + struct path *path;
69099 int error = -EBADF;
69100
69101 if (!f.file)
69102 return error;
69103 - dentry = f.file->f_path.dentry;
69104 - audit_inode(NULL, dentry, 0);
69105 + path = &f.file->f_path;
69106 + audit_inode(NULL, path->dentry, 0);
69107 error = mnt_want_write_file(f.file);
69108 if (!error) {
69109 - error = removexattr(dentry, name);
69110 + error = removexattr(path, name);
69111 mnt_drop_write_file(f.file);
69112 }
69113 fdput(f);
69114 diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
69115 index 86df952..ac430d6 100644
69116 --- a/fs/xfs/libxfs/xfs_bmap.c
69117 +++ b/fs/xfs/libxfs/xfs_bmap.c
69118 @@ -583,7 +583,7 @@ xfs_bmap_validate_ret(
69119
69120 #else
69121 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
69122 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
69123 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
69124 #endif /* DEBUG */
69125
69126 /*
69127 diff --git a/fs/xfs/xfs_dir2_readdir.c b/fs/xfs/xfs_dir2_readdir.c
69128 index f1b69ed..3d0222f 100644
69129 --- a/fs/xfs/xfs_dir2_readdir.c
69130 +++ b/fs/xfs/xfs_dir2_readdir.c
69131 @@ -159,7 +159,12 @@ xfs_dir2_sf_getdents(
69132 ino = dp->d_ops->sf_get_ino(sfp, sfep);
69133 filetype = dp->d_ops->sf_get_ftype(sfep);
69134 ctx->pos = off & 0x7fffffff;
69135 - if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
69136 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
69137 + char name[sfep->namelen];
69138 + memcpy(name, sfep->name, sfep->namelen);
69139 + if (!dir_emit(ctx, name, sfep->namelen, ino, xfs_dir3_get_dtype(dp->i_mount, filetype)))
69140 + return 0;
69141 + } else if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
69142 xfs_dir3_get_dtype(dp->i_mount, filetype)))
69143 return 0;
69144 sfep = dp->d_ops->sf_nextentry(sfp, sfep);
69145 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
69146 index 3799695..0ddc953 100644
69147 --- a/fs/xfs/xfs_ioctl.c
69148 +++ b/fs/xfs/xfs_ioctl.c
69149 @@ -122,7 +122,7 @@ xfs_find_handle(
69150 }
69151
69152 error = -EFAULT;
69153 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
69154 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
69155 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
69156 goto out_put;
69157
69158 diff --git a/fs/xfs/xfs_linux.h b/fs/xfs/xfs_linux.h
69159 index d10dc8f..56b3430 100644
69160 --- a/fs/xfs/xfs_linux.h
69161 +++ b/fs/xfs/xfs_linux.h
69162 @@ -230,7 +230,7 @@ static inline kgid_t xfs_gid_to_kgid(__uint32_t gid)
69163 * of the compiler which do not like us using do_div in the middle
69164 * of large functions.
69165 */
69166 -static inline __u32 xfs_do_div(void *a, __u32 b, int n)
69167 +static inline __u32 __intentional_overflow(-1) xfs_do_div(void *a, __u32 b, int n)
69168 {
69169 __u32 mod;
69170
69171 @@ -286,7 +286,7 @@ static inline __u32 xfs_do_mod(void *a, __u32 b, int n)
69172 return 0;
69173 }
69174 #else
69175 -static inline __u32 xfs_do_div(void *a, __u32 b, int n)
69176 +static inline __u32 __intentional_overflow(-1) xfs_do_div(void *a, __u32 b, int n)
69177 {
69178 __u32 mod;
69179
69180 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
69181 new file mode 100644
69182 index 0000000..f27264e
69183 --- /dev/null
69184 +++ b/grsecurity/Kconfig
69185 @@ -0,0 +1,1166 @@
69186 +#
69187 +# grecurity configuration
69188 +#
69189 +menu "Memory Protections"
69190 +depends on GRKERNSEC
69191 +
69192 +config GRKERNSEC_KMEM
69193 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
69194 + default y if GRKERNSEC_CONFIG_AUTO
69195 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
69196 + help
69197 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
69198 + be written to or read from to modify or leak the contents of the running
69199 + kernel. /dev/port will also not be allowed to be opened, writing to
69200 + /dev/cpu/*/msr will be prevented, and support for kexec will be removed.
69201 + If you have module support disabled, enabling this will close up several
69202 + ways that are currently used to insert malicious code into the running
69203 + kernel.
69204 +
69205 + Even with this feature enabled, we still highly recommend that
69206 + you use the RBAC system, as it is still possible for an attacker to
69207 + modify the running kernel through other more obscure methods.
69208 +
69209 + It is highly recommended that you say Y here if you meet all the
69210 + conditions above.
69211 +
69212 +config GRKERNSEC_VM86
69213 + bool "Restrict VM86 mode"
69214 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
69215 + depends on X86_32
69216 +
69217 + help
69218 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
69219 + make use of a special execution mode on 32bit x86 processors called
69220 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
69221 + video cards and will still work with this option enabled. The purpose
69222 + of the option is to prevent exploitation of emulation errors in
69223 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
69224 + Nearly all users should be able to enable this option.
69225 +
69226 +config GRKERNSEC_IO
69227 + bool "Disable privileged I/O"
69228 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
69229 + depends on X86
69230 + select RTC_CLASS
69231 + select RTC_INTF_DEV
69232 + select RTC_DRV_CMOS
69233 +
69234 + help
69235 + If you say Y here, all ioperm and iopl calls will return an error.
69236 + Ioperm and iopl can be used to modify the running kernel.
69237 + Unfortunately, some programs need this access to operate properly,
69238 + the most notable of which are XFree86 and hwclock. hwclock can be
69239 + remedied by having RTC support in the kernel, so real-time
69240 + clock support is enabled if this option is enabled, to ensure
69241 + that hwclock operates correctly. If hwclock still does not work,
69242 + either update udev or symlink /dev/rtc to /dev/rtc0.
69243 +
69244 + If you're using XFree86 or a version of Xorg from 2012 or earlier,
69245 + you may not be able to boot into a graphical environment with this
69246 + option enabled. In this case, you should use the RBAC system instead.
69247 +
69248 +config GRKERNSEC_BPF_HARDEN
69249 + bool "Harden BPF interpreter"
69250 + default y if GRKERNSEC_CONFIG_AUTO
69251 + help
69252 + Unlike previous versions of grsecurity that hardened both the BPF
69253 + interpreted code against corruption at rest as well as the JIT code
69254 + against JIT-spray attacks and attacker-controlled immediate values
69255 + for ROP, this feature will enforce disabling of the new eBPF JIT engine
69256 + and will ensure the interpreted code is read-only at rest. This feature
69257 + may be removed at a later time when eBPF stabilizes to entirely revert
69258 + back to the more secure pre-3.16 BPF interpreter/JIT.
69259 +
69260 + If you're using KERNEXEC, it's recommended that you enable this option
69261 + to supplement the hardening of the kernel.
69262 +
69263 +config GRKERNSEC_PERF_HARDEN
69264 + bool "Disable unprivileged PERF_EVENTS usage by default"
69265 + default y if GRKERNSEC_CONFIG_AUTO
69266 + depends on PERF_EVENTS
69267 + help
69268 + If you say Y here, the range of acceptable values for the
69269 + /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
69270 + default to a new value: 3. When the sysctl is set to this value, no
69271 + unprivileged use of the PERF_EVENTS syscall interface will be permitted.
69272 +
69273 + Though PERF_EVENTS can be used legitimately for performance monitoring
69274 + and low-level application profiling, it is forced on regardless of
69275 + configuration, has been at fault for several vulnerabilities, and
69276 + creates new opportunities for side channels and other information leaks.
69277 +
69278 + This feature puts PERF_EVENTS into a secure default state and permits
69279 + the administrator to change out of it temporarily if unprivileged
69280 + application profiling is needed.
69281 +
69282 +config GRKERNSEC_RAND_THREADSTACK
69283 + bool "Insert random gaps between thread stacks"
69284 + default y if GRKERNSEC_CONFIG_AUTO
69285 + depends on PAX_RANDMMAP && !PPC
69286 + help
69287 + If you say Y here, a random-sized gap will be enforced between allocated
69288 + thread stacks. Glibc's NPTL and other threading libraries that
69289 + pass MAP_STACK to the kernel for thread stack allocation are supported.
69290 + The implementation currently provides 8 bits of entropy for the gap.
69291 +
69292 + Many distributions do not compile threaded remote services with the
69293 + -fstack-check argument to GCC, causing the variable-sized stack-based
69294 + allocator, alloca(), to not probe the stack on allocation. This
69295 + permits an unbounded alloca() to skip over any guard page and potentially
69296 + modify another thread's stack reliably. An enforced random gap
69297 + reduces the reliability of such an attack and increases the chance
69298 + that such a read/write to another thread's stack instead lands in
69299 + an unmapped area, causing a crash and triggering grsecurity's
69300 + anti-bruteforcing logic.
69301 +
69302 +config GRKERNSEC_PROC_MEMMAP
69303 + bool "Harden ASLR against information leaks and entropy reduction"
69304 + default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
69305 + depends on PAX_NOEXEC || PAX_ASLR
69306 + help
69307 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
69308 + give no information about the addresses of its mappings if
69309 + PaX features that rely on random addresses are enabled on the task.
69310 + In addition to sanitizing this information and disabling other
69311 + dangerous sources of information, this option causes reads of sensitive
69312 + /proc/<pid> entries where the file descriptor was opened in a different
69313 + task than the one performing the read. Such attempts are logged.
69314 + This option also limits argv/env strings for suid/sgid binaries
69315 + to 512KB to prevent a complete exhaustion of the stack entropy provided
69316 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
69317 + binaries to prevent alternative mmap layouts from being abused.
69318 +
69319 + If you use PaX it is essential that you say Y here as it closes up
69320 + several holes that make full ASLR useless locally.
69321 +
69322 +
69323 +config GRKERNSEC_KSTACKOVERFLOW
69324 + bool "Prevent kernel stack overflows"
69325 + default y if GRKERNSEC_CONFIG_AUTO
69326 + depends on !IA64 && 64BIT
69327 + help
69328 + If you say Y here, the kernel's process stacks will be allocated
69329 + with vmalloc instead of the kernel's default allocator. This
69330 + introduces guard pages that in combination with the alloca checking
69331 + of the STACKLEAK feature prevents all forms of kernel process stack
69332 + overflow abuse. Note that this is different from kernel stack
69333 + buffer overflows.
69334 +
69335 +config GRKERNSEC_BRUTE
69336 + bool "Deter exploit bruteforcing"
69337 + default y if GRKERNSEC_CONFIG_AUTO
69338 + help
69339 + If you say Y here, attempts to bruteforce exploits against forking
69340 + daemons such as apache or sshd, as well as against suid/sgid binaries
69341 + will be deterred. When a child of a forking daemon is killed by PaX
69342 + or crashes due to an illegal instruction or other suspicious signal,
69343 + the parent process will be delayed 30 seconds upon every subsequent
69344 + fork until the administrator is able to assess the situation and
69345 + restart the daemon.
69346 + In the suid/sgid case, the attempt is logged, the user has all their
69347 + existing instances of the suid/sgid binary terminated and will
69348 + be unable to execute any suid/sgid binaries for 15 minutes.
69349 +
69350 + It is recommended that you also enable signal logging in the auditing
69351 + section so that logs are generated when a process triggers a suspicious
69352 + signal.
69353 + If the sysctl option is enabled, a sysctl option with name
69354 + "deter_bruteforce" is created.
69355 +
69356 +config GRKERNSEC_MODHARDEN
69357 + bool "Harden module auto-loading"
69358 + default y if GRKERNSEC_CONFIG_AUTO
69359 + depends on MODULES
69360 + help
69361 + If you say Y here, module auto-loading in response to use of some
69362 + feature implemented by an unloaded module will be restricted to
69363 + root users. Enabling this option helps defend against attacks
69364 + by unprivileged users who abuse the auto-loading behavior to
69365 + cause a vulnerable module to load that is then exploited.
69366 +
69367 + If this option prevents a legitimate use of auto-loading for a
69368 + non-root user, the administrator can execute modprobe manually
69369 + with the exact name of the module mentioned in the alert log.
69370 + Alternatively, the administrator can add the module to the list
69371 + of modules loaded at boot by modifying init scripts.
69372 +
69373 + Modification of init scripts will most likely be needed on
69374 + Ubuntu servers with encrypted home directory support enabled,
69375 + as the first non-root user logging in will cause the ecb(aes),
69376 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
69377 +
69378 +config GRKERNSEC_HIDESYM
69379 + bool "Hide kernel symbols"
69380 + default y if GRKERNSEC_CONFIG_AUTO
69381 + select PAX_USERCOPY_SLABS
69382 + help
69383 + If you say Y here, getting information on loaded modules, and
69384 + displaying all kernel symbols through a syscall will be restricted
69385 + to users with CAP_SYS_MODULE. For software compatibility reasons,
69386 + /proc/kallsyms will be restricted to the root user. The RBAC
69387 + system can hide that entry even from root.
69388 +
69389 + This option also prevents leaking of kernel addresses through
69390 + several /proc entries.
69391 +
69392 + Note that this option is only effective provided the following
69393 + conditions are met:
69394 + 1) The kernel using grsecurity is not precompiled by some distribution
69395 + 2) You have also enabled GRKERNSEC_DMESG
69396 + 3) You are using the RBAC system and hiding other files such as your
69397 + kernel image and System.map. Alternatively, enabling this option
69398 + causes the permissions on /boot, /lib/modules, and the kernel
69399 + source directory to change at compile time to prevent
69400 + reading by non-root users.
69401 + If the above conditions are met, this option will aid in providing a
69402 + useful protection against local kernel exploitation of overflows
69403 + and arbitrary read/write vulnerabilities.
69404 +
69405 + It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
69406 + in addition to this feature.
69407 +
69408 +config GRKERNSEC_RANDSTRUCT
69409 + bool "Randomize layout of sensitive kernel structures"
69410 + default y if GRKERNSEC_CONFIG_AUTO
69411 + select GRKERNSEC_HIDESYM
69412 + select MODVERSIONS if MODULES
69413 + help
69414 + If you say Y here, the layouts of a number of sensitive kernel
69415 + structures (task, fs, cred, etc) and all structures composed entirely
69416 + of function pointers (aka "ops" structs) will be randomized at compile-time.
69417 + This can introduce the requirement of an additional infoleak
69418 + vulnerability for exploits targeting these structure types.
69419 +
69420 + Enabling this feature will introduce some performance impact, slightly
69421 + increase memory usage, and prevent the use of forensic tools like
69422 + Volatility against the system (unless the kernel source tree isn't
69423 + cleaned after kernel installation).
69424 +
69425 + The seed used for compilation is located at tools/gcc/randomize_layout_seed.h.
69426 + It remains after a make clean to allow for external modules to be compiled
69427 + with the existing seed and will be removed by a make mrproper or
69428 + make distclean.
69429 +
69430 + Note that the implementation requires gcc 4.6.4. or newer. You may need
69431 + to install the supporting headers explicitly in addition to the normal
69432 + gcc package.
69433 +
69434 +config GRKERNSEC_RANDSTRUCT_PERFORMANCE
69435 + bool "Use cacheline-aware structure randomization"
69436 + depends on GRKERNSEC_RANDSTRUCT
69437 + default y if GRKERNSEC_CONFIG_PRIORITY_PERF
69438 + help
69439 + If you say Y here, the RANDSTRUCT randomization will make a best effort
69440 + at restricting randomization to cacheline-sized groups of elements. It
69441 + will further not randomize bitfields in structures. This reduces the
69442 + performance hit of RANDSTRUCT at the cost of weakened randomization.
69443 +
69444 +config GRKERNSEC_KERN_LOCKOUT
69445 + bool "Active kernel exploit response"
69446 + default y if GRKERNSEC_CONFIG_AUTO
69447 + depends on X86 || ARM || PPC || SPARC
69448 + help
69449 + If you say Y here, when a PaX alert is triggered due to suspicious
69450 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
69451 + or an OOPS occurs due to bad memory accesses, instead of just
69452 + terminating the offending process (and potentially allowing
69453 + a subsequent exploit from the same user), we will take one of two
69454 + actions:
69455 + If the user was root, we will panic the system
69456 + If the user was non-root, we will log the attempt, terminate
69457 + all processes owned by the user, then prevent them from creating
69458 + any new processes until the system is restarted
69459 + This deters repeated kernel exploitation/bruteforcing attempts
69460 + and is useful for later forensics.
69461 +
69462 +config GRKERNSEC_OLD_ARM_USERLAND
69463 + bool "Old ARM userland compatibility"
69464 + depends on ARM && (CPU_V6 || CPU_V6K || CPU_V7)
69465 + help
69466 + If you say Y here, stubs of executable code to perform such operations
69467 + as "compare-exchange" will be placed at fixed locations in the ARM vector
69468 + table. This is unfortunately needed for old ARM userland meant to run
69469 + across a wide range of processors. Without this option enabled,
69470 + the get_tls and data memory barrier stubs will be emulated by the kernel,
69471 + which is enough for Linaro userlands or other userlands designed for v6
69472 + and newer ARM CPUs. It's recommended that you try without this option enabled
69473 + first, and only enable it if your userland does not boot (it will likely fail
69474 + at init time).
69475 +
69476 +endmenu
69477 +menu "Role Based Access Control Options"
69478 +depends on GRKERNSEC
69479 +
69480 +config GRKERNSEC_RBAC_DEBUG
69481 + bool
69482 +
69483 +config GRKERNSEC_NO_RBAC
69484 + bool "Disable RBAC system"
69485 + help
69486 + If you say Y here, the /dev/grsec device will be removed from the kernel,
69487 + preventing the RBAC system from being enabled. You should only say Y
69488 + here if you have no intention of using the RBAC system, so as to prevent
69489 + an attacker with root access from misusing the RBAC system to hide files
69490 + and processes when loadable module support and /dev/[k]mem have been
69491 + locked down.
69492 +
69493 +config GRKERNSEC_ACL_HIDEKERN
69494 + bool "Hide kernel processes"
69495 + help
69496 + If you say Y here, all kernel threads will be hidden to all
69497 + processes but those whose subject has the "view hidden processes"
69498 + flag.
69499 +
69500 +config GRKERNSEC_ACL_MAXTRIES
69501 + int "Maximum tries before password lockout"
69502 + default 3
69503 + help
69504 + This option enforces the maximum number of times a user can attempt
69505 + to authorize themselves with the grsecurity RBAC system before being
69506 + denied the ability to attempt authorization again for a specified time.
69507 + The lower the number, the harder it will be to brute-force a password.
69508 +
69509 +config GRKERNSEC_ACL_TIMEOUT
69510 + int "Time to wait after max password tries, in seconds"
69511 + default 30
69512 + help
69513 + This option specifies the time the user must wait after attempting to
69514 + authorize to the RBAC system with the maximum number of invalid
69515 + passwords. The higher the number, the harder it will be to brute-force
69516 + a password.
69517 +
69518 +endmenu
69519 +menu "Filesystem Protections"
69520 +depends on GRKERNSEC
69521 +
69522 +config GRKERNSEC_PROC
69523 + bool "Proc restrictions"
69524 + default y if GRKERNSEC_CONFIG_AUTO
69525 + help
69526 + If you say Y here, the permissions of the /proc filesystem
69527 + will be altered to enhance system security and privacy. You MUST
69528 + choose either a user only restriction or a user and group restriction.
69529 + Depending upon the option you choose, you can either restrict users to
69530 + see only the processes they themselves run, or choose a group that can
69531 + view all processes and files normally restricted to root if you choose
69532 + the "restrict to user only" option. NOTE: If you're running identd or
69533 + ntpd as a non-root user, you will have to run it as the group you
69534 + specify here.
69535 +
69536 +config GRKERNSEC_PROC_USER
69537 + bool "Restrict /proc to user only"
69538 + depends on GRKERNSEC_PROC
69539 + help
69540 + If you say Y here, non-root users will only be able to view their own
69541 + processes, and restricts them from viewing network-related information,
69542 + and viewing kernel symbol and module information.
69543 +
69544 +config GRKERNSEC_PROC_USERGROUP
69545 + bool "Allow special group"
69546 + default y if GRKERNSEC_CONFIG_AUTO
69547 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
69548 + help
69549 + If you say Y here, you will be able to select a group that will be
69550 + able to view all processes and network-related information. If you've
69551 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
69552 + remain hidden. This option is useful if you want to run identd as
69553 + a non-root user. The group you select may also be chosen at boot time
69554 + via "grsec_proc_gid=" on the kernel commandline.
69555 +
69556 +config GRKERNSEC_PROC_GID
69557 + int "GID for special group"
69558 + depends on GRKERNSEC_PROC_USERGROUP
69559 + default 1001
69560 +
69561 +config GRKERNSEC_PROC_ADD
69562 + bool "Additional restrictions"
69563 + default y if GRKERNSEC_CONFIG_AUTO
69564 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
69565 + help
69566 + If you say Y here, additional restrictions will be placed on
69567 + /proc that keep normal users from viewing device information and
69568 + slabinfo information that could be useful for exploits.
69569 +
69570 +config GRKERNSEC_LINK
69571 + bool "Linking restrictions"
69572 + default y if GRKERNSEC_CONFIG_AUTO
69573 + help
69574 + If you say Y here, /tmp race exploits will be prevented, since users
69575 + will no longer be able to follow symlinks owned by other users in
69576 + world-writable +t directories (e.g. /tmp), unless the owner of the
69577 + symlink is the owner of the directory. users will also not be
69578 + able to hardlink to files they do not own. If the sysctl option is
69579 + enabled, a sysctl option with name "linking_restrictions" is created.
69580 +
69581 +config GRKERNSEC_SYMLINKOWN
69582 + bool "Kernel-enforced SymlinksIfOwnerMatch"
69583 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
69584 + help
69585 + Apache's SymlinksIfOwnerMatch option has an inherent race condition
69586 + that prevents it from being used as a security feature. As Apache
69587 + verifies the symlink by performing a stat() against the target of
69588 + the symlink before it is followed, an attacker can setup a symlink
69589 + to point to a same-owned file, then replace the symlink with one
69590 + that targets another user's file just after Apache "validates" the
69591 + symlink -- a classic TOCTOU race. If you say Y here, a complete,
69592 + race-free replacement for Apache's "SymlinksIfOwnerMatch" option
69593 + will be in place for the group you specify. If the sysctl option
69594 + is enabled, a sysctl option with name "enforce_symlinksifowner" is
69595 + created.
69596 +
69597 +config GRKERNSEC_SYMLINKOWN_GID
69598 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
69599 + depends on GRKERNSEC_SYMLINKOWN
69600 + default 1006
69601 + help
69602 + Setting this GID determines what group kernel-enforced
69603 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
69604 + is enabled, a sysctl option with name "symlinkown_gid" is created.
69605 +
69606 +config GRKERNSEC_FIFO
69607 + bool "FIFO restrictions"
69608 + default y if GRKERNSEC_CONFIG_AUTO
69609 + help
69610 + If you say Y here, users will not be able to write to FIFOs they don't
69611 + own in world-writable +t directories (e.g. /tmp), unless the owner of
69612 + the FIFO is the same owner of the directory it's held in. If the sysctl
69613 + option is enabled, a sysctl option with name "fifo_restrictions" is
69614 + created.
69615 +
69616 +config GRKERNSEC_SYSFS_RESTRICT
69617 + bool "Sysfs/debugfs restriction"
69618 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
69619 + depends on SYSFS
69620 + help
69621 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
69622 + any filesystem normally mounted under it (e.g. debugfs) will be
69623 + mostly accessible only by root. These filesystems generally provide access
69624 + to hardware and debug information that isn't appropriate for unprivileged
69625 + users of the system. Sysfs and debugfs have also become a large source
69626 + of new vulnerabilities, ranging from infoleaks to local compromise.
69627 + There has been very little oversight with an eye toward security involved
69628 + in adding new exporters of information to these filesystems, so their
69629 + use is discouraged.
69630 + For reasons of compatibility, a few directories have been whitelisted
69631 + for access by non-root users:
69632 + /sys/fs/selinux
69633 + /sys/fs/fuse
69634 + /sys/devices/system/cpu
69635 +
69636 +config GRKERNSEC_ROFS
69637 + bool "Runtime read-only mount protection"
69638 + depends on SYSCTL
69639 + help
69640 + If you say Y here, a sysctl option with name "romount_protect" will
69641 + be created. By setting this option to 1 at runtime, filesystems
69642 + will be protected in the following ways:
69643 + * No new writable mounts will be allowed
69644 + * Existing read-only mounts won't be able to be remounted read/write
69645 + * Write operations will be denied on all block devices
69646 + This option acts independently of grsec_lock: once it is set to 1,
69647 + it cannot be turned off. Therefore, please be mindful of the resulting
69648 + behavior if this option is enabled in an init script on a read-only
69649 + filesystem.
69650 + Also be aware that as with other root-focused features, GRKERNSEC_KMEM
69651 + and GRKERNSEC_IO should be enabled and module loading disabled via
69652 + config or at runtime.
69653 + This feature is mainly intended for secure embedded systems.
69654 +
69655 +
69656 +config GRKERNSEC_DEVICE_SIDECHANNEL
69657 + bool "Eliminate stat/notify-based device sidechannels"
69658 + default y if GRKERNSEC_CONFIG_AUTO
69659 + help
69660 + If you say Y here, timing analyses on block or character
69661 + devices like /dev/ptmx using stat or inotify/dnotify/fanotify
69662 + will be thwarted for unprivileged users. If a process without
69663 + CAP_MKNOD stats such a device, the last access and last modify times
69664 + will match the device's create time. No access or modify events
69665 + will be triggered through inotify/dnotify/fanotify for such devices.
69666 + This feature will prevent attacks that may at a minimum
69667 + allow an attacker to determine the administrator's password length.
69668 +
69669 +config GRKERNSEC_CHROOT
69670 + bool "Chroot jail restrictions"
69671 + default y if GRKERNSEC_CONFIG_AUTO
69672 + help
69673 + If you say Y here, you will be able to choose several options that will
69674 + make breaking out of a chrooted jail much more difficult. If you
69675 + encounter no software incompatibilities with the following options, it
69676 + is recommended that you enable each one.
69677 +
69678 + Note that the chroot restrictions are not intended to apply to "chroots"
69679 + to directories that are simple bind mounts of the global root filesystem.
69680 + For several other reasons, a user shouldn't expect any significant
69681 + security by performing such a chroot.
69682 +
69683 +config GRKERNSEC_CHROOT_MOUNT
69684 + bool "Deny mounts"
69685 + default y if GRKERNSEC_CONFIG_AUTO
69686 + depends on GRKERNSEC_CHROOT
69687 + help
69688 + If you say Y here, processes inside a chroot will not be able to
69689 + mount or remount filesystems. If the sysctl option is enabled, a
69690 + sysctl option with name "chroot_deny_mount" is created.
69691 +
69692 +config GRKERNSEC_CHROOT_DOUBLE
69693 + bool "Deny double-chroots"
69694 + default y if GRKERNSEC_CONFIG_AUTO
69695 + depends on GRKERNSEC_CHROOT
69696 + help
69697 + If you say Y here, processes inside a chroot will not be able to chroot
69698 + again outside the chroot. This is a widely used method of breaking
69699 + out of a chroot jail and should not be allowed. If the sysctl
69700 + option is enabled, a sysctl option with name
69701 + "chroot_deny_chroot" is created.
69702 +
69703 +config GRKERNSEC_CHROOT_PIVOT
69704 + bool "Deny pivot_root in chroot"
69705 + default y if GRKERNSEC_CONFIG_AUTO
69706 + depends on GRKERNSEC_CHROOT
69707 + help
69708 + If you say Y here, processes inside a chroot will not be able to use
69709 + a function called pivot_root() that was introduced in Linux 2.3.41. It
69710 + works similar to chroot in that it changes the root filesystem. This
69711 + function could be misused in a chrooted process to attempt to break out
69712 + of the chroot, and therefore should not be allowed. If the sysctl
69713 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
69714 + created.
69715 +
69716 +config GRKERNSEC_CHROOT_CHDIR
69717 + bool "Enforce chdir(\"/\") on all chroots"
69718 + default y if GRKERNSEC_CONFIG_AUTO
69719 + depends on GRKERNSEC_CHROOT
69720 + help
69721 + If you say Y here, the current working directory of all newly-chrooted
69722 + applications will be set to the the root directory of the chroot.
69723 + The man page on chroot(2) states:
69724 + Note that this call does not change the current working
69725 + directory, so that `.' can be outside the tree rooted at
69726 + `/'. In particular, the super-user can escape from a
69727 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
69728 +
69729 + It is recommended that you say Y here, since it's not known to break
69730 + any software. If the sysctl option is enabled, a sysctl option with
69731 + name "chroot_enforce_chdir" is created.
69732 +
69733 +config GRKERNSEC_CHROOT_CHMOD
69734 + bool "Deny (f)chmod +s"
69735 + default y if GRKERNSEC_CONFIG_AUTO
69736 + depends on GRKERNSEC_CHROOT
69737 + help
69738 + If you say Y here, processes inside a chroot will not be able to chmod
69739 + or fchmod files to make them have suid or sgid bits. This protects
69740 + against another published method of breaking a chroot. If the sysctl
69741 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
69742 + created.
69743 +
69744 +config GRKERNSEC_CHROOT_FCHDIR
69745 + bool "Deny fchdir and fhandle out of chroot"
69746 + default y if GRKERNSEC_CONFIG_AUTO
69747 + depends on GRKERNSEC_CHROOT
69748 + help
69749 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
69750 + to a file descriptor of the chrooting process that points to a directory
69751 + outside the filesystem will be stopped. Additionally, this option prevents
69752 + use of the recently-created syscall for opening files by a guessable "file
69753 + handle" inside a chroot. If the sysctl option is enabled, a sysctl option
69754 + with name "chroot_deny_fchdir" is created.
69755 +
69756 +config GRKERNSEC_CHROOT_MKNOD
69757 + bool "Deny mknod"
69758 + default y if GRKERNSEC_CONFIG_AUTO
69759 + depends on GRKERNSEC_CHROOT
69760 + help
69761 + If you say Y here, processes inside a chroot will not be allowed to
69762 + mknod. The problem with using mknod inside a chroot is that it
69763 + would allow an attacker to create a device entry that is the same
69764 + as one on the physical root of your system, which could range from
69765 + anything from the console device to a device for your harddrive (which
69766 + they could then use to wipe the drive or steal data). It is recommended
69767 + that you say Y here, unless you run into software incompatibilities.
69768 + If the sysctl option is enabled, a sysctl option with name
69769 + "chroot_deny_mknod" is created.
69770 +
69771 +config GRKERNSEC_CHROOT_SHMAT
69772 + bool "Deny shmat() out of chroot"
69773 + default y if GRKERNSEC_CONFIG_AUTO
69774 + depends on GRKERNSEC_CHROOT
69775 + help
69776 + If you say Y here, processes inside a chroot will not be able to attach
69777 + to shared memory segments that were created outside of the chroot jail.
69778 + It is recommended that you say Y here. If the sysctl option is enabled,
69779 + a sysctl option with name "chroot_deny_shmat" is created.
69780 +
69781 +config GRKERNSEC_CHROOT_UNIX
69782 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
69783 + default y if GRKERNSEC_CONFIG_AUTO
69784 + depends on GRKERNSEC_CHROOT
69785 + help
69786 + If you say Y here, processes inside a chroot will not be able to
69787 + connect to abstract (meaning not belonging to a filesystem) Unix
69788 + domain sockets that were bound outside of a chroot. It is recommended
69789 + that you say Y here. If the sysctl option is enabled, a sysctl option
69790 + with name "chroot_deny_unix" is created.
69791 +
69792 +config GRKERNSEC_CHROOT_FINDTASK
69793 + bool "Protect outside processes"
69794 + default y if GRKERNSEC_CONFIG_AUTO
69795 + depends on GRKERNSEC_CHROOT
69796 + help
69797 + If you say Y here, processes inside a chroot will not be able to
69798 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
69799 + getsid, or view any process outside of the chroot. If the sysctl
69800 + option is enabled, a sysctl option with name "chroot_findtask" is
69801 + created.
69802 +
69803 +config GRKERNSEC_CHROOT_NICE
69804 + bool "Restrict priority changes"
69805 + default y if GRKERNSEC_CONFIG_AUTO
69806 + depends on GRKERNSEC_CHROOT
69807 + help
69808 + If you say Y here, processes inside a chroot will not be able to raise
69809 + the priority of processes in the chroot, or alter the priority of
69810 + processes outside the chroot. This provides more security than simply
69811 + removing CAP_SYS_NICE from the process' capability set. If the
69812 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
69813 + is created.
69814 +
69815 +config GRKERNSEC_CHROOT_SYSCTL
69816 + bool "Deny sysctl writes"
69817 + default y if GRKERNSEC_CONFIG_AUTO
69818 + depends on GRKERNSEC_CHROOT
69819 + help
69820 + If you say Y here, an attacker in a chroot will not be able to
69821 + write to sysctl entries, either by sysctl(2) or through a /proc
69822 + interface. It is strongly recommended that you say Y here. If the
69823 + sysctl option is enabled, a sysctl option with name
69824 + "chroot_deny_sysctl" is created.
69825 +
69826 +config GRKERNSEC_CHROOT_CAPS
69827 + bool "Capability restrictions"
69828 + default y if GRKERNSEC_CONFIG_AUTO
69829 + depends on GRKERNSEC_CHROOT
69830 + help
69831 + If you say Y here, the capabilities on all processes within a
69832 + chroot jail will be lowered to stop module insertion, raw i/o,
69833 + system and net admin tasks, rebooting the system, modifying immutable
69834 + files, modifying IPC owned by another, and changing the system time.
69835 + This is left an option because it can break some apps. Disable this
69836 + if your chrooted apps are having problems performing those kinds of
69837 + tasks. If the sysctl option is enabled, a sysctl option with
69838 + name "chroot_caps" is created.
69839 +
69840 +config GRKERNSEC_CHROOT_INITRD
69841 + bool "Exempt initrd tasks from restrictions"
69842 + default y if GRKERNSEC_CONFIG_AUTO
69843 + depends on GRKERNSEC_CHROOT && BLK_DEV_INITRD
69844 + help
69845 + If you say Y here, tasks started prior to init will be exempted from
69846 + grsecurity's chroot restrictions. This option is mainly meant to
69847 + resolve Plymouth's performing privileged operations unnecessarily
69848 + in a chroot.
69849 +
69850 +endmenu
69851 +menu "Kernel Auditing"
69852 +depends on GRKERNSEC
69853 +
69854 +config GRKERNSEC_AUDIT_GROUP
69855 + bool "Single group for auditing"
69856 + help
69857 + If you say Y here, the exec and chdir logging features will only operate
69858 + on a group you specify. This option is recommended if you only want to
69859 + watch certain users instead of having a large amount of logs from the
69860 + entire system. If the sysctl option is enabled, a sysctl option with
69861 + name "audit_group" is created.
69862 +
69863 +config GRKERNSEC_AUDIT_GID
69864 + int "GID for auditing"
69865 + depends on GRKERNSEC_AUDIT_GROUP
69866 + default 1007
69867 +
69868 +config GRKERNSEC_EXECLOG
69869 + bool "Exec logging"
69870 + help
69871 + If you say Y here, all execve() calls will be logged (since the
69872 + other exec*() calls are frontends to execve(), all execution
69873 + will be logged). Useful for shell-servers that like to keep track
69874 + of their users. If the sysctl option is enabled, a sysctl option with
69875 + name "exec_logging" is created.
69876 + WARNING: This option when enabled will produce a LOT of logs, especially
69877 + on an active system.
69878 +
69879 +config GRKERNSEC_RESLOG
69880 + bool "Resource logging"
69881 + default y if GRKERNSEC_CONFIG_AUTO
69882 + help
69883 + If you say Y here, all attempts to overstep resource limits will
69884 + be logged with the resource name, the requested size, and the current
69885 + limit. It is highly recommended that you say Y here. If the sysctl
69886 + option is enabled, a sysctl option with name "resource_logging" is
69887 + created. If the RBAC system is enabled, the sysctl value is ignored.
69888 +
69889 +config GRKERNSEC_CHROOT_EXECLOG
69890 + bool "Log execs within chroot"
69891 + help
69892 + If you say Y here, all executions inside a chroot jail will be logged
69893 + to syslog. This can cause a large amount of logs if certain
69894 + applications (eg. djb's daemontools) are installed on the system, and
69895 + is therefore left as an option. If the sysctl option is enabled, a
69896 + sysctl option with name "chroot_execlog" is created.
69897 +
69898 +config GRKERNSEC_AUDIT_PTRACE
69899 + bool "Ptrace logging"
69900 + help
69901 + If you say Y here, all attempts to attach to a process via ptrace
69902 + will be logged. If the sysctl option is enabled, a sysctl option
69903 + with name "audit_ptrace" is created.
69904 +
69905 +config GRKERNSEC_AUDIT_CHDIR
69906 + bool "Chdir logging"
69907 + help
69908 + If you say Y here, all chdir() calls will be logged. If the sysctl
69909 + option is enabled, a sysctl option with name "audit_chdir" is created.
69910 +
69911 +config GRKERNSEC_AUDIT_MOUNT
69912 + bool "(Un)Mount logging"
69913 + help
69914 + If you say Y here, all mounts and unmounts will be logged. If the
69915 + sysctl option is enabled, a sysctl option with name "audit_mount" is
69916 + created.
69917 +
69918 +config GRKERNSEC_SIGNAL
69919 + bool "Signal logging"
69920 + default y if GRKERNSEC_CONFIG_AUTO
69921 + help
69922 + If you say Y here, certain important signals will be logged, such as
69923 + SIGSEGV, which will as a result inform you of when a error in a program
69924 + occurred, which in some cases could mean a possible exploit attempt.
69925 + If the sysctl option is enabled, a sysctl option with name
69926 + "signal_logging" is created.
69927 +
69928 +config GRKERNSEC_FORKFAIL
69929 + bool "Fork failure logging"
69930 + help
69931 + If you say Y here, all failed fork() attempts will be logged.
69932 + This could suggest a fork bomb, or someone attempting to overstep
69933 + their process limit. If the sysctl option is enabled, a sysctl option
69934 + with name "forkfail_logging" is created.
69935 +
69936 +config GRKERNSEC_TIME
69937 + bool "Time change logging"
69938 + default y if GRKERNSEC_CONFIG_AUTO
69939 + help
69940 + If you say Y here, any changes of the system clock will be logged.
69941 + If the sysctl option is enabled, a sysctl option with name
69942 + "timechange_logging" is created.
69943 +
69944 +config GRKERNSEC_PROC_IPADDR
69945 + bool "/proc/<pid>/ipaddr support"
69946 + default y if GRKERNSEC_CONFIG_AUTO
69947 + help
69948 + If you say Y here, a new entry will be added to each /proc/<pid>
69949 + directory that contains the IP address of the person using the task.
69950 + The IP is carried across local TCP and AF_UNIX stream sockets.
69951 + This information can be useful for IDS/IPSes to perform remote response
69952 + to a local attack. The entry is readable by only the owner of the
69953 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
69954 + the RBAC system), and thus does not create privacy concerns.
69955 +
69956 +config GRKERNSEC_RWXMAP_LOG
69957 + bool 'Denied RWX mmap/mprotect logging'
69958 + default y if GRKERNSEC_CONFIG_AUTO
69959 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
69960 + help
69961 + If you say Y here, calls to mmap() and mprotect() with explicit
69962 + usage of PROT_WRITE and PROT_EXEC together will be logged when
69963 + denied by the PAX_MPROTECT feature. This feature will also
69964 + log other problematic scenarios that can occur when PAX_MPROTECT
69965 + is enabled on a binary, like textrels and PT_GNU_STACK. If the
69966 + sysctl option is enabled, a sysctl option with name "rwxmap_logging"
69967 + is created.
69968 +
69969 +endmenu
69970 +
69971 +menu "Executable Protections"
69972 +depends on GRKERNSEC
69973 +
69974 +config GRKERNSEC_DMESG
69975 + bool "Dmesg(8) restriction"
69976 + default y if GRKERNSEC_CONFIG_AUTO
69977 + help
69978 + If you say Y here, non-root users will not be able to use dmesg(8)
69979 + to view the contents of the kernel's circular log buffer.
69980 + The kernel's log buffer often contains kernel addresses and other
69981 + identifying information useful to an attacker in fingerprinting a
69982 + system for a targeted exploit.
69983 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
69984 + created.
69985 +
69986 +config GRKERNSEC_HARDEN_PTRACE
69987 + bool "Deter ptrace-based process snooping"
69988 + default y if GRKERNSEC_CONFIG_AUTO
69989 + help
69990 + If you say Y here, TTY sniffers and other malicious monitoring
69991 + programs implemented through ptrace will be defeated. If you
69992 + have been using the RBAC system, this option has already been
69993 + enabled for several years for all users, with the ability to make
69994 + fine-grained exceptions.
69995 +
69996 + This option only affects the ability of non-root users to ptrace
69997 + processes that are not a descendent of the ptracing process.
69998 + This means that strace ./binary and gdb ./binary will still work,
69999 + but attaching to arbitrary processes will not. If the sysctl
70000 + option is enabled, a sysctl option with name "harden_ptrace" is
70001 + created.
70002 +
70003 +config GRKERNSEC_PTRACE_READEXEC
70004 + bool "Require read access to ptrace sensitive binaries"
70005 + default y if GRKERNSEC_CONFIG_AUTO
70006 + help
70007 + If you say Y here, unprivileged users will not be able to ptrace unreadable
70008 + binaries. This option is useful in environments that
70009 + remove the read bits (e.g. file mode 4711) from suid binaries to
70010 + prevent infoleaking of their contents. This option adds
70011 + consistency to the use of that file mode, as the binary could normally
70012 + be read out when run without privileges while ptracing.
70013 +
70014 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
70015 + is created.
70016 +
70017 +config GRKERNSEC_SETXID
70018 + bool "Enforce consistent multithreaded privileges"
70019 + default y if GRKERNSEC_CONFIG_AUTO
70020 + depends on (X86 || SPARC64 || PPC || ARM || MIPS)
70021 + help
70022 + If you say Y here, a change from a root uid to a non-root uid
70023 + in a multithreaded application will cause the resulting uids,
70024 + gids, supplementary groups, and capabilities in that thread
70025 + to be propagated to the other threads of the process. In most
70026 + cases this is unnecessary, as glibc will emulate this behavior
70027 + on behalf of the application. Other libcs do not act in the
70028 + same way, allowing the other threads of the process to continue
70029 + running with root privileges. If the sysctl option is enabled,
70030 + a sysctl option with name "consistent_setxid" is created.
70031 +
70032 +config GRKERNSEC_HARDEN_IPC
70033 + bool "Disallow access to overly-permissive IPC objects"
70034 + default y if GRKERNSEC_CONFIG_AUTO
70035 + depends on SYSVIPC
70036 + help
70037 + If you say Y here, access to overly-permissive IPC objects (shared
70038 + memory, message queues, and semaphores) will be denied for processes
70039 + given the following criteria beyond normal permission checks:
70040 + 1) If the IPC object is world-accessible and the euid doesn't match
70041 + that of the creator or current uid for the IPC object
70042 + 2) If the IPC object is group-accessible and the egid doesn't
70043 + match that of the creator or current gid for the IPC object
70044 + It's a common error to grant too much permission to these objects,
70045 + with impact ranging from denial of service and information leaking to
70046 + privilege escalation. This feature was developed in response to
70047 + research by Tim Brown:
70048 + http://labs.portcullis.co.uk/whitepapers/memory-squatting-attacks-on-system-v-shared-memory/
70049 + who found hundreds of such insecure usages. Processes with
70050 + CAP_IPC_OWNER are still permitted to access these IPC objects.
70051 + If the sysctl option is enabled, a sysctl option with name
70052 + "harden_ipc" is created.
70053 +
70054 +config GRKERNSEC_TPE
70055 + bool "Trusted Path Execution (TPE)"
70056 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
70057 + help
70058 + If you say Y here, you will be able to choose a gid to add to the
70059 + supplementary groups of users you want to mark as "untrusted."
70060 + These users will not be able to execute any files that are not in
70061 + root-owned directories writable only by root. If the sysctl option
70062 + is enabled, a sysctl option with name "tpe" is created.
70063 +
70064 +config GRKERNSEC_TPE_ALL
70065 + bool "Partially restrict all non-root users"
70066 + depends on GRKERNSEC_TPE
70067 + help
70068 + If you say Y here, all non-root users will be covered under
70069 + a weaker TPE restriction. This is separate from, and in addition to,
70070 + the main TPE options that you have selected elsewhere. Thus, if a
70071 + "trusted" GID is chosen, this restriction applies to even that GID.
70072 + Under this restriction, all non-root users will only be allowed to
70073 + execute files in directories they own that are not group or
70074 + world-writable, or in directories owned by root and writable only by
70075 + root. If the sysctl option is enabled, a sysctl option with name
70076 + "tpe_restrict_all" is created.
70077 +
70078 +config GRKERNSEC_TPE_INVERT
70079 + bool "Invert GID option"
70080 + depends on GRKERNSEC_TPE
70081 + help
70082 + If you say Y here, the group you specify in the TPE configuration will
70083 + decide what group TPE restrictions will be *disabled* for. This
70084 + option is useful if you want TPE restrictions to be applied to most
70085 + users on the system. If the sysctl option is enabled, a sysctl option
70086 + with name "tpe_invert" is created. Unlike other sysctl options, this
70087 + entry will default to on for backward-compatibility.
70088 +
70089 +config GRKERNSEC_TPE_GID
70090 + int
70091 + default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
70092 + default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
70093 +
70094 +config GRKERNSEC_TPE_UNTRUSTED_GID
70095 + int "GID for TPE-untrusted users"
70096 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
70097 + default 1005
70098 + help
70099 + Setting this GID determines what group TPE restrictions will be
70100 + *enabled* for. If the sysctl option is enabled, a sysctl option
70101 + with name "tpe_gid" is created.
70102 +
70103 +config GRKERNSEC_TPE_TRUSTED_GID
70104 + int "GID for TPE-trusted users"
70105 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
70106 + default 1005
70107 + help
70108 + Setting this GID determines what group TPE restrictions will be
70109 + *disabled* for. If the sysctl option is enabled, a sysctl option
70110 + with name "tpe_gid" is created.
70111 +
70112 +endmenu
70113 +menu "Network Protections"
70114 +depends on GRKERNSEC
70115 +
70116 +config GRKERNSEC_BLACKHOLE
70117 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
70118 + default y if GRKERNSEC_CONFIG_AUTO
70119 + depends on NET
70120 + help
70121 + If you say Y here, neither TCP resets nor ICMP
70122 + destination-unreachable packets will be sent in response to packets
70123 + sent to ports for which no associated listening process exists.
70124 + It will also prevent the sending of ICMP protocol unreachable packets
70125 + in response to packets with unknown protocols.
70126 + This feature supports both IPV4 and IPV6 and exempts the
70127 + loopback interface from blackholing. Enabling this feature
70128 + makes a host more resilient to DoS attacks and reduces network
70129 + visibility against scanners.
70130 +
70131 + The blackhole feature as-implemented is equivalent to the FreeBSD
70132 + blackhole feature, as it prevents RST responses to all packets, not
70133 + just SYNs. Under most application behavior this causes no
70134 + problems, but applications (like haproxy) may not close certain
70135 + connections in a way that cleanly terminates them on the remote
70136 + end, leaving the remote host in LAST_ACK state. Because of this
70137 + side-effect and to prevent intentional LAST_ACK DoSes, this
70138 + feature also adds automatic mitigation against such attacks.
70139 + The mitigation drastically reduces the amount of time a socket
70140 + can spend in LAST_ACK state. If you're using haproxy and not
70141 + all servers it connects to have this option enabled, consider
70142 + disabling this feature on the haproxy host.
70143 +
70144 + If the sysctl option is enabled, two sysctl options with names
70145 + "ip_blackhole" and "lastack_retries" will be created.
70146 + While "ip_blackhole" takes the standard zero/non-zero on/off
70147 + toggle, "lastack_retries" uses the same kinds of values as
70148 + "tcp_retries1" and "tcp_retries2". The default value of 4
70149 + prevents a socket from lasting more than 45 seconds in LAST_ACK
70150 + state.
70151 +
70152 +config GRKERNSEC_NO_SIMULT_CONNECT
70153 + bool "Disable TCP Simultaneous Connect"
70154 + default y if GRKERNSEC_CONFIG_AUTO
70155 + depends on NET
70156 + help
70157 + If you say Y here, a feature by Willy Tarreau will be enabled that
70158 + removes a weakness in Linux's strict implementation of TCP that
70159 + allows two clients to connect to each other without either entering
70160 + a listening state. The weakness allows an attacker to easily prevent
70161 + a client from connecting to a known server provided the source port
70162 + for the connection is guessed correctly.
70163 +
70164 + As the weakness could be used to prevent an antivirus or IPS from
70165 + fetching updates, or prevent an SSL gateway from fetching a CRL,
70166 + it should be eliminated by enabling this option. Though Linux is
70167 + one of few operating systems supporting simultaneous connect, it
70168 + has no legitimate use in practice and is rarely supported by firewalls.
70169 +
70170 +config GRKERNSEC_SOCKET
70171 + bool "Socket restrictions"
70172 + depends on NET
70173 + help
70174 + If you say Y here, you will be able to choose from several options.
70175 + If you assign a GID on your system and add it to the supplementary
70176 + groups of users you want to restrict socket access to, this patch
70177 + will perform up to three things, based on the option(s) you choose.
70178 +
70179 +config GRKERNSEC_SOCKET_ALL
70180 + bool "Deny any sockets to group"
70181 + depends on GRKERNSEC_SOCKET
70182 + help
70183 + If you say Y here, you will be able to choose a GID of whose users will
70184 + be unable to connect to other hosts from your machine or run server
70185 + applications from your machine. If the sysctl option is enabled, a
70186 + sysctl option with name "socket_all" is created.
70187 +
70188 +config GRKERNSEC_SOCKET_ALL_GID
70189 + int "GID to deny all sockets for"
70190 + depends on GRKERNSEC_SOCKET_ALL
70191 + default 1004
70192 + help
70193 + Here you can choose the GID to disable socket access for. Remember to
70194 + add the users you want socket access disabled for to the GID
70195 + specified here. If the sysctl option is enabled, a sysctl option
70196 + with name "socket_all_gid" is created.
70197 +
70198 +config GRKERNSEC_SOCKET_CLIENT
70199 + bool "Deny client sockets to group"
70200 + depends on GRKERNSEC_SOCKET
70201 + help
70202 + If you say Y here, you will be able to choose a GID of whose users will
70203 + be unable to connect to other hosts from your machine, but will be
70204 + able to run servers. If this option is enabled, all users in the group
70205 + you specify will have to use passive mode when initiating ftp transfers
70206 + from the shell on your machine. If the sysctl option is enabled, a
70207 + sysctl option with name "socket_client" is created.
70208 +
70209 +config GRKERNSEC_SOCKET_CLIENT_GID
70210 + int "GID to deny client sockets for"
70211 + depends on GRKERNSEC_SOCKET_CLIENT
70212 + default 1003
70213 + help
70214 + Here you can choose the GID to disable client socket access for.
70215 + Remember to add the users you want client socket access disabled for to
70216 + the GID specified here. If the sysctl option is enabled, a sysctl
70217 + option with name "socket_client_gid" is created.
70218 +
70219 +config GRKERNSEC_SOCKET_SERVER
70220 + bool "Deny server sockets to group"
70221 + depends on GRKERNSEC_SOCKET
70222 + help
70223 + If you say Y here, you will be able to choose a GID of whose users will
70224 + be unable to run server applications from your machine. If the sysctl
70225 + option is enabled, a sysctl option with name "socket_server" is created.
70226 +
70227 +config GRKERNSEC_SOCKET_SERVER_GID
70228 + int "GID to deny server sockets for"
70229 + depends on GRKERNSEC_SOCKET_SERVER
70230 + default 1002
70231 + help
70232 + Here you can choose the GID to disable server socket access for.
70233 + Remember to add the users you want server socket access disabled for to
70234 + the GID specified here. If the sysctl option is enabled, a sysctl
70235 + option with name "socket_server_gid" is created.
70236 +
70237 +endmenu
70238 +
70239 +menu "Physical Protections"
70240 +depends on GRKERNSEC
70241 +
70242 +config GRKERNSEC_DENYUSB
70243 + bool "Deny new USB connections after toggle"
70244 + default y if GRKERNSEC_CONFIG_AUTO
70245 + depends on SYSCTL && USB_SUPPORT
70246 + help
70247 + If you say Y here, a new sysctl option with name "deny_new_usb"
70248 + will be created. Setting its value to 1 will prevent any new
70249 + USB devices from being recognized by the OS. Any attempted USB
70250 + device insertion will be logged. This option is intended to be
70251 + used against custom USB devices designed to exploit vulnerabilities
70252 + in various USB device drivers.
70253 +
70254 + For greatest effectiveness, this sysctl should be set after any
70255 + relevant init scripts. This option is safe to enable in distros
70256 + as each user can choose whether or not to toggle the sysctl.
70257 +
70258 +config GRKERNSEC_DENYUSB_FORCE
70259 + bool "Reject all USB devices not connected at boot"
70260 + select USB
70261 + depends on GRKERNSEC_DENYUSB
70262 + help
70263 + If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
70264 + that doesn't involve a sysctl entry. This option should only be
70265 + enabled if you're sure you want to deny all new USB connections
70266 + at runtime and don't want to modify init scripts. This should not
70267 + be enabled by distros. It forces the core USB code to be built
70268 + into the kernel image so that all devices connected at boot time
70269 + can be recognized and new USB device connections can be prevented
70270 + prior to init running.
70271 +
70272 +endmenu
70273 +
70274 +menu "Sysctl Support"
70275 +depends on GRKERNSEC && SYSCTL
70276 +
70277 +config GRKERNSEC_SYSCTL
70278 + bool "Sysctl support"
70279 + default y if GRKERNSEC_CONFIG_AUTO
70280 + help
70281 + If you say Y here, you will be able to change the options that
70282 + grsecurity runs with at bootup, without having to recompile your
70283 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
70284 + to enable (1) or disable (0) various features. All the sysctl entries
70285 + are mutable until the "grsec_lock" entry is set to a non-zero value.
70286 + All features enabled in the kernel configuration are disabled at boot
70287 + if you do not say Y to the "Turn on features by default" option.
70288 + All options should be set at startup, and the grsec_lock entry should
70289 + be set to a non-zero value after all the options are set.
70290 + *THIS IS EXTREMELY IMPORTANT*
70291 +
70292 +config GRKERNSEC_SYSCTL_DISTRO
70293 + bool "Extra sysctl support for distro makers (READ HELP)"
70294 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
70295 + help
70296 + If you say Y here, additional sysctl options will be created
70297 + for features that affect processes running as root. Therefore,
70298 + it is critical when using this option that the grsec_lock entry be
70299 + enabled after boot. Only distros with prebuilt kernel packages
70300 + with this option enabled that can ensure grsec_lock is enabled
70301 + after boot should use this option.
70302 + *Failure to set grsec_lock after boot makes all grsec features
70303 + this option covers useless*
70304 +
70305 + Currently this option creates the following sysctl entries:
70306 + "Disable Privileged I/O": "disable_priv_io"
70307 +
70308 +config GRKERNSEC_SYSCTL_ON
70309 + bool "Turn on features by default"
70310 + default y if GRKERNSEC_CONFIG_AUTO
70311 + depends on GRKERNSEC_SYSCTL
70312 + help
70313 + If you say Y here, instead of having all features enabled in the
70314 + kernel configuration disabled at boot time, the features will be
70315 + enabled at boot time. It is recommended you say Y here unless
70316 + there is some reason you would want all sysctl-tunable features to
70317 + be disabled by default. As mentioned elsewhere, it is important
70318 + to enable the grsec_lock entry once you have finished modifying
70319 + the sysctl entries.
70320 +
70321 +endmenu
70322 +menu "Logging Options"
70323 +depends on GRKERNSEC
70324 +
70325 +config GRKERNSEC_FLOODTIME
70326 + int "Seconds in between log messages (minimum)"
70327 + default 10
70328 + help
70329 + This option allows you to enforce the number of seconds between
70330 + grsecurity log messages. The default should be suitable for most
70331 + people, however, if you choose to change it, choose a value small enough
70332 + to allow informative logs to be produced, but large enough to
70333 + prevent flooding.
70334 +
70335 + Setting both this value and GRKERNSEC_FLOODBURST to 0 will disable
70336 + any rate limiting on grsecurity log messages.
70337 +
70338 +config GRKERNSEC_FLOODBURST
70339 + int "Number of messages in a burst (maximum)"
70340 + default 6
70341 + help
70342 + This option allows you to choose the maximum number of messages allowed
70343 + within the flood time interval you chose in a separate option. The
70344 + default should be suitable for most people, however if you find that
70345 + many of your logs are being interpreted as flooding, you may want to
70346 + raise this value.
70347 +
70348 + Setting both this value and GRKERNSEC_FLOODTIME to 0 will disable
70349 + any rate limiting on grsecurity log messages.
70350 +
70351 +endmenu
70352 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
70353 new file mode 100644
70354 index 0000000..30ababb
70355 --- /dev/null
70356 +++ b/grsecurity/Makefile
70357 @@ -0,0 +1,54 @@
70358 +# grsecurity – access control and security hardening for Linux
70359 +# All code in this directory and various hooks located throughout the Linux kernel are
70360 +# Copyright (C) 2001-2014 Bradley Spengler, Open Source Security, Inc.
70361 +# http://www.grsecurity.net spender@grsecurity.net
70362 +#
70363 +# This program is free software; you can redistribute it and/or
70364 +# modify it under the terms of the GNU General Public License version 2
70365 +# as published by the Free Software Foundation.
70366 +#
70367 +# This program is distributed in the hope that it will be useful,
70368 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
70369 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
70370 +# GNU General Public License for more details.
70371 +#
70372 +# You should have received a copy of the GNU General Public License
70373 +# along with this program; if not, write to the Free Software
70374 +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
70375 +
70376 +KBUILD_CFLAGS += -Werror
70377 +
70378 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
70379 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
70380 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
70381 + grsec_usb.o grsec_ipc.o grsec_proc.o
70382 +
70383 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
70384 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
70385 + gracl_learn.o grsec_log.o gracl_policy.o
70386 +ifdef CONFIG_COMPAT
70387 +obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
70388 +endif
70389 +
70390 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
70391 +
70392 +ifdef CONFIG_NET
70393 +obj-y += grsec_sock.o
70394 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
70395 +endif
70396 +
70397 +ifndef CONFIG_GRKERNSEC
70398 +obj-y += grsec_disabled.o
70399 +endif
70400 +
70401 +ifdef CONFIG_GRKERNSEC_HIDESYM
70402 +extra-y := grsec_hidesym.o
70403 +$(obj)/grsec_hidesym.o:
70404 + @-chmod -f 500 /boot
70405 + @-chmod -f 500 /lib/modules
70406 + @-chmod -f 500 /lib64/modules
70407 + @-chmod -f 500 /lib32/modules
70408 + @-chmod -f 700 .
70409 + @-chmod -f 700 $(objtree)
70410 + @echo ' grsec: protected kernel image paths'
70411 +endif
70412 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
70413 new file mode 100644
70414 index 0000000..6ae3aa0
70415 --- /dev/null
70416 +++ b/grsecurity/gracl.c
70417 @@ -0,0 +1,2703 @@
70418 +#include <linux/kernel.h>
70419 +#include <linux/module.h>
70420 +#include <linux/sched.h>
70421 +#include <linux/mm.h>
70422 +#include <linux/file.h>
70423 +#include <linux/fs.h>
70424 +#include <linux/namei.h>
70425 +#include <linux/mount.h>
70426 +#include <linux/tty.h>
70427 +#include <linux/proc_fs.h>
70428 +#include <linux/lglock.h>
70429 +#include <linux/slab.h>
70430 +#include <linux/vmalloc.h>
70431 +#include <linux/types.h>
70432 +#include <linux/sysctl.h>
70433 +#include <linux/netdevice.h>
70434 +#include <linux/ptrace.h>
70435 +#include <linux/gracl.h>
70436 +#include <linux/gralloc.h>
70437 +#include <linux/security.h>
70438 +#include <linux/grinternal.h>
70439 +#include <linux/pid_namespace.h>
70440 +#include <linux/stop_machine.h>
70441 +#include <linux/fdtable.h>
70442 +#include <linux/percpu.h>
70443 +#include <linux/lglock.h>
70444 +#include <linux/hugetlb.h>
70445 +#include <linux/posix-timers.h>
70446 +#include <linux/prefetch.h>
70447 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
70448 +#include <linux/magic.h>
70449 +#include <linux/pagemap.h>
70450 +#include "../fs/btrfs/async-thread.h"
70451 +#include "../fs/btrfs/ctree.h"
70452 +#include "../fs/btrfs/btrfs_inode.h"
70453 +#endif
70454 +#include "../fs/mount.h"
70455 +
70456 +#include <asm/uaccess.h>
70457 +#include <asm/errno.h>
70458 +#include <asm/mman.h>
70459 +
70460 +#define FOR_EACH_ROLE_START(role) \
70461 + role = running_polstate.role_list; \
70462 + while (role) {
70463 +
70464 +#define FOR_EACH_ROLE_END(role) \
70465 + role = role->prev; \
70466 + }
70467 +
70468 +extern struct path gr_real_root;
70469 +
70470 +static struct gr_policy_state running_polstate;
70471 +struct gr_policy_state *polstate = &running_polstate;
70472 +extern struct gr_alloc_state *current_alloc_state;
70473 +
70474 +extern char *gr_shared_page[4];
70475 +DEFINE_RWLOCK(gr_inode_lock);
70476 +
70477 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
70478 +
70479 +#ifdef CONFIG_NET
70480 +extern struct vfsmount *sock_mnt;
70481 +#endif
70482 +
70483 +extern struct vfsmount *pipe_mnt;
70484 +extern struct vfsmount *shm_mnt;
70485 +
70486 +#ifdef CONFIG_HUGETLBFS
70487 +extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
70488 +#endif
70489 +
70490 +extern u16 acl_sp_role_value;
70491 +extern struct acl_object_label *fakefs_obj_rw;
70492 +extern struct acl_object_label *fakefs_obj_rwx;
70493 +
70494 +int gr_acl_is_enabled(void)
70495 +{
70496 + return (gr_status & GR_READY);
70497 +}
70498 +
70499 +void gr_enable_rbac_system(void)
70500 +{
70501 + pax_open_kernel();
70502 + gr_status |= GR_READY;
70503 + pax_close_kernel();
70504 +}
70505 +
70506 +int gr_rbac_disable(void *unused)
70507 +{
70508 + pax_open_kernel();
70509 + gr_status &= ~GR_READY;
70510 + pax_close_kernel();
70511 +
70512 + return 0;
70513 +}
70514 +
70515 +static inline dev_t __get_dev(const struct dentry *dentry)
70516 +{
70517 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
70518 + if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
70519 + return BTRFS_I(dentry->d_inode)->root->anon_dev;
70520 + else
70521 +#endif
70522 + return dentry->d_sb->s_dev;
70523 +}
70524 +
70525 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
70526 +{
70527 + return __get_dev(dentry);
70528 +}
70529 +
70530 +static char gr_task_roletype_to_char(struct task_struct *task)
70531 +{
70532 + switch (task->role->roletype &
70533 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
70534 + GR_ROLE_SPECIAL)) {
70535 + case GR_ROLE_DEFAULT:
70536 + return 'D';
70537 + case GR_ROLE_USER:
70538 + return 'U';
70539 + case GR_ROLE_GROUP:
70540 + return 'G';
70541 + case GR_ROLE_SPECIAL:
70542 + return 'S';
70543 + }
70544 +
70545 + return 'X';
70546 +}
70547 +
70548 +char gr_roletype_to_char(void)
70549 +{
70550 + return gr_task_roletype_to_char(current);
70551 +}
70552 +
70553 +__inline__ int
70554 +gr_acl_tpe_check(void)
70555 +{
70556 + if (unlikely(!(gr_status & GR_READY)))
70557 + return 0;
70558 + if (current->role->roletype & GR_ROLE_TPE)
70559 + return 1;
70560 + else
70561 + return 0;
70562 +}
70563 +
70564 +int
70565 +gr_handle_rawio(const struct inode *inode)
70566 +{
70567 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
70568 + if (inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR)) &&
70569 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
70570 + !capable(CAP_SYS_RAWIO))
70571 + return 1;
70572 +#endif
70573 + return 0;
70574 +}
70575 +
70576 +int
70577 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
70578 +{
70579 + if (likely(lena != lenb))
70580 + return 0;
70581 +
70582 + return !memcmp(a, b, lena);
70583 +}
70584 +
70585 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
70586 +{
70587 + *buflen -= namelen;
70588 + if (*buflen < 0)
70589 + return -ENAMETOOLONG;
70590 + *buffer -= namelen;
70591 + memcpy(*buffer, str, namelen);
70592 + return 0;
70593 +}
70594 +
70595 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
70596 +{
70597 + return prepend(buffer, buflen, name->name, name->len);
70598 +}
70599 +
70600 +static int prepend_path(const struct path *path, struct path *root,
70601 + char **buffer, int *buflen)
70602 +{
70603 + struct dentry *dentry = path->dentry;
70604 + struct vfsmount *vfsmnt = path->mnt;
70605 + struct mount *mnt = real_mount(vfsmnt);
70606 + bool slash = false;
70607 + int error = 0;
70608 +
70609 + while (dentry != root->dentry || vfsmnt != root->mnt) {
70610 + struct dentry * parent;
70611 +
70612 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
70613 + /* Global root? */
70614 + if (!mnt_has_parent(mnt)) {
70615 + goto out;
70616 + }
70617 + dentry = mnt->mnt_mountpoint;
70618 + mnt = mnt->mnt_parent;
70619 + vfsmnt = &mnt->mnt;
70620 + continue;
70621 + }
70622 + parent = dentry->d_parent;
70623 + prefetch(parent);
70624 + spin_lock(&dentry->d_lock);
70625 + error = prepend_name(buffer, buflen, &dentry->d_name);
70626 + spin_unlock(&dentry->d_lock);
70627 + if (!error)
70628 + error = prepend(buffer, buflen, "/", 1);
70629 + if (error)
70630 + break;
70631 +
70632 + slash = true;
70633 + dentry = parent;
70634 + }
70635 +
70636 +out:
70637 + if (!error && !slash)
70638 + error = prepend(buffer, buflen, "/", 1);
70639 +
70640 + return error;
70641 +}
70642 +
70643 +/* this must be called with mount_lock and rename_lock held */
70644 +
70645 +static char *__our_d_path(const struct path *path, struct path *root,
70646 + char *buf, int buflen)
70647 +{
70648 + char *res = buf + buflen;
70649 + int error;
70650 +
70651 + prepend(&res, &buflen, "\0", 1);
70652 + error = prepend_path(path, root, &res, &buflen);
70653 + if (error)
70654 + return ERR_PTR(error);
70655 +
70656 + return res;
70657 +}
70658 +
70659 +static char *
70660 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
70661 +{
70662 + char *retval;
70663 +
70664 + retval = __our_d_path(path, root, buf, buflen);
70665 + if (unlikely(IS_ERR(retval)))
70666 + retval = strcpy(buf, "<path too long>");
70667 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
70668 + retval[1] = '\0';
70669 +
70670 + return retval;
70671 +}
70672 +
70673 +static char *
70674 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
70675 + char *buf, int buflen)
70676 +{
70677 + struct path path;
70678 + char *res;
70679 +
70680 + path.dentry = (struct dentry *)dentry;
70681 + path.mnt = (struct vfsmount *)vfsmnt;
70682 +
70683 + /* we can use gr_real_root.dentry, gr_real_root.mnt, because this is only called
70684 + by the RBAC system */
70685 + res = gen_full_path(&path, &gr_real_root, buf, buflen);
70686 +
70687 + return res;
70688 +}
70689 +
70690 +static char *
70691 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
70692 + char *buf, int buflen)
70693 +{
70694 + char *res;
70695 + struct path path;
70696 + struct path root;
70697 + struct task_struct *reaper = init_pid_ns.child_reaper;
70698 +
70699 + path.dentry = (struct dentry *)dentry;
70700 + path.mnt = (struct vfsmount *)vfsmnt;
70701 +
70702 + /* we can't use gr_real_root.dentry, gr_real_root.mnt, because they belong only to the RBAC system */
70703 + get_fs_root(reaper->fs, &root);
70704 +
70705 + read_seqlock_excl(&mount_lock);
70706 + write_seqlock(&rename_lock);
70707 + res = gen_full_path(&path, &root, buf, buflen);
70708 + write_sequnlock(&rename_lock);
70709 + read_sequnlock_excl(&mount_lock);
70710 +
70711 + path_put(&root);
70712 + return res;
70713 +}
70714 +
70715 +char *
70716 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
70717 +{
70718 + char *ret;
70719 + read_seqlock_excl(&mount_lock);
70720 + write_seqlock(&rename_lock);
70721 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
70722 + PAGE_SIZE);
70723 + write_sequnlock(&rename_lock);
70724 + read_sequnlock_excl(&mount_lock);
70725 + return ret;
70726 +}
70727 +
70728 +static char *
70729 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
70730 +{
70731 + char *ret;
70732 + char *buf;
70733 + int buflen;
70734 +
70735 + read_seqlock_excl(&mount_lock);
70736 + write_seqlock(&rename_lock);
70737 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
70738 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
70739 + buflen = (int)(ret - buf);
70740 + if (buflen >= 5)
70741 + prepend(&ret, &buflen, "/proc", 5);
70742 + else
70743 + ret = strcpy(buf, "<path too long>");
70744 + write_sequnlock(&rename_lock);
70745 + read_sequnlock_excl(&mount_lock);
70746 + return ret;
70747 +}
70748 +
70749 +char *
70750 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
70751 +{
70752 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
70753 + PAGE_SIZE);
70754 +}
70755 +
70756 +char *
70757 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
70758 +{
70759 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
70760 + PAGE_SIZE);
70761 +}
70762 +
70763 +char *
70764 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
70765 +{
70766 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
70767 + PAGE_SIZE);
70768 +}
70769 +
70770 +char *
70771 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
70772 +{
70773 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
70774 + PAGE_SIZE);
70775 +}
70776 +
70777 +char *
70778 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
70779 +{
70780 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
70781 + PAGE_SIZE);
70782 +}
70783 +
70784 +__inline__ __u32
70785 +to_gr_audit(const __u32 reqmode)
70786 +{
70787 + /* masks off auditable permission flags, then shifts them to create
70788 + auditing flags, and adds the special case of append auditing if
70789 + we're requesting write */
70790 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
70791 +}
70792 +
70793 +struct acl_role_label *
70794 +__lookup_acl_role_label(const struct gr_policy_state *state, const struct task_struct *task, const uid_t uid,
70795 + const gid_t gid)
70796 +{
70797 + unsigned int index = gr_rhash(uid, GR_ROLE_USER, state->acl_role_set.r_size);
70798 + struct acl_role_label *match;
70799 + struct role_allowed_ip *ipp;
70800 + unsigned int x;
70801 + u32 curr_ip = task->signal->saved_ip;
70802 +
70803 + match = state->acl_role_set.r_hash[index];
70804 +
70805 + while (match) {
70806 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
70807 + for (x = 0; x < match->domain_child_num; x++) {
70808 + if (match->domain_children[x] == uid)
70809 + goto found;
70810 + }
70811 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
70812 + break;
70813 + match = match->next;
70814 + }
70815 +found:
70816 + if (match == NULL) {
70817 + try_group:
70818 + index = gr_rhash(gid, GR_ROLE_GROUP, state->acl_role_set.r_size);
70819 + match = state->acl_role_set.r_hash[index];
70820 +
70821 + while (match) {
70822 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
70823 + for (x = 0; x < match->domain_child_num; x++) {
70824 + if (match->domain_children[x] == gid)
70825 + goto found2;
70826 + }
70827 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
70828 + break;
70829 + match = match->next;
70830 + }
70831 +found2:
70832 + if (match == NULL)
70833 + match = state->default_role;
70834 + if (match->allowed_ips == NULL)
70835 + return match;
70836 + else {
70837 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
70838 + if (likely
70839 + ((ntohl(curr_ip) & ipp->netmask) ==
70840 + (ntohl(ipp->addr) & ipp->netmask)))
70841 + return match;
70842 + }
70843 + match = state->default_role;
70844 + }
70845 + } else if (match->allowed_ips == NULL) {
70846 + return match;
70847 + } else {
70848 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
70849 + if (likely
70850 + ((ntohl(curr_ip) & ipp->netmask) ==
70851 + (ntohl(ipp->addr) & ipp->netmask)))
70852 + return match;
70853 + }
70854 + goto try_group;
70855 + }
70856 +
70857 + return match;
70858 +}
70859 +
70860 +static struct acl_role_label *
70861 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
70862 + const gid_t gid)
70863 +{
70864 + return __lookup_acl_role_label(&running_polstate, task, uid, gid);
70865 +}
70866 +
70867 +struct acl_subject_label *
70868 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
70869 + const struct acl_role_label *role)
70870 +{
70871 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
70872 + struct acl_subject_label *match;
70873 +
70874 + match = role->subj_hash[index];
70875 +
70876 + while (match && (match->inode != ino || match->device != dev ||
70877 + (match->mode & GR_DELETED))) {
70878 + match = match->next;
70879 + }
70880 +
70881 + if (match && !(match->mode & GR_DELETED))
70882 + return match;
70883 + else
70884 + return NULL;
70885 +}
70886 +
70887 +struct acl_subject_label *
70888 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
70889 + const struct acl_role_label *role)
70890 +{
70891 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
70892 + struct acl_subject_label *match;
70893 +
70894 + match = role->subj_hash[index];
70895 +
70896 + while (match && (match->inode != ino || match->device != dev ||
70897 + !(match->mode & GR_DELETED))) {
70898 + match = match->next;
70899 + }
70900 +
70901 + if (match && (match->mode & GR_DELETED))
70902 + return match;
70903 + else
70904 + return NULL;
70905 +}
70906 +
70907 +static struct acl_object_label *
70908 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
70909 + const struct acl_subject_label *subj)
70910 +{
70911 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
70912 + struct acl_object_label *match;
70913 +
70914 + match = subj->obj_hash[index];
70915 +
70916 + while (match && (match->inode != ino || match->device != dev ||
70917 + (match->mode & GR_DELETED))) {
70918 + match = match->next;
70919 + }
70920 +
70921 + if (match && !(match->mode & GR_DELETED))
70922 + return match;
70923 + else
70924 + return NULL;
70925 +}
70926 +
70927 +static struct acl_object_label *
70928 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
70929 + const struct acl_subject_label *subj)
70930 +{
70931 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
70932 + struct acl_object_label *match;
70933 +
70934 + match = subj->obj_hash[index];
70935 +
70936 + while (match && (match->inode != ino || match->device != dev ||
70937 + !(match->mode & GR_DELETED))) {
70938 + match = match->next;
70939 + }
70940 +
70941 + if (match && (match->mode & GR_DELETED))
70942 + return match;
70943 +
70944 + match = subj->obj_hash[index];
70945 +
70946 + while (match && (match->inode != ino || match->device != dev ||
70947 + (match->mode & GR_DELETED))) {
70948 + match = match->next;
70949 + }
70950 +
70951 + if (match && !(match->mode & GR_DELETED))
70952 + return match;
70953 + else
70954 + return NULL;
70955 +}
70956 +
70957 +struct name_entry *
70958 +__lookup_name_entry(const struct gr_policy_state *state, const char *name)
70959 +{
70960 + unsigned int len = strlen(name);
70961 + unsigned int key = full_name_hash(name, len);
70962 + unsigned int index = key % state->name_set.n_size;
70963 + struct name_entry *match;
70964 +
70965 + match = state->name_set.n_hash[index];
70966 +
70967 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
70968 + match = match->next;
70969 +
70970 + return match;
70971 +}
70972 +
70973 +static struct name_entry *
70974 +lookup_name_entry(const char *name)
70975 +{
70976 + return __lookup_name_entry(&running_polstate, name);
70977 +}
70978 +
70979 +static struct name_entry *
70980 +lookup_name_entry_create(const char *name)
70981 +{
70982 + unsigned int len = strlen(name);
70983 + unsigned int key = full_name_hash(name, len);
70984 + unsigned int index = key % running_polstate.name_set.n_size;
70985 + struct name_entry *match;
70986 +
70987 + match = running_polstate.name_set.n_hash[index];
70988 +
70989 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
70990 + !match->deleted))
70991 + match = match->next;
70992 +
70993 + if (match && match->deleted)
70994 + return match;
70995 +
70996 + match = running_polstate.name_set.n_hash[index];
70997 +
70998 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
70999 + match->deleted))
71000 + match = match->next;
71001 +
71002 + if (match && !match->deleted)
71003 + return match;
71004 + else
71005 + return NULL;
71006 +}
71007 +
71008 +static struct inodev_entry *
71009 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
71010 +{
71011 + unsigned int index = gr_fhash(ino, dev, running_polstate.inodev_set.i_size);
71012 + struct inodev_entry *match;
71013 +
71014 + match = running_polstate.inodev_set.i_hash[index];
71015 +
71016 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
71017 + match = match->next;
71018 +
71019 + return match;
71020 +}
71021 +
71022 +void
71023 +__insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry)
71024 +{
71025 + unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
71026 + state->inodev_set.i_size);
71027 + struct inodev_entry **curr;
71028 +
71029 + entry->prev = NULL;
71030 +
71031 + curr = &state->inodev_set.i_hash[index];
71032 + if (*curr != NULL)
71033 + (*curr)->prev = entry;
71034 +
71035 + entry->next = *curr;
71036 + *curr = entry;
71037 +
71038 + return;
71039 +}
71040 +
71041 +static void
71042 +insert_inodev_entry(struct inodev_entry *entry)
71043 +{
71044 + __insert_inodev_entry(&running_polstate, entry);
71045 +}
71046 +
71047 +void
71048 +insert_acl_obj_label(struct acl_object_label *obj,
71049 + struct acl_subject_label *subj)
71050 +{
71051 + unsigned int index =
71052 + gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
71053 + struct acl_object_label **curr;
71054 +
71055 + obj->prev = NULL;
71056 +
71057 + curr = &subj->obj_hash[index];
71058 + if (*curr != NULL)
71059 + (*curr)->prev = obj;
71060 +
71061 + obj->next = *curr;
71062 + *curr = obj;
71063 +
71064 + return;
71065 +}
71066 +
71067 +void
71068 +insert_acl_subj_label(struct acl_subject_label *obj,
71069 + struct acl_role_label *role)
71070 +{
71071 + unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
71072 + struct acl_subject_label **curr;
71073 +
71074 + obj->prev = NULL;
71075 +
71076 + curr = &role->subj_hash[index];
71077 + if (*curr != NULL)
71078 + (*curr)->prev = obj;
71079 +
71080 + obj->next = *curr;
71081 + *curr = obj;
71082 +
71083 + return;
71084 +}
71085 +
71086 +/* derived from glibc fnmatch() 0: match, 1: no match*/
71087 +
71088 +static int
71089 +glob_match(const char *p, const char *n)
71090 +{
71091 + char c;
71092 +
71093 + while ((c = *p++) != '\0') {
71094 + switch (c) {
71095 + case '?':
71096 + if (*n == '\0')
71097 + return 1;
71098 + else if (*n == '/')
71099 + return 1;
71100 + break;
71101 + case '\\':
71102 + if (*n != c)
71103 + return 1;
71104 + break;
71105 + case '*':
71106 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
71107 + if (*n == '/')
71108 + return 1;
71109 + else if (c == '?') {
71110 + if (*n == '\0')
71111 + return 1;
71112 + else
71113 + ++n;
71114 + }
71115 + }
71116 + if (c == '\0') {
71117 + return 0;
71118 + } else {
71119 + const char *endp;
71120 +
71121 + if ((endp = strchr(n, '/')) == NULL)
71122 + endp = n + strlen(n);
71123 +
71124 + if (c == '[') {
71125 + for (--p; n < endp; ++n)
71126 + if (!glob_match(p, n))
71127 + return 0;
71128 + } else if (c == '/') {
71129 + while (*n != '\0' && *n != '/')
71130 + ++n;
71131 + if (*n == '/' && !glob_match(p, n + 1))
71132 + return 0;
71133 + } else {
71134 + for (--p; n < endp; ++n)
71135 + if (*n == c && !glob_match(p, n))
71136 + return 0;
71137 + }
71138 +
71139 + return 1;
71140 + }
71141 + case '[':
71142 + {
71143 + int not;
71144 + char cold;
71145 +
71146 + if (*n == '\0' || *n == '/')
71147 + return 1;
71148 +
71149 + not = (*p == '!' || *p == '^');
71150 + if (not)
71151 + ++p;
71152 +
71153 + c = *p++;
71154 + for (;;) {
71155 + unsigned char fn = (unsigned char)*n;
71156 +
71157 + if (c == '\0')
71158 + return 1;
71159 + else {
71160 + if (c == fn)
71161 + goto matched;
71162 + cold = c;
71163 + c = *p++;
71164 +
71165 + if (c == '-' && *p != ']') {
71166 + unsigned char cend = *p++;
71167 +
71168 + if (cend == '\0')
71169 + return 1;
71170 +
71171 + if (cold <= fn && fn <= cend)
71172 + goto matched;
71173 +
71174 + c = *p++;
71175 + }
71176 + }
71177 +
71178 + if (c == ']')
71179 + break;
71180 + }
71181 + if (!not)
71182 + return 1;
71183 + break;
71184 + matched:
71185 + while (c != ']') {
71186 + if (c == '\0')
71187 + return 1;
71188 +
71189 + c = *p++;
71190 + }
71191 + if (not)
71192 + return 1;
71193 + }
71194 + break;
71195 + default:
71196 + if (c != *n)
71197 + return 1;
71198 + }
71199 +
71200 + ++n;
71201 + }
71202 +
71203 + if (*n == '\0')
71204 + return 0;
71205 +
71206 + if (*n == '/')
71207 + return 0;
71208 +
71209 + return 1;
71210 +}
71211 +
71212 +static struct acl_object_label *
71213 +chk_glob_label(struct acl_object_label *globbed,
71214 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
71215 +{
71216 + struct acl_object_label *tmp;
71217 +
71218 + if (*path == NULL)
71219 + *path = gr_to_filename_nolock(dentry, mnt);
71220 +
71221 + tmp = globbed;
71222 +
71223 + while (tmp) {
71224 + if (!glob_match(tmp->filename, *path))
71225 + return tmp;
71226 + tmp = tmp->next;
71227 + }
71228 +
71229 + return NULL;
71230 +}
71231 +
71232 +static struct acl_object_label *
71233 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
71234 + const ino_t curr_ino, const dev_t curr_dev,
71235 + const struct acl_subject_label *subj, char **path, const int checkglob)
71236 +{
71237 + struct acl_subject_label *tmpsubj;
71238 + struct acl_object_label *retval;
71239 + struct acl_object_label *retval2;
71240 +
71241 + tmpsubj = (struct acl_subject_label *) subj;
71242 + read_lock(&gr_inode_lock);
71243 + do {
71244 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
71245 + if (retval) {
71246 + if (checkglob && retval->globbed) {
71247 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
71248 + if (retval2)
71249 + retval = retval2;
71250 + }
71251 + break;
71252 + }
71253 + } while ((tmpsubj = tmpsubj->parent_subject));
71254 + read_unlock(&gr_inode_lock);
71255 +
71256 + return retval;
71257 +}
71258 +
71259 +static __inline__ struct acl_object_label *
71260 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
71261 + struct dentry *curr_dentry,
71262 + const struct acl_subject_label *subj, char **path, const int checkglob)
71263 +{
71264 + int newglob = checkglob;
71265 + ino_t inode;
71266 + dev_t device;
71267 +
71268 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
71269 + as we don't want a / * rule to match instead of the / object
71270 + don't do this for create lookups that call this function though, since they're looking up
71271 + on the parent and thus need globbing checks on all paths
71272 + */
71273 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
71274 + newglob = GR_NO_GLOB;
71275 +
71276 + spin_lock(&curr_dentry->d_lock);
71277 + inode = curr_dentry->d_inode->i_ino;
71278 + device = __get_dev(curr_dentry);
71279 + spin_unlock(&curr_dentry->d_lock);
71280 +
71281 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
71282 +}
71283 +
71284 +#ifdef CONFIG_HUGETLBFS
71285 +static inline bool
71286 +is_hugetlbfs_mnt(const struct vfsmount *mnt)
71287 +{
71288 + int i;
71289 + for (i = 0; i < HUGE_MAX_HSTATE; i++) {
71290 + if (unlikely(hugetlbfs_vfsmount[i] == mnt))
71291 + return true;
71292 + }
71293 +
71294 + return false;
71295 +}
71296 +#endif
71297 +
71298 +static struct acl_object_label *
71299 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
71300 + const struct acl_subject_label *subj, char *path, const int checkglob)
71301 +{
71302 + struct dentry *dentry = (struct dentry *) l_dentry;
71303 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
71304 + struct mount *real_mnt = real_mount(mnt);
71305 + struct acl_object_label *retval;
71306 + struct dentry *parent;
71307 +
71308 + read_seqlock_excl(&mount_lock);
71309 + write_seqlock(&rename_lock);
71310 +
71311 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
71312 +#ifdef CONFIG_NET
71313 + mnt == sock_mnt ||
71314 +#endif
71315 +#ifdef CONFIG_HUGETLBFS
71316 + (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
71317 +#endif
71318 + /* ignore Eric Biederman */
71319 + IS_PRIVATE(l_dentry->d_inode))) {
71320 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
71321 + goto out;
71322 + }
71323 +
71324 + for (;;) {
71325 + if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
71326 + break;
71327 +
71328 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
71329 + if (!mnt_has_parent(real_mnt))
71330 + break;
71331 +
71332 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
71333 + if (retval != NULL)
71334 + goto out;
71335 +
71336 + dentry = real_mnt->mnt_mountpoint;
71337 + real_mnt = real_mnt->mnt_parent;
71338 + mnt = &real_mnt->mnt;
71339 + continue;
71340 + }
71341 +
71342 + parent = dentry->d_parent;
71343 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
71344 + if (retval != NULL)
71345 + goto out;
71346 +
71347 + dentry = parent;
71348 + }
71349 +
71350 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
71351 +
71352 + /* gr_real_root is pinned so we don't have to hold a reference */
71353 + if (retval == NULL)
71354 + retval = full_lookup(l_dentry, l_mnt, gr_real_root.dentry, subj, &path, checkglob);
71355 +out:
71356 + write_sequnlock(&rename_lock);
71357 + read_sequnlock_excl(&mount_lock);
71358 +
71359 + BUG_ON(retval == NULL);
71360 +
71361 + return retval;
71362 +}
71363 +
71364 +static __inline__ struct acl_object_label *
71365 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
71366 + const struct acl_subject_label *subj)
71367 +{
71368 + char *path = NULL;
71369 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
71370 +}
71371 +
71372 +static __inline__ struct acl_object_label *
71373 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
71374 + const struct acl_subject_label *subj)
71375 +{
71376 + char *path = NULL;
71377 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
71378 +}
71379 +
71380 +static __inline__ struct acl_object_label *
71381 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
71382 + const struct acl_subject_label *subj, char *path)
71383 +{
71384 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
71385 +}
71386 +
71387 +struct acl_subject_label *
71388 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
71389 + const struct acl_role_label *role)
71390 +{
71391 + struct dentry *dentry = (struct dentry *) l_dentry;
71392 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
71393 + struct mount *real_mnt = real_mount(mnt);
71394 + struct acl_subject_label *retval;
71395 + struct dentry *parent;
71396 +
71397 + read_seqlock_excl(&mount_lock);
71398 + write_seqlock(&rename_lock);
71399 +
71400 + for (;;) {
71401 + if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
71402 + break;
71403 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
71404 + if (!mnt_has_parent(real_mnt))
71405 + break;
71406 +
71407 + spin_lock(&dentry->d_lock);
71408 + read_lock(&gr_inode_lock);
71409 + retval =
71410 + lookup_acl_subj_label(dentry->d_inode->i_ino,
71411 + __get_dev(dentry), role);
71412 + read_unlock(&gr_inode_lock);
71413 + spin_unlock(&dentry->d_lock);
71414 + if (retval != NULL)
71415 + goto out;
71416 +
71417 + dentry = real_mnt->mnt_mountpoint;
71418 + real_mnt = real_mnt->mnt_parent;
71419 + mnt = &real_mnt->mnt;
71420 + continue;
71421 + }
71422 +
71423 + spin_lock(&dentry->d_lock);
71424 + read_lock(&gr_inode_lock);
71425 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
71426 + __get_dev(dentry), role);
71427 + read_unlock(&gr_inode_lock);
71428 + parent = dentry->d_parent;
71429 + spin_unlock(&dentry->d_lock);
71430 +
71431 + if (retval != NULL)
71432 + goto out;
71433 +
71434 + dentry = parent;
71435 + }
71436 +
71437 + spin_lock(&dentry->d_lock);
71438 + read_lock(&gr_inode_lock);
71439 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
71440 + __get_dev(dentry), role);
71441 + read_unlock(&gr_inode_lock);
71442 + spin_unlock(&dentry->d_lock);
71443 +
71444 + if (unlikely(retval == NULL)) {
71445 + /* gr_real_root is pinned, we don't need to hold a reference */
71446 + read_lock(&gr_inode_lock);
71447 + retval = lookup_acl_subj_label(gr_real_root.dentry->d_inode->i_ino,
71448 + __get_dev(gr_real_root.dentry), role);
71449 + read_unlock(&gr_inode_lock);
71450 + }
71451 +out:
71452 + write_sequnlock(&rename_lock);
71453 + read_sequnlock_excl(&mount_lock);
71454 +
71455 + BUG_ON(retval == NULL);
71456 +
71457 + return retval;
71458 +}
71459 +
71460 +void
71461 +assign_special_role(const char *rolename)
71462 +{
71463 + struct acl_object_label *obj;
71464 + struct acl_role_label *r;
71465 + struct acl_role_label *assigned = NULL;
71466 + struct task_struct *tsk;
71467 + struct file *filp;
71468 +
71469 + FOR_EACH_ROLE_START(r)
71470 + if (!strcmp(rolename, r->rolename) &&
71471 + (r->roletype & GR_ROLE_SPECIAL)) {
71472 + assigned = r;
71473 + break;
71474 + }
71475 + FOR_EACH_ROLE_END(r)
71476 +
71477 + if (!assigned)
71478 + return;
71479 +
71480 + read_lock(&tasklist_lock);
71481 + read_lock(&grsec_exec_file_lock);
71482 +
71483 + tsk = current->real_parent;
71484 + if (tsk == NULL)
71485 + goto out_unlock;
71486 +
71487 + filp = tsk->exec_file;
71488 + if (filp == NULL)
71489 + goto out_unlock;
71490 +
71491 + tsk->is_writable = 0;
71492 + tsk->inherited = 0;
71493 +
71494 + tsk->acl_sp_role = 1;
71495 + tsk->acl_role_id = ++acl_sp_role_value;
71496 + tsk->role = assigned;
71497 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
71498 +
71499 + /* ignore additional mmap checks for processes that are writable
71500 + by the default ACL */
71501 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
71502 + if (unlikely(obj->mode & GR_WRITE))
71503 + tsk->is_writable = 1;
71504 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
71505 + if (unlikely(obj->mode & GR_WRITE))
71506 + tsk->is_writable = 1;
71507 +
71508 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71509 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename,
71510 + tsk->acl->filename, tsk->comm, task_pid_nr(tsk));
71511 +#endif
71512 +
71513 +out_unlock:
71514 + read_unlock(&grsec_exec_file_lock);
71515 + read_unlock(&tasklist_lock);
71516 + return;
71517 +}
71518 +
71519 +
71520 +static void
71521 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
71522 +{
71523 + struct task_struct *task = current;
71524 + const struct cred *cred = current_cred();
71525 +
71526 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
71527 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
71528 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
71529 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
71530 +
71531 + return;
71532 +}
71533 +
71534 +static void
71535 +gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
71536 +{
71537 + struct task_struct *task = current;
71538 + const struct cred *cred = current_cred();
71539 +
71540 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
71541 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
71542 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
71543 + 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
71544 +
71545 + return;
71546 +}
71547 +
71548 +static void
71549 +gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
71550 +{
71551 + struct task_struct *task = current;
71552 + const struct cred *cred = current_cred();
71553 +
71554 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
71555 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
71556 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
71557 + 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
71558 +
71559 + return;
71560 +}
71561 +
71562 +static void
71563 +gr_set_proc_res(struct task_struct *task)
71564 +{
71565 + struct acl_subject_label *proc;
71566 + unsigned short i;
71567 +
71568 + proc = task->acl;
71569 +
71570 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
71571 + return;
71572 +
71573 + for (i = 0; i < RLIM_NLIMITS; i++) {
71574 + if (!(proc->resmask & (1U << i)))
71575 + continue;
71576 +
71577 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
71578 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
71579 +
71580 + if (i == RLIMIT_CPU)
71581 + update_rlimit_cpu(task, proc->res[i].rlim_cur);
71582 + }
71583 +
71584 + return;
71585 +}
71586 +
71587 +/* both of the below must be called with
71588 + rcu_read_lock();
71589 + read_lock(&tasklist_lock);
71590 + read_lock(&grsec_exec_file_lock);
71591 +*/
71592 +
71593 +struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename)
71594 +{
71595 + char *tmpname;
71596 + struct acl_subject_label *tmpsubj;
71597 + struct file *filp;
71598 + struct name_entry *nmatch;
71599 +
71600 + filp = task->exec_file;
71601 + if (filp == NULL)
71602 + return NULL;
71603 +
71604 + /* the following is to apply the correct subject
71605 + on binaries running when the RBAC system
71606 + is enabled, when the binaries have been
71607 + replaced or deleted since their execution
71608 + -----
71609 + when the RBAC system starts, the inode/dev
71610 + from exec_file will be one the RBAC system
71611 + is unaware of. It only knows the inode/dev
71612 + of the present file on disk, or the absence
71613 + of it.
71614 + */
71615 +
71616 + if (filename)
71617 + nmatch = __lookup_name_entry(state, filename);
71618 + else {
71619 + preempt_disable();
71620 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
71621 +
71622 + nmatch = __lookup_name_entry(state, tmpname);
71623 + preempt_enable();
71624 + }
71625 + tmpsubj = NULL;
71626 + if (nmatch) {
71627 + if (nmatch->deleted)
71628 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
71629 + else
71630 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
71631 + }
71632 + /* this also works for the reload case -- if we don't match a potentially inherited subject
71633 + then we fall back to a normal lookup based on the binary's ino/dev
71634 + */
71635 + if (tmpsubj == NULL)
71636 + tmpsubj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, task->role);
71637 +
71638 + return tmpsubj;
71639 +}
71640 +
71641 +static struct acl_subject_label *gr_get_subject_for_task(struct task_struct *task, const char *filename)
71642 +{
71643 + return __gr_get_subject_for_task(&running_polstate, task, filename);
71644 +}
71645 +
71646 +void __gr_apply_subject_to_task(const struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj)
71647 +{
71648 + struct acl_object_label *obj;
71649 + struct file *filp;
71650 +
71651 + filp = task->exec_file;
71652 +
71653 + task->acl = subj;
71654 + task->is_writable = 0;
71655 + /* ignore additional mmap checks for processes that are writable
71656 + by the default ACL */
71657 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, state->default_role->root_label);
71658 + if (unlikely(obj->mode & GR_WRITE))
71659 + task->is_writable = 1;
71660 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
71661 + if (unlikely(obj->mode & GR_WRITE))
71662 + task->is_writable = 1;
71663 +
71664 + gr_set_proc_res(task);
71665 +
71666 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71667 + 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);
71668 +#endif
71669 +}
71670 +
71671 +static void gr_apply_subject_to_task(struct task_struct *task, struct acl_subject_label *subj)
71672 +{
71673 + __gr_apply_subject_to_task(&running_polstate, task, subj);
71674 +}
71675 +
71676 +__u32
71677 +gr_search_file(const struct dentry * dentry, const __u32 mode,
71678 + const struct vfsmount * mnt)
71679 +{
71680 + __u32 retval = mode;
71681 + struct acl_subject_label *curracl;
71682 + struct acl_object_label *currobj;
71683 +
71684 + if (unlikely(!(gr_status & GR_READY)))
71685 + return (mode & ~GR_AUDITS);
71686 +
71687 + curracl = current->acl;
71688 +
71689 + currobj = chk_obj_label(dentry, mnt, curracl);
71690 + retval = currobj->mode & mode;
71691 +
71692 + /* if we're opening a specified transfer file for writing
71693 + (e.g. /dev/initctl), then transfer our role to init
71694 + */
71695 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
71696 + current->role->roletype & GR_ROLE_PERSIST)) {
71697 + struct task_struct *task = init_pid_ns.child_reaper;
71698 +
71699 + if (task->role != current->role) {
71700 + struct acl_subject_label *subj;
71701 +
71702 + task->acl_sp_role = 0;
71703 + task->acl_role_id = current->acl_role_id;
71704 + task->role = current->role;
71705 + rcu_read_lock();
71706 + read_lock(&grsec_exec_file_lock);
71707 + subj = gr_get_subject_for_task(task, NULL);
71708 + gr_apply_subject_to_task(task, subj);
71709 + read_unlock(&grsec_exec_file_lock);
71710 + rcu_read_unlock();
71711 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
71712 + }
71713 + }
71714 +
71715 + if (unlikely
71716 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
71717 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
71718 + __u32 new_mode = mode;
71719 +
71720 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
71721 +
71722 + retval = new_mode;
71723 +
71724 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
71725 + new_mode |= GR_INHERIT;
71726 +
71727 + if (!(mode & GR_NOLEARN))
71728 + gr_log_learn(dentry, mnt, new_mode);
71729 + }
71730 +
71731 + return retval;
71732 +}
71733 +
71734 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
71735 + const struct dentry *parent,
71736 + const struct vfsmount *mnt)
71737 +{
71738 + struct name_entry *match;
71739 + struct acl_object_label *matchpo;
71740 + struct acl_subject_label *curracl;
71741 + char *path;
71742 +
71743 + if (unlikely(!(gr_status & GR_READY)))
71744 + return NULL;
71745 +
71746 + preempt_disable();
71747 + path = gr_to_filename_rbac(new_dentry, mnt);
71748 + match = lookup_name_entry_create(path);
71749 +
71750 + curracl = current->acl;
71751 +
71752 + if (match) {
71753 + read_lock(&gr_inode_lock);
71754 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
71755 + read_unlock(&gr_inode_lock);
71756 +
71757 + if (matchpo) {
71758 + preempt_enable();
71759 + return matchpo;
71760 + }
71761 + }
71762 +
71763 + // lookup parent
71764 +
71765 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
71766 +
71767 + preempt_enable();
71768 + return matchpo;
71769 +}
71770 +
71771 +__u32
71772 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
71773 + const struct vfsmount * mnt, const __u32 mode)
71774 +{
71775 + struct acl_object_label *matchpo;
71776 + __u32 retval;
71777 +
71778 + if (unlikely(!(gr_status & GR_READY)))
71779 + return (mode & ~GR_AUDITS);
71780 +
71781 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
71782 +
71783 + retval = matchpo->mode & mode;
71784 +
71785 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
71786 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
71787 + __u32 new_mode = mode;
71788 +
71789 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
71790 +
71791 + gr_log_learn(new_dentry, mnt, new_mode);
71792 + return new_mode;
71793 + }
71794 +
71795 + return retval;
71796 +}
71797 +
71798 +__u32
71799 +gr_check_link(const struct dentry * new_dentry,
71800 + const struct dentry * parent_dentry,
71801 + const struct vfsmount * parent_mnt,
71802 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
71803 +{
71804 + struct acl_object_label *obj;
71805 + __u32 oldmode, newmode;
71806 + __u32 needmode;
71807 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
71808 + GR_DELETE | GR_INHERIT;
71809 +
71810 + if (unlikely(!(gr_status & GR_READY)))
71811 + return (GR_CREATE | GR_LINK);
71812 +
71813 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
71814 + oldmode = obj->mode;
71815 +
71816 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
71817 + newmode = obj->mode;
71818 +
71819 + needmode = newmode & checkmodes;
71820 +
71821 + // old name for hardlink must have at least the permissions of the new name
71822 + if ((oldmode & needmode) != needmode)
71823 + goto bad;
71824 +
71825 + // if old name had restrictions/auditing, make sure the new name does as well
71826 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
71827 +
71828 + // don't allow hardlinking of suid/sgid/fcapped files without permission
71829 + if (is_privileged_binary(old_dentry))
71830 + needmode |= GR_SETID;
71831 +
71832 + if ((newmode & needmode) != needmode)
71833 + goto bad;
71834 +
71835 + // enforce minimum permissions
71836 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
71837 + return newmode;
71838 +bad:
71839 + needmode = oldmode;
71840 + if (is_privileged_binary(old_dentry))
71841 + needmode |= GR_SETID;
71842 +
71843 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
71844 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
71845 + return (GR_CREATE | GR_LINK);
71846 + } else if (newmode & GR_SUPPRESS)
71847 + return GR_SUPPRESS;
71848 + else
71849 + return 0;
71850 +}
71851 +
71852 +int
71853 +gr_check_hidden_task(const struct task_struct *task)
71854 +{
71855 + if (unlikely(!(gr_status & GR_READY)))
71856 + return 0;
71857 +
71858 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
71859 + return 1;
71860 +
71861 + return 0;
71862 +}
71863 +
71864 +int
71865 +gr_check_protected_task(const struct task_struct *task)
71866 +{
71867 + if (unlikely(!(gr_status & GR_READY) || !task))
71868 + return 0;
71869 +
71870 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
71871 + task->acl != current->acl)
71872 + return 1;
71873 +
71874 + return 0;
71875 +}
71876 +
71877 +int
71878 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
71879 +{
71880 + struct task_struct *p;
71881 + int ret = 0;
71882 +
71883 + if (unlikely(!(gr_status & GR_READY) || !pid))
71884 + return ret;
71885 +
71886 + read_lock(&tasklist_lock);
71887 + do_each_pid_task(pid, type, p) {
71888 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
71889 + p->acl != current->acl) {
71890 + ret = 1;
71891 + goto out;
71892 + }
71893 + } while_each_pid_task(pid, type, p);
71894 +out:
71895 + read_unlock(&tasklist_lock);
71896 +
71897 + return ret;
71898 +}
71899 +
71900 +void
71901 +gr_copy_label(struct task_struct *tsk)
71902 +{
71903 + struct task_struct *p = current;
71904 +
71905 + tsk->inherited = p->inherited;
71906 + tsk->acl_sp_role = 0;
71907 + tsk->acl_role_id = p->acl_role_id;
71908 + tsk->acl = p->acl;
71909 + tsk->role = p->role;
71910 + tsk->signal->used_accept = 0;
71911 + tsk->signal->curr_ip = p->signal->curr_ip;
71912 + tsk->signal->saved_ip = p->signal->saved_ip;
71913 + if (p->exec_file)
71914 + get_file(p->exec_file);
71915 + tsk->exec_file = p->exec_file;
71916 + tsk->is_writable = p->is_writable;
71917 + if (unlikely(p->signal->used_accept)) {
71918 + p->signal->curr_ip = 0;
71919 + p->signal->saved_ip = 0;
71920 + }
71921 +
71922 + return;
71923 +}
71924 +
71925 +extern int gr_process_kernel_setuid_ban(struct user_struct *user);
71926 +
71927 +int
71928 +gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
71929 +{
71930 + unsigned int i;
71931 + __u16 num;
71932 + uid_t *uidlist;
71933 + uid_t curuid;
71934 + int realok = 0;
71935 + int effectiveok = 0;
71936 + int fsok = 0;
71937 + uid_t globalreal, globaleffective, globalfs;
71938 +
71939 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
71940 + struct user_struct *user;
71941 +
71942 + if (!uid_valid(real))
71943 + goto skipit;
71944 +
71945 + /* find user based on global namespace */
71946 +
71947 + globalreal = GR_GLOBAL_UID(real);
71948 +
71949 + user = find_user(make_kuid(&init_user_ns, globalreal));
71950 + if (user == NULL)
71951 + goto skipit;
71952 +
71953 + if (gr_process_kernel_setuid_ban(user)) {
71954 + /* for find_user */
71955 + free_uid(user);
71956 + return 1;
71957 + }
71958 +
71959 + /* for find_user */
71960 + free_uid(user);
71961 +
71962 +skipit:
71963 +#endif
71964 +
71965 + if (unlikely(!(gr_status & GR_READY)))
71966 + return 0;
71967 +
71968 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
71969 + gr_log_learn_uid_change(real, effective, fs);
71970 +
71971 + num = current->acl->user_trans_num;
71972 + uidlist = current->acl->user_transitions;
71973 +
71974 + if (uidlist == NULL)
71975 + return 0;
71976 +
71977 + if (!uid_valid(real)) {
71978 + realok = 1;
71979 + globalreal = (uid_t)-1;
71980 + } else {
71981 + globalreal = GR_GLOBAL_UID(real);
71982 + }
71983 + if (!uid_valid(effective)) {
71984 + effectiveok = 1;
71985 + globaleffective = (uid_t)-1;
71986 + } else {
71987 + globaleffective = GR_GLOBAL_UID(effective);
71988 + }
71989 + if (!uid_valid(fs)) {
71990 + fsok = 1;
71991 + globalfs = (uid_t)-1;
71992 + } else {
71993 + globalfs = GR_GLOBAL_UID(fs);
71994 + }
71995 +
71996 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
71997 + for (i = 0; i < num; i++) {
71998 + curuid = uidlist[i];
71999 + if (globalreal == curuid)
72000 + realok = 1;
72001 + if (globaleffective == curuid)
72002 + effectiveok = 1;
72003 + if (globalfs == curuid)
72004 + fsok = 1;
72005 + }
72006 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
72007 + for (i = 0; i < num; i++) {
72008 + curuid = uidlist[i];
72009 + if (globalreal == curuid)
72010 + break;
72011 + if (globaleffective == curuid)
72012 + break;
72013 + if (globalfs == curuid)
72014 + break;
72015 + }
72016 + /* not in deny list */
72017 + if (i == num) {
72018 + realok = 1;
72019 + effectiveok = 1;
72020 + fsok = 1;
72021 + }
72022 + }
72023 +
72024 + if (realok && effectiveok && fsok)
72025 + return 0;
72026 + else {
72027 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
72028 + return 1;
72029 + }
72030 +}
72031 +
72032 +int
72033 +gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
72034 +{
72035 + unsigned int i;
72036 + __u16 num;
72037 + gid_t *gidlist;
72038 + gid_t curgid;
72039 + int realok = 0;
72040 + int effectiveok = 0;
72041 + int fsok = 0;
72042 + gid_t globalreal, globaleffective, globalfs;
72043 +
72044 + if (unlikely(!(gr_status & GR_READY)))
72045 + return 0;
72046 +
72047 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
72048 + gr_log_learn_gid_change(real, effective, fs);
72049 +
72050 + num = current->acl->group_trans_num;
72051 + gidlist = current->acl->group_transitions;
72052 +
72053 + if (gidlist == NULL)
72054 + return 0;
72055 +
72056 + if (!gid_valid(real)) {
72057 + realok = 1;
72058 + globalreal = (gid_t)-1;
72059 + } else {
72060 + globalreal = GR_GLOBAL_GID(real);
72061 + }
72062 + if (!gid_valid(effective)) {
72063 + effectiveok = 1;
72064 + globaleffective = (gid_t)-1;
72065 + } else {
72066 + globaleffective = GR_GLOBAL_GID(effective);
72067 + }
72068 + if (!gid_valid(fs)) {
72069 + fsok = 1;
72070 + globalfs = (gid_t)-1;
72071 + } else {
72072 + globalfs = GR_GLOBAL_GID(fs);
72073 + }
72074 +
72075 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
72076 + for (i = 0; i < num; i++) {
72077 + curgid = gidlist[i];
72078 + if (globalreal == curgid)
72079 + realok = 1;
72080 + if (globaleffective == curgid)
72081 + effectiveok = 1;
72082 + if (globalfs == curgid)
72083 + fsok = 1;
72084 + }
72085 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
72086 + for (i = 0; i < num; i++) {
72087 + curgid = gidlist[i];
72088 + if (globalreal == curgid)
72089 + break;
72090 + if (globaleffective == curgid)
72091 + break;
72092 + if (globalfs == curgid)
72093 + break;
72094 + }
72095 + /* not in deny list */
72096 + if (i == num) {
72097 + realok = 1;
72098 + effectiveok = 1;
72099 + fsok = 1;
72100 + }
72101 + }
72102 +
72103 + if (realok && effectiveok && fsok)
72104 + return 0;
72105 + else {
72106 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
72107 + return 1;
72108 + }
72109 +}
72110 +
72111 +extern int gr_acl_is_capable(const int cap);
72112 +
72113 +void
72114 +gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
72115 +{
72116 + struct acl_role_label *role = task->role;
72117 + struct acl_subject_label *subj = NULL;
72118 + struct acl_object_label *obj;
72119 + struct file *filp;
72120 + uid_t uid;
72121 + gid_t gid;
72122 +
72123 + if (unlikely(!(gr_status & GR_READY)))
72124 + return;
72125 +
72126 + uid = GR_GLOBAL_UID(kuid);
72127 + gid = GR_GLOBAL_GID(kgid);
72128 +
72129 + filp = task->exec_file;
72130 +
72131 + /* kernel process, we'll give them the kernel role */
72132 + if (unlikely(!filp)) {
72133 + task->role = running_polstate.kernel_role;
72134 + task->acl = running_polstate.kernel_role->root_label;
72135 + return;
72136 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL)) {
72137 + /* save the current ip at time of role lookup so that the proper
72138 + IP will be learned for role_allowed_ip */
72139 + task->signal->saved_ip = task->signal->curr_ip;
72140 + role = lookup_acl_role_label(task, uid, gid);
72141 + }
72142 +
72143 + /* don't change the role if we're not a privileged process */
72144 + if (role && task->role != role &&
72145 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
72146 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
72147 + return;
72148 +
72149 + /* perform subject lookup in possibly new role
72150 + we can use this result below in the case where role == task->role
72151 + */
72152 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
72153 +
72154 + /* if we changed uid/gid, but result in the same role
72155 + and are using inheritance, don't lose the inherited subject
72156 + if current subject is other than what normal lookup
72157 + would result in, we arrived via inheritance, don't
72158 + lose subject
72159 + */
72160 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
72161 + (subj == task->acl)))
72162 + task->acl = subj;
72163 +
72164 + /* leave task->inherited unaffected */
72165 +
72166 + task->role = role;
72167 +
72168 + task->is_writable = 0;
72169 +
72170 + /* ignore additional mmap checks for processes that are writable
72171 + by the default ACL */
72172 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
72173 + if (unlikely(obj->mode & GR_WRITE))
72174 + task->is_writable = 1;
72175 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
72176 + if (unlikely(obj->mode & GR_WRITE))
72177 + task->is_writable = 1;
72178 +
72179 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
72180 + 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);
72181 +#endif
72182 +
72183 + gr_set_proc_res(task);
72184 +
72185 + return;
72186 +}
72187 +
72188 +int
72189 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
72190 + const int unsafe_flags)
72191 +{
72192 + struct task_struct *task = current;
72193 + struct acl_subject_label *newacl;
72194 + struct acl_object_label *obj;
72195 + __u32 retmode;
72196 +
72197 + if (unlikely(!(gr_status & GR_READY)))
72198 + return 0;
72199 +
72200 + newacl = chk_subj_label(dentry, mnt, task->role);
72201 +
72202 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
72203 + did an exec
72204 + */
72205 + rcu_read_lock();
72206 + read_lock(&tasklist_lock);
72207 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
72208 + (task->parent->acl->mode & GR_POVERRIDE))) {
72209 + read_unlock(&tasklist_lock);
72210 + rcu_read_unlock();
72211 + goto skip_check;
72212 + }
72213 + read_unlock(&tasklist_lock);
72214 + rcu_read_unlock();
72215 +
72216 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
72217 + !(task->role->roletype & GR_ROLE_GOD) &&
72218 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
72219 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
72220 + if (unsafe_flags & LSM_UNSAFE_SHARE)
72221 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
72222 + else
72223 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
72224 + return -EACCES;
72225 + }
72226 +
72227 +skip_check:
72228 +
72229 + obj = chk_obj_label(dentry, mnt, task->acl);
72230 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
72231 +
72232 + if (!(task->acl->mode & GR_INHERITLEARN) &&
72233 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
72234 + if (obj->nested)
72235 + task->acl = obj->nested;
72236 + else
72237 + task->acl = newacl;
72238 + task->inherited = 0;
72239 + } else {
72240 + task->inherited = 1;
72241 + if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
72242 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
72243 + }
72244 +
72245 + task->is_writable = 0;
72246 +
72247 + /* ignore additional mmap checks for processes that are writable
72248 + by the default ACL */
72249 + obj = chk_obj_label(dentry, mnt, running_polstate.default_role->root_label);
72250 + if (unlikely(obj->mode & GR_WRITE))
72251 + task->is_writable = 1;
72252 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
72253 + if (unlikely(obj->mode & GR_WRITE))
72254 + task->is_writable = 1;
72255 +
72256 + gr_set_proc_res(task);
72257 +
72258 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
72259 + 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);
72260 +#endif
72261 + return 0;
72262 +}
72263 +
72264 +/* always called with valid inodev ptr */
72265 +static void
72266 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
72267 +{
72268 + struct acl_object_label *matchpo;
72269 + struct acl_subject_label *matchps;
72270 + struct acl_subject_label *subj;
72271 + struct acl_role_label *role;
72272 + unsigned int x;
72273 +
72274 + FOR_EACH_ROLE_START(role)
72275 + FOR_EACH_SUBJECT_START(role, subj, x)
72276 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
72277 + matchpo->mode |= GR_DELETED;
72278 + FOR_EACH_SUBJECT_END(subj,x)
72279 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
72280 + /* nested subjects aren't in the role's subj_hash table */
72281 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
72282 + matchpo->mode |= GR_DELETED;
72283 + FOR_EACH_NESTED_SUBJECT_END(subj)
72284 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
72285 + matchps->mode |= GR_DELETED;
72286 + FOR_EACH_ROLE_END(role)
72287 +
72288 + inodev->nentry->deleted = 1;
72289 +
72290 + return;
72291 +}
72292 +
72293 +void
72294 +gr_handle_delete(const ino_t ino, const dev_t dev)
72295 +{
72296 + struct inodev_entry *inodev;
72297 +
72298 + if (unlikely(!(gr_status & GR_READY)))
72299 + return;
72300 +
72301 + write_lock(&gr_inode_lock);
72302 + inodev = lookup_inodev_entry(ino, dev);
72303 + if (inodev != NULL)
72304 + do_handle_delete(inodev, ino, dev);
72305 + write_unlock(&gr_inode_lock);
72306 +
72307 + return;
72308 +}
72309 +
72310 +static void
72311 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
72312 + const ino_t newinode, const dev_t newdevice,
72313 + struct acl_subject_label *subj)
72314 +{
72315 + unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
72316 + struct acl_object_label *match;
72317 +
72318 + match = subj->obj_hash[index];
72319 +
72320 + while (match && (match->inode != oldinode ||
72321 + match->device != olddevice ||
72322 + !(match->mode & GR_DELETED)))
72323 + match = match->next;
72324 +
72325 + if (match && (match->inode == oldinode)
72326 + && (match->device == olddevice)
72327 + && (match->mode & GR_DELETED)) {
72328 + if (match->prev == NULL) {
72329 + subj->obj_hash[index] = match->next;
72330 + if (match->next != NULL)
72331 + match->next->prev = NULL;
72332 + } else {
72333 + match->prev->next = match->next;
72334 + if (match->next != NULL)
72335 + match->next->prev = match->prev;
72336 + }
72337 + match->prev = NULL;
72338 + match->next = NULL;
72339 + match->inode = newinode;
72340 + match->device = newdevice;
72341 + match->mode &= ~GR_DELETED;
72342 +
72343 + insert_acl_obj_label(match, subj);
72344 + }
72345 +
72346 + return;
72347 +}
72348 +
72349 +static void
72350 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
72351 + const ino_t newinode, const dev_t newdevice,
72352 + struct acl_role_label *role)
72353 +{
72354 + unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
72355 + struct acl_subject_label *match;
72356 +
72357 + match = role->subj_hash[index];
72358 +
72359 + while (match && (match->inode != oldinode ||
72360 + match->device != olddevice ||
72361 + !(match->mode & GR_DELETED)))
72362 + match = match->next;
72363 +
72364 + if (match && (match->inode == oldinode)
72365 + && (match->device == olddevice)
72366 + && (match->mode & GR_DELETED)) {
72367 + if (match->prev == NULL) {
72368 + role->subj_hash[index] = match->next;
72369 + if (match->next != NULL)
72370 + match->next->prev = NULL;
72371 + } else {
72372 + match->prev->next = match->next;
72373 + if (match->next != NULL)
72374 + match->next->prev = match->prev;
72375 + }
72376 + match->prev = NULL;
72377 + match->next = NULL;
72378 + match->inode = newinode;
72379 + match->device = newdevice;
72380 + match->mode &= ~GR_DELETED;
72381 +
72382 + insert_acl_subj_label(match, role);
72383 + }
72384 +
72385 + return;
72386 +}
72387 +
72388 +static void
72389 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
72390 + const ino_t newinode, const dev_t newdevice)
72391 +{
72392 + unsigned int index = gr_fhash(oldinode, olddevice, running_polstate.inodev_set.i_size);
72393 + struct inodev_entry *match;
72394 +
72395 + match = running_polstate.inodev_set.i_hash[index];
72396 +
72397 + while (match && (match->nentry->inode != oldinode ||
72398 + match->nentry->device != olddevice || !match->nentry->deleted))
72399 + match = match->next;
72400 +
72401 + if (match && (match->nentry->inode == oldinode)
72402 + && (match->nentry->device == olddevice) &&
72403 + match->nentry->deleted) {
72404 + if (match->prev == NULL) {
72405 + running_polstate.inodev_set.i_hash[index] = match->next;
72406 + if (match->next != NULL)
72407 + match->next->prev = NULL;
72408 + } else {
72409 + match->prev->next = match->next;
72410 + if (match->next != NULL)
72411 + match->next->prev = match->prev;
72412 + }
72413 + match->prev = NULL;
72414 + match->next = NULL;
72415 + match->nentry->inode = newinode;
72416 + match->nentry->device = newdevice;
72417 + match->nentry->deleted = 0;
72418 +
72419 + insert_inodev_entry(match);
72420 + }
72421 +
72422 + return;
72423 +}
72424 +
72425 +static void
72426 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
72427 +{
72428 + struct acl_subject_label *subj;
72429 + struct acl_role_label *role;
72430 + unsigned int x;
72431 +
72432 + FOR_EACH_ROLE_START(role)
72433 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
72434 +
72435 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
72436 + if ((subj->inode == ino) && (subj->device == dev)) {
72437 + subj->inode = ino;
72438 + subj->device = dev;
72439 + }
72440 + /* nested subjects aren't in the role's subj_hash table */
72441 + update_acl_obj_label(matchn->inode, matchn->device,
72442 + ino, dev, subj);
72443 + FOR_EACH_NESTED_SUBJECT_END(subj)
72444 + FOR_EACH_SUBJECT_START(role, subj, x)
72445 + update_acl_obj_label(matchn->inode, matchn->device,
72446 + ino, dev, subj);
72447 + FOR_EACH_SUBJECT_END(subj,x)
72448 + FOR_EACH_ROLE_END(role)
72449 +
72450 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
72451 +
72452 + return;
72453 +}
72454 +
72455 +static void
72456 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
72457 + const struct vfsmount *mnt)
72458 +{
72459 + ino_t ino = dentry->d_inode->i_ino;
72460 + dev_t dev = __get_dev(dentry);
72461 +
72462 + __do_handle_create(matchn, ino, dev);
72463 +
72464 + return;
72465 +}
72466 +
72467 +void
72468 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
72469 +{
72470 + struct name_entry *matchn;
72471 +
72472 + if (unlikely(!(gr_status & GR_READY)))
72473 + return;
72474 +
72475 + preempt_disable();
72476 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
72477 +
72478 + if (unlikely((unsigned long)matchn)) {
72479 + write_lock(&gr_inode_lock);
72480 + do_handle_create(matchn, dentry, mnt);
72481 + write_unlock(&gr_inode_lock);
72482 + }
72483 + preempt_enable();
72484 +
72485 + return;
72486 +}
72487 +
72488 +void
72489 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
72490 +{
72491 + struct name_entry *matchn;
72492 +
72493 + if (unlikely(!(gr_status & GR_READY)))
72494 + return;
72495 +
72496 + preempt_disable();
72497 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
72498 +
72499 + if (unlikely((unsigned long)matchn)) {
72500 + write_lock(&gr_inode_lock);
72501 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
72502 + write_unlock(&gr_inode_lock);
72503 + }
72504 + preempt_enable();
72505 +
72506 + return;
72507 +}
72508 +
72509 +void
72510 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
72511 + struct dentry *old_dentry,
72512 + struct dentry *new_dentry,
72513 + struct vfsmount *mnt, const __u8 replace, unsigned int flags)
72514 +{
72515 + struct name_entry *matchn;
72516 + struct name_entry *matchn2 = NULL;
72517 + struct inodev_entry *inodev;
72518 + struct inode *inode = new_dentry->d_inode;
72519 + ino_t old_ino = old_dentry->d_inode->i_ino;
72520 + dev_t old_dev = __get_dev(old_dentry);
72521 + unsigned int exchange = flags & RENAME_EXCHANGE;
72522 +
72523 + /* vfs_rename swaps the name and parent link for old_dentry and
72524 + new_dentry
72525 + at this point, old_dentry has the new name, parent link, and inode
72526 + for the renamed file
72527 + if a file is being replaced by a rename, new_dentry has the inode
72528 + and name for the replaced file
72529 + */
72530 +
72531 + if (unlikely(!(gr_status & GR_READY)))
72532 + return;
72533 +
72534 + preempt_disable();
72535 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
72536 +
72537 + /* exchange cases:
72538 + a filename exists for the source, but not dest
72539 + do a recreate on source
72540 + a filename exists for the dest, but not source
72541 + do a recreate on dest
72542 + a filename exists for both source and dest
72543 + delete source and dest, then create source and dest
72544 + a filename exists for neither source nor dest
72545 + no updates needed
72546 +
72547 + the name entry lookups get us the old inode/dev associated with
72548 + each name, so do the deletes first (if possible) so that when
72549 + we do the create, we pick up on the right entries
72550 + */
72551 +
72552 + if (exchange)
72553 + matchn2 = lookup_name_entry(gr_to_filename_rbac(new_dentry, mnt));
72554 +
72555 + /* we wouldn't have to check d_inode if it weren't for
72556 + NFS silly-renaming
72557 + */
72558 +
72559 + write_lock(&gr_inode_lock);
72560 + if (unlikely((replace || exchange) && inode)) {
72561 + ino_t new_ino = inode->i_ino;
72562 + dev_t new_dev = __get_dev(new_dentry);
72563 +
72564 + inodev = lookup_inodev_entry(new_ino, new_dev);
72565 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
72566 + do_handle_delete(inodev, new_ino, new_dev);
72567 + }
72568 +
72569 + inodev = lookup_inodev_entry(old_ino, old_dev);
72570 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
72571 + do_handle_delete(inodev, old_ino, old_dev);
72572 +
72573 + if (unlikely(matchn != NULL))
72574 + do_handle_create(matchn, old_dentry, mnt);
72575 +
72576 + if (unlikely(matchn2 != NULL))
72577 + do_handle_create(matchn2, new_dentry, mnt);
72578 +
72579 + write_unlock(&gr_inode_lock);
72580 + preempt_enable();
72581 +
72582 + return;
72583 +}
72584 +
72585 +#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
72586 +static const unsigned long res_learn_bumps[GR_NLIMITS] = {
72587 + [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
72588 + [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
72589 + [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
72590 + [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
72591 + [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
72592 + [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
72593 + [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
72594 + [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
72595 + [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
72596 + [RLIMIT_AS] = GR_RLIM_AS_BUMP,
72597 + [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
72598 + [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
72599 + [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
72600 + [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
72601 + [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
72602 + [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
72603 +};
72604 +
72605 +void
72606 +gr_learn_resource(const struct task_struct *task,
72607 + const int res, const unsigned long wanted, const int gt)
72608 +{
72609 + struct acl_subject_label *acl;
72610 + const struct cred *cred;
72611 +
72612 + if (unlikely((gr_status & GR_READY) &&
72613 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
72614 + goto skip_reslog;
72615 +
72616 + gr_log_resource(task, res, wanted, gt);
72617 +skip_reslog:
72618 +
72619 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
72620 + return;
72621 +
72622 + acl = task->acl;
72623 +
72624 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
72625 + !(acl->resmask & (1U << (unsigned short) res))))
72626 + return;
72627 +
72628 + if (wanted >= acl->res[res].rlim_cur) {
72629 + unsigned long res_add;
72630 +
72631 + res_add = wanted + res_learn_bumps[res];
72632 +
72633 + acl->res[res].rlim_cur = res_add;
72634 +
72635 + if (wanted > acl->res[res].rlim_max)
72636 + acl->res[res].rlim_max = res_add;
72637 +
72638 + /* only log the subject filename, since resource logging is supported for
72639 + single-subject learning only */
72640 + rcu_read_lock();
72641 + cred = __task_cred(task);
72642 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
72643 + task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
72644 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
72645 + "", (unsigned long) res, &task->signal->saved_ip);
72646 + rcu_read_unlock();
72647 + }
72648 +
72649 + return;
72650 +}
72651 +EXPORT_SYMBOL_GPL(gr_learn_resource);
72652 +#endif
72653 +
72654 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
72655 +void
72656 +pax_set_initial_flags(struct linux_binprm *bprm)
72657 +{
72658 + struct task_struct *task = current;
72659 + struct acl_subject_label *proc;
72660 + unsigned long flags;
72661 +
72662 + if (unlikely(!(gr_status & GR_READY)))
72663 + return;
72664 +
72665 + flags = pax_get_flags(task);
72666 +
72667 + proc = task->acl;
72668 +
72669 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
72670 + flags &= ~MF_PAX_PAGEEXEC;
72671 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
72672 + flags &= ~MF_PAX_SEGMEXEC;
72673 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
72674 + flags &= ~MF_PAX_RANDMMAP;
72675 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
72676 + flags &= ~MF_PAX_EMUTRAMP;
72677 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
72678 + flags &= ~MF_PAX_MPROTECT;
72679 +
72680 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
72681 + flags |= MF_PAX_PAGEEXEC;
72682 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
72683 + flags |= MF_PAX_SEGMEXEC;
72684 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
72685 + flags |= MF_PAX_RANDMMAP;
72686 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
72687 + flags |= MF_PAX_EMUTRAMP;
72688 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
72689 + flags |= MF_PAX_MPROTECT;
72690 +
72691 + pax_set_flags(task, flags);
72692 +
72693 + return;
72694 +}
72695 +#endif
72696 +
72697 +int
72698 +gr_handle_proc_ptrace(struct task_struct *task)
72699 +{
72700 + struct file *filp;
72701 + struct task_struct *tmp = task;
72702 + struct task_struct *curtemp = current;
72703 + __u32 retmode;
72704 +
72705 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
72706 + if (unlikely(!(gr_status & GR_READY)))
72707 + return 0;
72708 +#endif
72709 +
72710 + read_lock(&tasklist_lock);
72711 + read_lock(&grsec_exec_file_lock);
72712 + filp = task->exec_file;
72713 +
72714 + while (task_pid_nr(tmp) > 0) {
72715 + if (tmp == curtemp)
72716 + break;
72717 + tmp = tmp->real_parent;
72718 + }
72719 +
72720 + if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
72721 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
72722 + read_unlock(&grsec_exec_file_lock);
72723 + read_unlock(&tasklist_lock);
72724 + return 1;
72725 + }
72726 +
72727 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
72728 + if (!(gr_status & GR_READY)) {
72729 + read_unlock(&grsec_exec_file_lock);
72730 + read_unlock(&tasklist_lock);
72731 + return 0;
72732 + }
72733 +#endif
72734 +
72735 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
72736 + read_unlock(&grsec_exec_file_lock);
72737 + read_unlock(&tasklist_lock);
72738 +
72739 + if (retmode & GR_NOPTRACE)
72740 + return 1;
72741 +
72742 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
72743 + && (current->acl != task->acl || (current->acl != current->role->root_label
72744 + && task_pid_nr(current) != task_pid_nr(task))))
72745 + return 1;
72746 +
72747 + return 0;
72748 +}
72749 +
72750 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
72751 +{
72752 + if (unlikely(!(gr_status & GR_READY)))
72753 + return;
72754 +
72755 + if (!(current->role->roletype & GR_ROLE_GOD))
72756 + return;
72757 +
72758 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
72759 + p->role->rolename, gr_task_roletype_to_char(p),
72760 + p->acl->filename);
72761 +}
72762 +
72763 +int
72764 +gr_handle_ptrace(struct task_struct *task, const long request)
72765 +{
72766 + struct task_struct *tmp = task;
72767 + struct task_struct *curtemp = current;
72768 + __u32 retmode;
72769 +
72770 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
72771 + if (unlikely(!(gr_status & GR_READY)))
72772 + return 0;
72773 +#endif
72774 + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
72775 + read_lock(&tasklist_lock);
72776 + while (task_pid_nr(tmp) > 0) {
72777 + if (tmp == curtemp)
72778 + break;
72779 + tmp = tmp->real_parent;
72780 + }
72781 +
72782 + if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
72783 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
72784 + read_unlock(&tasklist_lock);
72785 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
72786 + return 1;
72787 + }
72788 + read_unlock(&tasklist_lock);
72789 + }
72790 +
72791 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
72792 + if (!(gr_status & GR_READY))
72793 + return 0;
72794 +#endif
72795 +
72796 + read_lock(&grsec_exec_file_lock);
72797 + if (unlikely(!task->exec_file)) {
72798 + read_unlock(&grsec_exec_file_lock);
72799 + return 0;
72800 + }
72801 +
72802 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
72803 + read_unlock(&grsec_exec_file_lock);
72804 +
72805 + if (retmode & GR_NOPTRACE) {
72806 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
72807 + return 1;
72808 + }
72809 +
72810 + if (retmode & GR_PTRACERD) {
72811 + switch (request) {
72812 + case PTRACE_SEIZE:
72813 + case PTRACE_POKETEXT:
72814 + case PTRACE_POKEDATA:
72815 + case PTRACE_POKEUSR:
72816 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
72817 + case PTRACE_SETREGS:
72818 + case PTRACE_SETFPREGS:
72819 +#endif
72820 +#ifdef CONFIG_X86
72821 + case PTRACE_SETFPXREGS:
72822 +#endif
72823 +#ifdef CONFIG_ALTIVEC
72824 + case PTRACE_SETVRREGS:
72825 +#endif
72826 + return 1;
72827 + default:
72828 + return 0;
72829 + }
72830 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
72831 + !(current->role->roletype & GR_ROLE_GOD) &&
72832 + (current->acl != task->acl)) {
72833 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
72834 + return 1;
72835 + }
72836 +
72837 + return 0;
72838 +}
72839 +
72840 +static int is_writable_mmap(const struct file *filp)
72841 +{
72842 + struct task_struct *task = current;
72843 + struct acl_object_label *obj, *obj2;
72844 +
72845 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
72846 + !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))) {
72847 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
72848 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
72849 + task->role->root_label);
72850 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
72851 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
72852 + return 1;
72853 + }
72854 + }
72855 + return 0;
72856 +}
72857 +
72858 +int
72859 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
72860 +{
72861 + __u32 mode;
72862 +
72863 + if (unlikely(!file || !(prot & PROT_EXEC)))
72864 + return 1;
72865 +
72866 + if (is_writable_mmap(file))
72867 + return 0;
72868 +
72869 + mode =
72870 + gr_search_file(file->f_path.dentry,
72871 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
72872 + file->f_path.mnt);
72873 +
72874 + if (!gr_tpe_allow(file))
72875 + return 0;
72876 +
72877 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
72878 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
72879 + return 0;
72880 + } else if (unlikely(!(mode & GR_EXEC))) {
72881 + return 0;
72882 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
72883 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
72884 + return 1;
72885 + }
72886 +
72887 + return 1;
72888 +}
72889 +
72890 +int
72891 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
72892 +{
72893 + __u32 mode;
72894 +
72895 + if (unlikely(!file || !(prot & PROT_EXEC)))
72896 + return 1;
72897 +
72898 + if (is_writable_mmap(file))
72899 + return 0;
72900 +
72901 + mode =
72902 + gr_search_file(file->f_path.dentry,
72903 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
72904 + file->f_path.mnt);
72905 +
72906 + if (!gr_tpe_allow(file))
72907 + return 0;
72908 +
72909 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
72910 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
72911 + return 0;
72912 + } else if (unlikely(!(mode & GR_EXEC))) {
72913 + return 0;
72914 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
72915 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
72916 + return 1;
72917 + }
72918 +
72919 + return 1;
72920 +}
72921 +
72922 +void
72923 +gr_acl_handle_psacct(struct task_struct *task, const long code)
72924 +{
72925 + unsigned long runtime, cputime;
72926 + cputime_t utime, stime;
72927 + unsigned int wday, cday;
72928 + __u8 whr, chr;
72929 + __u8 wmin, cmin;
72930 + __u8 wsec, csec;
72931 + struct timespec curtime, starttime;
72932 +
72933 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
72934 + !(task->acl->mode & GR_PROCACCT)))
72935 + return;
72936 +
72937 + curtime = ns_to_timespec(ktime_get_ns());
72938 + starttime = ns_to_timespec(task->start_time);
72939 + runtime = curtime.tv_sec - starttime.tv_sec;
72940 + wday = runtime / (60 * 60 * 24);
72941 + runtime -= wday * (60 * 60 * 24);
72942 + whr = runtime / (60 * 60);
72943 + runtime -= whr * (60 * 60);
72944 + wmin = runtime / 60;
72945 + runtime -= wmin * 60;
72946 + wsec = runtime;
72947 +
72948 + task_cputime(task, &utime, &stime);
72949 + cputime = cputime_to_secs(utime + stime);
72950 + cday = cputime / (60 * 60 * 24);
72951 + cputime -= cday * (60 * 60 * 24);
72952 + chr = cputime / (60 * 60);
72953 + cputime -= chr * (60 * 60);
72954 + cmin = cputime / 60;
72955 + cputime -= cmin * 60;
72956 + csec = cputime;
72957 +
72958 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
72959 +
72960 + return;
72961 +}
72962 +
72963 +#ifdef CONFIG_TASKSTATS
72964 +int gr_is_taskstats_denied(int pid)
72965 +{
72966 + struct task_struct *task;
72967 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
72968 + const struct cred *cred;
72969 +#endif
72970 + int ret = 0;
72971 +
72972 + /* restrict taskstats viewing to un-chrooted root users
72973 + who have the 'view' subject flag if the RBAC system is enabled
72974 + */
72975 +
72976 + rcu_read_lock();
72977 + read_lock(&tasklist_lock);
72978 + task = find_task_by_vpid(pid);
72979 + if (task) {
72980 +#ifdef CONFIG_GRKERNSEC_CHROOT
72981 + if (proc_is_chrooted(task))
72982 + ret = -EACCES;
72983 +#endif
72984 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
72985 + cred = __task_cred(task);
72986 +#ifdef CONFIG_GRKERNSEC_PROC_USER
72987 + if (gr_is_global_nonroot(cred->uid))
72988 + ret = -EACCES;
72989 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
72990 + if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
72991 + ret = -EACCES;
72992 +#endif
72993 +#endif
72994 + if (gr_status & GR_READY) {
72995 + if (!(task->acl->mode & GR_VIEW))
72996 + ret = -EACCES;
72997 + }
72998 + } else
72999 + ret = -ENOENT;
73000 +
73001 + read_unlock(&tasklist_lock);
73002 + rcu_read_unlock();
73003 +
73004 + return ret;
73005 +}
73006 +#endif
73007 +
73008 +/* AUXV entries are filled via a descendant of search_binary_handler
73009 + after we've already applied the subject for the target
73010 +*/
73011 +int gr_acl_enable_at_secure(void)
73012 +{
73013 + if (unlikely(!(gr_status & GR_READY)))
73014 + return 0;
73015 +
73016 + if (current->acl->mode & GR_ATSECURE)
73017 + return 1;
73018 +
73019 + return 0;
73020 +}
73021 +
73022 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
73023 +{
73024 + struct task_struct *task = current;
73025 + struct dentry *dentry = file->f_path.dentry;
73026 + struct vfsmount *mnt = file->f_path.mnt;
73027 + struct acl_object_label *obj, *tmp;
73028 + struct acl_subject_label *subj;
73029 + unsigned int bufsize;
73030 + int is_not_root;
73031 + char *path;
73032 + dev_t dev = __get_dev(dentry);
73033 +
73034 + if (unlikely(!(gr_status & GR_READY)))
73035 + return 1;
73036 +
73037 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
73038 + return 1;
73039 +
73040 + /* ignore Eric Biederman */
73041 + if (IS_PRIVATE(dentry->d_inode))
73042 + return 1;
73043 +
73044 + subj = task->acl;
73045 + read_lock(&gr_inode_lock);
73046 + do {
73047 + obj = lookup_acl_obj_label(ino, dev, subj);
73048 + if (obj != NULL) {
73049 + read_unlock(&gr_inode_lock);
73050 + return (obj->mode & GR_FIND) ? 1 : 0;
73051 + }
73052 + } while ((subj = subj->parent_subject));
73053 + read_unlock(&gr_inode_lock);
73054 +
73055 + /* this is purely an optimization since we're looking for an object
73056 + for the directory we're doing a readdir on
73057 + if it's possible for any globbed object to match the entry we're
73058 + filling into the directory, then the object we find here will be
73059 + an anchor point with attached globbed objects
73060 + */
73061 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
73062 + if (obj->globbed == NULL)
73063 + return (obj->mode & GR_FIND) ? 1 : 0;
73064 +
73065 + is_not_root = ((obj->filename[0] == '/') &&
73066 + (obj->filename[1] == '\0')) ? 0 : 1;
73067 + bufsize = PAGE_SIZE - namelen - is_not_root;
73068 +
73069 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
73070 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
73071 + return 1;
73072 +
73073 + preempt_disable();
73074 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
73075 + bufsize);
73076 +
73077 + bufsize = strlen(path);
73078 +
73079 + /* if base is "/", don't append an additional slash */
73080 + if (is_not_root)
73081 + *(path + bufsize) = '/';
73082 + memcpy(path + bufsize + is_not_root, name, namelen);
73083 + *(path + bufsize + namelen + is_not_root) = '\0';
73084 +
73085 + tmp = obj->globbed;
73086 + while (tmp) {
73087 + if (!glob_match(tmp->filename, path)) {
73088 + preempt_enable();
73089 + return (tmp->mode & GR_FIND) ? 1 : 0;
73090 + }
73091 + tmp = tmp->next;
73092 + }
73093 + preempt_enable();
73094 + return (obj->mode & GR_FIND) ? 1 : 0;
73095 +}
73096 +
73097 +void gr_put_exec_file(struct task_struct *task)
73098 +{
73099 + struct file *filp;
73100 +
73101 + write_lock(&grsec_exec_file_lock);
73102 + filp = task->exec_file;
73103 + task->exec_file = NULL;
73104 + write_unlock(&grsec_exec_file_lock);
73105 +
73106 + if (filp)
73107 + fput(filp);
73108 +
73109 + return;
73110 +}
73111 +
73112 +
73113 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
73114 +EXPORT_SYMBOL_GPL(gr_acl_is_enabled);
73115 +#endif
73116 +#ifdef CONFIG_SECURITY
73117 +EXPORT_SYMBOL_GPL(gr_check_user_change);
73118 +EXPORT_SYMBOL_GPL(gr_check_group_change);
73119 +#endif
73120 +
73121 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
73122 new file mode 100644
73123 index 0000000..18ffbbd
73124 --- /dev/null
73125 +++ b/grsecurity/gracl_alloc.c
73126 @@ -0,0 +1,105 @@
73127 +#include <linux/kernel.h>
73128 +#include <linux/mm.h>
73129 +#include <linux/slab.h>
73130 +#include <linux/vmalloc.h>
73131 +#include <linux/gracl.h>
73132 +#include <linux/grsecurity.h>
73133 +
73134 +static struct gr_alloc_state __current_alloc_state = { 1, 1, NULL };
73135 +struct gr_alloc_state *current_alloc_state = &__current_alloc_state;
73136 +
73137 +static __inline__ int
73138 +alloc_pop(void)
73139 +{
73140 + if (current_alloc_state->alloc_stack_next == 1)
73141 + return 0;
73142 +
73143 + kfree(current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 2]);
73144 +
73145 + current_alloc_state->alloc_stack_next--;
73146 +
73147 + return 1;
73148 +}
73149 +
73150 +static __inline__ int
73151 +alloc_push(void *buf)
73152 +{
73153 + if (current_alloc_state->alloc_stack_next >= current_alloc_state->alloc_stack_size)
73154 + return 1;
73155 +
73156 + current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 1] = buf;
73157 +
73158 + current_alloc_state->alloc_stack_next++;
73159 +
73160 + return 0;
73161 +}
73162 +
73163 +void *
73164 +acl_alloc(unsigned long len)
73165 +{
73166 + void *ret = NULL;
73167 +
73168 + if (!len || len > PAGE_SIZE)
73169 + goto out;
73170 +
73171 + ret = kmalloc(len, GFP_KERNEL);
73172 +
73173 + if (ret) {
73174 + if (alloc_push(ret)) {
73175 + kfree(ret);
73176 + ret = NULL;
73177 + }
73178 + }
73179 +
73180 +out:
73181 + return ret;
73182 +}
73183 +
73184 +void *
73185 +acl_alloc_num(unsigned long num, unsigned long len)
73186 +{
73187 + if (!len || (num > (PAGE_SIZE / len)))
73188 + return NULL;
73189 +
73190 + return acl_alloc(num * len);
73191 +}
73192 +
73193 +void
73194 +acl_free_all(void)
73195 +{
73196 + if (!current_alloc_state->alloc_stack)
73197 + return;
73198 +
73199 + while (alloc_pop()) ;
73200 +
73201 + if (current_alloc_state->alloc_stack) {
73202 + if ((current_alloc_state->alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
73203 + kfree(current_alloc_state->alloc_stack);
73204 + else
73205 + vfree(current_alloc_state->alloc_stack);
73206 + }
73207 +
73208 + current_alloc_state->alloc_stack = NULL;
73209 + current_alloc_state->alloc_stack_size = 1;
73210 + current_alloc_state->alloc_stack_next = 1;
73211 +
73212 + return;
73213 +}
73214 +
73215 +int
73216 +acl_alloc_stack_init(unsigned long size)
73217 +{
73218 + if ((size * sizeof (void *)) <= PAGE_SIZE)
73219 + current_alloc_state->alloc_stack =
73220 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
73221 + else
73222 + current_alloc_state->alloc_stack = (void **) vmalloc(size * sizeof (void *));
73223 +
73224 + current_alloc_state->alloc_stack_size = size;
73225 + current_alloc_state->alloc_stack_next = 1;
73226 +
73227 + if (!current_alloc_state->alloc_stack)
73228 + return 0;
73229 + else
73230 + return 1;
73231 +}
73232 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
73233 new file mode 100644
73234 index 0000000..1a94c11
73235 --- /dev/null
73236 +++ b/grsecurity/gracl_cap.c
73237 @@ -0,0 +1,127 @@
73238 +#include <linux/kernel.h>
73239 +#include <linux/module.h>
73240 +#include <linux/sched.h>
73241 +#include <linux/gracl.h>
73242 +#include <linux/grsecurity.h>
73243 +#include <linux/grinternal.h>
73244 +
73245 +extern const char *captab_log[];
73246 +extern int captab_log_entries;
73247 +
73248 +int gr_learn_cap(const struct task_struct *task, const struct cred *cred, const int cap)
73249 +{
73250 + struct acl_subject_label *curracl;
73251 +
73252 + if (!gr_acl_is_enabled())
73253 + return 1;
73254 +
73255 + curracl = task->acl;
73256 +
73257 + if (curracl->mode & (GR_LEARN | GR_INHERITLEARN)) {
73258 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
73259 + task->role->roletype, GR_GLOBAL_UID(cred->uid),
73260 + GR_GLOBAL_GID(cred->gid), task->exec_file ?
73261 + gr_to_filename(task->exec_file->f_path.dentry,
73262 + task->exec_file->f_path.mnt) : curracl->filename,
73263 + curracl->filename, 0UL,
73264 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
73265 + return 1;
73266 + }
73267 +
73268 + return 0;
73269 +}
73270 +
73271 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
73272 +{
73273 + struct acl_subject_label *curracl;
73274 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
73275 + kernel_cap_t cap_audit = __cap_empty_set;
73276 +
73277 + if (!gr_acl_is_enabled())
73278 + return 1;
73279 +
73280 + curracl = task->acl;
73281 +
73282 + cap_drop = curracl->cap_lower;
73283 + cap_mask = curracl->cap_mask;
73284 + cap_audit = curracl->cap_invert_audit;
73285 +
73286 + while ((curracl = curracl->parent_subject)) {
73287 + /* if the cap isn't specified in the current computed mask but is specified in the
73288 + current level subject, and is lowered in the current level subject, then add
73289 + it to the set of dropped capabilities
73290 + otherwise, add the current level subject's mask to the current computed mask
73291 + */
73292 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
73293 + cap_raise(cap_mask, cap);
73294 + if (cap_raised(curracl->cap_lower, cap))
73295 + cap_raise(cap_drop, cap);
73296 + if (cap_raised(curracl->cap_invert_audit, cap))
73297 + cap_raise(cap_audit, cap);
73298 + }
73299 + }
73300 +
73301 + if (!cap_raised(cap_drop, cap)) {
73302 + if (cap_raised(cap_audit, cap))
73303 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
73304 + return 1;
73305 + }
73306 +
73307 + /* only learn the capability use if the process has the capability in the
73308 + general case, the two uses in sys.c of gr_learn_cap are an exception
73309 + to this rule to ensure any role transition involves what the full-learned
73310 + policy believes in a privileged process
73311 + */
73312 + if (cap_raised(cred->cap_effective, cap) && gr_learn_cap(task, cred, cap))
73313 + return 1;
73314 +
73315 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
73316 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
73317 +
73318 + return 0;
73319 +}
73320 +
73321 +int
73322 +gr_acl_is_capable(const int cap)
73323 +{
73324 + return gr_task_acl_is_capable(current, current_cred(), cap);
73325 +}
73326 +
73327 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
73328 +{
73329 + struct acl_subject_label *curracl;
73330 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
73331 +
73332 + if (!gr_acl_is_enabled())
73333 + return 1;
73334 +
73335 + curracl = task->acl;
73336 +
73337 + cap_drop = curracl->cap_lower;
73338 + cap_mask = curracl->cap_mask;
73339 +
73340 + while ((curracl = curracl->parent_subject)) {
73341 + /* if the cap isn't specified in the current computed mask but is specified in the
73342 + current level subject, and is lowered in the current level subject, then add
73343 + it to the set of dropped capabilities
73344 + otherwise, add the current level subject's mask to the current computed mask
73345 + */
73346 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
73347 + cap_raise(cap_mask, cap);
73348 + if (cap_raised(curracl->cap_lower, cap))
73349 + cap_raise(cap_drop, cap);
73350 + }
73351 + }
73352 +
73353 + if (!cap_raised(cap_drop, cap))
73354 + return 1;
73355 +
73356 + return 0;
73357 +}
73358 +
73359 +int
73360 +gr_acl_is_capable_nolog(const int cap)
73361 +{
73362 + return gr_task_acl_is_capable_nolog(current, cap);
73363 +}
73364 +
73365 diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
73366 new file mode 100644
73367 index 0000000..ca25605
73368 --- /dev/null
73369 +++ b/grsecurity/gracl_compat.c
73370 @@ -0,0 +1,270 @@
73371 +#include <linux/kernel.h>
73372 +#include <linux/gracl.h>
73373 +#include <linux/compat.h>
73374 +#include <linux/gracl_compat.h>
73375 +
73376 +#include <asm/uaccess.h>
73377 +
73378 +int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
73379 +{
73380 + struct gr_arg_wrapper_compat uwrapcompat;
73381 +
73382 + if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
73383 + return -EFAULT;
73384 +
73385 + if (((uwrapcompat.version != GRSECURITY_VERSION) &&
73386 + (uwrapcompat.version != 0x2901)) ||
73387 + (uwrapcompat.size != sizeof(struct gr_arg_compat)))
73388 + return -EINVAL;
73389 +
73390 + uwrap->arg = compat_ptr(uwrapcompat.arg);
73391 + uwrap->version = uwrapcompat.version;
73392 + uwrap->size = sizeof(struct gr_arg);
73393 +
73394 + return 0;
73395 +}
73396 +
73397 +int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
73398 +{
73399 + struct gr_arg_compat argcompat;
73400 +
73401 + if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
73402 + return -EFAULT;
73403 +
73404 + arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
73405 + arg->role_db.num_pointers = argcompat.role_db.num_pointers;
73406 + arg->role_db.num_roles = argcompat.role_db.num_roles;
73407 + arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
73408 + arg->role_db.num_subjects = argcompat.role_db.num_subjects;
73409 + arg->role_db.num_objects = argcompat.role_db.num_objects;
73410 +
73411 + memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
73412 + memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
73413 + memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
73414 + memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
73415 + arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
73416 + arg->segv_device = argcompat.segv_device;
73417 + arg->segv_inode = argcompat.segv_inode;
73418 + arg->segv_uid = argcompat.segv_uid;
73419 + arg->num_sprole_pws = argcompat.num_sprole_pws;
73420 + arg->mode = argcompat.mode;
73421 +
73422 + return 0;
73423 +}
73424 +
73425 +int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
73426 +{
73427 + struct acl_object_label_compat objcompat;
73428 +
73429 + if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
73430 + return -EFAULT;
73431 +
73432 + obj->filename = compat_ptr(objcompat.filename);
73433 + obj->inode = objcompat.inode;
73434 + obj->device = objcompat.device;
73435 + obj->mode = objcompat.mode;
73436 +
73437 + obj->nested = compat_ptr(objcompat.nested);
73438 + obj->globbed = compat_ptr(objcompat.globbed);
73439 +
73440 + obj->prev = compat_ptr(objcompat.prev);
73441 + obj->next = compat_ptr(objcompat.next);
73442 +
73443 + return 0;
73444 +}
73445 +
73446 +int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
73447 +{
73448 + unsigned int i;
73449 + struct acl_subject_label_compat subjcompat;
73450 +
73451 + if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
73452 + return -EFAULT;
73453 +
73454 + subj->filename = compat_ptr(subjcompat.filename);
73455 + subj->inode = subjcompat.inode;
73456 + subj->device = subjcompat.device;
73457 + subj->mode = subjcompat.mode;
73458 + subj->cap_mask = subjcompat.cap_mask;
73459 + subj->cap_lower = subjcompat.cap_lower;
73460 + subj->cap_invert_audit = subjcompat.cap_invert_audit;
73461 +
73462 + for (i = 0; i < GR_NLIMITS; i++) {
73463 + if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
73464 + subj->res[i].rlim_cur = RLIM_INFINITY;
73465 + else
73466 + subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
73467 + if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
73468 + subj->res[i].rlim_max = RLIM_INFINITY;
73469 + else
73470 + subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
73471 + }
73472 + subj->resmask = subjcompat.resmask;
73473 +
73474 + subj->user_trans_type = subjcompat.user_trans_type;
73475 + subj->group_trans_type = subjcompat.group_trans_type;
73476 + subj->user_transitions = compat_ptr(subjcompat.user_transitions);
73477 + subj->group_transitions = compat_ptr(subjcompat.group_transitions);
73478 + subj->user_trans_num = subjcompat.user_trans_num;
73479 + subj->group_trans_num = subjcompat.group_trans_num;
73480 +
73481 + memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
73482 + memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
73483 + subj->ip_type = subjcompat.ip_type;
73484 + subj->ips = compat_ptr(subjcompat.ips);
73485 + subj->ip_num = subjcompat.ip_num;
73486 + subj->inaddr_any_override = subjcompat.inaddr_any_override;
73487 +
73488 + subj->crashes = subjcompat.crashes;
73489 + subj->expires = subjcompat.expires;
73490 +
73491 + subj->parent_subject = compat_ptr(subjcompat.parent_subject);
73492 + subj->hash = compat_ptr(subjcompat.hash);
73493 + subj->prev = compat_ptr(subjcompat.prev);
73494 + subj->next = compat_ptr(subjcompat.next);
73495 +
73496 + subj->obj_hash = compat_ptr(subjcompat.obj_hash);
73497 + subj->obj_hash_size = subjcompat.obj_hash_size;
73498 + subj->pax_flags = subjcompat.pax_flags;
73499 +
73500 + return 0;
73501 +}
73502 +
73503 +int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
73504 +{
73505 + struct acl_role_label_compat rolecompat;
73506 +
73507 + if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
73508 + return -EFAULT;
73509 +
73510 + role->rolename = compat_ptr(rolecompat.rolename);
73511 + role->uidgid = rolecompat.uidgid;
73512 + role->roletype = rolecompat.roletype;
73513 +
73514 + role->auth_attempts = rolecompat.auth_attempts;
73515 + role->expires = rolecompat.expires;
73516 +
73517 + role->root_label = compat_ptr(rolecompat.root_label);
73518 + role->hash = compat_ptr(rolecompat.hash);
73519 +
73520 + role->prev = compat_ptr(rolecompat.prev);
73521 + role->next = compat_ptr(rolecompat.next);
73522 +
73523 + role->transitions = compat_ptr(rolecompat.transitions);
73524 + role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
73525 + role->domain_children = compat_ptr(rolecompat.domain_children);
73526 + role->domain_child_num = rolecompat.domain_child_num;
73527 +
73528 + role->umask = rolecompat.umask;
73529 +
73530 + role->subj_hash = compat_ptr(rolecompat.subj_hash);
73531 + role->subj_hash_size = rolecompat.subj_hash_size;
73532 +
73533 + return 0;
73534 +}
73535 +
73536 +int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
73537 +{
73538 + struct role_allowed_ip_compat roleip_compat;
73539 +
73540 + if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
73541 + return -EFAULT;
73542 +
73543 + roleip->addr = roleip_compat.addr;
73544 + roleip->netmask = roleip_compat.netmask;
73545 +
73546 + roleip->prev = compat_ptr(roleip_compat.prev);
73547 + roleip->next = compat_ptr(roleip_compat.next);
73548 +
73549 + return 0;
73550 +}
73551 +
73552 +int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
73553 +{
73554 + struct role_transition_compat trans_compat;
73555 +
73556 + if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
73557 + return -EFAULT;
73558 +
73559 + trans->rolename = compat_ptr(trans_compat.rolename);
73560 +
73561 + trans->prev = compat_ptr(trans_compat.prev);
73562 + trans->next = compat_ptr(trans_compat.next);
73563 +
73564 + return 0;
73565 +
73566 +}
73567 +
73568 +int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
73569 +{
73570 + struct gr_hash_struct_compat hash_compat;
73571 +
73572 + if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
73573 + return -EFAULT;
73574 +
73575 + hash->table = compat_ptr(hash_compat.table);
73576 + hash->nametable = compat_ptr(hash_compat.nametable);
73577 + hash->first = compat_ptr(hash_compat.first);
73578 +
73579 + hash->table_size = hash_compat.table_size;
73580 + hash->used_size = hash_compat.used_size;
73581 +
73582 + hash->type = hash_compat.type;
73583 +
73584 + return 0;
73585 +}
73586 +
73587 +int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
73588 +{
73589 + compat_uptr_t ptrcompat;
73590 +
73591 + if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
73592 + return -EFAULT;
73593 +
73594 + *(void **)ptr = compat_ptr(ptrcompat);
73595 +
73596 + return 0;
73597 +}
73598 +
73599 +int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
73600 +{
73601 + struct acl_ip_label_compat ip_compat;
73602 +
73603 + if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
73604 + return -EFAULT;
73605 +
73606 + ip->iface = compat_ptr(ip_compat.iface);
73607 + ip->addr = ip_compat.addr;
73608 + ip->netmask = ip_compat.netmask;
73609 + ip->low = ip_compat.low;
73610 + ip->high = ip_compat.high;
73611 + ip->mode = ip_compat.mode;
73612 + ip->type = ip_compat.type;
73613 +
73614 + memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
73615 +
73616 + ip->prev = compat_ptr(ip_compat.prev);
73617 + ip->next = compat_ptr(ip_compat.next);
73618 +
73619 + return 0;
73620 +}
73621 +
73622 +int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
73623 +{
73624 + struct sprole_pw_compat pw_compat;
73625 +
73626 + if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
73627 + return -EFAULT;
73628 +
73629 + pw->rolename = compat_ptr(pw_compat.rolename);
73630 + memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
73631 + memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
73632 +
73633 + return 0;
73634 +}
73635 +
73636 +size_t get_gr_arg_wrapper_size_compat(void)
73637 +{
73638 + return sizeof(struct gr_arg_wrapper_compat);
73639 +}
73640 +
73641 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
73642 new file mode 100644
73643 index 0000000..4008fdc
73644 --- /dev/null
73645 +++ b/grsecurity/gracl_fs.c
73646 @@ -0,0 +1,445 @@
73647 +#include <linux/kernel.h>
73648 +#include <linux/sched.h>
73649 +#include <linux/types.h>
73650 +#include <linux/fs.h>
73651 +#include <linux/file.h>
73652 +#include <linux/stat.h>
73653 +#include <linux/grsecurity.h>
73654 +#include <linux/grinternal.h>
73655 +#include <linux/gracl.h>
73656 +
73657 +umode_t
73658 +gr_acl_umask(void)
73659 +{
73660 + if (unlikely(!gr_acl_is_enabled()))
73661 + return 0;
73662 +
73663 + return current->role->umask;
73664 +}
73665 +
73666 +__u32
73667 +gr_acl_handle_hidden_file(const struct dentry * dentry,
73668 + const struct vfsmount * mnt)
73669 +{
73670 + __u32 mode;
73671 +
73672 + if (unlikely(d_is_negative(dentry)))
73673 + return GR_FIND;
73674 +
73675 + mode =
73676 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
73677 +
73678 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
73679 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
73680 + return mode;
73681 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
73682 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
73683 + return 0;
73684 + } else if (unlikely(!(mode & GR_FIND)))
73685 + return 0;
73686 +
73687 + return GR_FIND;
73688 +}
73689 +
73690 +__u32
73691 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
73692 + int acc_mode)
73693 +{
73694 + __u32 reqmode = GR_FIND;
73695 + __u32 mode;
73696 +
73697 + if (unlikely(d_is_negative(dentry)))
73698 + return reqmode;
73699 +
73700 + if (acc_mode & MAY_APPEND)
73701 + reqmode |= GR_APPEND;
73702 + else if (acc_mode & MAY_WRITE)
73703 + reqmode |= GR_WRITE;
73704 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
73705 + reqmode |= GR_READ;
73706 +
73707 + mode =
73708 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
73709 + mnt);
73710 +
73711 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
73712 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
73713 + reqmode & GR_READ ? " reading" : "",
73714 + reqmode & GR_WRITE ? " writing" : reqmode &
73715 + GR_APPEND ? " appending" : "");
73716 + return reqmode;
73717 + } else
73718 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
73719 + {
73720 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
73721 + reqmode & GR_READ ? " reading" : "",
73722 + reqmode & GR_WRITE ? " writing" : reqmode &
73723 + GR_APPEND ? " appending" : "");
73724 + return 0;
73725 + } else if (unlikely((mode & reqmode) != reqmode))
73726 + return 0;
73727 +
73728 + return reqmode;
73729 +}
73730 +
73731 +__u32
73732 +gr_acl_handle_creat(const struct dentry * dentry,
73733 + const struct dentry * p_dentry,
73734 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
73735 + const int imode)
73736 +{
73737 + __u32 reqmode = GR_WRITE | GR_CREATE;
73738 + __u32 mode;
73739 +
73740 + if (acc_mode & MAY_APPEND)
73741 + reqmode |= GR_APPEND;
73742 + // if a directory was required or the directory already exists, then
73743 + // don't count this open as a read
73744 + if ((acc_mode & MAY_READ) &&
73745 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
73746 + reqmode |= GR_READ;
73747 + if ((open_flags & O_CREAT) &&
73748 + ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
73749 + reqmode |= GR_SETID;
73750 +
73751 + mode =
73752 + gr_check_create(dentry, p_dentry, p_mnt,
73753 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
73754 +
73755 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
73756 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
73757 + reqmode & GR_READ ? " reading" : "",
73758 + reqmode & GR_WRITE ? " writing" : reqmode &
73759 + GR_APPEND ? " appending" : "");
73760 + return reqmode;
73761 + } else
73762 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
73763 + {
73764 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
73765 + reqmode & GR_READ ? " reading" : "",
73766 + reqmode & GR_WRITE ? " writing" : reqmode &
73767 + GR_APPEND ? " appending" : "");
73768 + return 0;
73769 + } else if (unlikely((mode & reqmode) != reqmode))
73770 + return 0;
73771 +
73772 + return reqmode;
73773 +}
73774 +
73775 +__u32
73776 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
73777 + const int fmode)
73778 +{
73779 + __u32 mode, reqmode = GR_FIND;
73780 +
73781 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
73782 + reqmode |= GR_EXEC;
73783 + if (fmode & S_IWOTH)
73784 + reqmode |= GR_WRITE;
73785 + if (fmode & S_IROTH)
73786 + reqmode |= GR_READ;
73787 +
73788 + mode =
73789 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
73790 + mnt);
73791 +
73792 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
73793 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
73794 + reqmode & GR_READ ? " reading" : "",
73795 + reqmode & GR_WRITE ? " writing" : "",
73796 + reqmode & GR_EXEC ? " executing" : "");
73797 + return reqmode;
73798 + } else
73799 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
73800 + {
73801 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
73802 + reqmode & GR_READ ? " reading" : "",
73803 + reqmode & GR_WRITE ? " writing" : "",
73804 + reqmode & GR_EXEC ? " executing" : "");
73805 + return 0;
73806 + } else if (unlikely((mode & reqmode) != reqmode))
73807 + return 0;
73808 +
73809 + return reqmode;
73810 +}
73811 +
73812 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
73813 +{
73814 + __u32 mode;
73815 +
73816 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
73817 +
73818 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
73819 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
73820 + return mode;
73821 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
73822 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
73823 + return 0;
73824 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
73825 + return 0;
73826 +
73827 + return (reqmode);
73828 +}
73829 +
73830 +__u32
73831 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
73832 +{
73833 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
73834 +}
73835 +
73836 +__u32
73837 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
73838 +{
73839 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
73840 +}
73841 +
73842 +__u32
73843 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
73844 +{
73845 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
73846 +}
73847 +
73848 +__u32
73849 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
73850 +{
73851 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
73852 +}
73853 +
73854 +__u32
73855 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
73856 + umode_t *modeptr)
73857 +{
73858 + umode_t mode;
73859 +
73860 + *modeptr &= ~gr_acl_umask();
73861 + mode = *modeptr;
73862 +
73863 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
73864 + return 1;
73865 +
73866 + if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
73867 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
73868 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
73869 + GR_CHMOD_ACL_MSG);
73870 + } else {
73871 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
73872 + }
73873 +}
73874 +
73875 +__u32
73876 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
73877 +{
73878 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
73879 +}
73880 +
73881 +__u32
73882 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
73883 +{
73884 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
73885 +}
73886 +
73887 +__u32
73888 +gr_acl_handle_removexattr(const struct dentry *dentry, const struct vfsmount *mnt)
73889 +{
73890 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_REMOVEXATTR_ACL_MSG);
73891 +}
73892 +
73893 +__u32
73894 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
73895 +{
73896 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
73897 +}
73898 +
73899 +__u32
73900 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
73901 +{
73902 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
73903 + GR_UNIXCONNECT_ACL_MSG);
73904 +}
73905 +
73906 +/* hardlinks require at minimum create and link permission,
73907 + any additional privilege required is based on the
73908 + privilege of the file being linked to
73909 +*/
73910 +__u32
73911 +gr_acl_handle_link(const struct dentry * new_dentry,
73912 + const struct dentry * parent_dentry,
73913 + const struct vfsmount * parent_mnt,
73914 + const struct dentry * old_dentry,
73915 + const struct vfsmount * old_mnt, const struct filename *to)
73916 +{
73917 + __u32 mode;
73918 + __u32 needmode = GR_CREATE | GR_LINK;
73919 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
73920 +
73921 + mode =
73922 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
73923 + old_mnt);
73924 +
73925 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
73926 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
73927 + return mode;
73928 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
73929 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
73930 + return 0;
73931 + } else if (unlikely((mode & needmode) != needmode))
73932 + return 0;
73933 +
73934 + return 1;
73935 +}
73936 +
73937 +__u32
73938 +gr_acl_handle_symlink(const struct dentry * new_dentry,
73939 + const struct dentry * parent_dentry,
73940 + const struct vfsmount * parent_mnt, const struct filename *from)
73941 +{
73942 + __u32 needmode = GR_WRITE | GR_CREATE;
73943 + __u32 mode;
73944 +
73945 + mode =
73946 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
73947 + GR_CREATE | GR_AUDIT_CREATE |
73948 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
73949 +
73950 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
73951 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
73952 + return mode;
73953 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
73954 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
73955 + return 0;
73956 + } else if (unlikely((mode & needmode) != needmode))
73957 + return 0;
73958 +
73959 + return (GR_WRITE | GR_CREATE);
73960 +}
73961 +
73962 +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)
73963 +{
73964 + __u32 mode;
73965 +
73966 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
73967 +
73968 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
73969 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
73970 + return mode;
73971 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
73972 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
73973 + return 0;
73974 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
73975 + return 0;
73976 +
73977 + return (reqmode);
73978 +}
73979 +
73980 +__u32
73981 +gr_acl_handle_mknod(const struct dentry * new_dentry,
73982 + const struct dentry * parent_dentry,
73983 + const struct vfsmount * parent_mnt,
73984 + const int mode)
73985 +{
73986 + __u32 reqmode = GR_WRITE | GR_CREATE;
73987 + if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
73988 + reqmode |= GR_SETID;
73989 +
73990 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
73991 + reqmode, GR_MKNOD_ACL_MSG);
73992 +}
73993 +
73994 +__u32
73995 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
73996 + const struct dentry *parent_dentry,
73997 + const struct vfsmount *parent_mnt)
73998 +{
73999 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
74000 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
74001 +}
74002 +
74003 +#define RENAME_CHECK_SUCCESS(old, new) \
74004 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
74005 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
74006 +
74007 +int
74008 +gr_acl_handle_rename(struct dentry *new_dentry,
74009 + struct dentry *parent_dentry,
74010 + const struct vfsmount *parent_mnt,
74011 + struct dentry *old_dentry,
74012 + struct inode *old_parent_inode,
74013 + struct vfsmount *old_mnt, const struct filename *newname, unsigned int flags)
74014 +{
74015 + __u32 comp1, comp2;
74016 + int error = 0;
74017 +
74018 + if (unlikely(!gr_acl_is_enabled()))
74019 + return 0;
74020 +
74021 + if (flags & RENAME_EXCHANGE) {
74022 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
74023 + GR_AUDIT_READ | GR_AUDIT_WRITE |
74024 + GR_SUPPRESS, parent_mnt);
74025 + comp2 =
74026 + gr_search_file(old_dentry,
74027 + GR_READ | GR_WRITE | GR_AUDIT_READ |
74028 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
74029 + } else if (d_is_negative(new_dentry)) {
74030 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
74031 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
74032 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
74033 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
74034 + GR_DELETE | GR_AUDIT_DELETE |
74035 + GR_AUDIT_READ | GR_AUDIT_WRITE |
74036 + GR_SUPPRESS, old_mnt);
74037 + } else {
74038 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
74039 + GR_CREATE | GR_DELETE |
74040 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
74041 + GR_AUDIT_READ | GR_AUDIT_WRITE |
74042 + GR_SUPPRESS, parent_mnt);
74043 + comp2 =
74044 + gr_search_file(old_dentry,
74045 + GR_READ | GR_WRITE | GR_AUDIT_READ |
74046 + GR_DELETE | GR_AUDIT_DELETE |
74047 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
74048 + }
74049 +
74050 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
74051 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
74052 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
74053 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
74054 + && !(comp2 & GR_SUPPRESS)) {
74055 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
74056 + error = -EACCES;
74057 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
74058 + error = -EACCES;
74059 +
74060 + return error;
74061 +}
74062 +
74063 +void
74064 +gr_acl_handle_exit(void)
74065 +{
74066 + u16 id;
74067 + char *rolename;
74068 +
74069 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
74070 + !(current->role->roletype & GR_ROLE_PERSIST))) {
74071 + id = current->acl_role_id;
74072 + rolename = current->role->rolename;
74073 + gr_set_acls(1);
74074 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
74075 + }
74076 +
74077 + gr_put_exec_file(current);
74078 + return;
74079 +}
74080 +
74081 +int
74082 +gr_acl_handle_procpidmem(const struct task_struct *task)
74083 +{
74084 + if (unlikely(!gr_acl_is_enabled()))
74085 + return 0;
74086 +
74087 + if (task != current && task->acl->mode & GR_PROTPROCFD)
74088 + return -EACCES;
74089 +
74090 + return 0;
74091 +}
74092 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
74093 new file mode 100644
74094 index 0000000..f056b81
74095 --- /dev/null
74096 +++ b/grsecurity/gracl_ip.c
74097 @@ -0,0 +1,386 @@
74098 +#include <linux/kernel.h>
74099 +#include <asm/uaccess.h>
74100 +#include <asm/errno.h>
74101 +#include <net/sock.h>
74102 +#include <linux/file.h>
74103 +#include <linux/fs.h>
74104 +#include <linux/net.h>
74105 +#include <linux/in.h>
74106 +#include <linux/skbuff.h>
74107 +#include <linux/ip.h>
74108 +#include <linux/udp.h>
74109 +#include <linux/types.h>
74110 +#include <linux/sched.h>
74111 +#include <linux/netdevice.h>
74112 +#include <linux/inetdevice.h>
74113 +#include <linux/gracl.h>
74114 +#include <linux/grsecurity.h>
74115 +#include <linux/grinternal.h>
74116 +
74117 +#define GR_BIND 0x01
74118 +#define GR_CONNECT 0x02
74119 +#define GR_INVERT 0x04
74120 +#define GR_BINDOVERRIDE 0x08
74121 +#define GR_CONNECTOVERRIDE 0x10
74122 +#define GR_SOCK_FAMILY 0x20
74123 +
74124 +static const char * gr_protocols[IPPROTO_MAX] = {
74125 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
74126 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
74127 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
74128 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
74129 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
74130 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
74131 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
74132 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
74133 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
74134 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
74135 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
74136 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
74137 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
74138 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
74139 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
74140 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
74141 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
74142 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
74143 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
74144 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
74145 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
74146 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
74147 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
74148 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
74149 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
74150 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
74151 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
74152 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
74153 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
74154 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
74155 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
74156 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
74157 + };
74158 +
74159 +static const char * gr_socktypes[SOCK_MAX] = {
74160 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
74161 + "unknown:7", "unknown:8", "unknown:9", "packet"
74162 + };
74163 +
74164 +static const char * gr_sockfamilies[AF_MAX+1] = {
74165 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
74166 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
74167 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
74168 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
74169 + };
74170 +
74171 +const char *
74172 +gr_proto_to_name(unsigned char proto)
74173 +{
74174 + return gr_protocols[proto];
74175 +}
74176 +
74177 +const char *
74178 +gr_socktype_to_name(unsigned char type)
74179 +{
74180 + return gr_socktypes[type];
74181 +}
74182 +
74183 +const char *
74184 +gr_sockfamily_to_name(unsigned char family)
74185 +{
74186 + return gr_sockfamilies[family];
74187 +}
74188 +
74189 +extern const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
74190 +
74191 +int
74192 +gr_search_socket(const int domain, const int type, const int protocol)
74193 +{
74194 + struct acl_subject_label *curr;
74195 + const struct cred *cred = current_cred();
74196 +
74197 + if (unlikely(!gr_acl_is_enabled()))
74198 + goto exit;
74199 +
74200 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
74201 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
74202 + goto exit; // let the kernel handle it
74203 +
74204 + curr = current->acl;
74205 +
74206 + if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
74207 + /* the family is allowed, if this is PF_INET allow it only if
74208 + the extra sock type/protocol checks pass */
74209 + if (domain == PF_INET)
74210 + goto inet_check;
74211 + goto exit;
74212 + } else {
74213 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
74214 + __u32 fakeip = 0;
74215 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
74216 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
74217 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
74218 + gr_to_filename(current->exec_file->f_path.dentry,
74219 + current->exec_file->f_path.mnt) :
74220 + curr->filename, curr->filename,
74221 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
74222 + &current->signal->saved_ip);
74223 + goto exit;
74224 + }
74225 + goto exit_fail;
74226 + }
74227 +
74228 +inet_check:
74229 + /* the rest of this checking is for IPv4 only */
74230 + if (!curr->ips)
74231 + goto exit;
74232 +
74233 + if ((curr->ip_type & (1U << type)) &&
74234 + (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
74235 + goto exit;
74236 +
74237 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
74238 + /* we don't place acls on raw sockets , and sometimes
74239 + dgram/ip sockets are opened for ioctl and not
74240 + bind/connect, so we'll fake a bind learn log */
74241 + if (type == SOCK_RAW || type == SOCK_PACKET) {
74242 + __u32 fakeip = 0;
74243 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
74244 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
74245 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
74246 + gr_to_filename(current->exec_file->f_path.dentry,
74247 + current->exec_file->f_path.mnt) :
74248 + curr->filename, curr->filename,
74249 + &fakeip, 0, type,
74250 + protocol, GR_CONNECT, &current->signal->saved_ip);
74251 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
74252 + __u32 fakeip = 0;
74253 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
74254 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
74255 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
74256 + gr_to_filename(current->exec_file->f_path.dentry,
74257 + current->exec_file->f_path.mnt) :
74258 + curr->filename, curr->filename,
74259 + &fakeip, 0, type,
74260 + protocol, GR_BIND, &current->signal->saved_ip);
74261 + }
74262 + /* we'll log when they use connect or bind */
74263 + goto exit;
74264 + }
74265 +
74266 +exit_fail:
74267 + if (domain == PF_INET)
74268 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
74269 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
74270 + else if (rcu_access_pointer(net_families[domain]) != NULL)
74271 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
74272 + gr_socktype_to_name(type), protocol);
74273 +
74274 + return 0;
74275 +exit:
74276 + return 1;
74277 +}
74278 +
74279 +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)
74280 +{
74281 + if ((ip->mode & mode) &&
74282 + (ip_port >= ip->low) &&
74283 + (ip_port <= ip->high) &&
74284 + ((ntohl(ip_addr) & our_netmask) ==
74285 + (ntohl(our_addr) & our_netmask))
74286 + && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
74287 + && (ip->type & (1U << type))) {
74288 + if (ip->mode & GR_INVERT)
74289 + return 2; // specifically denied
74290 + else
74291 + return 1; // allowed
74292 + }
74293 +
74294 + return 0; // not specifically allowed, may continue parsing
74295 +}
74296 +
74297 +static int
74298 +gr_search_connectbind(const int full_mode, struct sock *sk,
74299 + struct sockaddr_in *addr, const int type)
74300 +{
74301 + char iface[IFNAMSIZ] = {0};
74302 + struct acl_subject_label *curr;
74303 + struct acl_ip_label *ip;
74304 + struct inet_sock *isk;
74305 + struct net_device *dev;
74306 + struct in_device *idev;
74307 + unsigned long i;
74308 + int ret;
74309 + int mode = full_mode & (GR_BIND | GR_CONNECT);
74310 + __u32 ip_addr = 0;
74311 + __u32 our_addr;
74312 + __u32 our_netmask;
74313 + char *p;
74314 + __u16 ip_port = 0;
74315 + const struct cred *cred = current_cred();
74316 +
74317 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
74318 + return 0;
74319 +
74320 + curr = current->acl;
74321 + isk = inet_sk(sk);
74322 +
74323 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
74324 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
74325 + addr->sin_addr.s_addr = curr->inaddr_any_override;
74326 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
74327 + struct sockaddr_in saddr;
74328 + int err;
74329 +
74330 + saddr.sin_family = AF_INET;
74331 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
74332 + saddr.sin_port = isk->inet_sport;
74333 +
74334 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
74335 + if (err)
74336 + return err;
74337 +
74338 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
74339 + if (err)
74340 + return err;
74341 + }
74342 +
74343 + if (!curr->ips)
74344 + return 0;
74345 +
74346 + ip_addr = addr->sin_addr.s_addr;
74347 + ip_port = ntohs(addr->sin_port);
74348 +
74349 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
74350 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
74351 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
74352 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
74353 + gr_to_filename(current->exec_file->f_path.dentry,
74354 + current->exec_file->f_path.mnt) :
74355 + curr->filename, curr->filename,
74356 + &ip_addr, ip_port, type,
74357 + sk->sk_protocol, mode, &current->signal->saved_ip);
74358 + return 0;
74359 + }
74360 +
74361 + for (i = 0; i < curr->ip_num; i++) {
74362 + ip = *(curr->ips + i);
74363 + if (ip->iface != NULL) {
74364 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
74365 + p = strchr(iface, ':');
74366 + if (p != NULL)
74367 + *p = '\0';
74368 + dev = dev_get_by_name(sock_net(sk), iface);
74369 + if (dev == NULL)
74370 + continue;
74371 + idev = in_dev_get(dev);
74372 + if (idev == NULL) {
74373 + dev_put(dev);
74374 + continue;
74375 + }
74376 + rcu_read_lock();
74377 + for_ifa(idev) {
74378 + if (!strcmp(ip->iface, ifa->ifa_label)) {
74379 + our_addr = ifa->ifa_address;
74380 + our_netmask = 0xffffffff;
74381 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
74382 + if (ret == 1) {
74383 + rcu_read_unlock();
74384 + in_dev_put(idev);
74385 + dev_put(dev);
74386 + return 0;
74387 + } else if (ret == 2) {
74388 + rcu_read_unlock();
74389 + in_dev_put(idev);
74390 + dev_put(dev);
74391 + goto denied;
74392 + }
74393 + }
74394 + } endfor_ifa(idev);
74395 + rcu_read_unlock();
74396 + in_dev_put(idev);
74397 + dev_put(dev);
74398 + } else {
74399 + our_addr = ip->addr;
74400 + our_netmask = ip->netmask;
74401 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
74402 + if (ret == 1)
74403 + return 0;
74404 + else if (ret == 2)
74405 + goto denied;
74406 + }
74407 + }
74408 +
74409 +denied:
74410 + if (mode == GR_BIND)
74411 + 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));
74412 + else if (mode == GR_CONNECT)
74413 + 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));
74414 +
74415 + return -EACCES;
74416 +}
74417 +
74418 +int
74419 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
74420 +{
74421 + /* always allow disconnection of dgram sockets with connect */
74422 + if (addr->sin_family == AF_UNSPEC)
74423 + return 0;
74424 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
74425 +}
74426 +
74427 +int
74428 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
74429 +{
74430 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
74431 +}
74432 +
74433 +int gr_search_listen(struct socket *sock)
74434 +{
74435 + struct sock *sk = sock->sk;
74436 + struct sockaddr_in addr;
74437 +
74438 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
74439 + addr.sin_port = inet_sk(sk)->inet_sport;
74440 +
74441 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
74442 +}
74443 +
74444 +int gr_search_accept(struct socket *sock)
74445 +{
74446 + struct sock *sk = sock->sk;
74447 + struct sockaddr_in addr;
74448 +
74449 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
74450 + addr.sin_port = inet_sk(sk)->inet_sport;
74451 +
74452 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
74453 +}
74454 +
74455 +int
74456 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
74457 +{
74458 + if (addr)
74459 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
74460 + else {
74461 + struct sockaddr_in sin;
74462 + const struct inet_sock *inet = inet_sk(sk);
74463 +
74464 + sin.sin_addr.s_addr = inet->inet_daddr;
74465 + sin.sin_port = inet->inet_dport;
74466 +
74467 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
74468 + }
74469 +}
74470 +
74471 +int
74472 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
74473 +{
74474 + struct sockaddr_in sin;
74475 +
74476 + if (unlikely(skb->len < sizeof (struct udphdr)))
74477 + return 0; // skip this packet
74478 +
74479 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
74480 + sin.sin_port = udp_hdr(skb)->source;
74481 +
74482 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
74483 +}
74484 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
74485 new file mode 100644
74486 index 0000000..25f54ef
74487 --- /dev/null
74488 +++ b/grsecurity/gracl_learn.c
74489 @@ -0,0 +1,207 @@
74490 +#include <linux/kernel.h>
74491 +#include <linux/mm.h>
74492 +#include <linux/sched.h>
74493 +#include <linux/poll.h>
74494 +#include <linux/string.h>
74495 +#include <linux/file.h>
74496 +#include <linux/types.h>
74497 +#include <linux/vmalloc.h>
74498 +#include <linux/grinternal.h>
74499 +
74500 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
74501 + size_t count, loff_t *ppos);
74502 +extern int gr_acl_is_enabled(void);
74503 +
74504 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
74505 +static int gr_learn_attached;
74506 +
74507 +/* use a 512k buffer */
74508 +#define LEARN_BUFFER_SIZE (512 * 1024)
74509 +
74510 +static DEFINE_SPINLOCK(gr_learn_lock);
74511 +static DEFINE_MUTEX(gr_learn_user_mutex);
74512 +
74513 +/* we need to maintain two buffers, so that the kernel context of grlearn
74514 + uses a semaphore around the userspace copying, and the other kernel contexts
74515 + use a spinlock when copying into the buffer, since they cannot sleep
74516 +*/
74517 +static char *learn_buffer;
74518 +static char *learn_buffer_user;
74519 +static int learn_buffer_len;
74520 +static int learn_buffer_user_len;
74521 +
74522 +static ssize_t
74523 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
74524 +{
74525 + DECLARE_WAITQUEUE(wait, current);
74526 + ssize_t retval = 0;
74527 +
74528 + add_wait_queue(&learn_wait, &wait);
74529 + set_current_state(TASK_INTERRUPTIBLE);
74530 + do {
74531 + mutex_lock(&gr_learn_user_mutex);
74532 + spin_lock(&gr_learn_lock);
74533 + if (learn_buffer_len)
74534 + break;
74535 + spin_unlock(&gr_learn_lock);
74536 + mutex_unlock(&gr_learn_user_mutex);
74537 + if (file->f_flags & O_NONBLOCK) {
74538 + retval = -EAGAIN;
74539 + goto out;
74540 + }
74541 + if (signal_pending(current)) {
74542 + retval = -ERESTARTSYS;
74543 + goto out;
74544 + }
74545 +
74546 + schedule();
74547 + } while (1);
74548 +
74549 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
74550 + learn_buffer_user_len = learn_buffer_len;
74551 + retval = learn_buffer_len;
74552 + learn_buffer_len = 0;
74553 +
74554 + spin_unlock(&gr_learn_lock);
74555 +
74556 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
74557 + retval = -EFAULT;
74558 +
74559 + mutex_unlock(&gr_learn_user_mutex);
74560 +out:
74561 + set_current_state(TASK_RUNNING);
74562 + remove_wait_queue(&learn_wait, &wait);
74563 + return retval;
74564 +}
74565 +
74566 +static unsigned int
74567 +poll_learn(struct file * file, poll_table * wait)
74568 +{
74569 + poll_wait(file, &learn_wait, wait);
74570 +
74571 + if (learn_buffer_len)
74572 + return (POLLIN | POLLRDNORM);
74573 +
74574 + return 0;
74575 +}
74576 +
74577 +void
74578 +gr_clear_learn_entries(void)
74579 +{
74580 + char *tmp;
74581 +
74582 + mutex_lock(&gr_learn_user_mutex);
74583 + spin_lock(&gr_learn_lock);
74584 + tmp = learn_buffer;
74585 + learn_buffer = NULL;
74586 + spin_unlock(&gr_learn_lock);
74587 + if (tmp)
74588 + vfree(tmp);
74589 + if (learn_buffer_user != NULL) {
74590 + vfree(learn_buffer_user);
74591 + learn_buffer_user = NULL;
74592 + }
74593 + learn_buffer_len = 0;
74594 + mutex_unlock(&gr_learn_user_mutex);
74595 +
74596 + return;
74597 +}
74598 +
74599 +void
74600 +gr_add_learn_entry(const char *fmt, ...)
74601 +{
74602 + va_list args;
74603 + unsigned int len;
74604 +
74605 + if (!gr_learn_attached)
74606 + return;
74607 +
74608 + spin_lock(&gr_learn_lock);
74609 +
74610 + /* leave a gap at the end so we know when it's "full" but don't have to
74611 + compute the exact length of the string we're trying to append
74612 + */
74613 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
74614 + spin_unlock(&gr_learn_lock);
74615 + wake_up_interruptible(&learn_wait);
74616 + return;
74617 + }
74618 + if (learn_buffer == NULL) {
74619 + spin_unlock(&gr_learn_lock);
74620 + return;
74621 + }
74622 +
74623 + va_start(args, fmt);
74624 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
74625 + va_end(args);
74626 +
74627 + learn_buffer_len += len + 1;
74628 +
74629 + spin_unlock(&gr_learn_lock);
74630 + wake_up_interruptible(&learn_wait);
74631 +
74632 + return;
74633 +}
74634 +
74635 +static int
74636 +open_learn(struct inode *inode, struct file *file)
74637 +{
74638 + if (file->f_mode & FMODE_READ && gr_learn_attached)
74639 + return -EBUSY;
74640 + if (file->f_mode & FMODE_READ) {
74641 + int retval = 0;
74642 + mutex_lock(&gr_learn_user_mutex);
74643 + if (learn_buffer == NULL)
74644 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
74645 + if (learn_buffer_user == NULL)
74646 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
74647 + if (learn_buffer == NULL) {
74648 + retval = -ENOMEM;
74649 + goto out_error;
74650 + }
74651 + if (learn_buffer_user == NULL) {
74652 + retval = -ENOMEM;
74653 + goto out_error;
74654 + }
74655 + learn_buffer_len = 0;
74656 + learn_buffer_user_len = 0;
74657 + gr_learn_attached = 1;
74658 +out_error:
74659 + mutex_unlock(&gr_learn_user_mutex);
74660 + return retval;
74661 + }
74662 + return 0;
74663 +}
74664 +
74665 +static int
74666 +close_learn(struct inode *inode, struct file *file)
74667 +{
74668 + if (file->f_mode & FMODE_READ) {
74669 + char *tmp = NULL;
74670 + mutex_lock(&gr_learn_user_mutex);
74671 + spin_lock(&gr_learn_lock);
74672 + tmp = learn_buffer;
74673 + learn_buffer = NULL;
74674 + spin_unlock(&gr_learn_lock);
74675 + if (tmp)
74676 + vfree(tmp);
74677 + if (learn_buffer_user != NULL) {
74678 + vfree(learn_buffer_user);
74679 + learn_buffer_user = NULL;
74680 + }
74681 + learn_buffer_len = 0;
74682 + learn_buffer_user_len = 0;
74683 + gr_learn_attached = 0;
74684 + mutex_unlock(&gr_learn_user_mutex);
74685 + }
74686 +
74687 + return 0;
74688 +}
74689 +
74690 +const struct file_operations grsec_fops = {
74691 + .read = read_learn,
74692 + .write = write_grsec_handler,
74693 + .open = open_learn,
74694 + .release = close_learn,
74695 + .poll = poll_learn,
74696 +};
74697 diff --git a/grsecurity/gracl_policy.c b/grsecurity/gracl_policy.c
74698 new file mode 100644
74699 index 0000000..3f8ade0
74700 --- /dev/null
74701 +++ b/grsecurity/gracl_policy.c
74702 @@ -0,0 +1,1782 @@
74703 +#include <linux/kernel.h>
74704 +#include <linux/module.h>
74705 +#include <linux/sched.h>
74706 +#include <linux/mm.h>
74707 +#include <linux/file.h>
74708 +#include <linux/fs.h>
74709 +#include <linux/namei.h>
74710 +#include <linux/mount.h>
74711 +#include <linux/tty.h>
74712 +#include <linux/proc_fs.h>
74713 +#include <linux/lglock.h>
74714 +#include <linux/slab.h>
74715 +#include <linux/vmalloc.h>
74716 +#include <linux/types.h>
74717 +#include <linux/sysctl.h>
74718 +#include <linux/netdevice.h>
74719 +#include <linux/ptrace.h>
74720 +#include <linux/gracl.h>
74721 +#include <linux/gralloc.h>
74722 +#include <linux/security.h>
74723 +#include <linux/grinternal.h>
74724 +#include <linux/pid_namespace.h>
74725 +#include <linux/stop_machine.h>
74726 +#include <linux/fdtable.h>
74727 +#include <linux/percpu.h>
74728 +#include <linux/lglock.h>
74729 +#include <linux/hugetlb.h>
74730 +#include <linux/posix-timers.h>
74731 +#include "../fs/mount.h"
74732 +
74733 +#include <asm/uaccess.h>
74734 +#include <asm/errno.h>
74735 +#include <asm/mman.h>
74736 +
74737 +extern struct gr_policy_state *polstate;
74738 +
74739 +#define FOR_EACH_ROLE_START(role) \
74740 + role = polstate->role_list; \
74741 + while (role) {
74742 +
74743 +#define FOR_EACH_ROLE_END(role) \
74744 + role = role->prev; \
74745 + }
74746 +
74747 +struct path gr_real_root;
74748 +
74749 +extern struct gr_alloc_state *current_alloc_state;
74750 +
74751 +u16 acl_sp_role_value;
74752 +
74753 +static DEFINE_MUTEX(gr_dev_mutex);
74754 +
74755 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
74756 +extern void gr_clear_learn_entries(void);
74757 +
74758 +struct gr_arg *gr_usermode __read_only;
74759 +unsigned char *gr_system_salt __read_only;
74760 +unsigned char *gr_system_sum __read_only;
74761 +
74762 +static unsigned int gr_auth_attempts = 0;
74763 +static unsigned long gr_auth_expires = 0UL;
74764 +
74765 +struct acl_object_label *fakefs_obj_rw;
74766 +struct acl_object_label *fakefs_obj_rwx;
74767 +
74768 +extern int gr_init_uidset(void);
74769 +extern void gr_free_uidset(void);
74770 +extern void gr_remove_uid(uid_t uid);
74771 +extern int gr_find_uid(uid_t uid);
74772 +
74773 +extern struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename);
74774 +extern void __gr_apply_subject_to_task(struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj);
74775 +extern int gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb);
74776 +extern void __insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry);
74777 +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);
74778 +extern void insert_acl_obj_label(struct acl_object_label *obj, struct acl_subject_label *subj);
74779 +extern void insert_acl_subj_label(struct acl_subject_label *obj, struct acl_role_label *role);
74780 +extern struct name_entry * __lookup_name_entry(const struct gr_policy_state *state, const char *name);
74781 +extern char *gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt);
74782 +extern struct acl_subject_label *lookup_acl_subj_label(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
74783 +extern struct acl_subject_label *lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
74784 +extern void assign_special_role(const char *rolename);
74785 +extern struct acl_subject_label *chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt, const struct acl_role_label *role);
74786 +extern int gr_rbac_disable(void *unused);
74787 +extern void gr_enable_rbac_system(void);
74788 +
74789 +static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
74790 +{
74791 + if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
74792 + return -EFAULT;
74793 +
74794 + return 0;
74795 +}
74796 +
74797 +static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
74798 +{
74799 + if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
74800 + return -EFAULT;
74801 +
74802 + return 0;
74803 +}
74804 +
74805 +static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
74806 +{
74807 + if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
74808 + return -EFAULT;
74809 +
74810 + return 0;
74811 +}
74812 +
74813 +static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
74814 +{
74815 + if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
74816 + return -EFAULT;
74817 +
74818 + return 0;
74819 +}
74820 +
74821 +static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
74822 +{
74823 + if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
74824 + return -EFAULT;
74825 +
74826 + return 0;
74827 +}
74828 +
74829 +static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
74830 +{
74831 + if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
74832 + return -EFAULT;
74833 +
74834 + return 0;
74835 +}
74836 +
74837 +static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
74838 +{
74839 + if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
74840 + return -EFAULT;
74841 +
74842 + return 0;
74843 +}
74844 +
74845 +static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
74846 +{
74847 + if (copy_from_user(trans, userp, sizeof(struct role_transition)))
74848 + return -EFAULT;
74849 +
74850 + return 0;
74851 +}
74852 +
74853 +int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
74854 +{
74855 + if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
74856 + return -EFAULT;
74857 +
74858 + return 0;
74859 +}
74860 +
74861 +static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
74862 +{
74863 + if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
74864 + return -EFAULT;
74865 +
74866 + if (((uwrap->version != GRSECURITY_VERSION) &&
74867 + (uwrap->version != 0x2901)) ||
74868 + (uwrap->size != sizeof(struct gr_arg)))
74869 + return -EINVAL;
74870 +
74871 + return 0;
74872 +}
74873 +
74874 +static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
74875 +{
74876 + if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
74877 + return -EFAULT;
74878 +
74879 + return 0;
74880 +}
74881 +
74882 +static size_t get_gr_arg_wrapper_size_normal(void)
74883 +{
74884 + return sizeof(struct gr_arg_wrapper);
74885 +}
74886 +
74887 +#ifdef CONFIG_COMPAT
74888 +extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
74889 +extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
74890 +extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
74891 +extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
74892 +extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
74893 +extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
74894 +extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
74895 +extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
74896 +extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
74897 +extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
74898 +extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
74899 +extern size_t get_gr_arg_wrapper_size_compat(void);
74900 +
74901 +int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
74902 +int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
74903 +int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
74904 +int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
74905 +int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
74906 +int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
74907 +int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
74908 +int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
74909 +int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
74910 +int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
74911 +int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
74912 +size_t (* get_gr_arg_wrapper_size)(void) __read_only;
74913 +
74914 +#else
74915 +#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
74916 +#define copy_gr_arg copy_gr_arg_normal
74917 +#define copy_gr_hash_struct copy_gr_hash_struct_normal
74918 +#define copy_acl_object_label copy_acl_object_label_normal
74919 +#define copy_acl_subject_label copy_acl_subject_label_normal
74920 +#define copy_acl_role_label copy_acl_role_label_normal
74921 +#define copy_acl_ip_label copy_acl_ip_label_normal
74922 +#define copy_pointer_from_array copy_pointer_from_array_normal
74923 +#define copy_sprole_pw copy_sprole_pw_normal
74924 +#define copy_role_transition copy_role_transition_normal
74925 +#define copy_role_allowed_ip copy_role_allowed_ip_normal
74926 +#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
74927 +#endif
74928 +
74929 +static struct acl_subject_label *
74930 +lookup_subject_map(const struct acl_subject_label *userp)
74931 +{
74932 + unsigned int index = gr_shash(userp, polstate->subj_map_set.s_size);
74933 + struct subject_map *match;
74934 +
74935 + match = polstate->subj_map_set.s_hash[index];
74936 +
74937 + while (match && match->user != userp)
74938 + match = match->next;
74939 +
74940 + if (match != NULL)
74941 + return match->kernel;
74942 + else
74943 + return NULL;
74944 +}
74945 +
74946 +static void
74947 +insert_subj_map_entry(struct subject_map *subjmap)
74948 +{
74949 + unsigned int index = gr_shash(subjmap->user, polstate->subj_map_set.s_size);
74950 + struct subject_map **curr;
74951 +
74952 + subjmap->prev = NULL;
74953 +
74954 + curr = &polstate->subj_map_set.s_hash[index];
74955 + if (*curr != NULL)
74956 + (*curr)->prev = subjmap;
74957 +
74958 + subjmap->next = *curr;
74959 + *curr = subjmap;
74960 +
74961 + return;
74962 +}
74963 +
74964 +static void
74965 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
74966 +{
74967 + unsigned int index =
74968 + gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), polstate->acl_role_set.r_size);
74969 + struct acl_role_label **curr;
74970 + struct acl_role_label *tmp, *tmp2;
74971 +
74972 + curr = &polstate->acl_role_set.r_hash[index];
74973 +
74974 + /* simple case, slot is empty, just set it to our role */
74975 + if (*curr == NULL) {
74976 + *curr = role;
74977 + } else {
74978 + /* example:
74979 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
74980 + 2 -> 3
74981 + */
74982 + /* first check to see if we can already be reached via this slot */
74983 + tmp = *curr;
74984 + while (tmp && tmp != role)
74985 + tmp = tmp->next;
74986 + if (tmp == role) {
74987 + /* we don't need to add ourselves to this slot's chain */
74988 + return;
74989 + }
74990 + /* we need to add ourselves to this chain, two cases */
74991 + if (role->next == NULL) {
74992 + /* simple case, append the current chain to our role */
74993 + role->next = *curr;
74994 + *curr = role;
74995 + } else {
74996 + /* 1 -> 2 -> 3 -> 4
74997 + 2 -> 3 -> 4
74998 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
74999 + */
75000 + /* trickier case: walk our role's chain until we find
75001 + the role for the start of the current slot's chain */
75002 + tmp = role;
75003 + tmp2 = *curr;
75004 + while (tmp->next && tmp->next != tmp2)
75005 + tmp = tmp->next;
75006 + if (tmp->next == tmp2) {
75007 + /* from example above, we found 3, so just
75008 + replace this slot's chain with ours */
75009 + *curr = role;
75010 + } else {
75011 + /* we didn't find a subset of our role's chain
75012 + in the current slot's chain, so append their
75013 + chain to ours, and set us as the first role in
75014 + the slot's chain
75015 +
75016 + we could fold this case with the case above,
75017 + but making it explicit for clarity
75018 + */
75019 + tmp->next = tmp2;
75020 + *curr = role;
75021 + }
75022 + }
75023 + }
75024 +
75025 + return;
75026 +}
75027 +
75028 +static void
75029 +insert_acl_role_label(struct acl_role_label *role)
75030 +{
75031 + int i;
75032 +
75033 + if (polstate->role_list == NULL) {
75034 + polstate->role_list = role;
75035 + role->prev = NULL;
75036 + } else {
75037 + role->prev = polstate->role_list;
75038 + polstate->role_list = role;
75039 + }
75040 +
75041 + /* used for hash chains */
75042 + role->next = NULL;
75043 +
75044 + if (role->roletype & GR_ROLE_DOMAIN) {
75045 + for (i = 0; i < role->domain_child_num; i++)
75046 + __insert_acl_role_label(role, role->domain_children[i]);
75047 + } else
75048 + __insert_acl_role_label(role, role->uidgid);
75049 +}
75050 +
75051 +static int
75052 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
75053 +{
75054 + struct name_entry **curr, *nentry;
75055 + struct inodev_entry *ientry;
75056 + unsigned int len = strlen(name);
75057 + unsigned int key = full_name_hash(name, len);
75058 + unsigned int index = key % polstate->name_set.n_size;
75059 +
75060 + curr = &polstate->name_set.n_hash[index];
75061 +
75062 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
75063 + curr = &((*curr)->next);
75064 +
75065 + if (*curr != NULL)
75066 + return 1;
75067 +
75068 + nentry = acl_alloc(sizeof (struct name_entry));
75069 + if (nentry == NULL)
75070 + return 0;
75071 + ientry = acl_alloc(sizeof (struct inodev_entry));
75072 + if (ientry == NULL)
75073 + return 0;
75074 + ientry->nentry = nentry;
75075 +
75076 + nentry->key = key;
75077 + nentry->name = name;
75078 + nentry->inode = inode;
75079 + nentry->device = device;
75080 + nentry->len = len;
75081 + nentry->deleted = deleted;
75082 +
75083 + nentry->prev = NULL;
75084 + curr = &polstate->name_set.n_hash[index];
75085 + if (*curr != NULL)
75086 + (*curr)->prev = nentry;
75087 + nentry->next = *curr;
75088 + *curr = nentry;
75089 +
75090 + /* insert us into the table searchable by inode/dev */
75091 + __insert_inodev_entry(polstate, ientry);
75092 +
75093 + return 1;
75094 +}
75095 +
75096 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
75097 +
75098 +static void *
75099 +create_table(__u32 * len, int elementsize)
75100 +{
75101 + unsigned int table_sizes[] = {
75102 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
75103 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
75104 + 4194301, 8388593, 16777213, 33554393, 67108859
75105 + };
75106 + void *newtable = NULL;
75107 + unsigned int pwr = 0;
75108 +
75109 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
75110 + table_sizes[pwr] <= *len)
75111 + pwr++;
75112 +
75113 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
75114 + return newtable;
75115 +
75116 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
75117 + newtable =
75118 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
75119 + else
75120 + newtable = vmalloc(table_sizes[pwr] * elementsize);
75121 +
75122 + *len = table_sizes[pwr];
75123 +
75124 + return newtable;
75125 +}
75126 +
75127 +static int
75128 +init_variables(const struct gr_arg *arg, bool reload)
75129 +{
75130 + struct task_struct *reaper = init_pid_ns.child_reaper;
75131 + unsigned int stacksize;
75132 +
75133 + polstate->subj_map_set.s_size = arg->role_db.num_subjects;
75134 + polstate->acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
75135 + polstate->name_set.n_size = arg->role_db.num_objects;
75136 + polstate->inodev_set.i_size = arg->role_db.num_objects;
75137 +
75138 + if (!polstate->subj_map_set.s_size || !polstate->acl_role_set.r_size ||
75139 + !polstate->name_set.n_size || !polstate->inodev_set.i_size)
75140 + return 1;
75141 +
75142 + if (!reload) {
75143 + if (!gr_init_uidset())
75144 + return 1;
75145 + }
75146 +
75147 + /* set up the stack that holds allocation info */
75148 +
75149 + stacksize = arg->role_db.num_pointers + 5;
75150 +
75151 + if (!acl_alloc_stack_init(stacksize))
75152 + return 1;
75153 +
75154 + if (!reload) {
75155 + /* grab reference for the real root dentry and vfsmount */
75156 + get_fs_root(reaper->fs, &gr_real_root);
75157 +
75158 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
75159 + 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);
75160 +#endif
75161 +
75162 + fakefs_obj_rw = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
75163 + if (fakefs_obj_rw == NULL)
75164 + return 1;
75165 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
75166 +
75167 + fakefs_obj_rwx = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
75168 + if (fakefs_obj_rwx == NULL)
75169 + return 1;
75170 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
75171 + }
75172 +
75173 + polstate->subj_map_set.s_hash =
75174 + (struct subject_map **) create_table(&polstate->subj_map_set.s_size, sizeof(void *));
75175 + polstate->acl_role_set.r_hash =
75176 + (struct acl_role_label **) create_table(&polstate->acl_role_set.r_size, sizeof(void *));
75177 + polstate->name_set.n_hash = (struct name_entry **) create_table(&polstate->name_set.n_size, sizeof(void *));
75178 + polstate->inodev_set.i_hash =
75179 + (struct inodev_entry **) create_table(&polstate->inodev_set.i_size, sizeof(void *));
75180 +
75181 + if (!polstate->subj_map_set.s_hash || !polstate->acl_role_set.r_hash ||
75182 + !polstate->name_set.n_hash || !polstate->inodev_set.i_hash)
75183 + return 1;
75184 +
75185 + memset(polstate->subj_map_set.s_hash, 0,
75186 + sizeof(struct subject_map *) * polstate->subj_map_set.s_size);
75187 + memset(polstate->acl_role_set.r_hash, 0,
75188 + sizeof (struct acl_role_label *) * polstate->acl_role_set.r_size);
75189 + memset(polstate->name_set.n_hash, 0,
75190 + sizeof (struct name_entry *) * polstate->name_set.n_size);
75191 + memset(polstate->inodev_set.i_hash, 0,
75192 + sizeof (struct inodev_entry *) * polstate->inodev_set.i_size);
75193 +
75194 + return 0;
75195 +}
75196 +
75197 +/* free information not needed after startup
75198 + currently contains user->kernel pointer mappings for subjects
75199 +*/
75200 +
75201 +static void
75202 +free_init_variables(void)
75203 +{
75204 + __u32 i;
75205 +
75206 + if (polstate->subj_map_set.s_hash) {
75207 + for (i = 0; i < polstate->subj_map_set.s_size; i++) {
75208 + if (polstate->subj_map_set.s_hash[i]) {
75209 + kfree(polstate->subj_map_set.s_hash[i]);
75210 + polstate->subj_map_set.s_hash[i] = NULL;
75211 + }
75212 + }
75213 +
75214 + if ((polstate->subj_map_set.s_size * sizeof (struct subject_map *)) <=
75215 + PAGE_SIZE)
75216 + kfree(polstate->subj_map_set.s_hash);
75217 + else
75218 + vfree(polstate->subj_map_set.s_hash);
75219 + }
75220 +
75221 + return;
75222 +}
75223 +
75224 +static void
75225 +free_variables(bool reload)
75226 +{
75227 + struct acl_subject_label *s;
75228 + struct acl_role_label *r;
75229 + struct task_struct *task, *task2;
75230 + unsigned int x;
75231 +
75232 + if (!reload) {
75233 + gr_clear_learn_entries();
75234 +
75235 + read_lock(&tasklist_lock);
75236 + do_each_thread(task2, task) {
75237 + task->acl_sp_role = 0;
75238 + task->acl_role_id = 0;
75239 + task->inherited = 0;
75240 + task->acl = NULL;
75241 + task->role = NULL;
75242 + } while_each_thread(task2, task);
75243 + read_unlock(&tasklist_lock);
75244 +
75245 + kfree(fakefs_obj_rw);
75246 + fakefs_obj_rw = NULL;
75247 + kfree(fakefs_obj_rwx);
75248 + fakefs_obj_rwx = NULL;
75249 +
75250 + /* release the reference to the real root dentry and vfsmount */
75251 + path_put(&gr_real_root);
75252 + memset(&gr_real_root, 0, sizeof(gr_real_root));
75253 + }
75254 +
75255 + /* free all object hash tables */
75256 +
75257 + FOR_EACH_ROLE_START(r)
75258 + if (r->subj_hash == NULL)
75259 + goto next_role;
75260 + FOR_EACH_SUBJECT_START(r, s, x)
75261 + if (s->obj_hash == NULL)
75262 + break;
75263 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
75264 + kfree(s->obj_hash);
75265 + else
75266 + vfree(s->obj_hash);
75267 + FOR_EACH_SUBJECT_END(s, x)
75268 + FOR_EACH_NESTED_SUBJECT_START(r, s)
75269 + if (s->obj_hash == NULL)
75270 + break;
75271 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
75272 + kfree(s->obj_hash);
75273 + else
75274 + vfree(s->obj_hash);
75275 + FOR_EACH_NESTED_SUBJECT_END(s)
75276 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
75277 + kfree(r->subj_hash);
75278 + else
75279 + vfree(r->subj_hash);
75280 + r->subj_hash = NULL;
75281 +next_role:
75282 + FOR_EACH_ROLE_END(r)
75283 +
75284 + acl_free_all();
75285 +
75286 + if (polstate->acl_role_set.r_hash) {
75287 + if ((polstate->acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
75288 + PAGE_SIZE)
75289 + kfree(polstate->acl_role_set.r_hash);
75290 + else
75291 + vfree(polstate->acl_role_set.r_hash);
75292 + }
75293 + if (polstate->name_set.n_hash) {
75294 + if ((polstate->name_set.n_size * sizeof (struct name_entry *)) <=
75295 + PAGE_SIZE)
75296 + kfree(polstate->name_set.n_hash);
75297 + else
75298 + vfree(polstate->name_set.n_hash);
75299 + }
75300 +
75301 + if (polstate->inodev_set.i_hash) {
75302 + if ((polstate->inodev_set.i_size * sizeof (struct inodev_entry *)) <=
75303 + PAGE_SIZE)
75304 + kfree(polstate->inodev_set.i_hash);
75305 + else
75306 + vfree(polstate->inodev_set.i_hash);
75307 + }
75308 +
75309 + if (!reload)
75310 + gr_free_uidset();
75311 +
75312 + memset(&polstate->name_set, 0, sizeof (struct name_db));
75313 + memset(&polstate->inodev_set, 0, sizeof (struct inodev_db));
75314 + memset(&polstate->acl_role_set, 0, sizeof (struct acl_role_db));
75315 + memset(&polstate->subj_map_set, 0, sizeof (struct acl_subj_map_db));
75316 +
75317 + polstate->default_role = NULL;
75318 + polstate->kernel_role = NULL;
75319 + polstate->role_list = NULL;
75320 +
75321 + return;
75322 +}
75323 +
75324 +static struct acl_subject_label *
75325 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
75326 +
75327 +static int alloc_and_copy_string(char **name, unsigned int maxlen)
75328 +{
75329 + unsigned int len = strnlen_user(*name, maxlen);
75330 + char *tmp;
75331 +
75332 + if (!len || len >= maxlen)
75333 + return -EINVAL;
75334 +
75335 + if ((tmp = (char *) acl_alloc(len)) == NULL)
75336 + return -ENOMEM;
75337 +
75338 + if (copy_from_user(tmp, *name, len))
75339 + return -EFAULT;
75340 +
75341 + tmp[len-1] = '\0';
75342 + *name = tmp;
75343 +
75344 + return 0;
75345 +}
75346 +
75347 +static int
75348 +copy_user_glob(struct acl_object_label *obj)
75349 +{
75350 + struct acl_object_label *g_tmp, **guser;
75351 + int error;
75352 +
75353 + if (obj->globbed == NULL)
75354 + return 0;
75355 +
75356 + guser = &obj->globbed;
75357 + while (*guser) {
75358 + g_tmp = (struct acl_object_label *)
75359 + acl_alloc(sizeof (struct acl_object_label));
75360 + if (g_tmp == NULL)
75361 + return -ENOMEM;
75362 +
75363 + if (copy_acl_object_label(g_tmp, *guser))
75364 + return -EFAULT;
75365 +
75366 + error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
75367 + if (error)
75368 + return error;
75369 +
75370 + *guser = g_tmp;
75371 + guser = &(g_tmp->next);
75372 + }
75373 +
75374 + return 0;
75375 +}
75376 +
75377 +static int
75378 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
75379 + struct acl_role_label *role)
75380 +{
75381 + struct acl_object_label *o_tmp;
75382 + int ret;
75383 +
75384 + while (userp) {
75385 + if ((o_tmp = (struct acl_object_label *)
75386 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
75387 + return -ENOMEM;
75388 +
75389 + if (copy_acl_object_label(o_tmp, userp))
75390 + return -EFAULT;
75391 +
75392 + userp = o_tmp->prev;
75393 +
75394 + ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
75395 + if (ret)
75396 + return ret;
75397 +
75398 + insert_acl_obj_label(o_tmp, subj);
75399 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
75400 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
75401 + return -ENOMEM;
75402 +
75403 + ret = copy_user_glob(o_tmp);
75404 + if (ret)
75405 + return ret;
75406 +
75407 + if (o_tmp->nested) {
75408 + int already_copied;
75409 +
75410 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
75411 + if (IS_ERR(o_tmp->nested))
75412 + return PTR_ERR(o_tmp->nested);
75413 +
75414 + /* insert into nested subject list if we haven't copied this one yet
75415 + to prevent duplicate entries */
75416 + if (!already_copied) {
75417 + o_tmp->nested->next = role->hash->first;
75418 + role->hash->first = o_tmp->nested;
75419 + }
75420 + }
75421 + }
75422 +
75423 + return 0;
75424 +}
75425 +
75426 +static __u32
75427 +count_user_subjs(struct acl_subject_label *userp)
75428 +{
75429 + struct acl_subject_label s_tmp;
75430 + __u32 num = 0;
75431 +
75432 + while (userp) {
75433 + if (copy_acl_subject_label(&s_tmp, userp))
75434 + break;
75435 +
75436 + userp = s_tmp.prev;
75437 + }
75438 +
75439 + return num;
75440 +}
75441 +
75442 +static int
75443 +copy_user_allowedips(struct acl_role_label *rolep)
75444 +{
75445 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
75446 +
75447 + ruserip = rolep->allowed_ips;
75448 +
75449 + while (ruserip) {
75450 + rlast = rtmp;
75451 +
75452 + if ((rtmp = (struct role_allowed_ip *)
75453 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
75454 + return -ENOMEM;
75455 +
75456 + if (copy_role_allowed_ip(rtmp, ruserip))
75457 + return -EFAULT;
75458 +
75459 + ruserip = rtmp->prev;
75460 +
75461 + if (!rlast) {
75462 + rtmp->prev = NULL;
75463 + rolep->allowed_ips = rtmp;
75464 + } else {
75465 + rlast->next = rtmp;
75466 + rtmp->prev = rlast;
75467 + }
75468 +
75469 + if (!ruserip)
75470 + rtmp->next = NULL;
75471 + }
75472 +
75473 + return 0;
75474 +}
75475 +
75476 +static int
75477 +copy_user_transitions(struct acl_role_label *rolep)
75478 +{
75479 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
75480 + int error;
75481 +
75482 + rusertp = rolep->transitions;
75483 +
75484 + while (rusertp) {
75485 + rlast = rtmp;
75486 +
75487 + if ((rtmp = (struct role_transition *)
75488 + acl_alloc(sizeof (struct role_transition))) == NULL)
75489 + return -ENOMEM;
75490 +
75491 + if (copy_role_transition(rtmp, rusertp))
75492 + return -EFAULT;
75493 +
75494 + rusertp = rtmp->prev;
75495 +
75496 + error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
75497 + if (error)
75498 + return error;
75499 +
75500 + if (!rlast) {
75501 + rtmp->prev = NULL;
75502 + rolep->transitions = rtmp;
75503 + } else {
75504 + rlast->next = rtmp;
75505 + rtmp->prev = rlast;
75506 + }
75507 +
75508 + if (!rusertp)
75509 + rtmp->next = NULL;
75510 + }
75511 +
75512 + return 0;
75513 +}
75514 +
75515 +static __u32 count_user_objs(const struct acl_object_label __user *userp)
75516 +{
75517 + struct acl_object_label o_tmp;
75518 + __u32 num = 0;
75519 +
75520 + while (userp) {
75521 + if (copy_acl_object_label(&o_tmp, userp))
75522 + break;
75523 +
75524 + userp = o_tmp.prev;
75525 + num++;
75526 + }
75527 +
75528 + return num;
75529 +}
75530 +
75531 +static struct acl_subject_label *
75532 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
75533 +{
75534 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
75535 + __u32 num_objs;
75536 + struct acl_ip_label **i_tmp, *i_utmp2;
75537 + struct gr_hash_struct ghash;
75538 + struct subject_map *subjmap;
75539 + unsigned int i_num;
75540 + int err;
75541 +
75542 + if (already_copied != NULL)
75543 + *already_copied = 0;
75544 +
75545 + s_tmp = lookup_subject_map(userp);
75546 +
75547 + /* we've already copied this subject into the kernel, just return
75548 + the reference to it, and don't copy it over again
75549 + */
75550 + if (s_tmp) {
75551 + if (already_copied != NULL)
75552 + *already_copied = 1;
75553 + return(s_tmp);
75554 + }
75555 +
75556 + if ((s_tmp = (struct acl_subject_label *)
75557 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
75558 + return ERR_PTR(-ENOMEM);
75559 +
75560 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
75561 + if (subjmap == NULL)
75562 + return ERR_PTR(-ENOMEM);
75563 +
75564 + subjmap->user = userp;
75565 + subjmap->kernel = s_tmp;
75566 + insert_subj_map_entry(subjmap);
75567 +
75568 + if (copy_acl_subject_label(s_tmp, userp))
75569 + return ERR_PTR(-EFAULT);
75570 +
75571 + err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
75572 + if (err)
75573 + return ERR_PTR(err);
75574 +
75575 + if (!strcmp(s_tmp->filename, "/"))
75576 + role->root_label = s_tmp;
75577 +
75578 + if (copy_gr_hash_struct(&ghash, s_tmp->hash))
75579 + return ERR_PTR(-EFAULT);
75580 +
75581 + /* copy user and group transition tables */
75582 +
75583 + if (s_tmp->user_trans_num) {
75584 + uid_t *uidlist;
75585 +
75586 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
75587 + if (uidlist == NULL)
75588 + return ERR_PTR(-ENOMEM);
75589 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
75590 + return ERR_PTR(-EFAULT);
75591 +
75592 + s_tmp->user_transitions = uidlist;
75593 + }
75594 +
75595 + if (s_tmp->group_trans_num) {
75596 + gid_t *gidlist;
75597 +
75598 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
75599 + if (gidlist == NULL)
75600 + return ERR_PTR(-ENOMEM);
75601 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
75602 + return ERR_PTR(-EFAULT);
75603 +
75604 + s_tmp->group_transitions = gidlist;
75605 + }
75606 +
75607 + /* set up object hash table */
75608 + num_objs = count_user_objs(ghash.first);
75609 +
75610 + s_tmp->obj_hash_size = num_objs;
75611 + s_tmp->obj_hash =
75612 + (struct acl_object_label **)
75613 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
75614 +
75615 + if (!s_tmp->obj_hash)
75616 + return ERR_PTR(-ENOMEM);
75617 +
75618 + memset(s_tmp->obj_hash, 0,
75619 + s_tmp->obj_hash_size *
75620 + sizeof (struct acl_object_label *));
75621 +
75622 + /* add in objects */
75623 + err = copy_user_objs(ghash.first, s_tmp, role);
75624 +
75625 + if (err)
75626 + return ERR_PTR(err);
75627 +
75628 + /* set pointer for parent subject */
75629 + if (s_tmp->parent_subject) {
75630 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
75631 +
75632 + if (IS_ERR(s_tmp2))
75633 + return s_tmp2;
75634 +
75635 + s_tmp->parent_subject = s_tmp2;
75636 + }
75637 +
75638 + /* add in ip acls */
75639 +
75640 + if (!s_tmp->ip_num) {
75641 + s_tmp->ips = NULL;
75642 + goto insert;
75643 + }
75644 +
75645 + i_tmp =
75646 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
75647 + sizeof (struct acl_ip_label *));
75648 +
75649 + if (!i_tmp)
75650 + return ERR_PTR(-ENOMEM);
75651 +
75652 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
75653 + *(i_tmp + i_num) =
75654 + (struct acl_ip_label *)
75655 + acl_alloc(sizeof (struct acl_ip_label));
75656 + if (!*(i_tmp + i_num))
75657 + return ERR_PTR(-ENOMEM);
75658 +
75659 + if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
75660 + return ERR_PTR(-EFAULT);
75661 +
75662 + if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
75663 + return ERR_PTR(-EFAULT);
75664 +
75665 + if ((*(i_tmp + i_num))->iface == NULL)
75666 + continue;
75667 +
75668 + err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
75669 + if (err)
75670 + return ERR_PTR(err);
75671 + }
75672 +
75673 + s_tmp->ips = i_tmp;
75674 +
75675 +insert:
75676 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
75677 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
75678 + return ERR_PTR(-ENOMEM);
75679 +
75680 + return s_tmp;
75681 +}
75682 +
75683 +static int
75684 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
75685 +{
75686 + struct acl_subject_label s_pre;
75687 + struct acl_subject_label * ret;
75688 + int err;
75689 +
75690 + while (userp) {
75691 + if (copy_acl_subject_label(&s_pre, userp))
75692 + return -EFAULT;
75693 +
75694 + ret = do_copy_user_subj(userp, role, NULL);
75695 +
75696 + err = PTR_ERR(ret);
75697 + if (IS_ERR(ret))
75698 + return err;
75699 +
75700 + insert_acl_subj_label(ret, role);
75701 +
75702 + userp = s_pre.prev;
75703 + }
75704 +
75705 + return 0;
75706 +}
75707 +
75708 +static int
75709 +copy_user_acl(struct gr_arg *arg)
75710 +{
75711 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
75712 + struct acl_subject_label *subj_list;
75713 + struct sprole_pw *sptmp;
75714 + struct gr_hash_struct *ghash;
75715 + uid_t *domainlist;
75716 + unsigned int r_num;
75717 + int err = 0;
75718 + __u16 i;
75719 + __u32 num_subjs;
75720 +
75721 + /* we need a default and kernel role */
75722 + if (arg->role_db.num_roles < 2)
75723 + return -EINVAL;
75724 +
75725 + /* copy special role authentication info from userspace */
75726 +
75727 + polstate->num_sprole_pws = arg->num_sprole_pws;
75728 + polstate->acl_special_roles = (struct sprole_pw **) acl_alloc_num(polstate->num_sprole_pws, sizeof(struct sprole_pw *));
75729 +
75730 + if (!polstate->acl_special_roles && polstate->num_sprole_pws)
75731 + return -ENOMEM;
75732 +
75733 + for (i = 0; i < polstate->num_sprole_pws; i++) {
75734 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
75735 + if (!sptmp)
75736 + return -ENOMEM;
75737 + if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
75738 + return -EFAULT;
75739 +
75740 + err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
75741 + if (err)
75742 + return err;
75743 +
75744 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
75745 + printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
75746 +#endif
75747 +
75748 + polstate->acl_special_roles[i] = sptmp;
75749 + }
75750 +
75751 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
75752 +
75753 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
75754 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
75755 +
75756 + if (!r_tmp)
75757 + return -ENOMEM;
75758 +
75759 + if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
75760 + return -EFAULT;
75761 +
75762 + if (copy_acl_role_label(r_tmp, r_utmp2))
75763 + return -EFAULT;
75764 +
75765 + err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
75766 + if (err)
75767 + return err;
75768 +
75769 + if (!strcmp(r_tmp->rolename, "default")
75770 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
75771 + polstate->default_role = r_tmp;
75772 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
75773 + polstate->kernel_role = r_tmp;
75774 + }
75775 +
75776 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
75777 + return -ENOMEM;
75778 +
75779 + if (copy_gr_hash_struct(ghash, r_tmp->hash))
75780 + return -EFAULT;
75781 +
75782 + r_tmp->hash = ghash;
75783 +
75784 + num_subjs = count_user_subjs(r_tmp->hash->first);
75785 +
75786 + r_tmp->subj_hash_size = num_subjs;
75787 + r_tmp->subj_hash =
75788 + (struct acl_subject_label **)
75789 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
75790 +
75791 + if (!r_tmp->subj_hash)
75792 + return -ENOMEM;
75793 +
75794 + err = copy_user_allowedips(r_tmp);
75795 + if (err)
75796 + return err;
75797 +
75798 + /* copy domain info */
75799 + if (r_tmp->domain_children != NULL) {
75800 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
75801 + if (domainlist == NULL)
75802 + return -ENOMEM;
75803 +
75804 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
75805 + return -EFAULT;
75806 +
75807 + r_tmp->domain_children = domainlist;
75808 + }
75809 +
75810 + err = copy_user_transitions(r_tmp);
75811 + if (err)
75812 + return err;
75813 +
75814 + memset(r_tmp->subj_hash, 0,
75815 + r_tmp->subj_hash_size *
75816 + sizeof (struct acl_subject_label *));
75817 +
75818 + /* acquire the list of subjects, then NULL out
75819 + the list prior to parsing the subjects for this role,
75820 + as during this parsing the list is replaced with a list
75821 + of *nested* subjects for the role
75822 + */
75823 + subj_list = r_tmp->hash->first;
75824 +
75825 + /* set nested subject list to null */
75826 + r_tmp->hash->first = NULL;
75827 +
75828 + err = copy_user_subjs(subj_list, r_tmp);
75829 +
75830 + if (err)
75831 + return err;
75832 +
75833 + insert_acl_role_label(r_tmp);
75834 + }
75835 +
75836 + if (polstate->default_role == NULL || polstate->kernel_role == NULL)
75837 + return -EINVAL;
75838 +
75839 + return err;
75840 +}
75841 +
75842 +static int gracl_reload_apply_policies(void *reload)
75843 +{
75844 + struct gr_reload_state *reload_state = (struct gr_reload_state *)reload;
75845 + struct task_struct *task, *task2;
75846 + struct acl_role_label *role, *rtmp;
75847 + struct acl_subject_label *subj;
75848 + const struct cred *cred;
75849 + int role_applied;
75850 + int ret = 0;
75851 +
75852 + memcpy(&reload_state->oldpolicy, reload_state->oldpolicy_ptr, sizeof(struct gr_policy_state));
75853 + memcpy(&reload_state->oldalloc, reload_state->oldalloc_ptr, sizeof(struct gr_alloc_state));
75854 +
75855 + /* first make sure we'll be able to apply the new policy cleanly */
75856 + do_each_thread(task2, task) {
75857 + if (task->exec_file == NULL)
75858 + continue;
75859 + role_applied = 0;
75860 + if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
75861 + /* preserve special roles */
75862 + FOR_EACH_ROLE_START(role)
75863 + if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
75864 + rtmp = task->role;
75865 + task->role = role;
75866 + role_applied = 1;
75867 + break;
75868 + }
75869 + FOR_EACH_ROLE_END(role)
75870 + }
75871 + if (!role_applied) {
75872 + cred = __task_cred(task);
75873 + rtmp = task->role;
75874 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
75875 + }
75876 + /* this handles non-nested inherited subjects, nested subjects will still
75877 + be dropped currently */
75878 + subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
75879 + task->tmpacl = __gr_get_subject_for_task(polstate, task, NULL);
75880 + /* change the role back so that we've made no modifications to the policy */
75881 + task->role = rtmp;
75882 +
75883 + if (subj == NULL || task->tmpacl == NULL) {
75884 + ret = -EINVAL;
75885 + goto out;
75886 + }
75887 + } while_each_thread(task2, task);
75888 +
75889 + /* now actually apply the policy */
75890 +
75891 + do_each_thread(task2, task) {
75892 + if (task->exec_file) {
75893 + role_applied = 0;
75894 + if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
75895 + /* preserve special roles */
75896 + FOR_EACH_ROLE_START(role)
75897 + if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
75898 + task->role = role;
75899 + role_applied = 1;
75900 + break;
75901 + }
75902 + FOR_EACH_ROLE_END(role)
75903 + }
75904 + if (!role_applied) {
75905 + cred = __task_cred(task);
75906 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
75907 + }
75908 + /* this handles non-nested inherited subjects, nested subjects will still
75909 + be dropped currently */
75910 + if (!reload_state->oldmode && task->inherited)
75911 + subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
75912 + else {
75913 + /* looked up and tagged to the task previously */
75914 + subj = task->tmpacl;
75915 + }
75916 + /* subj will be non-null */
75917 + __gr_apply_subject_to_task(polstate, task, subj);
75918 + if (reload_state->oldmode) {
75919 + task->acl_role_id = 0;
75920 + task->acl_sp_role = 0;
75921 + task->inherited = 0;
75922 + }
75923 + } else {
75924 + // it's a kernel process
75925 + task->role = polstate->kernel_role;
75926 + task->acl = polstate->kernel_role->root_label;
75927 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
75928 + task->acl->mode &= ~GR_PROCFIND;
75929 +#endif
75930 + }
75931 + } while_each_thread(task2, task);
75932 +
75933 + memcpy(reload_state->oldpolicy_ptr, &reload_state->newpolicy, sizeof(struct gr_policy_state));
75934 + memcpy(reload_state->oldalloc_ptr, &reload_state->newalloc, sizeof(struct gr_alloc_state));
75935 +
75936 +out:
75937 +
75938 + return ret;
75939 +}
75940 +
75941 +static int gracl_reload(struct gr_arg *args, unsigned char oldmode)
75942 +{
75943 + struct gr_reload_state new_reload_state = { };
75944 + int err;
75945 +
75946 + new_reload_state.oldpolicy_ptr = polstate;
75947 + new_reload_state.oldalloc_ptr = current_alloc_state;
75948 + new_reload_state.oldmode = oldmode;
75949 +
75950 + current_alloc_state = &new_reload_state.newalloc;
75951 + polstate = &new_reload_state.newpolicy;
75952 +
75953 + /* everything relevant is now saved off, copy in the new policy */
75954 + if (init_variables(args, true)) {
75955 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
75956 + err = -ENOMEM;
75957 + goto error;
75958 + }
75959 +
75960 + err = copy_user_acl(args);
75961 + free_init_variables();
75962 + if (err)
75963 + goto error;
75964 + /* the new policy is copied in, with the old policy available via saved_state
75965 + first go through applying roles, making sure to preserve special roles
75966 + then apply new subjects, making sure to preserve inherited and nested subjects,
75967 + though currently only inherited subjects will be preserved
75968 + */
75969 + err = stop_machine(gracl_reload_apply_policies, &new_reload_state, NULL);
75970 + if (err)
75971 + goto error;
75972 +
75973 + /* we've now applied the new policy, so restore the old policy state to free it */
75974 + polstate = &new_reload_state.oldpolicy;
75975 + current_alloc_state = &new_reload_state.oldalloc;
75976 + free_variables(true);
75977 +
75978 + /* oldpolicy/oldalloc_ptr point to the new policy/alloc states as they were copied
75979 + to running_polstate/current_alloc_state inside stop_machine
75980 + */
75981 + err = 0;
75982 + goto out;
75983 +error:
75984 + /* on error of loading the new policy, we'll just keep the previous
75985 + policy set around
75986 + */
75987 + free_variables(true);
75988 +
75989 + /* doesn't affect runtime, but maintains consistent state */
75990 +out:
75991 + polstate = new_reload_state.oldpolicy_ptr;
75992 + current_alloc_state = new_reload_state.oldalloc_ptr;
75993 +
75994 + return err;
75995 +}
75996 +
75997 +static int
75998 +gracl_init(struct gr_arg *args)
75999 +{
76000 + int error = 0;
76001 +
76002 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
76003 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
76004 +
76005 + if (init_variables(args, false)) {
76006 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
76007 + error = -ENOMEM;
76008 + goto out;
76009 + }
76010 +
76011 + error = copy_user_acl(args);
76012 + free_init_variables();
76013 + if (error)
76014 + goto out;
76015 +
76016 + error = gr_set_acls(0);
76017 + if (error)
76018 + goto out;
76019 +
76020 + gr_enable_rbac_system();
76021 +
76022 + return 0;
76023 +
76024 +out:
76025 + free_variables(false);
76026 + return error;
76027 +}
76028 +
76029 +static int
76030 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
76031 + unsigned char **sum)
76032 +{
76033 + struct acl_role_label *r;
76034 + struct role_allowed_ip *ipp;
76035 + struct role_transition *trans;
76036 + unsigned int i;
76037 + int found = 0;
76038 + u32 curr_ip = current->signal->curr_ip;
76039 +
76040 + current->signal->saved_ip = curr_ip;
76041 +
76042 + /* check transition table */
76043 +
76044 + for (trans = current->role->transitions; trans; trans = trans->next) {
76045 + if (!strcmp(rolename, trans->rolename)) {
76046 + found = 1;
76047 + break;
76048 + }
76049 + }
76050 +
76051 + if (!found)
76052 + return 0;
76053 +
76054 + /* handle special roles that do not require authentication
76055 + and check ip */
76056 +
76057 + FOR_EACH_ROLE_START(r)
76058 + if (!strcmp(rolename, r->rolename) &&
76059 + (r->roletype & GR_ROLE_SPECIAL)) {
76060 + found = 0;
76061 + if (r->allowed_ips != NULL) {
76062 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
76063 + if ((ntohl(curr_ip) & ipp->netmask) ==
76064 + (ntohl(ipp->addr) & ipp->netmask))
76065 + found = 1;
76066 + }
76067 + } else
76068 + found = 2;
76069 + if (!found)
76070 + return 0;
76071 +
76072 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
76073 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
76074 + *salt = NULL;
76075 + *sum = NULL;
76076 + return 1;
76077 + }
76078 + }
76079 + FOR_EACH_ROLE_END(r)
76080 +
76081 + for (i = 0; i < polstate->num_sprole_pws; i++) {
76082 + if (!strcmp(rolename, polstate->acl_special_roles[i]->rolename)) {
76083 + *salt = polstate->acl_special_roles[i]->salt;
76084 + *sum = polstate->acl_special_roles[i]->sum;
76085 + return 1;
76086 + }
76087 + }
76088 +
76089 + return 0;
76090 +}
76091 +
76092 +int gr_check_secure_terminal(struct task_struct *task)
76093 +{
76094 + struct task_struct *p, *p2, *p3;
76095 + struct files_struct *files;
76096 + struct fdtable *fdt;
76097 + struct file *our_file = NULL, *file;
76098 + int i;
76099 +
76100 + if (task->signal->tty == NULL)
76101 + return 1;
76102 +
76103 + files = get_files_struct(task);
76104 + if (files != NULL) {
76105 + rcu_read_lock();
76106 + fdt = files_fdtable(files);
76107 + for (i=0; i < fdt->max_fds; i++) {
76108 + file = fcheck_files(files, i);
76109 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
76110 + get_file(file);
76111 + our_file = file;
76112 + }
76113 + }
76114 + rcu_read_unlock();
76115 + put_files_struct(files);
76116 + }
76117 +
76118 + if (our_file == NULL)
76119 + return 1;
76120 +
76121 + read_lock(&tasklist_lock);
76122 + do_each_thread(p2, p) {
76123 + files = get_files_struct(p);
76124 + if (files == NULL ||
76125 + (p->signal && p->signal->tty == task->signal->tty)) {
76126 + if (files != NULL)
76127 + put_files_struct(files);
76128 + continue;
76129 + }
76130 + rcu_read_lock();
76131 + fdt = files_fdtable(files);
76132 + for (i=0; i < fdt->max_fds; i++) {
76133 + file = fcheck_files(files, i);
76134 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
76135 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
76136 + p3 = task;
76137 + while (task_pid_nr(p3) > 0) {
76138 + if (p3 == p)
76139 + break;
76140 + p3 = p3->real_parent;
76141 + }
76142 + if (p3 == p)
76143 + break;
76144 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
76145 + gr_handle_alertkill(p);
76146 + rcu_read_unlock();
76147 + put_files_struct(files);
76148 + read_unlock(&tasklist_lock);
76149 + fput(our_file);
76150 + return 0;
76151 + }
76152 + }
76153 + rcu_read_unlock();
76154 + put_files_struct(files);
76155 + } while_each_thread(p2, p);
76156 + read_unlock(&tasklist_lock);
76157 +
76158 + fput(our_file);
76159 + return 1;
76160 +}
76161 +
76162 +ssize_t
76163 +write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
76164 +{
76165 + struct gr_arg_wrapper uwrap;
76166 + unsigned char *sprole_salt = NULL;
76167 + unsigned char *sprole_sum = NULL;
76168 + int error = 0;
76169 + int error2 = 0;
76170 + size_t req_count = 0;
76171 + unsigned char oldmode = 0;
76172 +
76173 + mutex_lock(&gr_dev_mutex);
76174 +
76175 + if (gr_acl_is_enabled() && !(current->acl->mode & GR_KERNELAUTH)) {
76176 + error = -EPERM;
76177 + goto out;
76178 + }
76179 +
76180 +#ifdef CONFIG_COMPAT
76181 + pax_open_kernel();
76182 + if (is_compat_task()) {
76183 + copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
76184 + copy_gr_arg = &copy_gr_arg_compat;
76185 + copy_acl_object_label = &copy_acl_object_label_compat;
76186 + copy_acl_subject_label = &copy_acl_subject_label_compat;
76187 + copy_acl_role_label = &copy_acl_role_label_compat;
76188 + copy_acl_ip_label = &copy_acl_ip_label_compat;
76189 + copy_role_allowed_ip = &copy_role_allowed_ip_compat;
76190 + copy_role_transition = &copy_role_transition_compat;
76191 + copy_sprole_pw = &copy_sprole_pw_compat;
76192 + copy_gr_hash_struct = &copy_gr_hash_struct_compat;
76193 + copy_pointer_from_array = &copy_pointer_from_array_compat;
76194 + get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
76195 + } else {
76196 + copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
76197 + copy_gr_arg = &copy_gr_arg_normal;
76198 + copy_acl_object_label = &copy_acl_object_label_normal;
76199 + copy_acl_subject_label = &copy_acl_subject_label_normal;
76200 + copy_acl_role_label = &copy_acl_role_label_normal;
76201 + copy_acl_ip_label = &copy_acl_ip_label_normal;
76202 + copy_role_allowed_ip = &copy_role_allowed_ip_normal;
76203 + copy_role_transition = &copy_role_transition_normal;
76204 + copy_sprole_pw = &copy_sprole_pw_normal;
76205 + copy_gr_hash_struct = &copy_gr_hash_struct_normal;
76206 + copy_pointer_from_array = &copy_pointer_from_array_normal;
76207 + get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
76208 + }
76209 + pax_close_kernel();
76210 +#endif
76211 +
76212 + req_count = get_gr_arg_wrapper_size();
76213 +
76214 + if (count != req_count) {
76215 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
76216 + error = -EINVAL;
76217 + goto out;
76218 + }
76219 +
76220 +
76221 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
76222 + gr_auth_expires = 0;
76223 + gr_auth_attempts = 0;
76224 + }
76225 +
76226 + error = copy_gr_arg_wrapper(buf, &uwrap);
76227 + if (error)
76228 + goto out;
76229 +
76230 + error = copy_gr_arg(uwrap.arg, gr_usermode);
76231 + if (error)
76232 + goto out;
76233 +
76234 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
76235 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
76236 + time_after(gr_auth_expires, get_seconds())) {
76237 + error = -EBUSY;
76238 + goto out;
76239 + }
76240 +
76241 + /* if non-root trying to do anything other than use a special role,
76242 + do not attempt authentication, do not count towards authentication
76243 + locking
76244 + */
76245 +
76246 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
76247 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
76248 + gr_is_global_nonroot(current_uid())) {
76249 + error = -EPERM;
76250 + goto out;
76251 + }
76252 +
76253 + /* ensure pw and special role name are null terminated */
76254 +
76255 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
76256 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
76257 +
76258 + /* Okay.
76259 + * We have our enough of the argument structure..(we have yet
76260 + * to copy_from_user the tables themselves) . Copy the tables
76261 + * only if we need them, i.e. for loading operations. */
76262 +
76263 + switch (gr_usermode->mode) {
76264 + case GR_STATUS:
76265 + if (gr_acl_is_enabled()) {
76266 + error = 1;
76267 + if (!gr_check_secure_terminal(current))
76268 + error = 3;
76269 + } else
76270 + error = 2;
76271 + goto out;
76272 + case GR_SHUTDOWN:
76273 + if (gr_acl_is_enabled() && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
76274 + stop_machine(gr_rbac_disable, NULL, NULL);
76275 + free_variables(false);
76276 + memset(gr_usermode, 0, sizeof(struct gr_arg));
76277 + memset(gr_system_salt, 0, GR_SALT_LEN);
76278 + memset(gr_system_sum, 0, GR_SHA_LEN);
76279 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
76280 + } else if (gr_acl_is_enabled()) {
76281 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
76282 + error = -EPERM;
76283 + } else {
76284 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
76285 + error = -EAGAIN;
76286 + }
76287 + break;
76288 + case GR_ENABLE:
76289 + if (!gr_acl_is_enabled() && !(error2 = gracl_init(gr_usermode)))
76290 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
76291 + else {
76292 + if (gr_acl_is_enabled())
76293 + error = -EAGAIN;
76294 + else
76295 + error = error2;
76296 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
76297 + }
76298 + break;
76299 + case GR_OLDRELOAD:
76300 + oldmode = 1;
76301 + case GR_RELOAD:
76302 + if (!gr_acl_is_enabled()) {
76303 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
76304 + error = -EAGAIN;
76305 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
76306 + error2 = gracl_reload(gr_usermode, oldmode);
76307 + if (!error2)
76308 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
76309 + else {
76310 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
76311 + error = error2;
76312 + }
76313 + } else {
76314 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
76315 + error = -EPERM;
76316 + }
76317 + break;
76318 + case GR_SEGVMOD:
76319 + if (unlikely(!gr_acl_is_enabled())) {
76320 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
76321 + error = -EAGAIN;
76322 + break;
76323 + }
76324 +
76325 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
76326 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
76327 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
76328 + struct acl_subject_label *segvacl;
76329 + segvacl =
76330 + lookup_acl_subj_label(gr_usermode->segv_inode,
76331 + gr_usermode->segv_device,
76332 + current->role);
76333 + if (segvacl) {
76334 + segvacl->crashes = 0;
76335 + segvacl->expires = 0;
76336 + }
76337 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
76338 + gr_remove_uid(gr_usermode->segv_uid);
76339 + }
76340 + } else {
76341 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
76342 + error = -EPERM;
76343 + }
76344 + break;
76345 + case GR_SPROLE:
76346 + case GR_SPROLEPAM:
76347 + if (unlikely(!gr_acl_is_enabled())) {
76348 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
76349 + error = -EAGAIN;
76350 + break;
76351 + }
76352 +
76353 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
76354 + current->role->expires = 0;
76355 + current->role->auth_attempts = 0;
76356 + }
76357 +
76358 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
76359 + time_after(current->role->expires, get_seconds())) {
76360 + error = -EBUSY;
76361 + goto out;
76362 + }
76363 +
76364 + if (lookup_special_role_auth
76365 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
76366 + && ((!sprole_salt && !sprole_sum)
76367 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
76368 + char *p = "";
76369 + assign_special_role(gr_usermode->sp_role);
76370 + read_lock(&tasklist_lock);
76371 + if (current->real_parent)
76372 + p = current->real_parent->role->rolename;
76373 + read_unlock(&tasklist_lock);
76374 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
76375 + p, acl_sp_role_value);
76376 + } else {
76377 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
76378 + error = -EPERM;
76379 + if(!(current->role->auth_attempts++))
76380 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
76381 +
76382 + goto out;
76383 + }
76384 + break;
76385 + case GR_UNSPROLE:
76386 + if (unlikely(!gr_acl_is_enabled())) {
76387 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
76388 + error = -EAGAIN;
76389 + break;
76390 + }
76391 +
76392 + if (current->role->roletype & GR_ROLE_SPECIAL) {
76393 + char *p = "";
76394 + int i = 0;
76395 +
76396 + read_lock(&tasklist_lock);
76397 + if (current->real_parent) {
76398 + p = current->real_parent->role->rolename;
76399 + i = current->real_parent->acl_role_id;
76400 + }
76401 + read_unlock(&tasklist_lock);
76402 +
76403 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
76404 + gr_set_acls(1);
76405 + } else {
76406 + error = -EPERM;
76407 + goto out;
76408 + }
76409 + break;
76410 + default:
76411 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
76412 + error = -EINVAL;
76413 + break;
76414 + }
76415 +
76416 + if (error != -EPERM)
76417 + goto out;
76418 +
76419 + if(!(gr_auth_attempts++))
76420 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
76421 +
76422 + out:
76423 + mutex_unlock(&gr_dev_mutex);
76424 +
76425 + if (!error)
76426 + error = req_count;
76427 +
76428 + return error;
76429 +}
76430 +
76431 +int
76432 +gr_set_acls(const int type)
76433 +{
76434 + struct task_struct *task, *task2;
76435 + struct acl_role_label *role = current->role;
76436 + struct acl_subject_label *subj;
76437 + __u16 acl_role_id = current->acl_role_id;
76438 + const struct cred *cred;
76439 + int ret;
76440 +
76441 + rcu_read_lock();
76442 + read_lock(&tasklist_lock);
76443 + read_lock(&grsec_exec_file_lock);
76444 + do_each_thread(task2, task) {
76445 + /* check to see if we're called from the exit handler,
76446 + if so, only replace ACLs that have inherited the admin
76447 + ACL */
76448 +
76449 + if (type && (task->role != role ||
76450 + task->acl_role_id != acl_role_id))
76451 + continue;
76452 +
76453 + task->acl_role_id = 0;
76454 + task->acl_sp_role = 0;
76455 + task->inherited = 0;
76456 +
76457 + if (task->exec_file) {
76458 + cred = __task_cred(task);
76459 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
76460 + subj = __gr_get_subject_for_task(polstate, task, NULL);
76461 + if (subj == NULL) {
76462 + ret = -EINVAL;
76463 + read_unlock(&grsec_exec_file_lock);
76464 + read_unlock(&tasklist_lock);
76465 + rcu_read_unlock();
76466 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
76467 + return ret;
76468 + }
76469 + __gr_apply_subject_to_task(polstate, task, subj);
76470 + } else {
76471 + // it's a kernel process
76472 + task->role = polstate->kernel_role;
76473 + task->acl = polstate->kernel_role->root_label;
76474 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
76475 + task->acl->mode &= ~GR_PROCFIND;
76476 +#endif
76477 + }
76478 + } while_each_thread(task2, task);
76479 + read_unlock(&grsec_exec_file_lock);
76480 + read_unlock(&tasklist_lock);
76481 + rcu_read_unlock();
76482 +
76483 + return 0;
76484 +}
76485 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
76486 new file mode 100644
76487 index 0000000..39645c9
76488 --- /dev/null
76489 +++ b/grsecurity/gracl_res.c
76490 @@ -0,0 +1,68 @@
76491 +#include <linux/kernel.h>
76492 +#include <linux/sched.h>
76493 +#include <linux/gracl.h>
76494 +#include <linux/grinternal.h>
76495 +
76496 +static const char *restab_log[] = {
76497 + [RLIMIT_CPU] = "RLIMIT_CPU",
76498 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
76499 + [RLIMIT_DATA] = "RLIMIT_DATA",
76500 + [RLIMIT_STACK] = "RLIMIT_STACK",
76501 + [RLIMIT_CORE] = "RLIMIT_CORE",
76502 + [RLIMIT_RSS] = "RLIMIT_RSS",
76503 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
76504 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
76505 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
76506 + [RLIMIT_AS] = "RLIMIT_AS",
76507 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
76508 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
76509 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
76510 + [RLIMIT_NICE] = "RLIMIT_NICE",
76511 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
76512 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
76513 + [GR_CRASH_RES] = "RLIMIT_CRASH"
76514 +};
76515 +
76516 +void
76517 +gr_log_resource(const struct task_struct *task,
76518 + const int res, const unsigned long wanted, const int gt)
76519 +{
76520 + const struct cred *cred;
76521 + unsigned long rlim;
76522 +
76523 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
76524 + return;
76525 +
76526 + // not yet supported resource
76527 + if (unlikely(!restab_log[res]))
76528 + return;
76529 +
76530 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
76531 + rlim = task_rlimit_max(task, res);
76532 + else
76533 + rlim = task_rlimit(task, res);
76534 +
76535 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
76536 + return;
76537 +
76538 + rcu_read_lock();
76539 + cred = __task_cred(task);
76540 +
76541 + if (res == RLIMIT_NPROC &&
76542 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
76543 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
76544 + goto out_rcu_unlock;
76545 + else if (res == RLIMIT_MEMLOCK &&
76546 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
76547 + goto out_rcu_unlock;
76548 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
76549 + goto out_rcu_unlock;
76550 + rcu_read_unlock();
76551 +
76552 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
76553 +
76554 + return;
76555 +out_rcu_unlock:
76556 + rcu_read_unlock();
76557 + return;
76558 +}
76559 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
76560 new file mode 100644
76561 index 0000000..2040e61
76562 --- /dev/null
76563 +++ b/grsecurity/gracl_segv.c
76564 @@ -0,0 +1,313 @@
76565 +#include <linux/kernel.h>
76566 +#include <linux/mm.h>
76567 +#include <asm/uaccess.h>
76568 +#include <asm/errno.h>
76569 +#include <asm/mman.h>
76570 +#include <net/sock.h>
76571 +#include <linux/file.h>
76572 +#include <linux/fs.h>
76573 +#include <linux/net.h>
76574 +#include <linux/in.h>
76575 +#include <linux/slab.h>
76576 +#include <linux/types.h>
76577 +#include <linux/sched.h>
76578 +#include <linux/timer.h>
76579 +#include <linux/gracl.h>
76580 +#include <linux/grsecurity.h>
76581 +#include <linux/grinternal.h>
76582 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
76583 +#include <linux/magic.h>
76584 +#include <linux/pagemap.h>
76585 +#include "../fs/btrfs/async-thread.h"
76586 +#include "../fs/btrfs/ctree.h"
76587 +#include "../fs/btrfs/btrfs_inode.h"
76588 +#endif
76589 +
76590 +static struct crash_uid *uid_set;
76591 +static unsigned short uid_used;
76592 +static DEFINE_SPINLOCK(gr_uid_lock);
76593 +extern rwlock_t gr_inode_lock;
76594 +extern struct acl_subject_label *
76595 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
76596 + struct acl_role_label *role);
76597 +
76598 +static inline dev_t __get_dev(const struct dentry *dentry)
76599 +{
76600 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
76601 + if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
76602 + return BTRFS_I(dentry->d_inode)->root->anon_dev;
76603 + else
76604 +#endif
76605 + return dentry->d_sb->s_dev;
76606 +}
76607 +
76608 +int
76609 +gr_init_uidset(void)
76610 +{
76611 + uid_set =
76612 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
76613 + uid_used = 0;
76614 +
76615 + return uid_set ? 1 : 0;
76616 +}
76617 +
76618 +void
76619 +gr_free_uidset(void)
76620 +{
76621 + if (uid_set) {
76622 + struct crash_uid *tmpset;
76623 + spin_lock(&gr_uid_lock);
76624 + tmpset = uid_set;
76625 + uid_set = NULL;
76626 + uid_used = 0;
76627 + spin_unlock(&gr_uid_lock);
76628 + if (tmpset)
76629 + kfree(tmpset);
76630 + }
76631 +
76632 + return;
76633 +}
76634 +
76635 +int
76636 +gr_find_uid(const uid_t uid)
76637 +{
76638 + struct crash_uid *tmp = uid_set;
76639 + uid_t buid;
76640 + int low = 0, high = uid_used - 1, mid;
76641 +
76642 + while (high >= low) {
76643 + mid = (low + high) >> 1;
76644 + buid = tmp[mid].uid;
76645 + if (buid == uid)
76646 + return mid;
76647 + if (buid > uid)
76648 + high = mid - 1;
76649 + if (buid < uid)
76650 + low = mid + 1;
76651 + }
76652 +
76653 + return -1;
76654 +}
76655 +
76656 +static __inline__ void
76657 +gr_insertsort(void)
76658 +{
76659 + unsigned short i, j;
76660 + struct crash_uid index;
76661 +
76662 + for (i = 1; i < uid_used; i++) {
76663 + index = uid_set[i];
76664 + j = i;
76665 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
76666 + uid_set[j] = uid_set[j - 1];
76667 + j--;
76668 + }
76669 + uid_set[j] = index;
76670 + }
76671 +
76672 + return;
76673 +}
76674 +
76675 +static __inline__ void
76676 +gr_insert_uid(const kuid_t kuid, const unsigned long expires)
76677 +{
76678 + int loc;
76679 + uid_t uid = GR_GLOBAL_UID(kuid);
76680 +
76681 + if (uid_used == GR_UIDTABLE_MAX)
76682 + return;
76683 +
76684 + loc = gr_find_uid(uid);
76685 +
76686 + if (loc >= 0) {
76687 + uid_set[loc].expires = expires;
76688 + return;
76689 + }
76690 +
76691 + uid_set[uid_used].uid = uid;
76692 + uid_set[uid_used].expires = expires;
76693 + uid_used++;
76694 +
76695 + gr_insertsort();
76696 +
76697 + return;
76698 +}
76699 +
76700 +void
76701 +gr_remove_uid(const unsigned short loc)
76702 +{
76703 + unsigned short i;
76704 +
76705 + for (i = loc + 1; i < uid_used; i++)
76706 + uid_set[i - 1] = uid_set[i];
76707 +
76708 + uid_used--;
76709 +
76710 + return;
76711 +}
76712 +
76713 +int
76714 +gr_check_crash_uid(const kuid_t kuid)
76715 +{
76716 + int loc;
76717 + int ret = 0;
76718 + uid_t uid;
76719 +
76720 + if (unlikely(!gr_acl_is_enabled()))
76721 + return 0;
76722 +
76723 + uid = GR_GLOBAL_UID(kuid);
76724 +
76725 + spin_lock(&gr_uid_lock);
76726 + loc = gr_find_uid(uid);
76727 +
76728 + if (loc < 0)
76729 + goto out_unlock;
76730 +
76731 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
76732 + gr_remove_uid(loc);
76733 + else
76734 + ret = 1;
76735 +
76736 +out_unlock:
76737 + spin_unlock(&gr_uid_lock);
76738 + return ret;
76739 +}
76740 +
76741 +static __inline__ int
76742 +proc_is_setxid(const struct cred *cred)
76743 +{
76744 + if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
76745 + !uid_eq(cred->uid, cred->fsuid))
76746 + return 1;
76747 + if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
76748 + !gid_eq(cred->gid, cred->fsgid))
76749 + return 1;
76750 +
76751 + return 0;
76752 +}
76753 +
76754 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
76755 +
76756 +void
76757 +gr_handle_crash(struct task_struct *task, const int sig)
76758 +{
76759 + struct acl_subject_label *curr;
76760 + struct task_struct *tsk, *tsk2;
76761 + const struct cred *cred;
76762 + const struct cred *cred2;
76763 +
76764 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
76765 + return;
76766 +
76767 + if (unlikely(!gr_acl_is_enabled()))
76768 + return;
76769 +
76770 + curr = task->acl;
76771 +
76772 + if (!(curr->resmask & (1U << GR_CRASH_RES)))
76773 + return;
76774 +
76775 + if (time_before_eq(curr->expires, get_seconds())) {
76776 + curr->expires = 0;
76777 + curr->crashes = 0;
76778 + }
76779 +
76780 + curr->crashes++;
76781 +
76782 + if (!curr->expires)
76783 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
76784 +
76785 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
76786 + time_after(curr->expires, get_seconds())) {
76787 + rcu_read_lock();
76788 + cred = __task_cred(task);
76789 + if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
76790 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
76791 + spin_lock(&gr_uid_lock);
76792 + gr_insert_uid(cred->uid, curr->expires);
76793 + spin_unlock(&gr_uid_lock);
76794 + curr->expires = 0;
76795 + curr->crashes = 0;
76796 + read_lock(&tasklist_lock);
76797 + do_each_thread(tsk2, tsk) {
76798 + cred2 = __task_cred(tsk);
76799 + if (tsk != task && uid_eq(cred2->uid, cred->uid))
76800 + gr_fake_force_sig(SIGKILL, tsk);
76801 + } while_each_thread(tsk2, tsk);
76802 + read_unlock(&tasklist_lock);
76803 + } else {
76804 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
76805 + read_lock(&tasklist_lock);
76806 + read_lock(&grsec_exec_file_lock);
76807 + do_each_thread(tsk2, tsk) {
76808 + if (likely(tsk != task)) {
76809 + // if this thread has the same subject as the one that triggered
76810 + // RES_CRASH and it's the same binary, kill it
76811 + if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
76812 + gr_fake_force_sig(SIGKILL, tsk);
76813 + }
76814 + } while_each_thread(tsk2, tsk);
76815 + read_unlock(&grsec_exec_file_lock);
76816 + read_unlock(&tasklist_lock);
76817 + }
76818 + rcu_read_unlock();
76819 + }
76820 +
76821 + return;
76822 +}
76823 +
76824 +int
76825 +gr_check_crash_exec(const struct file *filp)
76826 +{
76827 + struct acl_subject_label *curr;
76828 +
76829 + if (unlikely(!gr_acl_is_enabled()))
76830 + return 0;
76831 +
76832 + read_lock(&gr_inode_lock);
76833 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
76834 + __get_dev(filp->f_path.dentry),
76835 + current->role);
76836 + read_unlock(&gr_inode_lock);
76837 +
76838 + if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
76839 + (!curr->crashes && !curr->expires))
76840 + return 0;
76841 +
76842 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
76843 + time_after(curr->expires, get_seconds()))
76844 + return 1;
76845 + else if (time_before_eq(curr->expires, get_seconds())) {
76846 + curr->crashes = 0;
76847 + curr->expires = 0;
76848 + }
76849 +
76850 + return 0;
76851 +}
76852 +
76853 +void
76854 +gr_handle_alertkill(struct task_struct *task)
76855 +{
76856 + struct acl_subject_label *curracl;
76857 + __u32 curr_ip;
76858 + struct task_struct *p, *p2;
76859 +
76860 + if (unlikely(!gr_acl_is_enabled()))
76861 + return;
76862 +
76863 + curracl = task->acl;
76864 + curr_ip = task->signal->curr_ip;
76865 +
76866 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
76867 + read_lock(&tasklist_lock);
76868 + do_each_thread(p2, p) {
76869 + if (p->signal->curr_ip == curr_ip)
76870 + gr_fake_force_sig(SIGKILL, p);
76871 + } while_each_thread(p2, p);
76872 + read_unlock(&tasklist_lock);
76873 + } else if (curracl->mode & GR_KILLPROC)
76874 + gr_fake_force_sig(SIGKILL, task);
76875 +
76876 + return;
76877 +}
76878 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
76879 new file mode 100644
76880 index 0000000..6b0c9cc
76881 --- /dev/null
76882 +++ b/grsecurity/gracl_shm.c
76883 @@ -0,0 +1,40 @@
76884 +#include <linux/kernel.h>
76885 +#include <linux/mm.h>
76886 +#include <linux/sched.h>
76887 +#include <linux/file.h>
76888 +#include <linux/ipc.h>
76889 +#include <linux/gracl.h>
76890 +#include <linux/grsecurity.h>
76891 +#include <linux/grinternal.h>
76892 +
76893 +int
76894 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
76895 + const u64 shm_createtime, const kuid_t cuid, const int shmid)
76896 +{
76897 + struct task_struct *task;
76898 +
76899 + if (!gr_acl_is_enabled())
76900 + return 1;
76901 +
76902 + rcu_read_lock();
76903 + read_lock(&tasklist_lock);
76904 +
76905 + task = find_task_by_vpid(shm_cprid);
76906 +
76907 + if (unlikely(!task))
76908 + task = find_task_by_vpid(shm_lapid);
76909 +
76910 + if (unlikely(task && (time_before_eq64(task->start_time, shm_createtime) ||
76911 + (task_pid_nr(task) == shm_lapid)) &&
76912 + (task->acl->mode & GR_PROTSHM) &&
76913 + (task->acl != current->acl))) {
76914 + read_unlock(&tasklist_lock);
76915 + rcu_read_unlock();
76916 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
76917 + return 0;
76918 + }
76919 + read_unlock(&tasklist_lock);
76920 + rcu_read_unlock();
76921 +
76922 + return 1;
76923 +}
76924 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
76925 new file mode 100644
76926 index 0000000..bc0be01
76927 --- /dev/null
76928 +++ b/grsecurity/grsec_chdir.c
76929 @@ -0,0 +1,19 @@
76930 +#include <linux/kernel.h>
76931 +#include <linux/sched.h>
76932 +#include <linux/fs.h>
76933 +#include <linux/file.h>
76934 +#include <linux/grsecurity.h>
76935 +#include <linux/grinternal.h>
76936 +
76937 +void
76938 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
76939 +{
76940 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
76941 + if ((grsec_enable_chdir && grsec_enable_group &&
76942 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
76943 + !grsec_enable_group)) {
76944 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
76945 + }
76946 +#endif
76947 + return;
76948 +}
76949 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
76950 new file mode 100644
76951 index 0000000..6d99cec
76952 --- /dev/null
76953 +++ b/grsecurity/grsec_chroot.c
76954 @@ -0,0 +1,385 @@
76955 +#include <linux/kernel.h>
76956 +#include <linux/module.h>
76957 +#include <linux/sched.h>
76958 +#include <linux/file.h>
76959 +#include <linux/fs.h>
76960 +#include <linux/mount.h>
76961 +#include <linux/types.h>
76962 +#include "../fs/mount.h"
76963 +#include <linux/grsecurity.h>
76964 +#include <linux/grinternal.h>
76965 +
76966 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
76967 +int gr_init_ran;
76968 +#endif
76969 +
76970 +void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
76971 +{
76972 +#ifdef CONFIG_GRKERNSEC
76973 + if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
76974 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
76975 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
76976 + && gr_init_ran
76977 +#endif
76978 + )
76979 + task->gr_is_chrooted = 1;
76980 + else {
76981 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
76982 + if (task_pid_nr(task) == 1 && !gr_init_ran)
76983 + gr_init_ran = 1;
76984 +#endif
76985 + task->gr_is_chrooted = 0;
76986 + }
76987 +
76988 + task->gr_chroot_dentry = path->dentry;
76989 +#endif
76990 + return;
76991 +}
76992 +
76993 +void gr_clear_chroot_entries(struct task_struct *task)
76994 +{
76995 +#ifdef CONFIG_GRKERNSEC
76996 + task->gr_is_chrooted = 0;
76997 + task->gr_chroot_dentry = NULL;
76998 +#endif
76999 + return;
77000 +}
77001 +
77002 +int
77003 +gr_handle_chroot_unix(const pid_t pid)
77004 +{
77005 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
77006 + struct task_struct *p;
77007 +
77008 + if (unlikely(!grsec_enable_chroot_unix))
77009 + return 1;
77010 +
77011 + if (likely(!proc_is_chrooted(current)))
77012 + return 1;
77013 +
77014 + rcu_read_lock();
77015 + read_lock(&tasklist_lock);
77016 + p = find_task_by_vpid_unrestricted(pid);
77017 + if (unlikely(p && !have_same_root(current, p))) {
77018 + read_unlock(&tasklist_lock);
77019 + rcu_read_unlock();
77020 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
77021 + return 0;
77022 + }
77023 + read_unlock(&tasklist_lock);
77024 + rcu_read_unlock();
77025 +#endif
77026 + return 1;
77027 +}
77028 +
77029 +int
77030 +gr_handle_chroot_nice(void)
77031 +{
77032 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
77033 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
77034 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
77035 + return -EPERM;
77036 + }
77037 +#endif
77038 + return 0;
77039 +}
77040 +
77041 +int
77042 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
77043 +{
77044 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
77045 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
77046 + && proc_is_chrooted(current)) {
77047 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
77048 + return -EACCES;
77049 + }
77050 +#endif
77051 + return 0;
77052 +}
77053 +
77054 +int
77055 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
77056 +{
77057 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
77058 + struct task_struct *p;
77059 + int ret = 0;
77060 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
77061 + return ret;
77062 +
77063 + read_lock(&tasklist_lock);
77064 + do_each_pid_task(pid, type, p) {
77065 + if (!have_same_root(current, p)) {
77066 + ret = 1;
77067 + goto out;
77068 + }
77069 + } while_each_pid_task(pid, type, p);
77070 +out:
77071 + read_unlock(&tasklist_lock);
77072 + return ret;
77073 +#endif
77074 + return 0;
77075 +}
77076 +
77077 +int
77078 +gr_pid_is_chrooted(struct task_struct *p)
77079 +{
77080 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
77081 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
77082 + return 0;
77083 +
77084 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
77085 + !have_same_root(current, p)) {
77086 + return 1;
77087 + }
77088 +#endif
77089 + return 0;
77090 +}
77091 +
77092 +EXPORT_SYMBOL_GPL(gr_pid_is_chrooted);
77093 +
77094 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
77095 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
77096 +{
77097 + struct path path, currentroot;
77098 + int ret = 0;
77099 +
77100 + path.dentry = (struct dentry *)u_dentry;
77101 + path.mnt = (struct vfsmount *)u_mnt;
77102 + get_fs_root(current->fs, &currentroot);
77103 + if (path_is_under(&path, &currentroot))
77104 + ret = 1;
77105 + path_put(&currentroot);
77106 +
77107 + return ret;
77108 +}
77109 +#endif
77110 +
77111 +int
77112 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
77113 +{
77114 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
77115 + if (!grsec_enable_chroot_fchdir)
77116 + return 1;
77117 +
77118 + if (!proc_is_chrooted(current))
77119 + return 1;
77120 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
77121 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
77122 + return 0;
77123 + }
77124 +#endif
77125 + return 1;
77126 +}
77127 +
77128 +int
77129 +gr_chroot_fhandle(void)
77130 +{
77131 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
77132 + if (!grsec_enable_chroot_fchdir)
77133 + return 1;
77134 +
77135 + if (!proc_is_chrooted(current))
77136 + return 1;
77137 + else {
77138 + gr_log_noargs(GR_DONT_AUDIT, GR_CHROOT_FHANDLE_MSG);
77139 + return 0;
77140 + }
77141 +#endif
77142 + return 1;
77143 +}
77144 +
77145 +int
77146 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
77147 + const u64 shm_createtime)
77148 +{
77149 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
77150 + struct task_struct *p;
77151 +
77152 + if (unlikely(!grsec_enable_chroot_shmat))
77153 + return 1;
77154 +
77155 + if (likely(!proc_is_chrooted(current)))
77156 + return 1;
77157 +
77158 + rcu_read_lock();
77159 + read_lock(&tasklist_lock);
77160 +
77161 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
77162 + if (time_before_eq64(p->start_time, shm_createtime)) {
77163 + if (have_same_root(current, p)) {
77164 + goto allow;
77165 + } else {
77166 + read_unlock(&tasklist_lock);
77167 + rcu_read_unlock();
77168 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
77169 + return 0;
77170 + }
77171 + }
77172 + /* creator exited, pid reuse, fall through to next check */
77173 + }
77174 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
77175 + if (unlikely(!have_same_root(current, p))) {
77176 + read_unlock(&tasklist_lock);
77177 + rcu_read_unlock();
77178 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
77179 + return 0;
77180 + }
77181 + }
77182 +
77183 +allow:
77184 + read_unlock(&tasklist_lock);
77185 + rcu_read_unlock();
77186 +#endif
77187 + return 1;
77188 +}
77189 +
77190 +void
77191 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
77192 +{
77193 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
77194 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
77195 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
77196 +#endif
77197 + return;
77198 +}
77199 +
77200 +int
77201 +gr_handle_chroot_mknod(const struct dentry *dentry,
77202 + const struct vfsmount *mnt, const int mode)
77203 +{
77204 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
77205 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
77206 + proc_is_chrooted(current)) {
77207 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
77208 + return -EPERM;
77209 + }
77210 +#endif
77211 + return 0;
77212 +}
77213 +
77214 +int
77215 +gr_handle_chroot_mount(const struct dentry *dentry,
77216 + const struct vfsmount *mnt, const char *dev_name)
77217 +{
77218 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
77219 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
77220 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
77221 + return -EPERM;
77222 + }
77223 +#endif
77224 + return 0;
77225 +}
77226 +
77227 +int
77228 +gr_handle_chroot_pivot(void)
77229 +{
77230 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
77231 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
77232 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
77233 + return -EPERM;
77234 + }
77235 +#endif
77236 + return 0;
77237 +}
77238 +
77239 +int
77240 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
77241 +{
77242 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
77243 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
77244 + !gr_is_outside_chroot(dentry, mnt)) {
77245 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
77246 + return -EPERM;
77247 + }
77248 +#endif
77249 + return 0;
77250 +}
77251 +
77252 +extern const char *captab_log[];
77253 +extern int captab_log_entries;
77254 +
77255 +int
77256 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
77257 +{
77258 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
77259 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
77260 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
77261 + if (cap_raised(chroot_caps, cap)) {
77262 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
77263 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
77264 + }
77265 + return 0;
77266 + }
77267 + }
77268 +#endif
77269 + return 1;
77270 +}
77271 +
77272 +int
77273 +gr_chroot_is_capable(const int cap)
77274 +{
77275 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
77276 + return gr_task_chroot_is_capable(current, current_cred(), cap);
77277 +#endif
77278 + return 1;
77279 +}
77280 +
77281 +int
77282 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
77283 +{
77284 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
77285 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
77286 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
77287 + if (cap_raised(chroot_caps, cap)) {
77288 + return 0;
77289 + }
77290 + }
77291 +#endif
77292 + return 1;
77293 +}
77294 +
77295 +int
77296 +gr_chroot_is_capable_nolog(const int cap)
77297 +{
77298 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
77299 + return gr_task_chroot_is_capable_nolog(current, cap);
77300 +#endif
77301 + return 1;
77302 +}
77303 +
77304 +int
77305 +gr_handle_chroot_sysctl(const int op)
77306 +{
77307 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
77308 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
77309 + proc_is_chrooted(current))
77310 + return -EACCES;
77311 +#endif
77312 + return 0;
77313 +}
77314 +
77315 +void
77316 +gr_handle_chroot_chdir(const struct path *path)
77317 +{
77318 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
77319 + if (grsec_enable_chroot_chdir)
77320 + set_fs_pwd(current->fs, path);
77321 +#endif
77322 + return;
77323 +}
77324 +
77325 +int
77326 +gr_handle_chroot_chmod(const struct dentry *dentry,
77327 + const struct vfsmount *mnt, const int mode)
77328 +{
77329 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
77330 + /* allow chmod +s on directories, but not files */
77331 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
77332 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
77333 + proc_is_chrooted(current)) {
77334 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
77335 + return -EPERM;
77336 + }
77337 +#endif
77338 + return 0;
77339 +}
77340 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
77341 new file mode 100644
77342 index 0000000..0f9ac91
77343 --- /dev/null
77344 +++ b/grsecurity/grsec_disabled.c
77345 @@ -0,0 +1,440 @@
77346 +#include <linux/kernel.h>
77347 +#include <linux/module.h>
77348 +#include <linux/sched.h>
77349 +#include <linux/file.h>
77350 +#include <linux/fs.h>
77351 +#include <linux/kdev_t.h>
77352 +#include <linux/net.h>
77353 +#include <linux/in.h>
77354 +#include <linux/ip.h>
77355 +#include <linux/skbuff.h>
77356 +#include <linux/sysctl.h>
77357 +
77358 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
77359 +void
77360 +pax_set_initial_flags(struct linux_binprm *bprm)
77361 +{
77362 + return;
77363 +}
77364 +#endif
77365 +
77366 +#ifdef CONFIG_SYSCTL
77367 +__u32
77368 +gr_handle_sysctl(const struct ctl_table * table, const int op)
77369 +{
77370 + return 0;
77371 +}
77372 +#endif
77373 +
77374 +#ifdef CONFIG_TASKSTATS
77375 +int gr_is_taskstats_denied(int pid)
77376 +{
77377 + return 0;
77378 +}
77379 +#endif
77380 +
77381 +int
77382 +gr_acl_is_enabled(void)
77383 +{
77384 + return 0;
77385 +}
77386 +
77387 +int
77388 +gr_learn_cap(const struct task_struct *task, const struct cred *cred, const int cap)
77389 +{
77390 + return 0;
77391 +}
77392 +
77393 +void
77394 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
77395 +{
77396 + return;
77397 +}
77398 +
77399 +int
77400 +gr_handle_rawio(const struct inode *inode)
77401 +{
77402 + return 0;
77403 +}
77404 +
77405 +void
77406 +gr_acl_handle_psacct(struct task_struct *task, const long code)
77407 +{
77408 + return;
77409 +}
77410 +
77411 +int
77412 +gr_handle_ptrace(struct task_struct *task, const long request)
77413 +{
77414 + return 0;
77415 +}
77416 +
77417 +int
77418 +gr_handle_proc_ptrace(struct task_struct *task)
77419 +{
77420 + return 0;
77421 +}
77422 +
77423 +int
77424 +gr_set_acls(const int type)
77425 +{
77426 + return 0;
77427 +}
77428 +
77429 +int
77430 +gr_check_hidden_task(const struct task_struct *tsk)
77431 +{
77432 + return 0;
77433 +}
77434 +
77435 +int
77436 +gr_check_protected_task(const struct task_struct *task)
77437 +{
77438 + return 0;
77439 +}
77440 +
77441 +int
77442 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
77443 +{
77444 + return 0;
77445 +}
77446 +
77447 +void
77448 +gr_copy_label(struct task_struct *tsk)
77449 +{
77450 + return;
77451 +}
77452 +
77453 +void
77454 +gr_set_pax_flags(struct task_struct *task)
77455 +{
77456 + return;
77457 +}
77458 +
77459 +int
77460 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
77461 + const int unsafe_share)
77462 +{
77463 + return 0;
77464 +}
77465 +
77466 +void
77467 +gr_handle_delete(const ino_t ino, const dev_t dev)
77468 +{
77469 + return;
77470 +}
77471 +
77472 +void
77473 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
77474 +{
77475 + return;
77476 +}
77477 +
77478 +void
77479 +gr_handle_crash(struct task_struct *task, const int sig)
77480 +{
77481 + return;
77482 +}
77483 +
77484 +int
77485 +gr_check_crash_exec(const struct file *filp)
77486 +{
77487 + return 0;
77488 +}
77489 +
77490 +int
77491 +gr_check_crash_uid(const kuid_t uid)
77492 +{
77493 + return 0;
77494 +}
77495 +
77496 +void
77497 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
77498 + struct dentry *old_dentry,
77499 + struct dentry *new_dentry,
77500 + struct vfsmount *mnt, const __u8 replace, unsigned int flags)
77501 +{
77502 + return;
77503 +}
77504 +
77505 +int
77506 +gr_search_socket(const int family, const int type, const int protocol)
77507 +{
77508 + return 1;
77509 +}
77510 +
77511 +int
77512 +gr_search_connectbind(const int mode, const struct socket *sock,
77513 + const struct sockaddr_in *addr)
77514 +{
77515 + return 0;
77516 +}
77517 +
77518 +void
77519 +gr_handle_alertkill(struct task_struct *task)
77520 +{
77521 + return;
77522 +}
77523 +
77524 +__u32
77525 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
77526 +{
77527 + return 1;
77528 +}
77529 +
77530 +__u32
77531 +gr_acl_handle_hidden_file(const struct dentry * dentry,
77532 + const struct vfsmount * mnt)
77533 +{
77534 + return 1;
77535 +}
77536 +
77537 +__u32
77538 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
77539 + int acc_mode)
77540 +{
77541 + return 1;
77542 +}
77543 +
77544 +__u32
77545 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
77546 +{
77547 + return 1;
77548 +}
77549 +
77550 +__u32
77551 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
77552 +{
77553 + return 1;
77554 +}
77555 +
77556 +int
77557 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
77558 + unsigned int *vm_flags)
77559 +{
77560 + return 1;
77561 +}
77562 +
77563 +__u32
77564 +gr_acl_handle_truncate(const struct dentry * dentry,
77565 + const struct vfsmount * mnt)
77566 +{
77567 + return 1;
77568 +}
77569 +
77570 +__u32
77571 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
77572 +{
77573 + return 1;
77574 +}
77575 +
77576 +__u32
77577 +gr_acl_handle_access(const struct dentry * dentry,
77578 + const struct vfsmount * mnt, const int fmode)
77579 +{
77580 + return 1;
77581 +}
77582 +
77583 +__u32
77584 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
77585 + umode_t *mode)
77586 +{
77587 + return 1;
77588 +}
77589 +
77590 +__u32
77591 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
77592 +{
77593 + return 1;
77594 +}
77595 +
77596 +__u32
77597 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
77598 +{
77599 + return 1;
77600 +}
77601 +
77602 +__u32
77603 +gr_acl_handle_removexattr(const struct dentry * dentry, const struct vfsmount * mnt)
77604 +{
77605 + return 1;
77606 +}
77607 +
77608 +void
77609 +grsecurity_init(void)
77610 +{
77611 + return;
77612 +}
77613 +
77614 +umode_t gr_acl_umask(void)
77615 +{
77616 + return 0;
77617 +}
77618 +
77619 +__u32
77620 +gr_acl_handle_mknod(const struct dentry * new_dentry,
77621 + const struct dentry * parent_dentry,
77622 + const struct vfsmount * parent_mnt,
77623 + const int mode)
77624 +{
77625 + return 1;
77626 +}
77627 +
77628 +__u32
77629 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
77630 + const struct dentry * parent_dentry,
77631 + const struct vfsmount * parent_mnt)
77632 +{
77633 + return 1;
77634 +}
77635 +
77636 +__u32
77637 +gr_acl_handle_symlink(const struct dentry * new_dentry,
77638 + const struct dentry * parent_dentry,
77639 + const struct vfsmount * parent_mnt, const struct filename *from)
77640 +{
77641 + return 1;
77642 +}
77643 +
77644 +__u32
77645 +gr_acl_handle_link(const struct dentry * new_dentry,
77646 + const struct dentry * parent_dentry,
77647 + const struct vfsmount * parent_mnt,
77648 + const struct dentry * old_dentry,
77649 + const struct vfsmount * old_mnt, const struct filename *to)
77650 +{
77651 + return 1;
77652 +}
77653 +
77654 +int
77655 +gr_acl_handle_rename(const struct dentry *new_dentry,
77656 + const struct dentry *parent_dentry,
77657 + const struct vfsmount *parent_mnt,
77658 + const struct dentry *old_dentry,
77659 + const struct inode *old_parent_inode,
77660 + const struct vfsmount *old_mnt, const struct filename *newname,
77661 + unsigned int flags)
77662 +{
77663 + return 0;
77664 +}
77665 +
77666 +int
77667 +gr_acl_handle_filldir(const struct file *file, const char *name,
77668 + const int namelen, const ino_t ino)
77669 +{
77670 + return 1;
77671 +}
77672 +
77673 +int
77674 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
77675 + const u64 shm_createtime, const kuid_t cuid, const int shmid)
77676 +{
77677 + return 1;
77678 +}
77679 +
77680 +int
77681 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
77682 +{
77683 + return 0;
77684 +}
77685 +
77686 +int
77687 +gr_search_accept(const struct socket *sock)
77688 +{
77689 + return 0;
77690 +}
77691 +
77692 +int
77693 +gr_search_listen(const struct socket *sock)
77694 +{
77695 + return 0;
77696 +}
77697 +
77698 +int
77699 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
77700 +{
77701 + return 0;
77702 +}
77703 +
77704 +__u32
77705 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
77706 +{
77707 + return 1;
77708 +}
77709 +
77710 +__u32
77711 +gr_acl_handle_creat(const struct dentry * dentry,
77712 + const struct dentry * p_dentry,
77713 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
77714 + const int imode)
77715 +{
77716 + return 1;
77717 +}
77718 +
77719 +void
77720 +gr_acl_handle_exit(void)
77721 +{
77722 + return;
77723 +}
77724 +
77725 +int
77726 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
77727 +{
77728 + return 1;
77729 +}
77730 +
77731 +void
77732 +gr_set_role_label(const kuid_t uid, const kgid_t gid)
77733 +{
77734 + return;
77735 +}
77736 +
77737 +int
77738 +gr_acl_handle_procpidmem(const struct task_struct *task)
77739 +{
77740 + return 0;
77741 +}
77742 +
77743 +int
77744 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
77745 +{
77746 + return 0;
77747 +}
77748 +
77749 +int
77750 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
77751 +{
77752 + return 0;
77753 +}
77754 +
77755 +int
77756 +gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
77757 +{
77758 + return 0;
77759 +}
77760 +
77761 +int
77762 +gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
77763 +{
77764 + return 0;
77765 +}
77766 +
77767 +int gr_acl_enable_at_secure(void)
77768 +{
77769 + return 0;
77770 +}
77771 +
77772 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
77773 +{
77774 + return dentry->d_sb->s_dev;
77775 +}
77776 +
77777 +void gr_put_exec_file(struct task_struct *task)
77778 +{
77779 + return;
77780 +}
77781 +
77782 +#ifdef CONFIG_SECURITY
77783 +EXPORT_SYMBOL_GPL(gr_check_user_change);
77784 +EXPORT_SYMBOL_GPL(gr_check_group_change);
77785 +#endif
77786 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
77787 new file mode 100644
77788 index 0000000..14638ff
77789 --- /dev/null
77790 +++ b/grsecurity/grsec_exec.c
77791 @@ -0,0 +1,188 @@
77792 +#include <linux/kernel.h>
77793 +#include <linux/sched.h>
77794 +#include <linux/file.h>
77795 +#include <linux/binfmts.h>
77796 +#include <linux/fs.h>
77797 +#include <linux/types.h>
77798 +#include <linux/grdefs.h>
77799 +#include <linux/grsecurity.h>
77800 +#include <linux/grinternal.h>
77801 +#include <linux/capability.h>
77802 +#include <linux/module.h>
77803 +#include <linux/compat.h>
77804 +
77805 +#include <asm/uaccess.h>
77806 +
77807 +#ifdef CONFIG_GRKERNSEC_EXECLOG
77808 +static char gr_exec_arg_buf[132];
77809 +static DEFINE_MUTEX(gr_exec_arg_mutex);
77810 +#endif
77811 +
77812 +struct user_arg_ptr {
77813 +#ifdef CONFIG_COMPAT
77814 + bool is_compat;
77815 +#endif
77816 + union {
77817 + const char __user *const __user *native;
77818 +#ifdef CONFIG_COMPAT
77819 + const compat_uptr_t __user *compat;
77820 +#endif
77821 + } ptr;
77822 +};
77823 +
77824 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
77825 +
77826 +void
77827 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
77828 +{
77829 +#ifdef CONFIG_GRKERNSEC_EXECLOG
77830 + char *grarg = gr_exec_arg_buf;
77831 + unsigned int i, x, execlen = 0;
77832 + char c;
77833 +
77834 + if (!((grsec_enable_execlog && grsec_enable_group &&
77835 + in_group_p(grsec_audit_gid))
77836 + || (grsec_enable_execlog && !grsec_enable_group)))
77837 + return;
77838 +
77839 + mutex_lock(&gr_exec_arg_mutex);
77840 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
77841 +
77842 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
77843 + const char __user *p;
77844 + unsigned int len;
77845 +
77846 + p = get_user_arg_ptr(argv, i);
77847 + if (IS_ERR(p))
77848 + goto log;
77849 +
77850 + len = strnlen_user(p, 128 - execlen);
77851 + if (len > 128 - execlen)
77852 + len = 128 - execlen;
77853 + else if (len > 0)
77854 + len--;
77855 + if (copy_from_user(grarg + execlen, p, len))
77856 + goto log;
77857 +
77858 + /* rewrite unprintable characters */
77859 + for (x = 0; x < len; x++) {
77860 + c = *(grarg + execlen + x);
77861 + if (c < 32 || c > 126)
77862 + *(grarg + execlen + x) = ' ';
77863 + }
77864 +
77865 + execlen += len;
77866 + *(grarg + execlen) = ' ';
77867 + *(grarg + execlen + 1) = '\0';
77868 + execlen++;
77869 + }
77870 +
77871 + log:
77872 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
77873 + bprm->file->f_path.mnt, grarg);
77874 + mutex_unlock(&gr_exec_arg_mutex);
77875 +#endif
77876 + return;
77877 +}
77878 +
77879 +#ifdef CONFIG_GRKERNSEC
77880 +extern int gr_acl_is_capable(const int cap);
77881 +extern int gr_acl_is_capable_nolog(const int cap);
77882 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
77883 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
77884 +extern int gr_chroot_is_capable(const int cap);
77885 +extern int gr_chroot_is_capable_nolog(const int cap);
77886 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
77887 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
77888 +#endif
77889 +
77890 +const char *captab_log[] = {
77891 + "CAP_CHOWN",
77892 + "CAP_DAC_OVERRIDE",
77893 + "CAP_DAC_READ_SEARCH",
77894 + "CAP_FOWNER",
77895 + "CAP_FSETID",
77896 + "CAP_KILL",
77897 + "CAP_SETGID",
77898 + "CAP_SETUID",
77899 + "CAP_SETPCAP",
77900 + "CAP_LINUX_IMMUTABLE",
77901 + "CAP_NET_BIND_SERVICE",
77902 + "CAP_NET_BROADCAST",
77903 + "CAP_NET_ADMIN",
77904 + "CAP_NET_RAW",
77905 + "CAP_IPC_LOCK",
77906 + "CAP_IPC_OWNER",
77907 + "CAP_SYS_MODULE",
77908 + "CAP_SYS_RAWIO",
77909 + "CAP_SYS_CHROOT",
77910 + "CAP_SYS_PTRACE",
77911 + "CAP_SYS_PACCT",
77912 + "CAP_SYS_ADMIN",
77913 + "CAP_SYS_BOOT",
77914 + "CAP_SYS_NICE",
77915 + "CAP_SYS_RESOURCE",
77916 + "CAP_SYS_TIME",
77917 + "CAP_SYS_TTY_CONFIG",
77918 + "CAP_MKNOD",
77919 + "CAP_LEASE",
77920 + "CAP_AUDIT_WRITE",
77921 + "CAP_AUDIT_CONTROL",
77922 + "CAP_SETFCAP",
77923 + "CAP_MAC_OVERRIDE",
77924 + "CAP_MAC_ADMIN",
77925 + "CAP_SYSLOG",
77926 + "CAP_WAKE_ALARM",
77927 + "CAP_BLOCK_SUSPEND"
77928 +};
77929 +
77930 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
77931 +
77932 +int gr_is_capable(const int cap)
77933 +{
77934 +#ifdef CONFIG_GRKERNSEC
77935 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
77936 + return 1;
77937 + return 0;
77938 +#else
77939 + return 1;
77940 +#endif
77941 +}
77942 +
77943 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
77944 +{
77945 +#ifdef CONFIG_GRKERNSEC
77946 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
77947 + return 1;
77948 + return 0;
77949 +#else
77950 + return 1;
77951 +#endif
77952 +}
77953 +
77954 +int gr_is_capable_nolog(const int cap)
77955 +{
77956 +#ifdef CONFIG_GRKERNSEC
77957 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
77958 + return 1;
77959 + return 0;
77960 +#else
77961 + return 1;
77962 +#endif
77963 +}
77964 +
77965 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
77966 +{
77967 +#ifdef CONFIG_GRKERNSEC
77968 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
77969 + return 1;
77970 + return 0;
77971 +#else
77972 + return 1;
77973 +#endif
77974 +}
77975 +
77976 +EXPORT_SYMBOL_GPL(gr_is_capable);
77977 +EXPORT_SYMBOL_GPL(gr_is_capable_nolog);
77978 +EXPORT_SYMBOL_GPL(gr_task_is_capable);
77979 +EXPORT_SYMBOL_GPL(gr_task_is_capable_nolog);
77980 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
77981 new file mode 100644
77982 index 0000000..06cc6ea
77983 --- /dev/null
77984 +++ b/grsecurity/grsec_fifo.c
77985 @@ -0,0 +1,24 @@
77986 +#include <linux/kernel.h>
77987 +#include <linux/sched.h>
77988 +#include <linux/fs.h>
77989 +#include <linux/file.h>
77990 +#include <linux/grinternal.h>
77991 +
77992 +int
77993 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
77994 + const struct dentry *dir, const int flag, const int acc_mode)
77995 +{
77996 +#ifdef CONFIG_GRKERNSEC_FIFO
77997 + const struct cred *cred = current_cred();
77998 +
77999 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
78000 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
78001 + !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
78002 + !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
78003 + if (!inode_permission(dentry->d_inode, acc_mode))
78004 + 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));
78005 + return -EACCES;
78006 + }
78007 +#endif
78008 + return 0;
78009 +}
78010 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
78011 new file mode 100644
78012 index 0000000..8ca18bf
78013 --- /dev/null
78014 +++ b/grsecurity/grsec_fork.c
78015 @@ -0,0 +1,23 @@
78016 +#include <linux/kernel.h>
78017 +#include <linux/sched.h>
78018 +#include <linux/grsecurity.h>
78019 +#include <linux/grinternal.h>
78020 +#include <linux/errno.h>
78021 +
78022 +void
78023 +gr_log_forkfail(const int retval)
78024 +{
78025 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
78026 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
78027 + switch (retval) {
78028 + case -EAGAIN:
78029 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
78030 + break;
78031 + case -ENOMEM:
78032 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
78033 + break;
78034 + }
78035 + }
78036 +#endif
78037 + return;
78038 +}
78039 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
78040 new file mode 100644
78041 index 0000000..b7cb191
78042 --- /dev/null
78043 +++ b/grsecurity/grsec_init.c
78044 @@ -0,0 +1,286 @@
78045 +#include <linux/kernel.h>
78046 +#include <linux/sched.h>
78047 +#include <linux/mm.h>
78048 +#include <linux/gracl.h>
78049 +#include <linux/slab.h>
78050 +#include <linux/vmalloc.h>
78051 +#include <linux/percpu.h>
78052 +#include <linux/module.h>
78053 +
78054 +int grsec_enable_ptrace_readexec;
78055 +int grsec_enable_setxid;
78056 +int grsec_enable_symlinkown;
78057 +kgid_t grsec_symlinkown_gid;
78058 +int grsec_enable_brute;
78059 +int grsec_enable_link;
78060 +int grsec_enable_dmesg;
78061 +int grsec_enable_harden_ptrace;
78062 +int grsec_enable_harden_ipc;
78063 +int grsec_enable_fifo;
78064 +int grsec_enable_execlog;
78065 +int grsec_enable_signal;
78066 +int grsec_enable_forkfail;
78067 +int grsec_enable_audit_ptrace;
78068 +int grsec_enable_time;
78069 +int grsec_enable_group;
78070 +kgid_t grsec_audit_gid;
78071 +int grsec_enable_chdir;
78072 +int grsec_enable_mount;
78073 +int grsec_enable_rofs;
78074 +int grsec_deny_new_usb;
78075 +int grsec_enable_chroot_findtask;
78076 +int grsec_enable_chroot_mount;
78077 +int grsec_enable_chroot_shmat;
78078 +int grsec_enable_chroot_fchdir;
78079 +int grsec_enable_chroot_double;
78080 +int grsec_enable_chroot_pivot;
78081 +int grsec_enable_chroot_chdir;
78082 +int grsec_enable_chroot_chmod;
78083 +int grsec_enable_chroot_mknod;
78084 +int grsec_enable_chroot_nice;
78085 +int grsec_enable_chroot_execlog;
78086 +int grsec_enable_chroot_caps;
78087 +int grsec_enable_chroot_sysctl;
78088 +int grsec_enable_chroot_unix;
78089 +int grsec_enable_tpe;
78090 +kgid_t grsec_tpe_gid;
78091 +int grsec_enable_blackhole;
78092 +#ifdef CONFIG_IPV6_MODULE
78093 +EXPORT_SYMBOL_GPL(grsec_enable_blackhole);
78094 +#endif
78095 +int grsec_lastack_retries;
78096 +int grsec_enable_tpe_all;
78097 +int grsec_enable_tpe_invert;
78098 +int grsec_enable_socket_all;
78099 +kgid_t grsec_socket_all_gid;
78100 +int grsec_enable_socket_client;
78101 +kgid_t grsec_socket_client_gid;
78102 +int grsec_enable_socket_server;
78103 +kgid_t grsec_socket_server_gid;
78104 +int grsec_resource_logging;
78105 +int grsec_disable_privio;
78106 +int grsec_enable_log_rwxmaps;
78107 +int grsec_lock;
78108 +
78109 +DEFINE_SPINLOCK(grsec_alert_lock);
78110 +unsigned long grsec_alert_wtime = 0;
78111 +unsigned long grsec_alert_fyet = 0;
78112 +
78113 +DEFINE_SPINLOCK(grsec_audit_lock);
78114 +
78115 +DEFINE_RWLOCK(grsec_exec_file_lock);
78116 +
78117 +char *gr_shared_page[4];
78118 +
78119 +char *gr_alert_log_fmt;
78120 +char *gr_audit_log_fmt;
78121 +char *gr_alert_log_buf;
78122 +char *gr_audit_log_buf;
78123 +
78124 +extern struct gr_arg *gr_usermode;
78125 +extern unsigned char *gr_system_salt;
78126 +extern unsigned char *gr_system_sum;
78127 +
78128 +void __init
78129 +grsecurity_init(void)
78130 +{
78131 + int j;
78132 + /* create the per-cpu shared pages */
78133 +
78134 +#ifdef CONFIG_X86
78135 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
78136 +#endif
78137 +
78138 + for (j = 0; j < 4; j++) {
78139 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
78140 + if (gr_shared_page[j] == NULL) {
78141 + panic("Unable to allocate grsecurity shared page");
78142 + return;
78143 + }
78144 + }
78145 +
78146 + /* allocate log buffers */
78147 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
78148 + if (!gr_alert_log_fmt) {
78149 + panic("Unable to allocate grsecurity alert log format buffer");
78150 + return;
78151 + }
78152 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
78153 + if (!gr_audit_log_fmt) {
78154 + panic("Unable to allocate grsecurity audit log format buffer");
78155 + return;
78156 + }
78157 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
78158 + if (!gr_alert_log_buf) {
78159 + panic("Unable to allocate grsecurity alert log buffer");
78160 + return;
78161 + }
78162 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
78163 + if (!gr_audit_log_buf) {
78164 + panic("Unable to allocate grsecurity audit log buffer");
78165 + return;
78166 + }
78167 +
78168 + /* allocate memory for authentication structure */
78169 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
78170 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
78171 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
78172 +
78173 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
78174 + panic("Unable to allocate grsecurity authentication structure");
78175 + return;
78176 + }
78177 +
78178 +#ifdef CONFIG_GRKERNSEC_IO
78179 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
78180 + grsec_disable_privio = 1;
78181 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
78182 + grsec_disable_privio = 1;
78183 +#else
78184 + grsec_disable_privio = 0;
78185 +#endif
78186 +#endif
78187 +
78188 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
78189 + /* for backward compatibility, tpe_invert always defaults to on if
78190 + enabled in the kernel
78191 + */
78192 + grsec_enable_tpe_invert = 1;
78193 +#endif
78194 +
78195 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
78196 +#ifndef CONFIG_GRKERNSEC_SYSCTL
78197 + grsec_lock = 1;
78198 +#endif
78199 +
78200 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78201 + grsec_enable_log_rwxmaps = 1;
78202 +#endif
78203 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
78204 + grsec_enable_group = 1;
78205 + grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
78206 +#endif
78207 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
78208 + grsec_enable_ptrace_readexec = 1;
78209 +#endif
78210 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
78211 + grsec_enable_chdir = 1;
78212 +#endif
78213 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
78214 + grsec_enable_harden_ptrace = 1;
78215 +#endif
78216 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
78217 + grsec_enable_harden_ipc = 1;
78218 +#endif
78219 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
78220 + grsec_enable_mount = 1;
78221 +#endif
78222 +#ifdef CONFIG_GRKERNSEC_LINK
78223 + grsec_enable_link = 1;
78224 +#endif
78225 +#ifdef CONFIG_GRKERNSEC_BRUTE
78226 + grsec_enable_brute = 1;
78227 +#endif
78228 +#ifdef CONFIG_GRKERNSEC_DMESG
78229 + grsec_enable_dmesg = 1;
78230 +#endif
78231 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78232 + grsec_enable_blackhole = 1;
78233 + grsec_lastack_retries = 4;
78234 +#endif
78235 +#ifdef CONFIG_GRKERNSEC_FIFO
78236 + grsec_enable_fifo = 1;
78237 +#endif
78238 +#ifdef CONFIG_GRKERNSEC_EXECLOG
78239 + grsec_enable_execlog = 1;
78240 +#endif
78241 +#ifdef CONFIG_GRKERNSEC_SETXID
78242 + grsec_enable_setxid = 1;
78243 +#endif
78244 +#ifdef CONFIG_GRKERNSEC_SIGNAL
78245 + grsec_enable_signal = 1;
78246 +#endif
78247 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
78248 + grsec_enable_forkfail = 1;
78249 +#endif
78250 +#ifdef CONFIG_GRKERNSEC_TIME
78251 + grsec_enable_time = 1;
78252 +#endif
78253 +#ifdef CONFIG_GRKERNSEC_RESLOG
78254 + grsec_resource_logging = 1;
78255 +#endif
78256 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
78257 + grsec_enable_chroot_findtask = 1;
78258 +#endif
78259 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
78260 + grsec_enable_chroot_unix = 1;
78261 +#endif
78262 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
78263 + grsec_enable_chroot_mount = 1;
78264 +#endif
78265 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
78266 + grsec_enable_chroot_fchdir = 1;
78267 +#endif
78268 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
78269 + grsec_enable_chroot_shmat = 1;
78270 +#endif
78271 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
78272 + grsec_enable_audit_ptrace = 1;
78273 +#endif
78274 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
78275 + grsec_enable_chroot_double = 1;
78276 +#endif
78277 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
78278 + grsec_enable_chroot_pivot = 1;
78279 +#endif
78280 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
78281 + grsec_enable_chroot_chdir = 1;
78282 +#endif
78283 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
78284 + grsec_enable_chroot_chmod = 1;
78285 +#endif
78286 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
78287 + grsec_enable_chroot_mknod = 1;
78288 +#endif
78289 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
78290 + grsec_enable_chroot_nice = 1;
78291 +#endif
78292 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
78293 + grsec_enable_chroot_execlog = 1;
78294 +#endif
78295 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
78296 + grsec_enable_chroot_caps = 1;
78297 +#endif
78298 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
78299 + grsec_enable_chroot_sysctl = 1;
78300 +#endif
78301 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
78302 + grsec_enable_symlinkown = 1;
78303 + grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
78304 +#endif
78305 +#ifdef CONFIG_GRKERNSEC_TPE
78306 + grsec_enable_tpe = 1;
78307 + grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
78308 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
78309 + grsec_enable_tpe_all = 1;
78310 +#endif
78311 +#endif
78312 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
78313 + grsec_enable_socket_all = 1;
78314 + grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
78315 +#endif
78316 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
78317 + grsec_enable_socket_client = 1;
78318 + grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
78319 +#endif
78320 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
78321 + grsec_enable_socket_server = 1;
78322 + grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
78323 +#endif
78324 +#endif
78325 +#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
78326 + grsec_deny_new_usb = 1;
78327 +#endif
78328 +
78329 + return;
78330 +}
78331 diff --git a/grsecurity/grsec_ipc.c b/grsecurity/grsec_ipc.c
78332 new file mode 100644
78333 index 0000000..1773300
78334 --- /dev/null
78335 +++ b/grsecurity/grsec_ipc.c
78336 @@ -0,0 +1,48 @@
78337 +#include <linux/kernel.h>
78338 +#include <linux/mm.h>
78339 +#include <linux/sched.h>
78340 +#include <linux/file.h>
78341 +#include <linux/ipc.h>
78342 +#include <linux/ipc_namespace.h>
78343 +#include <linux/grsecurity.h>
78344 +#include <linux/grinternal.h>
78345 +
78346 +int
78347 +gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode)
78348 +{
78349 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
78350 + int write;
78351 + int orig_granted_mode;
78352 + kuid_t euid;
78353 + kgid_t egid;
78354 +
78355 + if (!grsec_enable_harden_ipc)
78356 + return 1;
78357 +
78358 + euid = current_euid();
78359 + egid = current_egid();
78360 +
78361 + write = requested_mode & 00002;
78362 + orig_granted_mode = ipcp->mode;
78363 +
78364 + if (uid_eq(euid, ipcp->cuid) || uid_eq(euid, ipcp->uid))
78365 + orig_granted_mode >>= 6;
78366 + else {
78367 + /* if likely wrong permissions, lock to user */
78368 + if (orig_granted_mode & 0007)
78369 + orig_granted_mode = 0;
78370 + /* otherwise do a egid-only check */
78371 + else if (gid_eq(egid, ipcp->cgid) || gid_eq(egid, ipcp->gid))
78372 + orig_granted_mode >>= 3;
78373 + /* otherwise, no access */
78374 + else
78375 + orig_granted_mode = 0;
78376 + }
78377 + if (!(requested_mode & ~granted_mode & 0007) && (requested_mode & ~orig_granted_mode & 0007) &&
78378 + !ns_capable_nolog(ns->user_ns, CAP_IPC_OWNER)) {
78379 + gr_log_str_int(GR_DONT_AUDIT, GR_IPC_DENIED_MSG, write ? "write" : "read", GR_GLOBAL_UID(ipcp->cuid));
78380 + return 0;
78381 + }
78382 +#endif
78383 + return 1;
78384 +}
78385 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
78386 new file mode 100644
78387 index 0000000..5e05e20
78388 --- /dev/null
78389 +++ b/grsecurity/grsec_link.c
78390 @@ -0,0 +1,58 @@
78391 +#include <linux/kernel.h>
78392 +#include <linux/sched.h>
78393 +#include <linux/fs.h>
78394 +#include <linux/file.h>
78395 +#include <linux/grinternal.h>
78396 +
78397 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
78398 +{
78399 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
78400 + const struct inode *link_inode = link->dentry->d_inode;
78401 +
78402 + if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
78403 + /* ignore root-owned links, e.g. /proc/self */
78404 + gr_is_global_nonroot(link_inode->i_uid) && target &&
78405 + !uid_eq(link_inode->i_uid, target->i_uid)) {
78406 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
78407 + return 1;
78408 + }
78409 +#endif
78410 + return 0;
78411 +}
78412 +
78413 +int
78414 +gr_handle_follow_link(const struct inode *parent,
78415 + const struct inode *inode,
78416 + const struct dentry *dentry, const struct vfsmount *mnt)
78417 +{
78418 +#ifdef CONFIG_GRKERNSEC_LINK
78419 + const struct cred *cred = current_cred();
78420 +
78421 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
78422 + (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
78423 + (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
78424 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
78425 + return -EACCES;
78426 + }
78427 +#endif
78428 + return 0;
78429 +}
78430 +
78431 +int
78432 +gr_handle_hardlink(const struct dentry *dentry,
78433 + const struct vfsmount *mnt,
78434 + struct inode *inode, const int mode, const struct filename *to)
78435 +{
78436 +#ifdef CONFIG_GRKERNSEC_LINK
78437 + const struct cred *cred = current_cred();
78438 +
78439 + if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
78440 + (!S_ISREG(mode) || is_privileged_binary(dentry) ||
78441 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
78442 + !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
78443 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
78444 + return -EPERM;
78445 + }
78446 +#endif
78447 + return 0;
78448 +}
78449 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
78450 new file mode 100644
78451 index 0000000..dbe0a6b
78452 --- /dev/null
78453 +++ b/grsecurity/grsec_log.c
78454 @@ -0,0 +1,341 @@
78455 +#include <linux/kernel.h>
78456 +#include <linux/sched.h>
78457 +#include <linux/file.h>
78458 +#include <linux/tty.h>
78459 +#include <linux/fs.h>
78460 +#include <linux/mm.h>
78461 +#include <linux/grinternal.h>
78462 +
78463 +#ifdef CONFIG_TREE_PREEMPT_RCU
78464 +#define DISABLE_PREEMPT() preempt_disable()
78465 +#define ENABLE_PREEMPT() preempt_enable()
78466 +#else
78467 +#define DISABLE_PREEMPT()
78468 +#define ENABLE_PREEMPT()
78469 +#endif
78470 +
78471 +#define BEGIN_LOCKS(x) \
78472 + DISABLE_PREEMPT(); \
78473 + rcu_read_lock(); \
78474 + read_lock(&tasklist_lock); \
78475 + read_lock(&grsec_exec_file_lock); \
78476 + if (x != GR_DO_AUDIT) \
78477 + spin_lock(&grsec_alert_lock); \
78478 + else \
78479 + spin_lock(&grsec_audit_lock)
78480 +
78481 +#define END_LOCKS(x) \
78482 + if (x != GR_DO_AUDIT) \
78483 + spin_unlock(&grsec_alert_lock); \
78484 + else \
78485 + spin_unlock(&grsec_audit_lock); \
78486 + read_unlock(&grsec_exec_file_lock); \
78487 + read_unlock(&tasklist_lock); \
78488 + rcu_read_unlock(); \
78489 + ENABLE_PREEMPT(); \
78490 + if (x == GR_DONT_AUDIT) \
78491 + gr_handle_alertkill(current)
78492 +
78493 +enum {
78494 + FLOODING,
78495 + NO_FLOODING
78496 +};
78497 +
78498 +extern char *gr_alert_log_fmt;
78499 +extern char *gr_audit_log_fmt;
78500 +extern char *gr_alert_log_buf;
78501 +extern char *gr_audit_log_buf;
78502 +
78503 +static int gr_log_start(int audit)
78504 +{
78505 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
78506 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
78507 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
78508 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
78509 + unsigned long curr_secs = get_seconds();
78510 +
78511 + if (audit == GR_DO_AUDIT)
78512 + goto set_fmt;
78513 +
78514 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
78515 + grsec_alert_wtime = curr_secs;
78516 + grsec_alert_fyet = 0;
78517 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
78518 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
78519 + grsec_alert_fyet++;
78520 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
78521 + grsec_alert_wtime = curr_secs;
78522 + grsec_alert_fyet++;
78523 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
78524 + return FLOODING;
78525 + }
78526 + else return FLOODING;
78527 +
78528 +set_fmt:
78529 +#endif
78530 + memset(buf, 0, PAGE_SIZE);
78531 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
78532 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
78533 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
78534 + } else if (current->signal->curr_ip) {
78535 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
78536 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
78537 + } else if (gr_acl_is_enabled()) {
78538 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
78539 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
78540 + } else {
78541 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
78542 + strcpy(buf, fmt);
78543 + }
78544 +
78545 + return NO_FLOODING;
78546 +}
78547 +
78548 +static void gr_log_middle(int audit, const char *msg, va_list ap)
78549 + __attribute__ ((format (printf, 2, 0)));
78550 +
78551 +static void gr_log_middle(int audit, const char *msg, va_list ap)
78552 +{
78553 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
78554 + unsigned int len = strlen(buf);
78555 +
78556 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
78557 +
78558 + return;
78559 +}
78560 +
78561 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
78562 + __attribute__ ((format (printf, 2, 3)));
78563 +
78564 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
78565 +{
78566 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
78567 + unsigned int len = strlen(buf);
78568 + va_list ap;
78569 +
78570 + va_start(ap, msg);
78571 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
78572 + va_end(ap);
78573 +
78574 + return;
78575 +}
78576 +
78577 +static void gr_log_end(int audit, int append_default)
78578 +{
78579 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
78580 + if (append_default) {
78581 + struct task_struct *task = current;
78582 + struct task_struct *parent = task->real_parent;
78583 + const struct cred *cred = __task_cred(task);
78584 + const struct cred *pcred = __task_cred(parent);
78585 + unsigned int len = strlen(buf);
78586 +
78587 + 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));
78588 + }
78589 +
78590 + printk("%s\n", buf);
78591 +
78592 + return;
78593 +}
78594 +
78595 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
78596 +{
78597 + int logtype;
78598 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
78599 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
78600 + void *voidptr = NULL;
78601 + int num1 = 0, num2 = 0;
78602 + unsigned long ulong1 = 0, ulong2 = 0;
78603 + struct dentry *dentry = NULL;
78604 + struct vfsmount *mnt = NULL;
78605 + struct file *file = NULL;
78606 + struct task_struct *task = NULL;
78607 + struct vm_area_struct *vma = NULL;
78608 + const struct cred *cred, *pcred;
78609 + va_list ap;
78610 +
78611 + BEGIN_LOCKS(audit);
78612 + logtype = gr_log_start(audit);
78613 + if (logtype == FLOODING) {
78614 + END_LOCKS(audit);
78615 + return;
78616 + }
78617 + va_start(ap, argtypes);
78618 + switch (argtypes) {
78619 + case GR_TTYSNIFF:
78620 + task = va_arg(ap, struct task_struct *);
78621 + 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));
78622 + break;
78623 + case GR_SYSCTL_HIDDEN:
78624 + str1 = va_arg(ap, char *);
78625 + gr_log_middle_varargs(audit, msg, result, str1);
78626 + break;
78627 + case GR_RBAC:
78628 + dentry = va_arg(ap, struct dentry *);
78629 + mnt = va_arg(ap, struct vfsmount *);
78630 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
78631 + break;
78632 + case GR_RBAC_STR:
78633 + dentry = va_arg(ap, struct dentry *);
78634 + mnt = va_arg(ap, struct vfsmount *);
78635 + str1 = va_arg(ap, char *);
78636 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
78637 + break;
78638 + case GR_STR_RBAC:
78639 + str1 = va_arg(ap, char *);
78640 + dentry = va_arg(ap, struct dentry *);
78641 + mnt = va_arg(ap, struct vfsmount *);
78642 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
78643 + break;
78644 + case GR_RBAC_MODE2:
78645 + dentry = va_arg(ap, struct dentry *);
78646 + mnt = va_arg(ap, struct vfsmount *);
78647 + str1 = va_arg(ap, char *);
78648 + str2 = va_arg(ap, char *);
78649 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
78650 + break;
78651 + case GR_RBAC_MODE3:
78652 + dentry = va_arg(ap, struct dentry *);
78653 + mnt = va_arg(ap, struct vfsmount *);
78654 + str1 = va_arg(ap, char *);
78655 + str2 = va_arg(ap, char *);
78656 + str3 = va_arg(ap, char *);
78657 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
78658 + break;
78659 + case GR_FILENAME:
78660 + dentry = va_arg(ap, struct dentry *);
78661 + mnt = va_arg(ap, struct vfsmount *);
78662 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
78663 + break;
78664 + case GR_STR_FILENAME:
78665 + str1 = va_arg(ap, char *);
78666 + dentry = va_arg(ap, struct dentry *);
78667 + mnt = va_arg(ap, struct vfsmount *);
78668 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
78669 + break;
78670 + case GR_FILENAME_STR:
78671 + dentry = va_arg(ap, struct dentry *);
78672 + mnt = va_arg(ap, struct vfsmount *);
78673 + str1 = va_arg(ap, char *);
78674 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
78675 + break;
78676 + case GR_FILENAME_TWO_INT:
78677 + dentry = va_arg(ap, struct dentry *);
78678 + mnt = va_arg(ap, struct vfsmount *);
78679 + num1 = va_arg(ap, int);
78680 + num2 = va_arg(ap, int);
78681 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
78682 + break;
78683 + case GR_FILENAME_TWO_INT_STR:
78684 + dentry = va_arg(ap, struct dentry *);
78685 + mnt = va_arg(ap, struct vfsmount *);
78686 + num1 = va_arg(ap, int);
78687 + num2 = va_arg(ap, int);
78688 + str1 = va_arg(ap, char *);
78689 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
78690 + break;
78691 + case GR_TEXTREL:
78692 + file = va_arg(ap, struct file *);
78693 + ulong1 = va_arg(ap, unsigned long);
78694 + ulong2 = va_arg(ap, unsigned long);
78695 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
78696 + break;
78697 + case GR_PTRACE:
78698 + task = va_arg(ap, struct task_struct *);
78699 + 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));
78700 + break;
78701 + case GR_RESOURCE:
78702 + task = va_arg(ap, struct task_struct *);
78703 + cred = __task_cred(task);
78704 + pcred = __task_cred(task->real_parent);
78705 + ulong1 = va_arg(ap, unsigned long);
78706 + str1 = va_arg(ap, char *);
78707 + ulong2 = va_arg(ap, unsigned long);
78708 + 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));
78709 + break;
78710 + case GR_CAP:
78711 + task = va_arg(ap, struct task_struct *);
78712 + cred = __task_cred(task);
78713 + pcred = __task_cred(task->real_parent);
78714 + str1 = va_arg(ap, char *);
78715 + 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));
78716 + break;
78717 + case GR_SIG:
78718 + str1 = va_arg(ap, char *);
78719 + voidptr = va_arg(ap, void *);
78720 + gr_log_middle_varargs(audit, msg, str1, voidptr);
78721 + break;
78722 + case GR_SIG2:
78723 + task = va_arg(ap, struct task_struct *);
78724 + cred = __task_cred(task);
78725 + pcred = __task_cred(task->real_parent);
78726 + num1 = va_arg(ap, int);
78727 + 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));
78728 + break;
78729 + case GR_CRASH1:
78730 + task = va_arg(ap, struct task_struct *);
78731 + cred = __task_cred(task);
78732 + pcred = __task_cred(task->real_parent);
78733 + ulong1 = va_arg(ap, unsigned long);
78734 + 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);
78735 + break;
78736 + case GR_CRASH2:
78737 + task = va_arg(ap, struct task_struct *);
78738 + cred = __task_cred(task);
78739 + pcred = __task_cred(task->real_parent);
78740 + ulong1 = va_arg(ap, unsigned long);
78741 + 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);
78742 + break;
78743 + case GR_RWXMAP:
78744 + file = va_arg(ap, struct file *);
78745 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
78746 + break;
78747 + case GR_RWXMAPVMA:
78748 + vma = va_arg(ap, struct vm_area_struct *);
78749 + if (vma->vm_file)
78750 + str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
78751 + else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
78752 + str1 = "<stack>";
78753 + else if (vma->vm_start <= current->mm->brk &&
78754 + vma->vm_end >= current->mm->start_brk)
78755 + str1 = "<heap>";
78756 + else
78757 + str1 = "<anonymous mapping>";
78758 + gr_log_middle_varargs(audit, msg, str1);
78759 + break;
78760 + case GR_PSACCT:
78761 + {
78762 + unsigned int wday, cday;
78763 + __u8 whr, chr;
78764 + __u8 wmin, cmin;
78765 + __u8 wsec, csec;
78766 + char cur_tty[64] = { 0 };
78767 + char parent_tty[64] = { 0 };
78768 +
78769 + task = va_arg(ap, struct task_struct *);
78770 + wday = va_arg(ap, unsigned int);
78771 + cday = va_arg(ap, unsigned int);
78772 + whr = va_arg(ap, int);
78773 + chr = va_arg(ap, int);
78774 + wmin = va_arg(ap, int);
78775 + cmin = va_arg(ap, int);
78776 + wsec = va_arg(ap, int);
78777 + csec = va_arg(ap, int);
78778 + ulong1 = va_arg(ap, unsigned long);
78779 + cred = __task_cred(task);
78780 + pcred = __task_cred(task->real_parent);
78781 +
78782 + 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));
78783 + }
78784 + break;
78785 + default:
78786 + gr_log_middle(audit, msg, ap);
78787 + }
78788 + va_end(ap);
78789 + // these don't need DEFAULTSECARGS printed on the end
78790 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
78791 + gr_log_end(audit, 0);
78792 + else
78793 + gr_log_end(audit, 1);
78794 + END_LOCKS(audit);
78795 +}
78796 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
78797 new file mode 100644
78798 index 0000000..0e39d8c
78799 --- /dev/null
78800 +++ b/grsecurity/grsec_mem.c
78801 @@ -0,0 +1,48 @@
78802 +#include <linux/kernel.h>
78803 +#include <linux/sched.h>
78804 +#include <linux/mm.h>
78805 +#include <linux/mman.h>
78806 +#include <linux/module.h>
78807 +#include <linux/grinternal.h>
78808 +
78809 +void gr_handle_msr_write(void)
78810 +{
78811 + gr_log_noargs(GR_DONT_AUDIT, GR_MSRWRITE_MSG);
78812 + return;
78813 +}
78814 +EXPORT_SYMBOL_GPL(gr_handle_msr_write);
78815 +
78816 +void
78817 +gr_handle_ioperm(void)
78818 +{
78819 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
78820 + return;
78821 +}
78822 +
78823 +void
78824 +gr_handle_iopl(void)
78825 +{
78826 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
78827 + return;
78828 +}
78829 +
78830 +void
78831 +gr_handle_mem_readwrite(u64 from, u64 to)
78832 +{
78833 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
78834 + return;
78835 +}
78836 +
78837 +void
78838 +gr_handle_vm86(void)
78839 +{
78840 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
78841 + return;
78842 +}
78843 +
78844 +void
78845 +gr_log_badprocpid(const char *entry)
78846 +{
78847 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
78848 + return;
78849 +}
78850 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
78851 new file mode 100644
78852 index 0000000..cd9e124
78853 --- /dev/null
78854 +++ b/grsecurity/grsec_mount.c
78855 @@ -0,0 +1,65 @@
78856 +#include <linux/kernel.h>
78857 +#include <linux/sched.h>
78858 +#include <linux/mount.h>
78859 +#include <linux/major.h>
78860 +#include <linux/grsecurity.h>
78861 +#include <linux/grinternal.h>
78862 +
78863 +void
78864 +gr_log_remount(const char *devname, const int retval)
78865 +{
78866 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
78867 + if (grsec_enable_mount && (retval >= 0))
78868 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
78869 +#endif
78870 + return;
78871 +}
78872 +
78873 +void
78874 +gr_log_unmount(const char *devname, const int retval)
78875 +{
78876 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
78877 + if (grsec_enable_mount && (retval >= 0))
78878 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
78879 +#endif
78880 + return;
78881 +}
78882 +
78883 +void
78884 +gr_log_mount(const char *from, const char *to, const int retval)
78885 +{
78886 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
78887 + if (grsec_enable_mount && (retval >= 0))
78888 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
78889 +#endif
78890 + return;
78891 +}
78892 +
78893 +int
78894 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
78895 +{
78896 +#ifdef CONFIG_GRKERNSEC_ROFS
78897 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
78898 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
78899 + return -EPERM;
78900 + } else
78901 + return 0;
78902 +#endif
78903 + return 0;
78904 +}
78905 +
78906 +int
78907 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
78908 +{
78909 +#ifdef CONFIG_GRKERNSEC_ROFS
78910 + struct inode *inode = dentry->d_inode;
78911 +
78912 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
78913 + inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR))) {
78914 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
78915 + return -EPERM;
78916 + } else
78917 + return 0;
78918 +#endif
78919 + return 0;
78920 +}
78921 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
78922 new file mode 100644
78923 index 0000000..6ee9d50
78924 --- /dev/null
78925 +++ b/grsecurity/grsec_pax.c
78926 @@ -0,0 +1,45 @@
78927 +#include <linux/kernel.h>
78928 +#include <linux/sched.h>
78929 +#include <linux/mm.h>
78930 +#include <linux/file.h>
78931 +#include <linux/grinternal.h>
78932 +#include <linux/grsecurity.h>
78933 +
78934 +void
78935 +gr_log_textrel(struct vm_area_struct * vma)
78936 +{
78937 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78938 + if (grsec_enable_log_rwxmaps)
78939 + gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
78940 +#endif
78941 + return;
78942 +}
78943 +
78944 +void gr_log_ptgnustack(struct file *file)
78945 +{
78946 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78947 + if (grsec_enable_log_rwxmaps)
78948 + gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
78949 +#endif
78950 + return;
78951 +}
78952 +
78953 +void
78954 +gr_log_rwxmmap(struct file *file)
78955 +{
78956 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78957 + if (grsec_enable_log_rwxmaps)
78958 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
78959 +#endif
78960 + return;
78961 +}
78962 +
78963 +void
78964 +gr_log_rwxmprotect(struct vm_area_struct *vma)
78965 +{
78966 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78967 + if (grsec_enable_log_rwxmaps)
78968 + gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
78969 +#endif
78970 + return;
78971 +}
78972 diff --git a/grsecurity/grsec_proc.c b/grsecurity/grsec_proc.c
78973 new file mode 100644
78974 index 0000000..2005a3a
78975 --- /dev/null
78976 +++ b/grsecurity/grsec_proc.c
78977 @@ -0,0 +1,20 @@
78978 +#include <linux/kernel.h>
78979 +#include <linux/sched.h>
78980 +#include <linux/grsecurity.h>
78981 +#include <linux/grinternal.h>
78982 +
78983 +int gr_proc_is_restricted(void)
78984 +{
78985 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
78986 + const struct cred *cred = current_cred();
78987 +#endif
78988 +
78989 +#ifdef CONFIG_GRKERNSEC_PROC_USER
78990 + if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
78991 + return -EACCES;
78992 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
78993 + if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
78994 + return -EACCES;
78995 +#endif
78996 + return 0;
78997 +}
78998 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
78999 new file mode 100644
79000 index 0000000..f7f29aa
79001 --- /dev/null
79002 +++ b/grsecurity/grsec_ptrace.c
79003 @@ -0,0 +1,30 @@
79004 +#include <linux/kernel.h>
79005 +#include <linux/sched.h>
79006 +#include <linux/grinternal.h>
79007 +#include <linux/security.h>
79008 +
79009 +void
79010 +gr_audit_ptrace(struct task_struct *task)
79011 +{
79012 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
79013 + if (grsec_enable_audit_ptrace)
79014 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
79015 +#endif
79016 + return;
79017 +}
79018 +
79019 +int
79020 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
79021 +{
79022 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
79023 + const struct dentry *dentry = file->f_path.dentry;
79024 + const struct vfsmount *mnt = file->f_path.mnt;
79025 +
79026 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
79027 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
79028 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
79029 + return -EACCES;
79030 + }
79031 +#endif
79032 + return 0;
79033 +}
79034 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
79035 new file mode 100644
79036 index 0000000..3860c7e
79037 --- /dev/null
79038 +++ b/grsecurity/grsec_sig.c
79039 @@ -0,0 +1,236 @@
79040 +#include <linux/kernel.h>
79041 +#include <linux/sched.h>
79042 +#include <linux/fs.h>
79043 +#include <linux/delay.h>
79044 +#include <linux/grsecurity.h>
79045 +#include <linux/grinternal.h>
79046 +#include <linux/hardirq.h>
79047 +
79048 +char *signames[] = {
79049 + [SIGSEGV] = "Segmentation fault",
79050 + [SIGILL] = "Illegal instruction",
79051 + [SIGABRT] = "Abort",
79052 + [SIGBUS] = "Invalid alignment/Bus error"
79053 +};
79054 +
79055 +void
79056 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
79057 +{
79058 +#ifdef CONFIG_GRKERNSEC_SIGNAL
79059 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
79060 + (sig == SIGABRT) || (sig == SIGBUS))) {
79061 + if (task_pid_nr(t) == task_pid_nr(current)) {
79062 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
79063 + } else {
79064 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
79065 + }
79066 + }
79067 +#endif
79068 + return;
79069 +}
79070 +
79071 +int
79072 +gr_handle_signal(const struct task_struct *p, const int sig)
79073 +{
79074 +#ifdef CONFIG_GRKERNSEC
79075 + /* ignore the 0 signal for protected task checks */
79076 + if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
79077 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
79078 + return -EPERM;
79079 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
79080 + return -EPERM;
79081 + }
79082 +#endif
79083 + return 0;
79084 +}
79085 +
79086 +#ifdef CONFIG_GRKERNSEC
79087 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
79088 +
79089 +int gr_fake_force_sig(int sig, struct task_struct *t)
79090 +{
79091 + unsigned long int flags;
79092 + int ret, blocked, ignored;
79093 + struct k_sigaction *action;
79094 +
79095 + spin_lock_irqsave(&t->sighand->siglock, flags);
79096 + action = &t->sighand->action[sig-1];
79097 + ignored = action->sa.sa_handler == SIG_IGN;
79098 + blocked = sigismember(&t->blocked, sig);
79099 + if (blocked || ignored) {
79100 + action->sa.sa_handler = SIG_DFL;
79101 + if (blocked) {
79102 + sigdelset(&t->blocked, sig);
79103 + recalc_sigpending_and_wake(t);
79104 + }
79105 + }
79106 + if (action->sa.sa_handler == SIG_DFL)
79107 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
79108 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
79109 +
79110 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
79111 +
79112 + return ret;
79113 +}
79114 +#endif
79115 +
79116 +#define GR_USER_BAN_TIME (15 * 60)
79117 +#define GR_DAEMON_BRUTE_TIME (30 * 60)
79118 +
79119 +void gr_handle_brute_attach(int dumpable)
79120 +{
79121 +#ifdef CONFIG_GRKERNSEC_BRUTE
79122 + struct task_struct *p = current;
79123 + kuid_t uid = GLOBAL_ROOT_UID;
79124 + int daemon = 0;
79125 +
79126 + if (!grsec_enable_brute)
79127 + return;
79128 +
79129 + rcu_read_lock();
79130 + read_lock(&tasklist_lock);
79131 + read_lock(&grsec_exec_file_lock);
79132 + if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
79133 + p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
79134 + p->real_parent->brute = 1;
79135 + daemon = 1;
79136 + } else {
79137 + const struct cred *cred = __task_cred(p), *cred2;
79138 + struct task_struct *tsk, *tsk2;
79139 +
79140 + if (dumpable != SUID_DUMP_USER && gr_is_global_nonroot(cred->uid)) {
79141 + struct user_struct *user;
79142 +
79143 + uid = cred->uid;
79144 +
79145 + /* this is put upon execution past expiration */
79146 + user = find_user(uid);
79147 + if (user == NULL)
79148 + goto unlock;
79149 + user->suid_banned = 1;
79150 + user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
79151 + if (user->suid_ban_expires == ~0UL)
79152 + user->suid_ban_expires--;
79153 +
79154 + /* only kill other threads of the same binary, from the same user */
79155 + do_each_thread(tsk2, tsk) {
79156 + cred2 = __task_cred(tsk);
79157 + if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
79158 + gr_fake_force_sig(SIGKILL, tsk);
79159 + } while_each_thread(tsk2, tsk);
79160 + }
79161 + }
79162 +unlock:
79163 + read_unlock(&grsec_exec_file_lock);
79164 + read_unlock(&tasklist_lock);
79165 + rcu_read_unlock();
79166 +
79167 + if (gr_is_global_nonroot(uid))
79168 + 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);
79169 + else if (daemon)
79170 + gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
79171 +
79172 +#endif
79173 + return;
79174 +}
79175 +
79176 +void gr_handle_brute_check(void)
79177 +{
79178 +#ifdef CONFIG_GRKERNSEC_BRUTE
79179 + struct task_struct *p = current;
79180 +
79181 + if (unlikely(p->brute)) {
79182 + if (!grsec_enable_brute)
79183 + p->brute = 0;
79184 + else if (time_before(get_seconds(), p->brute_expires))
79185 + msleep(30 * 1000);
79186 + }
79187 +#endif
79188 + return;
79189 +}
79190 +
79191 +void gr_handle_kernel_exploit(void)
79192 +{
79193 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
79194 + const struct cred *cred;
79195 + struct task_struct *tsk, *tsk2;
79196 + struct user_struct *user;
79197 + kuid_t uid;
79198 +
79199 + if (in_irq() || in_serving_softirq() || in_nmi())
79200 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
79201 +
79202 + uid = current_uid();
79203 +
79204 + if (gr_is_global_root(uid))
79205 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
79206 + else {
79207 + /* kill all the processes of this user, hold a reference
79208 + to their creds struct, and prevent them from creating
79209 + another process until system reset
79210 + */
79211 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
79212 + GR_GLOBAL_UID(uid));
79213 + /* we intentionally leak this ref */
79214 + user = get_uid(current->cred->user);
79215 + if (user)
79216 + user->kernel_banned = 1;
79217 +
79218 + /* kill all processes of this user */
79219 + read_lock(&tasklist_lock);
79220 + do_each_thread(tsk2, tsk) {
79221 + cred = __task_cred(tsk);
79222 + if (uid_eq(cred->uid, uid))
79223 + gr_fake_force_sig(SIGKILL, tsk);
79224 + } while_each_thread(tsk2, tsk);
79225 + read_unlock(&tasklist_lock);
79226 + }
79227 +#endif
79228 +}
79229 +
79230 +#ifdef CONFIG_GRKERNSEC_BRUTE
79231 +static bool suid_ban_expired(struct user_struct *user)
79232 +{
79233 + if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
79234 + user->suid_banned = 0;
79235 + user->suid_ban_expires = 0;
79236 + free_uid(user);
79237 + return true;
79238 + }
79239 +
79240 + return false;
79241 +}
79242 +#endif
79243 +
79244 +int gr_process_kernel_exec_ban(void)
79245 +{
79246 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
79247 + if (unlikely(current->cred->user->kernel_banned))
79248 + return -EPERM;
79249 +#endif
79250 + return 0;
79251 +}
79252 +
79253 +int gr_process_kernel_setuid_ban(struct user_struct *user)
79254 +{
79255 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
79256 + if (unlikely(user->kernel_banned))
79257 + gr_fake_force_sig(SIGKILL, current);
79258 +#endif
79259 + return 0;
79260 +}
79261 +
79262 +int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
79263 +{
79264 +#ifdef CONFIG_GRKERNSEC_BRUTE
79265 + struct user_struct *user = current->cred->user;
79266 + if (unlikely(user->suid_banned)) {
79267 + if (suid_ban_expired(user))
79268 + return 0;
79269 + /* disallow execution of suid binaries only */
79270 + else if (!uid_eq(bprm->cred->euid, current->cred->uid))
79271 + return -EPERM;
79272 + }
79273 +#endif
79274 + return 0;
79275 +}
79276 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
79277 new file mode 100644
79278 index 0000000..e3650b6
79279 --- /dev/null
79280 +++ b/grsecurity/grsec_sock.c
79281 @@ -0,0 +1,244 @@
79282 +#include <linux/kernel.h>
79283 +#include <linux/module.h>
79284 +#include <linux/sched.h>
79285 +#include <linux/file.h>
79286 +#include <linux/net.h>
79287 +#include <linux/in.h>
79288 +#include <linux/ip.h>
79289 +#include <net/sock.h>
79290 +#include <net/inet_sock.h>
79291 +#include <linux/grsecurity.h>
79292 +#include <linux/grinternal.h>
79293 +#include <linux/gracl.h>
79294 +
79295 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
79296 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
79297 +
79298 +EXPORT_SYMBOL_GPL(gr_search_udp_recvmsg);
79299 +EXPORT_SYMBOL_GPL(gr_search_udp_sendmsg);
79300 +
79301 +#ifdef CONFIG_UNIX_MODULE
79302 +EXPORT_SYMBOL_GPL(gr_acl_handle_unix);
79303 +EXPORT_SYMBOL_GPL(gr_acl_handle_mknod);
79304 +EXPORT_SYMBOL_GPL(gr_handle_chroot_unix);
79305 +EXPORT_SYMBOL_GPL(gr_handle_create);
79306 +#endif
79307 +
79308 +#ifdef CONFIG_GRKERNSEC
79309 +#define gr_conn_table_size 32749
79310 +struct conn_table_entry {
79311 + struct conn_table_entry *next;
79312 + struct signal_struct *sig;
79313 +};
79314 +
79315 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
79316 +DEFINE_SPINLOCK(gr_conn_table_lock);
79317 +
79318 +extern const char * gr_socktype_to_name(unsigned char type);
79319 +extern const char * gr_proto_to_name(unsigned char proto);
79320 +extern const char * gr_sockfamily_to_name(unsigned char family);
79321 +
79322 +static __inline__ int
79323 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
79324 +{
79325 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
79326 +}
79327 +
79328 +static __inline__ int
79329 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
79330 + __u16 sport, __u16 dport)
79331 +{
79332 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
79333 + sig->gr_sport == sport && sig->gr_dport == dport))
79334 + return 1;
79335 + else
79336 + return 0;
79337 +}
79338 +
79339 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
79340 +{
79341 + struct conn_table_entry **match;
79342 + unsigned int index;
79343 +
79344 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
79345 + sig->gr_sport, sig->gr_dport,
79346 + gr_conn_table_size);
79347 +
79348 + newent->sig = sig;
79349 +
79350 + match = &gr_conn_table[index];
79351 + newent->next = *match;
79352 + *match = newent;
79353 +
79354 + return;
79355 +}
79356 +
79357 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
79358 +{
79359 + struct conn_table_entry *match, *last = NULL;
79360 + unsigned int index;
79361 +
79362 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
79363 + sig->gr_sport, sig->gr_dport,
79364 + gr_conn_table_size);
79365 +
79366 + match = gr_conn_table[index];
79367 + while (match && !conn_match(match->sig,
79368 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
79369 + sig->gr_dport)) {
79370 + last = match;
79371 + match = match->next;
79372 + }
79373 +
79374 + if (match) {
79375 + if (last)
79376 + last->next = match->next;
79377 + else
79378 + gr_conn_table[index] = NULL;
79379 + kfree(match);
79380 + }
79381 +
79382 + return;
79383 +}
79384 +
79385 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
79386 + __u16 sport, __u16 dport)
79387 +{
79388 + struct conn_table_entry *match;
79389 + unsigned int index;
79390 +
79391 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
79392 +
79393 + match = gr_conn_table[index];
79394 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
79395 + match = match->next;
79396 +
79397 + if (match)
79398 + return match->sig;
79399 + else
79400 + return NULL;
79401 +}
79402 +
79403 +#endif
79404 +
79405 +void gr_update_task_in_ip_table(const struct inet_sock *inet)
79406 +{
79407 +#ifdef CONFIG_GRKERNSEC
79408 + struct signal_struct *sig = current->signal;
79409 + struct conn_table_entry *newent;
79410 +
79411 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
79412 + if (newent == NULL)
79413 + return;
79414 + /* no bh lock needed since we are called with bh disabled */
79415 + spin_lock(&gr_conn_table_lock);
79416 + gr_del_task_from_ip_table_nolock(sig);
79417 + sig->gr_saddr = inet->inet_rcv_saddr;
79418 + sig->gr_daddr = inet->inet_daddr;
79419 + sig->gr_sport = inet->inet_sport;
79420 + sig->gr_dport = inet->inet_dport;
79421 + gr_add_to_task_ip_table_nolock(sig, newent);
79422 + spin_unlock(&gr_conn_table_lock);
79423 +#endif
79424 + return;
79425 +}
79426 +
79427 +void gr_del_task_from_ip_table(struct task_struct *task)
79428 +{
79429 +#ifdef CONFIG_GRKERNSEC
79430 + spin_lock_bh(&gr_conn_table_lock);
79431 + gr_del_task_from_ip_table_nolock(task->signal);
79432 + spin_unlock_bh(&gr_conn_table_lock);
79433 +#endif
79434 + return;
79435 +}
79436 +
79437 +void
79438 +gr_attach_curr_ip(const struct sock *sk)
79439 +{
79440 +#ifdef CONFIG_GRKERNSEC
79441 + struct signal_struct *p, *set;
79442 + const struct inet_sock *inet = inet_sk(sk);
79443 +
79444 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
79445 + return;
79446 +
79447 + set = current->signal;
79448 +
79449 + spin_lock_bh(&gr_conn_table_lock);
79450 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
79451 + inet->inet_dport, inet->inet_sport);
79452 + if (unlikely(p != NULL)) {
79453 + set->curr_ip = p->curr_ip;
79454 + set->used_accept = 1;
79455 + gr_del_task_from_ip_table_nolock(p);
79456 + spin_unlock_bh(&gr_conn_table_lock);
79457 + return;
79458 + }
79459 + spin_unlock_bh(&gr_conn_table_lock);
79460 +
79461 + set->curr_ip = inet->inet_daddr;
79462 + set->used_accept = 1;
79463 +#endif
79464 + return;
79465 +}
79466 +
79467 +int
79468 +gr_handle_sock_all(const int family, const int type, const int protocol)
79469 +{
79470 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
79471 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
79472 + (family != AF_UNIX)) {
79473 + if (family == AF_INET)
79474 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
79475 + else
79476 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
79477 + return -EACCES;
79478 + }
79479 +#endif
79480 + return 0;
79481 +}
79482 +
79483 +int
79484 +gr_handle_sock_server(const struct sockaddr *sck)
79485 +{
79486 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
79487 + if (grsec_enable_socket_server &&
79488 + in_group_p(grsec_socket_server_gid) &&
79489 + sck && (sck->sa_family != AF_UNIX) &&
79490 + (sck->sa_family != AF_LOCAL)) {
79491 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
79492 + return -EACCES;
79493 + }
79494 +#endif
79495 + return 0;
79496 +}
79497 +
79498 +int
79499 +gr_handle_sock_server_other(const struct sock *sck)
79500 +{
79501 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
79502 + if (grsec_enable_socket_server &&
79503 + in_group_p(grsec_socket_server_gid) &&
79504 + sck && (sck->sk_family != AF_UNIX) &&
79505 + (sck->sk_family != AF_LOCAL)) {
79506 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
79507 + return -EACCES;
79508 + }
79509 +#endif
79510 + return 0;
79511 +}
79512 +
79513 +int
79514 +gr_handle_sock_client(const struct sockaddr *sck)
79515 +{
79516 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
79517 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
79518 + sck && (sck->sa_family != AF_UNIX) &&
79519 + (sck->sa_family != AF_LOCAL)) {
79520 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
79521 + return -EACCES;
79522 + }
79523 +#endif
79524 + return 0;
79525 +}
79526 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
79527 new file mode 100644
79528 index 0000000..8159888
79529 --- /dev/null
79530 +++ b/grsecurity/grsec_sysctl.c
79531 @@ -0,0 +1,479 @@
79532 +#include <linux/kernel.h>
79533 +#include <linux/sched.h>
79534 +#include <linux/sysctl.h>
79535 +#include <linux/grsecurity.h>
79536 +#include <linux/grinternal.h>
79537 +
79538 +int
79539 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
79540 +{
79541 +#ifdef CONFIG_GRKERNSEC_SYSCTL
79542 + if (dirname == NULL || name == NULL)
79543 + return 0;
79544 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
79545 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
79546 + return -EACCES;
79547 + }
79548 +#endif
79549 + return 0;
79550 +}
79551 +
79552 +#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
79553 +static int __maybe_unused __read_only one = 1;
79554 +#endif
79555 +
79556 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
79557 + defined(CONFIG_GRKERNSEC_DENYUSB)
79558 +struct ctl_table grsecurity_table[] = {
79559 +#ifdef CONFIG_GRKERNSEC_SYSCTL
79560 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
79561 +#ifdef CONFIG_GRKERNSEC_IO
79562 + {
79563 + .procname = "disable_priv_io",
79564 + .data = &grsec_disable_privio,
79565 + .maxlen = sizeof(int),
79566 + .mode = 0600,
79567 + .proc_handler = &proc_dointvec,
79568 + },
79569 +#endif
79570 +#endif
79571 +#ifdef CONFIG_GRKERNSEC_LINK
79572 + {
79573 + .procname = "linking_restrictions",
79574 + .data = &grsec_enable_link,
79575 + .maxlen = sizeof(int),
79576 + .mode = 0600,
79577 + .proc_handler = &proc_dointvec,
79578 + },
79579 +#endif
79580 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
79581 + {
79582 + .procname = "enforce_symlinksifowner",
79583 + .data = &grsec_enable_symlinkown,
79584 + .maxlen = sizeof(int),
79585 + .mode = 0600,
79586 + .proc_handler = &proc_dointvec,
79587 + },
79588 + {
79589 + .procname = "symlinkown_gid",
79590 + .data = &grsec_symlinkown_gid,
79591 + .maxlen = sizeof(int),
79592 + .mode = 0600,
79593 + .proc_handler = &proc_dointvec,
79594 + },
79595 +#endif
79596 +#ifdef CONFIG_GRKERNSEC_BRUTE
79597 + {
79598 + .procname = "deter_bruteforce",
79599 + .data = &grsec_enable_brute,
79600 + .maxlen = sizeof(int),
79601 + .mode = 0600,
79602 + .proc_handler = &proc_dointvec,
79603 + },
79604 +#endif
79605 +#ifdef CONFIG_GRKERNSEC_FIFO
79606 + {
79607 + .procname = "fifo_restrictions",
79608 + .data = &grsec_enable_fifo,
79609 + .maxlen = sizeof(int),
79610 + .mode = 0600,
79611 + .proc_handler = &proc_dointvec,
79612 + },
79613 +#endif
79614 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
79615 + {
79616 + .procname = "ptrace_readexec",
79617 + .data = &grsec_enable_ptrace_readexec,
79618 + .maxlen = sizeof(int),
79619 + .mode = 0600,
79620 + .proc_handler = &proc_dointvec,
79621 + },
79622 +#endif
79623 +#ifdef CONFIG_GRKERNSEC_SETXID
79624 + {
79625 + .procname = "consistent_setxid",
79626 + .data = &grsec_enable_setxid,
79627 + .maxlen = sizeof(int),
79628 + .mode = 0600,
79629 + .proc_handler = &proc_dointvec,
79630 + },
79631 +#endif
79632 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79633 + {
79634 + .procname = "ip_blackhole",
79635 + .data = &grsec_enable_blackhole,
79636 + .maxlen = sizeof(int),
79637 + .mode = 0600,
79638 + .proc_handler = &proc_dointvec,
79639 + },
79640 + {
79641 + .procname = "lastack_retries",
79642 + .data = &grsec_lastack_retries,
79643 + .maxlen = sizeof(int),
79644 + .mode = 0600,
79645 + .proc_handler = &proc_dointvec,
79646 + },
79647 +#endif
79648 +#ifdef CONFIG_GRKERNSEC_EXECLOG
79649 + {
79650 + .procname = "exec_logging",
79651 + .data = &grsec_enable_execlog,
79652 + .maxlen = sizeof(int),
79653 + .mode = 0600,
79654 + .proc_handler = &proc_dointvec,
79655 + },
79656 +#endif
79657 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
79658 + {
79659 + .procname = "rwxmap_logging",
79660 + .data = &grsec_enable_log_rwxmaps,
79661 + .maxlen = sizeof(int),
79662 + .mode = 0600,
79663 + .proc_handler = &proc_dointvec,
79664 + },
79665 +#endif
79666 +#ifdef CONFIG_GRKERNSEC_SIGNAL
79667 + {
79668 + .procname = "signal_logging",
79669 + .data = &grsec_enable_signal,
79670 + .maxlen = sizeof(int),
79671 + .mode = 0600,
79672 + .proc_handler = &proc_dointvec,
79673 + },
79674 +#endif
79675 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
79676 + {
79677 + .procname = "forkfail_logging",
79678 + .data = &grsec_enable_forkfail,
79679 + .maxlen = sizeof(int),
79680 + .mode = 0600,
79681 + .proc_handler = &proc_dointvec,
79682 + },
79683 +#endif
79684 +#ifdef CONFIG_GRKERNSEC_TIME
79685 + {
79686 + .procname = "timechange_logging",
79687 + .data = &grsec_enable_time,
79688 + .maxlen = sizeof(int),
79689 + .mode = 0600,
79690 + .proc_handler = &proc_dointvec,
79691 + },
79692 +#endif
79693 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
79694 + {
79695 + .procname = "chroot_deny_shmat",
79696 + .data = &grsec_enable_chroot_shmat,
79697 + .maxlen = sizeof(int),
79698 + .mode = 0600,
79699 + .proc_handler = &proc_dointvec,
79700 + },
79701 +#endif
79702 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
79703 + {
79704 + .procname = "chroot_deny_unix",
79705 + .data = &grsec_enable_chroot_unix,
79706 + .maxlen = sizeof(int),
79707 + .mode = 0600,
79708 + .proc_handler = &proc_dointvec,
79709 + },
79710 +#endif
79711 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
79712 + {
79713 + .procname = "chroot_deny_mount",
79714 + .data = &grsec_enable_chroot_mount,
79715 + .maxlen = sizeof(int),
79716 + .mode = 0600,
79717 + .proc_handler = &proc_dointvec,
79718 + },
79719 +#endif
79720 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
79721 + {
79722 + .procname = "chroot_deny_fchdir",
79723 + .data = &grsec_enable_chroot_fchdir,
79724 + .maxlen = sizeof(int),
79725 + .mode = 0600,
79726 + .proc_handler = &proc_dointvec,
79727 + },
79728 +#endif
79729 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
79730 + {
79731 + .procname = "chroot_deny_chroot",
79732 + .data = &grsec_enable_chroot_double,
79733 + .maxlen = sizeof(int),
79734 + .mode = 0600,
79735 + .proc_handler = &proc_dointvec,
79736 + },
79737 +#endif
79738 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
79739 + {
79740 + .procname = "chroot_deny_pivot",
79741 + .data = &grsec_enable_chroot_pivot,
79742 + .maxlen = sizeof(int),
79743 + .mode = 0600,
79744 + .proc_handler = &proc_dointvec,
79745 + },
79746 +#endif
79747 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
79748 + {
79749 + .procname = "chroot_enforce_chdir",
79750 + .data = &grsec_enable_chroot_chdir,
79751 + .maxlen = sizeof(int),
79752 + .mode = 0600,
79753 + .proc_handler = &proc_dointvec,
79754 + },
79755 +#endif
79756 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
79757 + {
79758 + .procname = "chroot_deny_chmod",
79759 + .data = &grsec_enable_chroot_chmod,
79760 + .maxlen = sizeof(int),
79761 + .mode = 0600,
79762 + .proc_handler = &proc_dointvec,
79763 + },
79764 +#endif
79765 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
79766 + {
79767 + .procname = "chroot_deny_mknod",
79768 + .data = &grsec_enable_chroot_mknod,
79769 + .maxlen = sizeof(int),
79770 + .mode = 0600,
79771 + .proc_handler = &proc_dointvec,
79772 + },
79773 +#endif
79774 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
79775 + {
79776 + .procname = "chroot_restrict_nice",
79777 + .data = &grsec_enable_chroot_nice,
79778 + .maxlen = sizeof(int),
79779 + .mode = 0600,
79780 + .proc_handler = &proc_dointvec,
79781 + },
79782 +#endif
79783 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
79784 + {
79785 + .procname = "chroot_execlog",
79786 + .data = &grsec_enable_chroot_execlog,
79787 + .maxlen = sizeof(int),
79788 + .mode = 0600,
79789 + .proc_handler = &proc_dointvec,
79790 + },
79791 +#endif
79792 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
79793 + {
79794 + .procname = "chroot_caps",
79795 + .data = &grsec_enable_chroot_caps,
79796 + .maxlen = sizeof(int),
79797 + .mode = 0600,
79798 + .proc_handler = &proc_dointvec,
79799 + },
79800 +#endif
79801 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
79802 + {
79803 + .procname = "chroot_deny_sysctl",
79804 + .data = &grsec_enable_chroot_sysctl,
79805 + .maxlen = sizeof(int),
79806 + .mode = 0600,
79807 + .proc_handler = &proc_dointvec,
79808 + },
79809 +#endif
79810 +#ifdef CONFIG_GRKERNSEC_TPE
79811 + {
79812 + .procname = "tpe",
79813 + .data = &grsec_enable_tpe,
79814 + .maxlen = sizeof(int),
79815 + .mode = 0600,
79816 + .proc_handler = &proc_dointvec,
79817 + },
79818 + {
79819 + .procname = "tpe_gid",
79820 + .data = &grsec_tpe_gid,
79821 + .maxlen = sizeof(int),
79822 + .mode = 0600,
79823 + .proc_handler = &proc_dointvec,
79824 + },
79825 +#endif
79826 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
79827 + {
79828 + .procname = "tpe_invert",
79829 + .data = &grsec_enable_tpe_invert,
79830 + .maxlen = sizeof(int),
79831 + .mode = 0600,
79832 + .proc_handler = &proc_dointvec,
79833 + },
79834 +#endif
79835 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
79836 + {
79837 + .procname = "tpe_restrict_all",
79838 + .data = &grsec_enable_tpe_all,
79839 + .maxlen = sizeof(int),
79840 + .mode = 0600,
79841 + .proc_handler = &proc_dointvec,
79842 + },
79843 +#endif
79844 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
79845 + {
79846 + .procname = "socket_all",
79847 + .data = &grsec_enable_socket_all,
79848 + .maxlen = sizeof(int),
79849 + .mode = 0600,
79850 + .proc_handler = &proc_dointvec,
79851 + },
79852 + {
79853 + .procname = "socket_all_gid",
79854 + .data = &grsec_socket_all_gid,
79855 + .maxlen = sizeof(int),
79856 + .mode = 0600,
79857 + .proc_handler = &proc_dointvec,
79858 + },
79859 +#endif
79860 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
79861 + {
79862 + .procname = "socket_client",
79863 + .data = &grsec_enable_socket_client,
79864 + .maxlen = sizeof(int),
79865 + .mode = 0600,
79866 + .proc_handler = &proc_dointvec,
79867 + },
79868 + {
79869 + .procname = "socket_client_gid",
79870 + .data = &grsec_socket_client_gid,
79871 + .maxlen = sizeof(int),
79872 + .mode = 0600,
79873 + .proc_handler = &proc_dointvec,
79874 + },
79875 +#endif
79876 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
79877 + {
79878 + .procname = "socket_server",
79879 + .data = &grsec_enable_socket_server,
79880 + .maxlen = sizeof(int),
79881 + .mode = 0600,
79882 + .proc_handler = &proc_dointvec,
79883 + },
79884 + {
79885 + .procname = "socket_server_gid",
79886 + .data = &grsec_socket_server_gid,
79887 + .maxlen = sizeof(int),
79888 + .mode = 0600,
79889 + .proc_handler = &proc_dointvec,
79890 + },
79891 +#endif
79892 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
79893 + {
79894 + .procname = "audit_group",
79895 + .data = &grsec_enable_group,
79896 + .maxlen = sizeof(int),
79897 + .mode = 0600,
79898 + .proc_handler = &proc_dointvec,
79899 + },
79900 + {
79901 + .procname = "audit_gid",
79902 + .data = &grsec_audit_gid,
79903 + .maxlen = sizeof(int),
79904 + .mode = 0600,
79905 + .proc_handler = &proc_dointvec,
79906 + },
79907 +#endif
79908 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
79909 + {
79910 + .procname = "audit_chdir",
79911 + .data = &grsec_enable_chdir,
79912 + .maxlen = sizeof(int),
79913 + .mode = 0600,
79914 + .proc_handler = &proc_dointvec,
79915 + },
79916 +#endif
79917 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
79918 + {
79919 + .procname = "audit_mount",
79920 + .data = &grsec_enable_mount,
79921 + .maxlen = sizeof(int),
79922 + .mode = 0600,
79923 + .proc_handler = &proc_dointvec,
79924 + },
79925 +#endif
79926 +#ifdef CONFIG_GRKERNSEC_DMESG
79927 + {
79928 + .procname = "dmesg",
79929 + .data = &grsec_enable_dmesg,
79930 + .maxlen = sizeof(int),
79931 + .mode = 0600,
79932 + .proc_handler = &proc_dointvec,
79933 + },
79934 +#endif
79935 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
79936 + {
79937 + .procname = "chroot_findtask",
79938 + .data = &grsec_enable_chroot_findtask,
79939 + .maxlen = sizeof(int),
79940 + .mode = 0600,
79941 + .proc_handler = &proc_dointvec,
79942 + },
79943 +#endif
79944 +#ifdef CONFIG_GRKERNSEC_RESLOG
79945 + {
79946 + .procname = "resource_logging",
79947 + .data = &grsec_resource_logging,
79948 + .maxlen = sizeof(int),
79949 + .mode = 0600,
79950 + .proc_handler = &proc_dointvec,
79951 + },
79952 +#endif
79953 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
79954 + {
79955 + .procname = "audit_ptrace",
79956 + .data = &grsec_enable_audit_ptrace,
79957 + .maxlen = sizeof(int),
79958 + .mode = 0600,
79959 + .proc_handler = &proc_dointvec,
79960 + },
79961 +#endif
79962 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
79963 + {
79964 + .procname = "harden_ptrace",
79965 + .data = &grsec_enable_harden_ptrace,
79966 + .maxlen = sizeof(int),
79967 + .mode = 0600,
79968 + .proc_handler = &proc_dointvec,
79969 + },
79970 +#endif
79971 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
79972 + {
79973 + .procname = "harden_ipc",
79974 + .data = &grsec_enable_harden_ipc,
79975 + .maxlen = sizeof(int),
79976 + .mode = 0600,
79977 + .proc_handler = &proc_dointvec,
79978 + },
79979 +#endif
79980 + {
79981 + .procname = "grsec_lock",
79982 + .data = &grsec_lock,
79983 + .maxlen = sizeof(int),
79984 + .mode = 0600,
79985 + .proc_handler = &proc_dointvec,
79986 + },
79987 +#endif
79988 +#ifdef CONFIG_GRKERNSEC_ROFS
79989 + {
79990 + .procname = "romount_protect",
79991 + .data = &grsec_enable_rofs,
79992 + .maxlen = sizeof(int),
79993 + .mode = 0600,
79994 + .proc_handler = &proc_dointvec_minmax,
79995 + .extra1 = &one,
79996 + .extra2 = &one,
79997 + },
79998 +#endif
79999 +#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
80000 + {
80001 + .procname = "deny_new_usb",
80002 + .data = &grsec_deny_new_usb,
80003 + .maxlen = sizeof(int),
80004 + .mode = 0600,
80005 + .proc_handler = &proc_dointvec,
80006 + },
80007 +#endif
80008 + { }
80009 +};
80010 +#endif
80011 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
80012 new file mode 100644
80013 index 0000000..61b514e
80014 --- /dev/null
80015 +++ b/grsecurity/grsec_time.c
80016 @@ -0,0 +1,16 @@
80017 +#include <linux/kernel.h>
80018 +#include <linux/sched.h>
80019 +#include <linux/grinternal.h>
80020 +#include <linux/module.h>
80021 +
80022 +void
80023 +gr_log_timechange(void)
80024 +{
80025 +#ifdef CONFIG_GRKERNSEC_TIME
80026 + if (grsec_enable_time)
80027 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
80028 +#endif
80029 + return;
80030 +}
80031 +
80032 +EXPORT_SYMBOL_GPL(gr_log_timechange);
80033 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
80034 new file mode 100644
80035 index 0000000..d1953de
80036 --- /dev/null
80037 +++ b/grsecurity/grsec_tpe.c
80038 @@ -0,0 +1,78 @@
80039 +#include <linux/kernel.h>
80040 +#include <linux/sched.h>
80041 +#include <linux/file.h>
80042 +#include <linux/fs.h>
80043 +#include <linux/grinternal.h>
80044 +
80045 +extern int gr_acl_tpe_check(void);
80046 +
80047 +int
80048 +gr_tpe_allow(const struct file *file)
80049 +{
80050 +#ifdef CONFIG_GRKERNSEC
80051 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
80052 + struct inode *file_inode = file->f_path.dentry->d_inode;
80053 + const struct cred *cred = current_cred();
80054 + char *msg = NULL;
80055 + char *msg2 = NULL;
80056 +
80057 + // never restrict root
80058 + if (gr_is_global_root(cred->uid))
80059 + return 1;
80060 +
80061 + if (grsec_enable_tpe) {
80062 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
80063 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
80064 + msg = "not being in trusted group";
80065 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
80066 + msg = "being in untrusted group";
80067 +#else
80068 + if (in_group_p(grsec_tpe_gid))
80069 + msg = "being in untrusted group";
80070 +#endif
80071 + }
80072 + if (!msg && gr_acl_tpe_check())
80073 + msg = "being in untrusted role";
80074 +
80075 + // not in any affected group/role
80076 + if (!msg)
80077 + goto next_check;
80078 +
80079 + if (gr_is_global_nonroot(inode->i_uid))
80080 + msg2 = "file in non-root-owned directory";
80081 + else if (inode->i_mode & S_IWOTH)
80082 + msg2 = "file in world-writable directory";
80083 + else if (inode->i_mode & S_IWGRP)
80084 + msg2 = "file in group-writable directory";
80085 + else if (file_inode->i_mode & S_IWOTH)
80086 + msg2 = "file is world-writable";
80087 +
80088 + if (msg && msg2) {
80089 + char fullmsg[70] = {0};
80090 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
80091 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
80092 + return 0;
80093 + }
80094 + msg = NULL;
80095 +next_check:
80096 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
80097 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
80098 + return 1;
80099 +
80100 + if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
80101 + msg = "directory not owned by user";
80102 + else if (inode->i_mode & S_IWOTH)
80103 + msg = "file in world-writable directory";
80104 + else if (inode->i_mode & S_IWGRP)
80105 + msg = "file in group-writable directory";
80106 + else if (file_inode->i_mode & S_IWOTH)
80107 + msg = "file is world-writable";
80108 +
80109 + if (msg) {
80110 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
80111 + return 0;
80112 + }
80113 +#endif
80114 +#endif
80115 + return 1;
80116 +}
80117 diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
80118 new file mode 100644
80119 index 0000000..ae02d8e
80120 --- /dev/null
80121 +++ b/grsecurity/grsec_usb.c
80122 @@ -0,0 +1,15 @@
80123 +#include <linux/kernel.h>
80124 +#include <linux/grinternal.h>
80125 +#include <linux/module.h>
80126 +
80127 +int gr_handle_new_usb(void)
80128 +{
80129 +#ifdef CONFIG_GRKERNSEC_DENYUSB
80130 + if (grsec_deny_new_usb) {
80131 + printk(KERN_ALERT "grsec: denied insert of new USB device\n");
80132 + return 1;
80133 + }
80134 +#endif
80135 + return 0;
80136 +}
80137 +EXPORT_SYMBOL_GPL(gr_handle_new_usb);
80138 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
80139 new file mode 100644
80140 index 0000000..158b330
80141 --- /dev/null
80142 +++ b/grsecurity/grsum.c
80143 @@ -0,0 +1,64 @@
80144 +#include <linux/err.h>
80145 +#include <linux/kernel.h>
80146 +#include <linux/sched.h>
80147 +#include <linux/mm.h>
80148 +#include <linux/scatterlist.h>
80149 +#include <linux/crypto.h>
80150 +#include <linux/gracl.h>
80151 +
80152 +
80153 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
80154 +#error "crypto and sha256 must be built into the kernel"
80155 +#endif
80156 +
80157 +int
80158 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
80159 +{
80160 + struct crypto_hash *tfm;
80161 + struct hash_desc desc;
80162 + struct scatterlist sg[2];
80163 + unsigned char temp_sum[GR_SHA_LEN] __attribute__((aligned(__alignof__(unsigned long))));
80164 + unsigned long *tmpsumptr = (unsigned long *)temp_sum;
80165 + unsigned long *sumptr = (unsigned long *)sum;
80166 + int cryptres;
80167 + int retval = 1;
80168 + volatile int mismatched = 0;
80169 + volatile int dummy = 0;
80170 + unsigned int i;
80171 +
80172 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
80173 + if (IS_ERR(tfm)) {
80174 + /* should never happen, since sha256 should be built in */
80175 + memset(entry->pw, 0, GR_PW_LEN);
80176 + return 1;
80177 + }
80178 +
80179 + sg_init_table(sg, 2);
80180 + sg_set_buf(&sg[0], salt, GR_SALT_LEN);
80181 + sg_set_buf(&sg[1], entry->pw, strlen(entry->pw));
80182 +
80183 + desc.tfm = tfm;
80184 + desc.flags = 0;
80185 +
80186 + cryptres = crypto_hash_digest(&desc, sg, GR_SALT_LEN + strlen(entry->pw),
80187 + temp_sum);
80188 +
80189 + memset(entry->pw, 0, GR_PW_LEN);
80190 +
80191 + if (cryptres)
80192 + goto out;
80193 +
80194 + for (i = 0; i < GR_SHA_LEN/sizeof(tmpsumptr[0]); i++)
80195 + if (sumptr[i] != tmpsumptr[i])
80196 + mismatched = 1;
80197 + else
80198 + dummy = 1; // waste a cycle
80199 +
80200 + if (!mismatched)
80201 + retval = dummy - 1;
80202 +
80203 +out:
80204 + crypto_free_hash(tfm);
80205 +
80206 + return retval;
80207 +}
80208 diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
80209 index 77ff547..181834f 100644
80210 --- a/include/asm-generic/4level-fixup.h
80211 +++ b/include/asm-generic/4level-fixup.h
80212 @@ -13,8 +13,10 @@
80213 #define pmd_alloc(mm, pud, address) \
80214 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
80215 NULL: pmd_offset(pud, address))
80216 +#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
80217
80218 #define pud_alloc(mm, pgd, address) (pgd)
80219 +#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
80220 #define pud_offset(pgd, start) (pgd)
80221 #define pud_none(pud) 0
80222 #define pud_bad(pud) 0
80223 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
80224 index b7babf0..1e4b4f1 100644
80225 --- a/include/asm-generic/atomic-long.h
80226 +++ b/include/asm-generic/atomic-long.h
80227 @@ -22,6 +22,12 @@
80228
80229 typedef atomic64_t atomic_long_t;
80230
80231 +#ifdef CONFIG_PAX_REFCOUNT
80232 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
80233 +#else
80234 +typedef atomic64_t atomic_long_unchecked_t;
80235 +#endif
80236 +
80237 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
80238
80239 static inline long atomic_long_read(atomic_long_t *l)
80240 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
80241 return (long)atomic64_read(v);
80242 }
80243
80244 +#ifdef CONFIG_PAX_REFCOUNT
80245 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
80246 +{
80247 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
80248 +
80249 + return (long)atomic64_read_unchecked(v);
80250 +}
80251 +#endif
80252 +
80253 static inline void atomic_long_set(atomic_long_t *l, long i)
80254 {
80255 atomic64_t *v = (atomic64_t *)l;
80256 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
80257 atomic64_set(v, i);
80258 }
80259
80260 +#ifdef CONFIG_PAX_REFCOUNT
80261 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
80262 +{
80263 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
80264 +
80265 + atomic64_set_unchecked(v, i);
80266 +}
80267 +#endif
80268 +
80269 static inline void atomic_long_inc(atomic_long_t *l)
80270 {
80271 atomic64_t *v = (atomic64_t *)l;
80272 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
80273 atomic64_inc(v);
80274 }
80275
80276 +#ifdef CONFIG_PAX_REFCOUNT
80277 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
80278 +{
80279 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
80280 +
80281 + atomic64_inc_unchecked(v);
80282 +}
80283 +#endif
80284 +
80285 static inline void atomic_long_dec(atomic_long_t *l)
80286 {
80287 atomic64_t *v = (atomic64_t *)l;
80288 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
80289 atomic64_dec(v);
80290 }
80291
80292 +#ifdef CONFIG_PAX_REFCOUNT
80293 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
80294 +{
80295 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
80296 +
80297 + atomic64_dec_unchecked(v);
80298 +}
80299 +#endif
80300 +
80301 static inline void atomic_long_add(long i, atomic_long_t *l)
80302 {
80303 atomic64_t *v = (atomic64_t *)l;
80304 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
80305 atomic64_add(i, v);
80306 }
80307
80308 +#ifdef CONFIG_PAX_REFCOUNT
80309 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
80310 +{
80311 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
80312 +
80313 + atomic64_add_unchecked(i, v);
80314 +}
80315 +#endif
80316 +
80317 static inline void atomic_long_sub(long i, atomic_long_t *l)
80318 {
80319 atomic64_t *v = (atomic64_t *)l;
80320 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
80321 atomic64_sub(i, v);
80322 }
80323
80324 +#ifdef CONFIG_PAX_REFCOUNT
80325 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
80326 +{
80327 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
80328 +
80329 + atomic64_sub_unchecked(i, v);
80330 +}
80331 +#endif
80332 +
80333 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
80334 {
80335 atomic64_t *v = (atomic64_t *)l;
80336 @@ -94,13 +154,22 @@ static inline int atomic_long_add_negative(long i, atomic_long_t *l)
80337 return atomic64_add_negative(i, v);
80338 }
80339
80340 -static inline long atomic_long_add_return(long i, atomic_long_t *l)
80341 +static inline long __intentional_overflow(-1) atomic_long_add_return(long i, atomic_long_t *l)
80342 {
80343 atomic64_t *v = (atomic64_t *)l;
80344
80345 return (long)atomic64_add_return(i, v);
80346 }
80347
80348 +#ifdef CONFIG_PAX_REFCOUNT
80349 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
80350 +{
80351 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
80352 +
80353 + return (long)atomic64_add_return_unchecked(i, v);
80354 +}
80355 +#endif
80356 +
80357 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
80358 {
80359 atomic64_t *v = (atomic64_t *)l;
80360 @@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
80361 return (long)atomic64_inc_return(v);
80362 }
80363
80364 +#ifdef CONFIG_PAX_REFCOUNT
80365 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
80366 +{
80367 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
80368 +
80369 + return (long)atomic64_inc_return_unchecked(v);
80370 +}
80371 +#endif
80372 +
80373 static inline long atomic_long_dec_return(atomic_long_t *l)
80374 {
80375 atomic64_t *v = (atomic64_t *)l;
80376 @@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
80377
80378 typedef atomic_t atomic_long_t;
80379
80380 +#ifdef CONFIG_PAX_REFCOUNT
80381 +typedef atomic_unchecked_t atomic_long_unchecked_t;
80382 +#else
80383 +typedef atomic_t atomic_long_unchecked_t;
80384 +#endif
80385 +
80386 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
80387 static inline long atomic_long_read(atomic_long_t *l)
80388 {
80389 @@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
80390 return (long)atomic_read(v);
80391 }
80392
80393 +#ifdef CONFIG_PAX_REFCOUNT
80394 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
80395 +{
80396 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
80397 +
80398 + return (long)atomic_read_unchecked(v);
80399 +}
80400 +#endif
80401 +
80402 static inline void atomic_long_set(atomic_long_t *l, long i)
80403 {
80404 atomic_t *v = (atomic_t *)l;
80405 @@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
80406 atomic_set(v, i);
80407 }
80408
80409 +#ifdef CONFIG_PAX_REFCOUNT
80410 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
80411 +{
80412 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
80413 +
80414 + atomic_set_unchecked(v, i);
80415 +}
80416 +#endif
80417 +
80418 static inline void atomic_long_inc(atomic_long_t *l)
80419 {
80420 atomic_t *v = (atomic_t *)l;
80421 @@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
80422 atomic_inc(v);
80423 }
80424
80425 +#ifdef CONFIG_PAX_REFCOUNT
80426 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
80427 +{
80428 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
80429 +
80430 + atomic_inc_unchecked(v);
80431 +}
80432 +#endif
80433 +
80434 static inline void atomic_long_dec(atomic_long_t *l)
80435 {
80436 atomic_t *v = (atomic_t *)l;
80437 @@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
80438 atomic_dec(v);
80439 }
80440
80441 +#ifdef CONFIG_PAX_REFCOUNT
80442 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
80443 +{
80444 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
80445 +
80446 + atomic_dec_unchecked(v);
80447 +}
80448 +#endif
80449 +
80450 static inline void atomic_long_add(long i, atomic_long_t *l)
80451 {
80452 atomic_t *v = (atomic_t *)l;
80453 @@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
80454 atomic_add(i, v);
80455 }
80456
80457 +#ifdef CONFIG_PAX_REFCOUNT
80458 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
80459 +{
80460 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
80461 +
80462 + atomic_add_unchecked(i, v);
80463 +}
80464 +#endif
80465 +
80466 static inline void atomic_long_sub(long i, atomic_long_t *l)
80467 {
80468 atomic_t *v = (atomic_t *)l;
80469 @@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
80470 atomic_sub(i, v);
80471 }
80472
80473 +#ifdef CONFIG_PAX_REFCOUNT
80474 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
80475 +{
80476 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
80477 +
80478 + atomic_sub_unchecked(i, v);
80479 +}
80480 +#endif
80481 +
80482 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
80483 {
80484 atomic_t *v = (atomic_t *)l;
80485 @@ -211,13 +349,23 @@ static inline int atomic_long_add_negative(long i, atomic_long_t *l)
80486 return atomic_add_negative(i, v);
80487 }
80488
80489 -static inline long atomic_long_add_return(long i, atomic_long_t *l)
80490 +static inline long __intentional_overflow(-1) atomic_long_add_return(long i, atomic_long_t *l)
80491 {
80492 atomic_t *v = (atomic_t *)l;
80493
80494 return (long)atomic_add_return(i, v);
80495 }
80496
80497 +#ifdef CONFIG_PAX_REFCOUNT
80498 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
80499 +{
80500 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
80501 +
80502 + return (long)atomic_add_return_unchecked(i, v);
80503 +}
80504 +
80505 +#endif
80506 +
80507 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
80508 {
80509 atomic_t *v = (atomic_t *)l;
80510 @@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
80511 return (long)atomic_inc_return(v);
80512 }
80513
80514 +#ifdef CONFIG_PAX_REFCOUNT
80515 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
80516 +{
80517 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
80518 +
80519 + return (long)atomic_inc_return_unchecked(v);
80520 +}
80521 +#endif
80522 +
80523 static inline long atomic_long_dec_return(atomic_long_t *l)
80524 {
80525 atomic_t *v = (atomic_t *)l;
80526 @@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
80527
80528 #endif /* BITS_PER_LONG == 64 */
80529
80530 +#ifdef CONFIG_PAX_REFCOUNT
80531 +static inline void pax_refcount_needs_these_functions(void)
80532 +{
80533 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
80534 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
80535 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
80536 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
80537 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
80538 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
80539 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
80540 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
80541 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
80542 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
80543 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
80544 +#ifdef CONFIG_X86
80545 + atomic_clear_mask_unchecked(0, NULL);
80546 + atomic_set_mask_unchecked(0, NULL);
80547 +#endif
80548 +
80549 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
80550 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
80551 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
80552 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
80553 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
80554 + atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
80555 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
80556 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
80557 +}
80558 +#else
80559 +#define atomic_read_unchecked(v) atomic_read(v)
80560 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
80561 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
80562 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
80563 +#define atomic_inc_unchecked(v) atomic_inc(v)
80564 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
80565 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
80566 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
80567 +#define atomic_dec_unchecked(v) atomic_dec(v)
80568 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
80569 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
80570 +#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
80571 +#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
80572 +
80573 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
80574 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
80575 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
80576 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
80577 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
80578 +#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
80579 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
80580 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
80581 +#endif
80582 +
80583 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
80584 diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
80585 index 9c79e76..9f7827d 100644
80586 --- a/include/asm-generic/atomic.h
80587 +++ b/include/asm-generic/atomic.h
80588 @@ -154,7 +154,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
80589 * Atomically clears the bits set in @mask from @v
80590 */
80591 #ifndef atomic_clear_mask
80592 -static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
80593 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
80594 {
80595 unsigned long flags;
80596
80597 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
80598 index b18ce4f..2ee2843 100644
80599 --- a/include/asm-generic/atomic64.h
80600 +++ b/include/asm-generic/atomic64.h
80601 @@ -16,6 +16,8 @@ typedef struct {
80602 long long counter;
80603 } atomic64_t;
80604
80605 +typedef atomic64_t atomic64_unchecked_t;
80606 +
80607 #define ATOMIC64_INIT(i) { (i) }
80608
80609 extern long long atomic64_read(const atomic64_t *v);
80610 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
80611 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
80612 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
80613
80614 +#define atomic64_read_unchecked(v) atomic64_read(v)
80615 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
80616 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
80617 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
80618 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
80619 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
80620 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
80621 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
80622 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
80623 +
80624 #endif /* _ASM_GENERIC_ATOMIC64_H */
80625 diff --git a/include/asm-generic/barrier.h b/include/asm-generic/barrier.h
80626 index 1402fa8..025a736 100644
80627 --- a/include/asm-generic/barrier.h
80628 +++ b/include/asm-generic/barrier.h
80629 @@ -74,7 +74,7 @@
80630 do { \
80631 compiletime_assert_atomic_type(*p); \
80632 smp_mb(); \
80633 - ACCESS_ONCE(*p) = (v); \
80634 + ACCESS_ONCE_RW(*p) = (v); \
80635 } while (0)
80636
80637 #define smp_load_acquire(p) \
80638 diff --git a/include/asm-generic/bitops/__fls.h b/include/asm-generic/bitops/__fls.h
80639 index a60a7cc..0fe12f2 100644
80640 --- a/include/asm-generic/bitops/__fls.h
80641 +++ b/include/asm-generic/bitops/__fls.h
80642 @@ -9,7 +9,7 @@
80643 *
80644 * Undefined if no set bit exists, so code should check against 0 first.
80645 */
80646 -static __always_inline unsigned long __fls(unsigned long word)
80647 +static __always_inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
80648 {
80649 int num = BITS_PER_LONG - 1;
80650
80651 diff --git a/include/asm-generic/bitops/fls.h b/include/asm-generic/bitops/fls.h
80652 index 0576d1f..dad6c71 100644
80653 --- a/include/asm-generic/bitops/fls.h
80654 +++ b/include/asm-generic/bitops/fls.h
80655 @@ -9,7 +9,7 @@
80656 * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
80657 */
80658
80659 -static __always_inline int fls(int x)
80660 +static __always_inline int __intentional_overflow(-1) fls(int x)
80661 {
80662 int r = 32;
80663
80664 diff --git a/include/asm-generic/bitops/fls64.h b/include/asm-generic/bitops/fls64.h
80665 index b097cf8..3d40e14 100644
80666 --- a/include/asm-generic/bitops/fls64.h
80667 +++ b/include/asm-generic/bitops/fls64.h
80668 @@ -15,7 +15,7 @@
80669 * at position 64.
80670 */
80671 #if BITS_PER_LONG == 32
80672 -static __always_inline int fls64(__u64 x)
80673 +static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
80674 {
80675 __u32 h = x >> 32;
80676 if (h)
80677 @@ -23,7 +23,7 @@ static __always_inline int fls64(__u64 x)
80678 return fls(x);
80679 }
80680 #elif BITS_PER_LONG == 64
80681 -static __always_inline int fls64(__u64 x)
80682 +static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
80683 {
80684 if (x == 0)
80685 return 0;
80686 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
80687 index 1bfcfe5..e04c5c9 100644
80688 --- a/include/asm-generic/cache.h
80689 +++ b/include/asm-generic/cache.h
80690 @@ -6,7 +6,7 @@
80691 * cache lines need to provide their own cache.h.
80692 */
80693
80694 -#define L1_CACHE_SHIFT 5
80695 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
80696 +#define L1_CACHE_SHIFT 5UL
80697 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
80698
80699 #endif /* __ASM_GENERIC_CACHE_H */
80700 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
80701 index 0d68a1e..b74a761 100644
80702 --- a/include/asm-generic/emergency-restart.h
80703 +++ b/include/asm-generic/emergency-restart.h
80704 @@ -1,7 +1,7 @@
80705 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
80706 #define _ASM_GENERIC_EMERGENCY_RESTART_H
80707
80708 -static inline void machine_emergency_restart(void)
80709 +static inline __noreturn void machine_emergency_restart(void)
80710 {
80711 machine_restart(NULL);
80712 }
80713 diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h
80714 index 975e1cc..0b8a083 100644
80715 --- a/include/asm-generic/io.h
80716 +++ b/include/asm-generic/io.h
80717 @@ -289,7 +289,7 @@ static inline void pci_iounmap(struct pci_dev *dev, void __iomem *p)
80718 * These are pretty trivial
80719 */
80720 #ifndef virt_to_phys
80721 -static inline unsigned long virt_to_phys(volatile void *address)
80722 +static inline unsigned long __intentional_overflow(-1) virt_to_phys(volatile void *address)
80723 {
80724 return __pa((unsigned long)address);
80725 }
80726 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
80727 index 90f99c7..00ce236 100644
80728 --- a/include/asm-generic/kmap_types.h
80729 +++ b/include/asm-generic/kmap_types.h
80730 @@ -2,9 +2,9 @@
80731 #define _ASM_GENERIC_KMAP_TYPES_H
80732
80733 #ifdef __WITH_KM_FENCE
80734 -# define KM_TYPE_NR 41
80735 +# define KM_TYPE_NR 42
80736 #else
80737 -# define KM_TYPE_NR 20
80738 +# define KM_TYPE_NR 21
80739 #endif
80740
80741 #endif
80742 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
80743 index 9ceb03b..62b0b8f 100644
80744 --- a/include/asm-generic/local.h
80745 +++ b/include/asm-generic/local.h
80746 @@ -23,24 +23,37 @@ typedef struct
80747 atomic_long_t a;
80748 } local_t;
80749
80750 +typedef struct {
80751 + atomic_long_unchecked_t a;
80752 +} local_unchecked_t;
80753 +
80754 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
80755
80756 #define local_read(l) atomic_long_read(&(l)->a)
80757 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
80758 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
80759 +#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
80760 #define local_inc(l) atomic_long_inc(&(l)->a)
80761 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
80762 #define local_dec(l) atomic_long_dec(&(l)->a)
80763 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
80764 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
80765 +#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
80766 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
80767 +#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
80768
80769 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
80770 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
80771 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
80772 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
80773 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
80774 +#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
80775 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
80776 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
80777 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
80778
80779 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
80780 +#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
80781 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
80782 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
80783 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
80784 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
80785 index 725612b..9cc513a 100644
80786 --- a/include/asm-generic/pgtable-nopmd.h
80787 +++ b/include/asm-generic/pgtable-nopmd.h
80788 @@ -1,14 +1,19 @@
80789 #ifndef _PGTABLE_NOPMD_H
80790 #define _PGTABLE_NOPMD_H
80791
80792 -#ifndef __ASSEMBLY__
80793 -
80794 #include <asm-generic/pgtable-nopud.h>
80795
80796 -struct mm_struct;
80797 -
80798 #define __PAGETABLE_PMD_FOLDED
80799
80800 +#define PMD_SHIFT PUD_SHIFT
80801 +#define PTRS_PER_PMD 1
80802 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
80803 +#define PMD_MASK (~(PMD_SIZE-1))
80804 +
80805 +#ifndef __ASSEMBLY__
80806 +
80807 +struct mm_struct;
80808 +
80809 /*
80810 * Having the pmd type consist of a pud gets the size right, and allows
80811 * us to conceptually access the pud entry that this pmd is folded into
80812 @@ -16,11 +21,6 @@ struct mm_struct;
80813 */
80814 typedef struct { pud_t pud; } pmd_t;
80815
80816 -#define PMD_SHIFT PUD_SHIFT
80817 -#define PTRS_PER_PMD 1
80818 -#define PMD_SIZE (1UL << PMD_SHIFT)
80819 -#define PMD_MASK (~(PMD_SIZE-1))
80820 -
80821 /*
80822 * The "pud_xxx()" functions here are trivial for a folded two-level
80823 * setup: the pmd is never bad, and a pmd always exists (as it's folded
80824 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
80825 index 810431d..0ec4804f 100644
80826 --- a/include/asm-generic/pgtable-nopud.h
80827 +++ b/include/asm-generic/pgtable-nopud.h
80828 @@ -1,10 +1,15 @@
80829 #ifndef _PGTABLE_NOPUD_H
80830 #define _PGTABLE_NOPUD_H
80831
80832 -#ifndef __ASSEMBLY__
80833 -
80834 #define __PAGETABLE_PUD_FOLDED
80835
80836 +#define PUD_SHIFT PGDIR_SHIFT
80837 +#define PTRS_PER_PUD 1
80838 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
80839 +#define PUD_MASK (~(PUD_SIZE-1))
80840 +
80841 +#ifndef __ASSEMBLY__
80842 +
80843 /*
80844 * Having the pud type consist of a pgd gets the size right, and allows
80845 * us to conceptually access the pgd entry that this pud is folded into
80846 @@ -12,11 +17,6 @@
80847 */
80848 typedef struct { pgd_t pgd; } pud_t;
80849
80850 -#define PUD_SHIFT PGDIR_SHIFT
80851 -#define PTRS_PER_PUD 1
80852 -#define PUD_SIZE (1UL << PUD_SHIFT)
80853 -#define PUD_MASK (~(PUD_SIZE-1))
80854 -
80855 /*
80856 * The "pgd_xxx()" functions here are trivial for a folded two-level
80857 * setup: the pud is never bad, and a pud always exists (as it's folded
80858 @@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
80859 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
80860
80861 #define pgd_populate(mm, pgd, pud) do { } while (0)
80862 +#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
80863 /*
80864 * (puds are folded into pgds so this doesn't get actually called,
80865 * but the define is needed for a generic inline function.)
80866 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
80867 index 53b2acc..f4568e7 100644
80868 --- a/include/asm-generic/pgtable.h
80869 +++ b/include/asm-generic/pgtable.h
80870 @@ -819,6 +819,22 @@ static inline void pmdp_set_numa(struct mm_struct *mm, unsigned long addr,
80871 }
80872 #endif /* CONFIG_NUMA_BALANCING */
80873
80874 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
80875 +#ifdef CONFIG_PAX_KERNEXEC
80876 +#error KERNEXEC requires pax_open_kernel
80877 +#else
80878 +static inline unsigned long pax_open_kernel(void) { return 0; }
80879 +#endif
80880 +#endif
80881 +
80882 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
80883 +#ifdef CONFIG_PAX_KERNEXEC
80884 +#error KERNEXEC requires pax_close_kernel
80885 +#else
80886 +static inline unsigned long pax_close_kernel(void) { return 0; }
80887 +#endif
80888 +#endif
80889 +
80890 #endif /* CONFIG_MMU */
80891
80892 #endif /* !__ASSEMBLY__ */
80893 diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
80894 index 72d8803..cb9749c 100644
80895 --- a/include/asm-generic/uaccess.h
80896 +++ b/include/asm-generic/uaccess.h
80897 @@ -343,4 +343,20 @@ clear_user(void __user *to, unsigned long n)
80898 return __clear_user(to, n);
80899 }
80900
80901 +#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
80902 +#ifdef CONFIG_PAX_MEMORY_UDEREF
80903 +#error UDEREF requires pax_open_userland
80904 +#else
80905 +static inline unsigned long pax_open_userland(void) { return 0; }
80906 +#endif
80907 +#endif
80908 +
80909 +#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
80910 +#ifdef CONFIG_PAX_MEMORY_UDEREF
80911 +#error UDEREF requires pax_close_userland
80912 +#else
80913 +static inline unsigned long pax_close_userland(void) { return 0; }
80914 +#endif
80915 +#endif
80916 +
80917 #endif /* __ASM_GENERIC_UACCESS_H */
80918 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
80919 index 5ba0360..e85c934 100644
80920 --- a/include/asm-generic/vmlinux.lds.h
80921 +++ b/include/asm-generic/vmlinux.lds.h
80922 @@ -231,6 +231,7 @@
80923 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
80924 VMLINUX_SYMBOL(__start_rodata) = .; \
80925 *(.rodata) *(.rodata.*) \
80926 + *(.data..read_only) \
80927 *(__vermagic) /* Kernel version magic */ \
80928 . = ALIGN(8); \
80929 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
80930 @@ -722,17 +723,18 @@
80931 * section in the linker script will go there too. @phdr should have
80932 * a leading colon.
80933 *
80934 - * Note that this macros defines __per_cpu_load as an absolute symbol.
80935 + * Note that this macros defines per_cpu_load as an absolute symbol.
80936 * If there is no need to put the percpu section at a predetermined
80937 * address, use PERCPU_SECTION.
80938 */
80939 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
80940 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
80941 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
80942 + per_cpu_load = .; \
80943 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
80944 - LOAD_OFFSET) { \
80945 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
80946 PERCPU_INPUT(cacheline) \
80947 } phdr \
80948 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
80949 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
80950
80951 /**
80952 * PERCPU_SECTION - define output section for percpu area, simple version
80953 diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
80954 index 623a59c..1e79ab9 100644
80955 --- a/include/crypto/algapi.h
80956 +++ b/include/crypto/algapi.h
80957 @@ -34,7 +34,7 @@ struct crypto_type {
80958 unsigned int maskclear;
80959 unsigned int maskset;
80960 unsigned int tfmsize;
80961 -};
80962 +} __do_const;
80963
80964 struct crypto_instance {
80965 struct crypto_alg alg;
80966 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
80967 index 1968907..7d9ed9f 100644
80968 --- a/include/drm/drmP.h
80969 +++ b/include/drm/drmP.h
80970 @@ -68,6 +68,7 @@
80971 #include <linux/workqueue.h>
80972 #include <linux/poll.h>
80973 #include <asm/pgalloc.h>
80974 +#include <asm/local.h>
80975 #include <drm/drm.h>
80976 #include <drm/drm_sarea.h>
80977 #include <drm/drm_vma_manager.h>
80978 @@ -260,10 +261,12 @@ do { \
80979 * \param cmd command.
80980 * \param arg argument.
80981 */
80982 -typedef int drm_ioctl_t(struct drm_device *dev, void *data,
80983 +typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
80984 + struct drm_file *file_priv);
80985 +typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
80986 struct drm_file *file_priv);
80987
80988 -typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
80989 +typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
80990 unsigned long arg);
80991
80992 #define DRM_IOCTL_NR(n) _IOC_NR(n)
80993 @@ -279,10 +282,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
80994 struct drm_ioctl_desc {
80995 unsigned int cmd;
80996 int flags;
80997 - drm_ioctl_t *func;
80998 + drm_ioctl_t func;
80999 unsigned int cmd_drv;
81000 const char *name;
81001 -};
81002 +} __do_const;
81003
81004 /**
81005 * Creates a driver or general drm_ioctl_desc array entry for the given
81006 @@ -946,7 +949,8 @@ struct drm_info_list {
81007 int (*show)(struct seq_file*, void*); /** show callback */
81008 u32 driver_features; /**< Required driver features for this entry */
81009 void *data;
81010 -};
81011 +} __do_const;
81012 +typedef struct drm_info_list __no_const drm_info_list_no_const;
81013
81014 /**
81015 * debugfs node structure. This structure represents a debugfs file.
81016 @@ -1030,7 +1034,7 @@ struct drm_device {
81017
81018 /** \name Usage Counters */
81019 /*@{ */
81020 - int open_count; /**< Outstanding files open, protected by drm_global_mutex. */
81021 + local_t open_count; /**< Outstanding files open, protected by drm_global_mutex. */
81022 spinlock_t buf_lock; /**< For drm_device::buf_use and a few other things. */
81023 int buf_use; /**< Buffers in use -- cannot alloc */
81024 atomic_t buf_alloc; /**< Buffer allocation in progress */
81025 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
81026 index a3d75fe..6802f9c 100644
81027 --- a/include/drm/drm_crtc_helper.h
81028 +++ b/include/drm/drm_crtc_helper.h
81029 @@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
81030 struct drm_connector *connector);
81031 /* disable encoder when not in use - more explicit than dpms off */
81032 void (*disable)(struct drm_encoder *encoder);
81033 -};
81034 +} __no_const;
81035
81036 /**
81037 * drm_connector_helper_funcs - helper operations for connectors
81038 diff --git a/include/drm/i915_pciids.h b/include/drm/i915_pciids.h
81039 index a70d456..6ea07cd 100644
81040 --- a/include/drm/i915_pciids.h
81041 +++ b/include/drm/i915_pciids.h
81042 @@ -37,7 +37,7 @@
81043 */
81044 #define INTEL_VGA_DEVICE(id, info) { \
81045 0x8086, id, \
81046 - ~0, ~0, \
81047 + PCI_ANY_ID, PCI_ANY_ID, \
81048 0x030000, 0xff0000, \
81049 (unsigned long) info }
81050
81051 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
81052 index 72dcbe8..8db58d7 100644
81053 --- a/include/drm/ttm/ttm_memory.h
81054 +++ b/include/drm/ttm/ttm_memory.h
81055 @@ -48,7 +48,7 @@
81056
81057 struct ttm_mem_shrink {
81058 int (*do_shrink) (struct ttm_mem_shrink *);
81059 -};
81060 +} __no_const;
81061
81062 /**
81063 * struct ttm_mem_global - Global memory accounting structure.
81064 diff --git a/include/drm/ttm/ttm_page_alloc.h b/include/drm/ttm/ttm_page_alloc.h
81065 index 49a8284..9643967 100644
81066 --- a/include/drm/ttm/ttm_page_alloc.h
81067 +++ b/include/drm/ttm/ttm_page_alloc.h
81068 @@ -80,6 +80,7 @@ void ttm_dma_page_alloc_fini(void);
81069 */
81070 extern int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data);
81071
81072 +struct device;
81073 extern int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev);
81074 extern void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev);
81075
81076 diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
81077 index 4b840e8..155d235 100644
81078 --- a/include/keys/asymmetric-subtype.h
81079 +++ b/include/keys/asymmetric-subtype.h
81080 @@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
81081 /* Verify the signature on a key of this subtype (optional) */
81082 int (*verify_signature)(const struct key *key,
81083 const struct public_key_signature *sig);
81084 -};
81085 +} __do_const;
81086
81087 /**
81088 * asymmetric_key_subtype - Get the subtype from an asymmetric key
81089 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
81090 index c1da539..1dcec55 100644
81091 --- a/include/linux/atmdev.h
81092 +++ b/include/linux/atmdev.h
81093 @@ -28,7 +28,7 @@ struct compat_atm_iobuf {
81094 #endif
81095
81096 struct k_atm_aal_stats {
81097 -#define __HANDLE_ITEM(i) atomic_t i
81098 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
81099 __AAL_STAT_ITEMS
81100 #undef __HANDLE_ITEM
81101 };
81102 @@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
81103 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
81104 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
81105 struct module *owner;
81106 -};
81107 +} __do_const ;
81108
81109 struct atmphy_ops {
81110 int (*start)(struct atm_dev *dev);
81111 diff --git a/include/linux/audit.h b/include/linux/audit.h
81112 index 22cfddb..1514eef 100644
81113 --- a/include/linux/audit.h
81114 +++ b/include/linux/audit.h
81115 @@ -86,7 +86,7 @@ extern unsigned compat_dir_class[];
81116 extern unsigned compat_chattr_class[];
81117 extern unsigned compat_signal_class[];
81118
81119 -extern int __weak audit_classify_compat_syscall(int abi, unsigned syscall);
81120 +extern int audit_classify_compat_syscall(int abi, unsigned syscall);
81121
81122 /* audit_names->type values */
81123 #define AUDIT_TYPE_UNKNOWN 0 /* we don't know yet */
81124 @@ -210,7 +210,7 @@ static inline void audit_ptrace(struct task_struct *t)
81125 extern unsigned int audit_serial(void);
81126 extern int auditsc_get_stamp(struct audit_context *ctx,
81127 struct timespec *t, unsigned int *serial);
81128 -extern int audit_set_loginuid(kuid_t loginuid);
81129 +extern int __intentional_overflow(-1) audit_set_loginuid(kuid_t loginuid);
81130
81131 static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
81132 {
81133 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
81134 index 61f29e5..e67c658 100644
81135 --- a/include/linux/binfmts.h
81136 +++ b/include/linux/binfmts.h
81137 @@ -44,7 +44,7 @@ struct linux_binprm {
81138 unsigned interp_flags;
81139 unsigned interp_data;
81140 unsigned long loader, exec;
81141 -};
81142 +} __randomize_layout;
81143
81144 #define BINPRM_FLAGS_ENFORCE_NONDUMP_BIT 0
81145 #define BINPRM_FLAGS_ENFORCE_NONDUMP (1 << BINPRM_FLAGS_ENFORCE_NONDUMP_BIT)
81146 @@ -73,8 +73,10 @@ struct linux_binfmt {
81147 int (*load_binary)(struct linux_binprm *);
81148 int (*load_shlib)(struct file *);
81149 int (*core_dump)(struct coredump_params *cprm);
81150 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
81151 + void (*handle_mmap)(struct file *);
81152 unsigned long min_coredump; /* minimal dump size */
81153 -};
81154 +} __do_const __randomize_layout;
81155
81156 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
81157
81158 diff --git a/include/linux/bitops.h b/include/linux/bitops.h
81159 index 38b5f5c..645018c 100644
81160 --- a/include/linux/bitops.h
81161 +++ b/include/linux/bitops.h
81162 @@ -125,7 +125,7 @@ static inline __u64 ror64(__u64 word, unsigned int shift)
81163 * @word: value to rotate
81164 * @shift: bits to roll
81165 */
81166 -static inline __u32 rol32(__u32 word, unsigned int shift)
81167 +static inline __u32 __intentional_overflow(-1) rol32(__u32 word, unsigned int shift)
81168 {
81169 return (word << shift) | (word >> (32 - shift));
81170 }
81171 @@ -135,7 +135,7 @@ static inline __u32 rol32(__u32 word, unsigned int shift)
81172 * @word: value to rotate
81173 * @shift: bits to roll
81174 */
81175 -static inline __u32 ror32(__u32 word, unsigned int shift)
81176 +static inline __u32 __intentional_overflow(-1) ror32(__u32 word, unsigned int shift)
81177 {
81178 return (word >> shift) | (word << (32 - shift));
81179 }
81180 @@ -191,7 +191,7 @@ static inline __s32 sign_extend32(__u32 value, int index)
81181 return (__s32)(value << shift) >> shift;
81182 }
81183
81184 -static inline unsigned fls_long(unsigned long l)
81185 +static inline unsigned __intentional_overflow(-1) fls_long(unsigned long l)
81186 {
81187 if (sizeof(l) == 4)
81188 return fls(l);
81189 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
81190 index f2057ff8..59dfa2d 100644
81191 --- a/include/linux/blkdev.h
81192 +++ b/include/linux/blkdev.h
81193 @@ -1625,7 +1625,7 @@ struct block_device_operations {
81194 /* this callback is with swap_lock and sometimes page table lock held */
81195 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
81196 struct module *owner;
81197 -};
81198 +} __do_const;
81199
81200 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
81201 unsigned long);
81202 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
81203 index afc1343..9735539 100644
81204 --- a/include/linux/blktrace_api.h
81205 +++ b/include/linux/blktrace_api.h
81206 @@ -25,7 +25,7 @@ struct blk_trace {
81207 struct dentry *dropped_file;
81208 struct dentry *msg_file;
81209 struct list_head running_list;
81210 - atomic_t dropped;
81211 + atomic_unchecked_t dropped;
81212 };
81213
81214 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
81215 diff --git a/include/linux/cache.h b/include/linux/cache.h
81216 index 17e7e82..1d7da26 100644
81217 --- a/include/linux/cache.h
81218 +++ b/include/linux/cache.h
81219 @@ -16,6 +16,14 @@
81220 #define __read_mostly
81221 #endif
81222
81223 +#ifndef __read_only
81224 +#ifdef CONFIG_PAX_KERNEXEC
81225 +#error KERNEXEC requires __read_only
81226 +#else
81227 +#define __read_only __read_mostly
81228 +#endif
81229 +#endif
81230 +
81231 #ifndef ____cacheline_aligned
81232 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
81233 #endif
81234 diff --git a/include/linux/capability.h b/include/linux/capability.h
81235 index aa93e5e..985a1b0 100644
81236 --- a/include/linux/capability.h
81237 +++ b/include/linux/capability.h
81238 @@ -214,9 +214,14 @@ extern bool has_ns_capability_noaudit(struct task_struct *t,
81239 extern bool capable(int cap);
81240 extern bool ns_capable(struct user_namespace *ns, int cap);
81241 extern bool capable_wrt_inode_uidgid(const struct inode *inode, int cap);
81242 +extern bool capable_wrt_inode_uidgid_nolog(const struct inode *inode, int cap);
81243 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
81244 +extern bool capable_nolog(int cap);
81245 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
81246
81247 /* audit system wants to get cap info from files as well */
81248 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
81249
81250 +extern int is_privileged_binary(const struct dentry *dentry);
81251 +
81252 #endif /* !_LINUX_CAPABILITY_H */
81253 diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
81254 index 8609d57..86e4d79 100644
81255 --- a/include/linux/cdrom.h
81256 +++ b/include/linux/cdrom.h
81257 @@ -87,7 +87,6 @@ struct cdrom_device_ops {
81258
81259 /* driver specifications */
81260 const int capability; /* capability flags */
81261 - int n_minors; /* number of active minor devices */
81262 /* handle uniform packets for scsi type devices (scsi,atapi) */
81263 int (*generic_packet) (struct cdrom_device_info *,
81264 struct packet_command *);
81265 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
81266 index 4ce9056..86caac6 100644
81267 --- a/include/linux/cleancache.h
81268 +++ b/include/linux/cleancache.h
81269 @@ -31,7 +31,7 @@ struct cleancache_ops {
81270 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
81271 void (*invalidate_inode)(int, struct cleancache_filekey);
81272 void (*invalidate_fs)(int);
81273 -};
81274 +} __no_const;
81275
81276 extern struct cleancache_ops *
81277 cleancache_register_ops(struct cleancache_ops *ops);
81278 diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
81279 index da6996e..9d13d5f 100644
81280 --- a/include/linux/clk-provider.h
81281 +++ b/include/linux/clk-provider.h
81282 @@ -180,6 +180,7 @@ struct clk_ops {
81283 void (*init)(struct clk_hw *hw);
81284 int (*debug_init)(struct clk_hw *hw, struct dentry *dentry);
81285 };
81286 +typedef struct clk_ops __no_const clk_ops_no_const;
81287
81288 /**
81289 * struct clk_init_data - holds init data that's common to all clocks and is
81290 diff --git a/include/linux/compat.h b/include/linux/compat.h
81291 index e649426..a74047b 100644
81292 --- a/include/linux/compat.h
81293 +++ b/include/linux/compat.h
81294 @@ -316,7 +316,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
81295 compat_size_t __user *len_ptr);
81296
81297 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
81298 -asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
81299 +asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
81300 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
81301 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
81302 compat_ssize_t msgsz, int msgflg);
81303 @@ -436,7 +436,7 @@ extern int compat_ptrace_request(struct task_struct *child,
81304 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
81305 compat_ulong_t addr, compat_ulong_t data);
81306 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
81307 - compat_long_t addr, compat_long_t data);
81308 + compat_ulong_t addr, compat_ulong_t data);
81309
81310 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, compat_size_t);
81311 /*
81312 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
81313 index 2507fd2..55203f8 100644
81314 --- a/include/linux/compiler-gcc4.h
81315 +++ b/include/linux/compiler-gcc4.h
81316 @@ -39,9 +39,34 @@
81317 # define __compiletime_warning(message) __attribute__((warning(message)))
81318 # define __compiletime_error(message) __attribute__((error(message)))
81319 #endif /* __CHECKER__ */
81320 +
81321 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
81322 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
81323 +#define __bos0(ptr) __bos((ptr), 0)
81324 +#define __bos1(ptr) __bos((ptr), 1)
81325 #endif /* GCC_VERSION >= 40300 */
81326
81327 #if GCC_VERSION >= 40500
81328 +
81329 +#ifdef RANDSTRUCT_PLUGIN
81330 +#define __randomize_layout __attribute__((randomize_layout))
81331 +#define __no_randomize_layout __attribute__((no_randomize_layout))
81332 +#endif
81333 +
81334 +#ifdef CONSTIFY_PLUGIN
81335 +#define __no_const __attribute__((no_const))
81336 +#define __do_const __attribute__((do_const))
81337 +#endif
81338 +
81339 +#ifdef SIZE_OVERFLOW_PLUGIN
81340 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
81341 +#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
81342 +#endif
81343 +
81344 +#ifdef LATENT_ENTROPY_PLUGIN
81345 +#define __latent_entropy __attribute__((latent_entropy))
81346 +#endif
81347 +
81348 /*
81349 * Mark a position in code as unreachable. This can be used to
81350 * suppress control flow warnings after asm blocks that transfer
81351 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
81352 index d5ad7b1..3b74638 100644
81353 --- a/include/linux/compiler.h
81354 +++ b/include/linux/compiler.h
81355 @@ -5,11 +5,14 @@
81356
81357 #ifdef __CHECKER__
81358 # define __user __attribute__((noderef, address_space(1)))
81359 +# define __force_user __force __user
81360 # define __kernel __attribute__((address_space(0)))
81361 +# define __force_kernel __force __kernel
81362 # define __safe __attribute__((safe))
81363 # define __force __attribute__((force))
81364 # define __nocast __attribute__((nocast))
81365 # define __iomem __attribute__((noderef, address_space(2)))
81366 +# define __force_iomem __force __iomem
81367 # define __must_hold(x) __attribute__((context(x,1,1)))
81368 # define __acquires(x) __attribute__((context(x,0,1)))
81369 # define __releases(x) __attribute__((context(x,1,0)))
81370 @@ -17,20 +20,37 @@
81371 # define __release(x) __context__(x,-1)
81372 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
81373 # define __percpu __attribute__((noderef, address_space(3)))
81374 +# define __force_percpu __force __percpu
81375 #ifdef CONFIG_SPARSE_RCU_POINTER
81376 # define __rcu __attribute__((noderef, address_space(4)))
81377 +# define __force_rcu __force __rcu
81378 #else
81379 # define __rcu
81380 +# define __force_rcu
81381 #endif
81382 extern void __chk_user_ptr(const volatile void __user *);
81383 extern void __chk_io_ptr(const volatile void __iomem *);
81384 #else
81385 -# define __user
81386 -# define __kernel
81387 +# ifdef CHECKER_PLUGIN
81388 +//# define __user
81389 +//# define __force_user
81390 +//# define __kernel
81391 +//# define __force_kernel
81392 +# else
81393 +# ifdef STRUCTLEAK_PLUGIN
81394 +# define __user __attribute__((user))
81395 +# else
81396 +# define __user
81397 +# endif
81398 +# define __force_user
81399 +# define __kernel
81400 +# define __force_kernel
81401 +# endif
81402 # define __safe
81403 # define __force
81404 # define __nocast
81405 # define __iomem
81406 +# define __force_iomem
81407 # define __chk_user_ptr(x) (void)0
81408 # define __chk_io_ptr(x) (void)0
81409 # define __builtin_warning(x, y...) (1)
81410 @@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
81411 # define __release(x) (void)0
81412 # define __cond_lock(x,c) (c)
81413 # define __percpu
81414 +# define __force_percpu
81415 # define __rcu
81416 +# define __force_rcu
81417 #endif
81418
81419 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
81420 @@ -286,6 +308,34 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
81421 # define __attribute_const__ /* unimplemented */
81422 #endif
81423
81424 +#ifndef __randomize_layout
81425 +# define __randomize_layout
81426 +#endif
81427 +
81428 +#ifndef __no_randomize_layout
81429 +# define __no_randomize_layout
81430 +#endif
81431 +
81432 +#ifndef __no_const
81433 +# define __no_const
81434 +#endif
81435 +
81436 +#ifndef __do_const
81437 +# define __do_const
81438 +#endif
81439 +
81440 +#ifndef __size_overflow
81441 +# define __size_overflow(...)
81442 +#endif
81443 +
81444 +#ifndef __intentional_overflow
81445 +# define __intentional_overflow(...)
81446 +#endif
81447 +
81448 +#ifndef __latent_entropy
81449 +# define __latent_entropy
81450 +#endif
81451 +
81452 /*
81453 * Tell gcc if a function is cold. The compiler will assume any path
81454 * directly leading to the call is unlikely.
81455 @@ -295,6 +345,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
81456 #define __cold
81457 #endif
81458
81459 +#ifndef __alloc_size
81460 +#define __alloc_size(...)
81461 +#endif
81462 +
81463 +#ifndef __bos
81464 +#define __bos(ptr, arg)
81465 +#endif
81466 +
81467 +#ifndef __bos0
81468 +#define __bos0(ptr)
81469 +#endif
81470 +
81471 +#ifndef __bos1
81472 +#define __bos1(ptr)
81473 +#endif
81474 +
81475 /* Simple shorthand for a section definition */
81476 #ifndef __section
81477 # define __section(S) __attribute__ ((__section__(#S)))
81478 @@ -378,7 +444,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
81479 * use is to mediate communication between process-level code and irq/NMI
81480 * handlers, all running on the same CPU.
81481 */
81482 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
81483 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
81484 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
81485
81486 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
81487 #ifdef CONFIG_KPROBES
81488 diff --git a/include/linux/completion.h b/include/linux/completion.h
81489 index 5d5aaae..0ea9b84 100644
81490 --- a/include/linux/completion.h
81491 +++ b/include/linux/completion.h
81492 @@ -90,16 +90,16 @@ static inline void reinit_completion(struct completion *x)
81493
81494 extern void wait_for_completion(struct completion *);
81495 extern void wait_for_completion_io(struct completion *);
81496 -extern int wait_for_completion_interruptible(struct completion *x);
81497 -extern int wait_for_completion_killable(struct completion *x);
81498 +extern int wait_for_completion_interruptible(struct completion *x) __intentional_overflow(-1);
81499 +extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
81500 extern unsigned long wait_for_completion_timeout(struct completion *x,
81501 - unsigned long timeout);
81502 + unsigned long timeout) __intentional_overflow(-1);
81503 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
81504 - unsigned long timeout);
81505 + unsigned long timeout) __intentional_overflow(-1);
81506 extern long wait_for_completion_interruptible_timeout(
81507 - struct completion *x, unsigned long timeout);
81508 + struct completion *x, unsigned long timeout) __intentional_overflow(-1);
81509 extern long wait_for_completion_killable_timeout(
81510 - struct completion *x, unsigned long timeout);
81511 + struct completion *x, unsigned long timeout) __intentional_overflow(-1);
81512 extern bool try_wait_for_completion(struct completion *x);
81513 extern bool completion_done(struct completion *x);
81514
81515 diff --git a/include/linux/configfs.h b/include/linux/configfs.h
81516 index 34025df..d94bbbc 100644
81517 --- a/include/linux/configfs.h
81518 +++ b/include/linux/configfs.h
81519 @@ -125,7 +125,7 @@ struct configfs_attribute {
81520 const char *ca_name;
81521 struct module *ca_owner;
81522 umode_t ca_mode;
81523 -};
81524 +} __do_const;
81525
81526 /*
81527 * Users often need to create attribute structures for their configurable
81528 diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
81529 index 7d1955a..d86a3ca 100644
81530 --- a/include/linux/cpufreq.h
81531 +++ b/include/linux/cpufreq.h
81532 @@ -203,6 +203,7 @@ struct global_attr {
81533 ssize_t (*store)(struct kobject *a, struct attribute *b,
81534 const char *c, size_t count);
81535 };
81536 +typedef struct global_attr __no_const global_attr_no_const;
81537
81538 #define define_one_global_ro(_name) \
81539 static struct global_attr _name = \
81540 @@ -269,7 +270,7 @@ struct cpufreq_driver {
81541 bool boost_supported;
81542 bool boost_enabled;
81543 int (*set_boost) (int state);
81544 -};
81545 +} __do_const;
81546
81547 /* flags */
81548 #define CPUFREQ_STICKY (1 << 0) /* driver isn't removed even if
81549 diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
81550 index 25e0df6..952dffd 100644
81551 --- a/include/linux/cpuidle.h
81552 +++ b/include/linux/cpuidle.h
81553 @@ -50,7 +50,8 @@ struct cpuidle_state {
81554 int index);
81555
81556 int (*enter_dead) (struct cpuidle_device *dev, int index);
81557 -};
81558 +} __do_const;
81559 +typedef struct cpuidle_state __no_const cpuidle_state_no_const;
81560
81561 /* Idle State Flags */
81562 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
81563 @@ -209,7 +210,7 @@ struct cpuidle_governor {
81564 void (*reflect) (struct cpuidle_device *dev, int index);
81565
81566 struct module *owner;
81567 -};
81568 +} __do_const;
81569
81570 #ifdef CONFIG_CPU_IDLE
81571 extern int cpuidle_register_governor(struct cpuidle_governor *gov);
81572 diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
81573 index 2997af6..424ddc1 100644
81574 --- a/include/linux/cpumask.h
81575 +++ b/include/linux/cpumask.h
81576 @@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
81577 }
81578
81579 /* Valid inputs for n are -1 and 0. */
81580 -static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
81581 +static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
81582 {
81583 return n+1;
81584 }
81585
81586 -static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
81587 +static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
81588 {
81589 return n+1;
81590 }
81591
81592 -static inline unsigned int cpumask_next_and(int n,
81593 +static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
81594 const struct cpumask *srcp,
81595 const struct cpumask *andp)
81596 {
81597 @@ -174,7 +174,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
81598 *
81599 * Returns >= nr_cpu_ids if no further cpus set.
81600 */
81601 -static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
81602 +static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
81603 {
81604 /* -1 is a legal arg here. */
81605 if (n != -1)
81606 @@ -189,7 +189,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
81607 *
81608 * Returns >= nr_cpu_ids if no further cpus unset.
81609 */
81610 -static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
81611 +static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
81612 {
81613 /* -1 is a legal arg here. */
81614 if (n != -1)
81615 @@ -197,7 +197,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
81616 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
81617 }
81618
81619 -int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
81620 +int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
81621 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
81622 int cpumask_set_cpu_local_first(int i, int numa_node, cpumask_t *dstp);
81623
81624 diff --git a/include/linux/cred.h b/include/linux/cred.h
81625 index b2d0820..2ecafd3 100644
81626 --- a/include/linux/cred.h
81627 +++ b/include/linux/cred.h
81628 @@ -35,7 +35,7 @@ struct group_info {
81629 int nblocks;
81630 kgid_t small_block[NGROUPS_SMALL];
81631 kgid_t *blocks[0];
81632 -};
81633 +} __randomize_layout;
81634
81635 /**
81636 * get_group_info - Get a reference to a group info structure
81637 @@ -136,7 +136,7 @@ struct cred {
81638 struct user_namespace *user_ns; /* user_ns the caps and keyrings are relative to. */
81639 struct group_info *group_info; /* supplementary groups for euid/fsgid */
81640 struct rcu_head rcu; /* RCU deletion hook */
81641 -};
81642 +} __randomize_layout;
81643
81644 extern void __put_cred(struct cred *);
81645 extern void exit_creds(struct task_struct *);
81646 @@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
81647 static inline void validate_process_creds(void)
81648 {
81649 }
81650 +static inline void validate_task_creds(struct task_struct *task)
81651 +{
81652 +}
81653 #endif
81654
81655 /**
81656 @@ -331,6 +334,7 @@ static inline void put_cred(const struct cred *_cred)
81657
81658 #define task_uid(task) (task_cred_xxx((task), uid))
81659 #define task_euid(task) (task_cred_xxx((task), euid))
81660 +#define task_securebits(task) (task_cred_xxx((task), securebits))
81661
81662 #define current_cred_xxx(xxx) \
81663 ({ \
81664 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
81665 index d45e949..51cf5ea 100644
81666 --- a/include/linux/crypto.h
81667 +++ b/include/linux/crypto.h
81668 @@ -373,7 +373,7 @@ struct cipher_tfm {
81669 const u8 *key, unsigned int keylen);
81670 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
81671 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
81672 -};
81673 +} __no_const;
81674
81675 struct hash_tfm {
81676 int (*init)(struct hash_desc *desc);
81677 @@ -394,13 +394,13 @@ struct compress_tfm {
81678 int (*cot_decompress)(struct crypto_tfm *tfm,
81679 const u8 *src, unsigned int slen,
81680 u8 *dst, unsigned int *dlen);
81681 -};
81682 +} __no_const;
81683
81684 struct rng_tfm {
81685 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
81686 unsigned int dlen);
81687 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
81688 -};
81689 +} __no_const;
81690
81691 #define crt_ablkcipher crt_u.ablkcipher
81692 #define crt_aead crt_u.aead
81693 diff --git a/include/linux/ctype.h b/include/linux/ctype.h
81694 index 653589e..4ef254a 100644
81695 --- a/include/linux/ctype.h
81696 +++ b/include/linux/ctype.h
81697 @@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
81698 * Fast implementation of tolower() for internal usage. Do not use in your
81699 * code.
81700 */
81701 -static inline char _tolower(const char c)
81702 +static inline unsigned char _tolower(const unsigned char c)
81703 {
81704 return c | 0x20;
81705 }
81706 diff --git a/include/linux/dcache.h b/include/linux/dcache.h
81707 index 75a227c..1456987 100644
81708 --- a/include/linux/dcache.h
81709 +++ b/include/linux/dcache.h
81710 @@ -134,7 +134,7 @@ struct dentry {
81711 } d_u;
81712 struct list_head d_subdirs; /* our children */
81713 struct hlist_node d_alias; /* inode alias list */
81714 -};
81715 +} __randomize_layout;
81716
81717 /*
81718 * dentry->d_lock spinlock nesting subclasses:
81719 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
81720 index 7925bf0..d5143d2 100644
81721 --- a/include/linux/decompress/mm.h
81722 +++ b/include/linux/decompress/mm.h
81723 @@ -77,7 +77,7 @@ static void free(void *where)
81724 * warnings when not needed (indeed large_malloc / large_free are not
81725 * needed by inflate */
81726
81727 -#define malloc(a) kmalloc(a, GFP_KERNEL)
81728 +#define malloc(a) kmalloc((a), GFP_KERNEL)
81729 #define free(a) kfree(a)
81730
81731 #define large_malloc(a) vmalloc(a)
81732 diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
81733 index f1863dc..5c26074 100644
81734 --- a/include/linux/devfreq.h
81735 +++ b/include/linux/devfreq.h
81736 @@ -114,7 +114,7 @@ struct devfreq_governor {
81737 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
81738 int (*event_handler)(struct devfreq *devfreq,
81739 unsigned int event, void *data);
81740 -};
81741 +} __do_const;
81742
81743 /**
81744 * struct devfreq - Device devfreq structure
81745 diff --git a/include/linux/device.h b/include/linux/device.h
81746 index 43d183a..03b6ba2 100644
81747 --- a/include/linux/device.h
81748 +++ b/include/linux/device.h
81749 @@ -310,7 +310,7 @@ struct subsys_interface {
81750 struct list_head node;
81751 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
81752 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
81753 -};
81754 +} __do_const;
81755
81756 int subsys_interface_register(struct subsys_interface *sif);
81757 void subsys_interface_unregister(struct subsys_interface *sif);
81758 @@ -506,7 +506,7 @@ struct device_type {
81759 void (*release)(struct device *dev);
81760
81761 const struct dev_pm_ops *pm;
81762 -};
81763 +} __do_const;
81764
81765 /* interface for exporting device attributes */
81766 struct device_attribute {
81767 @@ -516,11 +516,12 @@ struct device_attribute {
81768 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
81769 const char *buf, size_t count);
81770 };
81771 +typedef struct device_attribute __no_const device_attribute_no_const;
81772
81773 struct dev_ext_attribute {
81774 struct device_attribute attr;
81775 void *var;
81776 -};
81777 +} __do_const;
81778
81779 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
81780 char *buf);
81781 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
81782 index 931b709..89b2d89 100644
81783 --- a/include/linux/dma-mapping.h
81784 +++ b/include/linux/dma-mapping.h
81785 @@ -60,7 +60,7 @@ struct dma_map_ops {
81786 u64 (*get_required_mask)(struct device *dev);
81787 #endif
81788 int is_phys;
81789 -};
81790 +} __do_const;
81791
81792 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
81793
81794 diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
81795 index 1f9e642..39e4263 100644
81796 --- a/include/linux/dmaengine.h
81797 +++ b/include/linux/dmaengine.h
81798 @@ -1147,9 +1147,9 @@ struct dma_pinned_list {
81799 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
81800 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
81801
81802 -dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
81803 +dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
81804 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
81805 -dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
81806 +dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
81807 struct dma_pinned_list *pinned_list, struct page *page,
81808 unsigned int offset, size_t len);
81809
81810 diff --git a/include/linux/efi.h b/include/linux/efi.h
81811 index 45cb4ff..c9b4912 100644
81812 --- a/include/linux/efi.h
81813 +++ b/include/linux/efi.h
81814 @@ -1036,6 +1036,7 @@ struct efivar_operations {
81815 efi_set_variable_t *set_variable;
81816 efi_query_variable_store_t *query_variable_store;
81817 };
81818 +typedef struct efivar_operations __no_const efivar_operations_no_const;
81819
81820 struct efivars {
81821 /*
81822 diff --git a/include/linux/elf.h b/include/linux/elf.h
81823 index 67a5fa7..b817372 100644
81824 --- a/include/linux/elf.h
81825 +++ b/include/linux/elf.h
81826 @@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
81827 #define elf_note elf32_note
81828 #define elf_addr_t Elf32_Off
81829 #define Elf_Half Elf32_Half
81830 +#define elf_dyn Elf32_Dyn
81831
81832 #else
81833
81834 @@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
81835 #define elf_note elf64_note
81836 #define elf_addr_t Elf64_Off
81837 #define Elf_Half Elf64_Half
81838 +#define elf_dyn Elf64_Dyn
81839
81840 #endif
81841
81842 diff --git a/include/linux/err.h b/include/linux/err.h
81843 index a729120..6ede2c9 100644
81844 --- a/include/linux/err.h
81845 +++ b/include/linux/err.h
81846 @@ -20,12 +20,12 @@
81847
81848 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
81849
81850 -static inline void * __must_check ERR_PTR(long error)
81851 +static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
81852 {
81853 return (void *) error;
81854 }
81855
81856 -static inline long __must_check PTR_ERR(__force const void *ptr)
81857 +static inline long __must_check __intentional_overflow(-1) PTR_ERR(__force const void *ptr)
81858 {
81859 return (long) ptr;
81860 }
81861 diff --git a/include/linux/extcon.h b/include/linux/extcon.h
81862 index 36f49c4..a2a1f4c 100644
81863 --- a/include/linux/extcon.h
81864 +++ b/include/linux/extcon.h
81865 @@ -135,7 +135,7 @@ struct extcon_dev {
81866 /* /sys/class/extcon/.../mutually_exclusive/... */
81867 struct attribute_group attr_g_muex;
81868 struct attribute **attrs_muex;
81869 - struct device_attribute *d_attrs_muex;
81870 + device_attribute_no_const *d_attrs_muex;
81871 };
81872
81873 /**
81874 diff --git a/include/linux/fb.h b/include/linux/fb.h
81875 index 09bb7a1..d98870a 100644
81876 --- a/include/linux/fb.h
81877 +++ b/include/linux/fb.h
81878 @@ -305,7 +305,7 @@ struct fb_ops {
81879 /* called at KDB enter and leave time to prepare the console */
81880 int (*fb_debug_enter)(struct fb_info *info);
81881 int (*fb_debug_leave)(struct fb_info *info);
81882 -};
81883 +} __do_const;
81884
81885 #ifdef CONFIG_FB_TILEBLITTING
81886 #define FB_TILE_CURSOR_NONE 0
81887 diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
81888 index 230f87b..1fd0485 100644
81889 --- a/include/linux/fdtable.h
81890 +++ b/include/linux/fdtable.h
81891 @@ -100,7 +100,7 @@ struct files_struct *get_files_struct(struct task_struct *);
81892 void put_files_struct(struct files_struct *fs);
81893 void reset_files_struct(struct files_struct *);
81894 int unshare_files(struct files_struct **);
81895 -struct files_struct *dup_fd(struct files_struct *, int *);
81896 +struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
81897 void do_close_on_exec(struct files_struct *);
81898 int iterate_fd(struct files_struct *, unsigned,
81899 int (*)(const void *, struct file *, unsigned),
81900 diff --git a/include/linux/filter.h b/include/linux/filter.h
81901 index a5227ab..c789945 100644
81902 --- a/include/linux/filter.h
81903 +++ b/include/linux/filter.h
81904 @@ -9,6 +9,11 @@
81905 #include <linux/skbuff.h>
81906 #include <linux/workqueue.h>
81907 #include <uapi/linux/filter.h>
81908 +#include <asm/cacheflush.h>
81909 +
81910 +struct sk_buff;
81911 +struct sock;
81912 +struct seccomp_data;
81913
81914 /* Internally used and optimized filter representation with extended
81915 * instruction set based on top of classic BPF.
81916 @@ -320,20 +325,23 @@ struct sock_fprog_kern {
81917 struct sock_filter *filter;
81918 };
81919
81920 -struct sk_buff;
81921 -struct sock;
81922 -struct seccomp_data;
81923 +struct bpf_work_struct {
81924 + struct bpf_prog *prog;
81925 + struct work_struct work;
81926 +};
81927
81928 struct bpf_prog {
81929 + u32 pages; /* Number of allocated pages */
81930 u32 jited:1, /* Is our filter JIT'ed? */
81931 len:31; /* Number of filter blocks */
81932 struct sock_fprog_kern *orig_prog; /* Original BPF program */
81933 + struct bpf_work_struct *work; /* Deferred free work struct */
81934 unsigned int (*bpf_func)(const struct sk_buff *skb,
81935 const struct bpf_insn *filter);
81936 + /* Instructions for interpreter */
81937 union {
81938 struct sock_filter insns[0];
81939 struct bpf_insn insnsi[0];
81940 - struct work_struct work;
81941 };
81942 };
81943
81944 @@ -353,6 +361,26 @@ static inline unsigned int bpf_prog_size(unsigned int proglen)
81945
81946 #define bpf_classic_proglen(fprog) (fprog->len * sizeof(fprog->filter[0]))
81947
81948 +#ifdef CONFIG_DEBUG_SET_MODULE_RONX
81949 +static inline void bpf_prog_lock_ro(struct bpf_prog *fp)
81950 +{
81951 + set_memory_ro((unsigned long)fp, fp->pages);
81952 +}
81953 +
81954 +static inline void bpf_prog_unlock_ro(struct bpf_prog *fp)
81955 +{
81956 + set_memory_rw((unsigned long)fp, fp->pages);
81957 +}
81958 +#else
81959 +static inline void bpf_prog_lock_ro(struct bpf_prog *fp)
81960 +{
81961 +}
81962 +
81963 +static inline void bpf_prog_unlock_ro(struct bpf_prog *fp)
81964 +{
81965 +}
81966 +#endif /* CONFIG_DEBUG_SET_MODULE_RONX */
81967 +
81968 int sk_filter(struct sock *sk, struct sk_buff *skb);
81969
81970 void bpf_prog_select_runtime(struct bpf_prog *fp);
81971 @@ -361,6 +389,17 @@ void bpf_prog_free(struct bpf_prog *fp);
81972 int bpf_convert_filter(struct sock_filter *prog, int len,
81973 struct bpf_insn *new_prog, int *new_len);
81974
81975 +struct bpf_prog *bpf_prog_alloc(unsigned int size, gfp_t gfp_extra_flags);
81976 +struct bpf_prog *bpf_prog_realloc(struct bpf_prog *fp_old, unsigned int size,
81977 + gfp_t gfp_extra_flags);
81978 +void __bpf_prog_free(struct bpf_prog *fp);
81979 +
81980 +static inline void bpf_prog_unlock_free(struct bpf_prog *fp)
81981 +{
81982 + bpf_prog_unlock_ro(fp);
81983 + __bpf_prog_free(fp);
81984 +}
81985 +
81986 int bpf_prog_create(struct bpf_prog **pfp, struct sock_fprog_kern *fprog);
81987 void bpf_prog_destroy(struct bpf_prog *fp);
81988
81989 @@ -450,7 +489,7 @@ static inline void bpf_jit_compile(struct bpf_prog *fp)
81990
81991 static inline void bpf_jit_free(struct bpf_prog *fp)
81992 {
81993 - kfree(fp);
81994 + bpf_prog_unlock_free(fp);
81995 }
81996 #endif /* CONFIG_BPF_JIT */
81997
81998 diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
81999 index 8293262..2b3b8bd 100644
82000 --- a/include/linux/frontswap.h
82001 +++ b/include/linux/frontswap.h
82002 @@ -11,7 +11,7 @@ struct frontswap_ops {
82003 int (*load)(unsigned, pgoff_t, struct page *);
82004 void (*invalidate_page)(unsigned, pgoff_t);
82005 void (*invalidate_area)(unsigned);
82006 -};
82007 +} __no_const;
82008
82009 extern bool frontswap_enabled;
82010 extern struct frontswap_ops *
82011 diff --git a/include/linux/fs.h b/include/linux/fs.h
82012 index 9418772..0155807 100644
82013 --- a/include/linux/fs.h
82014 +++ b/include/linux/fs.h
82015 @@ -401,7 +401,7 @@ struct address_space {
82016 spinlock_t private_lock; /* for use by the address_space */
82017 struct list_head private_list; /* ditto */
82018 void *private_data; /* ditto */
82019 -} __attribute__((aligned(sizeof(long))));
82020 +} __attribute__((aligned(sizeof(long)))) __randomize_layout;
82021 /*
82022 * On most architectures that alignment is already the case; but
82023 * must be enforced here for CRIS, to let the least significant bit
82024 @@ -444,7 +444,7 @@ struct block_device {
82025 int bd_fsfreeze_count;
82026 /* Mutex for freeze */
82027 struct mutex bd_fsfreeze_mutex;
82028 -};
82029 +} __randomize_layout;
82030
82031 /*
82032 * Radix-tree tags, for tagging dirty and writeback pages within the pagecache
82033 @@ -613,7 +613,7 @@ struct inode {
82034 #endif
82035
82036 void *i_private; /* fs or device private pointer */
82037 -};
82038 +} __randomize_layout;
82039
82040 static inline int inode_unhashed(struct inode *inode)
82041 {
82042 @@ -806,7 +806,7 @@ struct file {
82043 struct list_head f_tfile_llink;
82044 #endif /* #ifdef CONFIG_EPOLL */
82045 struct address_space *f_mapping;
82046 -} __attribute__((aligned(4))); /* lest something weird decides that 2 is OK */
82047 +} __attribute__((aligned(4))) __randomize_layout; /* lest something weird decides that 2 is OK */
82048
82049 struct file_handle {
82050 __u32 handle_bytes;
82051 @@ -934,7 +934,7 @@ struct file_lock {
82052 int state; /* state of grant or error if -ve */
82053 } afs;
82054 } fl_u;
82055 -};
82056 +} __randomize_layout;
82057
82058 /* The following constant reflects the upper bound of the file/locking space */
82059 #ifndef OFFSET_MAX
82060 @@ -1284,7 +1284,7 @@ struct super_block {
82061 struct list_lru s_dentry_lru ____cacheline_aligned_in_smp;
82062 struct list_lru s_inode_lru ____cacheline_aligned_in_smp;
82063 struct rcu_head rcu;
82064 -};
82065 +} __randomize_layout;
82066
82067 extern struct timespec current_fs_time(struct super_block *sb);
82068
82069 @@ -1510,7 +1510,8 @@ struct file_operations {
82070 long (*fallocate)(struct file *file, int mode, loff_t offset,
82071 loff_t len);
82072 int (*show_fdinfo)(struct seq_file *m, struct file *f);
82073 -};
82074 +} __do_const __randomize_layout;
82075 +typedef struct file_operations __no_const file_operations_no_const;
82076
82077 struct inode_operations {
82078 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
82079 @@ -2796,4 +2797,14 @@ static inline bool dir_relax(struct inode *inode)
82080 return !IS_DEADDIR(inode);
82081 }
82082
82083 +static inline bool is_sidechannel_device(const struct inode *inode)
82084 +{
82085 +#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
82086 + umode_t mode = inode->i_mode;
82087 + return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
82088 +#else
82089 + return false;
82090 +#endif
82091 +}
82092 +
82093 #endif /* _LINUX_FS_H */
82094 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
82095 index 0efc3e6..fd23610 100644
82096 --- a/include/linux/fs_struct.h
82097 +++ b/include/linux/fs_struct.h
82098 @@ -6,13 +6,13 @@
82099 #include <linux/seqlock.h>
82100
82101 struct fs_struct {
82102 - int users;
82103 + atomic_t users;
82104 spinlock_t lock;
82105 seqcount_t seq;
82106 int umask;
82107 int in_exec;
82108 struct path root, pwd;
82109 -};
82110 +} __randomize_layout;
82111
82112 extern struct kmem_cache *fs_cachep;
82113
82114 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
82115 index 7714849..a4a5c7a 100644
82116 --- a/include/linux/fscache-cache.h
82117 +++ b/include/linux/fscache-cache.h
82118 @@ -113,7 +113,7 @@ struct fscache_operation {
82119 fscache_operation_release_t release;
82120 };
82121
82122 -extern atomic_t fscache_op_debug_id;
82123 +extern atomic_unchecked_t fscache_op_debug_id;
82124 extern void fscache_op_work_func(struct work_struct *work);
82125
82126 extern void fscache_enqueue_operation(struct fscache_operation *);
82127 @@ -135,7 +135,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
82128 INIT_WORK(&op->work, fscache_op_work_func);
82129 atomic_set(&op->usage, 1);
82130 op->state = FSCACHE_OP_ST_INITIALISED;
82131 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
82132 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
82133 op->processor = processor;
82134 op->release = release;
82135 INIT_LIST_HEAD(&op->pend_link);
82136 diff --git a/include/linux/fscache.h b/include/linux/fscache.h
82137 index 115bb81..e7b812b 100644
82138 --- a/include/linux/fscache.h
82139 +++ b/include/linux/fscache.h
82140 @@ -152,7 +152,7 @@ struct fscache_cookie_def {
82141 * - this is mandatory for any object that may have data
82142 */
82143 void (*now_uncached)(void *cookie_netfs_data);
82144 -};
82145 +} __do_const;
82146
82147 /*
82148 * fscache cached network filesystem type
82149 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
82150 index 1c804b0..1432c2b 100644
82151 --- a/include/linux/fsnotify.h
82152 +++ b/include/linux/fsnotify.h
82153 @@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
82154 struct inode *inode = file_inode(file);
82155 __u32 mask = FS_ACCESS;
82156
82157 + if (is_sidechannel_device(inode))
82158 + return;
82159 +
82160 if (S_ISDIR(inode->i_mode))
82161 mask |= FS_ISDIR;
82162
82163 @@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
82164 struct inode *inode = file_inode(file);
82165 __u32 mask = FS_MODIFY;
82166
82167 + if (is_sidechannel_device(inode))
82168 + return;
82169 +
82170 if (S_ISDIR(inode->i_mode))
82171 mask |= FS_ISDIR;
82172
82173 @@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
82174 */
82175 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
82176 {
82177 - return kstrdup(name, GFP_KERNEL);
82178 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
82179 }
82180
82181 /*
82182 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
82183 index ec274e0..e678159 100644
82184 --- a/include/linux/genhd.h
82185 +++ b/include/linux/genhd.h
82186 @@ -194,7 +194,7 @@ struct gendisk {
82187 struct kobject *slave_dir;
82188
82189 struct timer_rand_state *random;
82190 - atomic_t sync_io; /* RAID */
82191 + atomic_unchecked_t sync_io; /* RAID */
82192 struct disk_events *ev;
82193 #ifdef CONFIG_BLK_DEV_INTEGRITY
82194 struct blk_integrity *integrity;
82195 @@ -435,7 +435,7 @@ extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
82196 extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
82197
82198 /* drivers/char/random.c */
82199 -extern void add_disk_randomness(struct gendisk *disk);
82200 +extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
82201 extern void rand_initialize_disk(struct gendisk *disk);
82202
82203 static inline sector_t get_start_sect(struct block_device *bdev)
82204 diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
82205 index c0894dd..2fbf10c 100644
82206 --- a/include/linux/genl_magic_func.h
82207 +++ b/include/linux/genl_magic_func.h
82208 @@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
82209 },
82210
82211 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
82212 -static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
82213 +static struct genl_ops ZZZ_genl_ops[] = {
82214 #include GENL_MAGIC_INCLUDE_FILE
82215 };
82216
82217 diff --git a/include/linux/gfp.h b/include/linux/gfp.h
82218 index 5e7219d..b1ed627 100644
82219 --- a/include/linux/gfp.h
82220 +++ b/include/linux/gfp.h
82221 @@ -34,6 +34,13 @@ struct vm_area_struct;
82222 #define ___GFP_NO_KSWAPD 0x400000u
82223 #define ___GFP_OTHER_NODE 0x800000u
82224 #define ___GFP_WRITE 0x1000000u
82225 +
82226 +#ifdef CONFIG_PAX_USERCOPY_SLABS
82227 +#define ___GFP_USERCOPY 0x2000000u
82228 +#else
82229 +#define ___GFP_USERCOPY 0
82230 +#endif
82231 +
82232 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
82233
82234 /*
82235 @@ -90,6 +97,7 @@ struct vm_area_struct;
82236 #define __GFP_NO_KSWAPD ((__force gfp_t)___GFP_NO_KSWAPD)
82237 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
82238 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
82239 +#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
82240
82241 /*
82242 * This may seem redundant, but it's a way of annotating false positives vs.
82243 @@ -97,7 +105,7 @@ struct vm_area_struct;
82244 */
82245 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
82246
82247 -#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
82248 +#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
82249 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
82250
82251 /* This equals 0, but use constants in case they ever change */
82252 @@ -155,6 +163,8 @@ struct vm_area_struct;
82253 /* 4GB DMA on some platforms */
82254 #define GFP_DMA32 __GFP_DMA32
82255
82256 +#define GFP_USERCOPY __GFP_USERCOPY
82257 +
82258 /* Convert GFP flags to their corresponding migrate type */
82259 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
82260 {
82261 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
82262 new file mode 100644
82263 index 0000000..edb2cb6
82264 --- /dev/null
82265 +++ b/include/linux/gracl.h
82266 @@ -0,0 +1,340 @@
82267 +#ifndef GR_ACL_H
82268 +#define GR_ACL_H
82269 +
82270 +#include <linux/grdefs.h>
82271 +#include <linux/resource.h>
82272 +#include <linux/capability.h>
82273 +#include <linux/dcache.h>
82274 +#include <asm/resource.h>
82275 +
82276 +/* Major status information */
82277 +
82278 +#define GR_VERSION "grsecurity 3.0"
82279 +#define GRSECURITY_VERSION 0x3000
82280 +
82281 +enum {
82282 + GR_SHUTDOWN = 0,
82283 + GR_ENABLE = 1,
82284 + GR_SPROLE = 2,
82285 + GR_OLDRELOAD = 3,
82286 + GR_SEGVMOD = 4,
82287 + GR_STATUS = 5,
82288 + GR_UNSPROLE = 6,
82289 + GR_PASSSET = 7,
82290 + GR_SPROLEPAM = 8,
82291 + GR_RELOAD = 9,
82292 +};
82293 +
82294 +/* Password setup definitions
82295 + * kernel/grhash.c */
82296 +enum {
82297 + GR_PW_LEN = 128,
82298 + GR_SALT_LEN = 16,
82299 + GR_SHA_LEN = 32,
82300 +};
82301 +
82302 +enum {
82303 + GR_SPROLE_LEN = 64,
82304 +};
82305 +
82306 +enum {
82307 + GR_NO_GLOB = 0,
82308 + GR_REG_GLOB,
82309 + GR_CREATE_GLOB
82310 +};
82311 +
82312 +#define GR_NLIMITS 32
82313 +
82314 +/* Begin Data Structures */
82315 +
82316 +struct sprole_pw {
82317 + unsigned char *rolename;
82318 + unsigned char salt[GR_SALT_LEN];
82319 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
82320 +};
82321 +
82322 +struct name_entry {
82323 + __u32 key;
82324 + ino_t inode;
82325 + dev_t device;
82326 + char *name;
82327 + __u16 len;
82328 + __u8 deleted;
82329 + struct name_entry *prev;
82330 + struct name_entry *next;
82331 +};
82332 +
82333 +struct inodev_entry {
82334 + struct name_entry *nentry;
82335 + struct inodev_entry *prev;
82336 + struct inodev_entry *next;
82337 +};
82338 +
82339 +struct acl_role_db {
82340 + struct acl_role_label **r_hash;
82341 + __u32 r_size;
82342 +};
82343 +
82344 +struct inodev_db {
82345 + struct inodev_entry **i_hash;
82346 + __u32 i_size;
82347 +};
82348 +
82349 +struct name_db {
82350 + struct name_entry **n_hash;
82351 + __u32 n_size;
82352 +};
82353 +
82354 +struct crash_uid {
82355 + uid_t uid;
82356 + unsigned long expires;
82357 +};
82358 +
82359 +struct gr_hash_struct {
82360 + void **table;
82361 + void **nametable;
82362 + void *first;
82363 + __u32 table_size;
82364 + __u32 used_size;
82365 + int type;
82366 +};
82367 +
82368 +/* Userspace Grsecurity ACL data structures */
82369 +
82370 +struct acl_subject_label {
82371 + char *filename;
82372 + ino_t inode;
82373 + dev_t device;
82374 + __u32 mode;
82375 + kernel_cap_t cap_mask;
82376 + kernel_cap_t cap_lower;
82377 + kernel_cap_t cap_invert_audit;
82378 +
82379 + struct rlimit res[GR_NLIMITS];
82380 + __u32 resmask;
82381 +
82382 + __u8 user_trans_type;
82383 + __u8 group_trans_type;
82384 + uid_t *user_transitions;
82385 + gid_t *group_transitions;
82386 + __u16 user_trans_num;
82387 + __u16 group_trans_num;
82388 +
82389 + __u32 sock_families[2];
82390 + __u32 ip_proto[8];
82391 + __u32 ip_type;
82392 + struct acl_ip_label **ips;
82393 + __u32 ip_num;
82394 + __u32 inaddr_any_override;
82395 +
82396 + __u32 crashes;
82397 + unsigned long expires;
82398 +
82399 + struct acl_subject_label *parent_subject;
82400 + struct gr_hash_struct *hash;
82401 + struct acl_subject_label *prev;
82402 + struct acl_subject_label *next;
82403 +
82404 + struct acl_object_label **obj_hash;
82405 + __u32 obj_hash_size;
82406 + __u16 pax_flags;
82407 +};
82408 +
82409 +struct role_allowed_ip {
82410 + __u32 addr;
82411 + __u32 netmask;
82412 +
82413 + struct role_allowed_ip *prev;
82414 + struct role_allowed_ip *next;
82415 +};
82416 +
82417 +struct role_transition {
82418 + char *rolename;
82419 +
82420 + struct role_transition *prev;
82421 + struct role_transition *next;
82422 +};
82423 +
82424 +struct acl_role_label {
82425 + char *rolename;
82426 + uid_t uidgid;
82427 + __u16 roletype;
82428 +
82429 + __u16 auth_attempts;
82430 + unsigned long expires;
82431 +
82432 + struct acl_subject_label *root_label;
82433 + struct gr_hash_struct *hash;
82434 +
82435 + struct acl_role_label *prev;
82436 + struct acl_role_label *next;
82437 +
82438 + struct role_transition *transitions;
82439 + struct role_allowed_ip *allowed_ips;
82440 + uid_t *domain_children;
82441 + __u16 domain_child_num;
82442 +
82443 + umode_t umask;
82444 +
82445 + struct acl_subject_label **subj_hash;
82446 + __u32 subj_hash_size;
82447 +};
82448 +
82449 +struct user_acl_role_db {
82450 + struct acl_role_label **r_table;
82451 + __u32 num_pointers; /* Number of allocations to track */
82452 + __u32 num_roles; /* Number of roles */
82453 + __u32 num_domain_children; /* Number of domain children */
82454 + __u32 num_subjects; /* Number of subjects */
82455 + __u32 num_objects; /* Number of objects */
82456 +};
82457 +
82458 +struct acl_object_label {
82459 + char *filename;
82460 + ino_t inode;
82461 + dev_t device;
82462 + __u32 mode;
82463 +
82464 + struct acl_subject_label *nested;
82465 + struct acl_object_label *globbed;
82466 +
82467 + /* next two structures not used */
82468 +
82469 + struct acl_object_label *prev;
82470 + struct acl_object_label *next;
82471 +};
82472 +
82473 +struct acl_ip_label {
82474 + char *iface;
82475 + __u32 addr;
82476 + __u32 netmask;
82477 + __u16 low, high;
82478 + __u8 mode;
82479 + __u32 type;
82480 + __u32 proto[8];
82481 +
82482 + /* next two structures not used */
82483 +
82484 + struct acl_ip_label *prev;
82485 + struct acl_ip_label *next;
82486 +};
82487 +
82488 +struct gr_arg {
82489 + struct user_acl_role_db role_db;
82490 + unsigned char pw[GR_PW_LEN];
82491 + unsigned char salt[GR_SALT_LEN];
82492 + unsigned char sum[GR_SHA_LEN];
82493 + unsigned char sp_role[GR_SPROLE_LEN];
82494 + struct sprole_pw *sprole_pws;
82495 + dev_t segv_device;
82496 + ino_t segv_inode;
82497 + uid_t segv_uid;
82498 + __u16 num_sprole_pws;
82499 + __u16 mode;
82500 +};
82501 +
82502 +struct gr_arg_wrapper {
82503 + struct gr_arg *arg;
82504 + __u32 version;
82505 + __u32 size;
82506 +};
82507 +
82508 +struct subject_map {
82509 + struct acl_subject_label *user;
82510 + struct acl_subject_label *kernel;
82511 + struct subject_map *prev;
82512 + struct subject_map *next;
82513 +};
82514 +
82515 +struct acl_subj_map_db {
82516 + struct subject_map **s_hash;
82517 + __u32 s_size;
82518 +};
82519 +
82520 +struct gr_policy_state {
82521 + struct sprole_pw **acl_special_roles;
82522 + __u16 num_sprole_pws;
82523 + struct acl_role_label *kernel_role;
82524 + struct acl_role_label *role_list;
82525 + struct acl_role_label *default_role;
82526 + struct acl_role_db acl_role_set;
82527 + struct acl_subj_map_db subj_map_set;
82528 + struct name_db name_set;
82529 + struct inodev_db inodev_set;
82530 +};
82531 +
82532 +struct gr_alloc_state {
82533 + unsigned long alloc_stack_next;
82534 + unsigned long alloc_stack_size;
82535 + void **alloc_stack;
82536 +};
82537 +
82538 +struct gr_reload_state {
82539 + struct gr_policy_state oldpolicy;
82540 + struct gr_alloc_state oldalloc;
82541 + struct gr_policy_state newpolicy;
82542 + struct gr_alloc_state newalloc;
82543 + struct gr_policy_state *oldpolicy_ptr;
82544 + struct gr_alloc_state *oldalloc_ptr;
82545 + unsigned char oldmode;
82546 +};
82547 +
82548 +/* End Data Structures Section */
82549 +
82550 +/* Hash functions generated by empirical testing by Brad Spengler
82551 + Makes good use of the low bits of the inode. Generally 0-1 times
82552 + in loop for successful match. 0-3 for unsuccessful match.
82553 + Shift/add algorithm with modulus of table size and an XOR*/
82554 +
82555 +static __inline__ unsigned int
82556 +gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
82557 +{
82558 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
82559 +}
82560 +
82561 + static __inline__ unsigned int
82562 +gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
82563 +{
82564 + return ((const unsigned long)userp % sz);
82565 +}
82566 +
82567 +static __inline__ unsigned int
82568 +gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
82569 +{
82570 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
82571 +}
82572 +
82573 +static __inline__ unsigned int
82574 +gr_nhash(const char *name, const __u16 len, const unsigned int sz)
82575 +{
82576 + return full_name_hash((const unsigned char *)name, len) % sz;
82577 +}
82578 +
82579 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
82580 + subj = NULL; \
82581 + iter = 0; \
82582 + while (iter < role->subj_hash_size) { \
82583 + if (subj == NULL) \
82584 + subj = role->subj_hash[iter]; \
82585 + if (subj == NULL) { \
82586 + iter++; \
82587 + continue; \
82588 + }
82589 +
82590 +#define FOR_EACH_SUBJECT_END(subj,iter) \
82591 + subj = subj->next; \
82592 + if (subj == NULL) \
82593 + iter++; \
82594 + }
82595 +
82596 +
82597 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
82598 + subj = role->hash->first; \
82599 + while (subj != NULL) {
82600 +
82601 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
82602 + subj = subj->next; \
82603 + }
82604 +
82605 +#endif
82606 +
82607 diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
82608 new file mode 100644
82609 index 0000000..33ebd1f
82610 --- /dev/null
82611 +++ b/include/linux/gracl_compat.h
82612 @@ -0,0 +1,156 @@
82613 +#ifndef GR_ACL_COMPAT_H
82614 +#define GR_ACL_COMPAT_H
82615 +
82616 +#include <linux/resource.h>
82617 +#include <asm/resource.h>
82618 +
82619 +struct sprole_pw_compat {
82620 + compat_uptr_t rolename;
82621 + unsigned char salt[GR_SALT_LEN];
82622 + unsigned char sum[GR_SHA_LEN];
82623 +};
82624 +
82625 +struct gr_hash_struct_compat {
82626 + compat_uptr_t table;
82627 + compat_uptr_t nametable;
82628 + compat_uptr_t first;
82629 + __u32 table_size;
82630 + __u32 used_size;
82631 + int type;
82632 +};
82633 +
82634 +struct acl_subject_label_compat {
82635 + compat_uptr_t filename;
82636 + compat_ino_t inode;
82637 + __u32 device;
82638 + __u32 mode;
82639 + kernel_cap_t cap_mask;
82640 + kernel_cap_t cap_lower;
82641 + kernel_cap_t cap_invert_audit;
82642 +
82643 + struct compat_rlimit res[GR_NLIMITS];
82644 + __u32 resmask;
82645 +
82646 + __u8 user_trans_type;
82647 + __u8 group_trans_type;
82648 + compat_uptr_t user_transitions;
82649 + compat_uptr_t group_transitions;
82650 + __u16 user_trans_num;
82651 + __u16 group_trans_num;
82652 +
82653 + __u32 sock_families[2];
82654 + __u32 ip_proto[8];
82655 + __u32 ip_type;
82656 + compat_uptr_t ips;
82657 + __u32 ip_num;
82658 + __u32 inaddr_any_override;
82659 +
82660 + __u32 crashes;
82661 + compat_ulong_t expires;
82662 +
82663 + compat_uptr_t parent_subject;
82664 + compat_uptr_t hash;
82665 + compat_uptr_t prev;
82666 + compat_uptr_t next;
82667 +
82668 + compat_uptr_t obj_hash;
82669 + __u32 obj_hash_size;
82670 + __u16 pax_flags;
82671 +};
82672 +
82673 +struct role_allowed_ip_compat {
82674 + __u32 addr;
82675 + __u32 netmask;
82676 +
82677 + compat_uptr_t prev;
82678 + compat_uptr_t next;
82679 +};
82680 +
82681 +struct role_transition_compat {
82682 + compat_uptr_t rolename;
82683 +
82684 + compat_uptr_t prev;
82685 + compat_uptr_t next;
82686 +};
82687 +
82688 +struct acl_role_label_compat {
82689 + compat_uptr_t rolename;
82690 + uid_t uidgid;
82691 + __u16 roletype;
82692 +
82693 + __u16 auth_attempts;
82694 + compat_ulong_t expires;
82695 +
82696 + compat_uptr_t root_label;
82697 + compat_uptr_t hash;
82698 +
82699 + compat_uptr_t prev;
82700 + compat_uptr_t next;
82701 +
82702 + compat_uptr_t transitions;
82703 + compat_uptr_t allowed_ips;
82704 + compat_uptr_t domain_children;
82705 + __u16 domain_child_num;
82706 +
82707 + umode_t umask;
82708 +
82709 + compat_uptr_t subj_hash;
82710 + __u32 subj_hash_size;
82711 +};
82712 +
82713 +struct user_acl_role_db_compat {
82714 + compat_uptr_t r_table;
82715 + __u32 num_pointers;
82716 + __u32 num_roles;
82717 + __u32 num_domain_children;
82718 + __u32 num_subjects;
82719 + __u32 num_objects;
82720 +};
82721 +
82722 +struct acl_object_label_compat {
82723 + compat_uptr_t filename;
82724 + compat_ino_t inode;
82725 + __u32 device;
82726 + __u32 mode;
82727 +
82728 + compat_uptr_t nested;
82729 + compat_uptr_t globbed;
82730 +
82731 + compat_uptr_t prev;
82732 + compat_uptr_t next;
82733 +};
82734 +
82735 +struct acl_ip_label_compat {
82736 + compat_uptr_t iface;
82737 + __u32 addr;
82738 + __u32 netmask;
82739 + __u16 low, high;
82740 + __u8 mode;
82741 + __u32 type;
82742 + __u32 proto[8];
82743 +
82744 + compat_uptr_t prev;
82745 + compat_uptr_t next;
82746 +};
82747 +
82748 +struct gr_arg_compat {
82749 + struct user_acl_role_db_compat role_db;
82750 + unsigned char pw[GR_PW_LEN];
82751 + unsigned char salt[GR_SALT_LEN];
82752 + unsigned char sum[GR_SHA_LEN];
82753 + unsigned char sp_role[GR_SPROLE_LEN];
82754 + compat_uptr_t sprole_pws;
82755 + __u32 segv_device;
82756 + compat_ino_t segv_inode;
82757 + uid_t segv_uid;
82758 + __u16 num_sprole_pws;
82759 + __u16 mode;
82760 +};
82761 +
82762 +struct gr_arg_wrapper_compat {
82763 + compat_uptr_t arg;
82764 + __u32 version;
82765 + __u32 size;
82766 +};
82767 +
82768 +#endif
82769 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
82770 new file mode 100644
82771 index 0000000..323ecf2
82772 --- /dev/null
82773 +++ b/include/linux/gralloc.h
82774 @@ -0,0 +1,9 @@
82775 +#ifndef __GRALLOC_H
82776 +#define __GRALLOC_H
82777 +
82778 +void acl_free_all(void);
82779 +int acl_alloc_stack_init(unsigned long size);
82780 +void *acl_alloc(unsigned long len);
82781 +void *acl_alloc_num(unsigned long num, unsigned long len);
82782 +
82783 +#endif
82784 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
82785 new file mode 100644
82786 index 0000000..be66033
82787 --- /dev/null
82788 +++ b/include/linux/grdefs.h
82789 @@ -0,0 +1,140 @@
82790 +#ifndef GRDEFS_H
82791 +#define GRDEFS_H
82792 +
82793 +/* Begin grsecurity status declarations */
82794 +
82795 +enum {
82796 + GR_READY = 0x01,
82797 + GR_STATUS_INIT = 0x00 // disabled state
82798 +};
82799 +
82800 +/* Begin ACL declarations */
82801 +
82802 +/* Role flags */
82803 +
82804 +enum {
82805 + GR_ROLE_USER = 0x0001,
82806 + GR_ROLE_GROUP = 0x0002,
82807 + GR_ROLE_DEFAULT = 0x0004,
82808 + GR_ROLE_SPECIAL = 0x0008,
82809 + GR_ROLE_AUTH = 0x0010,
82810 + GR_ROLE_NOPW = 0x0020,
82811 + GR_ROLE_GOD = 0x0040,
82812 + GR_ROLE_LEARN = 0x0080,
82813 + GR_ROLE_TPE = 0x0100,
82814 + GR_ROLE_DOMAIN = 0x0200,
82815 + GR_ROLE_PAM = 0x0400,
82816 + GR_ROLE_PERSIST = 0x0800
82817 +};
82818 +
82819 +/* ACL Subject and Object mode flags */
82820 +enum {
82821 + GR_DELETED = 0x80000000
82822 +};
82823 +
82824 +/* ACL Object-only mode flags */
82825 +enum {
82826 + GR_READ = 0x00000001,
82827 + GR_APPEND = 0x00000002,
82828 + GR_WRITE = 0x00000004,
82829 + GR_EXEC = 0x00000008,
82830 + GR_FIND = 0x00000010,
82831 + GR_INHERIT = 0x00000020,
82832 + GR_SETID = 0x00000040,
82833 + GR_CREATE = 0x00000080,
82834 + GR_DELETE = 0x00000100,
82835 + GR_LINK = 0x00000200,
82836 + GR_AUDIT_READ = 0x00000400,
82837 + GR_AUDIT_APPEND = 0x00000800,
82838 + GR_AUDIT_WRITE = 0x00001000,
82839 + GR_AUDIT_EXEC = 0x00002000,
82840 + GR_AUDIT_FIND = 0x00004000,
82841 + GR_AUDIT_INHERIT= 0x00008000,
82842 + GR_AUDIT_SETID = 0x00010000,
82843 + GR_AUDIT_CREATE = 0x00020000,
82844 + GR_AUDIT_DELETE = 0x00040000,
82845 + GR_AUDIT_LINK = 0x00080000,
82846 + GR_PTRACERD = 0x00100000,
82847 + GR_NOPTRACE = 0x00200000,
82848 + GR_SUPPRESS = 0x00400000,
82849 + GR_NOLEARN = 0x00800000,
82850 + GR_INIT_TRANSFER= 0x01000000
82851 +};
82852 +
82853 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
82854 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
82855 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
82856 +
82857 +/* ACL subject-only mode flags */
82858 +enum {
82859 + GR_KILL = 0x00000001,
82860 + GR_VIEW = 0x00000002,
82861 + GR_PROTECTED = 0x00000004,
82862 + GR_LEARN = 0x00000008,
82863 + GR_OVERRIDE = 0x00000010,
82864 + /* just a placeholder, this mode is only used in userspace */
82865 + GR_DUMMY = 0x00000020,
82866 + GR_PROTSHM = 0x00000040,
82867 + GR_KILLPROC = 0x00000080,
82868 + GR_KILLIPPROC = 0x00000100,
82869 + /* just a placeholder, this mode is only used in userspace */
82870 + GR_NOTROJAN = 0x00000200,
82871 + GR_PROTPROCFD = 0x00000400,
82872 + GR_PROCACCT = 0x00000800,
82873 + GR_RELAXPTRACE = 0x00001000,
82874 + //GR_NESTED = 0x00002000,
82875 + GR_INHERITLEARN = 0x00004000,
82876 + GR_PROCFIND = 0x00008000,
82877 + GR_POVERRIDE = 0x00010000,
82878 + GR_KERNELAUTH = 0x00020000,
82879 + GR_ATSECURE = 0x00040000,
82880 + GR_SHMEXEC = 0x00080000
82881 +};
82882 +
82883 +enum {
82884 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
82885 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
82886 + GR_PAX_ENABLE_MPROTECT = 0x0004,
82887 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
82888 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
82889 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
82890 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
82891 + GR_PAX_DISABLE_MPROTECT = 0x0400,
82892 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
82893 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
82894 +};
82895 +
82896 +enum {
82897 + GR_ID_USER = 0x01,
82898 + GR_ID_GROUP = 0x02,
82899 +};
82900 +
82901 +enum {
82902 + GR_ID_ALLOW = 0x01,
82903 + GR_ID_DENY = 0x02,
82904 +};
82905 +
82906 +#define GR_CRASH_RES 31
82907 +#define GR_UIDTABLE_MAX 500
82908 +
82909 +/* begin resource learning section */
82910 +enum {
82911 + GR_RLIM_CPU_BUMP = 60,
82912 + GR_RLIM_FSIZE_BUMP = 50000,
82913 + GR_RLIM_DATA_BUMP = 10000,
82914 + GR_RLIM_STACK_BUMP = 1000,
82915 + GR_RLIM_CORE_BUMP = 10000,
82916 + GR_RLIM_RSS_BUMP = 500000,
82917 + GR_RLIM_NPROC_BUMP = 1,
82918 + GR_RLIM_NOFILE_BUMP = 5,
82919 + GR_RLIM_MEMLOCK_BUMP = 50000,
82920 + GR_RLIM_AS_BUMP = 500000,
82921 + GR_RLIM_LOCKS_BUMP = 2,
82922 + GR_RLIM_SIGPENDING_BUMP = 5,
82923 + GR_RLIM_MSGQUEUE_BUMP = 10000,
82924 + GR_RLIM_NICE_BUMP = 1,
82925 + GR_RLIM_RTPRIO_BUMP = 1,
82926 + GR_RLIM_RTTIME_BUMP = 1000000
82927 +};
82928 +
82929 +#endif
82930 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
82931 new file mode 100644
82932 index 0000000..d25522e
82933 --- /dev/null
82934 +++ b/include/linux/grinternal.h
82935 @@ -0,0 +1,229 @@
82936 +#ifndef __GRINTERNAL_H
82937 +#define __GRINTERNAL_H
82938 +
82939 +#ifdef CONFIG_GRKERNSEC
82940 +
82941 +#include <linux/fs.h>
82942 +#include <linux/mnt_namespace.h>
82943 +#include <linux/nsproxy.h>
82944 +#include <linux/gracl.h>
82945 +#include <linux/grdefs.h>
82946 +#include <linux/grmsg.h>
82947 +
82948 +void gr_add_learn_entry(const char *fmt, ...)
82949 + __attribute__ ((format (printf, 1, 2)));
82950 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
82951 + const struct vfsmount *mnt);
82952 +__u32 gr_check_create(const struct dentry *new_dentry,
82953 + const struct dentry *parent,
82954 + const struct vfsmount *mnt, const __u32 mode);
82955 +int gr_check_protected_task(const struct task_struct *task);
82956 +__u32 to_gr_audit(const __u32 reqmode);
82957 +int gr_set_acls(const int type);
82958 +int gr_acl_is_enabled(void);
82959 +char gr_roletype_to_char(void);
82960 +
82961 +void gr_handle_alertkill(struct task_struct *task);
82962 +char *gr_to_filename(const struct dentry *dentry,
82963 + const struct vfsmount *mnt);
82964 +char *gr_to_filename1(const struct dentry *dentry,
82965 + const struct vfsmount *mnt);
82966 +char *gr_to_filename2(const struct dentry *dentry,
82967 + const struct vfsmount *mnt);
82968 +char *gr_to_filename3(const struct dentry *dentry,
82969 + const struct vfsmount *mnt);
82970 +
82971 +extern int grsec_enable_ptrace_readexec;
82972 +extern int grsec_enable_harden_ptrace;
82973 +extern int grsec_enable_link;
82974 +extern int grsec_enable_fifo;
82975 +extern int grsec_enable_execve;
82976 +extern int grsec_enable_shm;
82977 +extern int grsec_enable_execlog;
82978 +extern int grsec_enable_signal;
82979 +extern int grsec_enable_audit_ptrace;
82980 +extern int grsec_enable_forkfail;
82981 +extern int grsec_enable_time;
82982 +extern int grsec_enable_rofs;
82983 +extern int grsec_deny_new_usb;
82984 +extern int grsec_enable_chroot_shmat;
82985 +extern int grsec_enable_chroot_mount;
82986 +extern int grsec_enable_chroot_double;
82987 +extern int grsec_enable_chroot_pivot;
82988 +extern int grsec_enable_chroot_chdir;
82989 +extern int grsec_enable_chroot_chmod;
82990 +extern int grsec_enable_chroot_mknod;
82991 +extern int grsec_enable_chroot_fchdir;
82992 +extern int grsec_enable_chroot_nice;
82993 +extern int grsec_enable_chroot_execlog;
82994 +extern int grsec_enable_chroot_caps;
82995 +extern int grsec_enable_chroot_sysctl;
82996 +extern int grsec_enable_chroot_unix;
82997 +extern int grsec_enable_symlinkown;
82998 +extern kgid_t grsec_symlinkown_gid;
82999 +extern int grsec_enable_tpe;
83000 +extern kgid_t grsec_tpe_gid;
83001 +extern int grsec_enable_tpe_all;
83002 +extern int grsec_enable_tpe_invert;
83003 +extern int grsec_enable_socket_all;
83004 +extern kgid_t grsec_socket_all_gid;
83005 +extern int grsec_enable_socket_client;
83006 +extern kgid_t grsec_socket_client_gid;
83007 +extern int grsec_enable_socket_server;
83008 +extern kgid_t grsec_socket_server_gid;
83009 +extern kgid_t grsec_audit_gid;
83010 +extern int grsec_enable_group;
83011 +extern int grsec_enable_log_rwxmaps;
83012 +extern int grsec_enable_mount;
83013 +extern int grsec_enable_chdir;
83014 +extern int grsec_resource_logging;
83015 +extern int grsec_enable_blackhole;
83016 +extern int grsec_lastack_retries;
83017 +extern int grsec_enable_brute;
83018 +extern int grsec_enable_harden_ipc;
83019 +extern int grsec_lock;
83020 +
83021 +extern spinlock_t grsec_alert_lock;
83022 +extern unsigned long grsec_alert_wtime;
83023 +extern unsigned long grsec_alert_fyet;
83024 +
83025 +extern spinlock_t grsec_audit_lock;
83026 +
83027 +extern rwlock_t grsec_exec_file_lock;
83028 +
83029 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
83030 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
83031 + (tsk)->exec_file->f_path.mnt) : "/")
83032 +
83033 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
83034 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
83035 + (tsk)->real_parent->exec_file->f_path.mnt) : "/")
83036 +
83037 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
83038 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
83039 + (tsk)->exec_file->f_path.mnt) : "/")
83040 +
83041 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
83042 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
83043 + (tsk)->real_parent->exec_file->f_path.mnt) : "/")
83044 +
83045 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
83046 +
83047 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
83048 +
83049 +static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
83050 +{
83051 + if (file1 && file2) {
83052 + const struct inode *inode1 = file1->f_path.dentry->d_inode;
83053 + const struct inode *inode2 = file2->f_path.dentry->d_inode;
83054 + if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
83055 + return true;
83056 + }
83057 +
83058 + return false;
83059 +}
83060 +
83061 +#define GR_CHROOT_CAPS {{ \
83062 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
83063 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
83064 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
83065 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
83066 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
83067 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
83068 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
83069 +
83070 +#define security_learn(normal_msg,args...) \
83071 +({ \
83072 + read_lock(&grsec_exec_file_lock); \
83073 + gr_add_learn_entry(normal_msg "\n", ## args); \
83074 + read_unlock(&grsec_exec_file_lock); \
83075 +})
83076 +
83077 +enum {
83078 + GR_DO_AUDIT,
83079 + GR_DONT_AUDIT,
83080 + /* used for non-audit messages that we shouldn't kill the task on */
83081 + GR_DONT_AUDIT_GOOD
83082 +};
83083 +
83084 +enum {
83085 + GR_TTYSNIFF,
83086 + GR_RBAC,
83087 + GR_RBAC_STR,
83088 + GR_STR_RBAC,
83089 + GR_RBAC_MODE2,
83090 + GR_RBAC_MODE3,
83091 + GR_FILENAME,
83092 + GR_SYSCTL_HIDDEN,
83093 + GR_NOARGS,
83094 + GR_ONE_INT,
83095 + GR_ONE_INT_TWO_STR,
83096 + GR_ONE_STR,
83097 + GR_STR_INT,
83098 + GR_TWO_STR_INT,
83099 + GR_TWO_INT,
83100 + GR_TWO_U64,
83101 + GR_THREE_INT,
83102 + GR_FIVE_INT_TWO_STR,
83103 + GR_TWO_STR,
83104 + GR_THREE_STR,
83105 + GR_FOUR_STR,
83106 + GR_STR_FILENAME,
83107 + GR_FILENAME_STR,
83108 + GR_FILENAME_TWO_INT,
83109 + GR_FILENAME_TWO_INT_STR,
83110 + GR_TEXTREL,
83111 + GR_PTRACE,
83112 + GR_RESOURCE,
83113 + GR_CAP,
83114 + GR_SIG,
83115 + GR_SIG2,
83116 + GR_CRASH1,
83117 + GR_CRASH2,
83118 + GR_PSACCT,
83119 + GR_RWXMAP,
83120 + GR_RWXMAPVMA
83121 +};
83122 +
83123 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
83124 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
83125 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
83126 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
83127 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
83128 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
83129 +#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)
83130 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
83131 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
83132 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
83133 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
83134 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
83135 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
83136 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
83137 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
83138 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
83139 +#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)
83140 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
83141 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
83142 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
83143 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
83144 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
83145 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
83146 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
83147 +#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)
83148 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
83149 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
83150 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
83151 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
83152 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
83153 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
83154 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
83155 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
83156 +#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)
83157 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
83158 +#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
83159 +
83160 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
83161 +
83162 +#endif
83163 +
83164 +#endif
83165 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
83166 new file mode 100644
83167 index 0000000..b02ba9d
83168 --- /dev/null
83169 +++ b/include/linux/grmsg.h
83170 @@ -0,0 +1,117 @@
83171 +#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"
83172 +#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"
83173 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
83174 +#define GR_STOPMOD_MSG "denied modification of module state by "
83175 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
83176 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
83177 +#define GR_IOPERM_MSG "denied use of ioperm() by "
83178 +#define GR_IOPL_MSG "denied use of iopl() by "
83179 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
83180 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
83181 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
83182 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
83183 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
83184 +#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"
83185 +#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"
83186 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
83187 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
83188 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
83189 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
83190 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
83191 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
83192 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
83193 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
83194 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
83195 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
83196 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
83197 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
83198 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
83199 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
83200 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
83201 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
83202 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
83203 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
83204 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
83205 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
83206 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
83207 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
83208 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
83209 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
83210 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
83211 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
83212 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
83213 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
83214 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
83215 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
83216 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
83217 +#define GR_CHROOT_FHANDLE_MSG "denied use of file handles inside chroot by "
83218 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
83219 +#define GR_SETXATTR_ACL_MSG "%s setting extended attribute of %.950s by "
83220 +#define GR_REMOVEXATTR_ACL_MSG "%s removing extended attribute of %.950s by "
83221 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
83222 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
83223 +#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"
83224 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
83225 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
83226 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
83227 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
83228 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
83229 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
83230 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
83231 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
83232 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
83233 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
83234 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
83235 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
83236 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
83237 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
83238 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
83239 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
83240 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
83241 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
83242 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
83243 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
83244 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
83245 +#define GR_NICE_CHROOT_MSG "denied priority change by "
83246 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
83247 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
83248 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
83249 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
83250 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
83251 +#define GR_TIME_MSG "time set by "
83252 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
83253 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
83254 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
83255 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
83256 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
83257 +#define GR_BIND_MSG "denied bind() by "
83258 +#define GR_CONNECT_MSG "denied connect() by "
83259 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
83260 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
83261 +#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"
83262 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
83263 +#define GR_CAP_ACL_MSG "use of %s denied for "
83264 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
83265 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
83266 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
83267 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
83268 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
83269 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
83270 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
83271 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
83272 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
83273 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
83274 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
83275 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
83276 +#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
83277 +#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
83278 +#define GR_VM86_MSG "denied use of vm86 by "
83279 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
83280 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
83281 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
83282 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
83283 +#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
83284 +#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 "
83285 +#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 "
83286 +#define GR_IPC_DENIED_MSG "denied %s of overly-permissive IPC object with creator uid %u by "
83287 +#define GR_MSRWRITE_MSG "denied write to CPU MSR by "
83288 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
83289 new file mode 100644
83290 index 0000000..10b9635
83291 --- /dev/null
83292 +++ b/include/linux/grsecurity.h
83293 @@ -0,0 +1,254 @@
83294 +#ifndef GR_SECURITY_H
83295 +#define GR_SECURITY_H
83296 +#include <linux/fs.h>
83297 +#include <linux/fs_struct.h>
83298 +#include <linux/binfmts.h>
83299 +#include <linux/gracl.h>
83300 +
83301 +/* notify of brain-dead configs */
83302 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
83303 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
83304 +#endif
83305 +#if defined(CONFIG_GRKERNSEC_PROC) && !defined(CONFIG_GRKERNSEC_PROC_USER) && !defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
83306 +#error "CONFIG_GRKERNSEC_PROC enabled, but neither CONFIG_GRKERNSEC_PROC_USER nor CONFIG_GRKERNSEC_PROC_USERGROUP enabled"
83307 +#endif
83308 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
83309 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
83310 +#endif
83311 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
83312 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
83313 +#endif
83314 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
83315 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
83316 +#endif
83317 +
83318 +int gr_handle_new_usb(void);
83319 +
83320 +void gr_handle_brute_attach(int dumpable);
83321 +void gr_handle_brute_check(void);
83322 +void gr_handle_kernel_exploit(void);
83323 +
83324 +char gr_roletype_to_char(void);
83325 +
83326 +int gr_proc_is_restricted(void);
83327 +
83328 +int gr_acl_enable_at_secure(void);
83329 +
83330 +int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
83331 +int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
83332 +
83333 +int gr_learn_cap(const struct task_struct *task, const struct cred *cred, const int cap);
83334 +
83335 +void gr_del_task_from_ip_table(struct task_struct *p);
83336 +
83337 +int gr_pid_is_chrooted(struct task_struct *p);
83338 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
83339 +int gr_handle_chroot_nice(void);
83340 +int gr_handle_chroot_sysctl(const int op);
83341 +int gr_handle_chroot_setpriority(struct task_struct *p,
83342 + const int niceval);
83343 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
83344 +int gr_chroot_fhandle(void);
83345 +int gr_handle_chroot_chroot(const struct dentry *dentry,
83346 + const struct vfsmount *mnt);
83347 +void gr_handle_chroot_chdir(const struct path *path);
83348 +int gr_handle_chroot_chmod(const struct dentry *dentry,
83349 + const struct vfsmount *mnt, const int mode);
83350 +int gr_handle_chroot_mknod(const struct dentry *dentry,
83351 + const struct vfsmount *mnt, const int mode);
83352 +int gr_handle_chroot_mount(const struct dentry *dentry,
83353 + const struct vfsmount *mnt,
83354 + const char *dev_name);
83355 +int gr_handle_chroot_pivot(void);
83356 +int gr_handle_chroot_unix(const pid_t pid);
83357 +
83358 +int gr_handle_rawio(const struct inode *inode);
83359 +
83360 +void gr_handle_ioperm(void);
83361 +void gr_handle_iopl(void);
83362 +void gr_handle_msr_write(void);
83363 +
83364 +umode_t gr_acl_umask(void);
83365 +
83366 +int gr_tpe_allow(const struct file *file);
83367 +
83368 +void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
83369 +void gr_clear_chroot_entries(struct task_struct *task);
83370 +
83371 +void gr_log_forkfail(const int retval);
83372 +void gr_log_timechange(void);
83373 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
83374 +void gr_log_chdir(const struct dentry *dentry,
83375 + const struct vfsmount *mnt);
83376 +void gr_log_chroot_exec(const struct dentry *dentry,
83377 + const struct vfsmount *mnt);
83378 +void gr_log_remount(const char *devname, const int retval);
83379 +void gr_log_unmount(const char *devname, const int retval);
83380 +void gr_log_mount(const char *from, const char *to, const int retval);
83381 +void gr_log_textrel(struct vm_area_struct *vma);
83382 +void gr_log_ptgnustack(struct file *file);
83383 +void gr_log_rwxmmap(struct file *file);
83384 +void gr_log_rwxmprotect(struct vm_area_struct *vma);
83385 +
83386 +int gr_handle_follow_link(const struct inode *parent,
83387 + const struct inode *inode,
83388 + const struct dentry *dentry,
83389 + const struct vfsmount *mnt);
83390 +int gr_handle_fifo(const struct dentry *dentry,
83391 + const struct vfsmount *mnt,
83392 + const struct dentry *dir, const int flag,
83393 + const int acc_mode);
83394 +int gr_handle_hardlink(const struct dentry *dentry,
83395 + const struct vfsmount *mnt,
83396 + struct inode *inode,
83397 + const int mode, const struct filename *to);
83398 +
83399 +int gr_is_capable(const int cap);
83400 +int gr_is_capable_nolog(const int cap);
83401 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
83402 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
83403 +
83404 +void gr_copy_label(struct task_struct *tsk);
83405 +void gr_handle_crash(struct task_struct *task, const int sig);
83406 +int gr_handle_signal(const struct task_struct *p, const int sig);
83407 +int gr_check_crash_uid(const kuid_t uid);
83408 +int gr_check_protected_task(const struct task_struct *task);
83409 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
83410 +int gr_acl_handle_mmap(const struct file *file,
83411 + const unsigned long prot);
83412 +int gr_acl_handle_mprotect(const struct file *file,
83413 + const unsigned long prot);
83414 +int gr_check_hidden_task(const struct task_struct *tsk);
83415 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
83416 + const struct vfsmount *mnt);
83417 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
83418 + const struct vfsmount *mnt);
83419 +__u32 gr_acl_handle_access(const struct dentry *dentry,
83420 + const struct vfsmount *mnt, const int fmode);
83421 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
83422 + const struct vfsmount *mnt, umode_t *mode);
83423 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
83424 + const struct vfsmount *mnt);
83425 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
83426 + const struct vfsmount *mnt);
83427 +__u32 gr_acl_handle_removexattr(const struct dentry *dentry,
83428 + const struct vfsmount *mnt);
83429 +int gr_handle_ptrace(struct task_struct *task, const long request);
83430 +int gr_handle_proc_ptrace(struct task_struct *task);
83431 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
83432 + const struct vfsmount *mnt);
83433 +int gr_check_crash_exec(const struct file *filp);
83434 +int gr_acl_is_enabled(void);
83435 +void gr_set_role_label(struct task_struct *task, const kuid_t uid,
83436 + const kgid_t gid);
83437 +int gr_set_proc_label(const struct dentry *dentry,
83438 + const struct vfsmount *mnt,
83439 + const int unsafe_flags);
83440 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
83441 + const struct vfsmount *mnt);
83442 +__u32 gr_acl_handle_open(const struct dentry *dentry,
83443 + const struct vfsmount *mnt, int acc_mode);
83444 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
83445 + const struct dentry *p_dentry,
83446 + const struct vfsmount *p_mnt,
83447 + int open_flags, int acc_mode, const int imode);
83448 +void gr_handle_create(const struct dentry *dentry,
83449 + const struct vfsmount *mnt);
83450 +void gr_handle_proc_create(const struct dentry *dentry,
83451 + const struct inode *inode);
83452 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
83453 + const struct dentry *parent_dentry,
83454 + const struct vfsmount *parent_mnt,
83455 + const int mode);
83456 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
83457 + const struct dentry *parent_dentry,
83458 + const struct vfsmount *parent_mnt);
83459 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
83460 + const struct vfsmount *mnt);
83461 +void gr_handle_delete(const ino_t ino, const dev_t dev);
83462 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
83463 + const struct vfsmount *mnt);
83464 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
83465 + const struct dentry *parent_dentry,
83466 + const struct vfsmount *parent_mnt,
83467 + const struct filename *from);
83468 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
83469 + const struct dentry *parent_dentry,
83470 + const struct vfsmount *parent_mnt,
83471 + const struct dentry *old_dentry,
83472 + const struct vfsmount *old_mnt, const struct filename *to);
83473 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
83474 +int gr_acl_handle_rename(struct dentry *new_dentry,
83475 + struct dentry *parent_dentry,
83476 + const struct vfsmount *parent_mnt,
83477 + struct dentry *old_dentry,
83478 + struct inode *old_parent_inode,
83479 + struct vfsmount *old_mnt, const struct filename *newname, unsigned int flags);
83480 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
83481 + struct dentry *old_dentry,
83482 + struct dentry *new_dentry,
83483 + struct vfsmount *mnt, const __u8 replace, unsigned int flags);
83484 +__u32 gr_check_link(const struct dentry *new_dentry,
83485 + const struct dentry *parent_dentry,
83486 + const struct vfsmount *parent_mnt,
83487 + const struct dentry *old_dentry,
83488 + const struct vfsmount *old_mnt);
83489 +int gr_acl_handle_filldir(const struct file *file, const char *name,
83490 + const unsigned int namelen, const ino_t ino);
83491 +
83492 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
83493 + const struct vfsmount *mnt);
83494 +void gr_acl_handle_exit(void);
83495 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
83496 +int gr_acl_handle_procpidmem(const struct task_struct *task);
83497 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
83498 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
83499 +void gr_audit_ptrace(struct task_struct *task);
83500 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
83501 +void gr_put_exec_file(struct task_struct *task);
83502 +
83503 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
83504 +
83505 +#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
83506 +extern void gr_learn_resource(const struct task_struct *task, const int res,
83507 + const unsigned long wanted, const int gt);
83508 +#else
83509 +static inline void gr_learn_resource(const struct task_struct *task, const int res,
83510 + const unsigned long wanted, const int gt)
83511 +{
83512 +}
83513 +#endif
83514 +
83515 +#ifdef CONFIG_GRKERNSEC_RESLOG
83516 +extern void gr_log_resource(const struct task_struct *task, const int res,
83517 + const unsigned long wanted, const int gt);
83518 +#else
83519 +static inline void gr_log_resource(const struct task_struct *task, const int res,
83520 + const unsigned long wanted, const int gt)
83521 +{
83522 +}
83523 +#endif
83524 +
83525 +#ifdef CONFIG_GRKERNSEC
83526 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
83527 +void gr_handle_vm86(void);
83528 +void gr_handle_mem_readwrite(u64 from, u64 to);
83529 +
83530 +void gr_log_badprocpid(const char *entry);
83531 +
83532 +extern int grsec_enable_dmesg;
83533 +extern int grsec_disable_privio;
83534 +
83535 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
83536 +extern kgid_t grsec_proc_gid;
83537 +#endif
83538 +
83539 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
83540 +extern int grsec_enable_chroot_findtask;
83541 +#endif
83542 +#ifdef CONFIG_GRKERNSEC_SETXID
83543 +extern int grsec_enable_setxid;
83544 +#endif
83545 +#endif
83546 +
83547 +#endif
83548 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
83549 new file mode 100644
83550 index 0000000..e7ffaaf
83551 --- /dev/null
83552 +++ b/include/linux/grsock.h
83553 @@ -0,0 +1,19 @@
83554 +#ifndef __GRSOCK_H
83555 +#define __GRSOCK_H
83556 +
83557 +extern void gr_attach_curr_ip(const struct sock *sk);
83558 +extern int gr_handle_sock_all(const int family, const int type,
83559 + const int protocol);
83560 +extern int gr_handle_sock_server(const struct sockaddr *sck);
83561 +extern int gr_handle_sock_server_other(const struct sock *sck);
83562 +extern int gr_handle_sock_client(const struct sockaddr *sck);
83563 +extern int gr_search_connect(struct socket * sock,
83564 + struct sockaddr_in * addr);
83565 +extern int gr_search_bind(struct socket * sock,
83566 + struct sockaddr_in * addr);
83567 +extern int gr_search_listen(struct socket * sock);
83568 +extern int gr_search_accept(struct socket * sock);
83569 +extern int gr_search_socket(const int domain, const int type,
83570 + const int protocol);
83571 +
83572 +#endif
83573 diff --git a/include/linux/hash.h b/include/linux/hash.h
83574 index d0494c3..69b7715 100644
83575 --- a/include/linux/hash.h
83576 +++ b/include/linux/hash.h
83577 @@ -87,7 +87,7 @@ static inline u32 hash32_ptr(const void *ptr)
83578 struct fast_hash_ops {
83579 u32 (*hash)(const void *data, u32 len, u32 seed);
83580 u32 (*hash2)(const u32 *data, u32 len, u32 seed);
83581 -};
83582 +} __no_const;
83583
83584 /**
83585 * arch_fast_hash - Caclulates a hash over a given buffer that can have
83586 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
83587 index 9286a46..373f27f 100644
83588 --- a/include/linux/highmem.h
83589 +++ b/include/linux/highmem.h
83590 @@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
83591 kunmap_atomic(kaddr);
83592 }
83593
83594 +static inline void sanitize_highpage(struct page *page)
83595 +{
83596 + void *kaddr;
83597 + unsigned long flags;
83598 +
83599 + local_irq_save(flags);
83600 + kaddr = kmap_atomic(page);
83601 + clear_page(kaddr);
83602 + kunmap_atomic(kaddr);
83603 + local_irq_restore(flags);
83604 +}
83605 +
83606 static inline void zero_user_segments(struct page *page,
83607 unsigned start1, unsigned end1,
83608 unsigned start2, unsigned end2)
83609 diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
83610 index 1c7b89a..7dda400 100644
83611 --- a/include/linux/hwmon-sysfs.h
83612 +++ b/include/linux/hwmon-sysfs.h
83613 @@ -25,7 +25,8 @@
83614 struct sensor_device_attribute{
83615 struct device_attribute dev_attr;
83616 int index;
83617 -};
83618 +} __do_const;
83619 +typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
83620 #define to_sensor_dev_attr(_dev_attr) \
83621 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
83622
83623 @@ -41,7 +42,8 @@ struct sensor_device_attribute_2 {
83624 struct device_attribute dev_attr;
83625 u8 index;
83626 u8 nr;
83627 -};
83628 +} __do_const;
83629 +typedef struct sensor_device_attribute_2 __no_const sensor_device_attribute_2_no_const;
83630 #define to_sensor_dev_attr_2(_dev_attr) \
83631 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
83632
83633 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
83634 index b556e0a..c10a515 100644
83635 --- a/include/linux/i2c.h
83636 +++ b/include/linux/i2c.h
83637 @@ -378,6 +378,7 @@ struct i2c_algorithm {
83638 /* To determine what the adapter supports */
83639 u32 (*functionality) (struct i2c_adapter *);
83640 };
83641 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
83642
83643 /**
83644 * struct i2c_bus_recovery_info - I2C bus recovery information
83645 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
83646 index d23c3c2..eb63c81 100644
83647 --- a/include/linux/i2o.h
83648 +++ b/include/linux/i2o.h
83649 @@ -565,7 +565,7 @@ struct i2o_controller {
83650 struct i2o_device *exec; /* Executive */
83651 #if BITS_PER_LONG == 64
83652 spinlock_t context_list_lock; /* lock for context_list */
83653 - atomic_t context_list_counter; /* needed for unique contexts */
83654 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
83655 struct list_head context_list; /* list of context id's
83656 and pointers */
83657 #endif
83658 diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
83659 index aff7ad8..3942bbd 100644
83660 --- a/include/linux/if_pppox.h
83661 +++ b/include/linux/if_pppox.h
83662 @@ -76,7 +76,7 @@ struct pppox_proto {
83663 int (*ioctl)(struct socket *sock, unsigned int cmd,
83664 unsigned long arg);
83665 struct module *owner;
83666 -};
83667 +} __do_const;
83668
83669 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
83670 extern void unregister_pppox_proto(int proto_num);
83671 diff --git a/include/linux/init.h b/include/linux/init.h
83672 index 2df8e8d..3e1280d 100644
83673 --- a/include/linux/init.h
83674 +++ b/include/linux/init.h
83675 @@ -37,9 +37,17 @@
83676 * section.
83677 */
83678
83679 +#define add_init_latent_entropy __latent_entropy
83680 +
83681 +#ifdef CONFIG_MEMORY_HOTPLUG
83682 +#define add_meminit_latent_entropy
83683 +#else
83684 +#define add_meminit_latent_entropy __latent_entropy
83685 +#endif
83686 +
83687 /* These are for everybody (although not all archs will actually
83688 discard it in modules) */
83689 -#define __init __section(.init.text) __cold notrace
83690 +#define __init __section(.init.text) __cold notrace add_init_latent_entropy
83691 #define __initdata __section(.init.data)
83692 #define __initconst __constsection(.init.rodata)
83693 #define __exitdata __section(.exit.data)
83694 @@ -100,7 +108,7 @@
83695 #define __cpuexitconst
83696
83697 /* Used for MEMORY_HOTPLUG */
83698 -#define __meminit __section(.meminit.text) __cold notrace
83699 +#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
83700 #define __meminitdata __section(.meminit.data)
83701 #define __meminitconst __constsection(.meminit.rodata)
83702 #define __memexit __section(.memexit.text) __exitused __cold notrace
83703 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
83704 index 2bb4c4f3..e0fac69 100644
83705 --- a/include/linux/init_task.h
83706 +++ b/include/linux/init_task.h
83707 @@ -149,6 +149,12 @@ extern struct task_group root_task_group;
83708
83709 #define INIT_TASK_COMM "swapper"
83710
83711 +#ifdef CONFIG_X86
83712 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
83713 +#else
83714 +#define INIT_TASK_THREAD_INFO
83715 +#endif
83716 +
83717 #ifdef CONFIG_RT_MUTEXES
83718 # define INIT_RT_MUTEXES(tsk) \
83719 .pi_waiters = RB_ROOT, \
83720 @@ -196,6 +202,7 @@ extern struct task_group root_task_group;
83721 RCU_POINTER_INITIALIZER(cred, &init_cred), \
83722 .comm = INIT_TASK_COMM, \
83723 .thread = INIT_THREAD, \
83724 + INIT_TASK_THREAD_INFO \
83725 .fs = &init_fs, \
83726 .files = &init_files, \
83727 .signal = &init_signals, \
83728 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
83729 index 698ad05..8601bb7 100644
83730 --- a/include/linux/interrupt.h
83731 +++ b/include/linux/interrupt.h
83732 @@ -418,8 +418,8 @@ extern const char * const softirq_to_name[NR_SOFTIRQS];
83733
83734 struct softirq_action
83735 {
83736 - void (*action)(struct softirq_action *);
83737 -};
83738 + void (*action)(void);
83739 +} __no_const;
83740
83741 asmlinkage void do_softirq(void);
83742 asmlinkage void __do_softirq(void);
83743 @@ -433,7 +433,7 @@ static inline void do_softirq_own_stack(void)
83744 }
83745 #endif
83746
83747 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
83748 +extern void open_softirq(int nr, void (*action)(void));
83749 extern void softirq_init(void);
83750 extern void __raise_softirq_irqoff(unsigned int nr);
83751
83752 diff --git a/include/linux/iommu.h b/include/linux/iommu.h
83753 index 20f9a52..63ee2e3 100644
83754 --- a/include/linux/iommu.h
83755 +++ b/include/linux/iommu.h
83756 @@ -131,7 +131,7 @@ struct iommu_ops {
83757 u32 (*domain_get_windows)(struct iommu_domain *domain);
83758
83759 unsigned long pgsize_bitmap;
83760 -};
83761 +} __do_const;
83762
83763 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
83764 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
83765 diff --git a/include/linux/ioport.h b/include/linux/ioport.h
83766 index 142ec54..873e033 100644
83767 --- a/include/linux/ioport.h
83768 +++ b/include/linux/ioport.h
83769 @@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
83770 int adjust_resource(struct resource *res, resource_size_t start,
83771 resource_size_t size);
83772 resource_size_t resource_alignment(struct resource *res);
83773 -static inline resource_size_t resource_size(const struct resource *res)
83774 +static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
83775 {
83776 return res->end - res->start + 1;
83777 }
83778 diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h
83779 index 35e7eca..6afb7ad 100644
83780 --- a/include/linux/ipc_namespace.h
83781 +++ b/include/linux/ipc_namespace.h
83782 @@ -69,7 +69,7 @@ struct ipc_namespace {
83783 struct user_namespace *user_ns;
83784
83785 unsigned int proc_inum;
83786 -};
83787 +} __randomize_layout;
83788
83789 extern struct ipc_namespace init_ipc_ns;
83790 extern atomic_t nr_ipc_ns;
83791 diff --git a/include/linux/irq.h b/include/linux/irq.h
83792 index 62af592..cc3b0d0 100644
83793 --- a/include/linux/irq.h
83794 +++ b/include/linux/irq.h
83795 @@ -344,7 +344,8 @@ struct irq_chip {
83796 void (*irq_release_resources)(struct irq_data *data);
83797
83798 unsigned long flags;
83799 -};
83800 +} __do_const;
83801 +typedef struct irq_chip __no_const irq_chip_no_const;
83802
83803 /*
83804 * irq_chip specific flags
83805 diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
83806 index 45e2d8c..26d85da 100644
83807 --- a/include/linux/irqchip/arm-gic.h
83808 +++ b/include/linux/irqchip/arm-gic.h
83809 @@ -75,9 +75,11 @@
83810
83811 #ifndef __ASSEMBLY__
83812
83813 +#include <linux/irq.h>
83814 +
83815 struct device_node;
83816
83817 -extern struct irq_chip gic_arch_extn;
83818 +extern irq_chip_no_const gic_arch_extn;
83819
83820 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
83821 u32 offset, struct device_node *);
83822 diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
83823 index c367cbd..c9b79e6 100644
83824 --- a/include/linux/jiffies.h
83825 +++ b/include/linux/jiffies.h
83826 @@ -280,20 +280,20 @@ extern unsigned long preset_lpj;
83827 /*
83828 * Convert various time units to each other:
83829 */
83830 -extern unsigned int jiffies_to_msecs(const unsigned long j);
83831 -extern unsigned int jiffies_to_usecs(const unsigned long j);
83832 +extern unsigned int jiffies_to_msecs(const unsigned long j) __intentional_overflow(-1);
83833 +extern unsigned int jiffies_to_usecs(const unsigned long j) __intentional_overflow(-1);
83834
83835 -static inline u64 jiffies_to_nsecs(const unsigned long j)
83836 +static inline u64 __intentional_overflow(-1) jiffies_to_nsecs(const unsigned long j)
83837 {
83838 return (u64)jiffies_to_usecs(j) * NSEC_PER_USEC;
83839 }
83840
83841 -extern unsigned long msecs_to_jiffies(const unsigned int m);
83842 -extern unsigned long usecs_to_jiffies(const unsigned int u);
83843 +extern unsigned long msecs_to_jiffies(const unsigned int m) __intentional_overflow(-1);
83844 +extern unsigned long usecs_to_jiffies(const unsigned int u) __intentional_overflow(-1);
83845 extern unsigned long timespec_to_jiffies(const struct timespec *value);
83846 extern void jiffies_to_timespec(const unsigned long jiffies,
83847 - struct timespec *value);
83848 -extern unsigned long timeval_to_jiffies(const struct timeval *value);
83849 + struct timespec *value) __intentional_overflow(-1);
83850 +extern unsigned long timeval_to_jiffies(const struct timeval *value) __intentional_overflow(-1);
83851 extern void jiffies_to_timeval(const unsigned long jiffies,
83852 struct timeval *value);
83853
83854 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
83855 index 6883e19..e854fcb 100644
83856 --- a/include/linux/kallsyms.h
83857 +++ b/include/linux/kallsyms.h
83858 @@ -15,7 +15,8 @@
83859
83860 struct module;
83861
83862 -#ifdef CONFIG_KALLSYMS
83863 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
83864 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
83865 /* Lookup the address for a symbol. Returns 0 if not found. */
83866 unsigned long kallsyms_lookup_name(const char *name);
83867
83868 @@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
83869 /* Stupid that this does nothing, but I didn't create this mess. */
83870 #define __print_symbol(fmt, addr)
83871 #endif /*CONFIG_KALLSYMS*/
83872 +#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
83873 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
83874 +extern unsigned long kallsyms_lookup_name(const char *name);
83875 +extern void __print_symbol(const char *fmt, unsigned long address);
83876 +extern int sprint_backtrace(char *buffer, unsigned long address);
83877 +extern int sprint_symbol(char *buffer, unsigned long address);
83878 +extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
83879 +const char *kallsyms_lookup(unsigned long addr,
83880 + unsigned long *symbolsize,
83881 + unsigned long *offset,
83882 + char **modname, char *namebuf);
83883 +extern int kallsyms_lookup_size_offset(unsigned long addr,
83884 + unsigned long *symbolsize,
83885 + unsigned long *offset);
83886 +#endif
83887
83888 /* This macro allows us to keep printk typechecking */
83889 static __printf(1, 2)
83890 diff --git a/include/linux/key-type.h b/include/linux/key-type.h
83891 index 44792ee..6172f2a 100644
83892 --- a/include/linux/key-type.h
83893 +++ b/include/linux/key-type.h
83894 @@ -132,7 +132,7 @@ struct key_type {
83895 /* internal fields */
83896 struct list_head link; /* link in types list */
83897 struct lock_class_key lock_class; /* key->sem lock class */
83898 -};
83899 +} __do_const;
83900
83901 extern struct key_type key_type_keyring;
83902
83903 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
83904 index e465bb1..19f605f 100644
83905 --- a/include/linux/kgdb.h
83906 +++ b/include/linux/kgdb.h
83907 @@ -52,7 +52,7 @@ extern int kgdb_connected;
83908 extern int kgdb_io_module_registered;
83909
83910 extern atomic_t kgdb_setting_breakpoint;
83911 -extern atomic_t kgdb_cpu_doing_single_step;
83912 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
83913
83914 extern struct task_struct *kgdb_usethread;
83915 extern struct task_struct *kgdb_contthread;
83916 @@ -254,7 +254,7 @@ struct kgdb_arch {
83917 void (*correct_hw_break)(void);
83918
83919 void (*enable_nmi)(bool on);
83920 -};
83921 +} __do_const;
83922
83923 /**
83924 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
83925 @@ -279,7 +279,7 @@ struct kgdb_io {
83926 void (*pre_exception) (void);
83927 void (*post_exception) (void);
83928 int is_console;
83929 -};
83930 +} __do_const;
83931
83932 extern struct kgdb_arch arch_kgdb_ops;
83933
83934 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
83935 index 0555cc6..40116ce 100644
83936 --- a/include/linux/kmod.h
83937 +++ b/include/linux/kmod.h
83938 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
83939 * usually useless though. */
83940 extern __printf(2, 3)
83941 int __request_module(bool wait, const char *name, ...);
83942 +extern __printf(3, 4)
83943 +int ___request_module(bool wait, char *param_name, const char *name, ...);
83944 #define request_module(mod...) __request_module(true, mod)
83945 #define request_module_nowait(mod...) __request_module(false, mod)
83946 #define try_then_request_module(x, mod...) \
83947 @@ -57,6 +59,9 @@ struct subprocess_info {
83948 struct work_struct work;
83949 struct completion *complete;
83950 char *path;
83951 +#ifdef CONFIG_GRKERNSEC
83952 + char *origpath;
83953 +#endif
83954 char **argv;
83955 char **envp;
83956 int wait;
83957 diff --git a/include/linux/kobject.h b/include/linux/kobject.h
83958 index 2d61b90..a1d0a13 100644
83959 --- a/include/linux/kobject.h
83960 +++ b/include/linux/kobject.h
83961 @@ -118,7 +118,7 @@ struct kobj_type {
83962 struct attribute **default_attrs;
83963 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
83964 const void *(*namespace)(struct kobject *kobj);
83965 -};
83966 +} __do_const;
83967
83968 struct kobj_uevent_env {
83969 char *argv[3];
83970 @@ -142,6 +142,7 @@ struct kobj_attribute {
83971 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
83972 const char *buf, size_t count);
83973 };
83974 +typedef struct kobj_attribute __no_const kobj_attribute_no_const;
83975
83976 extern const struct sysfs_ops kobj_sysfs_ops;
83977
83978 @@ -169,7 +170,7 @@ struct kset {
83979 spinlock_t list_lock;
83980 struct kobject kobj;
83981 const struct kset_uevent_ops *uevent_ops;
83982 -};
83983 +} __randomize_layout;
83984
83985 extern void kset_init(struct kset *kset);
83986 extern int __must_check kset_register(struct kset *kset);
83987 diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
83988 index df32d25..fb52e27 100644
83989 --- a/include/linux/kobject_ns.h
83990 +++ b/include/linux/kobject_ns.h
83991 @@ -44,7 +44,7 @@ struct kobj_ns_type_operations {
83992 const void *(*netlink_ns)(struct sock *sk);
83993 const void *(*initial_ns)(void);
83994 void (*drop_ns)(void *);
83995 -};
83996 +} __do_const;
83997
83998 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
83999 int kobj_ns_type_registered(enum kobj_ns_type type);
84000 diff --git a/include/linux/kref.h b/include/linux/kref.h
84001 index 484604d..0f6c5b6 100644
84002 --- a/include/linux/kref.h
84003 +++ b/include/linux/kref.h
84004 @@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
84005 static inline int kref_sub(struct kref *kref, unsigned int count,
84006 void (*release)(struct kref *kref))
84007 {
84008 - WARN_ON(release == NULL);
84009 + BUG_ON(release == NULL);
84010
84011 if (atomic_sub_and_test((int) count, &kref->refcount)) {
84012 release(kref);
84013 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
84014 index a4c33b3..e854710 100644
84015 --- a/include/linux/kvm_host.h
84016 +++ b/include/linux/kvm_host.h
84017 @@ -452,7 +452,7 @@ static inline void kvm_irqfd_exit(void)
84018 {
84019 }
84020 #endif
84021 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
84022 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
84023 struct module *module);
84024 void kvm_exit(void);
84025
84026 @@ -618,7 +618,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
84027 struct kvm_guest_debug *dbg);
84028 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
84029
84030 -int kvm_arch_init(void *opaque);
84031 +int kvm_arch_init(const void *opaque);
84032 void kvm_arch_exit(void);
84033
84034 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
84035 diff --git a/include/linux/libata.h b/include/linux/libata.h
84036 index 92abb49..e7fff2a 100644
84037 --- a/include/linux/libata.h
84038 +++ b/include/linux/libata.h
84039 @@ -976,7 +976,7 @@ struct ata_port_operations {
84040 * fields must be pointers.
84041 */
84042 const struct ata_port_operations *inherits;
84043 -};
84044 +} __do_const;
84045
84046 struct ata_port_info {
84047 unsigned long flags;
84048 diff --git a/include/linux/linkage.h b/include/linux/linkage.h
84049 index a6a42dd..6c5ebce 100644
84050 --- a/include/linux/linkage.h
84051 +++ b/include/linux/linkage.h
84052 @@ -36,6 +36,7 @@
84053 #endif
84054
84055 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
84056 +#define __page_aligned_rodata __read_only __aligned(PAGE_SIZE)
84057 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
84058
84059 /*
84060 diff --git a/include/linux/list.h b/include/linux/list.h
84061 index cbbb96f..602d023 100644
84062 --- a/include/linux/list.h
84063 +++ b/include/linux/list.h
84064 @@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
84065 extern void list_del(struct list_head *entry);
84066 #endif
84067
84068 +extern void __pax_list_add(struct list_head *new,
84069 + struct list_head *prev,
84070 + struct list_head *next);
84071 +static inline void pax_list_add(struct list_head *new, struct list_head *head)
84072 +{
84073 + __pax_list_add(new, head, head->next);
84074 +}
84075 +static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
84076 +{
84077 + __pax_list_add(new, head->prev, head);
84078 +}
84079 +extern void pax_list_del(struct list_head *entry);
84080 +
84081 /**
84082 * list_replace - replace old entry by new one
84083 * @old : the element to be replaced
84084 @@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
84085 INIT_LIST_HEAD(entry);
84086 }
84087
84088 +extern void pax_list_del_init(struct list_head *entry);
84089 +
84090 /**
84091 * list_move - delete from one list and add as another's head
84092 * @list: the entry to move
84093 diff --git a/include/linux/lockref.h b/include/linux/lockref.h
84094 index 4bfde0e..d6e2e09 100644
84095 --- a/include/linux/lockref.h
84096 +++ b/include/linux/lockref.h
84097 @@ -47,4 +47,36 @@ static inline int __lockref_is_dead(const struct lockref *l)
84098 return ((int)l->count < 0);
84099 }
84100
84101 +static inline unsigned int __lockref_read(struct lockref *lockref)
84102 +{
84103 + return lockref->count;
84104 +}
84105 +
84106 +static inline void __lockref_set(struct lockref *lockref, unsigned int count)
84107 +{
84108 + lockref->count = count;
84109 +}
84110 +
84111 +static inline void __lockref_inc(struct lockref *lockref)
84112 +{
84113 +
84114 +#ifdef CONFIG_PAX_REFCOUNT
84115 + atomic_inc((atomic_t *)&lockref->count);
84116 +#else
84117 + lockref->count++;
84118 +#endif
84119 +
84120 +}
84121 +
84122 +static inline void __lockref_dec(struct lockref *lockref)
84123 +{
84124 +
84125 +#ifdef CONFIG_PAX_REFCOUNT
84126 + atomic_dec((atomic_t *)&lockref->count);
84127 +#else
84128 + lockref->count--;
84129 +#endif
84130 +
84131 +}
84132 +
84133 #endif /* __LINUX_LOCKREF_H */
84134 diff --git a/include/linux/math64.h b/include/linux/math64.h
84135 index c45c089..298841c 100644
84136 --- a/include/linux/math64.h
84137 +++ b/include/linux/math64.h
84138 @@ -15,7 +15,7 @@
84139 * This is commonly provided by 32bit archs to provide an optimized 64bit
84140 * divide.
84141 */
84142 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
84143 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
84144 {
84145 *remainder = dividend % divisor;
84146 return dividend / divisor;
84147 @@ -42,7 +42,7 @@ static inline u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder)
84148 /**
84149 * div64_u64 - unsigned 64bit divide with 64bit divisor
84150 */
84151 -static inline u64 div64_u64(u64 dividend, u64 divisor)
84152 +static inline u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
84153 {
84154 return dividend / divisor;
84155 }
84156 @@ -61,7 +61,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
84157 #define div64_ul(x, y) div_u64((x), (y))
84158
84159 #ifndef div_u64_rem
84160 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
84161 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
84162 {
84163 *remainder = do_div(dividend, divisor);
84164 return dividend;
84165 @@ -77,7 +77,7 @@ extern u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder);
84166 #endif
84167
84168 #ifndef div64_u64
84169 -extern u64 div64_u64(u64 dividend, u64 divisor);
84170 +extern u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor);
84171 #endif
84172
84173 #ifndef div64_s64
84174 @@ -94,7 +94,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
84175 * divide.
84176 */
84177 #ifndef div_u64
84178 -static inline u64 div_u64(u64 dividend, u32 divisor)
84179 +static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
84180 {
84181 u32 remainder;
84182 return div_u64_rem(dividend, divisor, &remainder);
84183 diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h
84184 index f230a97..714c006 100644
84185 --- a/include/linux/mempolicy.h
84186 +++ b/include/linux/mempolicy.h
84187 @@ -91,6 +91,10 @@ static inline struct mempolicy *mpol_dup(struct mempolicy *pol)
84188 }
84189
84190 #define vma_policy(vma) ((vma)->vm_policy)
84191 +static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
84192 +{
84193 + vma->vm_policy = pol;
84194 +}
84195
84196 static inline void mpol_get(struct mempolicy *pol)
84197 {
84198 @@ -228,6 +232,9 @@ static inline void mpol_free_shared_policy(struct shared_policy *p)
84199 }
84200
84201 #define vma_policy(vma) NULL
84202 +static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
84203 +{
84204 +}
84205
84206 static inline int
84207 vma_dup_policy(struct vm_area_struct *src, struct vm_area_struct *dst)
84208 diff --git a/include/linux/mm.h b/include/linux/mm.h
84209 index f952cc8..b9f6135 100644
84210 --- a/include/linux/mm.h
84211 +++ b/include/linux/mm.h
84212 @@ -127,6 +127,11 @@ extern unsigned int kobjsize(const void *objp);
84213 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
84214 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
84215 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
84216 +
84217 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
84218 +#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
84219 +#endif
84220 +
84221 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
84222
84223 #ifdef CONFIG_MEM_SOFT_DIRTY
84224 @@ -237,8 +242,8 @@ struct vm_operations_struct {
84225 /* called by access_process_vm when get_user_pages() fails, typically
84226 * for use by special VMAs that can switch between memory and hardware
84227 */
84228 - int (*access)(struct vm_area_struct *vma, unsigned long addr,
84229 - void *buf, int len, int write);
84230 + ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
84231 + void *buf, size_t len, int write);
84232
84233 /* Called by the /proc/PID/maps code to ask the vma whether it
84234 * has a special name. Returning non-NULL will also cause this
84235 @@ -274,6 +279,7 @@ struct vm_operations_struct {
84236 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
84237 unsigned long size, pgoff_t pgoff);
84238 };
84239 +typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
84240
84241 struct mmu_gather;
84242 struct inode;
84243 @@ -1163,8 +1169,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
84244 unsigned long *pfn);
84245 int follow_phys(struct vm_area_struct *vma, unsigned long address,
84246 unsigned int flags, unsigned long *prot, resource_size_t *phys);
84247 -int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
84248 - void *buf, int len, int write);
84249 +ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
84250 + void *buf, size_t len, int write);
84251
84252 static inline void unmap_shared_mapping_range(struct address_space *mapping,
84253 loff_t const holebegin, loff_t const holelen)
84254 @@ -1204,9 +1210,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
84255 }
84256 #endif
84257
84258 -extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
84259 -extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
84260 - void *buf, int len, int write);
84261 +extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
84262 +extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
84263 + void *buf, size_t len, int write);
84264
84265 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
84266 unsigned long start, unsigned long nr_pages,
84267 @@ -1238,34 +1244,6 @@ int set_page_dirty_lock(struct page *page);
84268 int clear_page_dirty_for_io(struct page *page);
84269 int get_cmdline(struct task_struct *task, char *buffer, int buflen);
84270
84271 -/* Is the vma a continuation of the stack vma above it? */
84272 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
84273 -{
84274 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
84275 -}
84276 -
84277 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
84278 - unsigned long addr)
84279 -{
84280 - return (vma->vm_flags & VM_GROWSDOWN) &&
84281 - (vma->vm_start == addr) &&
84282 - !vma_growsdown(vma->vm_prev, addr);
84283 -}
84284 -
84285 -/* Is the vma a continuation of the stack vma below it? */
84286 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
84287 -{
84288 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
84289 -}
84290 -
84291 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
84292 - unsigned long addr)
84293 -{
84294 - return (vma->vm_flags & VM_GROWSUP) &&
84295 - (vma->vm_end == addr) &&
84296 - !vma_growsup(vma->vm_next, addr);
84297 -}
84298 -
84299 extern pid_t
84300 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
84301
84302 @@ -1365,6 +1343,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
84303 }
84304 #endif
84305
84306 +#ifdef CONFIG_MMU
84307 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
84308 +#else
84309 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
84310 +{
84311 + return __pgprot(0);
84312 +}
84313 +#endif
84314 +
84315 int vma_wants_writenotify(struct vm_area_struct *vma);
84316
84317 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
84318 @@ -1383,8 +1370,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
84319 {
84320 return 0;
84321 }
84322 +
84323 +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
84324 + unsigned long address)
84325 +{
84326 + return 0;
84327 +}
84328 #else
84329 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
84330 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
84331 #endif
84332
84333 #ifdef __PAGETABLE_PMD_FOLDED
84334 @@ -1393,8 +1387,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
84335 {
84336 return 0;
84337 }
84338 +
84339 +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
84340 + unsigned long address)
84341 +{
84342 + return 0;
84343 +}
84344 #else
84345 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
84346 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
84347 #endif
84348
84349 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
84350 @@ -1412,11 +1413,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
84351 NULL: pud_offset(pgd, address);
84352 }
84353
84354 +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
84355 +{
84356 + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
84357 + NULL: pud_offset(pgd, address);
84358 +}
84359 +
84360 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
84361 {
84362 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
84363 NULL: pmd_offset(pud, address);
84364 }
84365 +
84366 +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
84367 +{
84368 + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
84369 + NULL: pmd_offset(pud, address);
84370 +}
84371 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
84372
84373 #if USE_SPLIT_PTE_PTLOCKS
84374 @@ -1815,7 +1828,7 @@ extern int install_special_mapping(struct mm_struct *mm,
84375 unsigned long addr, unsigned long len,
84376 unsigned long flags, struct page **pages);
84377
84378 -extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
84379 +extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long) __intentional_overflow(-1);
84380
84381 extern unsigned long mmap_region(struct file *file, unsigned long addr,
84382 unsigned long len, vm_flags_t vm_flags, unsigned long pgoff);
84383 @@ -1823,6 +1836,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
84384 unsigned long len, unsigned long prot, unsigned long flags,
84385 unsigned long pgoff, unsigned long *populate);
84386 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
84387 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
84388
84389 #ifdef CONFIG_MMU
84390 extern int __mm_populate(unsigned long addr, unsigned long len,
84391 @@ -1851,10 +1865,11 @@ struct vm_unmapped_area_info {
84392 unsigned long high_limit;
84393 unsigned long align_mask;
84394 unsigned long align_offset;
84395 + unsigned long threadstack_offset;
84396 };
84397
84398 -extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
84399 -extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
84400 +extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
84401 +extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
84402
84403 /*
84404 * Search for an unmapped address range.
84405 @@ -1866,7 +1881,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
84406 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
84407 */
84408 static inline unsigned long
84409 -vm_unmapped_area(struct vm_unmapped_area_info *info)
84410 +vm_unmapped_area(const struct vm_unmapped_area_info *info)
84411 {
84412 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
84413 return unmapped_area(info);
84414 @@ -1928,6 +1943,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
84415 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
84416 struct vm_area_struct **pprev);
84417
84418 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
84419 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
84420 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
84421 +
84422 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
84423 NULL if none. Assume start_addr < end_addr. */
84424 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
84425 @@ -1956,15 +1975,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
84426 return vma;
84427 }
84428
84429 -#ifdef CONFIG_MMU
84430 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
84431 -#else
84432 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
84433 -{
84434 - return __pgprot(0);
84435 -}
84436 -#endif
84437 -
84438 #ifdef CONFIG_NUMA_BALANCING
84439 unsigned long change_prot_numa(struct vm_area_struct *vma,
84440 unsigned long start, unsigned long end);
84441 @@ -2016,6 +2026,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
84442 static inline void vm_stat_account(struct mm_struct *mm,
84443 unsigned long flags, struct file *file, long pages)
84444 {
84445 +
84446 +#ifdef CONFIG_PAX_RANDMMAP
84447 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
84448 +#endif
84449 +
84450 mm->total_vm += pages;
84451 }
84452 #endif /* CONFIG_PROC_FS */
84453 @@ -2104,7 +2119,7 @@ extern int unpoison_memory(unsigned long pfn);
84454 extern int sysctl_memory_failure_early_kill;
84455 extern int sysctl_memory_failure_recovery;
84456 extern void shake_page(struct page *p, int access);
84457 -extern atomic_long_t num_poisoned_pages;
84458 +extern atomic_long_unchecked_t num_poisoned_pages;
84459 extern int soft_offline_page(struct page *page, int flags);
84460
84461 #if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_HUGETLBFS)
84462 @@ -2139,5 +2154,11 @@ void __init setup_nr_node_ids(void);
84463 static inline void setup_nr_node_ids(void) {}
84464 #endif
84465
84466 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
84467 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
84468 +#else
84469 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
84470 +#endif
84471 +
84472 #endif /* __KERNEL__ */
84473 #endif /* _LINUX_MM_H */
84474 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
84475 index 6e0b286..90d9c0d 100644
84476 --- a/include/linux/mm_types.h
84477 +++ b/include/linux/mm_types.h
84478 @@ -308,7 +308,9 @@ struct vm_area_struct {
84479 #ifdef CONFIG_NUMA
84480 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
84481 #endif
84482 -};
84483 +
84484 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
84485 +} __randomize_layout;
84486
84487 struct core_thread {
84488 struct task_struct *task;
84489 @@ -454,7 +456,25 @@ struct mm_struct {
84490 bool tlb_flush_pending;
84491 #endif
84492 struct uprobes_state uprobes_state;
84493 -};
84494 +
84495 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
84496 + unsigned long pax_flags;
84497 +#endif
84498 +
84499 +#ifdef CONFIG_PAX_DLRESOLVE
84500 + unsigned long call_dl_resolve;
84501 +#endif
84502 +
84503 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
84504 + unsigned long call_syscall;
84505 +#endif
84506 +
84507 +#ifdef CONFIG_PAX_ASLR
84508 + unsigned long delta_mmap; /* randomized offset */
84509 + unsigned long delta_stack; /* randomized offset */
84510 +#endif
84511 +
84512 +} __randomize_layout;
84513
84514 static inline void mm_init_cpumask(struct mm_struct *mm)
84515 {
84516 diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
84517 index c5d5278..f0b68c8 100644
84518 --- a/include/linux/mmiotrace.h
84519 +++ b/include/linux/mmiotrace.h
84520 @@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
84521 /* Called from ioremap.c */
84522 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
84523 void __iomem *addr);
84524 -extern void mmiotrace_iounmap(volatile void __iomem *addr);
84525 +extern void mmiotrace_iounmap(const volatile void __iomem *addr);
84526
84527 /* For anyone to insert markers. Remember trailing newline. */
84528 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
84529 @@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
84530 {
84531 }
84532
84533 -static inline void mmiotrace_iounmap(volatile void __iomem *addr)
84534 +static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
84535 {
84536 }
84537
84538 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
84539 index b21bac4..94142ca 100644
84540 --- a/include/linux/mmzone.h
84541 +++ b/include/linux/mmzone.h
84542 @@ -527,7 +527,7 @@ struct zone {
84543
84544 ZONE_PADDING(_pad3_)
84545 /* Zone statistics */
84546 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
84547 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
84548 } ____cacheline_internodealigned_in_smp;
84549
84550 typedef enum {
84551 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
84552 index 44eeef0..a92d3f9 100644
84553 --- a/include/linux/mod_devicetable.h
84554 +++ b/include/linux/mod_devicetable.h
84555 @@ -139,7 +139,7 @@ struct usb_device_id {
84556 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
84557 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
84558
84559 -#define HID_ANY_ID (~0)
84560 +#define HID_ANY_ID (~0U)
84561 #define HID_BUS_ANY 0xffff
84562 #define HID_GROUP_ANY 0x0000
84563
84564 @@ -475,7 +475,7 @@ struct dmi_system_id {
84565 const char *ident;
84566 struct dmi_strmatch matches[4];
84567 void *driver_data;
84568 -};
84569 +} __do_const;
84570 /*
84571 * struct dmi_device_id appears during expansion of
84572 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
84573 diff --git a/include/linux/module.h b/include/linux/module.h
84574 index 71f282a..b2387e2 100644
84575 --- a/include/linux/module.h
84576 +++ b/include/linux/module.h
84577 @@ -17,9 +17,11 @@
84578 #include <linux/moduleparam.h>
84579 #include <linux/jump_label.h>
84580 #include <linux/export.h>
84581 +#include <linux/fs.h>
84582
84583 #include <linux/percpu.h>
84584 #include <asm/module.h>
84585 +#include <asm/pgtable.h>
84586
84587 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
84588 #define MODULE_SIG_STRING "~Module signature appended~\n"
84589 @@ -42,7 +44,7 @@ struct module_kobject {
84590 struct kobject *drivers_dir;
84591 struct module_param_attrs *mp;
84592 struct completion *kobj_completion;
84593 -};
84594 +} __randomize_layout;
84595
84596 struct module_attribute {
84597 struct attribute attr;
84598 @@ -54,12 +56,13 @@ struct module_attribute {
84599 int (*test)(struct module *);
84600 void (*free)(struct module *);
84601 };
84602 +typedef struct module_attribute __no_const module_attribute_no_const;
84603
84604 struct module_version_attribute {
84605 struct module_attribute mattr;
84606 const char *module_name;
84607 const char *version;
84608 -} __attribute__ ((__aligned__(sizeof(void *))));
84609 +} __do_const __attribute__ ((__aligned__(sizeof(void *))));
84610
84611 extern ssize_t __modver_version_show(struct module_attribute *,
84612 struct module_kobject *, char *);
84613 @@ -235,7 +238,7 @@ struct module {
84614
84615 /* Sysfs stuff. */
84616 struct module_kobject mkobj;
84617 - struct module_attribute *modinfo_attrs;
84618 + module_attribute_no_const *modinfo_attrs;
84619 const char *version;
84620 const char *srcversion;
84621 struct kobject *holders_dir;
84622 @@ -284,19 +287,16 @@ struct module {
84623 int (*init)(void);
84624
84625 /* If this is non-NULL, vfree after init() returns */
84626 - void *module_init;
84627 + void *module_init_rx, *module_init_rw;
84628
84629 /* Here is the actual code + data, vfree'd on unload. */
84630 - void *module_core;
84631 + void *module_core_rx, *module_core_rw;
84632
84633 /* Here are the sizes of the init and core sections */
84634 - unsigned int init_size, core_size;
84635 + unsigned int init_size_rw, core_size_rw;
84636
84637 /* The size of the executable code in each section. */
84638 - unsigned int init_text_size, core_text_size;
84639 -
84640 - /* Size of RO sections of the module (text+rodata) */
84641 - unsigned int init_ro_size, core_ro_size;
84642 + unsigned int init_size_rx, core_size_rx;
84643
84644 /* Arch-specific module values */
84645 struct mod_arch_specific arch;
84646 @@ -352,6 +352,10 @@ struct module {
84647 #ifdef CONFIG_EVENT_TRACING
84648 struct ftrace_event_call **trace_events;
84649 unsigned int num_trace_events;
84650 + struct file_operations trace_id;
84651 + struct file_operations trace_enable;
84652 + struct file_operations trace_format;
84653 + struct file_operations trace_filter;
84654 #endif
84655 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
84656 unsigned int num_ftrace_callsites;
84657 @@ -375,7 +379,7 @@ struct module {
84658 ctor_fn_t *ctors;
84659 unsigned int num_ctors;
84660 #endif
84661 -};
84662 +} __randomize_layout;
84663 #ifndef MODULE_ARCH_INIT
84664 #define MODULE_ARCH_INIT {}
84665 #endif
84666 @@ -396,18 +400,48 @@ bool is_module_address(unsigned long addr);
84667 bool is_module_percpu_address(unsigned long addr);
84668 bool is_module_text_address(unsigned long addr);
84669
84670 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
84671 +{
84672 +
84673 +#ifdef CONFIG_PAX_KERNEXEC
84674 + if (ktla_ktva(addr) >= (unsigned long)start &&
84675 + ktla_ktva(addr) < (unsigned long)start + size)
84676 + return 1;
84677 +#endif
84678 +
84679 + return ((void *)addr >= start && (void *)addr < start + size);
84680 +}
84681 +
84682 +static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
84683 +{
84684 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
84685 +}
84686 +
84687 +static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
84688 +{
84689 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
84690 +}
84691 +
84692 +static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
84693 +{
84694 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
84695 +}
84696 +
84697 +static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
84698 +{
84699 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
84700 +}
84701 +
84702 static inline bool within_module_core(unsigned long addr,
84703 const struct module *mod)
84704 {
84705 - return (unsigned long)mod->module_core <= addr &&
84706 - addr < (unsigned long)mod->module_core + mod->core_size;
84707 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
84708 }
84709
84710 static inline bool within_module_init(unsigned long addr,
84711 const struct module *mod)
84712 {
84713 - return (unsigned long)mod->module_init <= addr &&
84714 - addr < (unsigned long)mod->module_init + mod->init_size;
84715 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
84716 }
84717
84718 static inline bool within_module(unsigned long addr, const struct module *mod)
84719 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
84720 index 7eeb9bb..68f37e0 100644
84721 --- a/include/linux/moduleloader.h
84722 +++ b/include/linux/moduleloader.h
84723 @@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
84724 sections. Returns NULL on failure. */
84725 void *module_alloc(unsigned long size);
84726
84727 +#ifdef CONFIG_PAX_KERNEXEC
84728 +void *module_alloc_exec(unsigned long size);
84729 +#else
84730 +#define module_alloc_exec(x) module_alloc(x)
84731 +#endif
84732 +
84733 /* Free memory returned from module_alloc. */
84734 void module_free(struct module *mod, void *module_region);
84735
84736 +#ifdef CONFIG_PAX_KERNEXEC
84737 +void module_free_exec(struct module *mod, void *module_region);
84738 +#else
84739 +#define module_free_exec(x, y) module_free((x), (y))
84740 +#endif
84741 +
84742 /*
84743 * Apply the given relocation to the (simplified) ELF. Return -error
84744 * or 0.
84745 @@ -45,8 +57,10 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
84746 unsigned int relsec,
84747 struct module *me)
84748 {
84749 +#ifdef CONFIG_MODULES
84750 printk(KERN_ERR "module %s: REL relocation unsupported\n",
84751 module_name(me));
84752 +#endif
84753 return -ENOEXEC;
84754 }
84755 #endif
84756 @@ -68,8 +82,10 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
84757 unsigned int relsec,
84758 struct module *me)
84759 {
84760 +#ifdef CONFIG_MODULES
84761 printk(KERN_ERR "module %s: REL relocation unsupported\n",
84762 module_name(me));
84763 +#endif
84764 return -ENOEXEC;
84765 }
84766 #endif
84767 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
84768 index 494f99e..5059f63 100644
84769 --- a/include/linux/moduleparam.h
84770 +++ b/include/linux/moduleparam.h
84771 @@ -293,7 +293,7 @@ static inline void __kernel_param_unlock(void)
84772 * @len is usually just sizeof(string).
84773 */
84774 #define module_param_string(name, string, len, perm) \
84775 - static const struct kparam_string __param_string_##name \
84776 + static const struct kparam_string __param_string_##name __used \
84777 = { len, string }; \
84778 __module_param_call(MODULE_PARAM_PREFIX, name, \
84779 &param_ops_string, \
84780 @@ -437,7 +437,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
84781 */
84782 #define module_param_array_named(name, array, type, nump, perm) \
84783 param_check_##type(name, &(array)[0]); \
84784 - static const struct kparam_array __param_arr_##name \
84785 + static const struct kparam_array __param_arr_##name __used \
84786 = { .max = ARRAY_SIZE(array), .num = nump, \
84787 .ops = &param_ops_##type, \
84788 .elemsize = sizeof(array[0]), .elem = array }; \
84789 diff --git a/include/linux/mount.h b/include/linux/mount.h
84790 index 9262e4b..0a45f98 100644
84791 --- a/include/linux/mount.h
84792 +++ b/include/linux/mount.h
84793 @@ -66,7 +66,7 @@ struct vfsmount {
84794 struct dentry *mnt_root; /* root of the mounted tree */
84795 struct super_block *mnt_sb; /* pointer to superblock */
84796 int mnt_flags;
84797 -};
84798 +} __randomize_layout;
84799
84800 struct file; /* forward dec */
84801 struct path;
84802 diff --git a/include/linux/namei.h b/include/linux/namei.h
84803 index 492de72..1bddcd4 100644
84804 --- a/include/linux/namei.h
84805 +++ b/include/linux/namei.h
84806 @@ -19,7 +19,7 @@ struct nameidata {
84807 unsigned seq, m_seq;
84808 int last_type;
84809 unsigned depth;
84810 - char *saved_names[MAX_NESTED_LINKS + 1];
84811 + const char *saved_names[MAX_NESTED_LINKS + 1];
84812 };
84813
84814 /*
84815 @@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
84816
84817 extern void nd_jump_link(struct nameidata *nd, struct path *path);
84818
84819 -static inline void nd_set_link(struct nameidata *nd, char *path)
84820 +static inline void nd_set_link(struct nameidata *nd, const char *path)
84821 {
84822 nd->saved_names[nd->depth] = path;
84823 }
84824
84825 -static inline char *nd_get_link(struct nameidata *nd)
84826 +static inline const char *nd_get_link(const struct nameidata *nd)
84827 {
84828 return nd->saved_names[nd->depth];
84829 }
84830 diff --git a/include/linux/net.h b/include/linux/net.h
84831 index 17d8339..81656c0 100644
84832 --- a/include/linux/net.h
84833 +++ b/include/linux/net.h
84834 @@ -192,7 +192,7 @@ struct net_proto_family {
84835 int (*create)(struct net *net, struct socket *sock,
84836 int protocol, int kern);
84837 struct module *owner;
84838 -};
84839 +} __do_const;
84840
84841 struct iovec;
84842 struct kvec;
84843 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
84844 index c8e388e..5d8cd9b 100644
84845 --- a/include/linux/netdevice.h
84846 +++ b/include/linux/netdevice.h
84847 @@ -1147,6 +1147,7 @@ struct net_device_ops {
84848 void *priv);
84849 int (*ndo_get_lock_subclass)(struct net_device *dev);
84850 };
84851 +typedef struct net_device_ops __no_const net_device_ops_no_const;
84852
84853 /**
84854 * enum net_device_priv_flags - &struct net_device priv_flags
84855 @@ -1485,10 +1486,10 @@ struct net_device {
84856
84857 struct net_device_stats stats;
84858
84859 - atomic_long_t rx_dropped;
84860 - atomic_long_t tx_dropped;
84861 + atomic_long_unchecked_t rx_dropped;
84862 + atomic_long_unchecked_t tx_dropped;
84863
84864 - atomic_t carrier_changes;
84865 + atomic_unchecked_t carrier_changes;
84866
84867 #ifdef CONFIG_WIRELESS_EXT
84868 const struct iw_handler_def * wireless_handlers;
84869 diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
84870 index 2517ece..0bbfcfb 100644
84871 --- a/include/linux/netfilter.h
84872 +++ b/include/linux/netfilter.h
84873 @@ -85,7 +85,7 @@ struct nf_sockopt_ops {
84874 #endif
84875 /* Use the module struct to lock set/get code in place */
84876 struct module *owner;
84877 -};
84878 +} __do_const;
84879
84880 /* Function to register/unregister hook points. */
84881 int nf_register_hook(struct nf_hook_ops *reg);
84882 diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
84883 index e955d47..04a5338 100644
84884 --- a/include/linux/netfilter/nfnetlink.h
84885 +++ b/include/linux/netfilter/nfnetlink.h
84886 @@ -19,7 +19,7 @@ struct nfnl_callback {
84887 const struct nlattr * const cda[]);
84888 const struct nla_policy *policy; /* netlink attribute policy */
84889 const u_int16_t attr_count; /* number of nlattr's */
84890 -};
84891 +} __do_const;
84892
84893 struct nfnetlink_subsystem {
84894 const char *name;
84895 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
84896 new file mode 100644
84897 index 0000000..33f4af8
84898 --- /dev/null
84899 +++ b/include/linux/netfilter/xt_gradm.h
84900 @@ -0,0 +1,9 @@
84901 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
84902 +#define _LINUX_NETFILTER_XT_GRADM_H 1
84903 +
84904 +struct xt_gradm_mtinfo {
84905 + __u16 flags;
84906 + __u16 invflags;
84907 +};
84908 +
84909 +#endif
84910 diff --git a/include/linux/nls.h b/include/linux/nls.h
84911 index 520681b..2b7fabb 100644
84912 --- a/include/linux/nls.h
84913 +++ b/include/linux/nls.h
84914 @@ -31,7 +31,7 @@ struct nls_table {
84915 const unsigned char *charset2upper;
84916 struct module *owner;
84917 struct nls_table *next;
84918 -};
84919 +} __do_const;
84920
84921 /* this value hold the maximum octet of charset */
84922 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
84923 @@ -46,7 +46,7 @@ enum utf16_endian {
84924 /* nls_base.c */
84925 extern int __register_nls(struct nls_table *, struct module *);
84926 extern int unregister_nls(struct nls_table *);
84927 -extern struct nls_table *load_nls(char *);
84928 +extern struct nls_table *load_nls(const char *);
84929 extern void unload_nls(struct nls_table *);
84930 extern struct nls_table *load_nls_default(void);
84931 #define register_nls(nls) __register_nls((nls), THIS_MODULE)
84932 diff --git a/include/linux/notifier.h b/include/linux/notifier.h
84933 index d14a4c3..a078786 100644
84934 --- a/include/linux/notifier.h
84935 +++ b/include/linux/notifier.h
84936 @@ -54,7 +54,8 @@ struct notifier_block {
84937 notifier_fn_t notifier_call;
84938 struct notifier_block __rcu *next;
84939 int priority;
84940 -};
84941 +} __do_const;
84942 +typedef struct notifier_block __no_const notifier_block_no_const;
84943
84944 struct atomic_notifier_head {
84945 spinlock_t lock;
84946 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
84947 index b2a0f15..4d7da32 100644
84948 --- a/include/linux/oprofile.h
84949 +++ b/include/linux/oprofile.h
84950 @@ -138,9 +138,9 @@ int oprofilefs_create_ulong(struct dentry * root,
84951 int oprofilefs_create_ro_ulong(struct dentry * root,
84952 char const * name, ulong * val);
84953
84954 -/** Create a file for read-only access to an atomic_t. */
84955 +/** Create a file for read-only access to an atomic_unchecked_t. */
84956 int oprofilefs_create_ro_atomic(struct dentry * root,
84957 - char const * name, atomic_t * val);
84958 + char const * name, atomic_unchecked_t * val);
84959
84960 /** create a directory */
84961 struct dentry *oprofilefs_mkdir(struct dentry *parent, char const *name);
84962 diff --git a/include/linux/padata.h b/include/linux/padata.h
84963 index 4386946..f50c615 100644
84964 --- a/include/linux/padata.h
84965 +++ b/include/linux/padata.h
84966 @@ -129,7 +129,7 @@ struct parallel_data {
84967 struct padata_serial_queue __percpu *squeue;
84968 atomic_t reorder_objects;
84969 atomic_t refcnt;
84970 - atomic_t seq_nr;
84971 + atomic_unchecked_t seq_nr;
84972 struct padata_cpumask cpumask;
84973 spinlock_t lock ____cacheline_aligned;
84974 unsigned int processed;
84975 diff --git a/include/linux/path.h b/include/linux/path.h
84976 index d137218..be0c176 100644
84977 --- a/include/linux/path.h
84978 +++ b/include/linux/path.h
84979 @@ -1,13 +1,15 @@
84980 #ifndef _LINUX_PATH_H
84981 #define _LINUX_PATH_H
84982
84983 +#include <linux/compiler.h>
84984 +
84985 struct dentry;
84986 struct vfsmount;
84987
84988 struct path {
84989 struct vfsmount *mnt;
84990 struct dentry *dentry;
84991 -};
84992 +} __randomize_layout;
84993
84994 extern void path_get(const struct path *);
84995 extern void path_put(const struct path *);
84996 diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
84997 index 5f2e559..7d59314 100644
84998 --- a/include/linux/pci_hotplug.h
84999 +++ b/include/linux/pci_hotplug.h
85000 @@ -71,7 +71,8 @@ struct hotplug_slot_ops {
85001 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
85002 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
85003 int (*reset_slot) (struct hotplug_slot *slot, int probe);
85004 -};
85005 +} __do_const;
85006 +typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
85007
85008 /**
85009 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
85010 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
85011 index 707617a..28a2e7e 100644
85012 --- a/include/linux/perf_event.h
85013 +++ b/include/linux/perf_event.h
85014 @@ -339,8 +339,8 @@ struct perf_event {
85015
85016 enum perf_event_active_state state;
85017 unsigned int attach_state;
85018 - local64_t count;
85019 - atomic64_t child_count;
85020 + local64_t count; /* PaX: fix it one day */
85021 + atomic64_unchecked_t child_count;
85022
85023 /*
85024 * These are the total time in nanoseconds that the event
85025 @@ -391,8 +391,8 @@ struct perf_event {
85026 * These accumulate total time (in nanoseconds) that children
85027 * events have been enabled and running, respectively.
85028 */
85029 - atomic64_t child_total_time_enabled;
85030 - atomic64_t child_total_time_running;
85031 + atomic64_unchecked_t child_total_time_enabled;
85032 + atomic64_unchecked_t child_total_time_running;
85033
85034 /*
85035 * Protect attach/detach and child_list:
85036 @@ -722,7 +722,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
85037 entry->ip[entry->nr++] = ip;
85038 }
85039
85040 -extern int sysctl_perf_event_paranoid;
85041 +extern int sysctl_perf_event_legitimately_concerned;
85042 extern int sysctl_perf_event_mlock;
85043 extern int sysctl_perf_event_sample_rate;
85044 extern int sysctl_perf_cpu_time_max_percent;
85045 @@ -737,19 +737,24 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
85046 loff_t *ppos);
85047
85048
85049 +static inline bool perf_paranoid_any(void)
85050 +{
85051 + return sysctl_perf_event_legitimately_concerned > 2;
85052 +}
85053 +
85054 static inline bool perf_paranoid_tracepoint_raw(void)
85055 {
85056 - return sysctl_perf_event_paranoid > -1;
85057 + return sysctl_perf_event_legitimately_concerned > -1;
85058 }
85059
85060 static inline bool perf_paranoid_cpu(void)
85061 {
85062 - return sysctl_perf_event_paranoid > 0;
85063 + return sysctl_perf_event_legitimately_concerned > 0;
85064 }
85065
85066 static inline bool perf_paranoid_kernel(void)
85067 {
85068 - return sysctl_perf_event_paranoid > 1;
85069 + return sysctl_perf_event_legitimately_concerned > 1;
85070 }
85071
85072 extern void perf_event_init(void);
85073 @@ -880,7 +885,7 @@ struct perf_pmu_events_attr {
85074 struct device_attribute attr;
85075 u64 id;
85076 const char *event_str;
85077 -};
85078 +} __do_const;
85079
85080 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
85081 static struct perf_pmu_events_attr _var = { \
85082 diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h
85083 index 1997ffc..4f1f44d 100644
85084 --- a/include/linux/pid_namespace.h
85085 +++ b/include/linux/pid_namespace.h
85086 @@ -44,7 +44,7 @@ struct pid_namespace {
85087 int hide_pid;
85088 int reboot; /* group exit code if this pidns was rebooted */
85089 unsigned int proc_inum;
85090 -};
85091 +} __randomize_layout;
85092
85093 extern struct pid_namespace init_pid_ns;
85094
85095 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
85096 index eb8b8ac..62649e1 100644
85097 --- a/include/linux/pipe_fs_i.h
85098 +++ b/include/linux/pipe_fs_i.h
85099 @@ -47,10 +47,10 @@ struct pipe_inode_info {
85100 struct mutex mutex;
85101 wait_queue_head_t wait;
85102 unsigned int nrbufs, curbuf, buffers;
85103 - unsigned int readers;
85104 - unsigned int writers;
85105 - unsigned int files;
85106 - unsigned int waiting_writers;
85107 + atomic_t readers;
85108 + atomic_t writers;
85109 + atomic_t files;
85110 + atomic_t waiting_writers;
85111 unsigned int r_counter;
85112 unsigned int w_counter;
85113 struct page *tmp_page;
85114 diff --git a/include/linux/pm.h b/include/linux/pm.h
85115 index 72c0fe0..26918ed 100644
85116 --- a/include/linux/pm.h
85117 +++ b/include/linux/pm.h
85118 @@ -620,6 +620,7 @@ extern int dev_pm_put_subsys_data(struct device *dev);
85119 struct dev_pm_domain {
85120 struct dev_pm_ops ops;
85121 };
85122 +typedef struct dev_pm_domain __no_const dev_pm_domain_no_const;
85123
85124 /*
85125 * The PM_EVENT_ messages are also used by drivers implementing the legacy
85126 diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
85127 index ebc4c76..7fab7b0 100644
85128 --- a/include/linux/pm_domain.h
85129 +++ b/include/linux/pm_domain.h
85130 @@ -44,11 +44,11 @@ struct gpd_dev_ops {
85131 int (*thaw_early)(struct device *dev);
85132 int (*thaw)(struct device *dev);
85133 bool (*active_wakeup)(struct device *dev);
85134 -};
85135 +} __no_const;
85136
85137 struct gpd_cpu_data {
85138 unsigned int saved_exit_latency;
85139 - struct cpuidle_state *idle_state;
85140 + cpuidle_state_no_const *idle_state;
85141 };
85142
85143 struct generic_pm_domain {
85144 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
85145 index 367f49b..d2f5a14 100644
85146 --- a/include/linux/pm_runtime.h
85147 +++ b/include/linux/pm_runtime.h
85148 @@ -125,7 +125,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
85149
85150 static inline void pm_runtime_mark_last_busy(struct device *dev)
85151 {
85152 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
85153 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
85154 }
85155
85156 #else /* !CONFIG_PM_RUNTIME */
85157 diff --git a/include/linux/pnp.h b/include/linux/pnp.h
85158 index 195aafc..49a7bc2 100644
85159 --- a/include/linux/pnp.h
85160 +++ b/include/linux/pnp.h
85161 @@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
85162 struct pnp_fixup {
85163 char id[7];
85164 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
85165 -};
85166 +} __do_const;
85167
85168 /* config parameters */
85169 #define PNP_CONFIG_NORMAL 0x0001
85170 diff --git a/include/linux/poison.h b/include/linux/poison.h
85171 index 2110a81..13a11bb 100644
85172 --- a/include/linux/poison.h
85173 +++ b/include/linux/poison.h
85174 @@ -19,8 +19,8 @@
85175 * under normal circumstances, used to verify that nobody uses
85176 * non-initialized list entries.
85177 */
85178 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
85179 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
85180 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
85181 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
85182
85183 /********** include/linux/timer.h **********/
85184 /*
85185 diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
85186 index d8b187c3..9a9257a 100644
85187 --- a/include/linux/power/smartreflex.h
85188 +++ b/include/linux/power/smartreflex.h
85189 @@ -238,7 +238,7 @@ struct omap_sr_class_data {
85190 int (*notify)(struct omap_sr *sr, u32 status);
85191 u8 notify_flags;
85192 u8 class_type;
85193 -};
85194 +} __do_const;
85195
85196 /**
85197 * struct omap_sr_nvalue_table - Smartreflex n-target value info
85198 diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
85199 index 4ea1d37..80f4b33 100644
85200 --- a/include/linux/ppp-comp.h
85201 +++ b/include/linux/ppp-comp.h
85202 @@ -84,7 +84,7 @@ struct compressor {
85203 struct module *owner;
85204 /* Extra skb space needed by the compressor algorithm */
85205 unsigned int comp_extra;
85206 -};
85207 +} __do_const;
85208
85209 /*
85210 * The return value from decompress routine is the length of the
85211 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
85212 index de83b4e..c4b997d 100644
85213 --- a/include/linux/preempt.h
85214 +++ b/include/linux/preempt.h
85215 @@ -27,11 +27,16 @@ extern void preempt_count_sub(int val);
85216 #define preempt_count_dec_and_test() __preempt_count_dec_and_test()
85217 #endif
85218
85219 +#define raw_preempt_count_add(val) __preempt_count_add(val)
85220 +#define raw_preempt_count_sub(val) __preempt_count_sub(val)
85221 +
85222 #define __preempt_count_inc() __preempt_count_add(1)
85223 #define __preempt_count_dec() __preempt_count_sub(1)
85224
85225 #define preempt_count_inc() preempt_count_add(1)
85226 +#define raw_preempt_count_inc() raw_preempt_count_add(1)
85227 #define preempt_count_dec() preempt_count_sub(1)
85228 +#define raw_preempt_count_dec() raw_preempt_count_sub(1)
85229
85230 #ifdef CONFIG_PREEMPT_COUNT
85231
85232 @@ -41,6 +46,12 @@ do { \
85233 barrier(); \
85234 } while (0)
85235
85236 +#define raw_preempt_disable() \
85237 +do { \
85238 + raw_preempt_count_inc(); \
85239 + barrier(); \
85240 +} while (0)
85241 +
85242 #define sched_preempt_enable_no_resched() \
85243 do { \
85244 barrier(); \
85245 @@ -49,6 +60,12 @@ do { \
85246
85247 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
85248
85249 +#define raw_preempt_enable_no_resched() \
85250 +do { \
85251 + barrier(); \
85252 + raw_preempt_count_dec(); \
85253 +} while (0)
85254 +
85255 #ifdef CONFIG_PREEMPT
85256 #define preempt_enable() \
85257 do { \
85258 @@ -113,8 +130,10 @@ do { \
85259 * region.
85260 */
85261 #define preempt_disable() barrier()
85262 +#define raw_preempt_disable() barrier()
85263 #define sched_preempt_enable_no_resched() barrier()
85264 #define preempt_enable_no_resched() barrier()
85265 +#define raw_preempt_enable_no_resched() barrier()
85266 #define preempt_enable() barrier()
85267 #define preempt_check_resched() do { } while (0)
85268
85269 @@ -128,11 +147,13 @@ do { \
85270 /*
85271 * Modules have no business playing preemption tricks.
85272 */
85273 +#ifndef CONFIG_PAX_KERNEXEC
85274 #undef sched_preempt_enable_no_resched
85275 #undef preempt_enable_no_resched
85276 #undef preempt_enable_no_resched_notrace
85277 #undef preempt_check_resched
85278 #endif
85279 +#endif
85280
85281 #define preempt_set_need_resched() \
85282 do { \
85283 diff --git a/include/linux/printk.h b/include/linux/printk.h
85284 index d78125f..7f36596 100644
85285 --- a/include/linux/printk.h
85286 +++ b/include/linux/printk.h
85287 @@ -124,6 +124,8 @@ static inline __printf(1, 2) __cold
85288 void early_printk(const char *s, ...) { }
85289 #endif
85290
85291 +extern int kptr_restrict;
85292 +
85293 #ifdef CONFIG_PRINTK
85294 asmlinkage __printf(5, 0)
85295 int vprintk_emit(int facility, int level,
85296 @@ -158,7 +160,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
85297
85298 extern int printk_delay_msec;
85299 extern int dmesg_restrict;
85300 -extern int kptr_restrict;
85301
85302 extern void wake_up_klogd(void);
85303
85304 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
85305 index 9d117f6..d832b31 100644
85306 --- a/include/linux/proc_fs.h
85307 +++ b/include/linux/proc_fs.h
85308 @@ -17,8 +17,11 @@ extern void proc_flush_task(struct task_struct *);
85309 extern struct proc_dir_entry *proc_symlink(const char *,
85310 struct proc_dir_entry *, const char *);
85311 extern struct proc_dir_entry *proc_mkdir(const char *, struct proc_dir_entry *);
85312 +extern struct proc_dir_entry *proc_mkdir_restrict(const char *, struct proc_dir_entry *);
85313 extern struct proc_dir_entry *proc_mkdir_data(const char *, umode_t,
85314 struct proc_dir_entry *, void *);
85315 +extern struct proc_dir_entry *proc_mkdir_data_restrict(const char *, umode_t,
85316 + struct proc_dir_entry *, void *);
85317 extern struct proc_dir_entry *proc_mkdir_mode(const char *, umode_t,
85318 struct proc_dir_entry *);
85319
85320 @@ -34,6 +37,19 @@ static inline struct proc_dir_entry *proc_create(
85321 return proc_create_data(name, mode, parent, proc_fops, NULL);
85322 }
85323
85324 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
85325 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
85326 +{
85327 +#ifdef CONFIG_GRKERNSEC_PROC_USER
85328 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
85329 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
85330 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
85331 +#else
85332 + return proc_create_data(name, mode, parent, proc_fops, NULL);
85333 +#endif
85334 +}
85335 +
85336 +
85337 extern void proc_set_size(struct proc_dir_entry *, loff_t);
85338 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
85339 extern void *PDE_DATA(const struct inode *);
85340 @@ -56,8 +72,12 @@ static inline struct proc_dir_entry *proc_symlink(const char *name,
85341 struct proc_dir_entry *parent,const char *dest) { return NULL;}
85342 static inline struct proc_dir_entry *proc_mkdir(const char *name,
85343 struct proc_dir_entry *parent) {return NULL;}
85344 +static inline struct proc_dir_entry *proc_mkdir_restrict(const char *name,
85345 + struct proc_dir_entry *parent) { return NULL; }
85346 static inline struct proc_dir_entry *proc_mkdir_data(const char *name,
85347 umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
85348 +static inline struct proc_dir_entry *proc_mkdir_data_restrict(const char *name,
85349 + umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
85350 static inline struct proc_dir_entry *proc_mkdir_mode(const char *name,
85351 umode_t mode, struct proc_dir_entry *parent) { return NULL; }
85352 #define proc_create(name, mode, parent, proc_fops) ({NULL;})
85353 @@ -77,7 +97,7 @@ static inline int remove_proc_subtree(const char *name, struct proc_dir_entry *p
85354 static inline struct proc_dir_entry *proc_net_mkdir(
85355 struct net *net, const char *name, struct proc_dir_entry *parent)
85356 {
85357 - return proc_mkdir_data(name, 0, parent, net);
85358 + return proc_mkdir_data_restrict(name, 0, parent, net);
85359 }
85360
85361 #endif /* _LINUX_PROC_FS_H */
85362 diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
85363 index 34a1e10..70f6bde 100644
85364 --- a/include/linux/proc_ns.h
85365 +++ b/include/linux/proc_ns.h
85366 @@ -14,7 +14,7 @@ struct proc_ns_operations {
85367 void (*put)(void *ns);
85368 int (*install)(struct nsproxy *nsproxy, void *ns);
85369 unsigned int (*inum)(void *ns);
85370 -};
85371 +} __do_const __randomize_layout;
85372
85373 struct proc_ns {
85374 void *ns;
85375 diff --git a/include/linux/quota.h b/include/linux/quota.h
85376 index 80d345a..9e89a9a 100644
85377 --- a/include/linux/quota.h
85378 +++ b/include/linux/quota.h
85379 @@ -70,7 +70,7 @@ struct kqid { /* Type in which we store the quota identifier */
85380
85381 extern bool qid_eq(struct kqid left, struct kqid right);
85382 extern bool qid_lt(struct kqid left, struct kqid right);
85383 -extern qid_t from_kqid(struct user_namespace *to, struct kqid qid);
85384 +extern qid_t from_kqid(struct user_namespace *to, struct kqid qid) __intentional_overflow(-1);
85385 extern qid_t from_kqid_munged(struct user_namespace *to, struct kqid qid);
85386 extern bool qid_valid(struct kqid qid);
85387
85388 diff --git a/include/linux/random.h b/include/linux/random.h
85389 index 57fbbff..2170304 100644
85390 --- a/include/linux/random.h
85391 +++ b/include/linux/random.h
85392 @@ -9,9 +9,19 @@
85393 #include <uapi/linux/random.h>
85394
85395 extern void add_device_randomness(const void *, unsigned int);
85396 +
85397 +static inline void add_latent_entropy(void)
85398 +{
85399 +
85400 +#ifdef LATENT_ENTROPY_PLUGIN
85401 + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
85402 +#endif
85403 +
85404 +}
85405 +
85406 extern void add_input_randomness(unsigned int type, unsigned int code,
85407 - unsigned int value);
85408 -extern void add_interrupt_randomness(int irq, int irq_flags);
85409 + unsigned int value) __latent_entropy;
85410 +extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
85411
85412 extern void get_random_bytes(void *buf, int nbytes);
85413 extern void get_random_bytes_arch(void *buf, int nbytes);
85414 @@ -22,10 +32,10 @@ extern int random_int_secret_init(void);
85415 extern const struct file_operations random_fops, urandom_fops;
85416 #endif
85417
85418 -unsigned int get_random_int(void);
85419 +unsigned int __intentional_overflow(-1) get_random_int(void);
85420 unsigned long randomize_range(unsigned long start, unsigned long end, unsigned long len);
85421
85422 -u32 prandom_u32(void);
85423 +u32 prandom_u32(void) __intentional_overflow(-1);
85424 void prandom_bytes(void *buf, int nbytes);
85425 void prandom_seed(u32 seed);
85426 void prandom_reseed_late(void);
85427 @@ -37,6 +47,11 @@ struct rnd_state {
85428 u32 prandom_u32_state(struct rnd_state *state);
85429 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
85430
85431 +static inline unsigned long __intentional_overflow(-1) pax_get_random_long(void)
85432 +{
85433 + return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
85434 +}
85435 +
85436 /**
85437 * prandom_u32_max - returns a pseudo-random number in interval [0, ep_ro)
85438 * @ep_ro: right open interval endpoint
85439 @@ -49,7 +64,7 @@ void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
85440 *
85441 * Returns: pseudo-random number in interval [0, ep_ro)
85442 */
85443 -static inline u32 prandom_u32_max(u32 ep_ro)
85444 +static inline u32 __intentional_overflow(-1) prandom_u32_max(u32 ep_ro)
85445 {
85446 return (u32)(((u64) prandom_u32() * ep_ro) >> 32);
85447 }
85448 diff --git a/include/linux/rbtree_augmented.h b/include/linux/rbtree_augmented.h
85449 index fea49b5..2ac22bb 100644
85450 --- a/include/linux/rbtree_augmented.h
85451 +++ b/include/linux/rbtree_augmented.h
85452 @@ -80,7 +80,9 @@ rbname ## _rotate(struct rb_node *rb_old, struct rb_node *rb_new) \
85453 old->rbaugmented = rbcompute(old); \
85454 } \
85455 rbstatic const struct rb_augment_callbacks rbname = { \
85456 - rbname ## _propagate, rbname ## _copy, rbname ## _rotate \
85457 + .propagate = rbname ## _propagate, \
85458 + .copy = rbname ## _copy, \
85459 + .rotate = rbname ## _rotate \
85460 };
85461
85462
85463 diff --git a/include/linux/rculist.h b/include/linux/rculist.h
85464 index 372ad5e..d4373f8 100644
85465 --- a/include/linux/rculist.h
85466 +++ b/include/linux/rculist.h
85467 @@ -29,8 +29,8 @@
85468 */
85469 static inline void INIT_LIST_HEAD_RCU(struct list_head *list)
85470 {
85471 - ACCESS_ONCE(list->next) = list;
85472 - ACCESS_ONCE(list->prev) = list;
85473 + ACCESS_ONCE_RW(list->next) = list;
85474 + ACCESS_ONCE_RW(list->prev) = list;
85475 }
85476
85477 /*
85478 @@ -59,6 +59,9 @@ void __list_add_rcu(struct list_head *new,
85479 struct list_head *prev, struct list_head *next);
85480 #endif
85481
85482 +void __pax_list_add_rcu(struct list_head *new,
85483 + struct list_head *prev, struct list_head *next);
85484 +
85485 /**
85486 * list_add_rcu - add a new entry to rcu-protected list
85487 * @new: new entry to be added
85488 @@ -80,6 +83,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
85489 __list_add_rcu(new, head, head->next);
85490 }
85491
85492 +static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
85493 +{
85494 + __pax_list_add_rcu(new, head, head->next);
85495 +}
85496 +
85497 /**
85498 * list_add_tail_rcu - add a new entry to rcu-protected list
85499 * @new: new entry to be added
85500 @@ -102,6 +110,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
85501 __list_add_rcu(new, head->prev, head);
85502 }
85503
85504 +static inline void pax_list_add_tail_rcu(struct list_head *new,
85505 + struct list_head *head)
85506 +{
85507 + __pax_list_add_rcu(new, head->prev, head);
85508 +}
85509 +
85510 /**
85511 * list_del_rcu - deletes entry from list without re-initialization
85512 * @entry: the element to delete from the list.
85513 @@ -132,6 +146,8 @@ static inline void list_del_rcu(struct list_head *entry)
85514 entry->prev = LIST_POISON2;
85515 }
85516
85517 +extern void pax_list_del_rcu(struct list_head *entry);
85518 +
85519 /**
85520 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
85521 * @n: the element to delete from the hash list.
85522 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
85523 index 48bf152..d38b785 100644
85524 --- a/include/linux/reboot.h
85525 +++ b/include/linux/reboot.h
85526 @@ -44,9 +44,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
85527 */
85528
85529 extern void migrate_to_reboot_cpu(void);
85530 -extern void machine_restart(char *cmd);
85531 -extern void machine_halt(void);
85532 -extern void machine_power_off(void);
85533 +extern void machine_restart(char *cmd) __noreturn;
85534 +extern void machine_halt(void) __noreturn;
85535 +extern void machine_power_off(void) __noreturn;
85536
85537 extern void machine_shutdown(void);
85538 struct pt_regs;
85539 @@ -57,9 +57,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
85540 */
85541
85542 extern void kernel_restart_prepare(char *cmd);
85543 -extern void kernel_restart(char *cmd);
85544 -extern void kernel_halt(void);
85545 -extern void kernel_power_off(void);
85546 +extern void kernel_restart(char *cmd) __noreturn;
85547 +extern void kernel_halt(void) __noreturn;
85548 +extern void kernel_power_off(void) __noreturn;
85549
85550 extern int C_A_D; /* for sysctl */
85551 void ctrl_alt_del(void);
85552 @@ -73,7 +73,7 @@ extern int orderly_poweroff(bool force);
85553 * Emergency restart, callable from an interrupt handler.
85554 */
85555
85556 -extern void emergency_restart(void);
85557 +extern void emergency_restart(void) __noreturn;
85558 #include <asm/emergency-restart.h>
85559
85560 #endif /* _LINUX_REBOOT_H */
85561 diff --git a/include/linux/regset.h b/include/linux/regset.h
85562 index 8e0c9fe..ac4d221 100644
85563 --- a/include/linux/regset.h
85564 +++ b/include/linux/regset.h
85565 @@ -161,7 +161,8 @@ struct user_regset {
85566 unsigned int align;
85567 unsigned int bias;
85568 unsigned int core_note_type;
85569 -};
85570 +} __do_const;
85571 +typedef struct user_regset __no_const user_regset_no_const;
85572
85573 /**
85574 * struct user_regset_view - available regsets
85575 diff --git a/include/linux/relay.h b/include/linux/relay.h
85576 index d7c8359..818daf5 100644
85577 --- a/include/linux/relay.h
85578 +++ b/include/linux/relay.h
85579 @@ -157,7 +157,7 @@ struct rchan_callbacks
85580 * The callback should return 0 if successful, negative if not.
85581 */
85582 int (*remove_buf_file)(struct dentry *dentry);
85583 -};
85584 +} __no_const;
85585
85586 /*
85587 * CONFIG_RELAY kernel API, kernel/relay.c
85588 diff --git a/include/linux/rio.h b/include/linux/rio.h
85589 index 6bda06f..bf39a9b 100644
85590 --- a/include/linux/rio.h
85591 +++ b/include/linux/rio.h
85592 @@ -358,7 +358,7 @@ struct rio_ops {
85593 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
85594 u64 rstart, u32 size, u32 flags);
85595 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
85596 -};
85597 +} __no_const;
85598
85599 #define RIO_RESOURCE_MEM 0x00000100
85600 #define RIO_RESOURCE_DOORBELL 0x00000200
85601 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
85602 index be57450..31cf65e 100644
85603 --- a/include/linux/rmap.h
85604 +++ b/include/linux/rmap.h
85605 @@ -144,8 +144,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
85606 void anon_vma_init(void); /* create anon_vma_cachep */
85607 int anon_vma_prepare(struct vm_area_struct *);
85608 void unlink_anon_vmas(struct vm_area_struct *);
85609 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
85610 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
85611 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
85612 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
85613
85614 static inline void anon_vma_merge(struct vm_area_struct *vma,
85615 struct vm_area_struct *next)
85616 diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h
85617 index ed8f9e7..999bc96 100644
85618 --- a/include/linux/scatterlist.h
85619 +++ b/include/linux/scatterlist.h
85620 @@ -1,6 +1,7 @@
85621 #ifndef _LINUX_SCATTERLIST_H
85622 #define _LINUX_SCATTERLIST_H
85623
85624 +#include <linux/sched.h>
85625 #include <linux/string.h>
85626 #include <linux/bug.h>
85627 #include <linux/mm.h>
85628 @@ -114,6 +115,12 @@ static inline void sg_set_buf(struct scatterlist *sg, const void *buf,
85629 #ifdef CONFIG_DEBUG_SG
85630 BUG_ON(!virt_addr_valid(buf));
85631 #endif
85632 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
85633 + if (object_starts_on_stack(buf)) {
85634 + void *adjbuf = buf - current->stack + current->lowmem_stack;
85635 + sg_set_page(sg, virt_to_page(adjbuf), buflen, offset_in_page(adjbuf));
85636 + } else
85637 +#endif
85638 sg_set_page(sg, virt_to_page(buf), buflen, offset_in_page(buf));
85639 }
85640
85641 diff --git a/include/linux/sched.h b/include/linux/sched.h
85642 index 2b1d9e9..7fd5067 100644
85643 --- a/include/linux/sched.h
85644 +++ b/include/linux/sched.h
85645 @@ -132,6 +132,7 @@ struct fs_struct;
85646 struct perf_event_context;
85647 struct blk_plug;
85648 struct filename;
85649 +struct linux_binprm;
85650
85651 #define VMACACHE_BITS 2
85652 #define VMACACHE_SIZE (1U << VMACACHE_BITS)
85653 @@ -374,7 +375,7 @@ extern char __sched_text_start[], __sched_text_end[];
85654 extern int in_sched_functions(unsigned long addr);
85655
85656 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
85657 -extern signed long schedule_timeout(signed long timeout);
85658 +extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
85659 extern signed long schedule_timeout_interruptible(signed long timeout);
85660 extern signed long schedule_timeout_killable(signed long timeout);
85661 extern signed long schedule_timeout_uninterruptible(signed long timeout);
85662 @@ -385,6 +386,19 @@ struct nsproxy;
85663 struct user_namespace;
85664
85665 #ifdef CONFIG_MMU
85666 +
85667 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
85668 +extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
85669 +#else
85670 +static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
85671 +{
85672 + return 0;
85673 +}
85674 +#endif
85675 +
85676 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
85677 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
85678 +
85679 extern void arch_pick_mmap_layout(struct mm_struct *mm);
85680 extern unsigned long
85681 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
85682 @@ -682,6 +696,17 @@ struct signal_struct {
85683 #ifdef CONFIG_TASKSTATS
85684 struct taskstats *stats;
85685 #endif
85686 +
85687 +#ifdef CONFIG_GRKERNSEC
85688 + u32 curr_ip;
85689 + u32 saved_ip;
85690 + u32 gr_saddr;
85691 + u32 gr_daddr;
85692 + u16 gr_sport;
85693 + u16 gr_dport;
85694 + u8 used_accept:1;
85695 +#endif
85696 +
85697 #ifdef CONFIG_AUDIT
85698 unsigned audit_tty;
85699 unsigned audit_tty_log_passwd;
85700 @@ -708,7 +733,7 @@ struct signal_struct {
85701 struct mutex cred_guard_mutex; /* guard against foreign influences on
85702 * credential calculations
85703 * (notably. ptrace) */
85704 -};
85705 +} __randomize_layout;
85706
85707 /*
85708 * Bits in flags field of signal_struct.
85709 @@ -761,6 +786,14 @@ struct user_struct {
85710 struct key *session_keyring; /* UID's default session keyring */
85711 #endif
85712
85713 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
85714 + unsigned char kernel_banned;
85715 +#endif
85716 +#ifdef CONFIG_GRKERNSEC_BRUTE
85717 + unsigned char suid_banned;
85718 + unsigned long suid_ban_expires;
85719 +#endif
85720 +
85721 /* Hash table maintenance information */
85722 struct hlist_node uidhash_node;
85723 kuid_t uid;
85724 @@ -768,7 +801,7 @@ struct user_struct {
85725 #ifdef CONFIG_PERF_EVENTS
85726 atomic_long_t locked_vm;
85727 #endif
85728 -};
85729 +} __randomize_layout;
85730
85731 extern int uids_sysfs_init(void);
85732
85733 @@ -1224,6 +1257,9 @@ enum perf_event_task_context {
85734 struct task_struct {
85735 volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */
85736 void *stack;
85737 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
85738 + void *lowmem_stack;
85739 +#endif
85740 atomic_t usage;
85741 unsigned int flags; /* per process flags, defined below */
85742 unsigned int ptrace;
85743 @@ -1345,8 +1381,8 @@ struct task_struct {
85744 struct list_head thread_node;
85745
85746 struct completion *vfork_done; /* for vfork() */
85747 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
85748 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
85749 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
85750 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
85751
85752 cputime_t utime, stime, utimescaled, stimescaled;
85753 cputime_t gtime;
85754 @@ -1371,11 +1407,6 @@ struct task_struct {
85755 struct task_cputime cputime_expires;
85756 struct list_head cpu_timers[3];
85757
85758 -/* process credentials */
85759 - const struct cred __rcu *real_cred; /* objective and real subjective task
85760 - * credentials (COW) */
85761 - const struct cred __rcu *cred; /* effective (overridable) subjective task
85762 - * credentials (COW) */
85763 char comm[TASK_COMM_LEN]; /* executable name excluding path
85764 - access with [gs]et_task_comm (which lock
85765 it with task_lock())
85766 @@ -1393,6 +1424,10 @@ struct task_struct {
85767 #endif
85768 /* CPU-specific state of this task */
85769 struct thread_struct thread;
85770 +/* thread_info moved to task_struct */
85771 +#ifdef CONFIG_X86
85772 + struct thread_info tinfo;
85773 +#endif
85774 /* filesystem information */
85775 struct fs_struct *fs;
85776 /* open file information */
85777 @@ -1467,6 +1502,10 @@ struct task_struct {
85778 gfp_t lockdep_reclaim_gfp;
85779 #endif
85780
85781 +/* process credentials */
85782 + const struct cred __rcu *real_cred; /* objective and real subjective task
85783 + * credentials (COW) */
85784 +
85785 /* journalling filesystem info */
85786 void *journal_info;
85787
85788 @@ -1505,6 +1544,10 @@ struct task_struct {
85789 /* cg_list protected by css_set_lock and tsk->alloc_lock */
85790 struct list_head cg_list;
85791 #endif
85792 +
85793 + const struct cred __rcu *cred; /* effective (overridable) subjective task
85794 + * credentials (COW) */
85795 +
85796 #ifdef CONFIG_FUTEX
85797 struct robust_list_head __user *robust_list;
85798 #ifdef CONFIG_COMPAT
85799 @@ -1618,7 +1661,7 @@ struct task_struct {
85800 * Number of functions that haven't been traced
85801 * because of depth overrun.
85802 */
85803 - atomic_t trace_overrun;
85804 + atomic_unchecked_t trace_overrun;
85805 /* Pause for the tracing */
85806 atomic_t tracing_graph_pause;
85807 #endif
85808 @@ -1644,7 +1687,78 @@ struct task_struct {
85809 unsigned int sequential_io;
85810 unsigned int sequential_io_avg;
85811 #endif
85812 -};
85813 +
85814 +#ifdef CONFIG_GRKERNSEC
85815 + /* grsecurity */
85816 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
85817 + u64 exec_id;
85818 +#endif
85819 +#ifdef CONFIG_GRKERNSEC_SETXID
85820 + const struct cred *delayed_cred;
85821 +#endif
85822 + struct dentry *gr_chroot_dentry;
85823 + struct acl_subject_label *acl;
85824 + struct acl_subject_label *tmpacl;
85825 + struct acl_role_label *role;
85826 + struct file *exec_file;
85827 + unsigned long brute_expires;
85828 + u16 acl_role_id;
85829 + u8 inherited;
85830 + /* is this the task that authenticated to the special role */
85831 + u8 acl_sp_role;
85832 + u8 is_writable;
85833 + u8 brute;
85834 + u8 gr_is_chrooted;
85835 +#endif
85836 +
85837 +} __randomize_layout;
85838 +
85839 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
85840 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
85841 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
85842 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
85843 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
85844 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
85845 +
85846 +#ifdef CONFIG_PAX_SOFTMODE
85847 +extern int pax_softmode;
85848 +#endif
85849 +
85850 +extern int pax_check_flags(unsigned long *);
85851 +#define PAX_PARSE_FLAGS_FALLBACK (~0UL)
85852 +
85853 +/* if tsk != current then task_lock must be held on it */
85854 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
85855 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
85856 +{
85857 + if (likely(tsk->mm))
85858 + return tsk->mm->pax_flags;
85859 + else
85860 + return 0UL;
85861 +}
85862 +
85863 +/* if tsk != current then task_lock must be held on it */
85864 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
85865 +{
85866 + if (likely(tsk->mm)) {
85867 + tsk->mm->pax_flags = flags;
85868 + return 0;
85869 + }
85870 + return -EINVAL;
85871 +}
85872 +#endif
85873 +
85874 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
85875 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
85876 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
85877 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
85878 +#endif
85879 +
85880 +struct path;
85881 +extern char *pax_get_path(const struct path *path, char *buf, int buflen);
85882 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
85883 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
85884 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
85885
85886 /* Future-safe accessor for struct task_struct's cpus_allowed. */
85887 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
85888 @@ -1726,7 +1840,7 @@ struct pid_namespace;
85889 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
85890 struct pid_namespace *ns);
85891
85892 -static inline pid_t task_pid_nr(struct task_struct *tsk)
85893 +static inline pid_t task_pid_nr(const struct task_struct *tsk)
85894 {
85895 return tsk->pid;
85896 }
85897 @@ -2097,6 +2211,25 @@ extern u64 sched_clock_cpu(int cpu);
85898
85899 extern void sched_clock_init(void);
85900
85901 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
85902 +static inline void populate_stack(void)
85903 +{
85904 + struct task_struct *curtask = current;
85905 + int c;
85906 + int *ptr = curtask->stack;
85907 + int *end = curtask->stack + THREAD_SIZE;
85908 +
85909 + while (ptr < end) {
85910 + c = *(volatile int *)ptr;
85911 + ptr += PAGE_SIZE/sizeof(int);
85912 + }
85913 +}
85914 +#else
85915 +static inline void populate_stack(void)
85916 +{
85917 +}
85918 +#endif
85919 +
85920 #ifndef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK
85921 static inline void sched_clock_tick(void)
85922 {
85923 @@ -2230,7 +2363,9 @@ void yield(void);
85924 extern struct exec_domain default_exec_domain;
85925
85926 union thread_union {
85927 +#ifndef CONFIG_X86
85928 struct thread_info thread_info;
85929 +#endif
85930 unsigned long stack[THREAD_SIZE/sizeof(long)];
85931 };
85932
85933 @@ -2263,6 +2398,7 @@ extern struct pid_namespace init_pid_ns;
85934 */
85935
85936 extern struct task_struct *find_task_by_vpid(pid_t nr);
85937 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
85938 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
85939 struct pid_namespace *ns);
85940
85941 @@ -2427,7 +2563,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
85942 extern void exit_itimers(struct signal_struct *);
85943 extern void flush_itimer_signals(void);
85944
85945 -extern void do_group_exit(int);
85946 +extern __noreturn void do_group_exit(int);
85947
85948 extern int do_execve(struct filename *,
85949 const char __user * const __user *,
85950 @@ -2642,9 +2778,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
85951
85952 #endif
85953
85954 -static inline int object_is_on_stack(void *obj)
85955 +static inline int object_starts_on_stack(const void *obj)
85956 {
85957 - void *stack = task_stack_page(current);
85958 + const void *stack = task_stack_page(current);
85959
85960 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
85961 }
85962 diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
85963 index 596a0e0..bea77ec 100644
85964 --- a/include/linux/sched/sysctl.h
85965 +++ b/include/linux/sched/sysctl.h
85966 @@ -34,6 +34,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
85967 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
85968
85969 extern int sysctl_max_map_count;
85970 +extern unsigned long sysctl_heap_stack_gap;
85971
85972 extern unsigned int sysctl_sched_latency;
85973 extern unsigned int sysctl_sched_min_granularity;
85974 diff --git a/include/linux/security.h b/include/linux/security.h
85975 index 623f90e..90b39da 100644
85976 --- a/include/linux/security.h
85977 +++ b/include/linux/security.h
85978 @@ -27,6 +27,7 @@
85979 #include <linux/slab.h>
85980 #include <linux/err.h>
85981 #include <linux/string.h>
85982 +#include <linux/grsecurity.h>
85983
85984 struct linux_binprm;
85985 struct cred;
85986 @@ -116,8 +117,6 @@ struct seq_file;
85987
85988 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
85989
85990 -void reset_security_ops(void);
85991 -
85992 #ifdef CONFIG_MMU
85993 extern unsigned long mmap_min_addr;
85994 extern unsigned long dac_mmap_min_addr;
85995 @@ -1729,7 +1728,7 @@ struct security_operations {
85996 struct audit_context *actx);
85997 void (*audit_rule_free) (void *lsmrule);
85998 #endif /* CONFIG_AUDIT */
85999 -};
86000 +} __randomize_layout;
86001
86002 /* prototypes */
86003 extern int security_init(void);
86004 diff --git a/include/linux/semaphore.h b/include/linux/semaphore.h
86005 index dc368b8..e895209 100644
86006 --- a/include/linux/semaphore.h
86007 +++ b/include/linux/semaphore.h
86008 @@ -37,7 +37,7 @@ static inline void sema_init(struct semaphore *sem, int val)
86009 }
86010
86011 extern void down(struct semaphore *sem);
86012 -extern int __must_check down_interruptible(struct semaphore *sem);
86013 +extern int __must_check down_interruptible(struct semaphore *sem) __intentional_overflow(-1);
86014 extern int __must_check down_killable(struct semaphore *sem);
86015 extern int __must_check down_trylock(struct semaphore *sem);
86016 extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
86017 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
86018 index 52e0097..383f21d 100644
86019 --- a/include/linux/seq_file.h
86020 +++ b/include/linux/seq_file.h
86021 @@ -27,6 +27,9 @@ struct seq_file {
86022 struct mutex lock;
86023 const struct seq_operations *op;
86024 int poll_event;
86025 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
86026 + u64 exec_id;
86027 +#endif
86028 #ifdef CONFIG_USER_NS
86029 struct user_namespace *user_ns;
86030 #endif
86031 @@ -39,6 +42,7 @@ struct seq_operations {
86032 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
86033 int (*show) (struct seq_file *m, void *v);
86034 };
86035 +typedef struct seq_operations __no_const seq_operations_no_const;
86036
86037 #define SEQ_SKIP 1
86038
86039 @@ -96,6 +100,7 @@ void seq_pad(struct seq_file *m, char c);
86040
86041 char *mangle_path(char *s, const char *p, const char *esc);
86042 int seq_open(struct file *, const struct seq_operations *);
86043 +int seq_open_restrict(struct file *, const struct seq_operations *);
86044 ssize_t seq_read(struct file *, char __user *, size_t, loff_t *);
86045 loff_t seq_lseek(struct file *, loff_t, int);
86046 int seq_release(struct inode *, struct file *);
86047 @@ -138,6 +143,7 @@ static inline int seq_nodemask_list(struct seq_file *m, nodemask_t *mask)
86048 }
86049
86050 int single_open(struct file *, int (*)(struct seq_file *, void *), void *);
86051 +int single_open_restrict(struct file *, int (*)(struct seq_file *, void *), void *);
86052 int single_open_size(struct file *, int (*)(struct seq_file *, void *), void *, size_t);
86053 int single_release(struct inode *, struct file *);
86054 void *__seq_open_private(struct file *, const struct seq_operations *, int);
86055 diff --git a/include/linux/shm.h b/include/linux/shm.h
86056 index 6fb8016..ab4465e 100644
86057 --- a/include/linux/shm.h
86058 +++ b/include/linux/shm.h
86059 @@ -22,6 +22,10 @@ struct shmid_kernel /* private to the kernel */
86060 /* The task created the shm object. NULL if the task is dead. */
86061 struct task_struct *shm_creator;
86062 struct list_head shm_clist; /* list by creator */
86063 +#ifdef CONFIG_GRKERNSEC
86064 + u64 shm_createtime;
86065 + pid_t shm_lapid;
86066 +#endif
86067 };
86068
86069 /* shm_mode upper byte flags */
86070 diff --git a/include/linux/signal.h b/include/linux/signal.h
86071 index 750196f..ae7a3a4 100644
86072 --- a/include/linux/signal.h
86073 +++ b/include/linux/signal.h
86074 @@ -292,7 +292,7 @@ static inline void allow_signal(int sig)
86075 * know it'll be handled, so that they don't get converted to
86076 * SIGKILL or just silently dropped.
86077 */
86078 - kernel_sigaction(sig, (__force __sighandler_t)2);
86079 + kernel_sigaction(sig, (__force_user __sighandler_t)2);
86080 }
86081
86082 static inline void disallow_signal(int sig)
86083 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
86084 index abde271..bc9ece1 100644
86085 --- a/include/linux/skbuff.h
86086 +++ b/include/linux/skbuff.h
86087 @@ -728,7 +728,7 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
86088 struct sk_buff *__alloc_skb(unsigned int size, gfp_t priority, int flags,
86089 int node);
86090 struct sk_buff *build_skb(void *data, unsigned int frag_size);
86091 -static inline struct sk_buff *alloc_skb(unsigned int size,
86092 +static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
86093 gfp_t priority)
86094 {
86095 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
86096 @@ -1845,7 +1845,7 @@ static inline u32 skb_inner_network_header_len(const struct sk_buff *skb)
86097 return skb->inner_transport_header - skb->inner_network_header;
86098 }
86099
86100 -static inline int skb_network_offset(const struct sk_buff *skb)
86101 +static inline int __intentional_overflow(0) skb_network_offset(const struct sk_buff *skb)
86102 {
86103 return skb_network_header(skb) - skb->data;
86104 }
86105 @@ -1917,7 +1917,7 @@ static inline void skb_pop_rcv_encapsulation(struct sk_buff *skb)
86106 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
86107 */
86108 #ifndef NET_SKB_PAD
86109 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
86110 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
86111 #endif
86112
86113 int ___pskb_trim(struct sk_buff *skb, unsigned int len);
86114 @@ -2524,7 +2524,7 @@ struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags, int noblock,
86115 int *err);
86116 unsigned int datagram_poll(struct file *file, struct socket *sock,
86117 struct poll_table_struct *wait);
86118 -int skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
86119 +int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
86120 struct iovec *to, int size);
86121 int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb, int hlen,
86122 struct iovec *iov);
86123 @@ -2918,6 +2918,9 @@ static inline void nf_reset(struct sk_buff *skb)
86124 nf_bridge_put(skb->nf_bridge);
86125 skb->nf_bridge = NULL;
86126 #endif
86127 +#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
86128 + skb->nf_trace = 0;
86129 +#endif
86130 }
86131
86132 static inline void nf_reset_trace(struct sk_buff *skb)
86133 diff --git a/include/linux/slab.h b/include/linux/slab.h
86134 index 1d9abb7..b1e8b10 100644
86135 --- a/include/linux/slab.h
86136 +++ b/include/linux/slab.h
86137 @@ -14,15 +14,29 @@
86138 #include <linux/gfp.h>
86139 #include <linux/types.h>
86140 #include <linux/workqueue.h>
86141 -
86142 +#include <linux/err.h>
86143
86144 /*
86145 * Flags to pass to kmem_cache_create().
86146 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
86147 */
86148 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
86149 +
86150 +#ifdef CONFIG_PAX_USERCOPY_SLABS
86151 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
86152 +#else
86153 +#define SLAB_USERCOPY 0x00000000UL
86154 +#endif
86155 +
86156 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
86157 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
86158 +
86159 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
86160 +#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
86161 +#else
86162 +#define SLAB_NO_SANITIZE 0x00000000UL
86163 +#endif
86164 +
86165 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
86166 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
86167 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
86168 @@ -98,10 +112,13 @@
86169 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
86170 * Both make kfree a no-op.
86171 */
86172 -#define ZERO_SIZE_PTR ((void *)16)
86173 +#define ZERO_SIZE_PTR \
86174 +({ \
86175 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
86176 + (void *)(-MAX_ERRNO-1L); \
86177 +})
86178
86179 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
86180 - (unsigned long)ZERO_SIZE_PTR)
86181 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
86182
86183 #include <linux/kmemleak.h>
86184
86185 @@ -144,6 +161,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
86186 void kfree(const void *);
86187 void kzfree(const void *);
86188 size_t ksize(const void *);
86189 +const char *check_heap_object(const void *ptr, unsigned long n);
86190 +bool is_usercopy_object(const void *ptr);
86191
86192 /*
86193 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
86194 @@ -176,7 +195,7 @@ struct kmem_cache {
86195 unsigned int align; /* Alignment as calculated */
86196 unsigned long flags; /* Active flags on the slab */
86197 const char *name; /* Slab name for sysfs */
86198 - int refcount; /* Use counter */
86199 + atomic_t refcount; /* Use counter */
86200 void (*ctor)(void *); /* Called on object slot creation */
86201 struct list_head list; /* List of all slab caches on the system */
86202 };
86203 @@ -261,6 +280,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
86204 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
86205 #endif
86206
86207 +#ifdef CONFIG_PAX_USERCOPY_SLABS
86208 +extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
86209 +#endif
86210 +
86211 /*
86212 * Figure out which kmalloc slab an allocation of a certain size
86213 * belongs to.
86214 @@ -269,7 +292,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
86215 * 2 = 120 .. 192 bytes
86216 * n = 2^(n-1) .. 2^n -1
86217 */
86218 -static __always_inline int kmalloc_index(size_t size)
86219 +static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
86220 {
86221 if (!size)
86222 return 0;
86223 @@ -312,11 +335,11 @@ static __always_inline int kmalloc_index(size_t size)
86224 }
86225 #endif /* !CONFIG_SLOB */
86226
86227 -void *__kmalloc(size_t size, gfp_t flags);
86228 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
86229 void *kmem_cache_alloc(struct kmem_cache *, gfp_t flags);
86230
86231 #ifdef CONFIG_NUMA
86232 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
86233 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __alloc_size(1);
86234 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
86235 #else
86236 static __always_inline void *__kmalloc_node(size_t size, gfp_t flags, int node)
86237 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
86238 index 8235dfb..47ce586 100644
86239 --- a/include/linux/slab_def.h
86240 +++ b/include/linux/slab_def.h
86241 @@ -38,7 +38,7 @@ struct kmem_cache {
86242 /* 4) cache creation/removal */
86243 const char *name;
86244 struct list_head list;
86245 - int refcount;
86246 + atomic_t refcount;
86247 int object_size;
86248 int align;
86249
86250 @@ -54,10 +54,14 @@ struct kmem_cache {
86251 unsigned long node_allocs;
86252 unsigned long node_frees;
86253 unsigned long node_overflow;
86254 - atomic_t allochit;
86255 - atomic_t allocmiss;
86256 - atomic_t freehit;
86257 - atomic_t freemiss;
86258 + atomic_unchecked_t allochit;
86259 + atomic_unchecked_t allocmiss;
86260 + atomic_unchecked_t freehit;
86261 + atomic_unchecked_t freemiss;
86262 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
86263 + atomic_unchecked_t sanitized;
86264 + atomic_unchecked_t not_sanitized;
86265 +#endif
86266
86267 /*
86268 * If debugging is enabled, then the allocator can add additional
86269 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
86270 index d82abd4..408c3a0 100644
86271 --- a/include/linux/slub_def.h
86272 +++ b/include/linux/slub_def.h
86273 @@ -74,7 +74,7 @@ struct kmem_cache {
86274 struct kmem_cache_order_objects max;
86275 struct kmem_cache_order_objects min;
86276 gfp_t allocflags; /* gfp flags to use on each alloc */
86277 - int refcount; /* Refcount for slab cache destroy */
86278 + atomic_t refcount; /* Refcount for slab cache destroy */
86279 void (*ctor)(void *);
86280 int inuse; /* Offset to metadata */
86281 int align; /* Alignment */
86282 diff --git a/include/linux/smp.h b/include/linux/smp.h
86283 index 34347f2..8739978 100644
86284 --- a/include/linux/smp.h
86285 +++ b/include/linux/smp.h
86286 @@ -174,7 +174,9 @@ static inline void kick_all_cpus_sync(void) { }
86287 #endif
86288
86289 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
86290 +#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
86291 #define put_cpu() preempt_enable()
86292 +#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
86293
86294 /*
86295 * Callback to arch code if there's nosmp or maxcpus=0 on the
86296 diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
86297 index 46cca4c..3323536 100644
86298 --- a/include/linux/sock_diag.h
86299 +++ b/include/linux/sock_diag.h
86300 @@ -11,7 +11,7 @@ struct sock;
86301 struct sock_diag_handler {
86302 __u8 family;
86303 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
86304 -};
86305 +} __do_const;
86306
86307 int sock_diag_register(const struct sock_diag_handler *h);
86308 void sock_diag_unregister(const struct sock_diag_handler *h);
86309 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
86310 index 680f9a3..f13aeb0 100644
86311 --- a/include/linux/sonet.h
86312 +++ b/include/linux/sonet.h
86313 @@ -7,7 +7,7 @@
86314 #include <uapi/linux/sonet.h>
86315
86316 struct k_sonet_stats {
86317 -#define __HANDLE_ITEM(i) atomic_t i
86318 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
86319 __SONET_ITEMS
86320 #undef __HANDLE_ITEM
86321 };
86322 diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
86323 index 07d8e53..dc934c9 100644
86324 --- a/include/linux/sunrpc/addr.h
86325 +++ b/include/linux/sunrpc/addr.h
86326 @@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
86327 {
86328 switch (sap->sa_family) {
86329 case AF_INET:
86330 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
86331 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
86332 case AF_INET6:
86333 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
86334 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
86335 }
86336 return 0;
86337 }
86338 @@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
86339 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
86340 const struct sockaddr *src)
86341 {
86342 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
86343 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
86344 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
86345
86346 dsin->sin_family = ssin->sin_family;
86347 @@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
86348 if (sa->sa_family != AF_INET6)
86349 return 0;
86350
86351 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
86352 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
86353 }
86354
86355 #endif /* _LINUX_SUNRPC_ADDR_H */
86356 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
86357 index 70736b9..37f33db 100644
86358 --- a/include/linux/sunrpc/clnt.h
86359 +++ b/include/linux/sunrpc/clnt.h
86360 @@ -97,7 +97,7 @@ struct rpc_procinfo {
86361 unsigned int p_timer; /* Which RTT timer to use */
86362 u32 p_statidx; /* Which procedure to account */
86363 const char * p_name; /* name of procedure */
86364 -};
86365 +} __do_const;
86366
86367 #ifdef __KERNEL__
86368
86369 diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
86370 index cf61ecd..a4a9bc0 100644
86371 --- a/include/linux/sunrpc/svc.h
86372 +++ b/include/linux/sunrpc/svc.h
86373 @@ -417,7 +417,7 @@ struct svc_procedure {
86374 unsigned int pc_count; /* call count */
86375 unsigned int pc_cachetype; /* cache info (NFS) */
86376 unsigned int pc_xdrressize; /* maximum size of XDR reply */
86377 -};
86378 +} __do_const;
86379
86380 /*
86381 * Function prototypes.
86382 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
86383 index 975da75..318c083 100644
86384 --- a/include/linux/sunrpc/svc_rdma.h
86385 +++ b/include/linux/sunrpc/svc_rdma.h
86386 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
86387 extern unsigned int svcrdma_max_requests;
86388 extern unsigned int svcrdma_max_req_size;
86389
86390 -extern atomic_t rdma_stat_recv;
86391 -extern atomic_t rdma_stat_read;
86392 -extern atomic_t rdma_stat_write;
86393 -extern atomic_t rdma_stat_sq_starve;
86394 -extern atomic_t rdma_stat_rq_starve;
86395 -extern atomic_t rdma_stat_rq_poll;
86396 -extern atomic_t rdma_stat_rq_prod;
86397 -extern atomic_t rdma_stat_sq_poll;
86398 -extern atomic_t rdma_stat_sq_prod;
86399 +extern atomic_unchecked_t rdma_stat_recv;
86400 +extern atomic_unchecked_t rdma_stat_read;
86401 +extern atomic_unchecked_t rdma_stat_write;
86402 +extern atomic_unchecked_t rdma_stat_sq_starve;
86403 +extern atomic_unchecked_t rdma_stat_rq_starve;
86404 +extern atomic_unchecked_t rdma_stat_rq_poll;
86405 +extern atomic_unchecked_t rdma_stat_rq_prod;
86406 +extern atomic_unchecked_t rdma_stat_sq_poll;
86407 +extern atomic_unchecked_t rdma_stat_sq_prod;
86408
86409 #define RPCRDMA_VERSION 1
86410
86411 diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
86412 index 8d71d65..f79586e 100644
86413 --- a/include/linux/sunrpc/svcauth.h
86414 +++ b/include/linux/sunrpc/svcauth.h
86415 @@ -120,7 +120,7 @@ struct auth_ops {
86416 int (*release)(struct svc_rqst *rq);
86417 void (*domain_release)(struct auth_domain *);
86418 int (*set_client)(struct svc_rqst *rq);
86419 -};
86420 +} __do_const;
86421
86422 #define SVC_GARBAGE 1
86423 #define SVC_SYSERR 2
86424 diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
86425 index e7a018e..49f8b17 100644
86426 --- a/include/linux/swiotlb.h
86427 +++ b/include/linux/swiotlb.h
86428 @@ -60,7 +60,8 @@ extern void
86429
86430 extern void
86431 swiotlb_free_coherent(struct device *hwdev, size_t size,
86432 - void *vaddr, dma_addr_t dma_handle);
86433 + void *vaddr, dma_addr_t dma_handle,
86434 + struct dma_attrs *attrs);
86435
86436 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
86437 unsigned long offset, size_t size,
86438 diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
86439 index 0f86d85..dff3419 100644
86440 --- a/include/linux/syscalls.h
86441 +++ b/include/linux/syscalls.h
86442 @@ -98,10 +98,16 @@ struct sigaltstack;
86443 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
86444
86445 #define __SC_DECL(t, a) t a
86446 +#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))
86447 #define __TYPE_IS_L(t) (__same_type((t)0, 0L))
86448 #define __TYPE_IS_UL(t) (__same_type((t)0, 0UL))
86449 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
86450 -#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
86451 +#define __SC_LONG(t, a) __typeof( \
86452 + __builtin_choose_expr( \
86453 + sizeof(t) > sizeof(int), \
86454 + (t) 0, \
86455 + __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
86456 + )) a
86457 #define __SC_CAST(t, a) (t) a
86458 #define __SC_ARGS(t, a) a
86459 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
86460 @@ -383,11 +389,11 @@ asmlinkage long sys_sync(void);
86461 asmlinkage long sys_fsync(unsigned int fd);
86462 asmlinkage long sys_fdatasync(unsigned int fd);
86463 asmlinkage long sys_bdflush(int func, long data);
86464 -asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
86465 - char __user *type, unsigned long flags,
86466 +asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
86467 + const char __user *type, unsigned long flags,
86468 void __user *data);
86469 -asmlinkage long sys_umount(char __user *name, int flags);
86470 -asmlinkage long sys_oldumount(char __user *name);
86471 +asmlinkage long sys_umount(const char __user *name, int flags);
86472 +asmlinkage long sys_oldumount(const char __user *name);
86473 asmlinkage long sys_truncate(const char __user *path, long length);
86474 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
86475 asmlinkage long sys_stat(const char __user *filename,
86476 @@ -599,7 +605,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
86477 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
86478 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
86479 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
86480 - struct sockaddr __user *, int);
86481 + struct sockaddr __user *, int) __intentional_overflow(0);
86482 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
86483 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
86484 unsigned int vlen, unsigned flags);
86485 diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
86486 index 27b3b0b..e093dd9 100644
86487 --- a/include/linux/syscore_ops.h
86488 +++ b/include/linux/syscore_ops.h
86489 @@ -16,7 +16,7 @@ struct syscore_ops {
86490 int (*suspend)(void);
86491 void (*resume)(void);
86492 void (*shutdown)(void);
86493 -};
86494 +} __do_const;
86495
86496 extern void register_syscore_ops(struct syscore_ops *ops);
86497 extern void unregister_syscore_ops(struct syscore_ops *ops);
86498 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
86499 index b7361f8..341a15a 100644
86500 --- a/include/linux/sysctl.h
86501 +++ b/include/linux/sysctl.h
86502 @@ -39,6 +39,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
86503
86504 extern int proc_dostring(struct ctl_table *, int,
86505 void __user *, size_t *, loff_t *);
86506 +extern int proc_dostring_modpriv(struct ctl_table *, int,
86507 + void __user *, size_t *, loff_t *);
86508 extern int proc_dointvec(struct ctl_table *, int,
86509 void __user *, size_t *, loff_t *);
86510 extern int proc_dointvec_minmax(struct ctl_table *, int,
86511 @@ -113,7 +115,8 @@ struct ctl_table
86512 struct ctl_table_poll *poll;
86513 void *extra1;
86514 void *extra2;
86515 -};
86516 +} __do_const __randomize_layout;
86517 +typedef struct ctl_table __no_const ctl_table_no_const;
86518
86519 struct ctl_node {
86520 struct rb_node node;
86521 diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
86522 index f97d0db..c1187dc 100644
86523 --- a/include/linux/sysfs.h
86524 +++ b/include/linux/sysfs.h
86525 @@ -34,7 +34,8 @@ struct attribute {
86526 struct lock_class_key *key;
86527 struct lock_class_key skey;
86528 #endif
86529 -};
86530 +} __do_const;
86531 +typedef struct attribute __no_const attribute_no_const;
86532
86533 /**
86534 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
86535 @@ -63,7 +64,8 @@ struct attribute_group {
86536 struct attribute *, int);
86537 struct attribute **attrs;
86538 struct bin_attribute **bin_attrs;
86539 -};
86540 +} __do_const;
86541 +typedef struct attribute_group __no_const attribute_group_no_const;
86542
86543 /**
86544 * Use these macros to make defining attributes easier. See include/linux/device.h
86545 @@ -128,7 +130,8 @@ struct bin_attribute {
86546 char *, loff_t, size_t);
86547 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
86548 struct vm_area_struct *vma);
86549 -};
86550 +} __do_const;
86551 +typedef struct bin_attribute __no_const bin_attribute_no_const;
86552
86553 /**
86554 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
86555 diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
86556 index 387fa7d..3fcde6b 100644
86557 --- a/include/linux/sysrq.h
86558 +++ b/include/linux/sysrq.h
86559 @@ -16,6 +16,7 @@
86560
86561 #include <linux/errno.h>
86562 #include <linux/types.h>
86563 +#include <linux/compiler.h>
86564
86565 /* Possible values of bitmask for enabling sysrq functions */
86566 /* 0x0001 is reserved for enable everything */
86567 @@ -33,7 +34,7 @@ struct sysrq_key_op {
86568 char *help_msg;
86569 char *action_msg;
86570 int enable_mask;
86571 -};
86572 +} __do_const;
86573
86574 #ifdef CONFIG_MAGIC_SYSRQ
86575
86576 diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
86577 index ff307b5..f1a4468 100644
86578 --- a/include/linux/thread_info.h
86579 +++ b/include/linux/thread_info.h
86580 @@ -145,6 +145,13 @@ static inline bool test_and_clear_restore_sigmask(void)
86581 #error "no set_restore_sigmask() provided and default one won't work"
86582 #endif
86583
86584 +extern void __check_object_size(const void *ptr, unsigned long n, bool to_user, bool const_size);
86585 +
86586 +static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
86587 +{
86588 + __check_object_size(ptr, n, to_user, __builtin_constant_p(n));
86589 +}
86590 +
86591 #endif /* __KERNEL__ */
86592
86593 #endif /* _LINUX_THREAD_INFO_H */
86594 diff --git a/include/linux/tty.h b/include/linux/tty.h
86595 index 8413294..44391c7 100644
86596 --- a/include/linux/tty.h
86597 +++ b/include/linux/tty.h
86598 @@ -202,7 +202,7 @@ struct tty_port {
86599 const struct tty_port_operations *ops; /* Port operations */
86600 spinlock_t lock; /* Lock protecting tty field */
86601 int blocked_open; /* Waiting to open */
86602 - int count; /* Usage count */
86603 + atomic_t count; /* Usage count */
86604 wait_queue_head_t open_wait; /* Open waiters */
86605 wait_queue_head_t close_wait; /* Close waiters */
86606 wait_queue_head_t delta_msr_wait; /* Modem status change */
86607 @@ -284,7 +284,7 @@ struct tty_struct {
86608 /* If the tty has a pending do_SAK, queue it here - akpm */
86609 struct work_struct SAK_work;
86610 struct tty_port *port;
86611 -};
86612 +} __randomize_layout;
86613
86614 /* Each of a tty's open files has private_data pointing to tty_file_private */
86615 struct tty_file_private {
86616 @@ -548,7 +548,7 @@ extern int tty_port_open(struct tty_port *port,
86617 struct tty_struct *tty, struct file *filp);
86618 static inline int tty_port_users(struct tty_port *port)
86619 {
86620 - return port->count + port->blocked_open;
86621 + return atomic_read(&port->count) + port->blocked_open;
86622 }
86623
86624 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
86625 diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
86626 index e48c608..6a19af2 100644
86627 --- a/include/linux/tty_driver.h
86628 +++ b/include/linux/tty_driver.h
86629 @@ -287,7 +287,7 @@ struct tty_operations {
86630 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
86631 #endif
86632 const struct file_operations *proc_fops;
86633 -};
86634 +} __do_const __randomize_layout;
86635
86636 struct tty_driver {
86637 int magic; /* magic number for this structure */
86638 @@ -321,7 +321,7 @@ struct tty_driver {
86639
86640 const struct tty_operations *ops;
86641 struct list_head tty_drivers;
86642 -};
86643 +} __randomize_layout;
86644
86645 extern struct list_head tty_drivers;
86646
86647 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
86648 index 00c9d68..bc0188b 100644
86649 --- a/include/linux/tty_ldisc.h
86650 +++ b/include/linux/tty_ldisc.h
86651 @@ -215,7 +215,7 @@ struct tty_ldisc_ops {
86652
86653 struct module *owner;
86654
86655 - int refcount;
86656 + atomic_t refcount;
86657 };
86658
86659 struct tty_ldisc {
86660 diff --git a/include/linux/types.h b/include/linux/types.h
86661 index a0bb704..f511c77 100644
86662 --- a/include/linux/types.h
86663 +++ b/include/linux/types.h
86664 @@ -177,10 +177,26 @@ typedef struct {
86665 int counter;
86666 } atomic_t;
86667
86668 +#ifdef CONFIG_PAX_REFCOUNT
86669 +typedef struct {
86670 + int counter;
86671 +} atomic_unchecked_t;
86672 +#else
86673 +typedef atomic_t atomic_unchecked_t;
86674 +#endif
86675 +
86676 #ifdef CONFIG_64BIT
86677 typedef struct {
86678 long counter;
86679 } atomic64_t;
86680 +
86681 +#ifdef CONFIG_PAX_REFCOUNT
86682 +typedef struct {
86683 + long counter;
86684 +} atomic64_unchecked_t;
86685 +#else
86686 +typedef atomic64_t atomic64_unchecked_t;
86687 +#endif
86688 #endif
86689
86690 struct list_head {
86691 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
86692 index ecd3319..8a36ded 100644
86693 --- a/include/linux/uaccess.h
86694 +++ b/include/linux/uaccess.h
86695 @@ -75,11 +75,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
86696 long ret; \
86697 mm_segment_t old_fs = get_fs(); \
86698 \
86699 - set_fs(KERNEL_DS); \
86700 pagefault_disable(); \
86701 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
86702 - pagefault_enable(); \
86703 + set_fs(KERNEL_DS); \
86704 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
86705 set_fs(old_fs); \
86706 + pagefault_enable(); \
86707 ret; \
86708 })
86709
86710 diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
86711 index 2d1f9b6..d7a9fce 100644
86712 --- a/include/linux/uidgid.h
86713 +++ b/include/linux/uidgid.h
86714 @@ -175,4 +175,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
86715
86716 #endif /* CONFIG_USER_NS */
86717
86718 +#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
86719 +#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
86720 +#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
86721 +#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
86722 +
86723 #endif /* _LINUX_UIDGID_H */
86724 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
86725 index 99c1b4d..562e6f3 100644
86726 --- a/include/linux/unaligned/access_ok.h
86727 +++ b/include/linux/unaligned/access_ok.h
86728 @@ -4,34 +4,34 @@
86729 #include <linux/kernel.h>
86730 #include <asm/byteorder.h>
86731
86732 -static inline u16 get_unaligned_le16(const void *p)
86733 +static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
86734 {
86735 - return le16_to_cpup((__le16 *)p);
86736 + return le16_to_cpup((const __le16 *)p);
86737 }
86738
86739 -static inline u32 get_unaligned_le32(const void *p)
86740 +static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
86741 {
86742 - return le32_to_cpup((__le32 *)p);
86743 + return le32_to_cpup((const __le32 *)p);
86744 }
86745
86746 -static inline u64 get_unaligned_le64(const void *p)
86747 +static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
86748 {
86749 - return le64_to_cpup((__le64 *)p);
86750 + return le64_to_cpup((const __le64 *)p);
86751 }
86752
86753 -static inline u16 get_unaligned_be16(const void *p)
86754 +static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
86755 {
86756 - return be16_to_cpup((__be16 *)p);
86757 + return be16_to_cpup((const __be16 *)p);
86758 }
86759
86760 -static inline u32 get_unaligned_be32(const void *p)
86761 +static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
86762 {
86763 - return be32_to_cpup((__be32 *)p);
86764 + return be32_to_cpup((const __be32 *)p);
86765 }
86766
86767 -static inline u64 get_unaligned_be64(const void *p)
86768 +static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
86769 {
86770 - return be64_to_cpup((__be64 *)p);
86771 + return be64_to_cpup((const __be64 *)p);
86772 }
86773
86774 static inline void put_unaligned_le16(u16 val, void *p)
86775 diff --git a/include/linux/uprobes.h b/include/linux/uprobes.h
86776 index 4f844c6..60beb5d 100644
86777 --- a/include/linux/uprobes.h
86778 +++ b/include/linux/uprobes.h
86779 @@ -98,11 +98,11 @@ struct uprobes_state {
86780 struct xol_area *xol_area;
86781 };
86782
86783 -extern int __weak set_swbp(struct arch_uprobe *aup, struct mm_struct *mm, unsigned long vaddr);
86784 -extern int __weak set_orig_insn(struct arch_uprobe *aup, struct mm_struct *mm, unsigned long vaddr);
86785 -extern bool __weak is_swbp_insn(uprobe_opcode_t *insn);
86786 -extern bool __weak is_trap_insn(uprobe_opcode_t *insn);
86787 -extern unsigned long __weak uprobe_get_swbp_addr(struct pt_regs *regs);
86788 +extern int set_swbp(struct arch_uprobe *aup, struct mm_struct *mm, unsigned long vaddr);
86789 +extern int set_orig_insn(struct arch_uprobe *aup, struct mm_struct *mm, unsigned long vaddr);
86790 +extern bool is_swbp_insn(uprobe_opcode_t *insn);
86791 +extern bool is_trap_insn(uprobe_opcode_t *insn);
86792 +extern unsigned long uprobe_get_swbp_addr(struct pt_regs *regs);
86793 extern unsigned long uprobe_get_trap_addr(struct pt_regs *regs);
86794 extern int uprobe_write_opcode(struct mm_struct *mm, unsigned long vaddr, uprobe_opcode_t);
86795 extern int uprobe_register(struct inode *inode, loff_t offset, struct uprobe_consumer *uc);
86796 @@ -128,8 +128,8 @@ extern bool arch_uprobe_xol_was_trapped(struct task_struct *tsk);
86797 extern int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val, void *data);
86798 extern void arch_uprobe_abort_xol(struct arch_uprobe *aup, struct pt_regs *regs);
86799 extern unsigned long arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs *regs);
86800 -extern bool __weak arch_uprobe_ignore(struct arch_uprobe *aup, struct pt_regs *regs);
86801 -extern void __weak arch_uprobe_copy_ixol(struct page *page, unsigned long vaddr,
86802 +extern bool arch_uprobe_ignore(struct arch_uprobe *aup, struct pt_regs *regs);
86803 +extern void arch_uprobe_copy_ixol(struct page *page, unsigned long vaddr,
86804 void *src, unsigned long len);
86805 #else /* !CONFIG_UPROBES */
86806 struct uprobes_state {
86807 diff --git a/include/linux/usb.h b/include/linux/usb.h
86808 index d2465bc..5256de4 100644
86809 --- a/include/linux/usb.h
86810 +++ b/include/linux/usb.h
86811 @@ -571,7 +571,7 @@ struct usb_device {
86812 int maxchild;
86813
86814 u32 quirks;
86815 - atomic_t urbnum;
86816 + atomic_unchecked_t urbnum;
86817
86818 unsigned long active_duration;
86819
86820 @@ -1655,7 +1655,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
86821
86822 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
86823 __u8 request, __u8 requesttype, __u16 value, __u16 index,
86824 - void *data, __u16 size, int timeout);
86825 + void *data, __u16 size, int timeout) __intentional_overflow(-1);
86826 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
86827 void *data, int len, int *actual_length, int timeout);
86828 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
86829 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
86830 index d5952bb..9a626d4 100644
86831 --- a/include/linux/usb/renesas_usbhs.h
86832 +++ b/include/linux/usb/renesas_usbhs.h
86833 @@ -39,7 +39,7 @@ enum {
86834 */
86835 struct renesas_usbhs_driver_callback {
86836 int (*notify_hotplug)(struct platform_device *pdev);
86837 -};
86838 +} __no_const;
86839
86840 /*
86841 * callback functions for platform
86842 diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
86843 index e953726..8edb26a 100644
86844 --- a/include/linux/user_namespace.h
86845 +++ b/include/linux/user_namespace.h
86846 @@ -33,7 +33,7 @@ struct user_namespace {
86847 struct key *persistent_keyring_register;
86848 struct rw_semaphore persistent_keyring_register_sem;
86849 #endif
86850 -};
86851 +} __randomize_layout;
86852
86853 extern struct user_namespace init_user_ns;
86854
86855 diff --git a/include/linux/utsname.h b/include/linux/utsname.h
86856 index 239e277..22a5cf5 100644
86857 --- a/include/linux/utsname.h
86858 +++ b/include/linux/utsname.h
86859 @@ -24,7 +24,7 @@ struct uts_namespace {
86860 struct new_utsname name;
86861 struct user_namespace *user_ns;
86862 unsigned int proc_inum;
86863 -};
86864 +} __randomize_layout;
86865 extern struct uts_namespace init_uts_ns;
86866
86867 #ifdef CONFIG_UTS_NS
86868 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
86869 index 6f8fbcf..4efc177 100644
86870 --- a/include/linux/vermagic.h
86871 +++ b/include/linux/vermagic.h
86872 @@ -25,9 +25,42 @@
86873 #define MODULE_ARCH_VERMAGIC ""
86874 #endif
86875
86876 +#ifdef CONFIG_PAX_REFCOUNT
86877 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
86878 +#else
86879 +#define MODULE_PAX_REFCOUNT ""
86880 +#endif
86881 +
86882 +#ifdef CONSTIFY_PLUGIN
86883 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
86884 +#else
86885 +#define MODULE_CONSTIFY_PLUGIN ""
86886 +#endif
86887 +
86888 +#ifdef STACKLEAK_PLUGIN
86889 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
86890 +#else
86891 +#define MODULE_STACKLEAK_PLUGIN ""
86892 +#endif
86893 +
86894 +#ifdef RANDSTRUCT_PLUGIN
86895 +#include <generated/randomize_layout_hash.h>
86896 +#define MODULE_RANDSTRUCT_PLUGIN "RANDSTRUCT_PLUGIN_" RANDSTRUCT_HASHED_SEED
86897 +#else
86898 +#define MODULE_RANDSTRUCT_PLUGIN
86899 +#endif
86900 +
86901 +#ifdef CONFIG_GRKERNSEC
86902 +#define MODULE_GRSEC "GRSEC "
86903 +#else
86904 +#define MODULE_GRSEC ""
86905 +#endif
86906 +
86907 #define VERMAGIC_STRING \
86908 UTS_RELEASE " " \
86909 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
86910 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
86911 - MODULE_ARCH_VERMAGIC
86912 + MODULE_ARCH_VERMAGIC \
86913 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
86914 + MODULE_GRSEC MODULE_RANDSTRUCT_PLUGIN
86915
86916 diff --git a/include/linux/vga_switcheroo.h b/include/linux/vga_switcheroo.h
86917 index b483abd..af305ad 100644
86918 --- a/include/linux/vga_switcheroo.h
86919 +++ b/include/linux/vga_switcheroo.h
86920 @@ -63,9 +63,9 @@ int vga_switcheroo_get_client_state(struct pci_dev *dev);
86921
86922 void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic);
86923
86924 -int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain);
86925 +int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain);
86926 void vga_switcheroo_fini_domain_pm_ops(struct device *dev);
86927 -int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain);
86928 +int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain);
86929 #else
86930
86931 static inline void vga_switcheroo_unregister_client(struct pci_dev *dev) {}
86932 @@ -82,9 +82,9 @@ static inline int vga_switcheroo_get_client_state(struct pci_dev *dev) { return
86933
86934 static inline void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic) {}
86935
86936 -static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
86937 +static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
86938 static inline void vga_switcheroo_fini_domain_pm_ops(struct device *dev) {}
86939 -static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
86940 +static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
86941
86942 #endif
86943 #endif /* _LINUX_VGA_SWITCHEROO_H_ */
86944 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
86945 index b87696f..1d11de7 100644
86946 --- a/include/linux/vmalloc.h
86947 +++ b/include/linux/vmalloc.h
86948 @@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
86949 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
86950 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
86951 #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
86952 +
86953 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
86954 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
86955 +#endif
86956 +
86957 /* bits [20..32] reserved for arch specific ioremap internals */
86958
86959 /*
86960 @@ -82,6 +87,10 @@ extern void *vmap(struct page **pages, unsigned int count,
86961 unsigned long flags, pgprot_t prot);
86962 extern void vunmap(const void *addr);
86963
86964 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
86965 +extern void unmap_process_stacks(struct task_struct *task);
86966 +#endif
86967 +
86968 extern int remap_vmalloc_range_partial(struct vm_area_struct *vma,
86969 unsigned long uaddr, void *kaddr,
86970 unsigned long size);
86971 @@ -142,7 +151,7 @@ extern void free_vm_area(struct vm_struct *area);
86972
86973 /* for /dev/kmem */
86974 extern long vread(char *buf, char *addr, unsigned long count);
86975 -extern long vwrite(char *buf, char *addr, unsigned long count);
86976 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
86977
86978 /*
86979 * Internals. Dont't use..
86980 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
86981 index 82e7db7..f8ce3d0 100644
86982 --- a/include/linux/vmstat.h
86983 +++ b/include/linux/vmstat.h
86984 @@ -108,18 +108,18 @@ static inline void vm_events_fold_cpu(int cpu)
86985 /*
86986 * Zone based page accounting with per cpu differentials.
86987 */
86988 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
86989 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
86990
86991 static inline void zone_page_state_add(long x, struct zone *zone,
86992 enum zone_stat_item item)
86993 {
86994 - atomic_long_add(x, &zone->vm_stat[item]);
86995 - atomic_long_add(x, &vm_stat[item]);
86996 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
86997 + atomic_long_add_unchecked(x, &vm_stat[item]);
86998 }
86999
87000 -static inline unsigned long global_page_state(enum zone_stat_item item)
87001 +static inline unsigned long __intentional_overflow(-1) global_page_state(enum zone_stat_item item)
87002 {
87003 - long x = atomic_long_read(&vm_stat[item]);
87004 + long x = atomic_long_read_unchecked(&vm_stat[item]);
87005 #ifdef CONFIG_SMP
87006 if (x < 0)
87007 x = 0;
87008 @@ -127,10 +127,10 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
87009 return x;
87010 }
87011
87012 -static inline unsigned long zone_page_state(struct zone *zone,
87013 +static inline unsigned long __intentional_overflow(-1) zone_page_state(struct zone *zone,
87014 enum zone_stat_item item)
87015 {
87016 - long x = atomic_long_read(&zone->vm_stat[item]);
87017 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
87018 #ifdef CONFIG_SMP
87019 if (x < 0)
87020 x = 0;
87021 @@ -147,7 +147,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
87022 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
87023 enum zone_stat_item item)
87024 {
87025 - long x = atomic_long_read(&zone->vm_stat[item]);
87026 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
87027
87028 #ifdef CONFIG_SMP
87029 int cpu;
87030 @@ -234,14 +234,14 @@ static inline void __mod_zone_page_state(struct zone *zone,
87031
87032 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
87033 {
87034 - atomic_long_inc(&zone->vm_stat[item]);
87035 - atomic_long_inc(&vm_stat[item]);
87036 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
87037 + atomic_long_inc_unchecked(&vm_stat[item]);
87038 }
87039
87040 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
87041 {
87042 - atomic_long_dec(&zone->vm_stat[item]);
87043 - atomic_long_dec(&vm_stat[item]);
87044 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
87045 + atomic_long_dec_unchecked(&vm_stat[item]);
87046 }
87047
87048 static inline void __inc_zone_page_state(struct page *page,
87049 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
87050 index 91b0a68..0e9adf6 100644
87051 --- a/include/linux/xattr.h
87052 +++ b/include/linux/xattr.h
87053 @@ -28,7 +28,7 @@ struct xattr_handler {
87054 size_t size, int handler_flags);
87055 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
87056 size_t size, int flags, int handler_flags);
87057 -};
87058 +} __do_const;
87059
87060 struct xattr {
87061 const char *name;
87062 @@ -37,6 +37,9 @@ struct xattr {
87063 };
87064
87065 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
87066 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
87067 +ssize_t pax_getxattr(struct dentry *, void *, size_t);
87068 +#endif
87069 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
87070 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
87071 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
87072 diff --git a/include/linux/zlib.h b/include/linux/zlib.h
87073 index 92dbbd3..13ab0b3 100644
87074 --- a/include/linux/zlib.h
87075 +++ b/include/linux/zlib.h
87076 @@ -31,6 +31,7 @@
87077 #define _ZLIB_H
87078
87079 #include <linux/zconf.h>
87080 +#include <linux/compiler.h>
87081
87082 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
87083 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
87084 @@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
87085
87086 /* basic functions */
87087
87088 -extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
87089 +extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
87090 /*
87091 Returns the number of bytes that needs to be allocated for a per-
87092 stream workspace with the specified parameters. A pointer to this
87093 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
87094 index eb76cfd..9fd0e7c 100644
87095 --- a/include/media/v4l2-dev.h
87096 +++ b/include/media/v4l2-dev.h
87097 @@ -75,7 +75,7 @@ struct v4l2_file_operations {
87098 int (*mmap) (struct file *, struct vm_area_struct *);
87099 int (*open) (struct file *);
87100 int (*release) (struct file *);
87101 -};
87102 +} __do_const;
87103
87104 /*
87105 * Newer version of video_device, handled by videodev2.c
87106 diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
87107 index ffb69da..040393e 100644
87108 --- a/include/media/v4l2-device.h
87109 +++ b/include/media/v4l2-device.h
87110 @@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
87111 this function returns 0. If the name ends with a digit (e.g. cx18),
87112 then the name will be set to cx18-0 since cx180 looks really odd. */
87113 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
87114 - atomic_t *instance);
87115 + atomic_unchecked_t *instance);
87116
87117 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
87118 Since the parent disappears this ensures that v4l2_dev doesn't have an
87119 diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
87120 index d9fa68f..45c88d1 100644
87121 --- a/include/net/9p/transport.h
87122 +++ b/include/net/9p/transport.h
87123 @@ -63,7 +63,7 @@ struct p9_trans_module {
87124 int (*cancelled)(struct p9_client *, struct p9_req_t *req);
87125 int (*zc_request)(struct p9_client *, struct p9_req_t *,
87126 char *, char *, int , int, int, int);
87127 -};
87128 +} __do_const;
87129
87130 void v9fs_register_trans(struct p9_trans_module *m);
87131 void v9fs_unregister_trans(struct p9_trans_module *m);
87132 diff --git a/include/net/af_unix.h b/include/net/af_unix.h
87133 index a175ba4..196eb8242 100644
87134 --- a/include/net/af_unix.h
87135 +++ b/include/net/af_unix.h
87136 @@ -36,7 +36,7 @@ struct unix_skb_parms {
87137 u32 secid; /* Security ID */
87138 #endif
87139 u32 consumed;
87140 -};
87141 +} __randomize_layout;
87142
87143 #define UNIXCB(skb) (*(struct unix_skb_parms *)&((skb)->cb))
87144 #define UNIXSID(skb) (&UNIXCB((skb)).secid)
87145 diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
87146 index 8df15ad..837fbedd 100644
87147 --- a/include/net/bluetooth/l2cap.h
87148 +++ b/include/net/bluetooth/l2cap.h
87149 @@ -608,7 +608,7 @@ struct l2cap_ops {
87150 unsigned char *kdata,
87151 struct iovec *iov,
87152 int len);
87153 -};
87154 +} __do_const;
87155
87156 struct l2cap_conn {
87157 struct hci_conn *hcon;
87158 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
87159 index f2ae33d..c457cf0 100644
87160 --- a/include/net/caif/cfctrl.h
87161 +++ b/include/net/caif/cfctrl.h
87162 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
87163 void (*radioset_rsp)(void);
87164 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
87165 struct cflayer *client_layer);
87166 -};
87167 +} __no_const;
87168
87169 /* Link Setup Parameters for CAIF-Links. */
87170 struct cfctrl_link_param {
87171 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
87172 struct cfctrl {
87173 struct cfsrvl serv;
87174 struct cfctrl_rsp res;
87175 - atomic_t req_seq_no;
87176 - atomic_t rsp_seq_no;
87177 + atomic_unchecked_t req_seq_no;
87178 + atomic_unchecked_t rsp_seq_no;
87179 struct list_head list;
87180 /* Protects from simultaneous access to first_req list */
87181 spinlock_t info_list_lock;
87182 diff --git a/include/net/flow.h b/include/net/flow.h
87183 index 8109a15..504466d 100644
87184 --- a/include/net/flow.h
87185 +++ b/include/net/flow.h
87186 @@ -231,6 +231,6 @@ void flow_cache_fini(struct net *net);
87187
87188 void flow_cache_flush(struct net *net);
87189 void flow_cache_flush_deferred(struct net *net);
87190 -extern atomic_t flow_cache_genid;
87191 +extern atomic_unchecked_t flow_cache_genid;
87192
87193 #endif
87194 diff --git a/include/net/genetlink.h b/include/net/genetlink.h
87195 index af10c2c..a431cc5 100644
87196 --- a/include/net/genetlink.h
87197 +++ b/include/net/genetlink.h
87198 @@ -120,7 +120,7 @@ struct genl_ops {
87199 u8 cmd;
87200 u8 internal_flags;
87201 u8 flags;
87202 -};
87203 +} __do_const;
87204
87205 int __genl_register_family(struct genl_family *family);
87206
87207 diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
87208 index 734d9b5..48a9a4b 100644
87209 --- a/include/net/gro_cells.h
87210 +++ b/include/net/gro_cells.h
87211 @@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
87212 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
87213
87214 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
87215 - atomic_long_inc(&dev->rx_dropped);
87216 + atomic_long_inc_unchecked(&dev->rx_dropped);
87217 kfree_skb(skb);
87218 return;
87219 }
87220 diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
87221 index 5fbe656..9ed3d8b 100644
87222 --- a/include/net/inet_connection_sock.h
87223 +++ b/include/net/inet_connection_sock.h
87224 @@ -63,7 +63,7 @@ struct inet_connection_sock_af_ops {
87225 int (*bind_conflict)(const struct sock *sk,
87226 const struct inet_bind_bucket *tb, bool relax);
87227 void (*mtu_reduced)(struct sock *sk);
87228 -};
87229 +} __do_const;
87230
87231 /** inet_connection_sock - INET connection oriented sock
87232 *
87233 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
87234 index 01d590e..f69c61d 100644
87235 --- a/include/net/inetpeer.h
87236 +++ b/include/net/inetpeer.h
87237 @@ -47,7 +47,7 @@ struct inet_peer {
87238 */
87239 union {
87240 struct {
87241 - atomic_t rid; /* Frag reception counter */
87242 + atomic_unchecked_t rid; /* Frag reception counter */
87243 };
87244 struct rcu_head rcu;
87245 struct inet_peer *gc_next;
87246 diff --git a/include/net/ip.h b/include/net/ip.h
87247 index db4a771..965a42a 100644
87248 --- a/include/net/ip.h
87249 +++ b/include/net/ip.h
87250 @@ -316,7 +316,7 @@ static inline unsigned int ip_skb_dst_mtu(const struct sk_buff *skb)
87251 }
87252 }
87253
87254 -u32 ip_idents_reserve(u32 hash, int segs);
87255 +u32 ip_idents_reserve(u32 hash, int segs) __intentional_overflow(-1);
87256 void __ip_select_ident(struct iphdr *iph, int segs);
87257
87258 static inline void ip_select_ident_segs(struct sk_buff *skb, struct sock *sk, int segs)
87259 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
87260 index 9922093..a1755d6 100644
87261 --- a/include/net/ip_fib.h
87262 +++ b/include/net/ip_fib.h
87263 @@ -169,7 +169,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
87264
87265 #define FIB_RES_SADDR(net, res) \
87266 ((FIB_RES_NH(res).nh_saddr_genid == \
87267 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
87268 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
87269 FIB_RES_NH(res).nh_saddr : \
87270 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
87271 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
87272 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
87273 index 624a8a5..b1e2a24 100644
87274 --- a/include/net/ip_vs.h
87275 +++ b/include/net/ip_vs.h
87276 @@ -558,7 +558,7 @@ struct ip_vs_conn {
87277 struct ip_vs_conn *control; /* Master control connection */
87278 atomic_t n_control; /* Number of controlled ones */
87279 struct ip_vs_dest *dest; /* real server */
87280 - atomic_t in_pkts; /* incoming packet counter */
87281 + atomic_unchecked_t in_pkts; /* incoming packet counter */
87282
87283 /* packet transmitter for different forwarding methods. If it
87284 mangles the packet, it must return NF_DROP or better NF_STOLEN,
87285 @@ -705,7 +705,7 @@ struct ip_vs_dest {
87286 __be16 port; /* port number of the server */
87287 union nf_inet_addr addr; /* IP address of the server */
87288 volatile unsigned int flags; /* dest status flags */
87289 - atomic_t conn_flags; /* flags to copy to conn */
87290 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
87291 atomic_t weight; /* server weight */
87292
87293 atomic_t refcnt; /* reference counter */
87294 @@ -960,11 +960,11 @@ struct netns_ipvs {
87295 /* ip_vs_lblc */
87296 int sysctl_lblc_expiration;
87297 struct ctl_table_header *lblc_ctl_header;
87298 - struct ctl_table *lblc_ctl_table;
87299 + ctl_table_no_const *lblc_ctl_table;
87300 /* ip_vs_lblcr */
87301 int sysctl_lblcr_expiration;
87302 struct ctl_table_header *lblcr_ctl_header;
87303 - struct ctl_table *lblcr_ctl_table;
87304 + ctl_table_no_const *lblcr_ctl_table;
87305 /* ip_vs_est */
87306 struct list_head est_list; /* estimator list */
87307 spinlock_t est_lock;
87308 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
87309 index 8d4f588..2e37ad2 100644
87310 --- a/include/net/irda/ircomm_tty.h
87311 +++ b/include/net/irda/ircomm_tty.h
87312 @@ -33,6 +33,7 @@
87313 #include <linux/termios.h>
87314 #include <linux/timer.h>
87315 #include <linux/tty.h> /* struct tty_struct */
87316 +#include <asm/local.h>
87317
87318 #include <net/irda/irias_object.h>
87319 #include <net/irda/ircomm_core.h>
87320 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
87321 index 714cc9a..ea05f3e 100644
87322 --- a/include/net/iucv/af_iucv.h
87323 +++ b/include/net/iucv/af_iucv.h
87324 @@ -149,7 +149,7 @@ struct iucv_skb_cb {
87325 struct iucv_sock_list {
87326 struct hlist_head head;
87327 rwlock_t lock;
87328 - atomic_t autobind_name;
87329 + atomic_unchecked_t autobind_name;
87330 };
87331
87332 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
87333 diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
87334 index f3be818..bf46196 100644
87335 --- a/include/net/llc_c_ac.h
87336 +++ b/include/net/llc_c_ac.h
87337 @@ -87,7 +87,7 @@
87338 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
87339 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
87340
87341 -typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
87342 +typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
87343
87344 int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
87345 int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
87346 diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
87347 index 3948cf1..83b28c4 100644
87348 --- a/include/net/llc_c_ev.h
87349 +++ b/include/net/llc_c_ev.h
87350 @@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
87351 return (struct llc_conn_state_ev *)skb->cb;
87352 }
87353
87354 -typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
87355 -typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
87356 +typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
87357 +typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
87358
87359 int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
87360 int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
87361 diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
87362 index 0e79cfb..f46db31 100644
87363 --- a/include/net/llc_c_st.h
87364 +++ b/include/net/llc_c_st.h
87365 @@ -37,7 +37,7 @@ struct llc_conn_state_trans {
87366 u8 next_state;
87367 llc_conn_ev_qfyr_t *ev_qualifiers;
87368 llc_conn_action_t *ev_actions;
87369 -};
87370 +} __do_const;
87371
87372 struct llc_conn_state {
87373 u8 current_state;
87374 diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
87375 index a61b98c..aade1eb 100644
87376 --- a/include/net/llc_s_ac.h
87377 +++ b/include/net/llc_s_ac.h
87378 @@ -23,7 +23,7 @@
87379 #define SAP_ACT_TEST_IND 9
87380
87381 /* All action functions must look like this */
87382 -typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
87383 +typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
87384
87385 int llc_sap_action_unitdata_ind(struct llc_sap *sap, struct sk_buff *skb);
87386 int llc_sap_action_send_ui(struct llc_sap *sap, struct sk_buff *skb);
87387 diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
87388 index 567c681..cd73ac02 100644
87389 --- a/include/net/llc_s_st.h
87390 +++ b/include/net/llc_s_st.h
87391 @@ -20,7 +20,7 @@ struct llc_sap_state_trans {
87392 llc_sap_ev_t ev;
87393 u8 next_state;
87394 llc_sap_action_t *ev_actions;
87395 -};
87396 +} __do_const;
87397
87398 struct llc_sap_state {
87399 u8 curr_state;
87400 diff --git a/include/net/mac80211.h b/include/net/mac80211.h
87401 index dae2e24..89336e6 100644
87402 --- a/include/net/mac80211.h
87403 +++ b/include/net/mac80211.h
87404 @@ -4650,7 +4650,7 @@ struct rate_control_ops {
87405 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
87406
87407 u32 (*get_expected_throughput)(void *priv_sta);
87408 -};
87409 +} __do_const;
87410
87411 static inline int rate_supported(struct ieee80211_sta *sta,
87412 enum ieee80211_band band,
87413 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
87414 index 47f4254..fd095bc 100644
87415 --- a/include/net/neighbour.h
87416 +++ b/include/net/neighbour.h
87417 @@ -163,7 +163,7 @@ struct neigh_ops {
87418 void (*error_report)(struct neighbour *, struct sk_buff *);
87419 int (*output)(struct neighbour *, struct sk_buff *);
87420 int (*connected_output)(struct neighbour *, struct sk_buff *);
87421 -};
87422 +} __do_const;
87423
87424 struct pneigh_entry {
87425 struct pneigh_entry *next;
87426 @@ -217,7 +217,7 @@ struct neigh_table {
87427 struct neigh_statistics __percpu *stats;
87428 struct neigh_hash_table __rcu *nht;
87429 struct pneigh_entry **phash_buckets;
87430 -};
87431 +} __randomize_layout;
87432
87433 static inline int neigh_parms_family(struct neigh_parms *p)
87434 {
87435 diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
87436 index e0d6466..e2f3003 100644
87437 --- a/include/net/net_namespace.h
87438 +++ b/include/net/net_namespace.h
87439 @@ -129,8 +129,8 @@ struct net {
87440 struct netns_ipvs *ipvs;
87441 #endif
87442 struct sock *diag_nlsk;
87443 - atomic_t fnhe_genid;
87444 -};
87445 + atomic_unchecked_t fnhe_genid;
87446 +} __randomize_layout;
87447
87448 #include <linux/seq_file_net.h>
87449
87450 @@ -286,7 +286,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
87451 #define __net_init __init
87452 #define __net_exit __exit_refok
87453 #define __net_initdata __initdata
87454 +#ifdef CONSTIFY_PLUGIN
87455 #define __net_initconst __initconst
87456 +#else
87457 +#define __net_initconst __initdata
87458 +#endif
87459 #endif
87460
87461 struct pernet_operations {
87462 @@ -296,7 +300,7 @@ struct pernet_operations {
87463 void (*exit_batch)(struct list_head *net_exit_list);
87464 int *id;
87465 size_t size;
87466 -};
87467 +} __do_const;
87468
87469 /*
87470 * Use these carefully. If you implement a network device and it
87471 @@ -344,12 +348,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
87472
87473 static inline int rt_genid_ipv4(struct net *net)
87474 {
87475 - return atomic_read(&net->ipv4.rt_genid);
87476 + return atomic_read_unchecked(&net->ipv4.rt_genid);
87477 }
87478
87479 static inline void rt_genid_bump_ipv4(struct net *net)
87480 {
87481 - atomic_inc(&net->ipv4.rt_genid);
87482 + atomic_inc_unchecked(&net->ipv4.rt_genid);
87483 }
87484
87485 extern void (*__fib6_flush_trees)(struct net *net);
87486 @@ -376,12 +380,12 @@ static inline void rt_genid_bump_all(struct net *net)
87487
87488 static inline int fnhe_genid(struct net *net)
87489 {
87490 - return atomic_read(&net->fnhe_genid);
87491 + return atomic_read_unchecked(&net->fnhe_genid);
87492 }
87493
87494 static inline void fnhe_genid_bump(struct net *net)
87495 {
87496 - atomic_inc(&net->fnhe_genid);
87497 + atomic_inc_unchecked(&net->fnhe_genid);
87498 }
87499
87500 #endif /* __NET_NET_NAMESPACE_H */
87501 diff --git a/include/net/netdma.h b/include/net/netdma.h
87502 index 8ba8ce2..99b7fff 100644
87503 --- a/include/net/netdma.h
87504 +++ b/include/net/netdma.h
87505 @@ -24,7 +24,7 @@
87506 #include <linux/dmaengine.h>
87507 #include <linux/skbuff.h>
87508
87509 -int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
87510 +int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
87511 struct sk_buff *skb, int offset, struct iovec *to,
87512 size_t len, struct dma_pinned_list *pinned_list);
87513
87514 diff --git a/include/net/netlink.h b/include/net/netlink.h
87515 index 6c10762..3e5de0c 100644
87516 --- a/include/net/netlink.h
87517 +++ b/include/net/netlink.h
87518 @@ -521,7 +521,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
87519 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
87520 {
87521 if (mark)
87522 - skb_trim(skb, (unsigned char *) mark - skb->data);
87523 + skb_trim(skb, (const unsigned char *) mark - skb->data);
87524 }
87525
87526 /**
87527 diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
87528 index 29d6a94..235d3d84 100644
87529 --- a/include/net/netns/conntrack.h
87530 +++ b/include/net/netns/conntrack.h
87531 @@ -14,10 +14,10 @@ struct nf_conntrack_ecache;
87532 struct nf_proto_net {
87533 #ifdef CONFIG_SYSCTL
87534 struct ctl_table_header *ctl_table_header;
87535 - struct ctl_table *ctl_table;
87536 + ctl_table_no_const *ctl_table;
87537 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
87538 struct ctl_table_header *ctl_compat_header;
87539 - struct ctl_table *ctl_compat_table;
87540 + ctl_table_no_const *ctl_compat_table;
87541 #endif
87542 #endif
87543 unsigned int users;
87544 @@ -60,7 +60,7 @@ struct nf_ip_net {
87545 struct nf_icmp_net icmpv6;
87546 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
87547 struct ctl_table_header *ctl_table_header;
87548 - struct ctl_table *ctl_table;
87549 + ctl_table_no_const *ctl_table;
87550 #endif
87551 };
87552
87553 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
87554 index aec5e12..807233f 100644
87555 --- a/include/net/netns/ipv4.h
87556 +++ b/include/net/netns/ipv4.h
87557 @@ -82,7 +82,7 @@ struct netns_ipv4 {
87558
87559 struct ping_group_range ping_group_range;
87560
87561 - atomic_t dev_addr_genid;
87562 + atomic_unchecked_t dev_addr_genid;
87563
87564 #ifdef CONFIG_SYSCTL
87565 unsigned long *sysctl_local_reserved_ports;
87566 @@ -96,6 +96,6 @@ struct netns_ipv4 {
87567 struct fib_rules_ops *mr_rules_ops;
87568 #endif
87569 #endif
87570 - atomic_t rt_genid;
87571 + atomic_unchecked_t rt_genid;
87572 };
87573 #endif
87574 diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
87575 index eade27a..42894dd 100644
87576 --- a/include/net/netns/ipv6.h
87577 +++ b/include/net/netns/ipv6.h
87578 @@ -75,8 +75,8 @@ struct netns_ipv6 {
87579 struct fib_rules_ops *mr6_rules_ops;
87580 #endif
87581 #endif
87582 - atomic_t dev_addr_genid;
87583 - atomic_t rt_genid;
87584 + atomic_unchecked_t dev_addr_genid;
87585 + atomic_unchecked_t rt_genid;
87586 };
87587
87588 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
87589 diff --git a/include/net/netns/xfrm.h b/include/net/netns/xfrm.h
87590 index 3492434..209f58c 100644
87591 --- a/include/net/netns/xfrm.h
87592 +++ b/include/net/netns/xfrm.h
87593 @@ -64,7 +64,7 @@ struct netns_xfrm {
87594
87595 /* flow cache part */
87596 struct flow_cache flow_cache_global;
87597 - atomic_t flow_cache_genid;
87598 + atomic_unchecked_t flow_cache_genid;
87599 struct list_head flow_cache_gc_list;
87600 spinlock_t flow_cache_gc_lock;
87601 struct work_struct flow_cache_gc_work;
87602 diff --git a/include/net/ping.h b/include/net/ping.h
87603 index 026479b..d9b2829 100644
87604 --- a/include/net/ping.h
87605 +++ b/include/net/ping.h
87606 @@ -54,7 +54,7 @@ struct ping_iter_state {
87607
87608 extern struct proto ping_prot;
87609 #if IS_ENABLED(CONFIG_IPV6)
87610 -extern struct pingv6_ops pingv6_ops;
87611 +extern struct pingv6_ops *pingv6_ops;
87612 #endif
87613
87614 struct pingfakehdr {
87615 diff --git a/include/net/protocol.h b/include/net/protocol.h
87616 index d6fcc1f..ca277058 100644
87617 --- a/include/net/protocol.h
87618 +++ b/include/net/protocol.h
87619 @@ -49,7 +49,7 @@ struct net_protocol {
87620 * socket lookup?
87621 */
87622 icmp_strict_tag_validation:1;
87623 -};
87624 +} __do_const;
87625
87626 #if IS_ENABLED(CONFIG_IPV6)
87627 struct inet6_protocol {
87628 @@ -62,7 +62,7 @@ struct inet6_protocol {
87629 u8 type, u8 code, int offset,
87630 __be32 info);
87631 unsigned int flags; /* INET6_PROTO_xxx */
87632 -};
87633 +} __do_const;
87634
87635 #define INET6_PROTO_NOPOLICY 0x1
87636 #define INET6_PROTO_FINAL 0x2
87637 diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
87638 index e21b9f9..0191ef0 100644
87639 --- a/include/net/rtnetlink.h
87640 +++ b/include/net/rtnetlink.h
87641 @@ -93,7 +93,7 @@ struct rtnl_link_ops {
87642 int (*fill_slave_info)(struct sk_buff *skb,
87643 const struct net_device *dev,
87644 const struct net_device *slave_dev);
87645 -};
87646 +} __do_const;
87647
87648 int __rtnl_link_register(struct rtnl_link_ops *ops);
87649 void __rtnl_link_unregister(struct rtnl_link_ops *ops);
87650 diff --git a/include/net/sctp/checksum.h b/include/net/sctp/checksum.h
87651 index 4a5b9a3..ca27d73 100644
87652 --- a/include/net/sctp/checksum.h
87653 +++ b/include/net/sctp/checksum.h
87654 @@ -61,8 +61,8 @@ static inline __le32 sctp_compute_cksum(const struct sk_buff *skb,
87655 unsigned int offset)
87656 {
87657 struct sctphdr *sh = sctp_hdr(skb);
87658 - __le32 ret, old = sh->checksum;
87659 - const struct skb_checksum_ops ops = {
87660 + __le32 ret, old = sh->checksum;
87661 + static const struct skb_checksum_ops ops = {
87662 .update = sctp_csum_update,
87663 .combine = sctp_csum_combine,
87664 };
87665 diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
87666 index 72a31db..aaa63d9 100644
87667 --- a/include/net/sctp/sm.h
87668 +++ b/include/net/sctp/sm.h
87669 @@ -80,7 +80,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
87670 typedef struct {
87671 sctp_state_fn_t *fn;
87672 const char *name;
87673 -} sctp_sm_table_entry_t;
87674 +} __do_const sctp_sm_table_entry_t;
87675
87676 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
87677 * currently in use.
87678 @@ -292,7 +292,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
87679 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
87680
87681 /* Extern declarations for major data structures. */
87682 -extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
87683 +extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
87684
87685
87686 /* Get the size of a DATA chunk payload. */
87687 diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
87688 index 4ff3f67..89ae38e 100644
87689 --- a/include/net/sctp/structs.h
87690 +++ b/include/net/sctp/structs.h
87691 @@ -509,7 +509,7 @@ struct sctp_pf {
87692 void (*to_sk_saddr)(union sctp_addr *, struct sock *sk);
87693 void (*to_sk_daddr)(union sctp_addr *, struct sock *sk);
87694 struct sctp_af *af;
87695 -};
87696 +} __do_const;
87697
87698
87699 /* Structure to track chunk fragments that have been acked, but peer
87700 diff --git a/include/net/sock.h b/include/net/sock.h
87701 index b9a5bd0..dcd5f3c 100644
87702 --- a/include/net/sock.h
87703 +++ b/include/net/sock.h
87704 @@ -356,7 +356,7 @@ struct sock {
87705 unsigned int sk_napi_id;
87706 unsigned int sk_ll_usec;
87707 #endif
87708 - atomic_t sk_drops;
87709 + atomic_unchecked_t sk_drops;
87710 int sk_rcvbuf;
87711
87712 struct sk_filter __rcu *sk_filter;
87713 @@ -1053,7 +1053,7 @@ struct proto {
87714 void (*destroy_cgroup)(struct mem_cgroup *memcg);
87715 struct cg_proto *(*proto_cgroup)(struct mem_cgroup *memcg);
87716 #endif
87717 -};
87718 +} __randomize_layout;
87719
87720 /*
87721 * Bits in struct cg_proto.flags
87722 @@ -1240,7 +1240,7 @@ static inline u64 memcg_memory_allocated_read(struct cg_proto *prot)
87723 return ret >> PAGE_SHIFT;
87724 }
87725
87726 -static inline long
87727 +static inline long __intentional_overflow(-1)
87728 sk_memory_allocated(const struct sock *sk)
87729 {
87730 struct proto *prot = sk->sk_prot;
87731 @@ -1385,7 +1385,7 @@ struct sock_iocb {
87732 struct scm_cookie *scm;
87733 struct msghdr *msg, async_msg;
87734 struct kiocb *kiocb;
87735 -};
87736 +} __randomize_layout;
87737
87738 static inline struct sock_iocb *kiocb_to_siocb(struct kiocb *iocb)
87739 {
87740 @@ -1820,7 +1820,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
87741 }
87742
87743 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
87744 - char __user *from, char *to,
87745 + char __user *from, unsigned char *to,
87746 int copy, int offset)
87747 {
87748 if (skb->ip_summed == CHECKSUM_NONE) {
87749 @@ -2091,7 +2091,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
87750 }
87751 }
87752
87753 -struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
87754 +struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
87755
87756 /**
87757 * sk_page_frag - return an appropriate page_frag
87758 diff --git a/include/net/tcp.h b/include/net/tcp.h
87759 index 590e01a..76498f3 100644
87760 --- a/include/net/tcp.h
87761 +++ b/include/net/tcp.h
87762 @@ -523,7 +523,7 @@ void tcp_retransmit_timer(struct sock *sk);
87763 void tcp_xmit_retransmit_queue(struct sock *);
87764 void tcp_simple_retransmit(struct sock *);
87765 int tcp_trim_head(struct sock *, struct sk_buff *, u32);
87766 -int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int, gfp_t);
87767 +int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int, gfp_t);
87768
87769 void tcp_send_probe0(struct sock *);
87770 void tcp_send_partial(struct sock *);
87771 @@ -696,8 +696,8 @@ struct tcp_skb_cb {
87772 struct inet6_skb_parm h6;
87773 #endif
87774 } header; /* For incoming frames */
87775 - __u32 seq; /* Starting sequence number */
87776 - __u32 end_seq; /* SEQ + FIN + SYN + datalen */
87777 + __u32 seq __intentional_overflow(0); /* Starting sequence number */
87778 + __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
87779 __u32 when; /* used to compute rtt's */
87780 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
87781
87782 @@ -713,7 +713,7 @@ struct tcp_skb_cb {
87783
87784 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
87785 /* 1 byte hole */
87786 - __u32 ack_seq; /* Sequence number ACK'd */
87787 + __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
87788 };
87789
87790 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
87791 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
87792 index 721e9c3b..3c81bbf 100644
87793 --- a/include/net/xfrm.h
87794 +++ b/include/net/xfrm.h
87795 @@ -285,7 +285,6 @@ struct xfrm_dst;
87796 struct xfrm_policy_afinfo {
87797 unsigned short family;
87798 struct dst_ops *dst_ops;
87799 - void (*garbage_collect)(struct net *net);
87800 struct dst_entry *(*dst_lookup)(struct net *net, int tos,
87801 const xfrm_address_t *saddr,
87802 const xfrm_address_t *daddr);
87803 @@ -303,7 +302,7 @@ struct xfrm_policy_afinfo {
87804 struct net_device *dev,
87805 const struct flowi *fl);
87806 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
87807 -};
87808 +} __do_const;
87809
87810 int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
87811 int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
87812 @@ -342,7 +341,7 @@ struct xfrm_state_afinfo {
87813 int (*transport_finish)(struct sk_buff *skb,
87814 int async);
87815 void (*local_error)(struct sk_buff *skb, u32 mtu);
87816 -};
87817 +} __do_const;
87818
87819 int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
87820 int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
87821 @@ -437,7 +436,7 @@ struct xfrm_mode {
87822 struct module *owner;
87823 unsigned int encap;
87824 int flags;
87825 -};
87826 +} __do_const;
87827
87828 /* Flags for xfrm_mode. */
87829 enum {
87830 @@ -534,7 +533,7 @@ struct xfrm_policy {
87831 struct timer_list timer;
87832
87833 struct flow_cache_object flo;
87834 - atomic_t genid;
87835 + atomic_unchecked_t genid;
87836 u32 priority;
87837 u32 index;
87838 struct xfrm_mark mark;
87839 @@ -1167,6 +1166,7 @@ static inline void xfrm_sk_free_policy(struct sock *sk)
87840 }
87841
87842 void xfrm_garbage_collect(struct net *net);
87843 +void xfrm_garbage_collect_deferred(struct net *net);
87844
87845 #else
87846
87847 @@ -1205,6 +1205,9 @@ static inline int xfrm6_policy_check_reverse(struct sock *sk, int dir,
87848 static inline void xfrm_garbage_collect(struct net *net)
87849 {
87850 }
87851 +static inline void xfrm_garbage_collect_deferred(struct net *net)
87852 +{
87853 +}
87854 #endif
87855
87856 static __inline__
87857 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
87858 index 1017e0b..227aa4d 100644
87859 --- a/include/rdma/iw_cm.h
87860 +++ b/include/rdma/iw_cm.h
87861 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
87862 int backlog);
87863
87864 int (*destroy_listen)(struct iw_cm_id *cm_id);
87865 -};
87866 +} __no_const;
87867
87868 /**
87869 * iw_create_cm_id - Create an IW CM identifier.
87870 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
87871 index 52beadf..598734c 100644
87872 --- a/include/scsi/libfc.h
87873 +++ b/include/scsi/libfc.h
87874 @@ -771,6 +771,7 @@ struct libfc_function_template {
87875 */
87876 void (*disc_stop_final) (struct fc_lport *);
87877 };
87878 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
87879
87880 /**
87881 * struct fc_disc - Discovery context
87882 @@ -875,7 +876,7 @@ struct fc_lport {
87883 struct fc_vport *vport;
87884
87885 /* Operational Information */
87886 - struct libfc_function_template tt;
87887 + libfc_function_template_no_const tt;
87888 u8 link_up;
87889 u8 qfull;
87890 enum fc_lport_state state;
87891 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
87892 index 1a0d184..4fb841f 100644
87893 --- a/include/scsi/scsi_device.h
87894 +++ b/include/scsi/scsi_device.h
87895 @@ -185,9 +185,9 @@ struct scsi_device {
87896 unsigned int max_device_blocked; /* what device_blocked counts down from */
87897 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
87898
87899 - atomic_t iorequest_cnt;
87900 - atomic_t iodone_cnt;
87901 - atomic_t ioerr_cnt;
87902 + atomic_unchecked_t iorequest_cnt;
87903 + atomic_unchecked_t iodone_cnt;
87904 + atomic_unchecked_t ioerr_cnt;
87905
87906 struct device sdev_gendev,
87907 sdev_dev;
87908 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
87909 index 007a0bc..7188db8 100644
87910 --- a/include/scsi/scsi_transport_fc.h
87911 +++ b/include/scsi/scsi_transport_fc.h
87912 @@ -756,7 +756,8 @@ struct fc_function_template {
87913 unsigned long show_host_system_hostname:1;
87914
87915 unsigned long disable_target_scan:1;
87916 -};
87917 +} __do_const;
87918 +typedef struct fc_function_template __no_const fc_function_template_no_const;
87919
87920
87921 /**
87922 diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
87923 index ae6c3b8..fd748ac 100644
87924 --- a/include/sound/compress_driver.h
87925 +++ b/include/sound/compress_driver.h
87926 @@ -128,7 +128,7 @@ struct snd_compr_ops {
87927 struct snd_compr_caps *caps);
87928 int (*get_codec_caps) (struct snd_compr_stream *stream,
87929 struct snd_compr_codec_caps *codec);
87930 -};
87931 +} __no_const;
87932
87933 /**
87934 * struct snd_compr: Compressed device
87935 diff --git a/include/sound/soc.h b/include/sound/soc.h
87936 index c83a334..27c8038 100644
87937 --- a/include/sound/soc.h
87938 +++ b/include/sound/soc.h
87939 @@ -817,7 +817,7 @@ struct snd_soc_codec_driver {
87940 /* probe ordering - for components with runtime dependencies */
87941 int probe_order;
87942 int remove_order;
87943 -};
87944 +} __do_const;
87945
87946 /* SoC platform interface */
87947 struct snd_soc_platform_driver {
87948 @@ -861,7 +861,7 @@ struct snd_soc_platform_driver {
87949 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
87950 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
87951 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
87952 -};
87953 +} __do_const;
87954
87955 struct snd_soc_dai_link_component {
87956 const char *name;
87957 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
87958 index 9ec9864..e2ee1ee 100644
87959 --- a/include/target/target_core_base.h
87960 +++ b/include/target/target_core_base.h
87961 @@ -761,7 +761,7 @@ struct se_device {
87962 atomic_long_t write_bytes;
87963 /* Active commands on this virtual SE device */
87964 atomic_t simple_cmds;
87965 - atomic_t dev_ordered_id;
87966 + atomic_unchecked_t dev_ordered_id;
87967 atomic_t dev_ordered_sync;
87968 atomic_t dev_qf_count;
87969 int export_count;
87970 diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
87971 new file mode 100644
87972 index 0000000..fb634b7
87973 --- /dev/null
87974 +++ b/include/trace/events/fs.h
87975 @@ -0,0 +1,53 @@
87976 +#undef TRACE_SYSTEM
87977 +#define TRACE_SYSTEM fs
87978 +
87979 +#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
87980 +#define _TRACE_FS_H
87981 +
87982 +#include <linux/fs.h>
87983 +#include <linux/tracepoint.h>
87984 +
87985 +TRACE_EVENT(do_sys_open,
87986 +
87987 + TP_PROTO(const char *filename, int flags, int mode),
87988 +
87989 + TP_ARGS(filename, flags, mode),
87990 +
87991 + TP_STRUCT__entry(
87992 + __string( filename, filename )
87993 + __field( int, flags )
87994 + __field( int, mode )
87995 + ),
87996 +
87997 + TP_fast_assign(
87998 + __assign_str(filename, filename);
87999 + __entry->flags = flags;
88000 + __entry->mode = mode;
88001 + ),
88002 +
88003 + TP_printk("\"%s\" %x %o",
88004 + __get_str(filename), __entry->flags, __entry->mode)
88005 +);
88006 +
88007 +TRACE_EVENT(open_exec,
88008 +
88009 + TP_PROTO(const char *filename),
88010 +
88011 + TP_ARGS(filename),
88012 +
88013 + TP_STRUCT__entry(
88014 + __string( filename, filename )
88015 + ),
88016 +
88017 + TP_fast_assign(
88018 + __assign_str(filename, filename);
88019 + ),
88020 +
88021 + TP_printk("\"%s\"",
88022 + __get_str(filename))
88023 +);
88024 +
88025 +#endif /* _TRACE_FS_H */
88026 +
88027 +/* This part must be outside protection */
88028 +#include <trace/define_trace.h>
88029 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
88030 index 3608beb..df39d8a 100644
88031 --- a/include/trace/events/irq.h
88032 +++ b/include/trace/events/irq.h
88033 @@ -36,7 +36,7 @@ struct softirq_action;
88034 */
88035 TRACE_EVENT(irq_handler_entry,
88036
88037 - TP_PROTO(int irq, struct irqaction *action),
88038 + TP_PROTO(int irq, const struct irqaction *action),
88039
88040 TP_ARGS(irq, action),
88041
88042 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
88043 */
88044 TRACE_EVENT(irq_handler_exit,
88045
88046 - TP_PROTO(int irq, struct irqaction *action, int ret),
88047 + TP_PROTO(int irq, const struct irqaction *action, int ret),
88048
88049 TP_ARGS(irq, action, ret),
88050
88051 diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
88052 index 7caf44c..23c6f27 100644
88053 --- a/include/uapi/linux/a.out.h
88054 +++ b/include/uapi/linux/a.out.h
88055 @@ -39,6 +39,14 @@ enum machine_type {
88056 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
88057 };
88058
88059 +/* Constants for the N_FLAGS field */
88060 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
88061 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
88062 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
88063 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
88064 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
88065 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
88066 +
88067 #if !defined (N_MAGIC)
88068 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
88069 #endif
88070 diff --git a/include/uapi/linux/bcache.h b/include/uapi/linux/bcache.h
88071 index 22b6ad3..aeba37e 100644
88072 --- a/include/uapi/linux/bcache.h
88073 +++ b/include/uapi/linux/bcache.h
88074 @@ -5,6 +5,7 @@
88075 * Bcache on disk data structures
88076 */
88077
88078 +#include <linux/compiler.h>
88079 #include <asm/types.h>
88080
88081 #define BITMASK(name, type, field, offset, size) \
88082 @@ -20,8 +21,8 @@ static inline void SET_##name(type *k, __u64 v) \
88083 /* Btree keys - all units are in sectors */
88084
88085 struct bkey {
88086 - __u64 high;
88087 - __u64 low;
88088 + __u64 high __intentional_overflow(-1);
88089 + __u64 low __intentional_overflow(-1);
88090 __u64 ptr[];
88091 };
88092
88093 diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
88094 index d876736..ccce5c0 100644
88095 --- a/include/uapi/linux/byteorder/little_endian.h
88096 +++ b/include/uapi/linux/byteorder/little_endian.h
88097 @@ -42,51 +42,51 @@
88098
88099 static inline __le64 __cpu_to_le64p(const __u64 *p)
88100 {
88101 - return (__force __le64)*p;
88102 + return (__force const __le64)*p;
88103 }
88104 -static inline __u64 __le64_to_cpup(const __le64 *p)
88105 +static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
88106 {
88107 - return (__force __u64)*p;
88108 + return (__force const __u64)*p;
88109 }
88110 static inline __le32 __cpu_to_le32p(const __u32 *p)
88111 {
88112 - return (__force __le32)*p;
88113 + return (__force const __le32)*p;
88114 }
88115 static inline __u32 __le32_to_cpup(const __le32 *p)
88116 {
88117 - return (__force __u32)*p;
88118 + return (__force const __u32)*p;
88119 }
88120 static inline __le16 __cpu_to_le16p(const __u16 *p)
88121 {
88122 - return (__force __le16)*p;
88123 + return (__force const __le16)*p;
88124 }
88125 static inline __u16 __le16_to_cpup(const __le16 *p)
88126 {
88127 - return (__force __u16)*p;
88128 + return (__force const __u16)*p;
88129 }
88130 static inline __be64 __cpu_to_be64p(const __u64 *p)
88131 {
88132 - return (__force __be64)__swab64p(p);
88133 + return (__force const __be64)__swab64p(p);
88134 }
88135 static inline __u64 __be64_to_cpup(const __be64 *p)
88136 {
88137 - return __swab64p((__u64 *)p);
88138 + return __swab64p((const __u64 *)p);
88139 }
88140 static inline __be32 __cpu_to_be32p(const __u32 *p)
88141 {
88142 - return (__force __be32)__swab32p(p);
88143 + return (__force const __be32)__swab32p(p);
88144 }
88145 -static inline __u32 __be32_to_cpup(const __be32 *p)
88146 +static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
88147 {
88148 - return __swab32p((__u32 *)p);
88149 + return __swab32p((const __u32 *)p);
88150 }
88151 static inline __be16 __cpu_to_be16p(const __u16 *p)
88152 {
88153 - return (__force __be16)__swab16p(p);
88154 + return (__force const __be16)__swab16p(p);
88155 }
88156 static inline __u16 __be16_to_cpup(const __be16 *p)
88157 {
88158 - return __swab16p((__u16 *)p);
88159 + return __swab16p((const __u16 *)p);
88160 }
88161 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
88162 #define __le64_to_cpus(x) do { (void)(x); } while (0)
88163 diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
88164 index ef6103b..d4e65dd 100644
88165 --- a/include/uapi/linux/elf.h
88166 +++ b/include/uapi/linux/elf.h
88167 @@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
88168 #define PT_GNU_EH_FRAME 0x6474e550
88169
88170 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
88171 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
88172 +
88173 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
88174 +
88175 +/* Constants for the e_flags field */
88176 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
88177 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
88178 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
88179 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
88180 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
88181 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
88182
88183 /*
88184 * Extended Numbering
88185 @@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
88186 #define DT_DEBUG 21
88187 #define DT_TEXTREL 22
88188 #define DT_JMPREL 23
88189 +#define DT_FLAGS 30
88190 + #define DF_TEXTREL 0x00000004
88191 #define DT_ENCODING 32
88192 #define OLD_DT_LOOS 0x60000000
88193 #define DT_LOOS 0x6000000d
88194 @@ -240,6 +253,19 @@ typedef struct elf64_hdr {
88195 #define PF_W 0x2
88196 #define PF_X 0x1
88197
88198 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
88199 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
88200 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
88201 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
88202 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
88203 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
88204 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
88205 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
88206 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
88207 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
88208 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
88209 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
88210 +
88211 typedef struct elf32_phdr{
88212 Elf32_Word p_type;
88213 Elf32_Off p_offset;
88214 @@ -332,6 +358,8 @@ typedef struct elf64_shdr {
88215 #define EI_OSABI 7
88216 #define EI_PAD 8
88217
88218 +#define EI_PAX 14
88219 +
88220 #define ELFMAG0 0x7f /* EI_MAG */
88221 #define ELFMAG1 'E'
88222 #define ELFMAG2 'L'
88223 diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
88224 index aa169c4..6a2771d 100644
88225 --- a/include/uapi/linux/personality.h
88226 +++ b/include/uapi/linux/personality.h
88227 @@ -30,6 +30,7 @@ enum {
88228 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
88229 ADDR_NO_RANDOMIZE | \
88230 ADDR_COMPAT_LAYOUT | \
88231 + ADDR_LIMIT_3GB | \
88232 MMAP_PAGE_ZERO)
88233
88234 /*
88235 diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
88236 index 7530e74..e714828 100644
88237 --- a/include/uapi/linux/screen_info.h
88238 +++ b/include/uapi/linux/screen_info.h
88239 @@ -43,7 +43,8 @@ struct screen_info {
88240 __u16 pages; /* 0x32 */
88241 __u16 vesa_attributes; /* 0x34 */
88242 __u32 capabilities; /* 0x36 */
88243 - __u8 _reserved[6]; /* 0x3a */
88244 + __u16 vesapm_size; /* 0x3a */
88245 + __u8 _reserved[4]; /* 0x3c */
88246 } __attribute__((packed));
88247
88248 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
88249 diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
88250 index 0e011eb..82681b1 100644
88251 --- a/include/uapi/linux/swab.h
88252 +++ b/include/uapi/linux/swab.h
88253 @@ -43,7 +43,7 @@
88254 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
88255 */
88256
88257 -static inline __attribute_const__ __u16 __fswab16(__u16 val)
88258 +static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
88259 {
88260 #ifdef __HAVE_BUILTIN_BSWAP16__
88261 return __builtin_bswap16(val);
88262 @@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
88263 #endif
88264 }
88265
88266 -static inline __attribute_const__ __u32 __fswab32(__u32 val)
88267 +static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
88268 {
88269 #ifdef __HAVE_BUILTIN_BSWAP32__
88270 return __builtin_bswap32(val);
88271 @@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
88272 #endif
88273 }
88274
88275 -static inline __attribute_const__ __u64 __fswab64(__u64 val)
88276 +static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
88277 {
88278 #ifdef __HAVE_BUILTIN_BSWAP64__
88279 return __builtin_bswap64(val);
88280 diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
88281 index 43aaba1..1c30b48 100644
88282 --- a/include/uapi/linux/sysctl.h
88283 +++ b/include/uapi/linux/sysctl.h
88284 @@ -155,8 +155,6 @@ enum
88285 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
88286 };
88287
88288 -
88289 -
88290 /* CTL_VM names: */
88291 enum
88292 {
88293 diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
88294 index 778a329..1416ffb 100644
88295 --- a/include/uapi/linux/videodev2.h
88296 +++ b/include/uapi/linux/videodev2.h
88297 @@ -1285,7 +1285,7 @@ struct v4l2_ext_control {
88298 union {
88299 __s32 value;
88300 __s64 value64;
88301 - char *string;
88302 + char __user *string;
88303 __u8 *p_u8;
88304 __u16 *p_u16;
88305 __u32 *p_u32;
88306 diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
88307 index 1590c49..5eab462 100644
88308 --- a/include/uapi/linux/xattr.h
88309 +++ b/include/uapi/linux/xattr.h
88310 @@ -73,5 +73,9 @@
88311 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
88312 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
88313
88314 +/* User namespace */
88315 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
88316 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
88317 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
88318
88319 #endif /* _UAPI_LINUX_XATTR_H */
88320 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
88321 index f9466fa..f4e2b81 100644
88322 --- a/include/video/udlfb.h
88323 +++ b/include/video/udlfb.h
88324 @@ -53,10 +53,10 @@ struct dlfb_data {
88325 u32 pseudo_palette[256];
88326 int blank_mode; /*one of FB_BLANK_ */
88327 /* blit-only rendering path metrics, exposed through sysfs */
88328 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
88329 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
88330 - atomic_t bytes_sent; /* to usb, after compression including overhead */
88331 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
88332 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
88333 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
88334 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
88335 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
88336 };
88337
88338 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
88339 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
88340 index 30f5362..8ed8ac9 100644
88341 --- a/include/video/uvesafb.h
88342 +++ b/include/video/uvesafb.h
88343 @@ -122,6 +122,7 @@ struct uvesafb_par {
88344 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
88345 u8 pmi_setpal; /* PMI for palette changes */
88346 u16 *pmi_base; /* protected mode interface location */
88347 + u8 *pmi_code; /* protected mode code location */
88348 void *pmi_start;
88349 void *pmi_pal;
88350 u8 *vbe_state_orig; /*
88351 diff --git a/init/Kconfig b/init/Kconfig
88352 index 80a6907..baf7d53 100644
88353 --- a/init/Kconfig
88354 +++ b/init/Kconfig
88355 @@ -1150,6 +1150,7 @@ endif # CGROUPS
88356
88357 config CHECKPOINT_RESTORE
88358 bool "Checkpoint/restore support" if EXPERT
88359 + depends on !GRKERNSEC
88360 default n
88361 help
88362 Enables additional kernel features in a sake of checkpoint/restore.
88363 @@ -1635,7 +1636,7 @@ config SLUB_DEBUG
88364
88365 config COMPAT_BRK
88366 bool "Disable heap randomization"
88367 - default y
88368 + default n
88369 help
88370 Randomizing heap placement makes heap exploits harder, but it
88371 also breaks ancient binaries (including anything libc5 based).
88372 @@ -1923,7 +1924,7 @@ config INIT_ALL_POSSIBLE
88373 config STOP_MACHINE
88374 bool
88375 default y
88376 - depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
88377 + depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
88378 help
88379 Need stop_machine() primitive.
88380
88381 diff --git a/init/Makefile b/init/Makefile
88382 index 7bc47ee..6da2dc7 100644
88383 --- a/init/Makefile
88384 +++ b/init/Makefile
88385 @@ -2,6 +2,9 @@
88386 # Makefile for the linux kernel.
88387 #
88388
88389 +ccflags-y := $(GCC_PLUGINS_CFLAGS)
88390 +asflags-y := $(GCC_PLUGINS_AFLAGS)
88391 +
88392 obj-y := main.o version.o mounts.o
88393 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
88394 obj-y += noinitramfs.o
88395 diff --git a/init/do_mounts.c b/init/do_mounts.c
88396 index 82f2288..ea1430a 100644
88397 --- a/init/do_mounts.c
88398 +++ b/init/do_mounts.c
88399 @@ -359,11 +359,11 @@ static void __init get_fs_names(char *page)
88400 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
88401 {
88402 struct super_block *s;
88403 - int err = sys_mount(name, "/root", fs, flags, data);
88404 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
88405 if (err)
88406 return err;
88407
88408 - sys_chdir("/root");
88409 + sys_chdir((const char __force_user *)"/root");
88410 s = current->fs->pwd.dentry->d_sb;
88411 ROOT_DEV = s->s_dev;
88412 printk(KERN_INFO
88413 @@ -484,18 +484,18 @@ void __init change_floppy(char *fmt, ...)
88414 va_start(args, fmt);
88415 vsprintf(buf, fmt, args);
88416 va_end(args);
88417 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
88418 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
88419 if (fd >= 0) {
88420 sys_ioctl(fd, FDEJECT, 0);
88421 sys_close(fd);
88422 }
88423 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
88424 - fd = sys_open("/dev/console", O_RDWR, 0);
88425 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
88426 if (fd >= 0) {
88427 sys_ioctl(fd, TCGETS, (long)&termios);
88428 termios.c_lflag &= ~ICANON;
88429 sys_ioctl(fd, TCSETSF, (long)&termios);
88430 - sys_read(fd, &c, 1);
88431 + sys_read(fd, (char __user *)&c, 1);
88432 termios.c_lflag |= ICANON;
88433 sys_ioctl(fd, TCSETSF, (long)&termios);
88434 sys_close(fd);
88435 @@ -589,8 +589,8 @@ void __init prepare_namespace(void)
88436 mount_root();
88437 out:
88438 devtmpfs_mount("dev");
88439 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
88440 - sys_chroot(".");
88441 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
88442 + sys_chroot((const char __force_user *)".");
88443 }
88444
88445 static bool is_tmpfs;
88446 diff --git a/init/do_mounts.h b/init/do_mounts.h
88447 index f5b978a..69dbfe8 100644
88448 --- a/init/do_mounts.h
88449 +++ b/init/do_mounts.h
88450 @@ -15,15 +15,15 @@ extern int root_mountflags;
88451
88452 static inline int create_dev(char *name, dev_t dev)
88453 {
88454 - sys_unlink(name);
88455 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
88456 + sys_unlink((char __force_user *)name);
88457 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
88458 }
88459
88460 #if BITS_PER_LONG == 32
88461 static inline u32 bstat(char *name)
88462 {
88463 struct stat64 stat;
88464 - if (sys_stat64(name, &stat) != 0)
88465 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
88466 return 0;
88467 if (!S_ISBLK(stat.st_mode))
88468 return 0;
88469 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
88470 static inline u32 bstat(char *name)
88471 {
88472 struct stat stat;
88473 - if (sys_newstat(name, &stat) != 0)
88474 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
88475 return 0;
88476 if (!S_ISBLK(stat.st_mode))
88477 return 0;
88478 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
88479 index 3e0878e..8a9d7a0 100644
88480 --- a/init/do_mounts_initrd.c
88481 +++ b/init/do_mounts_initrd.c
88482 @@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
88483 {
88484 sys_unshare(CLONE_FS | CLONE_FILES);
88485 /* stdin/stdout/stderr for /linuxrc */
88486 - sys_open("/dev/console", O_RDWR, 0);
88487 + sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
88488 sys_dup(0);
88489 sys_dup(0);
88490 /* move initrd over / and chdir/chroot in initrd root */
88491 - sys_chdir("/root");
88492 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
88493 - sys_chroot(".");
88494 + sys_chdir((const char __force_user *)"/root");
88495 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
88496 + sys_chroot((const char __force_user *)".");
88497 sys_setsid();
88498 return 0;
88499 }
88500 @@ -59,8 +59,8 @@ static void __init handle_initrd(void)
88501 create_dev("/dev/root.old", Root_RAM0);
88502 /* mount initrd on rootfs' /root */
88503 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
88504 - sys_mkdir("/old", 0700);
88505 - sys_chdir("/old");
88506 + sys_mkdir((const char __force_user *)"/old", 0700);
88507 + sys_chdir((const char __force_user *)"/old");
88508
88509 /* try loading default modules from initrd */
88510 load_default_modules();
88511 @@ -80,31 +80,31 @@ static void __init handle_initrd(void)
88512 current->flags &= ~PF_FREEZER_SKIP;
88513
88514 /* move initrd to rootfs' /old */
88515 - sys_mount("..", ".", NULL, MS_MOVE, NULL);
88516 + sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
88517 /* switch root and cwd back to / of rootfs */
88518 - sys_chroot("..");
88519 + sys_chroot((const char __force_user *)"..");
88520
88521 if (new_decode_dev(real_root_dev) == Root_RAM0) {
88522 - sys_chdir("/old");
88523 + sys_chdir((const char __force_user *)"/old");
88524 return;
88525 }
88526
88527 - sys_chdir("/");
88528 + sys_chdir((const char __force_user *)"/");
88529 ROOT_DEV = new_decode_dev(real_root_dev);
88530 mount_root();
88531
88532 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
88533 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
88534 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
88535 if (!error)
88536 printk("okay\n");
88537 else {
88538 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
88539 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
88540 if (error == -ENOENT)
88541 printk("/initrd does not exist. Ignored.\n");
88542 else
88543 printk("failed\n");
88544 printk(KERN_NOTICE "Unmounting old root\n");
88545 - sys_umount("/old", MNT_DETACH);
88546 + sys_umount((char __force_user *)"/old", MNT_DETACH);
88547 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
88548 if (fd < 0) {
88549 error = fd;
88550 @@ -127,11 +127,11 @@ int __init initrd_load(void)
88551 * mounted in the normal path.
88552 */
88553 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
88554 - sys_unlink("/initrd.image");
88555 + sys_unlink((const char __force_user *)"/initrd.image");
88556 handle_initrd();
88557 return 1;
88558 }
88559 }
88560 - sys_unlink("/initrd.image");
88561 + sys_unlink((const char __force_user *)"/initrd.image");
88562 return 0;
88563 }
88564 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
88565 index 8cb6db5..d729f50 100644
88566 --- a/init/do_mounts_md.c
88567 +++ b/init/do_mounts_md.c
88568 @@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
88569 partitioned ? "_d" : "", minor,
88570 md_setup_args[ent].device_names);
88571
88572 - fd = sys_open(name, 0, 0);
88573 + fd = sys_open((char __force_user *)name, 0, 0);
88574 if (fd < 0) {
88575 printk(KERN_ERR "md: open failed - cannot start "
88576 "array %s\n", name);
88577 @@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
88578 * array without it
88579 */
88580 sys_close(fd);
88581 - fd = sys_open(name, 0, 0);
88582 + fd = sys_open((char __force_user *)name, 0, 0);
88583 sys_ioctl(fd, BLKRRPART, 0);
88584 }
88585 sys_close(fd);
88586 @@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
88587
88588 wait_for_device_probe();
88589
88590 - fd = sys_open("/dev/md0", 0, 0);
88591 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
88592 if (fd >= 0) {
88593 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
88594 sys_close(fd);
88595 diff --git a/init/init_task.c b/init/init_task.c
88596 index ba0a7f36..2bcf1d5 100644
88597 --- a/init/init_task.c
88598 +++ b/init/init_task.c
88599 @@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
88600 * Initial thread structure. Alignment of this is handled by a special
88601 * linker map entry.
88602 */
88603 +#ifdef CONFIG_X86
88604 +union thread_union init_thread_union __init_task_data;
88605 +#else
88606 union thread_union init_thread_union __init_task_data =
88607 { INIT_THREAD_INFO(init_task) };
88608 +#endif
88609 diff --git a/init/initramfs.c b/init/initramfs.c
88610 index bece48c..e911bd8 100644
88611 --- a/init/initramfs.c
88612 +++ b/init/initramfs.c
88613 @@ -25,7 +25,7 @@ static ssize_t __init xwrite(int fd, const char *p, size_t count)
88614
88615 /* sys_write only can write MAX_RW_COUNT aka 2G-4K bytes at most */
88616 while (count) {
88617 - ssize_t rv = sys_write(fd, p, count);
88618 + ssize_t rv = sys_write(fd, (char __force_user *)p, count);
88619
88620 if (rv < 0) {
88621 if (rv == -EINTR || rv == -EAGAIN)
88622 @@ -107,7 +107,7 @@ static void __init free_hash(void)
88623 }
88624 }
88625
88626 -static long __init do_utime(char *filename, time_t mtime)
88627 +static long __init do_utime(char __force_user *filename, time_t mtime)
88628 {
88629 struct timespec t[2];
88630
88631 @@ -142,7 +142,7 @@ static void __init dir_utime(void)
88632 struct dir_entry *de, *tmp;
88633 list_for_each_entry_safe(de, tmp, &dir_list, list) {
88634 list_del(&de->list);
88635 - do_utime(de->name, de->mtime);
88636 + do_utime((char __force_user *)de->name, de->mtime);
88637 kfree(de->name);
88638 kfree(de);
88639 }
88640 @@ -304,7 +304,7 @@ static int __init maybe_link(void)
88641 if (nlink >= 2) {
88642 char *old = find_link(major, minor, ino, mode, collected);
88643 if (old)
88644 - return (sys_link(old, collected) < 0) ? -1 : 1;
88645 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
88646 }
88647 return 0;
88648 }
88649 @@ -313,11 +313,11 @@ static void __init clean_path(char *path, umode_t mode)
88650 {
88651 struct stat st;
88652
88653 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
88654 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
88655 if (S_ISDIR(st.st_mode))
88656 - sys_rmdir(path);
88657 + sys_rmdir((char __force_user *)path);
88658 else
88659 - sys_unlink(path);
88660 + sys_unlink((char __force_user *)path);
88661 }
88662 }
88663
88664 @@ -338,7 +338,7 @@ static int __init do_name(void)
88665 int openflags = O_WRONLY|O_CREAT;
88666 if (ml != 1)
88667 openflags |= O_TRUNC;
88668 - wfd = sys_open(collected, openflags, mode);
88669 + wfd = sys_open((char __force_user *)collected, openflags, mode);
88670
88671 if (wfd >= 0) {
88672 sys_fchown(wfd, uid, gid);
88673 @@ -350,17 +350,17 @@ static int __init do_name(void)
88674 }
88675 }
88676 } else if (S_ISDIR(mode)) {
88677 - sys_mkdir(collected, mode);
88678 - sys_chown(collected, uid, gid);
88679 - sys_chmod(collected, mode);
88680 + sys_mkdir((char __force_user *)collected, mode);
88681 + sys_chown((char __force_user *)collected, uid, gid);
88682 + sys_chmod((char __force_user *)collected, mode);
88683 dir_add(collected, mtime);
88684 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
88685 S_ISFIFO(mode) || S_ISSOCK(mode)) {
88686 if (maybe_link() == 0) {
88687 - sys_mknod(collected, mode, rdev);
88688 - sys_chown(collected, uid, gid);
88689 - sys_chmod(collected, mode);
88690 - do_utime(collected, mtime);
88691 + sys_mknod((char __force_user *)collected, mode, rdev);
88692 + sys_chown((char __force_user *)collected, uid, gid);
88693 + sys_chmod((char __force_user *)collected, mode);
88694 + do_utime((char __force_user *)collected, mtime);
88695 }
88696 }
88697 return 0;
88698 @@ -372,7 +372,7 @@ static int __init do_copy(void)
88699 if (xwrite(wfd, victim, body_len) != body_len)
88700 error("write error");
88701 sys_close(wfd);
88702 - do_utime(vcollected, mtime);
88703 + do_utime((char __force_user *)vcollected, mtime);
88704 kfree(vcollected);
88705 eat(body_len);
88706 state = SkipIt;
88707 @@ -390,9 +390,9 @@ static int __init do_symlink(void)
88708 {
88709 collected[N_ALIGN(name_len) + body_len] = '\0';
88710 clean_path(collected, 0);
88711 - sys_symlink(collected + N_ALIGN(name_len), collected);
88712 - sys_lchown(collected, uid, gid);
88713 - do_utime(collected, mtime);
88714 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
88715 + sys_lchown((char __force_user *)collected, uid, gid);
88716 + do_utime((char __force_user *)collected, mtime);
88717 state = SkipIt;
88718 next_state = Reset;
88719 return 0;
88720 diff --git a/init/main.c b/init/main.c
88721 index d0f4b59..0c4b184 100644
88722 --- a/init/main.c
88723 +++ b/init/main.c
88724 @@ -98,6 +98,8 @@ extern void radix_tree_init(void);
88725 static inline void mark_rodata_ro(void) { }
88726 #endif
88727
88728 +extern void grsecurity_init(void);
88729 +
88730 /*
88731 * Debug helper: via this flag we know that we are in 'early bootup code'
88732 * where only the boot processor is running with IRQ disabled. This means
88733 @@ -159,6 +161,75 @@ static int __init set_reset_devices(char *str)
88734
88735 __setup("reset_devices", set_reset_devices);
88736
88737 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
88738 +kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
88739 +static int __init setup_grsec_proc_gid(char *str)
88740 +{
88741 + grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
88742 + return 1;
88743 +}
88744 +__setup("grsec_proc_gid=", setup_grsec_proc_gid);
88745 +#endif
88746 +
88747 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
88748 +unsigned long pax_user_shadow_base __read_only;
88749 +EXPORT_SYMBOL(pax_user_shadow_base);
88750 +extern char pax_enter_kernel_user[];
88751 +extern char pax_exit_kernel_user[];
88752 +#endif
88753 +
88754 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
88755 +static int __init setup_pax_nouderef(char *str)
88756 +{
88757 +#ifdef CONFIG_X86_32
88758 + unsigned int cpu;
88759 + struct desc_struct *gdt;
88760 +
88761 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
88762 + gdt = get_cpu_gdt_table(cpu);
88763 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
88764 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
88765 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
88766 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
88767 + }
88768 + loadsegment(ds, __KERNEL_DS);
88769 + loadsegment(es, __KERNEL_DS);
88770 + loadsegment(ss, __KERNEL_DS);
88771 +#else
88772 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
88773 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
88774 + clone_pgd_mask = ~(pgdval_t)0UL;
88775 + pax_user_shadow_base = 0UL;
88776 + setup_clear_cpu_cap(X86_FEATURE_PCID);
88777 + setup_clear_cpu_cap(X86_FEATURE_INVPCID);
88778 +#endif
88779 +
88780 + return 0;
88781 +}
88782 +early_param("pax_nouderef", setup_pax_nouderef);
88783 +
88784 +#ifdef CONFIG_X86_64
88785 +static int __init setup_pax_weakuderef(char *str)
88786 +{
88787 + if (clone_pgd_mask != ~(pgdval_t)0UL)
88788 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
88789 + return 1;
88790 +}
88791 +__setup("pax_weakuderef", setup_pax_weakuderef);
88792 +#endif
88793 +#endif
88794 +
88795 +#ifdef CONFIG_PAX_SOFTMODE
88796 +int pax_softmode;
88797 +
88798 +static int __init setup_pax_softmode(char *str)
88799 +{
88800 + get_option(&str, &pax_softmode);
88801 + return 1;
88802 +}
88803 +__setup("pax_softmode=", setup_pax_softmode);
88804 +#endif
88805 +
88806 static const char *argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
88807 const char *envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
88808 static const char *panic_later, *panic_param;
88809 @@ -728,7 +799,7 @@ static bool __init_or_module initcall_blacklisted(initcall_t fn)
88810 struct blacklist_entry *entry;
88811 char *fn_name;
88812
88813 - fn_name = kasprintf(GFP_KERNEL, "%pf", fn);
88814 + fn_name = kasprintf(GFP_KERNEL, "%pX", fn);
88815 if (!fn_name)
88816 return false;
88817
88818 @@ -780,7 +851,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
88819 {
88820 int count = preempt_count();
88821 int ret;
88822 - char msgbuf[64];
88823 + const char *msg1 = "", *msg2 = "";
88824
88825 if (initcall_blacklisted(fn))
88826 return -EPERM;
88827 @@ -790,18 +861,17 @@ int __init_or_module do_one_initcall(initcall_t fn)
88828 else
88829 ret = fn();
88830
88831 - msgbuf[0] = 0;
88832 -
88833 if (preempt_count() != count) {
88834 - sprintf(msgbuf, "preemption imbalance ");
88835 + msg1 = " preemption imbalance";
88836 preempt_count_set(count);
88837 }
88838 if (irqs_disabled()) {
88839 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
88840 + msg2 = " disabled interrupts";
88841 local_irq_enable();
88842 }
88843 - WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
88844 + WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
88845
88846 + add_latent_entropy();
88847 return ret;
88848 }
88849
88850 @@ -908,8 +978,8 @@ static int run_init_process(const char *init_filename)
88851 {
88852 argv_init[0] = init_filename;
88853 return do_execve(getname_kernel(init_filename),
88854 - (const char __user *const __user *)argv_init,
88855 - (const char __user *const __user *)envp_init);
88856 + (const char __user *const __force_user *)argv_init,
88857 + (const char __user *const __force_user *)envp_init);
88858 }
88859
88860 static int try_to_run_init_process(const char *init_filename)
88861 @@ -926,6 +996,10 @@ static int try_to_run_init_process(const char *init_filename)
88862 return ret;
88863 }
88864
88865 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
88866 +extern int gr_init_ran;
88867 +#endif
88868 +
88869 static noinline void __init kernel_init_freeable(void);
88870
88871 static int __ref kernel_init(void *unused)
88872 @@ -950,6 +1024,11 @@ static int __ref kernel_init(void *unused)
88873 ramdisk_execute_command, ret);
88874 }
88875
88876 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
88877 + /* if no initrd was used, be extra sure we enforce chroot restrictions */
88878 + gr_init_ran = 1;
88879 +#endif
88880 +
88881 /*
88882 * We try each of these until one succeeds.
88883 *
88884 @@ -1005,7 +1084,7 @@ static noinline void __init kernel_init_freeable(void)
88885 do_basic_setup();
88886
88887 /* Open the /dev/console on the rootfs, this should never fail */
88888 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
88889 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
88890 pr_err("Warning: unable to open an initial console.\n");
88891
88892 (void) sys_dup(0);
88893 @@ -1018,11 +1097,13 @@ static noinline void __init kernel_init_freeable(void)
88894 if (!ramdisk_execute_command)
88895 ramdisk_execute_command = "/init";
88896
88897 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
88898 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
88899 ramdisk_execute_command = NULL;
88900 prepare_namespace();
88901 }
88902
88903 + grsecurity_init();
88904 +
88905 /*
88906 * Ok, we have completed the initial bootup, and
88907 * we're essentially up and running. Get rid of the
88908 diff --git a/ipc/compat.c b/ipc/compat.c
88909 index b5ef4f7..ff31d87 100644
88910 --- a/ipc/compat.c
88911 +++ b/ipc/compat.c
88912 @@ -396,7 +396,7 @@ COMPAT_SYSCALL_DEFINE6(ipc, u32, call, int, first, int, second,
88913 COMPAT_SHMLBA);
88914 if (err < 0)
88915 return err;
88916 - return put_user(raddr, (compat_ulong_t *)compat_ptr(third));
88917 + return put_user(raddr, (compat_ulong_t __user *)compat_ptr(third));
88918 }
88919 case SHMDT:
88920 return sys_shmdt(compat_ptr(ptr));
88921 diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
88922 index e8075b2..76f2c6a 100644
88923 --- a/ipc/ipc_sysctl.c
88924 +++ b/ipc/ipc_sysctl.c
88925 @@ -30,7 +30,7 @@ static void *get_ipc(struct ctl_table *table)
88926 static int proc_ipc_dointvec(struct ctl_table *table, int write,
88927 void __user *buffer, size_t *lenp, loff_t *ppos)
88928 {
88929 - struct ctl_table ipc_table;
88930 + ctl_table_no_const ipc_table;
88931
88932 memcpy(&ipc_table, table, sizeof(ipc_table));
88933 ipc_table.data = get_ipc(table);
88934 @@ -41,7 +41,7 @@ static int proc_ipc_dointvec(struct ctl_table *table, int write,
88935 static int proc_ipc_dointvec_minmax(struct ctl_table *table, int write,
88936 void __user *buffer, size_t *lenp, loff_t *ppos)
88937 {
88938 - struct ctl_table ipc_table;
88939 + ctl_table_no_const ipc_table;
88940
88941 memcpy(&ipc_table, table, sizeof(ipc_table));
88942 ipc_table.data = get_ipc(table);
88943 @@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(struct ctl_table *table, int write,
88944 static int proc_ipc_callback_dointvec_minmax(struct ctl_table *table, int write,
88945 void __user *buffer, size_t *lenp, loff_t *ppos)
88946 {
88947 - struct ctl_table ipc_table;
88948 + ctl_table_no_const ipc_table;
88949 size_t lenp_bef = *lenp;
88950 int rc;
88951
88952 @@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec_minmax(struct ctl_table *table, int write,
88953 static int proc_ipc_doulongvec_minmax(struct ctl_table *table, int write,
88954 void __user *buffer, size_t *lenp, loff_t *ppos)
88955 {
88956 - struct ctl_table ipc_table;
88957 + ctl_table_no_const ipc_table;
88958 memcpy(&ipc_table, table, sizeof(ipc_table));
88959 ipc_table.data = get_ipc(table);
88960
88961 @@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
88962 static int proc_ipcauto_dointvec_minmax(struct ctl_table *table, int write,
88963 void __user *buffer, size_t *lenp, loff_t *ppos)
88964 {
88965 - struct ctl_table ipc_table;
88966 + ctl_table_no_const ipc_table;
88967 int oldval;
88968 int rc;
88969
88970 diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
88971 index 68d4e95..1477ded 100644
88972 --- a/ipc/mq_sysctl.c
88973 +++ b/ipc/mq_sysctl.c
88974 @@ -25,7 +25,7 @@ static void *get_mq(struct ctl_table *table)
88975 static int proc_mq_dointvec(struct ctl_table *table, int write,
88976 void __user *buffer, size_t *lenp, loff_t *ppos)
88977 {
88978 - struct ctl_table mq_table;
88979 + ctl_table_no_const mq_table;
88980 memcpy(&mq_table, table, sizeof(mq_table));
88981 mq_table.data = get_mq(table);
88982
88983 @@ -35,7 +35,7 @@ static int proc_mq_dointvec(struct ctl_table *table, int write,
88984 static int proc_mq_dointvec_minmax(struct ctl_table *table, int write,
88985 void __user *buffer, size_t *lenp, loff_t *ppos)
88986 {
88987 - struct ctl_table mq_table;
88988 + ctl_table_no_const mq_table;
88989 memcpy(&mq_table, table, sizeof(mq_table));
88990 mq_table.data = get_mq(table);
88991
88992 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
88993 index 4fcf39a..d3cc2ec 100644
88994 --- a/ipc/mqueue.c
88995 +++ b/ipc/mqueue.c
88996 @@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
88997 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
88998 info->attr.mq_msgsize);
88999
89000 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
89001 spin_lock(&mq_lock);
89002 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
89003 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
89004 diff --git a/ipc/shm.c b/ipc/shm.c
89005 index 7fc9f9f..95e201f 100644
89006 --- a/ipc/shm.c
89007 +++ b/ipc/shm.c
89008 @@ -72,6 +72,14 @@ static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp);
89009 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
89010 #endif
89011
89012 +#ifdef CONFIG_GRKERNSEC
89013 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
89014 + const u64 shm_createtime, const kuid_t cuid,
89015 + const int shmid);
89016 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
89017 + const u64 shm_createtime);
89018 +#endif
89019 +
89020 void shm_init_ns(struct ipc_namespace *ns)
89021 {
89022 ns->shm_ctlmax = SHMMAX;
89023 @@ -559,6 +567,9 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
89024 shp->shm_lprid = 0;
89025 shp->shm_atim = shp->shm_dtim = 0;
89026 shp->shm_ctim = get_seconds();
89027 +#ifdef CONFIG_GRKERNSEC
89028 + shp->shm_createtime = ktime_get_ns();
89029 +#endif
89030 shp->shm_segsz = size;
89031 shp->shm_nattch = 0;
89032 shp->shm_file = file;
89033 @@ -1095,6 +1106,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
89034 f_mode = FMODE_READ | FMODE_WRITE;
89035 }
89036 if (shmflg & SHM_EXEC) {
89037 +
89038 +#ifdef CONFIG_PAX_MPROTECT
89039 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
89040 + goto out;
89041 +#endif
89042 +
89043 prot |= PROT_EXEC;
89044 acc_mode |= S_IXUGO;
89045 }
89046 @@ -1119,6 +1136,15 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
89047 if (err)
89048 goto out_unlock;
89049
89050 +#ifdef CONFIG_GRKERNSEC
89051 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
89052 + shp->shm_perm.cuid, shmid) ||
89053 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
89054 + err = -EACCES;
89055 + goto out_unlock;
89056 + }
89057 +#endif
89058 +
89059 ipc_lock_object(&shp->shm_perm);
89060
89061 /* check if shm_destroy() is tearing down shp */
89062 @@ -1131,6 +1157,9 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
89063 path = shp->shm_file->f_path;
89064 path_get(&path);
89065 shp->shm_nattch++;
89066 +#ifdef CONFIG_GRKERNSEC
89067 + shp->shm_lapid = current->pid;
89068 +#endif
89069 size = i_size_read(path.dentry->d_inode);
89070 ipc_unlock_object(&shp->shm_perm);
89071 rcu_read_unlock();
89072 diff --git a/ipc/util.c b/ipc/util.c
89073 index 27d74e6..8be0be2 100644
89074 --- a/ipc/util.c
89075 +++ b/ipc/util.c
89076 @@ -71,6 +71,8 @@ struct ipc_proc_iface {
89077 int (*show)(struct seq_file *, void *);
89078 };
89079
89080 +extern int gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode);
89081 +
89082 static void ipc_memory_notifier(struct work_struct *work)
89083 {
89084 ipcns_notify(IPCNS_MEMCHANGED);
89085 @@ -537,6 +539,10 @@ int ipcperms(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, short flag)
89086 granted_mode >>= 6;
89087 else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid))
89088 granted_mode >>= 3;
89089 +
89090 + if (!gr_ipc_permitted(ns, ipcp, requested_mode, granted_mode))
89091 + return -1;
89092 +
89093 /* is there some bit set in requested_mode but not in granted_mode? */
89094 if ((requested_mode & ~granted_mode & 0007) &&
89095 !ns_capable(ns->user_ns, CAP_IPC_OWNER))
89096 diff --git a/kernel/audit.c b/kernel/audit.c
89097 index 6726aa6..bb864a9 100644
89098 --- a/kernel/audit.c
89099 +++ b/kernel/audit.c
89100 @@ -122,7 +122,7 @@ u32 audit_sig_sid = 0;
89101 3) suppressed due to audit_rate_limit
89102 4) suppressed due to audit_backlog_limit
89103 */
89104 -static atomic_t audit_lost = ATOMIC_INIT(0);
89105 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
89106
89107 /* The netlink socket. */
89108 static struct sock *audit_sock;
89109 @@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
89110 unsigned long now;
89111 int print;
89112
89113 - atomic_inc(&audit_lost);
89114 + atomic_inc_unchecked(&audit_lost);
89115
89116 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
89117
89118 @@ -273,7 +273,7 @@ void audit_log_lost(const char *message)
89119 if (print) {
89120 if (printk_ratelimit())
89121 pr_warn("audit_lost=%u audit_rate_limit=%u audit_backlog_limit=%u\n",
89122 - atomic_read(&audit_lost),
89123 + atomic_read_unchecked(&audit_lost),
89124 audit_rate_limit,
89125 audit_backlog_limit);
89126 audit_panic(message);
89127 @@ -840,7 +840,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
89128 s.pid = audit_pid;
89129 s.rate_limit = audit_rate_limit;
89130 s.backlog_limit = audit_backlog_limit;
89131 - s.lost = atomic_read(&audit_lost);
89132 + s.lost = atomic_read_unchecked(&audit_lost);
89133 s.backlog = skb_queue_len(&audit_skb_queue);
89134 s.version = AUDIT_VERSION_LATEST;
89135 s.backlog_wait_time = audit_backlog_wait_time;
89136 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
89137 index 21eae3c..66db239 100644
89138 --- a/kernel/auditsc.c
89139 +++ b/kernel/auditsc.c
89140 @@ -2023,7 +2023,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
89141 }
89142
89143 /* global counter which is incremented every time something logs in */
89144 -static atomic_t session_id = ATOMIC_INIT(0);
89145 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
89146
89147 static int audit_set_loginuid_perm(kuid_t loginuid)
89148 {
89149 @@ -2090,7 +2090,7 @@ int audit_set_loginuid(kuid_t loginuid)
89150
89151 /* are we setting or clearing? */
89152 if (uid_valid(loginuid))
89153 - sessionid = (unsigned int)atomic_inc_return(&session_id);
89154 + sessionid = (unsigned int)atomic_inc_return_unchecked(&session_id);
89155
89156 task->sessionid = sessionid;
89157 task->loginuid = loginuid;
89158 diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
89159 index 7f0dbcb..b54bb2c 100644
89160 --- a/kernel/bpf/core.c
89161 +++ b/kernel/bpf/core.c
89162 @@ -22,6 +22,7 @@
89163 */
89164 #include <linux/filter.h>
89165 #include <linux/skbuff.h>
89166 +#include <linux/vmalloc.h>
89167 #include <asm/unaligned.h>
89168
89169 /* Registers */
89170 @@ -63,6 +64,67 @@ void *bpf_internal_load_pointer_neg_helper(const struct sk_buff *skb, int k, uns
89171 return NULL;
89172 }
89173
89174 +struct bpf_prog *bpf_prog_alloc(unsigned int size, gfp_t gfp_extra_flags)
89175 +{
89176 + gfp_t gfp_flags = GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO |
89177 + gfp_extra_flags;
89178 + struct bpf_work_struct *ws;
89179 + struct bpf_prog *fp;
89180 +
89181 + size = round_up(size, PAGE_SIZE);
89182 + fp = __vmalloc(size, gfp_flags, PAGE_KERNEL);
89183 + if (fp == NULL)
89184 + return NULL;
89185 +
89186 + ws = kmalloc(sizeof(*ws), GFP_KERNEL | gfp_extra_flags);
89187 + if (ws == NULL) {
89188 + vfree(fp);
89189 + return NULL;
89190 + }
89191 +
89192 + fp->pages = size / PAGE_SIZE;
89193 + fp->work = ws;
89194 +
89195 + return fp;
89196 +}
89197 +EXPORT_SYMBOL_GPL(bpf_prog_alloc);
89198 +
89199 +struct bpf_prog *bpf_prog_realloc(struct bpf_prog *fp_old, unsigned int size,
89200 + gfp_t gfp_extra_flags)
89201 +{
89202 + gfp_t gfp_flags = GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO |
89203 + gfp_extra_flags;
89204 + struct bpf_prog *fp;
89205 +
89206 + BUG_ON(fp_old == NULL);
89207 +
89208 + size = round_up(size, PAGE_SIZE);
89209 + if (size <= fp_old->pages * PAGE_SIZE)
89210 + return fp_old;
89211 +
89212 + fp = __vmalloc(size, gfp_flags, PAGE_KERNEL);
89213 + if (fp != NULL) {
89214 + memcpy(fp, fp_old, fp_old->pages * PAGE_SIZE);
89215 + fp->pages = size / PAGE_SIZE;
89216 +
89217 + /* We keep fp->work from fp_old around in the new
89218 + * reallocated structure.
89219 + */
89220 + fp_old->work = NULL;
89221 + __bpf_prog_free(fp_old);
89222 + }
89223 +
89224 + return fp;
89225 +}
89226 +EXPORT_SYMBOL_GPL(bpf_prog_realloc);
89227 +
89228 +void __bpf_prog_free(struct bpf_prog *fp)
89229 +{
89230 + kfree(fp->work);
89231 + vfree(fp);
89232 +}
89233 +EXPORT_SYMBOL_GPL(__bpf_prog_free);
89234 +
89235 /* Base function for offset calculation. Needs to go into .text section,
89236 * therefore keeping it non-static as well; will also be used by JITs
89237 * anyway later on, so do not let the compiler omit it.
89238 @@ -523,12 +585,26 @@ void bpf_prog_select_runtime(struct bpf_prog *fp)
89239
89240 /* Probe if internal BPF can be JITed */
89241 bpf_int_jit_compile(fp);
89242 + /* Lock whole bpf_prog as read-only */
89243 + bpf_prog_lock_ro(fp);
89244 }
89245 EXPORT_SYMBOL_GPL(bpf_prog_select_runtime);
89246
89247 -/* free internal BPF program */
89248 +static void bpf_prog_free_deferred(struct work_struct *work)
89249 +{
89250 + struct bpf_work_struct *ws;
89251 +
89252 + ws = container_of(work, struct bpf_work_struct, work);
89253 + bpf_jit_free(ws->prog);
89254 +}
89255 +
89256 +/* Free internal BPF program */
89257 void bpf_prog_free(struct bpf_prog *fp)
89258 {
89259 - bpf_jit_free(fp);
89260 + struct bpf_work_struct *ws = fp->work;
89261 +
89262 + INIT_WORK(&ws->work, bpf_prog_free_deferred);
89263 + ws->prog = fp;
89264 + schedule_work(&ws->work);
89265 }
89266 EXPORT_SYMBOL_GPL(bpf_prog_free);
89267 diff --git a/kernel/capability.c b/kernel/capability.c
89268 index 989f5bf..d317ca0 100644
89269 --- a/kernel/capability.c
89270 +++ b/kernel/capability.c
89271 @@ -192,6 +192,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
89272 * before modification is attempted and the application
89273 * fails.
89274 */
89275 + if (tocopy > ARRAY_SIZE(kdata))
89276 + return -EFAULT;
89277 +
89278 if (copy_to_user(dataptr, kdata, tocopy
89279 * sizeof(struct __user_cap_data_struct))) {
89280 return -EFAULT;
89281 @@ -297,10 +300,11 @@ bool has_ns_capability(struct task_struct *t,
89282 int ret;
89283
89284 rcu_read_lock();
89285 - ret = security_capable(__task_cred(t), ns, cap);
89286 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
89287 + gr_task_is_capable(t, __task_cred(t), cap);
89288 rcu_read_unlock();
89289
89290 - return (ret == 0);
89291 + return ret;
89292 }
89293
89294 /**
89295 @@ -337,10 +341,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
89296 int ret;
89297
89298 rcu_read_lock();
89299 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
89300 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
89301 rcu_read_unlock();
89302
89303 - return (ret == 0);
89304 + return ret;
89305 }
89306
89307 /**
89308 @@ -378,7 +382,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
89309 BUG();
89310 }
89311
89312 - if (security_capable(current_cred(), ns, cap) == 0) {
89313 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
89314 current->flags |= PF_SUPERPRIV;
89315 return true;
89316 }
89317 @@ -386,6 +390,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
89318 }
89319 EXPORT_SYMBOL(ns_capable);
89320
89321 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
89322 +{
89323 + if (unlikely(!cap_valid(cap))) {
89324 + printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
89325 + BUG();
89326 + }
89327 +
89328 + if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
89329 + current->flags |= PF_SUPERPRIV;
89330 + return true;
89331 + }
89332 + return false;
89333 +}
89334 +EXPORT_SYMBOL(ns_capable_nolog);
89335 +
89336 /**
89337 * file_ns_capable - Determine if the file's opener had a capability in effect
89338 * @file: The file we want to check
89339 @@ -427,6 +446,12 @@ bool capable(int cap)
89340 }
89341 EXPORT_SYMBOL(capable);
89342
89343 +bool capable_nolog(int cap)
89344 +{
89345 + return ns_capable_nolog(&init_user_ns, cap);
89346 +}
89347 +EXPORT_SYMBOL(capable_nolog);
89348 +
89349 /**
89350 * capable_wrt_inode_uidgid - Check nsown_capable and uid and gid mapped
89351 * @inode: The inode in question
89352 @@ -444,3 +469,12 @@ bool capable_wrt_inode_uidgid(const struct inode *inode, int cap)
89353 kgid_has_mapping(ns, inode->i_gid);
89354 }
89355 EXPORT_SYMBOL(capable_wrt_inode_uidgid);
89356 +
89357 +bool capable_wrt_inode_uidgid_nolog(const struct inode *inode, int cap)
89358 +{
89359 + struct user_namespace *ns = current_user_ns();
89360 +
89361 + return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid) &&
89362 + kgid_has_mapping(ns, inode->i_gid);
89363 +}
89364 +EXPORT_SYMBOL(capable_wrt_inode_uidgid_nolog);
89365 diff --git a/kernel/cgroup.c b/kernel/cgroup.c
89366 index 3a73f99..4f29fea 100644
89367 --- a/kernel/cgroup.c
89368 +++ b/kernel/cgroup.c
89369 @@ -5341,6 +5341,14 @@ static void cgroup_release_agent(struct work_struct *work)
89370 release_list);
89371 list_del_init(&cgrp->release_list);
89372 raw_spin_unlock(&release_list_lock);
89373 +
89374 + /*
89375 + * don't bother calling call_usermodehelper if we haven't
89376 + * configured a binary to execute
89377 + */
89378 + if (cgrp->root->release_agent_path[0] == '\0')
89379 + goto continue_free;
89380 +
89381 pathbuf = kmalloc(PATH_MAX, GFP_KERNEL);
89382 if (!pathbuf)
89383 goto continue_free;
89384 @@ -5539,7 +5547,7 @@ static int cgroup_css_links_read(struct seq_file *seq, void *v)
89385 struct task_struct *task;
89386 int count = 0;
89387
89388 - seq_printf(seq, "css_set %p\n", cset);
89389 + seq_printf(seq, "css_set %pK\n", cset);
89390
89391 list_for_each_entry(task, &cset->tasks, cg_list) {
89392 if (count++ > MAX_TASKS_SHOWN_PER_CSS)
89393 diff --git a/kernel/compat.c b/kernel/compat.c
89394 index ebb3c36..1df606e 100644
89395 --- a/kernel/compat.c
89396 +++ b/kernel/compat.c
89397 @@ -13,6 +13,7 @@
89398
89399 #include <linux/linkage.h>
89400 #include <linux/compat.h>
89401 +#include <linux/module.h>
89402 #include <linux/errno.h>
89403 #include <linux/time.h>
89404 #include <linux/signal.h>
89405 @@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
89406 mm_segment_t oldfs;
89407 long ret;
89408
89409 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
89410 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
89411 oldfs = get_fs();
89412 set_fs(KERNEL_DS);
89413 ret = hrtimer_nanosleep_restart(restart);
89414 @@ -252,7 +253,7 @@ COMPAT_SYSCALL_DEFINE2(nanosleep, struct compat_timespec __user *, rqtp,
89415 oldfs = get_fs();
89416 set_fs(KERNEL_DS);
89417 ret = hrtimer_nanosleep(&tu,
89418 - rmtp ? (struct timespec __user *)&rmt : NULL,
89419 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
89420 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
89421 set_fs(oldfs);
89422
89423 @@ -379,7 +380,7 @@ COMPAT_SYSCALL_DEFINE1(sigpending, compat_old_sigset_t __user *, set)
89424 mm_segment_t old_fs = get_fs();
89425
89426 set_fs(KERNEL_DS);
89427 - ret = sys_sigpending((old_sigset_t __user *) &s);
89428 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
89429 set_fs(old_fs);
89430 if (ret == 0)
89431 ret = put_user(s, set);
89432 @@ -469,7 +470,7 @@ COMPAT_SYSCALL_DEFINE2(old_getrlimit, unsigned int, resource,
89433 mm_segment_t old_fs = get_fs();
89434
89435 set_fs(KERNEL_DS);
89436 - ret = sys_old_getrlimit(resource, (struct rlimit __user *)&r);
89437 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
89438 set_fs(old_fs);
89439
89440 if (!ret) {
89441 @@ -551,8 +552,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
89442 set_fs (KERNEL_DS);
89443 ret = sys_wait4(pid,
89444 (stat_addr ?
89445 - (unsigned int __user *) &status : NULL),
89446 - options, (struct rusage __user *) &r);
89447 + (unsigned int __force_user *) &status : NULL),
89448 + options, (struct rusage __force_user *) &r);
89449 set_fs (old_fs);
89450
89451 if (ret > 0) {
89452 @@ -578,8 +579,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
89453 memset(&info, 0, sizeof(info));
89454
89455 set_fs(KERNEL_DS);
89456 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
89457 - uru ? (struct rusage __user *)&ru : NULL);
89458 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
89459 + uru ? (struct rusage __force_user *)&ru : NULL);
89460 set_fs(old_fs);
89461
89462 if ((ret < 0) || (info.si_signo == 0))
89463 @@ -713,8 +714,8 @@ COMPAT_SYSCALL_DEFINE4(timer_settime, timer_t, timer_id, int, flags,
89464 oldfs = get_fs();
89465 set_fs(KERNEL_DS);
89466 err = sys_timer_settime(timer_id, flags,
89467 - (struct itimerspec __user *) &newts,
89468 - (struct itimerspec __user *) &oldts);
89469 + (struct itimerspec __force_user *) &newts,
89470 + (struct itimerspec __force_user *) &oldts);
89471 set_fs(oldfs);
89472 if (!err && old && put_compat_itimerspec(old, &oldts))
89473 return -EFAULT;
89474 @@ -731,7 +732,7 @@ COMPAT_SYSCALL_DEFINE2(timer_gettime, timer_t, timer_id,
89475 oldfs = get_fs();
89476 set_fs(KERNEL_DS);
89477 err = sys_timer_gettime(timer_id,
89478 - (struct itimerspec __user *) &ts);
89479 + (struct itimerspec __force_user *) &ts);
89480 set_fs(oldfs);
89481 if (!err && put_compat_itimerspec(setting, &ts))
89482 return -EFAULT;
89483 @@ -750,7 +751,7 @@ COMPAT_SYSCALL_DEFINE2(clock_settime, clockid_t, which_clock,
89484 oldfs = get_fs();
89485 set_fs(KERNEL_DS);
89486 err = sys_clock_settime(which_clock,
89487 - (struct timespec __user *) &ts);
89488 + (struct timespec __force_user *) &ts);
89489 set_fs(oldfs);
89490 return err;
89491 }
89492 @@ -765,7 +766,7 @@ COMPAT_SYSCALL_DEFINE2(clock_gettime, clockid_t, which_clock,
89493 oldfs = get_fs();
89494 set_fs(KERNEL_DS);
89495 err = sys_clock_gettime(which_clock,
89496 - (struct timespec __user *) &ts);
89497 + (struct timespec __force_user *) &ts);
89498 set_fs(oldfs);
89499 if (!err && compat_put_timespec(&ts, tp))
89500 return -EFAULT;
89501 @@ -785,7 +786,7 @@ COMPAT_SYSCALL_DEFINE2(clock_adjtime, clockid_t, which_clock,
89502
89503 oldfs = get_fs();
89504 set_fs(KERNEL_DS);
89505 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
89506 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
89507 set_fs(oldfs);
89508
89509 err = compat_put_timex(utp, &txc);
89510 @@ -805,7 +806,7 @@ COMPAT_SYSCALL_DEFINE2(clock_getres, clockid_t, which_clock,
89511 oldfs = get_fs();
89512 set_fs(KERNEL_DS);
89513 err = sys_clock_getres(which_clock,
89514 - (struct timespec __user *) &ts);
89515 + (struct timespec __force_user *) &ts);
89516 set_fs(oldfs);
89517 if (!err && tp && compat_put_timespec(&ts, tp))
89518 return -EFAULT;
89519 @@ -819,7 +820,7 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
89520 struct timespec tu;
89521 struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
89522
89523 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
89524 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
89525 oldfs = get_fs();
89526 set_fs(KERNEL_DS);
89527 err = clock_nanosleep_restart(restart);
89528 @@ -851,8 +852,8 @@ COMPAT_SYSCALL_DEFINE4(clock_nanosleep, clockid_t, which_clock, int, flags,
89529 oldfs = get_fs();
89530 set_fs(KERNEL_DS);
89531 err = sys_clock_nanosleep(which_clock, flags,
89532 - (struct timespec __user *) &in,
89533 - (struct timespec __user *) &out);
89534 + (struct timespec __force_user *) &in,
89535 + (struct timespec __force_user *) &out);
89536 set_fs(oldfs);
89537
89538 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
89539 @@ -1146,7 +1147,7 @@ COMPAT_SYSCALL_DEFINE2(sched_rr_get_interval,
89540 mm_segment_t old_fs = get_fs();
89541
89542 set_fs(KERNEL_DS);
89543 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
89544 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
89545 set_fs(old_fs);
89546 if (compat_put_timespec(&t, interval))
89547 return -EFAULT;
89548 diff --git a/kernel/configs.c b/kernel/configs.c
89549 index c18b1f1..b9a0132 100644
89550 --- a/kernel/configs.c
89551 +++ b/kernel/configs.c
89552 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
89553 struct proc_dir_entry *entry;
89554
89555 /* create the current config file */
89556 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
89557 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
89558 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
89559 + &ikconfig_file_ops);
89560 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
89561 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
89562 + &ikconfig_file_ops);
89563 +#endif
89564 +#else
89565 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
89566 &ikconfig_file_ops);
89567 +#endif
89568 +
89569 if (!entry)
89570 return -ENOMEM;
89571
89572 diff --git a/kernel/cred.c b/kernel/cred.c
89573 index e0573a4..26c0fd3 100644
89574 --- a/kernel/cred.c
89575 +++ b/kernel/cred.c
89576 @@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
89577 validate_creds(cred);
89578 alter_cred_subscribers(cred, -1);
89579 put_cred(cred);
89580 +
89581 +#ifdef CONFIG_GRKERNSEC_SETXID
89582 + cred = (struct cred *) tsk->delayed_cred;
89583 + if (cred != NULL) {
89584 + tsk->delayed_cred = NULL;
89585 + validate_creds(cred);
89586 + alter_cred_subscribers(cred, -1);
89587 + put_cred(cred);
89588 + }
89589 +#endif
89590 }
89591
89592 /**
89593 @@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
89594 * Always returns 0 thus allowing this function to be tail-called at the end
89595 * of, say, sys_setgid().
89596 */
89597 -int commit_creds(struct cred *new)
89598 +static int __commit_creds(struct cred *new)
89599 {
89600 struct task_struct *task = current;
89601 const struct cred *old = task->real_cred;
89602 @@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
89603
89604 get_cred(new); /* we will require a ref for the subj creds too */
89605
89606 + gr_set_role_label(task, new->uid, new->gid);
89607 +
89608 /* dumpability changes */
89609 if (!uid_eq(old->euid, new->euid) ||
89610 !gid_eq(old->egid, new->egid) ||
89611 @@ -479,6 +491,105 @@ int commit_creds(struct cred *new)
89612 put_cred(old);
89613 return 0;
89614 }
89615 +#ifdef CONFIG_GRKERNSEC_SETXID
89616 +extern int set_user(struct cred *new);
89617 +
89618 +void gr_delayed_cred_worker(void)
89619 +{
89620 + const struct cred *new = current->delayed_cred;
89621 + struct cred *ncred;
89622 +
89623 + current->delayed_cred = NULL;
89624 +
89625 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
89626 + // from doing get_cred on it when queueing this
89627 + put_cred(new);
89628 + return;
89629 + } else if (new == NULL)
89630 + return;
89631 +
89632 + ncred = prepare_creds();
89633 + if (!ncred)
89634 + goto die;
89635 + // uids
89636 + ncred->uid = new->uid;
89637 + ncred->euid = new->euid;
89638 + ncred->suid = new->suid;
89639 + ncred->fsuid = new->fsuid;
89640 + // gids
89641 + ncred->gid = new->gid;
89642 + ncred->egid = new->egid;
89643 + ncred->sgid = new->sgid;
89644 + ncred->fsgid = new->fsgid;
89645 + // groups
89646 + set_groups(ncred, new->group_info);
89647 + // caps
89648 + ncred->securebits = new->securebits;
89649 + ncred->cap_inheritable = new->cap_inheritable;
89650 + ncred->cap_permitted = new->cap_permitted;
89651 + ncred->cap_effective = new->cap_effective;
89652 + ncred->cap_bset = new->cap_bset;
89653 +
89654 + if (set_user(ncred)) {
89655 + abort_creds(ncred);
89656 + goto die;
89657 + }
89658 +
89659 + // from doing get_cred on it when queueing this
89660 + put_cred(new);
89661 +
89662 + __commit_creds(ncred);
89663 + return;
89664 +die:
89665 + // from doing get_cred on it when queueing this
89666 + put_cred(new);
89667 + do_group_exit(SIGKILL);
89668 +}
89669 +#endif
89670 +
89671 +int commit_creds(struct cred *new)
89672 +{
89673 +#ifdef CONFIG_GRKERNSEC_SETXID
89674 + int ret;
89675 + int schedule_it = 0;
89676 + struct task_struct *t;
89677 + unsigned oldsecurebits = current_cred()->securebits;
89678 +
89679 + /* we won't get called with tasklist_lock held for writing
89680 + and interrupts disabled as the cred struct in that case is
89681 + init_cred
89682 + */
89683 + if (grsec_enable_setxid && !current_is_single_threaded() &&
89684 + uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
89685 + !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
89686 + schedule_it = 1;
89687 + }
89688 + ret = __commit_creds(new);
89689 + if (schedule_it) {
89690 + rcu_read_lock();
89691 + read_lock(&tasklist_lock);
89692 + for (t = next_thread(current); t != current;
89693 + t = next_thread(t)) {
89694 + /* we'll check if the thread has uid 0 in
89695 + * the delayed worker routine
89696 + */
89697 + if (task_securebits(t) == oldsecurebits &&
89698 + t->delayed_cred == NULL) {
89699 + t->delayed_cred = get_cred(new);
89700 + set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
89701 + set_tsk_need_resched(t);
89702 + }
89703 + }
89704 + read_unlock(&tasklist_lock);
89705 + rcu_read_unlock();
89706 + }
89707 +
89708 + return ret;
89709 +#else
89710 + return __commit_creds(new);
89711 +#endif
89712 +}
89713 +
89714 EXPORT_SYMBOL(commit_creds);
89715
89716 /**
89717 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
89718 index 1adf62b..7736e06 100644
89719 --- a/kernel/debug/debug_core.c
89720 +++ b/kernel/debug/debug_core.c
89721 @@ -124,7 +124,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
89722 */
89723 static atomic_t masters_in_kgdb;
89724 static atomic_t slaves_in_kgdb;
89725 -static atomic_t kgdb_break_tasklet_var;
89726 +static atomic_unchecked_t kgdb_break_tasklet_var;
89727 atomic_t kgdb_setting_breakpoint;
89728
89729 struct task_struct *kgdb_usethread;
89730 @@ -134,7 +134,7 @@ int kgdb_single_step;
89731 static pid_t kgdb_sstep_pid;
89732
89733 /* to keep track of the CPU which is doing the single stepping*/
89734 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
89735 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
89736
89737 /*
89738 * If you are debugging a problem where roundup (the collection of
89739 @@ -549,7 +549,7 @@ return_normal:
89740 * kernel will only try for the value of sstep_tries before
89741 * giving up and continuing on.
89742 */
89743 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
89744 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
89745 (kgdb_info[cpu].task &&
89746 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
89747 atomic_set(&kgdb_active, -1);
89748 @@ -647,8 +647,8 @@ cpu_master_loop:
89749 }
89750
89751 kgdb_restore:
89752 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
89753 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
89754 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
89755 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
89756 if (kgdb_info[sstep_cpu].task)
89757 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
89758 else
89759 @@ -925,18 +925,18 @@ static void kgdb_unregister_callbacks(void)
89760 static void kgdb_tasklet_bpt(unsigned long ing)
89761 {
89762 kgdb_breakpoint();
89763 - atomic_set(&kgdb_break_tasklet_var, 0);
89764 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
89765 }
89766
89767 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
89768
89769 void kgdb_schedule_breakpoint(void)
89770 {
89771 - if (atomic_read(&kgdb_break_tasklet_var) ||
89772 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
89773 atomic_read(&kgdb_active) != -1 ||
89774 atomic_read(&kgdb_setting_breakpoint))
89775 return;
89776 - atomic_inc(&kgdb_break_tasklet_var);
89777 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
89778 tasklet_schedule(&kgdb_tasklet_breakpoint);
89779 }
89780 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
89781 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
89782 index 379650b..30c5180 100644
89783 --- a/kernel/debug/kdb/kdb_main.c
89784 +++ b/kernel/debug/kdb/kdb_main.c
89785 @@ -1977,7 +1977,7 @@ static int kdb_lsmod(int argc, const char **argv)
89786 continue;
89787
89788 kdb_printf("%-20s%8u 0x%p ", mod->name,
89789 - mod->core_size, (void *)mod);
89790 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
89791 #ifdef CONFIG_MODULE_UNLOAD
89792 kdb_printf("%4ld ", module_refcount(mod));
89793 #endif
89794 @@ -1987,7 +1987,7 @@ static int kdb_lsmod(int argc, const char **argv)
89795 kdb_printf(" (Loading)");
89796 else
89797 kdb_printf(" (Live)");
89798 - kdb_printf(" 0x%p", mod->module_core);
89799 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
89800
89801 #ifdef CONFIG_MODULE_UNLOAD
89802 {
89803 diff --git a/kernel/events/core.c b/kernel/events/core.c
89804 index 658f232..32e9595 100644
89805 --- a/kernel/events/core.c
89806 +++ b/kernel/events/core.c
89807 @@ -161,8 +161,15 @@ static struct srcu_struct pmus_srcu;
89808 * 0 - disallow raw tracepoint access for unpriv
89809 * 1 - disallow cpu events for unpriv
89810 * 2 - disallow kernel profiling for unpriv
89811 + * 3 - disallow all unpriv perf event use
89812 */
89813 -int sysctl_perf_event_paranoid __read_mostly = 1;
89814 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
89815 +int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
89816 +#elif defined(CONFIG_GRKERNSEC_HIDESYM)
89817 +int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
89818 +#else
89819 +int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
89820 +#endif
89821
89822 /* Minimum for 512 kiB + 1 user control page */
89823 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
89824 @@ -188,7 +195,7 @@ void update_perf_cpu_limits(void)
89825
89826 tmp *= sysctl_perf_cpu_time_max_percent;
89827 do_div(tmp, 100);
89828 - ACCESS_ONCE(perf_sample_allowed_ns) = tmp;
89829 + ACCESS_ONCE_RW(perf_sample_allowed_ns) = tmp;
89830 }
89831
89832 static int perf_rotate_context(struct perf_cpu_context *cpuctx);
89833 @@ -294,7 +301,7 @@ void perf_sample_event_took(u64 sample_len_ns)
89834 }
89835 }
89836
89837 -static atomic64_t perf_event_id;
89838 +static atomic64_unchecked_t perf_event_id;
89839
89840 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
89841 enum event_type_t event_type);
89842 @@ -3051,7 +3058,7 @@ static void __perf_event_read(void *info)
89843
89844 static inline u64 perf_event_count(struct perf_event *event)
89845 {
89846 - return local64_read(&event->count) + atomic64_read(&event->child_count);
89847 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
89848 }
89849
89850 static u64 perf_event_read(struct perf_event *event)
89851 @@ -3430,9 +3437,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
89852 mutex_lock(&event->child_mutex);
89853 total += perf_event_read(event);
89854 *enabled += event->total_time_enabled +
89855 - atomic64_read(&event->child_total_time_enabled);
89856 + atomic64_read_unchecked(&event->child_total_time_enabled);
89857 *running += event->total_time_running +
89858 - atomic64_read(&event->child_total_time_running);
89859 + atomic64_read_unchecked(&event->child_total_time_running);
89860
89861 list_for_each_entry(child, &event->child_list, child_list) {
89862 total += perf_event_read(child);
89863 @@ -3881,10 +3888,10 @@ void perf_event_update_userpage(struct perf_event *event)
89864 userpg->offset -= local64_read(&event->hw.prev_count);
89865
89866 userpg->time_enabled = enabled +
89867 - atomic64_read(&event->child_total_time_enabled);
89868 + atomic64_read_unchecked(&event->child_total_time_enabled);
89869
89870 userpg->time_running = running +
89871 - atomic64_read(&event->child_total_time_running);
89872 + atomic64_read_unchecked(&event->child_total_time_running);
89873
89874 arch_perf_update_userpage(userpg, now);
89875
89876 @@ -4448,7 +4455,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
89877
89878 /* Data. */
89879 sp = perf_user_stack_pointer(regs);
89880 - rem = __output_copy_user(handle, (void *) sp, dump_size);
89881 + rem = __output_copy_user(handle, (void __user *) sp, dump_size);
89882 dyn_size = dump_size - rem;
89883
89884 perf_output_skip(handle, rem);
89885 @@ -4539,11 +4546,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
89886 values[n++] = perf_event_count(event);
89887 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
89888 values[n++] = enabled +
89889 - atomic64_read(&event->child_total_time_enabled);
89890 + atomic64_read_unchecked(&event->child_total_time_enabled);
89891 }
89892 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
89893 values[n++] = running +
89894 - atomic64_read(&event->child_total_time_running);
89895 + atomic64_read_unchecked(&event->child_total_time_running);
89896 }
89897 if (read_format & PERF_FORMAT_ID)
89898 values[n++] = primary_event_id(event);
89899 @@ -6858,7 +6865,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
89900 event->parent = parent_event;
89901
89902 event->ns = get_pid_ns(task_active_pid_ns(current));
89903 - event->id = atomic64_inc_return(&perf_event_id);
89904 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
89905
89906 event->state = PERF_EVENT_STATE_INACTIVE;
89907
89908 @@ -7137,6 +7144,11 @@ SYSCALL_DEFINE5(perf_event_open,
89909 if (flags & ~PERF_FLAG_ALL)
89910 return -EINVAL;
89911
89912 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
89913 + if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
89914 + return -EACCES;
89915 +#endif
89916 +
89917 err = perf_copy_attr(attr_uptr, &attr);
89918 if (err)
89919 return err;
89920 @@ -7489,10 +7501,10 @@ static void sync_child_event(struct perf_event *child_event,
89921 /*
89922 * Add back the child's count to the parent's count:
89923 */
89924 - atomic64_add(child_val, &parent_event->child_count);
89925 - atomic64_add(child_event->total_time_enabled,
89926 + atomic64_add_unchecked(child_val, &parent_event->child_count);
89927 + atomic64_add_unchecked(child_event->total_time_enabled,
89928 &parent_event->child_total_time_enabled);
89929 - atomic64_add(child_event->total_time_running,
89930 + atomic64_add_unchecked(child_event->total_time_running,
89931 &parent_event->child_total_time_running);
89932
89933 /*
89934 diff --git a/kernel/events/internal.h b/kernel/events/internal.h
89935 index 569b2187..19940d9 100644
89936 --- a/kernel/events/internal.h
89937 +++ b/kernel/events/internal.h
89938 @@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
89939 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
89940 }
89941
89942 -#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
89943 +#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
89944 static inline unsigned long \
89945 func_name(struct perf_output_handle *handle, \
89946 - const void *buf, unsigned long len) \
89947 + const void user *buf, unsigned long len) \
89948 { \
89949 unsigned long size, written; \
89950 \
89951 @@ -117,7 +117,7 @@ memcpy_common(void *dst, const void *src, unsigned long n)
89952 return 0;
89953 }
89954
89955 -DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
89956 +DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
89957
89958 static inline unsigned long
89959 memcpy_skip(void *dst, const void *src, unsigned long n)
89960 @@ -125,7 +125,7 @@ memcpy_skip(void *dst, const void *src, unsigned long n)
89961 return 0;
89962 }
89963
89964 -DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip)
89965 +DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip, )
89966
89967 #ifndef arch_perf_out_copy_user
89968 #define arch_perf_out_copy_user arch_perf_out_copy_user
89969 @@ -143,7 +143,7 @@ arch_perf_out_copy_user(void *dst, const void *src, unsigned long n)
89970 }
89971 #endif
89972
89973 -DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
89974 +DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
89975
89976 /* Callchain handling */
89977 extern struct perf_callchain_entry *
89978 diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
89979 index ed8f2cd..fe8030c 100644
89980 --- a/kernel/events/uprobes.c
89981 +++ b/kernel/events/uprobes.c
89982 @@ -1670,7 +1670,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
89983 {
89984 struct page *page;
89985 uprobe_opcode_t opcode;
89986 - int result;
89987 + long result;
89988
89989 pagefault_disable();
89990 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
89991 diff --git a/kernel/exit.c b/kernel/exit.c
89992 index 32c58f7..9eb6907 100644
89993 --- a/kernel/exit.c
89994 +++ b/kernel/exit.c
89995 @@ -173,6 +173,10 @@ void release_task(struct task_struct *p)
89996 struct task_struct *leader;
89997 int zap_leader;
89998 repeat:
89999 +#ifdef CONFIG_NET
90000 + gr_del_task_from_ip_table(p);
90001 +#endif
90002 +
90003 /* don't need to get the RCU readlock here - the process is dead and
90004 * can't be modifying its own credentials. But shut RCU-lockdep up */
90005 rcu_read_lock();
90006 @@ -668,6 +672,8 @@ void do_exit(long code)
90007 struct task_struct *tsk = current;
90008 int group_dead;
90009
90010 + set_fs(USER_DS);
90011 +
90012 profile_task_exit(tsk);
90013
90014 WARN_ON(blk_needs_flush_plug(tsk));
90015 @@ -684,7 +690,6 @@ void do_exit(long code)
90016 * mm_release()->clear_child_tid() from writing to a user-controlled
90017 * kernel address.
90018 */
90019 - set_fs(USER_DS);
90020
90021 ptrace_event(PTRACE_EVENT_EXIT, code);
90022
90023 @@ -742,6 +747,9 @@ void do_exit(long code)
90024 tsk->exit_code = code;
90025 taskstats_exit(tsk, group_dead);
90026
90027 + gr_acl_handle_psacct(tsk, code);
90028 + gr_acl_handle_exit();
90029 +
90030 exit_mm(tsk);
90031
90032 if (group_dead)
90033 @@ -859,7 +867,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
90034 * Take down every thread in the group. This is called by fatal signals
90035 * as well as by sys_exit_group (below).
90036 */
90037 -void
90038 +__noreturn void
90039 do_group_exit(int exit_code)
90040 {
90041 struct signal_struct *sig = current->signal;
90042 diff --git a/kernel/fork.c b/kernel/fork.c
90043 index a91e47d..71c9064 100644
90044 --- a/kernel/fork.c
90045 +++ b/kernel/fork.c
90046 @@ -183,6 +183,48 @@ void thread_info_cache_init(void)
90047 # endif
90048 #endif
90049
90050 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
90051 +static inline struct thread_info *gr_alloc_thread_info_node(struct task_struct *tsk,
90052 + int node, void **lowmem_stack)
90053 +{
90054 + struct page *pages[THREAD_SIZE / PAGE_SIZE];
90055 + void *ret = NULL;
90056 + unsigned int i;
90057 +
90058 + *lowmem_stack = alloc_thread_info_node(tsk, node);
90059 + if (*lowmem_stack == NULL)
90060 + goto out;
90061 +
90062 + for (i = 0; i < THREAD_SIZE / PAGE_SIZE; i++)
90063 + pages[i] = virt_to_page(*lowmem_stack + (i * PAGE_SIZE));
90064 +
90065 + /* use VM_IOREMAP to gain THREAD_SIZE alignment */
90066 + ret = vmap(pages, THREAD_SIZE / PAGE_SIZE, VM_IOREMAP, PAGE_KERNEL);
90067 + if (ret == NULL) {
90068 + free_thread_info(*lowmem_stack);
90069 + *lowmem_stack = NULL;
90070 + }
90071 +
90072 +out:
90073 + return ret;
90074 +}
90075 +
90076 +static inline void gr_free_thread_info(struct task_struct *tsk, struct thread_info *ti)
90077 +{
90078 + unmap_process_stacks(tsk);
90079 +}
90080 +#else
90081 +static inline struct thread_info *gr_alloc_thread_info_node(struct task_struct *tsk,
90082 + int node, void **lowmem_stack)
90083 +{
90084 + return alloc_thread_info_node(tsk, node);
90085 +}
90086 +static inline void gr_free_thread_info(struct task_struct *tsk, struct thread_info *ti)
90087 +{
90088 + free_thread_info(ti);
90089 +}
90090 +#endif
90091 +
90092 /* SLAB cache for signal_struct structures (tsk->signal) */
90093 static struct kmem_cache *signal_cachep;
90094
90095 @@ -201,18 +243,22 @@ struct kmem_cache *vm_area_cachep;
90096 /* SLAB cache for mm_struct structures (tsk->mm) */
90097 static struct kmem_cache *mm_cachep;
90098
90099 -static void account_kernel_stack(struct thread_info *ti, int account)
90100 +static void account_kernel_stack(struct task_struct *tsk, struct thread_info *ti, int account)
90101 {
90102 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
90103 + struct zone *zone = page_zone(virt_to_page(tsk->lowmem_stack));
90104 +#else
90105 struct zone *zone = page_zone(virt_to_page(ti));
90106 +#endif
90107
90108 mod_zone_page_state(zone, NR_KERNEL_STACK, account);
90109 }
90110
90111 void free_task(struct task_struct *tsk)
90112 {
90113 - account_kernel_stack(tsk->stack, -1);
90114 + account_kernel_stack(tsk, tsk->stack, -1);
90115 arch_release_thread_info(tsk->stack);
90116 - free_thread_info(tsk->stack);
90117 + gr_free_thread_info(tsk, tsk->stack);
90118 rt_mutex_debug_task_free(tsk);
90119 ftrace_graph_exit_task(tsk);
90120 put_seccomp_filter(tsk);
90121 @@ -299,6 +345,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
90122 struct task_struct *tsk;
90123 struct thread_info *ti;
90124 unsigned long *stackend;
90125 + void *lowmem_stack;
90126 int node = tsk_fork_get_node(orig);
90127 int err;
90128
90129 @@ -306,7 +353,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
90130 if (!tsk)
90131 return NULL;
90132
90133 - ti = alloc_thread_info_node(tsk, node);
90134 + ti = gr_alloc_thread_info_node(tsk, node, &lowmem_stack);
90135 if (!ti)
90136 goto free_tsk;
90137
90138 @@ -315,6 +362,9 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
90139 goto free_ti;
90140
90141 tsk->stack = ti;
90142 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
90143 + tsk->lowmem_stack = lowmem_stack;
90144 +#endif
90145 #ifdef CONFIG_SECCOMP
90146 /*
90147 * We must handle setting up seccomp filters once we're under
90148 @@ -332,7 +382,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
90149 *stackend = STACK_END_MAGIC; /* for overflow detection */
90150
90151 #ifdef CONFIG_CC_STACKPROTECTOR
90152 - tsk->stack_canary = get_random_int();
90153 + tsk->stack_canary = pax_get_random_long();
90154 #endif
90155
90156 /*
90157 @@ -346,24 +396,92 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
90158 tsk->splice_pipe = NULL;
90159 tsk->task_frag.page = NULL;
90160
90161 - account_kernel_stack(ti, 1);
90162 + account_kernel_stack(tsk, ti, 1);
90163
90164 return tsk;
90165
90166 free_ti:
90167 - free_thread_info(ti);
90168 + gr_free_thread_info(tsk, ti);
90169 free_tsk:
90170 free_task_struct(tsk);
90171 return NULL;
90172 }
90173
90174 #ifdef CONFIG_MMU
90175 -static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
90176 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
90177 +{
90178 + struct vm_area_struct *tmp;
90179 + unsigned long charge;
90180 + struct file *file;
90181 + int retval;
90182 +
90183 + charge = 0;
90184 + if (mpnt->vm_flags & VM_ACCOUNT) {
90185 + unsigned long len = vma_pages(mpnt);
90186 +
90187 + if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
90188 + goto fail_nomem;
90189 + charge = len;
90190 + }
90191 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
90192 + if (!tmp)
90193 + goto fail_nomem;
90194 + *tmp = *mpnt;
90195 + tmp->vm_mm = mm;
90196 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
90197 + retval = vma_dup_policy(mpnt, tmp);
90198 + if (retval)
90199 + goto fail_nomem_policy;
90200 + if (anon_vma_fork(tmp, mpnt))
90201 + goto fail_nomem_anon_vma_fork;
90202 + tmp->vm_flags &= ~VM_LOCKED;
90203 + tmp->vm_next = tmp->vm_prev = NULL;
90204 + tmp->vm_mirror = NULL;
90205 + file = tmp->vm_file;
90206 + if (file) {
90207 + struct inode *inode = file_inode(file);
90208 + struct address_space *mapping = file->f_mapping;
90209 +
90210 + get_file(file);
90211 + if (tmp->vm_flags & VM_DENYWRITE)
90212 + atomic_dec(&inode->i_writecount);
90213 + mutex_lock(&mapping->i_mmap_mutex);
90214 + if (tmp->vm_flags & VM_SHARED)
90215 + atomic_inc(&mapping->i_mmap_writable);
90216 + flush_dcache_mmap_lock(mapping);
90217 + /* insert tmp into the share list, just after mpnt */
90218 + if (unlikely(tmp->vm_flags & VM_NONLINEAR))
90219 + vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
90220 + else
90221 + vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
90222 + flush_dcache_mmap_unlock(mapping);
90223 + mutex_unlock(&mapping->i_mmap_mutex);
90224 + }
90225 +
90226 + /*
90227 + * Clear hugetlb-related page reserves for children. This only
90228 + * affects MAP_PRIVATE mappings. Faults generated by the child
90229 + * are not guaranteed to succeed, even if read-only
90230 + */
90231 + if (is_vm_hugetlb_page(tmp))
90232 + reset_vma_resv_huge_pages(tmp);
90233 +
90234 + return tmp;
90235 +
90236 +fail_nomem_anon_vma_fork:
90237 + mpol_put(vma_policy(tmp));
90238 +fail_nomem_policy:
90239 + kmem_cache_free(vm_area_cachep, tmp);
90240 +fail_nomem:
90241 + vm_unacct_memory(charge);
90242 + return NULL;
90243 +}
90244 +
90245 +static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
90246 {
90247 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
90248 struct rb_node **rb_link, *rb_parent;
90249 int retval;
90250 - unsigned long charge;
90251
90252 uprobe_start_dup_mmap();
90253 down_write(&oldmm->mmap_sem);
90254 @@ -391,55 +509,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
90255
90256 prev = NULL;
90257 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
90258 - struct file *file;
90259 -
90260 if (mpnt->vm_flags & VM_DONTCOPY) {
90261 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
90262 -vma_pages(mpnt));
90263 continue;
90264 }
90265 - charge = 0;
90266 - if (mpnt->vm_flags & VM_ACCOUNT) {
90267 - unsigned long len = vma_pages(mpnt);
90268 -
90269 - if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
90270 - goto fail_nomem;
90271 - charge = len;
90272 - }
90273 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
90274 - if (!tmp)
90275 - goto fail_nomem;
90276 - *tmp = *mpnt;
90277 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
90278 - retval = vma_dup_policy(mpnt, tmp);
90279 - if (retval)
90280 - goto fail_nomem_policy;
90281 - tmp->vm_mm = mm;
90282 - if (anon_vma_fork(tmp, mpnt))
90283 - goto fail_nomem_anon_vma_fork;
90284 - tmp->vm_flags &= ~VM_LOCKED;
90285 - tmp->vm_next = tmp->vm_prev = NULL;
90286 - file = tmp->vm_file;
90287 - if (file) {
90288 - struct inode *inode = file_inode(file);
90289 - struct address_space *mapping = file->f_mapping;
90290 -
90291 - get_file(file);
90292 - if (tmp->vm_flags & VM_DENYWRITE)
90293 - atomic_dec(&inode->i_writecount);
90294 - mutex_lock(&mapping->i_mmap_mutex);
90295 - if (tmp->vm_flags & VM_SHARED)
90296 - atomic_inc(&mapping->i_mmap_writable);
90297 - flush_dcache_mmap_lock(mapping);
90298 - /* insert tmp into the share list, just after mpnt */
90299 - if (unlikely(tmp->vm_flags & VM_NONLINEAR))
90300 - vma_nonlinear_insert(tmp,
90301 - &mapping->i_mmap_nonlinear);
90302 - else
90303 - vma_interval_tree_insert_after(tmp, mpnt,
90304 - &mapping->i_mmap);
90305 - flush_dcache_mmap_unlock(mapping);
90306 - mutex_unlock(&mapping->i_mmap_mutex);
90307 + tmp = dup_vma(mm, oldmm, mpnt);
90308 + if (!tmp) {
90309 + retval = -ENOMEM;
90310 + goto out;
90311 }
90312
90313 /*
90314 @@ -471,6 +549,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
90315 if (retval)
90316 goto out;
90317 }
90318 +
90319 +#ifdef CONFIG_PAX_SEGMEXEC
90320 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
90321 + struct vm_area_struct *mpnt_m;
90322 +
90323 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
90324 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
90325 +
90326 + if (!mpnt->vm_mirror)
90327 + continue;
90328 +
90329 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
90330 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
90331 + mpnt->vm_mirror = mpnt_m;
90332 + } else {
90333 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
90334 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
90335 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
90336 + mpnt->vm_mirror->vm_mirror = mpnt;
90337 + }
90338 + }
90339 + BUG_ON(mpnt_m);
90340 + }
90341 +#endif
90342 +
90343 /* a new mm has just been created */
90344 arch_dup_mmap(oldmm, mm);
90345 retval = 0;
90346 @@ -480,14 +583,6 @@ out:
90347 up_write(&oldmm->mmap_sem);
90348 uprobe_end_dup_mmap();
90349 return retval;
90350 -fail_nomem_anon_vma_fork:
90351 - mpol_put(vma_policy(tmp));
90352 -fail_nomem_policy:
90353 - kmem_cache_free(vm_area_cachep, tmp);
90354 -fail_nomem:
90355 - retval = -ENOMEM;
90356 - vm_unacct_memory(charge);
90357 - goto out;
90358 }
90359
90360 static inline int mm_alloc_pgd(struct mm_struct *mm)
90361 @@ -729,8 +824,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
90362 return ERR_PTR(err);
90363
90364 mm = get_task_mm(task);
90365 - if (mm && mm != current->mm &&
90366 - !ptrace_may_access(task, mode)) {
90367 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
90368 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
90369 mmput(mm);
90370 mm = ERR_PTR(-EACCES);
90371 }
90372 @@ -933,13 +1028,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
90373 spin_unlock(&fs->lock);
90374 return -EAGAIN;
90375 }
90376 - fs->users++;
90377 + atomic_inc(&fs->users);
90378 spin_unlock(&fs->lock);
90379 return 0;
90380 }
90381 tsk->fs = copy_fs_struct(fs);
90382 if (!tsk->fs)
90383 return -ENOMEM;
90384 + /* Carry through gr_chroot_dentry and is_chrooted instead
90385 + of recomputing it here. Already copied when the task struct
90386 + is duplicated. This allows pivot_root to not be treated as
90387 + a chroot
90388 + */
90389 + //gr_set_chroot_entries(tsk, &tsk->fs->root);
90390 +
90391 return 0;
90392 }
90393
90394 @@ -1173,7 +1275,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
90395 * parts of the process environment (as per the clone
90396 * flags). The actual kick-off is left to the caller.
90397 */
90398 -static struct task_struct *copy_process(unsigned long clone_flags,
90399 +static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags,
90400 unsigned long stack_start,
90401 unsigned long stack_size,
90402 int __user *child_tidptr,
90403 @@ -1244,6 +1346,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
90404 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
90405 #endif
90406 retval = -EAGAIN;
90407 +
90408 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
90409 +
90410 if (atomic_read(&p->real_cred->user->processes) >=
90411 task_rlimit(p, RLIMIT_NPROC)) {
90412 if (p->real_cred->user != INIT_USER &&
90413 @@ -1493,6 +1598,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
90414 goto bad_fork_free_pid;
90415 }
90416
90417 + /* synchronizes with gr_set_acls()
90418 + we need to call this past the point of no return for fork()
90419 + */
90420 + gr_copy_label(p);
90421 +
90422 if (likely(p->pid)) {
90423 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
90424
90425 @@ -1583,6 +1693,8 @@ bad_fork_cleanup_count:
90426 bad_fork_free:
90427 free_task(p);
90428 fork_out:
90429 + gr_log_forkfail(retval);
90430 +
90431 return ERR_PTR(retval);
90432 }
90433
90434 @@ -1644,6 +1756,7 @@ long do_fork(unsigned long clone_flags,
90435
90436 p = copy_process(clone_flags, stack_start, stack_size,
90437 child_tidptr, NULL, trace);
90438 + add_latent_entropy();
90439 /*
90440 * Do this prior waking up the new thread - the thread pointer
90441 * might get invalid after that point, if the thread exits quickly.
90442 @@ -1660,6 +1773,8 @@ long do_fork(unsigned long clone_flags,
90443 if (clone_flags & CLONE_PARENT_SETTID)
90444 put_user(nr, parent_tidptr);
90445
90446 + gr_handle_brute_check();
90447 +
90448 if (clone_flags & CLONE_VFORK) {
90449 p->vfork_done = &vfork;
90450 init_completion(&vfork);
90451 @@ -1778,7 +1893,7 @@ void __init proc_caches_init(void)
90452 mm_cachep = kmem_cache_create("mm_struct",
90453 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
90454 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
90455 - vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
90456 + vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
90457 mmap_init();
90458 nsproxy_cache_init();
90459 }
90460 @@ -1818,7 +1933,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
90461 return 0;
90462
90463 /* don't need lock here; in the worst case we'll do useless copy */
90464 - if (fs->users == 1)
90465 + if (atomic_read(&fs->users) == 1)
90466 return 0;
90467
90468 *new_fsp = copy_fs_struct(fs);
90469 @@ -1930,7 +2045,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
90470 fs = current->fs;
90471 spin_lock(&fs->lock);
90472 current->fs = new_fs;
90473 - if (--fs->users)
90474 + gr_set_chroot_entries(current, &current->fs->root);
90475 + if (atomic_dec_return(&fs->users))
90476 new_fs = NULL;
90477 else
90478 new_fs = fs;
90479 diff --git a/kernel/futex.c b/kernel/futex.c
90480 index 22b3f1b..6820bc0 100644
90481 --- a/kernel/futex.c
90482 +++ b/kernel/futex.c
90483 @@ -202,7 +202,7 @@ struct futex_pi_state {
90484 atomic_t refcount;
90485
90486 union futex_key key;
90487 -};
90488 +} __randomize_layout;
90489
90490 /**
90491 * struct futex_q - The hashed futex queue entry, one per waiting task
90492 @@ -236,7 +236,7 @@ struct futex_q {
90493 struct rt_mutex_waiter *rt_waiter;
90494 union futex_key *requeue_pi_key;
90495 u32 bitset;
90496 -};
90497 +} __randomize_layout;
90498
90499 static const struct futex_q futex_q_init = {
90500 /* list gets initialized in queue_me()*/
90501 @@ -396,6 +396,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
90502 struct page *page, *page_head;
90503 int err, ro = 0;
90504
90505 +#ifdef CONFIG_PAX_SEGMEXEC
90506 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
90507 + return -EFAULT;
90508 +#endif
90509 +
90510 /*
90511 * The futex address must be "naturally" aligned.
90512 */
90513 @@ -595,7 +600,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
90514
90515 static int get_futex_value_locked(u32 *dest, u32 __user *from)
90516 {
90517 - int ret;
90518 + unsigned long ret;
90519
90520 pagefault_disable();
90521 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
90522 @@ -3000,6 +3005,7 @@ static void __init futex_detect_cmpxchg(void)
90523 {
90524 #ifndef CONFIG_HAVE_FUTEX_CMPXCHG
90525 u32 curval;
90526 + mm_segment_t oldfs;
90527
90528 /*
90529 * This will fail and we want it. Some arch implementations do
90530 @@ -3011,8 +3017,11 @@ static void __init futex_detect_cmpxchg(void)
90531 * implementation, the non-functional ones will return
90532 * -ENOSYS.
90533 */
90534 + oldfs = get_fs();
90535 + set_fs(USER_DS);
90536 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
90537 futex_cmpxchg_enabled = 1;
90538 + set_fs(oldfs);
90539 #endif
90540 }
90541
90542 diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
90543 index 55c8c93..9ba7ad6 100644
90544 --- a/kernel/futex_compat.c
90545 +++ b/kernel/futex_compat.c
90546 @@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
90547 return 0;
90548 }
90549
90550 -static void __user *futex_uaddr(struct robust_list __user *entry,
90551 +static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
90552 compat_long_t futex_offset)
90553 {
90554 compat_uptr_t base = ptr_to_compat(entry);
90555 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
90556 index b358a80..fc25240 100644
90557 --- a/kernel/gcov/base.c
90558 +++ b/kernel/gcov/base.c
90559 @@ -114,11 +114,6 @@ void gcov_enable_events(void)
90560 }
90561
90562 #ifdef CONFIG_MODULES
90563 -static inline int within(void *addr, void *start, unsigned long size)
90564 -{
90565 - return ((addr >= start) && (addr < start + size));
90566 -}
90567 -
90568 /* Update list and generate events when modules are unloaded. */
90569 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
90570 void *data)
90571 @@ -133,7 +128,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
90572
90573 /* Remove entries located in module from linked list. */
90574 while ((info = gcov_info_next(info))) {
90575 - if (within(info, mod->module_core, mod->core_size)) {
90576 + if (within_module_core_rw((unsigned long)info, mod)) {
90577 gcov_info_unlink(prev, info);
90578 if (gcov_events_enabled)
90579 gcov_event(GCOV_REMOVE, info);
90580 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
90581 index 9019f15..9a3c42e 100644
90582 --- a/kernel/jump_label.c
90583 +++ b/kernel/jump_label.c
90584 @@ -14,6 +14,7 @@
90585 #include <linux/err.h>
90586 #include <linux/static_key.h>
90587 #include <linux/jump_label_ratelimit.h>
90588 +#include <linux/mm.h>
90589
90590 #ifdef HAVE_JUMP_LABEL
90591
90592 @@ -51,7 +52,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
90593
90594 size = (((unsigned long)stop - (unsigned long)start)
90595 / sizeof(struct jump_entry));
90596 + pax_open_kernel();
90597 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
90598 + pax_close_kernel();
90599 }
90600
90601 static void jump_label_update(struct static_key *key, int enable);
90602 @@ -363,10 +366,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
90603 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
90604 struct jump_entry *iter;
90605
90606 + pax_open_kernel();
90607 for (iter = iter_start; iter < iter_stop; iter++) {
90608 if (within_module_init(iter->code, mod))
90609 iter->code = 0;
90610 }
90611 + pax_close_kernel();
90612 }
90613
90614 static int
90615 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
90616 index ae51670..c1a9796 100644
90617 --- a/kernel/kallsyms.c
90618 +++ b/kernel/kallsyms.c
90619 @@ -11,6 +11,9 @@
90620 * Changed the compression method from stem compression to "table lookup"
90621 * compression (see scripts/kallsyms.c for a more complete description)
90622 */
90623 +#ifdef CONFIG_GRKERNSEC_HIDESYM
90624 +#define __INCLUDED_BY_HIDESYM 1
90625 +#endif
90626 #include <linux/kallsyms.h>
90627 #include <linux/module.h>
90628 #include <linux/init.h>
90629 @@ -54,12 +57,33 @@ extern const unsigned long kallsyms_markers[] __weak;
90630
90631 static inline int is_kernel_inittext(unsigned long addr)
90632 {
90633 + if (system_state != SYSTEM_BOOTING)
90634 + return 0;
90635 +
90636 if (addr >= (unsigned long)_sinittext
90637 && addr <= (unsigned long)_einittext)
90638 return 1;
90639 return 0;
90640 }
90641
90642 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
90643 +#ifdef CONFIG_MODULES
90644 +static inline int is_module_text(unsigned long addr)
90645 +{
90646 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
90647 + return 1;
90648 +
90649 + addr = ktla_ktva(addr);
90650 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
90651 +}
90652 +#else
90653 +static inline int is_module_text(unsigned long addr)
90654 +{
90655 + return 0;
90656 +}
90657 +#endif
90658 +#endif
90659 +
90660 static inline int is_kernel_text(unsigned long addr)
90661 {
90662 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
90663 @@ -70,13 +94,28 @@ static inline int is_kernel_text(unsigned long addr)
90664
90665 static inline int is_kernel(unsigned long addr)
90666 {
90667 +
90668 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
90669 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
90670 + return 1;
90671 +
90672 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
90673 +#else
90674 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
90675 +#endif
90676 +
90677 return 1;
90678 return in_gate_area_no_mm(addr);
90679 }
90680
90681 static int is_ksym_addr(unsigned long addr)
90682 {
90683 +
90684 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
90685 + if (is_module_text(addr))
90686 + return 0;
90687 +#endif
90688 +
90689 if (all_var)
90690 return is_kernel(addr);
90691
90692 @@ -481,7 +520,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
90693
90694 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
90695 {
90696 - iter->name[0] = '\0';
90697 iter->nameoff = get_symbol_offset(new_pos);
90698 iter->pos = new_pos;
90699 }
90700 @@ -529,6 +567,11 @@ static int s_show(struct seq_file *m, void *p)
90701 {
90702 struct kallsym_iter *iter = m->private;
90703
90704 +#ifdef CONFIG_GRKERNSEC_HIDESYM
90705 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
90706 + return 0;
90707 +#endif
90708 +
90709 /* Some debugging symbols have no name. Ignore them. */
90710 if (!iter->name[0])
90711 return 0;
90712 @@ -542,6 +585,7 @@ static int s_show(struct seq_file *m, void *p)
90713 */
90714 type = iter->exported ? toupper(iter->type) :
90715 tolower(iter->type);
90716 +
90717 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
90718 type, iter->name, iter->module_name);
90719 } else
90720 @@ -567,7 +611,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
90721 struct kallsym_iter *iter;
90722 int ret;
90723
90724 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
90725 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
90726 if (!iter)
90727 return -ENOMEM;
90728 reset_iter(iter, 0);
90729 diff --git a/kernel/kcmp.c b/kernel/kcmp.c
90730 index 0aa69ea..a7fcafb 100644
90731 --- a/kernel/kcmp.c
90732 +++ b/kernel/kcmp.c
90733 @@ -100,6 +100,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
90734 struct task_struct *task1, *task2;
90735 int ret;
90736
90737 +#ifdef CONFIG_GRKERNSEC
90738 + return -ENOSYS;
90739 +#endif
90740 +
90741 rcu_read_lock();
90742
90743 /*
90744 diff --git a/kernel/kexec.c b/kernel/kexec.c
90745 index 2bee072..8979af8 100644
90746 --- a/kernel/kexec.c
90747 +++ b/kernel/kexec.c
90748 @@ -1349,7 +1349,8 @@ COMPAT_SYSCALL_DEFINE4(kexec_load, compat_ulong_t, entry,
90749 compat_ulong_t, flags)
90750 {
90751 struct compat_kexec_segment in;
90752 - struct kexec_segment out, __user *ksegments;
90753 + struct kexec_segment out;
90754 + struct kexec_segment __user *ksegments;
90755 unsigned long i, result;
90756
90757 /* Don't allow clients that don't understand the native
90758 diff --git a/kernel/kmod.c b/kernel/kmod.c
90759 index 8637e04..8b1d0d8 100644
90760 --- a/kernel/kmod.c
90761 +++ b/kernel/kmod.c
90762 @@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
90763 kfree(info->argv);
90764 }
90765
90766 -static int call_modprobe(char *module_name, int wait)
90767 +static int call_modprobe(char *module_name, char *module_param, int wait)
90768 {
90769 struct subprocess_info *info;
90770 static char *envp[] = {
90771 @@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
90772 NULL
90773 };
90774
90775 - char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
90776 + char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
90777 if (!argv)
90778 goto out;
90779
90780 @@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
90781 argv[1] = "-q";
90782 argv[2] = "--";
90783 argv[3] = module_name; /* check free_modprobe_argv() */
90784 - argv[4] = NULL;
90785 + argv[4] = module_param;
90786 + argv[5] = NULL;
90787
90788 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
90789 NULL, free_modprobe_argv, NULL);
90790 @@ -129,9 +130,8 @@ out:
90791 * If module auto-loading support is disabled then this function
90792 * becomes a no-operation.
90793 */
90794 -int __request_module(bool wait, const char *fmt, ...)
90795 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
90796 {
90797 - va_list args;
90798 char module_name[MODULE_NAME_LEN];
90799 unsigned int max_modprobes;
90800 int ret;
90801 @@ -150,9 +150,7 @@ int __request_module(bool wait, const char *fmt, ...)
90802 if (!modprobe_path[0])
90803 return 0;
90804
90805 - va_start(args, fmt);
90806 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
90807 - va_end(args);
90808 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
90809 if (ret >= MODULE_NAME_LEN)
90810 return -ENAMETOOLONG;
90811
90812 @@ -160,6 +158,20 @@ int __request_module(bool wait, const char *fmt, ...)
90813 if (ret)
90814 return ret;
90815
90816 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
90817 + if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
90818 + /* hack to workaround consolekit/udisks stupidity */
90819 + read_lock(&tasklist_lock);
90820 + if (!strcmp(current->comm, "mount") &&
90821 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
90822 + read_unlock(&tasklist_lock);
90823 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
90824 + return -EPERM;
90825 + }
90826 + read_unlock(&tasklist_lock);
90827 + }
90828 +#endif
90829 +
90830 /* If modprobe needs a service that is in a module, we get a recursive
90831 * loop. Limit the number of running kmod threads to max_threads/2 or
90832 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
90833 @@ -188,11 +200,52 @@ int __request_module(bool wait, const char *fmt, ...)
90834
90835 trace_module_request(module_name, wait, _RET_IP_);
90836
90837 - ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
90838 + ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
90839
90840 atomic_dec(&kmod_concurrent);
90841 return ret;
90842 }
90843 +
90844 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
90845 +{
90846 + va_list args;
90847 + int ret;
90848 +
90849 + va_start(args, fmt);
90850 + ret = ____request_module(wait, module_param, fmt, args);
90851 + va_end(args);
90852 +
90853 + return ret;
90854 +}
90855 +
90856 +int __request_module(bool wait, const char *fmt, ...)
90857 +{
90858 + va_list args;
90859 + int ret;
90860 +
90861 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
90862 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
90863 + char module_param[MODULE_NAME_LEN];
90864 +
90865 + memset(module_param, 0, sizeof(module_param));
90866 +
90867 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
90868 +
90869 + va_start(args, fmt);
90870 + ret = ____request_module(wait, module_param, fmt, args);
90871 + va_end(args);
90872 +
90873 + return ret;
90874 + }
90875 +#endif
90876 +
90877 + va_start(args, fmt);
90878 + ret = ____request_module(wait, NULL, fmt, args);
90879 + va_end(args);
90880 +
90881 + return ret;
90882 +}
90883 +
90884 EXPORT_SYMBOL(__request_module);
90885 #endif /* CONFIG_MODULES */
90886
90887 @@ -218,6 +271,20 @@ static int ____call_usermodehelper(void *data)
90888 */
90889 set_user_nice(current, 0);
90890
90891 +#ifdef CONFIG_GRKERNSEC
90892 + /* this is race-free as far as userland is concerned as we copied
90893 + out the path to be used prior to this point and are now operating
90894 + on that copy
90895 + */
90896 + if ((strncmp(sub_info->path, "/sbin/", 6) && strncmp(sub_info->path, "/usr/lib/", 9) &&
90897 + strncmp(sub_info->path, "/lib/", 5) && strncmp(sub_info->path, "/lib64/", 7) &&
90898 + strcmp(sub_info->path, "/usr/share/apport/apport")) || strstr(sub_info->path, "..")) {
90899 + printk(KERN_ALERT "grsec: denied exec of usermode helper binary %.950s located outside of /sbin and system library paths\n", sub_info->path);
90900 + retval = -EPERM;
90901 + goto fail;
90902 + }
90903 +#endif
90904 +
90905 retval = -ENOMEM;
90906 new = prepare_kernel_cred(current);
90907 if (!new)
90908 @@ -240,8 +307,8 @@ static int ____call_usermodehelper(void *data)
90909 commit_creds(new);
90910
90911 retval = do_execve(getname_kernel(sub_info->path),
90912 - (const char __user *const __user *)sub_info->argv,
90913 - (const char __user *const __user *)sub_info->envp);
90914 + (const char __user *const __force_user *)sub_info->argv,
90915 + (const char __user *const __force_user *)sub_info->envp);
90916 if (!retval)
90917 return 0;
90918
90919 @@ -260,6 +327,10 @@ static int call_helper(void *data)
90920
90921 static void call_usermodehelper_freeinfo(struct subprocess_info *info)
90922 {
90923 +#ifdef CONFIG_GRKERNSEC
90924 + kfree(info->path);
90925 + info->path = info->origpath;
90926 +#endif
90927 if (info->cleanup)
90928 (*info->cleanup)(info);
90929 kfree(info);
90930 @@ -300,7 +371,7 @@ static int wait_for_helper(void *data)
90931 *
90932 * Thus the __user pointer cast is valid here.
90933 */
90934 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
90935 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
90936
90937 /*
90938 * If ret is 0, either ____call_usermodehelper failed and the
90939 @@ -539,7 +610,12 @@ struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
90940 goto out;
90941
90942 INIT_WORK(&sub_info->work, __call_usermodehelper);
90943 +#ifdef CONFIG_GRKERNSEC
90944 + sub_info->origpath = path;
90945 + sub_info->path = kstrdup(path, gfp_mask);
90946 +#else
90947 sub_info->path = path;
90948 +#endif
90949 sub_info->argv = argv;
90950 sub_info->envp = envp;
90951
90952 @@ -647,7 +723,7 @@ EXPORT_SYMBOL(call_usermodehelper);
90953 static int proc_cap_handler(struct ctl_table *table, int write,
90954 void __user *buffer, size_t *lenp, loff_t *ppos)
90955 {
90956 - struct ctl_table t;
90957 + ctl_table_no_const t;
90958 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
90959 kernel_cap_t new_cap;
90960 int err, i;
90961 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
90962 index 3995f54..e247879 100644
90963 --- a/kernel/kprobes.c
90964 +++ b/kernel/kprobes.c
90965 @@ -31,6 +31,9 @@
90966 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
90967 * <prasanna@in.ibm.com> added function-return probes.
90968 */
90969 +#ifdef CONFIG_GRKERNSEC_HIDESYM
90970 +#define __INCLUDED_BY_HIDESYM 1
90971 +#endif
90972 #include <linux/kprobes.h>
90973 #include <linux/hash.h>
90974 #include <linux/init.h>
90975 @@ -122,12 +125,12 @@ enum kprobe_slot_state {
90976
90977 static void *alloc_insn_page(void)
90978 {
90979 - return module_alloc(PAGE_SIZE);
90980 + return module_alloc_exec(PAGE_SIZE);
90981 }
90982
90983 static void free_insn_page(void *page)
90984 {
90985 - module_free(NULL, page);
90986 + module_free_exec(NULL, page);
90987 }
90988
90989 struct kprobe_insn_cache kprobe_insn_slots = {
90990 @@ -2187,11 +2190,11 @@ static void report_probe(struct seq_file *pi, struct kprobe *p,
90991 kprobe_type = "k";
90992
90993 if (sym)
90994 - seq_printf(pi, "%p %s %s+0x%x %s ",
90995 + seq_printf(pi, "%pK %s %s+0x%x %s ",
90996 p->addr, kprobe_type, sym, offset,
90997 (modname ? modname : " "));
90998 else
90999 - seq_printf(pi, "%p %s %p ",
91000 + seq_printf(pi, "%pK %s %pK ",
91001 p->addr, kprobe_type, p->addr);
91002
91003 if (!pp)
91004 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
91005 index 6683cce..daf8999 100644
91006 --- a/kernel/ksysfs.c
91007 +++ b/kernel/ksysfs.c
91008 @@ -50,6 +50,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
91009 {
91010 if (count+1 > UEVENT_HELPER_PATH_LEN)
91011 return -ENOENT;
91012 + if (!capable(CAP_SYS_ADMIN))
91013 + return -EPERM;
91014 memcpy(uevent_helper, buf, count);
91015 uevent_helper[count] = '\0';
91016 if (count && uevent_helper[count-1] == '\n')
91017 @@ -176,7 +178,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
91018 return count;
91019 }
91020
91021 -static struct bin_attribute notes_attr = {
91022 +static bin_attribute_no_const notes_attr __read_only = {
91023 .attr = {
91024 .name = "notes",
91025 .mode = S_IRUGO,
91026 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
91027 index 88d0d44..e9ce0ee 100644
91028 --- a/kernel/locking/lockdep.c
91029 +++ b/kernel/locking/lockdep.c
91030 @@ -599,6 +599,10 @@ static int static_obj(void *obj)
91031 end = (unsigned long) &_end,
91032 addr = (unsigned long) obj;
91033
91034 +#ifdef CONFIG_PAX_KERNEXEC
91035 + start = ktla_ktva(start);
91036 +#endif
91037 +
91038 /*
91039 * static variable?
91040 */
91041 @@ -740,6 +744,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
91042 if (!static_obj(lock->key)) {
91043 debug_locks_off();
91044 printk("INFO: trying to register non-static key.\n");
91045 + printk("lock:%pS key:%pS.\n", lock, lock->key);
91046 printk("the code is fine but needs lockdep annotation.\n");
91047 printk("turning off the locking correctness validator.\n");
91048 dump_stack();
91049 @@ -3081,7 +3086,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
91050 if (!class)
91051 return 0;
91052 }
91053 - atomic_inc((atomic_t *)&class->ops);
91054 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)&class->ops);
91055 if (very_verbose(class)) {
91056 printk("\nacquire class [%p] %s", class->key, class->name);
91057 if (class->name_version > 1)
91058 diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
91059 index ef43ac4..2720dfa 100644
91060 --- a/kernel/locking/lockdep_proc.c
91061 +++ b/kernel/locking/lockdep_proc.c
91062 @@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
91063 return 0;
91064 }
91065
91066 - seq_printf(m, "%p", class->key);
91067 + seq_printf(m, "%pK", class->key);
91068 #ifdef CONFIG_DEBUG_LOCKDEP
91069 seq_printf(m, " OPS:%8ld", class->ops);
91070 #endif
91071 @@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
91072
91073 list_for_each_entry(entry, &class->locks_after, entry) {
91074 if (entry->distance == 1) {
91075 - seq_printf(m, " -> [%p] ", entry->class->key);
91076 + seq_printf(m, " -> [%pK] ", entry->class->key);
91077 print_name(m, entry->class);
91078 seq_puts(m, "\n");
91079 }
91080 @@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
91081 if (!class->key)
91082 continue;
91083
91084 - seq_printf(m, "[%p] ", class->key);
91085 + seq_printf(m, "[%pK] ", class->key);
91086 print_name(m, class);
91087 seq_puts(m, "\n");
91088 }
91089 @@ -496,7 +496,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
91090 if (!i)
91091 seq_line(m, '-', 40-namelen, namelen);
91092
91093 - snprintf(ip, sizeof(ip), "[<%p>]",
91094 + snprintf(ip, sizeof(ip), "[<%pK>]",
91095 (void *)class->contention_point[i]);
91096 seq_printf(m, "%40s %14lu %29s %pS\n",
91097 name, stats->contention_point[i],
91098 @@ -511,7 +511,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
91099 if (!i)
91100 seq_line(m, '-', 40-namelen, namelen);
91101
91102 - snprintf(ip, sizeof(ip), "[<%p>]",
91103 + snprintf(ip, sizeof(ip), "[<%pK>]",
91104 (void *)class->contending_point[i]);
91105 seq_printf(m, "%40s %14lu %29s %pS\n",
91106 name, stats->contending_point[i],
91107 diff --git a/kernel/locking/mcs_spinlock.c b/kernel/locking/mcs_spinlock.c
91108 index 9887a90..0cd2b1d 100644
91109 --- a/kernel/locking/mcs_spinlock.c
91110 +++ b/kernel/locking/mcs_spinlock.c
91111 @@ -100,7 +100,7 @@ bool osq_lock(struct optimistic_spin_queue *lock)
91112
91113 prev = decode_cpu(old);
91114 node->prev = prev;
91115 - ACCESS_ONCE(prev->next) = node;
91116 + ACCESS_ONCE_RW(prev->next) = node;
91117
91118 /*
91119 * Normally @prev is untouchable after the above store; because at that
91120 @@ -172,8 +172,8 @@ unqueue:
91121 * it will wait in Step-A.
91122 */
91123
91124 - ACCESS_ONCE(next->prev) = prev;
91125 - ACCESS_ONCE(prev->next) = next;
91126 + ACCESS_ONCE_RW(next->prev) = prev;
91127 + ACCESS_ONCE_RW(prev->next) = next;
91128
91129 return false;
91130 }
91131 @@ -195,13 +195,13 @@ void osq_unlock(struct optimistic_spin_queue *lock)
91132 node = this_cpu_ptr(&osq_node);
91133 next = xchg(&node->next, NULL);
91134 if (next) {
91135 - ACCESS_ONCE(next->locked) = 1;
91136 + ACCESS_ONCE_RW(next->locked) = 1;
91137 return;
91138 }
91139
91140 next = osq_wait_next(lock, node, NULL);
91141 if (next)
91142 - ACCESS_ONCE(next->locked) = 1;
91143 + ACCESS_ONCE_RW(next->locked) = 1;
91144 }
91145
91146 #endif
91147 diff --git a/kernel/locking/mcs_spinlock.h b/kernel/locking/mcs_spinlock.h
91148 index 23e89c5..8558eac 100644
91149 --- a/kernel/locking/mcs_spinlock.h
91150 +++ b/kernel/locking/mcs_spinlock.h
91151 @@ -81,7 +81,7 @@ void mcs_spin_lock(struct mcs_spinlock **lock, struct mcs_spinlock *node)
91152 */
91153 return;
91154 }
91155 - ACCESS_ONCE(prev->next) = node;
91156 + ACCESS_ONCE_RW(prev->next) = node;
91157
91158 /* Wait until the lock holder passes the lock down. */
91159 arch_mcs_spin_lock_contended(&node->locked);
91160 diff --git a/kernel/locking/mutex-debug.c b/kernel/locking/mutex-debug.c
91161 index 5cf6731..ce3bc5a 100644
91162 --- a/kernel/locking/mutex-debug.c
91163 +++ b/kernel/locking/mutex-debug.c
91164 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
91165 }
91166
91167 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
91168 - struct thread_info *ti)
91169 + struct task_struct *task)
91170 {
91171 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
91172
91173 /* Mark the current thread as blocked on the lock: */
91174 - ti->task->blocked_on = waiter;
91175 + task->blocked_on = waiter;
91176 }
91177
91178 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
91179 - struct thread_info *ti)
91180 + struct task_struct *task)
91181 {
91182 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
91183 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
91184 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
91185 - ti->task->blocked_on = NULL;
91186 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
91187 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
91188 + task->blocked_on = NULL;
91189
91190 list_del_init(&waiter->list);
91191 waiter->task = NULL;
91192 diff --git a/kernel/locking/mutex-debug.h b/kernel/locking/mutex-debug.h
91193 index 0799fd3..d06ae3b 100644
91194 --- a/kernel/locking/mutex-debug.h
91195 +++ b/kernel/locking/mutex-debug.h
91196 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
91197 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
91198 extern void debug_mutex_add_waiter(struct mutex *lock,
91199 struct mutex_waiter *waiter,
91200 - struct thread_info *ti);
91201 + struct task_struct *task);
91202 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
91203 - struct thread_info *ti);
91204 + struct task_struct *task);
91205 extern void debug_mutex_unlock(struct mutex *lock);
91206 extern void debug_mutex_init(struct mutex *lock, const char *name,
91207 struct lock_class_key *key);
91208 diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
91209 index ae712b2..d0d4a41 100644
91210 --- a/kernel/locking/mutex.c
91211 +++ b/kernel/locking/mutex.c
91212 @@ -486,7 +486,7 @@ slowpath:
91213 goto skip_wait;
91214
91215 debug_mutex_lock_common(lock, &waiter);
91216 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
91217 + debug_mutex_add_waiter(lock, &waiter, task);
91218
91219 /* add waiting tasks to the end of the waitqueue (FIFO): */
91220 list_add_tail(&waiter.list, &lock->wait_list);
91221 @@ -531,7 +531,7 @@ slowpath:
91222 schedule_preempt_disabled();
91223 spin_lock_mutex(&lock->wait_lock, flags);
91224 }
91225 - mutex_remove_waiter(lock, &waiter, current_thread_info());
91226 + mutex_remove_waiter(lock, &waiter, task);
91227 /* set it to 0 if there are no waiters left: */
91228 if (likely(list_empty(&lock->wait_list)))
91229 atomic_set(&lock->count, 0);
91230 @@ -568,7 +568,7 @@ skip_wait:
91231 return 0;
91232
91233 err:
91234 - mutex_remove_waiter(lock, &waiter, task_thread_info(task));
91235 + mutex_remove_waiter(lock, &waiter, task);
91236 spin_unlock_mutex(&lock->wait_lock, flags);
91237 debug_mutex_free_waiter(&waiter);
91238 mutex_release(&lock->dep_map, 1, ip);
91239 diff --git a/kernel/locking/rtmutex-tester.c b/kernel/locking/rtmutex-tester.c
91240 index 1d96dd0..994ff19 100644
91241 --- a/kernel/locking/rtmutex-tester.c
91242 +++ b/kernel/locking/rtmutex-tester.c
91243 @@ -22,7 +22,7 @@
91244 #define MAX_RT_TEST_MUTEXES 8
91245
91246 static spinlock_t rttest_lock;
91247 -static atomic_t rttest_event;
91248 +static atomic_unchecked_t rttest_event;
91249
91250 struct test_thread_data {
91251 int opcode;
91252 @@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
91253
91254 case RTTEST_LOCKCONT:
91255 td->mutexes[td->opdata] = 1;
91256 - td->event = atomic_add_return(1, &rttest_event);
91257 + td->event = atomic_add_return_unchecked(1, &rttest_event);
91258 return 0;
91259
91260 case RTTEST_RESET:
91261 @@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
91262 return 0;
91263
91264 case RTTEST_RESETEVENT:
91265 - atomic_set(&rttest_event, 0);
91266 + atomic_set_unchecked(&rttest_event, 0);
91267 return 0;
91268
91269 default:
91270 @@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
91271 return ret;
91272
91273 td->mutexes[id] = 1;
91274 - td->event = atomic_add_return(1, &rttest_event);
91275 + td->event = atomic_add_return_unchecked(1, &rttest_event);
91276 rt_mutex_lock(&mutexes[id]);
91277 - td->event = atomic_add_return(1, &rttest_event);
91278 + td->event = atomic_add_return_unchecked(1, &rttest_event);
91279 td->mutexes[id] = 4;
91280 return 0;
91281
91282 @@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
91283 return ret;
91284
91285 td->mutexes[id] = 1;
91286 - td->event = atomic_add_return(1, &rttest_event);
91287 + td->event = atomic_add_return_unchecked(1, &rttest_event);
91288 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
91289 - td->event = atomic_add_return(1, &rttest_event);
91290 + td->event = atomic_add_return_unchecked(1, &rttest_event);
91291 td->mutexes[id] = ret ? 0 : 4;
91292 return ret ? -EINTR : 0;
91293
91294 @@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
91295 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
91296 return ret;
91297
91298 - td->event = atomic_add_return(1, &rttest_event);
91299 + td->event = atomic_add_return_unchecked(1, &rttest_event);
91300 rt_mutex_unlock(&mutexes[id]);
91301 - td->event = atomic_add_return(1, &rttest_event);
91302 + td->event = atomic_add_return_unchecked(1, &rttest_event);
91303 td->mutexes[id] = 0;
91304 return 0;
91305
91306 @@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
91307 break;
91308
91309 td->mutexes[dat] = 2;
91310 - td->event = atomic_add_return(1, &rttest_event);
91311 + td->event = atomic_add_return_unchecked(1, &rttest_event);
91312 break;
91313
91314 default:
91315 @@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
91316 return;
91317
91318 td->mutexes[dat] = 3;
91319 - td->event = atomic_add_return(1, &rttest_event);
91320 + td->event = atomic_add_return_unchecked(1, &rttest_event);
91321 break;
91322
91323 case RTTEST_LOCKNOWAIT:
91324 @@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
91325 return;
91326
91327 td->mutexes[dat] = 1;
91328 - td->event = atomic_add_return(1, &rttest_event);
91329 + td->event = atomic_add_return_unchecked(1, &rttest_event);
91330 return;
91331
91332 default:
91333 diff --git a/kernel/module.c b/kernel/module.c
91334 index 1c47139..6242887 100644
91335 --- a/kernel/module.c
91336 +++ b/kernel/module.c
91337 @@ -60,6 +60,7 @@
91338 #include <linux/jump_label.h>
91339 #include <linux/pfn.h>
91340 #include <linux/bsearch.h>
91341 +#include <linux/grsecurity.h>
91342 #include <uapi/linux/module.h>
91343 #include "module-internal.h"
91344
91345 @@ -156,7 +157,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
91346
91347 /* Bounds of module allocation, for speeding __module_address.
91348 * Protected by module_mutex. */
91349 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
91350 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
91351 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
91352
91353 int register_module_notifier(struct notifier_block * nb)
91354 {
91355 @@ -323,7 +325,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
91356 return true;
91357
91358 list_for_each_entry_rcu(mod, &modules, list) {
91359 - struct symsearch arr[] = {
91360 + struct symsearch modarr[] = {
91361 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
91362 NOT_GPL_ONLY, false },
91363 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
91364 @@ -348,7 +350,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
91365 if (mod->state == MODULE_STATE_UNFORMED)
91366 continue;
91367
91368 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
91369 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
91370 return true;
91371 }
91372 return false;
91373 @@ -488,7 +490,7 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
91374 if (!pcpusec->sh_size)
91375 return 0;
91376
91377 - if (align > PAGE_SIZE) {
91378 + if (align-1 >= PAGE_SIZE) {
91379 pr_warn("%s: per-cpu alignment %li > %li\n",
91380 mod->name, align, PAGE_SIZE);
91381 align = PAGE_SIZE;
91382 @@ -1060,7 +1062,7 @@ struct module_attribute module_uevent =
91383 static ssize_t show_coresize(struct module_attribute *mattr,
91384 struct module_kobject *mk, char *buffer)
91385 {
91386 - return sprintf(buffer, "%u\n", mk->mod->core_size);
91387 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
91388 }
91389
91390 static struct module_attribute modinfo_coresize =
91391 @@ -1069,7 +1071,7 @@ static struct module_attribute modinfo_coresize =
91392 static ssize_t show_initsize(struct module_attribute *mattr,
91393 struct module_kobject *mk, char *buffer)
91394 {
91395 - return sprintf(buffer, "%u\n", mk->mod->init_size);
91396 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
91397 }
91398
91399 static struct module_attribute modinfo_initsize =
91400 @@ -1161,12 +1163,29 @@ static int check_version(Elf_Shdr *sechdrs,
91401 goto bad_version;
91402 }
91403
91404 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
91405 + /*
91406 + * avoid potentially printing jibberish on attempted load
91407 + * of a module randomized with a different seed
91408 + */
91409 + pr_warn("no symbol version for %s\n", symname);
91410 +#else
91411 pr_warn("%s: no symbol version for %s\n", mod->name, symname);
91412 +#endif
91413 return 0;
91414
91415 bad_version:
91416 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
91417 + /*
91418 + * avoid potentially printing jibberish on attempted load
91419 + * of a module randomized with a different seed
91420 + */
91421 + printk("attempted module disagrees about version of symbol %s\n",
91422 + symname);
91423 +#else
91424 printk("%s: disagrees about version of symbol %s\n",
91425 mod->name, symname);
91426 +#endif
91427 return 0;
91428 }
91429
91430 @@ -1282,7 +1301,7 @@ resolve_symbol_wait(struct module *mod,
91431 */
91432 #ifdef CONFIG_SYSFS
91433
91434 -#ifdef CONFIG_KALLSYMS
91435 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
91436 static inline bool sect_empty(const Elf_Shdr *sect)
91437 {
91438 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
91439 @@ -1422,7 +1441,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
91440 {
91441 unsigned int notes, loaded, i;
91442 struct module_notes_attrs *notes_attrs;
91443 - struct bin_attribute *nattr;
91444 + bin_attribute_no_const *nattr;
91445
91446 /* failed to create section attributes, so can't create notes */
91447 if (!mod->sect_attrs)
91448 @@ -1534,7 +1553,7 @@ static void del_usage_links(struct module *mod)
91449 static int module_add_modinfo_attrs(struct module *mod)
91450 {
91451 struct module_attribute *attr;
91452 - struct module_attribute *temp_attr;
91453 + module_attribute_no_const *temp_attr;
91454 int error = 0;
91455 int i;
91456
91457 @@ -1755,21 +1774,21 @@ static void set_section_ro_nx(void *base,
91458
91459 static void unset_module_core_ro_nx(struct module *mod)
91460 {
91461 - set_page_attributes(mod->module_core + mod->core_text_size,
91462 - mod->module_core + mod->core_size,
91463 + set_page_attributes(mod->module_core_rw,
91464 + mod->module_core_rw + mod->core_size_rw,
91465 set_memory_x);
91466 - set_page_attributes(mod->module_core,
91467 - mod->module_core + mod->core_ro_size,
91468 + set_page_attributes(mod->module_core_rx,
91469 + mod->module_core_rx + mod->core_size_rx,
91470 set_memory_rw);
91471 }
91472
91473 static void unset_module_init_ro_nx(struct module *mod)
91474 {
91475 - set_page_attributes(mod->module_init + mod->init_text_size,
91476 - mod->module_init + mod->init_size,
91477 + set_page_attributes(mod->module_init_rw,
91478 + mod->module_init_rw + mod->init_size_rw,
91479 set_memory_x);
91480 - set_page_attributes(mod->module_init,
91481 - mod->module_init + mod->init_ro_size,
91482 + set_page_attributes(mod->module_init_rx,
91483 + mod->module_init_rx + mod->init_size_rx,
91484 set_memory_rw);
91485 }
91486
91487 @@ -1782,14 +1801,14 @@ void set_all_modules_text_rw(void)
91488 list_for_each_entry_rcu(mod, &modules, list) {
91489 if (mod->state == MODULE_STATE_UNFORMED)
91490 continue;
91491 - if ((mod->module_core) && (mod->core_text_size)) {
91492 - set_page_attributes(mod->module_core,
91493 - mod->module_core + mod->core_text_size,
91494 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
91495 + set_page_attributes(mod->module_core_rx,
91496 + mod->module_core_rx + mod->core_size_rx,
91497 set_memory_rw);
91498 }
91499 - if ((mod->module_init) && (mod->init_text_size)) {
91500 - set_page_attributes(mod->module_init,
91501 - mod->module_init + mod->init_text_size,
91502 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
91503 + set_page_attributes(mod->module_init_rx,
91504 + mod->module_init_rx + mod->init_size_rx,
91505 set_memory_rw);
91506 }
91507 }
91508 @@ -1805,14 +1824,14 @@ void set_all_modules_text_ro(void)
91509 list_for_each_entry_rcu(mod, &modules, list) {
91510 if (mod->state == MODULE_STATE_UNFORMED)
91511 continue;
91512 - if ((mod->module_core) && (mod->core_text_size)) {
91513 - set_page_attributes(mod->module_core,
91514 - mod->module_core + mod->core_text_size,
91515 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
91516 + set_page_attributes(mod->module_core_rx,
91517 + mod->module_core_rx + mod->core_size_rx,
91518 set_memory_ro);
91519 }
91520 - if ((mod->module_init) && (mod->init_text_size)) {
91521 - set_page_attributes(mod->module_init,
91522 - mod->module_init + mod->init_text_size,
91523 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
91524 + set_page_attributes(mod->module_init_rx,
91525 + mod->module_init_rx + mod->init_size_rx,
91526 set_memory_ro);
91527 }
91528 }
91529 @@ -1865,16 +1884,19 @@ static void free_module(struct module *mod)
91530
91531 /* This may be NULL, but that's OK */
91532 unset_module_init_ro_nx(mod);
91533 - module_free(mod, mod->module_init);
91534 + module_free(mod, mod->module_init_rw);
91535 + module_free_exec(mod, mod->module_init_rx);
91536 kfree(mod->args);
91537 percpu_modfree(mod);
91538
91539 /* Free lock-classes: */
91540 - lockdep_free_key_range(mod->module_core, mod->core_size);
91541 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
91542 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
91543
91544 /* Finally, free the core (containing the module structure) */
91545 unset_module_core_ro_nx(mod);
91546 - module_free(mod, mod->module_core);
91547 + module_free_exec(mod, mod->module_core_rx);
91548 + module_free(mod, mod->module_core_rw);
91549
91550 #ifdef CONFIG_MPU
91551 update_protections(current->mm);
91552 @@ -1943,9 +1965,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
91553 int ret = 0;
91554 const struct kernel_symbol *ksym;
91555
91556 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
91557 + int is_fs_load = 0;
91558 + int register_filesystem_found = 0;
91559 + char *p;
91560 +
91561 + p = strstr(mod->args, "grsec_modharden_fs");
91562 + if (p) {
91563 + char *endptr = p + sizeof("grsec_modharden_fs") - 1;
91564 + /* copy \0 as well */
91565 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
91566 + is_fs_load = 1;
91567 + }
91568 +#endif
91569 +
91570 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
91571 const char *name = info->strtab + sym[i].st_name;
91572
91573 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
91574 + /* it's a real shame this will never get ripped and copied
91575 + upstream! ;(
91576 + */
91577 + if (is_fs_load && !strcmp(name, "register_filesystem"))
91578 + register_filesystem_found = 1;
91579 +#endif
91580 +
91581 switch (sym[i].st_shndx) {
91582 case SHN_COMMON:
91583 /* Ignore common symbols */
91584 @@ -1970,7 +2014,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
91585 ksym = resolve_symbol_wait(mod, info, name);
91586 /* Ok if resolved. */
91587 if (ksym && !IS_ERR(ksym)) {
91588 + pax_open_kernel();
91589 sym[i].st_value = ksym->value;
91590 + pax_close_kernel();
91591 break;
91592 }
91593
91594 @@ -1989,11 +2035,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
91595 secbase = (unsigned long)mod_percpu(mod);
91596 else
91597 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
91598 + pax_open_kernel();
91599 sym[i].st_value += secbase;
91600 + pax_close_kernel();
91601 break;
91602 }
91603 }
91604
91605 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
91606 + if (is_fs_load && !register_filesystem_found) {
91607 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
91608 + ret = -EPERM;
91609 + }
91610 +#endif
91611 +
91612 return ret;
91613 }
91614
91615 @@ -2077,22 +2132,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
91616 || s->sh_entsize != ~0UL
91617 || strstarts(sname, ".init"))
91618 continue;
91619 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
91620 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
91621 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
91622 + else
91623 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
91624 pr_debug("\t%s\n", sname);
91625 }
91626 - switch (m) {
91627 - case 0: /* executable */
91628 - mod->core_size = debug_align(mod->core_size);
91629 - mod->core_text_size = mod->core_size;
91630 - break;
91631 - case 1: /* RO: text and ro-data */
91632 - mod->core_size = debug_align(mod->core_size);
91633 - mod->core_ro_size = mod->core_size;
91634 - break;
91635 - case 3: /* whole core */
91636 - mod->core_size = debug_align(mod->core_size);
91637 - break;
91638 - }
91639 }
91640
91641 pr_debug("Init section allocation order:\n");
91642 @@ -2106,23 +2151,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
91643 || s->sh_entsize != ~0UL
91644 || !strstarts(sname, ".init"))
91645 continue;
91646 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
91647 - | INIT_OFFSET_MASK);
91648 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
91649 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
91650 + else
91651 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
91652 + s->sh_entsize |= INIT_OFFSET_MASK;
91653 pr_debug("\t%s\n", sname);
91654 }
91655 - switch (m) {
91656 - case 0: /* executable */
91657 - mod->init_size = debug_align(mod->init_size);
91658 - mod->init_text_size = mod->init_size;
91659 - break;
91660 - case 1: /* RO: text and ro-data */
91661 - mod->init_size = debug_align(mod->init_size);
91662 - mod->init_ro_size = mod->init_size;
91663 - break;
91664 - case 3: /* whole init */
91665 - mod->init_size = debug_align(mod->init_size);
91666 - break;
91667 - }
91668 }
91669 }
91670
91671 @@ -2295,7 +2330,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
91672
91673 /* Put symbol section at end of init part of module. */
91674 symsect->sh_flags |= SHF_ALLOC;
91675 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
91676 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
91677 info->index.sym) | INIT_OFFSET_MASK;
91678 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
91679
91680 @@ -2312,13 +2347,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
91681 }
91682
91683 /* Append room for core symbols at end of core part. */
91684 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
91685 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
91686 - mod->core_size += strtab_size;
91687 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
91688 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
91689 + mod->core_size_rx += strtab_size;
91690
91691 /* Put string table section at end of init part of module. */
91692 strsect->sh_flags |= SHF_ALLOC;
91693 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
91694 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
91695 info->index.str) | INIT_OFFSET_MASK;
91696 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
91697 }
91698 @@ -2336,12 +2371,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
91699 /* Make sure we get permanent strtab: don't use info->strtab. */
91700 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
91701
91702 + pax_open_kernel();
91703 +
91704 /* Set types up while we still have access to sections. */
91705 for (i = 0; i < mod->num_symtab; i++)
91706 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
91707
91708 - mod->core_symtab = dst = mod->module_core + info->symoffs;
91709 - mod->core_strtab = s = mod->module_core + info->stroffs;
91710 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
91711 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
91712 src = mod->symtab;
91713 for (ndst = i = 0; i < mod->num_symtab; i++) {
91714 if (i == 0 ||
91715 @@ -2353,6 +2390,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
91716 }
91717 }
91718 mod->core_num_syms = ndst;
91719 +
91720 + pax_close_kernel();
91721 }
91722 #else
91723 static inline void layout_symtab(struct module *mod, struct load_info *info)
91724 @@ -2386,17 +2425,33 @@ void * __weak module_alloc(unsigned long size)
91725 return vmalloc_exec(size);
91726 }
91727
91728 -static void *module_alloc_update_bounds(unsigned long size)
91729 +static void *module_alloc_update_bounds_rw(unsigned long size)
91730 {
91731 void *ret = module_alloc(size);
91732
91733 if (ret) {
91734 mutex_lock(&module_mutex);
91735 /* Update module bounds. */
91736 - if ((unsigned long)ret < module_addr_min)
91737 - module_addr_min = (unsigned long)ret;
91738 - if ((unsigned long)ret + size > module_addr_max)
91739 - module_addr_max = (unsigned long)ret + size;
91740 + if ((unsigned long)ret < module_addr_min_rw)
91741 + module_addr_min_rw = (unsigned long)ret;
91742 + if ((unsigned long)ret + size > module_addr_max_rw)
91743 + module_addr_max_rw = (unsigned long)ret + size;
91744 + mutex_unlock(&module_mutex);
91745 + }
91746 + return ret;
91747 +}
91748 +
91749 +static void *module_alloc_update_bounds_rx(unsigned long size)
91750 +{
91751 + void *ret = module_alloc_exec(size);
91752 +
91753 + if (ret) {
91754 + mutex_lock(&module_mutex);
91755 + /* Update module bounds. */
91756 + if ((unsigned long)ret < module_addr_min_rx)
91757 + module_addr_min_rx = (unsigned long)ret;
91758 + if ((unsigned long)ret + size > module_addr_max_rx)
91759 + module_addr_max_rx = (unsigned long)ret + size;
91760 mutex_unlock(&module_mutex);
91761 }
91762 return ret;
91763 @@ -2650,7 +2705,15 @@ static struct module *setup_load_info(struct load_info *info, int flags)
91764 mod = (void *)info->sechdrs[info->index.mod].sh_addr;
91765
91766 if (info->index.sym == 0) {
91767 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
91768 + /*
91769 + * avoid potentially printing jibberish on attempted load
91770 + * of a module randomized with a different seed
91771 + */
91772 + pr_warn("module has no symbols (stripped?)\n");
91773 +#else
91774 pr_warn("%s: module has no symbols (stripped?)\n", mod->name);
91775 +#endif
91776 return ERR_PTR(-ENOEXEC);
91777 }
91778
91779 @@ -2666,8 +2729,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
91780 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
91781 {
91782 const char *modmagic = get_modinfo(info, "vermagic");
91783 + const char *license = get_modinfo(info, "license");
91784 int err;
91785
91786 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
91787 + if (!license || !license_is_gpl_compatible(license))
91788 + return -ENOEXEC;
91789 +#endif
91790 +
91791 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
91792 modmagic = NULL;
91793
91794 @@ -2692,7 +2761,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
91795 }
91796
91797 /* Set up license info based on the info section */
91798 - set_license(mod, get_modinfo(info, "license"));
91799 + set_license(mod, license);
91800
91801 return 0;
91802 }
91803 @@ -2786,7 +2855,7 @@ static int move_module(struct module *mod, struct load_info *info)
91804 void *ptr;
91805
91806 /* Do the allocs. */
91807 - ptr = module_alloc_update_bounds(mod->core_size);
91808 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
91809 /*
91810 * The pointer to this block is stored in the module structure
91811 * which is inside the block. Just mark it as not being a
91812 @@ -2796,11 +2865,11 @@ static int move_module(struct module *mod, struct load_info *info)
91813 if (!ptr)
91814 return -ENOMEM;
91815
91816 - memset(ptr, 0, mod->core_size);
91817 - mod->module_core = ptr;
91818 + memset(ptr, 0, mod->core_size_rw);
91819 + mod->module_core_rw = ptr;
91820
91821 - if (mod->init_size) {
91822 - ptr = module_alloc_update_bounds(mod->init_size);
91823 + if (mod->init_size_rw) {
91824 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
91825 /*
91826 * The pointer to this block is stored in the module structure
91827 * which is inside the block. This block doesn't need to be
91828 @@ -2809,13 +2878,45 @@ static int move_module(struct module *mod, struct load_info *info)
91829 */
91830 kmemleak_ignore(ptr);
91831 if (!ptr) {
91832 - module_free(mod, mod->module_core);
91833 + module_free(mod, mod->module_core_rw);
91834 return -ENOMEM;
91835 }
91836 - memset(ptr, 0, mod->init_size);
91837 - mod->module_init = ptr;
91838 + memset(ptr, 0, mod->init_size_rw);
91839 + mod->module_init_rw = ptr;
91840 } else
91841 - mod->module_init = NULL;
91842 + mod->module_init_rw = NULL;
91843 +
91844 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
91845 + kmemleak_not_leak(ptr);
91846 + if (!ptr) {
91847 + if (mod->module_init_rw)
91848 + module_free(mod, mod->module_init_rw);
91849 + module_free(mod, mod->module_core_rw);
91850 + return -ENOMEM;
91851 + }
91852 +
91853 + pax_open_kernel();
91854 + memset(ptr, 0, mod->core_size_rx);
91855 + pax_close_kernel();
91856 + mod->module_core_rx = ptr;
91857 +
91858 + if (mod->init_size_rx) {
91859 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
91860 + kmemleak_ignore(ptr);
91861 + if (!ptr && mod->init_size_rx) {
91862 + module_free_exec(mod, mod->module_core_rx);
91863 + if (mod->module_init_rw)
91864 + module_free(mod, mod->module_init_rw);
91865 + module_free(mod, mod->module_core_rw);
91866 + return -ENOMEM;
91867 + }
91868 +
91869 + pax_open_kernel();
91870 + memset(ptr, 0, mod->init_size_rx);
91871 + pax_close_kernel();
91872 + mod->module_init_rx = ptr;
91873 + } else
91874 + mod->module_init_rx = NULL;
91875
91876 /* Transfer each section which specifies SHF_ALLOC */
91877 pr_debug("final section addresses:\n");
91878 @@ -2826,16 +2927,45 @@ static int move_module(struct module *mod, struct load_info *info)
91879 if (!(shdr->sh_flags & SHF_ALLOC))
91880 continue;
91881
91882 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
91883 - dest = mod->module_init
91884 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
91885 - else
91886 - dest = mod->module_core + shdr->sh_entsize;
91887 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
91888 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
91889 + dest = mod->module_init_rw
91890 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
91891 + else
91892 + dest = mod->module_init_rx
91893 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
91894 + } else {
91895 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
91896 + dest = mod->module_core_rw + shdr->sh_entsize;
91897 + else
91898 + dest = mod->module_core_rx + shdr->sh_entsize;
91899 + }
91900 +
91901 + if (shdr->sh_type != SHT_NOBITS) {
91902 +
91903 +#ifdef CONFIG_PAX_KERNEXEC
91904 +#ifdef CONFIG_X86_64
91905 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
91906 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
91907 +#endif
91908 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
91909 + pax_open_kernel();
91910 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
91911 + pax_close_kernel();
91912 + } else
91913 +#endif
91914
91915 - if (shdr->sh_type != SHT_NOBITS)
91916 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
91917 + }
91918 /* Update sh_addr to point to copy in image. */
91919 - shdr->sh_addr = (unsigned long)dest;
91920 +
91921 +#ifdef CONFIG_PAX_KERNEXEC
91922 + if (shdr->sh_flags & SHF_EXECINSTR)
91923 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
91924 + else
91925 +#endif
91926 +
91927 + shdr->sh_addr = (unsigned long)dest;
91928 pr_debug("\t0x%lx %s\n",
91929 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
91930 }
91931 @@ -2892,12 +3022,12 @@ static void flush_module_icache(const struct module *mod)
91932 * Do it before processing of module parameters, so the module
91933 * can provide parameter accessor functions of its own.
91934 */
91935 - if (mod->module_init)
91936 - flush_icache_range((unsigned long)mod->module_init,
91937 - (unsigned long)mod->module_init
91938 - + mod->init_size);
91939 - flush_icache_range((unsigned long)mod->module_core,
91940 - (unsigned long)mod->module_core + mod->core_size);
91941 + if (mod->module_init_rx)
91942 + flush_icache_range((unsigned long)mod->module_init_rx,
91943 + (unsigned long)mod->module_init_rx
91944 + + mod->init_size_rx);
91945 + flush_icache_range((unsigned long)mod->module_core_rx,
91946 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
91947
91948 set_fs(old_fs);
91949 }
91950 @@ -2954,8 +3084,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
91951 static void module_deallocate(struct module *mod, struct load_info *info)
91952 {
91953 percpu_modfree(mod);
91954 - module_free(mod, mod->module_init);
91955 - module_free(mod, mod->module_core);
91956 + module_free_exec(mod, mod->module_init_rx);
91957 + module_free_exec(mod, mod->module_core_rx);
91958 + module_free(mod, mod->module_init_rw);
91959 + module_free(mod, mod->module_core_rw);
91960 }
91961
91962 int __weak module_finalize(const Elf_Ehdr *hdr,
91963 @@ -2968,7 +3100,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
91964 static int post_relocation(struct module *mod, const struct load_info *info)
91965 {
91966 /* Sort exception table now relocations are done. */
91967 + pax_open_kernel();
91968 sort_extable(mod->extable, mod->extable + mod->num_exentries);
91969 + pax_close_kernel();
91970
91971 /* Copy relocated percpu area over. */
91972 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
91973 @@ -3077,11 +3211,12 @@ static int do_init_module(struct module *mod)
91974 mod->strtab = mod->core_strtab;
91975 #endif
91976 unset_module_init_ro_nx(mod);
91977 - module_free(mod, mod->module_init);
91978 - mod->module_init = NULL;
91979 - mod->init_size = 0;
91980 - mod->init_ro_size = 0;
91981 - mod->init_text_size = 0;
91982 + module_free(mod, mod->module_init_rw);
91983 + module_free_exec(mod, mod->module_init_rx);
91984 + mod->module_init_rw = NULL;
91985 + mod->module_init_rx = NULL;
91986 + mod->init_size_rw = 0;
91987 + mod->init_size_rx = 0;
91988 mutex_unlock(&module_mutex);
91989 wake_up_all(&module_wq);
91990
91991 @@ -3149,16 +3284,16 @@ static int complete_formation(struct module *mod, struct load_info *info)
91992 module_bug_finalize(info->hdr, info->sechdrs, mod);
91993
91994 /* Set RO and NX regions for core */
91995 - set_section_ro_nx(mod->module_core,
91996 - mod->core_text_size,
91997 - mod->core_ro_size,
91998 - mod->core_size);
91999 + set_section_ro_nx(mod->module_core_rx,
92000 + mod->core_size_rx,
92001 + mod->core_size_rx,
92002 + mod->core_size_rx);
92003
92004 /* Set RO and NX regions for init */
92005 - set_section_ro_nx(mod->module_init,
92006 - mod->init_text_size,
92007 - mod->init_ro_size,
92008 - mod->init_size);
92009 + set_section_ro_nx(mod->module_init_rx,
92010 + mod->init_size_rx,
92011 + mod->init_size_rx,
92012 + mod->init_size_rx);
92013
92014 /* Mark state as coming so strong_try_module_get() ignores us,
92015 * but kallsyms etc. can see us. */
92016 @@ -3242,9 +3377,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
92017 if (err)
92018 goto free_unload;
92019
92020 + /* Now copy in args */
92021 + mod->args = strndup_user(uargs, ~0UL >> 1);
92022 + if (IS_ERR(mod->args)) {
92023 + err = PTR_ERR(mod->args);
92024 + goto free_unload;
92025 + }
92026 +
92027 /* Set up MODINFO_ATTR fields */
92028 setup_modinfo(mod, info);
92029
92030 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
92031 + {
92032 + char *p, *p2;
92033 +
92034 + if (strstr(mod->args, "grsec_modharden_netdev")) {
92035 + 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);
92036 + err = -EPERM;
92037 + goto free_modinfo;
92038 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
92039 + p += sizeof("grsec_modharden_normal") - 1;
92040 + p2 = strstr(p, "_");
92041 + if (p2) {
92042 + *p2 = '\0';
92043 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
92044 + *p2 = '_';
92045 + }
92046 + err = -EPERM;
92047 + goto free_modinfo;
92048 + }
92049 + }
92050 +#endif
92051 +
92052 /* Fix up syms, so that st_value is a pointer to location. */
92053 err = simplify_symbols(mod, info);
92054 if (err < 0)
92055 @@ -3260,13 +3424,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
92056
92057 flush_module_icache(mod);
92058
92059 - /* Now copy in args */
92060 - mod->args = strndup_user(uargs, ~0UL >> 1);
92061 - if (IS_ERR(mod->args)) {
92062 - err = PTR_ERR(mod->args);
92063 - goto free_arch_cleanup;
92064 - }
92065 -
92066 dynamic_debug_setup(info->debug, info->num_debug);
92067
92068 /* Ftrace init must be called in the MODULE_STATE_UNFORMED state */
92069 @@ -3314,11 +3471,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
92070 ddebug_cleanup:
92071 dynamic_debug_remove(info->debug);
92072 synchronize_sched();
92073 - kfree(mod->args);
92074 - free_arch_cleanup:
92075 module_arch_cleanup(mod);
92076 free_modinfo:
92077 free_modinfo(mod);
92078 + kfree(mod->args);
92079 free_unload:
92080 module_unload_free(mod);
92081 unlink_mod:
92082 @@ -3403,10 +3559,16 @@ static const char *get_ksymbol(struct module *mod,
92083 unsigned long nextval;
92084
92085 /* At worse, next value is at end of module */
92086 - if (within_module_init(addr, mod))
92087 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
92088 + if (within_module_init_rx(addr, mod))
92089 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
92090 + else if (within_module_init_rw(addr, mod))
92091 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
92092 + else if (within_module_core_rx(addr, mod))
92093 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
92094 + else if (within_module_core_rw(addr, mod))
92095 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
92096 else
92097 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
92098 + return NULL;
92099
92100 /* Scan for closest preceding symbol, and next symbol. (ELF
92101 starts real symbols at 1). */
92102 @@ -3654,7 +3816,7 @@ static int m_show(struct seq_file *m, void *p)
92103 return 0;
92104
92105 seq_printf(m, "%s %u",
92106 - mod->name, mod->init_size + mod->core_size);
92107 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
92108 print_unload_info(m, mod);
92109
92110 /* Informative for users. */
92111 @@ -3663,7 +3825,7 @@ static int m_show(struct seq_file *m, void *p)
92112 mod->state == MODULE_STATE_COMING ? "Loading":
92113 "Live");
92114 /* Used by oprofile and other similar tools. */
92115 - seq_printf(m, " 0x%pK", mod->module_core);
92116 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
92117
92118 /* Taints info */
92119 if (mod->taints)
92120 @@ -3699,7 +3861,17 @@ static const struct file_operations proc_modules_operations = {
92121
92122 static int __init proc_modules_init(void)
92123 {
92124 +#ifndef CONFIG_GRKERNSEC_HIDESYM
92125 +#ifdef CONFIG_GRKERNSEC_PROC_USER
92126 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
92127 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
92128 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
92129 +#else
92130 proc_create("modules", 0, NULL, &proc_modules_operations);
92131 +#endif
92132 +#else
92133 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
92134 +#endif
92135 return 0;
92136 }
92137 module_init(proc_modules_init);
92138 @@ -3760,7 +3932,8 @@ struct module *__module_address(unsigned long addr)
92139 {
92140 struct module *mod;
92141
92142 - if (addr < module_addr_min || addr > module_addr_max)
92143 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
92144 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
92145 return NULL;
92146
92147 list_for_each_entry_rcu(mod, &modules, list) {
92148 @@ -3801,11 +3974,20 @@ bool is_module_text_address(unsigned long addr)
92149 */
92150 struct module *__module_text_address(unsigned long addr)
92151 {
92152 - struct module *mod = __module_address(addr);
92153 + struct module *mod;
92154 +
92155 +#ifdef CONFIG_X86_32
92156 + addr = ktla_ktva(addr);
92157 +#endif
92158 +
92159 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
92160 + return NULL;
92161 +
92162 + mod = __module_address(addr);
92163 +
92164 if (mod) {
92165 /* Make sure it's within the text section. */
92166 - if (!within(addr, mod->module_init, mod->init_text_size)
92167 - && !within(addr, mod->module_core, mod->core_text_size))
92168 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
92169 mod = NULL;
92170 }
92171 return mod;
92172 diff --git a/kernel/notifier.c b/kernel/notifier.c
92173 index 4803da6..1c5eea6 100644
92174 --- a/kernel/notifier.c
92175 +++ b/kernel/notifier.c
92176 @@ -5,6 +5,7 @@
92177 #include <linux/rcupdate.h>
92178 #include <linux/vmalloc.h>
92179 #include <linux/reboot.h>
92180 +#include <linux/mm.h>
92181
92182 /*
92183 * Notifier list for kernel code which wants to be called
92184 @@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
92185 while ((*nl) != NULL) {
92186 if (n->priority > (*nl)->priority)
92187 break;
92188 - nl = &((*nl)->next);
92189 + nl = (struct notifier_block **)&((*nl)->next);
92190 }
92191 - n->next = *nl;
92192 + pax_open_kernel();
92193 + *(const void **)&n->next = *nl;
92194 rcu_assign_pointer(*nl, n);
92195 + pax_close_kernel();
92196 return 0;
92197 }
92198
92199 @@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
92200 return 0;
92201 if (n->priority > (*nl)->priority)
92202 break;
92203 - nl = &((*nl)->next);
92204 + nl = (struct notifier_block **)&((*nl)->next);
92205 }
92206 - n->next = *nl;
92207 + pax_open_kernel();
92208 + *(const void **)&n->next = *nl;
92209 rcu_assign_pointer(*nl, n);
92210 + pax_close_kernel();
92211 return 0;
92212 }
92213
92214 @@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
92215 {
92216 while ((*nl) != NULL) {
92217 if ((*nl) == n) {
92218 + pax_open_kernel();
92219 rcu_assign_pointer(*nl, n->next);
92220 + pax_close_kernel();
92221 return 0;
92222 }
92223 - nl = &((*nl)->next);
92224 + nl = (struct notifier_block **)&((*nl)->next);
92225 }
92226 return -ENOENT;
92227 }
92228 diff --git a/kernel/padata.c b/kernel/padata.c
92229 index 161402f..598814c 100644
92230 --- a/kernel/padata.c
92231 +++ b/kernel/padata.c
92232 @@ -54,7 +54,7 @@ static int padata_cpu_hash(struct parallel_data *pd)
92233 * seq_nr mod. number of cpus in use.
92234 */
92235
92236 - seq_nr = atomic_inc_return(&pd->seq_nr);
92237 + seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
92238 cpu_index = seq_nr % cpumask_weight(pd->cpumask.pcpu);
92239
92240 return padata_index_to_cpu(pd, cpu_index);
92241 @@ -428,7 +428,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
92242 padata_init_pqueues(pd);
92243 padata_init_squeues(pd);
92244 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
92245 - atomic_set(&pd->seq_nr, -1);
92246 + atomic_set_unchecked(&pd->seq_nr, -1);
92247 atomic_set(&pd->reorder_objects, 0);
92248 atomic_set(&pd->refcnt, 0);
92249 pd->pinst = pinst;
92250 diff --git a/kernel/panic.c b/kernel/panic.c
92251 index d09dc5c..9abbdff 100644
92252 --- a/kernel/panic.c
92253 +++ b/kernel/panic.c
92254 @@ -53,7 +53,7 @@ EXPORT_SYMBOL(panic_blink);
92255 /*
92256 * Stop ourself in panic -- architecture code may override this
92257 */
92258 -void __weak panic_smp_self_stop(void)
92259 +void __weak __noreturn panic_smp_self_stop(void)
92260 {
92261 while (1)
92262 cpu_relax();
92263 @@ -421,7 +421,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
92264 disable_trace_on_warning();
92265
92266 pr_warn("------------[ cut here ]------------\n");
92267 - pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
92268 + pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pA()\n",
92269 raw_smp_processor_id(), current->pid, file, line, caller);
92270
92271 if (args)
92272 @@ -475,7 +475,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
92273 */
92274 __visible void __stack_chk_fail(void)
92275 {
92276 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
92277 + dump_stack();
92278 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
92279 __builtin_return_address(0));
92280 }
92281 EXPORT_SYMBOL(__stack_chk_fail);
92282 diff --git a/kernel/pid.c b/kernel/pid.c
92283 index 9b9a266..c20ef80 100644
92284 --- a/kernel/pid.c
92285 +++ b/kernel/pid.c
92286 @@ -33,6 +33,7 @@
92287 #include <linux/rculist.h>
92288 #include <linux/bootmem.h>
92289 #include <linux/hash.h>
92290 +#include <linux/security.h>
92291 #include <linux/pid_namespace.h>
92292 #include <linux/init_task.h>
92293 #include <linux/syscalls.h>
92294 @@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
92295
92296 int pid_max = PID_MAX_DEFAULT;
92297
92298 -#define RESERVED_PIDS 300
92299 +#define RESERVED_PIDS 500
92300
92301 int pid_max_min = RESERVED_PIDS + 1;
92302 int pid_max_max = PID_MAX_LIMIT;
92303 @@ -445,10 +446,18 @@ EXPORT_SYMBOL(pid_task);
92304 */
92305 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
92306 {
92307 + struct task_struct *task;
92308 +
92309 rcu_lockdep_assert(rcu_read_lock_held(),
92310 "find_task_by_pid_ns() needs rcu_read_lock()"
92311 " protection");
92312 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
92313 +
92314 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
92315 +
92316 + if (gr_pid_is_chrooted(task))
92317 + return NULL;
92318 +
92319 + return task;
92320 }
92321
92322 struct task_struct *find_task_by_vpid(pid_t vnr)
92323 @@ -456,6 +465,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
92324 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
92325 }
92326
92327 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
92328 +{
92329 + rcu_lockdep_assert(rcu_read_lock_held(),
92330 + "find_task_by_pid_ns() needs rcu_read_lock()"
92331 + " protection");
92332 + return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
92333 +}
92334 +
92335 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
92336 {
92337 struct pid *pid;
92338 diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
92339 index db95d8e..a0ca23f 100644
92340 --- a/kernel/pid_namespace.c
92341 +++ b/kernel/pid_namespace.c
92342 @@ -253,7 +253,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
92343 void __user *buffer, size_t *lenp, loff_t *ppos)
92344 {
92345 struct pid_namespace *pid_ns = task_active_pid_ns(current);
92346 - struct ctl_table tmp = *table;
92347 + ctl_table_no_const tmp = *table;
92348
92349 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
92350 return -EPERM;
92351 diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
92352 index e4e4121..71faf14 100644
92353 --- a/kernel/power/Kconfig
92354 +++ b/kernel/power/Kconfig
92355 @@ -24,6 +24,8 @@ config HIBERNATE_CALLBACKS
92356 config HIBERNATION
92357 bool "Hibernation (aka 'suspend to disk')"
92358 depends on SWAP && ARCH_HIBERNATION_POSSIBLE
92359 + depends on !GRKERNSEC_KMEM
92360 + depends on !PAX_MEMORY_SANITIZE
92361 select HIBERNATE_CALLBACKS
92362 select LZO_COMPRESS
92363 select LZO_DECOMPRESS
92364 diff --git a/kernel/power/process.c b/kernel/power/process.c
92365 index 7a37cf3..3e4c1c8 100644
92366 --- a/kernel/power/process.c
92367 +++ b/kernel/power/process.c
92368 @@ -35,6 +35,7 @@ static int try_to_freeze_tasks(bool user_only)
92369 unsigned int elapsed_msecs;
92370 bool wakeup = false;
92371 int sleep_usecs = USEC_PER_MSEC;
92372 + bool timedout = false;
92373
92374 do_gettimeofday(&start);
92375
92376 @@ -45,13 +46,20 @@ static int try_to_freeze_tasks(bool user_only)
92377
92378 while (true) {
92379 todo = 0;
92380 + if (time_after(jiffies, end_time))
92381 + timedout = true;
92382 read_lock(&tasklist_lock);
92383 do_each_thread(g, p) {
92384 if (p == current || !freeze_task(p))
92385 continue;
92386
92387 - if (!freezer_should_skip(p))
92388 + if (!freezer_should_skip(p)) {
92389 todo++;
92390 + if (timedout) {
92391 + printk(KERN_ERR "Task refusing to freeze:\n");
92392 + sched_show_task(p);
92393 + }
92394 + }
92395 } while_each_thread(g, p);
92396 read_unlock(&tasklist_lock);
92397
92398 @@ -60,7 +68,7 @@ static int try_to_freeze_tasks(bool user_only)
92399 todo += wq_busy;
92400 }
92401
92402 - if (!todo || time_after(jiffies, end_time))
92403 + if (!todo || timedout)
92404 break;
92405
92406 if (pm_wakeup_pending()) {
92407 diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
92408 index 1ce7706..3b07c49 100644
92409 --- a/kernel/printk/printk.c
92410 +++ b/kernel/printk/printk.c
92411 @@ -490,6 +490,11 @@ static int check_syslog_permissions(int type, bool from_file)
92412 if (from_file && type != SYSLOG_ACTION_OPEN)
92413 return 0;
92414
92415 +#ifdef CONFIG_GRKERNSEC_DMESG
92416 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
92417 + return -EPERM;
92418 +#endif
92419 +
92420 if (syslog_action_restricted(type)) {
92421 if (capable(CAP_SYSLOG))
92422 return 0;
92423 diff --git a/kernel/profile.c b/kernel/profile.c
92424 index 54bf5ba..df6e0a2 100644
92425 --- a/kernel/profile.c
92426 +++ b/kernel/profile.c
92427 @@ -37,7 +37,7 @@ struct profile_hit {
92428 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
92429 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
92430
92431 -static atomic_t *prof_buffer;
92432 +static atomic_unchecked_t *prof_buffer;
92433 static unsigned long prof_len, prof_shift;
92434
92435 int prof_on __read_mostly;
92436 @@ -256,7 +256,7 @@ static void profile_flip_buffers(void)
92437 hits[i].pc = 0;
92438 continue;
92439 }
92440 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
92441 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
92442 hits[i].hits = hits[i].pc = 0;
92443 }
92444 }
92445 @@ -317,9 +317,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
92446 * Add the current hit(s) and flush the write-queue out
92447 * to the global buffer:
92448 */
92449 - atomic_add(nr_hits, &prof_buffer[pc]);
92450 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
92451 for (i = 0; i < NR_PROFILE_HIT; ++i) {
92452 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
92453 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
92454 hits[i].pc = hits[i].hits = 0;
92455 }
92456 out:
92457 @@ -394,7 +394,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
92458 {
92459 unsigned long pc;
92460 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
92461 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
92462 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
92463 }
92464 #endif /* !CONFIG_SMP */
92465
92466 @@ -490,7 +490,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
92467 return -EFAULT;
92468 buf++; p++; count--; read++;
92469 }
92470 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
92471 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
92472 if (copy_to_user(buf, (void *)pnt, count))
92473 return -EFAULT;
92474 read += count;
92475 @@ -521,7 +521,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
92476 }
92477 #endif
92478 profile_discard_flip_buffers();
92479 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
92480 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
92481 return count;
92482 }
92483
92484 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
92485 index 54e7522..5b82dd6 100644
92486 --- a/kernel/ptrace.c
92487 +++ b/kernel/ptrace.c
92488 @@ -321,7 +321,7 @@ static int ptrace_attach(struct task_struct *task, long request,
92489 if (seize)
92490 flags |= PT_SEIZED;
92491 rcu_read_lock();
92492 - if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
92493 + if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
92494 flags |= PT_PTRACE_CAP;
92495 rcu_read_unlock();
92496 task->ptrace = flags;
92497 @@ -532,7 +532,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
92498 break;
92499 return -EIO;
92500 }
92501 - if (copy_to_user(dst, buf, retval))
92502 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
92503 return -EFAULT;
92504 copied += retval;
92505 src += retval;
92506 @@ -800,7 +800,7 @@ int ptrace_request(struct task_struct *child, long request,
92507 bool seized = child->ptrace & PT_SEIZED;
92508 int ret = -EIO;
92509 siginfo_t siginfo, *si;
92510 - void __user *datavp = (void __user *) data;
92511 + void __user *datavp = (__force void __user *) data;
92512 unsigned long __user *datalp = datavp;
92513 unsigned long flags;
92514
92515 @@ -1046,14 +1046,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
92516 goto out;
92517 }
92518
92519 + if (gr_handle_ptrace(child, request)) {
92520 + ret = -EPERM;
92521 + goto out_put_task_struct;
92522 + }
92523 +
92524 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
92525 ret = ptrace_attach(child, request, addr, data);
92526 /*
92527 * Some architectures need to do book-keeping after
92528 * a ptrace attach.
92529 */
92530 - if (!ret)
92531 + if (!ret) {
92532 arch_ptrace_attach(child);
92533 + gr_audit_ptrace(child);
92534 + }
92535 goto out_put_task_struct;
92536 }
92537
92538 @@ -1081,7 +1088,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
92539 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
92540 if (copied != sizeof(tmp))
92541 return -EIO;
92542 - return put_user(tmp, (unsigned long __user *)data);
92543 + return put_user(tmp, (__force unsigned long __user *)data);
92544 }
92545
92546 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
92547 @@ -1175,7 +1182,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
92548 }
92549
92550 COMPAT_SYSCALL_DEFINE4(ptrace, compat_long_t, request, compat_long_t, pid,
92551 - compat_long_t, addr, compat_long_t, data)
92552 + compat_ulong_t, addr, compat_ulong_t, data)
92553 {
92554 struct task_struct *child;
92555 long ret;
92556 @@ -1191,14 +1198,21 @@ COMPAT_SYSCALL_DEFINE4(ptrace, compat_long_t, request, compat_long_t, pid,
92557 goto out;
92558 }
92559
92560 + if (gr_handle_ptrace(child, request)) {
92561 + ret = -EPERM;
92562 + goto out_put_task_struct;
92563 + }
92564 +
92565 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
92566 ret = ptrace_attach(child, request, addr, data);
92567 /*
92568 * Some architectures need to do book-keeping after
92569 * a ptrace attach.
92570 */
92571 - if (!ret)
92572 + if (!ret) {
92573 arch_ptrace_attach(child);
92574 + gr_audit_ptrace(child);
92575 + }
92576 goto out_put_task_struct;
92577 }
92578
92579 diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
92580 index 948a769..5ca842b 100644
92581 --- a/kernel/rcu/rcutorture.c
92582 +++ b/kernel/rcu/rcutorture.c
92583 @@ -124,12 +124,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1],
92584 rcu_torture_count) = { 0 };
92585 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1],
92586 rcu_torture_batch) = { 0 };
92587 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
92588 -static atomic_t n_rcu_torture_alloc;
92589 -static atomic_t n_rcu_torture_alloc_fail;
92590 -static atomic_t n_rcu_torture_free;
92591 -static atomic_t n_rcu_torture_mberror;
92592 -static atomic_t n_rcu_torture_error;
92593 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
92594 +static atomic_unchecked_t n_rcu_torture_alloc;
92595 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
92596 +static atomic_unchecked_t n_rcu_torture_free;
92597 +static atomic_unchecked_t n_rcu_torture_mberror;
92598 +static atomic_unchecked_t n_rcu_torture_error;
92599 static long n_rcu_torture_barrier_error;
92600 static long n_rcu_torture_boost_ktrerror;
92601 static long n_rcu_torture_boost_rterror;
92602 @@ -200,11 +200,11 @@ rcu_torture_alloc(void)
92603
92604 spin_lock_bh(&rcu_torture_lock);
92605 if (list_empty(&rcu_torture_freelist)) {
92606 - atomic_inc(&n_rcu_torture_alloc_fail);
92607 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
92608 spin_unlock_bh(&rcu_torture_lock);
92609 return NULL;
92610 }
92611 - atomic_inc(&n_rcu_torture_alloc);
92612 + atomic_inc_unchecked(&n_rcu_torture_alloc);
92613 p = rcu_torture_freelist.next;
92614 list_del_init(p);
92615 spin_unlock_bh(&rcu_torture_lock);
92616 @@ -217,7 +217,7 @@ rcu_torture_alloc(void)
92617 static void
92618 rcu_torture_free(struct rcu_torture *p)
92619 {
92620 - atomic_inc(&n_rcu_torture_free);
92621 + atomic_inc_unchecked(&n_rcu_torture_free);
92622 spin_lock_bh(&rcu_torture_lock);
92623 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
92624 spin_unlock_bh(&rcu_torture_lock);
92625 @@ -301,7 +301,7 @@ rcu_torture_pipe_update_one(struct rcu_torture *rp)
92626 i = rp->rtort_pipe_count;
92627 if (i > RCU_TORTURE_PIPE_LEN)
92628 i = RCU_TORTURE_PIPE_LEN;
92629 - atomic_inc(&rcu_torture_wcount[i]);
92630 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
92631 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
92632 rp->rtort_mbtest = 0;
92633 return true;
92634 @@ -808,7 +808,7 @@ rcu_torture_writer(void *arg)
92635 i = old_rp->rtort_pipe_count;
92636 if (i > RCU_TORTURE_PIPE_LEN)
92637 i = RCU_TORTURE_PIPE_LEN;
92638 - atomic_inc(&rcu_torture_wcount[i]);
92639 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
92640 old_rp->rtort_pipe_count++;
92641 switch (synctype[torture_random(&rand) % nsynctypes]) {
92642 case RTWS_DEF_FREE:
92643 @@ -926,7 +926,7 @@ static void rcu_torture_timer(unsigned long unused)
92644 return;
92645 }
92646 if (p->rtort_mbtest == 0)
92647 - atomic_inc(&n_rcu_torture_mberror);
92648 + atomic_inc_unchecked(&n_rcu_torture_mberror);
92649 spin_lock(&rand_lock);
92650 cur_ops->read_delay(&rand);
92651 n_rcu_torture_timers++;
92652 @@ -996,7 +996,7 @@ rcu_torture_reader(void *arg)
92653 continue;
92654 }
92655 if (p->rtort_mbtest == 0)
92656 - atomic_inc(&n_rcu_torture_mberror);
92657 + atomic_inc_unchecked(&n_rcu_torture_mberror);
92658 cur_ops->read_delay(&rand);
92659 preempt_disable();
92660 pipe_count = p->rtort_pipe_count;
92661 @@ -1054,15 +1054,15 @@ rcu_torture_printk(char *page)
92662 }
92663 page += sprintf(page, "%s%s ", torture_type, TORTURE_FLAG);
92664 page += sprintf(page,
92665 - "rtc: %p ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
92666 + "rtc: %pP ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
92667 rcu_torture_current,
92668 rcu_torture_current_version,
92669 list_empty(&rcu_torture_freelist),
92670 - atomic_read(&n_rcu_torture_alloc),
92671 - atomic_read(&n_rcu_torture_alloc_fail),
92672 - atomic_read(&n_rcu_torture_free));
92673 + atomic_read_unchecked(&n_rcu_torture_alloc),
92674 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
92675 + atomic_read_unchecked(&n_rcu_torture_free));
92676 page += sprintf(page, "rtmbe: %d rtbke: %ld rtbre: %ld ",
92677 - atomic_read(&n_rcu_torture_mberror),
92678 + atomic_read_unchecked(&n_rcu_torture_mberror),
92679 n_rcu_torture_boost_ktrerror,
92680 n_rcu_torture_boost_rterror);
92681 page += sprintf(page, "rtbf: %ld rtb: %ld nt: %ld ",
92682 @@ -1075,14 +1075,14 @@ rcu_torture_printk(char *page)
92683 n_barrier_attempts,
92684 n_rcu_torture_barrier_error);
92685 page += sprintf(page, "\n%s%s ", torture_type, TORTURE_FLAG);
92686 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
92687 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
92688 n_rcu_torture_barrier_error != 0 ||
92689 n_rcu_torture_boost_ktrerror != 0 ||
92690 n_rcu_torture_boost_rterror != 0 ||
92691 n_rcu_torture_boost_failure != 0 ||
92692 i > 1) {
92693 page += sprintf(page, "!!! ");
92694 - atomic_inc(&n_rcu_torture_error);
92695 + atomic_inc_unchecked(&n_rcu_torture_error);
92696 WARN_ON_ONCE(1);
92697 }
92698 page += sprintf(page, "Reader Pipe: ");
92699 @@ -1096,7 +1096,7 @@ rcu_torture_printk(char *page)
92700 page += sprintf(page, "Free-Block Circulation: ");
92701 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
92702 page += sprintf(page, " %d",
92703 - atomic_read(&rcu_torture_wcount[i]));
92704 + atomic_read_unchecked(&rcu_torture_wcount[i]));
92705 }
92706 page += sprintf(page, "\n");
92707 if (cur_ops->stats)
92708 @@ -1461,7 +1461,7 @@ rcu_torture_cleanup(void)
92709
92710 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
92711
92712 - if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
92713 + if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
92714 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
92715 else if (torture_onoff_failures())
92716 rcu_torture_print_module_parms(cur_ops,
92717 @@ -1584,18 +1584,18 @@ rcu_torture_init(void)
92718
92719 rcu_torture_current = NULL;
92720 rcu_torture_current_version = 0;
92721 - atomic_set(&n_rcu_torture_alloc, 0);
92722 - atomic_set(&n_rcu_torture_alloc_fail, 0);
92723 - atomic_set(&n_rcu_torture_free, 0);
92724 - atomic_set(&n_rcu_torture_mberror, 0);
92725 - atomic_set(&n_rcu_torture_error, 0);
92726 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
92727 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
92728 + atomic_set_unchecked(&n_rcu_torture_free, 0);
92729 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
92730 + atomic_set_unchecked(&n_rcu_torture_error, 0);
92731 n_rcu_torture_barrier_error = 0;
92732 n_rcu_torture_boost_ktrerror = 0;
92733 n_rcu_torture_boost_rterror = 0;
92734 n_rcu_torture_boost_failure = 0;
92735 n_rcu_torture_boosts = 0;
92736 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
92737 - atomic_set(&rcu_torture_wcount[i], 0);
92738 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
92739 for_each_possible_cpu(cpu) {
92740 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
92741 per_cpu(rcu_torture_count, cpu)[i] = 0;
92742 diff --git a/kernel/rcu/tiny.c b/kernel/rcu/tiny.c
92743 index d9efcc1..ea543e9 100644
92744 --- a/kernel/rcu/tiny.c
92745 +++ b/kernel/rcu/tiny.c
92746 @@ -42,7 +42,7 @@
92747 /* Forward declarations for tiny_plugin.h. */
92748 struct rcu_ctrlblk;
92749 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
92750 -static void rcu_process_callbacks(struct softirq_action *unused);
92751 +static void rcu_process_callbacks(void);
92752 static void __call_rcu(struct rcu_head *head,
92753 void (*func)(struct rcu_head *rcu),
92754 struct rcu_ctrlblk *rcp);
92755 @@ -308,7 +308,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
92756 false));
92757 }
92758
92759 -static void rcu_process_callbacks(struct softirq_action *unused)
92760 +static __latent_entropy void rcu_process_callbacks(void)
92761 {
92762 __rcu_process_callbacks(&rcu_sched_ctrlblk);
92763 __rcu_process_callbacks(&rcu_bh_ctrlblk);
92764 diff --git a/kernel/rcu/tiny_plugin.h b/kernel/rcu/tiny_plugin.h
92765 index 858c565..7efd915 100644
92766 --- a/kernel/rcu/tiny_plugin.h
92767 +++ b/kernel/rcu/tiny_plugin.h
92768 @@ -152,17 +152,17 @@ static void check_cpu_stall(struct rcu_ctrlblk *rcp)
92769 dump_stack();
92770 }
92771 if (*rcp->curtail && ULONG_CMP_GE(j, js))
92772 - ACCESS_ONCE(rcp->jiffies_stall) = jiffies +
92773 + ACCESS_ONCE_RW(rcp->jiffies_stall) = jiffies +
92774 3 * rcu_jiffies_till_stall_check() + 3;
92775 else if (ULONG_CMP_GE(j, js))
92776 - ACCESS_ONCE(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
92777 + ACCESS_ONCE_RW(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
92778 }
92779
92780 static void reset_cpu_stall_ticks(struct rcu_ctrlblk *rcp)
92781 {
92782 rcp->ticks_this_gp = 0;
92783 rcp->gp_start = jiffies;
92784 - ACCESS_ONCE(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
92785 + ACCESS_ONCE_RW(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
92786 }
92787
92788 static void check_cpu_stalls(void)
92789 diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
92790 index 89a404a..f42a019 100644
92791 --- a/kernel/rcu/tree.c
92792 +++ b/kernel/rcu/tree.c
92793 @@ -263,7 +263,7 @@ static void rcu_momentary_dyntick_idle(void)
92794 */
92795 rdtp = this_cpu_ptr(&rcu_dynticks);
92796 smp_mb__before_atomic(); /* Earlier stuff before QS. */
92797 - atomic_add(2, &rdtp->dynticks); /* QS. */
92798 + atomic_add_unchecked(2, &rdtp->dynticks); /* QS. */
92799 smp_mb__after_atomic(); /* Later stuff after QS. */
92800 break;
92801 }
92802 @@ -523,9 +523,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
92803 rcu_prepare_for_idle(smp_processor_id());
92804 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
92805 smp_mb__before_atomic(); /* See above. */
92806 - atomic_inc(&rdtp->dynticks);
92807 + atomic_inc_unchecked(&rdtp->dynticks);
92808 smp_mb__after_atomic(); /* Force ordering with next sojourn. */
92809 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
92810 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
92811
92812 /*
92813 * It is illegal to enter an extended quiescent state while
92814 @@ -643,10 +643,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
92815 int user)
92816 {
92817 smp_mb__before_atomic(); /* Force ordering w/previous sojourn. */
92818 - atomic_inc(&rdtp->dynticks);
92819 + atomic_inc_unchecked(&rdtp->dynticks);
92820 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
92821 smp_mb__after_atomic(); /* See above. */
92822 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
92823 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
92824 rcu_cleanup_after_idle(smp_processor_id());
92825 trace_rcu_dyntick(TPS("End"), oldval, rdtp->dynticks_nesting);
92826 if (!user && !is_idle_task(current)) {
92827 @@ -767,14 +767,14 @@ void rcu_nmi_enter(void)
92828 struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
92829
92830 if (rdtp->dynticks_nmi_nesting == 0 &&
92831 - (atomic_read(&rdtp->dynticks) & 0x1))
92832 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
92833 return;
92834 rdtp->dynticks_nmi_nesting++;
92835 smp_mb__before_atomic(); /* Force delay from prior write. */
92836 - atomic_inc(&rdtp->dynticks);
92837 + atomic_inc_unchecked(&rdtp->dynticks);
92838 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
92839 smp_mb__after_atomic(); /* See above. */
92840 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
92841 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
92842 }
92843
92844 /**
92845 @@ -793,9 +793,9 @@ void rcu_nmi_exit(void)
92846 return;
92847 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
92848 smp_mb__before_atomic(); /* See above. */
92849 - atomic_inc(&rdtp->dynticks);
92850 + atomic_inc_unchecked(&rdtp->dynticks);
92851 smp_mb__after_atomic(); /* Force delay to next write. */
92852 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
92853 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
92854 }
92855
92856 /**
92857 @@ -808,7 +808,7 @@ void rcu_nmi_exit(void)
92858 */
92859 bool notrace __rcu_is_watching(void)
92860 {
92861 - return atomic_read(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
92862 + return atomic_read_unchecked(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
92863 }
92864
92865 /**
92866 @@ -891,7 +891,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
92867 static int dyntick_save_progress_counter(struct rcu_data *rdp,
92868 bool *isidle, unsigned long *maxj)
92869 {
92870 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
92871 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
92872 rcu_sysidle_check_cpu(rdp, isidle, maxj);
92873 if ((rdp->dynticks_snap & 0x1) == 0) {
92874 trace_rcu_fqs(rdp->rsp->name, rdp->gpnum, rdp->cpu, TPS("dti"));
92875 @@ -920,7 +920,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
92876 int *rcrmp;
92877 unsigned int snap;
92878
92879 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
92880 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
92881 snap = (unsigned int)rdp->dynticks_snap;
92882
92883 /*
92884 @@ -983,10 +983,10 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
92885 rdp->rsp->gp_start + jiffies_till_sched_qs) ||
92886 ULONG_CMP_GE(jiffies, rdp->rsp->jiffies_resched)) {
92887 if (!(ACCESS_ONCE(*rcrmp) & rdp->rsp->flavor_mask)) {
92888 - ACCESS_ONCE(rdp->cond_resched_completed) =
92889 + ACCESS_ONCE_RW(rdp->cond_resched_completed) =
92890 ACCESS_ONCE(rdp->mynode->completed);
92891 smp_mb(); /* ->cond_resched_completed before *rcrmp. */
92892 - ACCESS_ONCE(*rcrmp) =
92893 + ACCESS_ONCE_RW(*rcrmp) =
92894 ACCESS_ONCE(*rcrmp) + rdp->rsp->flavor_mask;
92895 resched_cpu(rdp->cpu); /* Force CPU into scheduler. */
92896 rdp->rsp->jiffies_resched += 5; /* Enable beating. */
92897 @@ -1008,7 +1008,7 @@ static void record_gp_stall_check_time(struct rcu_state *rsp)
92898 rsp->gp_start = j;
92899 smp_wmb(); /* Record start time before stall time. */
92900 j1 = rcu_jiffies_till_stall_check();
92901 - ACCESS_ONCE(rsp->jiffies_stall) = j + j1;
92902 + ACCESS_ONCE_RW(rsp->jiffies_stall) = j + j1;
92903 rsp->jiffies_resched = j + j1 / 2;
92904 }
92905
92906 @@ -1049,7 +1049,7 @@ static void print_other_cpu_stall(struct rcu_state *rsp)
92907 raw_spin_unlock_irqrestore(&rnp->lock, flags);
92908 return;
92909 }
92910 - ACCESS_ONCE(rsp->jiffies_stall) = jiffies + 3 * rcu_jiffies_till_stall_check() + 3;
92911 + ACCESS_ONCE_RW(rsp->jiffies_stall) = jiffies + 3 * rcu_jiffies_till_stall_check() + 3;
92912 raw_spin_unlock_irqrestore(&rnp->lock, flags);
92913
92914 /*
92915 @@ -1126,7 +1126,7 @@ static void print_cpu_stall(struct rcu_state *rsp)
92916
92917 raw_spin_lock_irqsave(&rnp->lock, flags);
92918 if (ULONG_CMP_GE(jiffies, ACCESS_ONCE(rsp->jiffies_stall)))
92919 - ACCESS_ONCE(rsp->jiffies_stall) = jiffies +
92920 + ACCESS_ONCE_RW(rsp->jiffies_stall) = jiffies +
92921 3 * rcu_jiffies_till_stall_check() + 3;
92922 raw_spin_unlock_irqrestore(&rnp->lock, flags);
92923
92924 @@ -1210,7 +1210,7 @@ void rcu_cpu_stall_reset(void)
92925 struct rcu_state *rsp;
92926
92927 for_each_rcu_flavor(rsp)
92928 - ACCESS_ONCE(rsp->jiffies_stall) = jiffies + ULONG_MAX / 2;
92929 + ACCESS_ONCE_RW(rsp->jiffies_stall) = jiffies + ULONG_MAX / 2;
92930 }
92931
92932 /*
92933 @@ -1596,7 +1596,7 @@ static int rcu_gp_init(struct rcu_state *rsp)
92934 raw_spin_unlock_irq(&rnp->lock);
92935 return 0;
92936 }
92937 - ACCESS_ONCE(rsp->gp_flags) = 0; /* Clear all flags: New grace period. */
92938 + ACCESS_ONCE_RW(rsp->gp_flags) = 0; /* Clear all flags: New grace period. */
92939
92940 if (WARN_ON_ONCE(rcu_gp_in_progress(rsp))) {
92941 /*
92942 @@ -1637,9 +1637,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
92943 rdp = this_cpu_ptr(rsp->rda);
92944 rcu_preempt_check_blocked_tasks(rnp);
92945 rnp->qsmask = rnp->qsmaskinit;
92946 - ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
92947 + ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
92948 WARN_ON_ONCE(rnp->completed != rsp->completed);
92949 - ACCESS_ONCE(rnp->completed) = rsp->completed;
92950 + ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
92951 if (rnp == rdp->mynode)
92952 (void)__note_gp_changes(rsp, rnp, rdp);
92953 rcu_preempt_boost_start_gp(rnp);
92954 @@ -1684,7 +1684,7 @@ static int rcu_gp_fqs(struct rcu_state *rsp, int fqs_state_in)
92955 if (ACCESS_ONCE(rsp->gp_flags) & RCU_GP_FLAG_FQS) {
92956 raw_spin_lock_irq(&rnp->lock);
92957 smp_mb__after_unlock_lock();
92958 - ACCESS_ONCE(rsp->gp_flags) &= ~RCU_GP_FLAG_FQS;
92959 + ACCESS_ONCE_RW(rsp->gp_flags) &= ~RCU_GP_FLAG_FQS;
92960 raw_spin_unlock_irq(&rnp->lock);
92961 }
92962 return fqs_state;
92963 @@ -1729,7 +1729,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
92964 rcu_for_each_node_breadth_first(rsp, rnp) {
92965 raw_spin_lock_irq(&rnp->lock);
92966 smp_mb__after_unlock_lock();
92967 - ACCESS_ONCE(rnp->completed) = rsp->gpnum;
92968 + ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
92969 rdp = this_cpu_ptr(rsp->rda);
92970 if (rnp == rdp->mynode)
92971 needgp = __note_gp_changes(rsp, rnp, rdp) || needgp;
92972 @@ -1744,14 +1744,14 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
92973 rcu_nocb_gp_set(rnp, nocb);
92974
92975 /* Declare grace period done. */
92976 - ACCESS_ONCE(rsp->completed) = rsp->gpnum;
92977 + ACCESS_ONCE_RW(rsp->completed) = rsp->gpnum;
92978 trace_rcu_grace_period(rsp->name, rsp->completed, TPS("end"));
92979 rsp->fqs_state = RCU_GP_IDLE;
92980 rdp = this_cpu_ptr(rsp->rda);
92981 /* Advance CBs to reduce false positives below. */
92982 needgp = rcu_advance_cbs(rsp, rnp, rdp) || needgp;
92983 if (needgp || cpu_needs_another_gp(rsp, rdp)) {
92984 - ACCESS_ONCE(rsp->gp_flags) = RCU_GP_FLAG_INIT;
92985 + ACCESS_ONCE_RW(rsp->gp_flags) = RCU_GP_FLAG_INIT;
92986 trace_rcu_grace_period(rsp->name,
92987 ACCESS_ONCE(rsp->gpnum),
92988 TPS("newreq"));
92989 @@ -1876,7 +1876,7 @@ rcu_start_gp_advanced(struct rcu_state *rsp, struct rcu_node *rnp,
92990 */
92991 return false;
92992 }
92993 - ACCESS_ONCE(rsp->gp_flags) = RCU_GP_FLAG_INIT;
92994 + ACCESS_ONCE_RW(rsp->gp_flags) = RCU_GP_FLAG_INIT;
92995 trace_rcu_grace_period(rsp->name, ACCESS_ONCE(rsp->gpnum),
92996 TPS("newreq"));
92997
92998 @@ -2097,7 +2097,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
92999 rsp->qlen += rdp->qlen;
93000 rdp->n_cbs_orphaned += rdp->qlen;
93001 rdp->qlen_lazy = 0;
93002 - ACCESS_ONCE(rdp->qlen) = 0;
93003 + ACCESS_ONCE_RW(rdp->qlen) = 0;
93004 }
93005
93006 /*
93007 @@ -2344,7 +2344,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
93008 }
93009 smp_mb(); /* List handling before counting for rcu_barrier(). */
93010 rdp->qlen_lazy -= count_lazy;
93011 - ACCESS_ONCE(rdp->qlen) = rdp->qlen - count;
93012 + ACCESS_ONCE_RW(rdp->qlen) = rdp->qlen - count;
93013 rdp->n_cbs_invoked += count;
93014
93015 /* Reinstate batch limit if we have worked down the excess. */
93016 @@ -2505,7 +2505,7 @@ static void force_quiescent_state(struct rcu_state *rsp)
93017 raw_spin_unlock_irqrestore(&rnp_old->lock, flags);
93018 return; /* Someone beat us to it. */
93019 }
93020 - ACCESS_ONCE(rsp->gp_flags) |= RCU_GP_FLAG_FQS;
93021 + ACCESS_ONCE_RW(rsp->gp_flags) |= RCU_GP_FLAG_FQS;
93022 raw_spin_unlock_irqrestore(&rnp_old->lock, flags);
93023 rcu_gp_kthread_wake(rsp);
93024 }
93025 @@ -2550,7 +2550,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
93026 /*
93027 * Do RCU core processing for the current CPU.
93028 */
93029 -static void rcu_process_callbacks(struct softirq_action *unused)
93030 +static void rcu_process_callbacks(void)
93031 {
93032 struct rcu_state *rsp;
93033
93034 @@ -2662,7 +2662,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
93035 WARN_ON_ONCE((unsigned long)head & 0x1); /* Misaligned rcu_head! */
93036 if (debug_rcu_head_queue(head)) {
93037 /* Probable double call_rcu(), so leak the callback. */
93038 - ACCESS_ONCE(head->func) = rcu_leak_callback;
93039 + ACCESS_ONCE_RW(head->func) = rcu_leak_callback;
93040 WARN_ONCE(1, "__call_rcu(): Leaked duplicate callback\n");
93041 return;
93042 }
93043 @@ -2690,7 +2690,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
93044 local_irq_restore(flags);
93045 return;
93046 }
93047 - ACCESS_ONCE(rdp->qlen) = rdp->qlen + 1;
93048 + ACCESS_ONCE_RW(rdp->qlen) = rdp->qlen + 1;
93049 if (lazy)
93050 rdp->qlen_lazy++;
93051 else
93052 @@ -2965,11 +2965,11 @@ void synchronize_sched_expedited(void)
93053 * counter wrap on a 32-bit system. Quite a few more CPUs would of
93054 * course be required on a 64-bit system.
93055 */
93056 - if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
93057 + if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
93058 (ulong)atomic_long_read(&rsp->expedited_done) +
93059 ULONG_MAX / 8)) {
93060 synchronize_sched();
93061 - atomic_long_inc(&rsp->expedited_wrap);
93062 + atomic_long_inc_unchecked(&rsp->expedited_wrap);
93063 return;
93064 }
93065
93066 @@ -2977,7 +2977,7 @@ void synchronize_sched_expedited(void)
93067 * Take a ticket. Note that atomic_inc_return() implies a
93068 * full memory barrier.
93069 */
93070 - snap = atomic_long_inc_return(&rsp->expedited_start);
93071 + snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
93072 firstsnap = snap;
93073 get_online_cpus();
93074 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
93075 @@ -2990,14 +2990,14 @@ void synchronize_sched_expedited(void)
93076 synchronize_sched_expedited_cpu_stop,
93077 NULL) == -EAGAIN) {
93078 put_online_cpus();
93079 - atomic_long_inc(&rsp->expedited_tryfail);
93080 + atomic_long_inc_unchecked(&rsp->expedited_tryfail);
93081
93082 /* Check to see if someone else did our work for us. */
93083 s = atomic_long_read(&rsp->expedited_done);
93084 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
93085 /* ensure test happens before caller kfree */
93086 smp_mb__before_atomic(); /* ^^^ */
93087 - atomic_long_inc(&rsp->expedited_workdone1);
93088 + atomic_long_inc_unchecked(&rsp->expedited_workdone1);
93089 return;
93090 }
93091
93092 @@ -3006,7 +3006,7 @@ void synchronize_sched_expedited(void)
93093 udelay(trycount * num_online_cpus());
93094 } else {
93095 wait_rcu_gp(call_rcu_sched);
93096 - atomic_long_inc(&rsp->expedited_normal);
93097 + atomic_long_inc_unchecked(&rsp->expedited_normal);
93098 return;
93099 }
93100
93101 @@ -3015,7 +3015,7 @@ void synchronize_sched_expedited(void)
93102 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
93103 /* ensure test happens before caller kfree */
93104 smp_mb__before_atomic(); /* ^^^ */
93105 - atomic_long_inc(&rsp->expedited_workdone2);
93106 + atomic_long_inc_unchecked(&rsp->expedited_workdone2);
93107 return;
93108 }
93109
93110 @@ -3027,10 +3027,10 @@ void synchronize_sched_expedited(void)
93111 * period works for us.
93112 */
93113 get_online_cpus();
93114 - snap = atomic_long_read(&rsp->expedited_start);
93115 + snap = atomic_long_read_unchecked(&rsp->expedited_start);
93116 smp_mb(); /* ensure read is before try_stop_cpus(). */
93117 }
93118 - atomic_long_inc(&rsp->expedited_stoppedcpus);
93119 + atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
93120
93121 /*
93122 * Everyone up to our most recent fetch is covered by our grace
93123 @@ -3039,16 +3039,16 @@ void synchronize_sched_expedited(void)
93124 * than we did already did their update.
93125 */
93126 do {
93127 - atomic_long_inc(&rsp->expedited_done_tries);
93128 + atomic_long_inc_unchecked(&rsp->expedited_done_tries);
93129 s = atomic_long_read(&rsp->expedited_done);
93130 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
93131 /* ensure test happens before caller kfree */
93132 smp_mb__before_atomic(); /* ^^^ */
93133 - atomic_long_inc(&rsp->expedited_done_lost);
93134 + atomic_long_inc_unchecked(&rsp->expedited_done_lost);
93135 break;
93136 }
93137 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
93138 - atomic_long_inc(&rsp->expedited_done_exit);
93139 + atomic_long_inc_unchecked(&rsp->expedited_done_exit);
93140
93141 put_online_cpus();
93142 }
93143 @@ -3254,7 +3254,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
93144 * ACCESS_ONCE() to prevent the compiler from speculating
93145 * the increment to precede the early-exit check.
93146 */
93147 - ACCESS_ONCE(rsp->n_barrier_done) = rsp->n_barrier_done + 1;
93148 + ACCESS_ONCE_RW(rsp->n_barrier_done) = rsp->n_barrier_done + 1;
93149 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
93150 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
93151 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
93152 @@ -3304,7 +3304,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
93153
93154 /* Increment ->n_barrier_done to prevent duplicate work. */
93155 smp_mb(); /* Keep increment after above mechanism. */
93156 - ACCESS_ONCE(rsp->n_barrier_done) = rsp->n_barrier_done + 1;
93157 + ACCESS_ONCE_RW(rsp->n_barrier_done) = rsp->n_barrier_done + 1;
93158 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
93159 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
93160 smp_mb(); /* Keep increment before caller's subsequent code. */
93161 @@ -3349,10 +3349,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
93162 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
93163 init_callback_list(rdp);
93164 rdp->qlen_lazy = 0;
93165 - ACCESS_ONCE(rdp->qlen) = 0;
93166 + ACCESS_ONCE_RW(rdp->qlen) = 0;
93167 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
93168 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
93169 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
93170 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
93171 rdp->cpu = cpu;
93172 rdp->rsp = rsp;
93173 rcu_boot_init_nocb_percpu_data(rdp);
93174 @@ -3385,8 +3385,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp)
93175 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
93176 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
93177 rcu_sysidle_init_percpu_data(rdp->dynticks);
93178 - atomic_set(&rdp->dynticks->dynticks,
93179 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
93180 + atomic_set_unchecked(&rdp->dynticks->dynticks,
93181 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
93182 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
93183
93184 /* Add CPU to rcu_node bitmasks. */
93185 diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
93186 index 6a86eb7..022b506 100644
93187 --- a/kernel/rcu/tree.h
93188 +++ b/kernel/rcu/tree.h
93189 @@ -87,11 +87,11 @@ struct rcu_dynticks {
93190 long long dynticks_nesting; /* Track irq/process nesting level. */
93191 /* Process level is worth LLONG_MAX/2. */
93192 int dynticks_nmi_nesting; /* Track NMI nesting level. */
93193 - atomic_t dynticks; /* Even value for idle, else odd. */
93194 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
93195 #ifdef CONFIG_NO_HZ_FULL_SYSIDLE
93196 long long dynticks_idle_nesting;
93197 /* irq/process nesting level from idle. */
93198 - atomic_t dynticks_idle; /* Even value for idle, else odd. */
93199 + atomic_unchecked_t dynticks_idle;/* Even value for idle, else odd. */
93200 /* "Idle" excludes userspace execution. */
93201 unsigned long dynticks_idle_jiffies;
93202 /* End of last non-NMI non-idle period. */
93203 @@ -461,17 +461,17 @@ struct rcu_state {
93204 /* _rcu_barrier(). */
93205 /* End of fields guarded by barrier_mutex. */
93206
93207 - atomic_long_t expedited_start; /* Starting ticket. */
93208 - atomic_long_t expedited_done; /* Done ticket. */
93209 - atomic_long_t expedited_wrap; /* # near-wrap incidents. */
93210 - atomic_long_t expedited_tryfail; /* # acquisition failures. */
93211 - atomic_long_t expedited_workdone1; /* # done by others #1. */
93212 - atomic_long_t expedited_workdone2; /* # done by others #2. */
93213 - atomic_long_t expedited_normal; /* # fallbacks to normal. */
93214 - atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
93215 - atomic_long_t expedited_done_tries; /* # tries to update _done. */
93216 - atomic_long_t expedited_done_lost; /* # times beaten to _done. */
93217 - atomic_long_t expedited_done_exit; /* # times exited _done loop. */
93218 + atomic_long_unchecked_t expedited_start; /* Starting ticket. */
93219 + atomic_long_t expedited_done; /* Done ticket. */
93220 + atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
93221 + atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
93222 + atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
93223 + atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
93224 + atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
93225 + atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
93226 + atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
93227 + atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
93228 + atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
93229
93230 unsigned long jiffies_force_qs; /* Time at which to invoke */
93231 /* force_quiescent_state(). */
93232 diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
93233 index a7997e2..9787c9e 100644
93234 --- a/kernel/rcu/tree_plugin.h
93235 +++ b/kernel/rcu/tree_plugin.h
93236 @@ -735,7 +735,7 @@ static int rcu_preempted_readers_exp(struct rcu_node *rnp)
93237 static int sync_rcu_preempt_exp_done(struct rcu_node *rnp)
93238 {
93239 return !rcu_preempted_readers_exp(rnp) &&
93240 - ACCESS_ONCE(rnp->expmask) == 0;
93241 + ACCESS_ONCE_RW(rnp->expmask) == 0;
93242 }
93243
93244 /*
93245 @@ -897,7 +897,7 @@ void synchronize_rcu_expedited(void)
93246
93247 /* Clean up and exit. */
93248 smp_mb(); /* ensure expedited GP seen before counter increment. */
93249 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
93250 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
93251 unlock_mb_ret:
93252 mutex_unlock(&sync_rcu_preempt_exp_mutex);
93253 mb_ret:
93254 @@ -1452,7 +1452,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
93255 free_cpumask_var(cm);
93256 }
93257
93258 -static struct smp_hotplug_thread rcu_cpu_thread_spec = {
93259 +static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
93260 .store = &rcu_cpu_kthread_task,
93261 .thread_should_run = rcu_cpu_kthread_should_run,
93262 .thread_fn = rcu_cpu_kthread,
93263 @@ -1932,7 +1932,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
93264 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
93265 pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
93266 cpu, ticks_value, ticks_title,
93267 - atomic_read(&rdtp->dynticks) & 0xfff,
93268 + atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
93269 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
93270 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
93271 fast_no_hz);
93272 @@ -2076,7 +2076,7 @@ static void wake_nocb_leader(struct rcu_data *rdp, bool force)
93273 return;
93274 if (ACCESS_ONCE(rdp_leader->nocb_leader_sleep) || force) {
93275 /* Prior xchg orders against prior callback enqueue. */
93276 - ACCESS_ONCE(rdp_leader->nocb_leader_sleep) = false;
93277 + ACCESS_ONCE_RW(rdp_leader->nocb_leader_sleep) = false;
93278 wake_up(&rdp_leader->nocb_wq);
93279 }
93280 }
93281 @@ -2101,7 +2101,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
93282
93283 /* Enqueue the callback on the nocb list and update counts. */
93284 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
93285 - ACCESS_ONCE(*old_rhpp) = rhp;
93286 + ACCESS_ONCE_RW(*old_rhpp) = rhp;
93287 atomic_long_add(rhcount, &rdp->nocb_q_count);
93288 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
93289
93290 @@ -2272,7 +2272,7 @@ wait_again:
93291 continue; /* No CBs here, try next follower. */
93292
93293 /* Move callbacks to wait-for-GP list, which is empty. */
93294 - ACCESS_ONCE(rdp->nocb_head) = NULL;
93295 + ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
93296 rdp->nocb_gp_tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
93297 rdp->nocb_gp_count = atomic_long_xchg(&rdp->nocb_q_count, 0);
93298 rdp->nocb_gp_count_lazy =
93299 @@ -2398,7 +2398,7 @@ static int rcu_nocb_kthread(void *arg)
93300 list = ACCESS_ONCE(rdp->nocb_follower_head);
93301 BUG_ON(!list);
93302 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, "WokeNonEmpty");
93303 - ACCESS_ONCE(rdp->nocb_follower_head) = NULL;
93304 + ACCESS_ONCE_RW(rdp->nocb_follower_head) = NULL;
93305 tail = xchg(&rdp->nocb_follower_tail, &rdp->nocb_follower_head);
93306 c = atomic_long_xchg(&rdp->nocb_follower_count, 0);
93307 cl = atomic_long_xchg(&rdp->nocb_follower_count_lazy, 0);
93308 @@ -2428,8 +2428,8 @@ static int rcu_nocb_kthread(void *arg)
93309 list = next;
93310 }
93311 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
93312 - ACCESS_ONCE(rdp->nocb_p_count) -= c;
93313 - ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
93314 + ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
93315 + ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
93316 rdp->n_nocbs_invoked += c;
93317 }
93318 return 0;
93319 @@ -2446,7 +2446,7 @@ static void do_nocb_deferred_wakeup(struct rcu_data *rdp)
93320 {
93321 if (!rcu_nocb_need_deferred_wakeup(rdp))
93322 return;
93323 - ACCESS_ONCE(rdp->nocb_defer_wakeup) = false;
93324 + ACCESS_ONCE_RW(rdp->nocb_defer_wakeup) = false;
93325 wake_nocb_leader(rdp, false);
93326 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, TPS("DeferredWakeEmpty"));
93327 }
93328 @@ -2510,7 +2510,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
93329 t = kthread_run(rcu_nocb_kthread, rdp,
93330 "rcuo%c/%d", rsp->abbr, cpu);
93331 BUG_ON(IS_ERR(t));
93332 - ACCESS_ONCE(rdp->nocb_kthread) = t;
93333 + ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
93334 }
93335 }
93336
93337 @@ -2641,11 +2641,11 @@ static void rcu_sysidle_enter(struct rcu_dynticks *rdtp, int irq)
93338
93339 /* Record start of fully idle period. */
93340 j = jiffies;
93341 - ACCESS_ONCE(rdtp->dynticks_idle_jiffies) = j;
93342 + ACCESS_ONCE_RW(rdtp->dynticks_idle_jiffies) = j;
93343 smp_mb__before_atomic();
93344 - atomic_inc(&rdtp->dynticks_idle);
93345 + atomic_inc_unchecked(&rdtp->dynticks_idle);
93346 smp_mb__after_atomic();
93347 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks_idle) & 0x1);
93348 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1);
93349 }
93350
93351 /*
93352 @@ -2710,9 +2710,9 @@ static void rcu_sysidle_exit(struct rcu_dynticks *rdtp, int irq)
93353
93354 /* Record end of idle period. */
93355 smp_mb__before_atomic();
93356 - atomic_inc(&rdtp->dynticks_idle);
93357 + atomic_inc_unchecked(&rdtp->dynticks_idle);
93358 smp_mb__after_atomic();
93359 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks_idle) & 0x1));
93360 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1));
93361
93362 /*
93363 * If we are the timekeeping CPU, we are permitted to be non-idle
93364 @@ -2753,7 +2753,7 @@ static void rcu_sysidle_check_cpu(struct rcu_data *rdp, bool *isidle,
93365 WARN_ON_ONCE(smp_processor_id() != tick_do_timer_cpu);
93366
93367 /* Pick up current idle and NMI-nesting counter and check. */
93368 - cur = atomic_read(&rdtp->dynticks_idle);
93369 + cur = atomic_read_unchecked(&rdtp->dynticks_idle);
93370 if (cur & 0x1) {
93371 *isidle = false; /* We are not idle! */
93372 return;
93373 @@ -2802,7 +2802,7 @@ static void rcu_sysidle(unsigned long j)
93374 case RCU_SYSIDLE_NOT:
93375
93376 /* First time all are idle, so note a short idle period. */
93377 - ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_SHORT;
93378 + ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_SHORT;
93379 break;
93380
93381 case RCU_SYSIDLE_SHORT:
93382 @@ -2840,7 +2840,7 @@ static void rcu_sysidle_cancel(void)
93383 {
93384 smp_mb();
93385 if (full_sysidle_state > RCU_SYSIDLE_SHORT)
93386 - ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_NOT;
93387 + ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_NOT;
93388 }
93389
93390 /*
93391 @@ -2888,7 +2888,7 @@ static void rcu_sysidle_cb(struct rcu_head *rhp)
93392 smp_mb(); /* grace period precedes setting inuse. */
93393
93394 rshp = container_of(rhp, struct rcu_sysidle_head, rh);
93395 - ACCESS_ONCE(rshp->inuse) = 0;
93396 + ACCESS_ONCE_RW(rshp->inuse) = 0;
93397 }
93398
93399 /*
93400 diff --git a/kernel/rcu/tree_trace.c b/kernel/rcu/tree_trace.c
93401 index 5cdc62e..cc52e88 100644
93402 --- a/kernel/rcu/tree_trace.c
93403 +++ b/kernel/rcu/tree_trace.c
93404 @@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
93405 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
93406 rdp->passed_quiesce, rdp->qs_pending);
93407 seq_printf(m, " dt=%d/%llx/%d df=%lu",
93408 - atomic_read(&rdp->dynticks->dynticks),
93409 + atomic_read_unchecked(&rdp->dynticks->dynticks),
93410 rdp->dynticks->dynticks_nesting,
93411 rdp->dynticks->dynticks_nmi_nesting,
93412 rdp->dynticks_fqs);
93413 @@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
93414 struct rcu_state *rsp = (struct rcu_state *)m->private;
93415
93416 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",
93417 - atomic_long_read(&rsp->expedited_start),
93418 + atomic_long_read_unchecked(&rsp->expedited_start),
93419 atomic_long_read(&rsp->expedited_done),
93420 - atomic_long_read(&rsp->expedited_wrap),
93421 - atomic_long_read(&rsp->expedited_tryfail),
93422 - atomic_long_read(&rsp->expedited_workdone1),
93423 - atomic_long_read(&rsp->expedited_workdone2),
93424 - atomic_long_read(&rsp->expedited_normal),
93425 - atomic_long_read(&rsp->expedited_stoppedcpus),
93426 - atomic_long_read(&rsp->expedited_done_tries),
93427 - atomic_long_read(&rsp->expedited_done_lost),
93428 - atomic_long_read(&rsp->expedited_done_exit));
93429 + atomic_long_read_unchecked(&rsp->expedited_wrap),
93430 + atomic_long_read_unchecked(&rsp->expedited_tryfail),
93431 + atomic_long_read_unchecked(&rsp->expedited_workdone1),
93432 + atomic_long_read_unchecked(&rsp->expedited_workdone2),
93433 + atomic_long_read_unchecked(&rsp->expedited_normal),
93434 + atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
93435 + atomic_long_read_unchecked(&rsp->expedited_done_tries),
93436 + atomic_long_read_unchecked(&rsp->expedited_done_lost),
93437 + atomic_long_read_unchecked(&rsp->expedited_done_exit));
93438 return 0;
93439 }
93440
93441 diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c
93442 index 4056d79..c11741a 100644
93443 --- a/kernel/rcu/update.c
93444 +++ b/kernel/rcu/update.c
93445 @@ -308,10 +308,10 @@ int rcu_jiffies_till_stall_check(void)
93446 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
93447 */
93448 if (till_stall_check < 3) {
93449 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
93450 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
93451 till_stall_check = 3;
93452 } else if (till_stall_check > 300) {
93453 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
93454 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
93455 till_stall_check = 300;
93456 }
93457 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
93458 diff --git a/kernel/resource.c b/kernel/resource.c
93459 index 60c5a38..ed77193 100644
93460 --- a/kernel/resource.c
93461 +++ b/kernel/resource.c
93462 @@ -161,8 +161,18 @@ static const struct file_operations proc_iomem_operations = {
93463
93464 static int __init ioresources_init(void)
93465 {
93466 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
93467 +#ifdef CONFIG_GRKERNSEC_PROC_USER
93468 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
93469 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
93470 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
93471 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
93472 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
93473 +#endif
93474 +#else
93475 proc_create("ioports", 0, NULL, &proc_ioports_operations);
93476 proc_create("iomem", 0, NULL, &proc_iomem_operations);
93477 +#endif
93478 return 0;
93479 }
93480 __initcall(ioresources_init);
93481 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
93482 index e73efba..c9bfbd4 100644
93483 --- a/kernel/sched/auto_group.c
93484 +++ b/kernel/sched/auto_group.c
93485 @@ -11,7 +11,7 @@
93486
93487 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
93488 static struct autogroup autogroup_default;
93489 -static atomic_t autogroup_seq_nr;
93490 +static atomic_unchecked_t autogroup_seq_nr;
93491
93492 void __init autogroup_init(struct task_struct *init_task)
93493 {
93494 @@ -79,7 +79,7 @@ static inline struct autogroup *autogroup_create(void)
93495
93496 kref_init(&ag->kref);
93497 init_rwsem(&ag->lock);
93498 - ag->id = atomic_inc_return(&autogroup_seq_nr);
93499 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
93500 ag->tg = tg;
93501 #ifdef CONFIG_RT_GROUP_SCHED
93502 /*
93503 diff --git a/kernel/sched/completion.c b/kernel/sched/completion.c
93504 index a63f4dc..349bbb0 100644
93505 --- a/kernel/sched/completion.c
93506 +++ b/kernel/sched/completion.c
93507 @@ -204,7 +204,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
93508 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
93509 * or number of jiffies left till timeout) if completed.
93510 */
93511 -long __sched
93512 +long __sched __intentional_overflow(-1)
93513 wait_for_completion_interruptible_timeout(struct completion *x,
93514 unsigned long timeout)
93515 {
93516 @@ -221,7 +221,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
93517 *
93518 * Return: -ERESTARTSYS if interrupted, 0 if completed.
93519 */
93520 -int __sched wait_for_completion_killable(struct completion *x)
93521 +int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
93522 {
93523 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
93524 if (t == -ERESTARTSYS)
93525 @@ -242,7 +242,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
93526 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
93527 * or number of jiffies left till timeout) if completed.
93528 */
93529 -long __sched
93530 +long __sched __intentional_overflow(-1)
93531 wait_for_completion_killable_timeout(struct completion *x,
93532 unsigned long timeout)
93533 {
93534 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
93535 index 6d7cb91..420f2d2 100644
93536 --- a/kernel/sched/core.c
93537 +++ b/kernel/sched/core.c
93538 @@ -1857,7 +1857,7 @@ void set_numabalancing_state(bool enabled)
93539 int sysctl_numa_balancing(struct ctl_table *table, int write,
93540 void __user *buffer, size_t *lenp, loff_t *ppos)
93541 {
93542 - struct ctl_table t;
93543 + ctl_table_no_const t;
93544 int err;
93545 int state = numabalancing_enabled;
93546
93547 @@ -2324,8 +2324,10 @@ context_switch(struct rq *rq, struct task_struct *prev,
93548 next->active_mm = oldmm;
93549 atomic_inc(&oldmm->mm_count);
93550 enter_lazy_tlb(oldmm, next);
93551 - } else
93552 + } else {
93553 switch_mm(oldmm, mm, next);
93554 + populate_stack();
93555 + }
93556
93557 if (!prev->mm) {
93558 prev->active_mm = NULL;
93559 @@ -3107,6 +3109,8 @@ int can_nice(const struct task_struct *p, const int nice)
93560 /* convert nice value [19,-20] to rlimit style value [1,40] */
93561 int nice_rlim = nice_to_rlimit(nice);
93562
93563 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
93564 +
93565 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
93566 capable(CAP_SYS_NICE));
93567 }
93568 @@ -3133,7 +3137,8 @@ SYSCALL_DEFINE1(nice, int, increment)
93569 nice = task_nice(current) + increment;
93570
93571 nice = clamp_val(nice, MIN_NICE, MAX_NICE);
93572 - if (increment < 0 && !can_nice(current, nice))
93573 + if (increment < 0 && (!can_nice(current, nice) ||
93574 + gr_handle_chroot_nice()))
93575 return -EPERM;
93576
93577 retval = security_task_setnice(current, nice);
93578 @@ -3412,6 +3417,7 @@ recheck:
93579 if (policy != p->policy && !rlim_rtprio)
93580 return -EPERM;
93581
93582 + gr_learn_resource(p, RLIMIT_RTPRIO, attr->sched_priority, 1);
93583 /* can't increase priority */
93584 if (attr->sched_priority > p->rt_priority &&
93585 attr->sched_priority > rlim_rtprio)
93586 @@ -4802,6 +4808,7 @@ void idle_task_exit(void)
93587
93588 if (mm != &init_mm) {
93589 switch_mm(mm, &init_mm, current);
93590 + populate_stack();
93591 finish_arch_post_lock_switch();
93592 }
93593 mmdrop(mm);
93594 @@ -4897,7 +4904,7 @@ static void migrate_tasks(unsigned int dead_cpu)
93595
93596 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
93597
93598 -static struct ctl_table sd_ctl_dir[] = {
93599 +static ctl_table_no_const sd_ctl_dir[] __read_only = {
93600 {
93601 .procname = "sched_domain",
93602 .mode = 0555,
93603 @@ -4914,17 +4921,17 @@ static struct ctl_table sd_ctl_root[] = {
93604 {}
93605 };
93606
93607 -static struct ctl_table *sd_alloc_ctl_entry(int n)
93608 +static ctl_table_no_const *sd_alloc_ctl_entry(int n)
93609 {
93610 - struct ctl_table *entry =
93611 + ctl_table_no_const *entry =
93612 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
93613
93614 return entry;
93615 }
93616
93617 -static void sd_free_ctl_entry(struct ctl_table **tablep)
93618 +static void sd_free_ctl_entry(ctl_table_no_const *tablep)
93619 {
93620 - struct ctl_table *entry;
93621 + ctl_table_no_const *entry;
93622
93623 /*
93624 * In the intermediate directories, both the child directory and
93625 @@ -4932,22 +4939,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
93626 * will always be set. In the lowest directory the names are
93627 * static strings and all have proc handlers.
93628 */
93629 - for (entry = *tablep; entry->mode; entry++) {
93630 - if (entry->child)
93631 - sd_free_ctl_entry(&entry->child);
93632 + for (entry = tablep; entry->mode; entry++) {
93633 + if (entry->child) {
93634 + sd_free_ctl_entry(entry->child);
93635 + pax_open_kernel();
93636 + entry->child = NULL;
93637 + pax_close_kernel();
93638 + }
93639 if (entry->proc_handler == NULL)
93640 kfree(entry->procname);
93641 }
93642
93643 - kfree(*tablep);
93644 - *tablep = NULL;
93645 + kfree(tablep);
93646 }
93647
93648 static int min_load_idx = 0;
93649 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
93650
93651 static void
93652 -set_table_entry(struct ctl_table *entry,
93653 +set_table_entry(ctl_table_no_const *entry,
93654 const char *procname, void *data, int maxlen,
93655 umode_t mode, proc_handler *proc_handler,
93656 bool load_idx)
93657 @@ -4967,7 +4977,7 @@ set_table_entry(struct ctl_table *entry,
93658 static struct ctl_table *
93659 sd_alloc_ctl_domain_table(struct sched_domain *sd)
93660 {
93661 - struct ctl_table *table = sd_alloc_ctl_entry(14);
93662 + ctl_table_no_const *table = sd_alloc_ctl_entry(14);
93663
93664 if (table == NULL)
93665 return NULL;
93666 @@ -5005,9 +5015,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
93667 return table;
93668 }
93669
93670 -static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
93671 +static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
93672 {
93673 - struct ctl_table *entry, *table;
93674 + ctl_table_no_const *entry, *table;
93675 struct sched_domain *sd;
93676 int domain_num = 0, i;
93677 char buf[32];
93678 @@ -5034,11 +5044,13 @@ static struct ctl_table_header *sd_sysctl_header;
93679 static void register_sched_domain_sysctl(void)
93680 {
93681 int i, cpu_num = num_possible_cpus();
93682 - struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
93683 + ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
93684 char buf[32];
93685
93686 WARN_ON(sd_ctl_dir[0].child);
93687 + pax_open_kernel();
93688 sd_ctl_dir[0].child = entry;
93689 + pax_close_kernel();
93690
93691 if (entry == NULL)
93692 return;
93693 @@ -5061,8 +5073,12 @@ static void unregister_sched_domain_sysctl(void)
93694 if (sd_sysctl_header)
93695 unregister_sysctl_table(sd_sysctl_header);
93696 sd_sysctl_header = NULL;
93697 - if (sd_ctl_dir[0].child)
93698 - sd_free_ctl_entry(&sd_ctl_dir[0].child);
93699 + if (sd_ctl_dir[0].child) {
93700 + sd_free_ctl_entry(sd_ctl_dir[0].child);
93701 + pax_open_kernel();
93702 + sd_ctl_dir[0].child = NULL;
93703 + pax_close_kernel();
93704 + }
93705 }
93706 #else
93707 static void register_sched_domain_sysctl(void)
93708 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
93709 index bfa3c86..e58767c 100644
93710 --- a/kernel/sched/fair.c
93711 +++ b/kernel/sched/fair.c
93712 @@ -1873,7 +1873,7 @@ void task_numa_fault(int last_cpupid, int mem_node, int pages, int flags)
93713
93714 static void reset_ptenuma_scan(struct task_struct *p)
93715 {
93716 - ACCESS_ONCE(p->mm->numa_scan_seq)++;
93717 + ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
93718 p->mm->numa_scan_offset = 0;
93719 }
93720
93721 @@ -7339,7 +7339,7 @@ static void nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle) { }
93722 * run_rebalance_domains is triggered when needed from the scheduler tick.
93723 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
93724 */
93725 -static void run_rebalance_domains(struct softirq_action *h)
93726 +static __latent_entropy void run_rebalance_domains(void)
93727 {
93728 struct rq *this_rq = this_rq();
93729 enum cpu_idle_type idle = this_rq->idle_balance ?
93730 diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
93731 index 579712f..a338a9d 100644
93732 --- a/kernel/sched/sched.h
93733 +++ b/kernel/sched/sched.h
93734 @@ -1146,7 +1146,7 @@ struct sched_class {
93735 #ifdef CONFIG_FAIR_GROUP_SCHED
93736 void (*task_move_group) (struct task_struct *p, int on_rq);
93737 #endif
93738 -};
93739 +} __do_const;
93740
93741 static inline void put_prev_task(struct rq *rq, struct task_struct *prev)
93742 {
93743 diff --git a/kernel/seccomp.c b/kernel/seccomp.c
93744 index 44eb005..84922be 100644
93745 --- a/kernel/seccomp.c
93746 +++ b/kernel/seccomp.c
93747 @@ -395,16 +395,15 @@ static struct seccomp_filter *seccomp_prepare_filter(struct sock_fprog *fprog)
93748 if (!filter)
93749 goto free_prog;
93750
93751 - filter->prog = kzalloc(bpf_prog_size(new_len),
93752 - GFP_KERNEL|__GFP_NOWARN);
93753 + filter->prog = bpf_prog_alloc(bpf_prog_size(new_len), __GFP_NOWARN);
93754 if (!filter->prog)
93755 goto free_filter;
93756
93757 ret = bpf_convert_filter(fp, fprog->len, filter->prog->insnsi, &new_len);
93758 if (ret)
93759 goto free_filter_prog;
93760 - kfree(fp);
93761
93762 + kfree(fp);
93763 atomic_set(&filter->usage, 1);
93764 filter->prog->len = new_len;
93765
93766 @@ -413,7 +412,7 @@ static struct seccomp_filter *seccomp_prepare_filter(struct sock_fprog *fprog)
93767 return filter;
93768
93769 free_filter_prog:
93770 - kfree(filter->prog);
93771 + __bpf_prog_free(filter->prog);
93772 free_filter:
93773 kfree(filter);
93774 free_prog:
93775 diff --git a/kernel/signal.c b/kernel/signal.c
93776 index 8f0876f..1153a5a 100644
93777 --- a/kernel/signal.c
93778 +++ b/kernel/signal.c
93779 @@ -53,12 +53,12 @@ static struct kmem_cache *sigqueue_cachep;
93780
93781 int print_fatal_signals __read_mostly;
93782
93783 -static void __user *sig_handler(struct task_struct *t, int sig)
93784 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
93785 {
93786 return t->sighand->action[sig - 1].sa.sa_handler;
93787 }
93788
93789 -static int sig_handler_ignored(void __user *handler, int sig)
93790 +static int sig_handler_ignored(__sighandler_t handler, int sig)
93791 {
93792 /* Is it explicitly or implicitly ignored? */
93793 return handler == SIG_IGN ||
93794 @@ -67,7 +67,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
93795
93796 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
93797 {
93798 - void __user *handler;
93799 + __sighandler_t handler;
93800
93801 handler = sig_handler(t, sig);
93802
93803 @@ -372,6 +372,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
93804 atomic_inc(&user->sigpending);
93805 rcu_read_unlock();
93806
93807 + if (!override_rlimit)
93808 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
93809 +
93810 if (override_rlimit ||
93811 atomic_read(&user->sigpending) <=
93812 task_rlimit(t, RLIMIT_SIGPENDING)) {
93813 @@ -499,7 +502,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
93814
93815 int unhandled_signal(struct task_struct *tsk, int sig)
93816 {
93817 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
93818 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
93819 if (is_global_init(tsk))
93820 return 1;
93821 if (handler != SIG_IGN && handler != SIG_DFL)
93822 @@ -793,6 +796,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
93823 }
93824 }
93825
93826 + /* allow glibc communication via tgkill to other threads in our
93827 + thread group */
93828 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
93829 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
93830 + && gr_handle_signal(t, sig))
93831 + return -EPERM;
93832 +
93833 return security_task_kill(t, info, sig, 0);
93834 }
93835
93836 @@ -1176,7 +1186,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
93837 return send_signal(sig, info, p, 1);
93838 }
93839
93840 -static int
93841 +int
93842 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
93843 {
93844 return send_signal(sig, info, t, 0);
93845 @@ -1213,6 +1223,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
93846 unsigned long int flags;
93847 int ret, blocked, ignored;
93848 struct k_sigaction *action;
93849 + int is_unhandled = 0;
93850
93851 spin_lock_irqsave(&t->sighand->siglock, flags);
93852 action = &t->sighand->action[sig-1];
93853 @@ -1227,9 +1238,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
93854 }
93855 if (action->sa.sa_handler == SIG_DFL)
93856 t->signal->flags &= ~SIGNAL_UNKILLABLE;
93857 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
93858 + is_unhandled = 1;
93859 ret = specific_send_sig_info(sig, info, t);
93860 spin_unlock_irqrestore(&t->sighand->siglock, flags);
93861
93862 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
93863 + normal operation */
93864 + if (is_unhandled) {
93865 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
93866 + gr_handle_crash(t, sig);
93867 + }
93868 +
93869 return ret;
93870 }
93871
93872 @@ -1300,8 +1320,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
93873 ret = check_kill_permission(sig, info, p);
93874 rcu_read_unlock();
93875
93876 - if (!ret && sig)
93877 + if (!ret && sig) {
93878 ret = do_send_sig_info(sig, info, p, true);
93879 + if (!ret)
93880 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
93881 + }
93882
93883 return ret;
93884 }
93885 @@ -2903,7 +2926,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
93886 int error = -ESRCH;
93887
93888 rcu_read_lock();
93889 - p = find_task_by_vpid(pid);
93890 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
93891 + /* allow glibc communication via tgkill to other threads in our
93892 + thread group */
93893 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
93894 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
93895 + p = find_task_by_vpid_unrestricted(pid);
93896 + else
93897 +#endif
93898 + p = find_task_by_vpid(pid);
93899 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
93900 error = check_kill_permission(sig, info, p);
93901 /*
93902 @@ -3236,8 +3267,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
93903 }
93904 seg = get_fs();
93905 set_fs(KERNEL_DS);
93906 - ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
93907 - (stack_t __force __user *) &uoss,
93908 + ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
93909 + (stack_t __force_user *) &uoss,
93910 compat_user_stack_pointer());
93911 set_fs(seg);
93912 if (ret >= 0 && uoss_ptr) {
93913 diff --git a/kernel/smpboot.c b/kernel/smpboot.c
93914 index eb89e18..a4e6792 100644
93915 --- a/kernel/smpboot.c
93916 +++ b/kernel/smpboot.c
93917 @@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
93918 }
93919 smpboot_unpark_thread(plug_thread, cpu);
93920 }
93921 - list_add(&plug_thread->list, &hotplug_threads);
93922 + pax_list_add(&plug_thread->list, &hotplug_threads);
93923 out:
93924 mutex_unlock(&smpboot_threads_lock);
93925 return ret;
93926 @@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
93927 {
93928 get_online_cpus();
93929 mutex_lock(&smpboot_threads_lock);
93930 - list_del(&plug_thread->list);
93931 + pax_list_del(&plug_thread->list);
93932 smpboot_destroy_threads(plug_thread);
93933 mutex_unlock(&smpboot_threads_lock);
93934 put_online_cpus();
93935 diff --git a/kernel/softirq.c b/kernel/softirq.c
93936 index 5918d22..e95d1926 100644
93937 --- a/kernel/softirq.c
93938 +++ b/kernel/softirq.c
93939 @@ -53,7 +53,7 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
93940 EXPORT_SYMBOL(irq_stat);
93941 #endif
93942
93943 -static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
93944 +static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
93945
93946 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
93947
93948 @@ -266,7 +266,7 @@ restart:
93949 kstat_incr_softirqs_this_cpu(vec_nr);
93950
93951 trace_softirq_entry(vec_nr);
93952 - h->action(h);
93953 + h->action();
93954 trace_softirq_exit(vec_nr);
93955 if (unlikely(prev_count != preempt_count())) {
93956 pr_err("huh, entered softirq %u %s %p with preempt_count %08x, exited with %08x?\n",
93957 @@ -426,7 +426,7 @@ void __raise_softirq_irqoff(unsigned int nr)
93958 or_softirq_pending(1UL << nr);
93959 }
93960
93961 -void open_softirq(int nr, void (*action)(struct softirq_action *))
93962 +void __init open_softirq(int nr, void (*action)(void))
93963 {
93964 softirq_vec[nr].action = action;
93965 }
93966 @@ -478,7 +478,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
93967 }
93968 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
93969
93970 -static void tasklet_action(struct softirq_action *a)
93971 +static void tasklet_action(void)
93972 {
93973 struct tasklet_struct *list;
93974
93975 @@ -514,7 +514,7 @@ static void tasklet_action(struct softirq_action *a)
93976 }
93977 }
93978
93979 -static void tasklet_hi_action(struct softirq_action *a)
93980 +static __latent_entropy void tasklet_hi_action(void)
93981 {
93982 struct tasklet_struct *list;
93983
93984 @@ -741,7 +741,7 @@ static struct notifier_block cpu_nfb = {
93985 .notifier_call = cpu_callback
93986 };
93987
93988 -static struct smp_hotplug_thread softirq_threads = {
93989 +static struct smp_hotplug_thread softirq_threads __read_only = {
93990 .store = &ksoftirqd,
93991 .thread_should_run = ksoftirqd_should_run,
93992 .thread_fn = run_ksoftirqd,
93993 diff --git a/kernel/sys.c b/kernel/sys.c
93994 index ce81291..df2ca85 100644
93995 --- a/kernel/sys.c
93996 +++ b/kernel/sys.c
93997 @@ -148,6 +148,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
93998 error = -EACCES;
93999 goto out;
94000 }
94001 +
94002 + if (gr_handle_chroot_setpriority(p, niceval)) {
94003 + error = -EACCES;
94004 + goto out;
94005 + }
94006 +
94007 no_nice = security_task_setnice(p, niceval);
94008 if (no_nice) {
94009 error = no_nice;
94010 @@ -351,6 +357,20 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
94011 goto error;
94012 }
94013
94014 + if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
94015 + goto error;
94016 +
94017 + if (!gid_eq(new->gid, old->gid)) {
94018 + /* make sure we generate a learn log for what will
94019 + end up being a role transition after a full-learning
94020 + policy is generated
94021 + CAP_SETGID is required to perform a transition
94022 + we may not log a CAP_SETGID check above, e.g.
94023 + in the case where new rgid = old egid
94024 + */
94025 + gr_learn_cap(current, new, CAP_SETGID);
94026 + }
94027 +
94028 if (rgid != (gid_t) -1 ||
94029 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
94030 new->sgid = new->egid;
94031 @@ -386,6 +406,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
94032 old = current_cred();
94033
94034 retval = -EPERM;
94035 +
94036 + if (gr_check_group_change(kgid, kgid, kgid))
94037 + goto error;
94038 +
94039 if (ns_capable(old->user_ns, CAP_SETGID))
94040 new->gid = new->egid = new->sgid = new->fsgid = kgid;
94041 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
94042 @@ -403,7 +427,7 @@ error:
94043 /*
94044 * change the user struct in a credentials set to match the new UID
94045 */
94046 -static int set_user(struct cred *new)
94047 +int set_user(struct cred *new)
94048 {
94049 struct user_struct *new_user;
94050
94051 @@ -483,7 +507,18 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
94052 goto error;
94053 }
94054
94055 + if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
94056 + goto error;
94057 +
94058 if (!uid_eq(new->uid, old->uid)) {
94059 + /* make sure we generate a learn log for what will
94060 + end up being a role transition after a full-learning
94061 + policy is generated
94062 + CAP_SETUID is required to perform a transition
94063 + we may not log a CAP_SETUID check above, e.g.
94064 + in the case where new ruid = old euid
94065 + */
94066 + gr_learn_cap(current, new, CAP_SETUID);
94067 retval = set_user(new);
94068 if (retval < 0)
94069 goto error;
94070 @@ -533,6 +568,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
94071 old = current_cred();
94072
94073 retval = -EPERM;
94074 +
94075 + if (gr_check_crash_uid(kuid))
94076 + goto error;
94077 + if (gr_check_user_change(kuid, kuid, kuid))
94078 + goto error;
94079 +
94080 if (ns_capable(old->user_ns, CAP_SETUID)) {
94081 new->suid = new->uid = kuid;
94082 if (!uid_eq(kuid, old->uid)) {
94083 @@ -602,6 +643,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
94084 goto error;
94085 }
94086
94087 + if (gr_check_user_change(kruid, keuid, INVALID_UID))
94088 + goto error;
94089 +
94090 if (ruid != (uid_t) -1) {
94091 new->uid = kruid;
94092 if (!uid_eq(kruid, old->uid)) {
94093 @@ -684,6 +728,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
94094 goto error;
94095 }
94096
94097 + if (gr_check_group_change(krgid, kegid, INVALID_GID))
94098 + goto error;
94099 +
94100 if (rgid != (gid_t) -1)
94101 new->gid = krgid;
94102 if (egid != (gid_t) -1)
94103 @@ -745,12 +792,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
94104 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
94105 ns_capable(old->user_ns, CAP_SETUID)) {
94106 if (!uid_eq(kuid, old->fsuid)) {
94107 + if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
94108 + goto error;
94109 +
94110 new->fsuid = kuid;
94111 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
94112 goto change_okay;
94113 }
94114 }
94115
94116 +error:
94117 abort_creds(new);
94118 return old_fsuid;
94119
94120 @@ -783,12 +834,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
94121 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
94122 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
94123 ns_capable(old->user_ns, CAP_SETGID)) {
94124 + if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
94125 + goto error;
94126 +
94127 if (!gid_eq(kgid, old->fsgid)) {
94128 new->fsgid = kgid;
94129 goto change_okay;
94130 }
94131 }
94132
94133 +error:
94134 abort_creds(new);
94135 return old_fsgid;
94136
94137 @@ -1167,19 +1222,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
94138 return -EFAULT;
94139
94140 down_read(&uts_sem);
94141 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
94142 + error = __copy_to_user(name->sysname, &utsname()->sysname,
94143 __OLD_UTS_LEN);
94144 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
94145 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
94146 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
94147 __OLD_UTS_LEN);
94148 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
94149 - error |= __copy_to_user(&name->release, &utsname()->release,
94150 + error |= __copy_to_user(name->release, &utsname()->release,
94151 __OLD_UTS_LEN);
94152 error |= __put_user(0, name->release + __OLD_UTS_LEN);
94153 - error |= __copy_to_user(&name->version, &utsname()->version,
94154 + error |= __copy_to_user(name->version, &utsname()->version,
94155 __OLD_UTS_LEN);
94156 error |= __put_user(0, name->version + __OLD_UTS_LEN);
94157 - error |= __copy_to_user(&name->machine, &utsname()->machine,
94158 + error |= __copy_to_user(name->machine, &utsname()->machine,
94159 __OLD_UTS_LEN);
94160 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
94161 up_read(&uts_sem);
94162 @@ -1381,6 +1436,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
94163 */
94164 new_rlim->rlim_cur = 1;
94165 }
94166 + /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
94167 + is changed to a lower value. Since tasks can be created by the same
94168 + user in between this limit change and an execve by this task, force
94169 + a recheck only for this task by setting PF_NPROC_EXCEEDED
94170 + */
94171 + if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
94172 + tsk->flags |= PF_NPROC_EXCEEDED;
94173 }
94174 if (!retval) {
94175 if (old_rlim)
94176 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
94177 index 75875a7..cd8e838 100644
94178 --- a/kernel/sysctl.c
94179 +++ b/kernel/sysctl.c
94180 @@ -94,7 +94,6 @@
94181
94182
94183 #if defined(CONFIG_SYSCTL)
94184 -
94185 /* External variables not in a header file. */
94186 extern int max_threads;
94187 extern int suid_dumpable;
94188 @@ -115,19 +114,20 @@ extern int sysctl_nr_trim_pages;
94189
94190 /* Constants used for minimum and maximum */
94191 #ifdef CONFIG_LOCKUP_DETECTOR
94192 -static int sixty = 60;
94193 +static int sixty __read_only = 60;
94194 #endif
94195
94196 -static int __maybe_unused neg_one = -1;
94197 +static int __maybe_unused neg_one __read_only = -1;
94198
94199 -static int zero;
94200 -static int __maybe_unused one = 1;
94201 -static int __maybe_unused two = 2;
94202 -static int __maybe_unused four = 4;
94203 -static unsigned long one_ul = 1;
94204 -static int one_hundred = 100;
94205 +static int zero __read_only = 0;
94206 +static int __maybe_unused one __read_only = 1;
94207 +static int __maybe_unused two __read_only = 2;
94208 +static int __maybe_unused three __read_only = 3;
94209 +static int __maybe_unused four __read_only = 4;
94210 +static unsigned long one_ul __read_only = 1;
94211 +static int one_hundred __read_only = 100;
94212 #ifdef CONFIG_PRINTK
94213 -static int ten_thousand = 10000;
94214 +static int ten_thousand __read_only = 10000;
94215 #endif
94216
94217 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
94218 @@ -181,10 +181,8 @@ static int proc_taint(struct ctl_table *table, int write,
94219 void __user *buffer, size_t *lenp, loff_t *ppos);
94220 #endif
94221
94222 -#ifdef CONFIG_PRINTK
94223 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
94224 void __user *buffer, size_t *lenp, loff_t *ppos);
94225 -#endif
94226
94227 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
94228 void __user *buffer, size_t *lenp, loff_t *ppos);
94229 @@ -215,6 +213,8 @@ static int sysrq_sysctl_handler(struct ctl_table *table, int write,
94230
94231 #endif
94232
94233 +extern struct ctl_table grsecurity_table[];
94234 +
94235 static struct ctl_table kern_table[];
94236 static struct ctl_table vm_table[];
94237 static struct ctl_table fs_table[];
94238 @@ -229,6 +229,20 @@ extern struct ctl_table epoll_table[];
94239 int sysctl_legacy_va_layout;
94240 #endif
94241
94242 +#ifdef CONFIG_PAX_SOFTMODE
94243 +static struct ctl_table pax_table[] = {
94244 + {
94245 + .procname = "softmode",
94246 + .data = &pax_softmode,
94247 + .maxlen = sizeof(unsigned int),
94248 + .mode = 0600,
94249 + .proc_handler = &proc_dointvec,
94250 + },
94251 +
94252 + { }
94253 +};
94254 +#endif
94255 +
94256 /* The default sysctl tables: */
94257
94258 static struct ctl_table sysctl_base_table[] = {
94259 @@ -277,6 +291,22 @@ static int max_extfrag_threshold = 1000;
94260 #endif
94261
94262 static struct ctl_table kern_table[] = {
94263 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
94264 + {
94265 + .procname = "grsecurity",
94266 + .mode = 0500,
94267 + .child = grsecurity_table,
94268 + },
94269 +#endif
94270 +
94271 +#ifdef CONFIG_PAX_SOFTMODE
94272 + {
94273 + .procname = "pax",
94274 + .mode = 0500,
94275 + .child = pax_table,
94276 + },
94277 +#endif
94278 +
94279 {
94280 .procname = "sched_child_runs_first",
94281 .data = &sysctl_sched_child_runs_first,
94282 @@ -641,7 +671,7 @@ static struct ctl_table kern_table[] = {
94283 .data = &modprobe_path,
94284 .maxlen = KMOD_PATH_LEN,
94285 .mode = 0644,
94286 - .proc_handler = proc_dostring,
94287 + .proc_handler = proc_dostring_modpriv,
94288 },
94289 {
94290 .procname = "modules_disabled",
94291 @@ -808,16 +838,20 @@ static struct ctl_table kern_table[] = {
94292 .extra1 = &zero,
94293 .extra2 = &one,
94294 },
94295 +#endif
94296 {
94297 .procname = "kptr_restrict",
94298 .data = &kptr_restrict,
94299 .maxlen = sizeof(int),
94300 .mode = 0644,
94301 .proc_handler = proc_dointvec_minmax_sysadmin,
94302 +#ifdef CONFIG_GRKERNSEC_HIDESYM
94303 + .extra1 = &two,
94304 +#else
94305 .extra1 = &zero,
94306 +#endif
94307 .extra2 = &two,
94308 },
94309 -#endif
94310 {
94311 .procname = "ngroups_max",
94312 .data = &ngroups_max,
94313 @@ -1073,10 +1107,17 @@ static struct ctl_table kern_table[] = {
94314 */
94315 {
94316 .procname = "perf_event_paranoid",
94317 - .data = &sysctl_perf_event_paranoid,
94318 - .maxlen = sizeof(sysctl_perf_event_paranoid),
94319 + .data = &sysctl_perf_event_legitimately_concerned,
94320 + .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
94321 .mode = 0644,
94322 - .proc_handler = proc_dointvec,
94323 + /* go ahead, be a hero */
94324 + .proc_handler = proc_dointvec_minmax_sysadmin,
94325 + .extra1 = &neg_one,
94326 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
94327 + .extra2 = &three,
94328 +#else
94329 + .extra2 = &two,
94330 +#endif
94331 },
94332 {
94333 .procname = "perf_event_mlock_kb",
94334 @@ -1335,6 +1376,13 @@ static struct ctl_table vm_table[] = {
94335 .proc_handler = proc_dointvec_minmax,
94336 .extra1 = &zero,
94337 },
94338 + {
94339 + .procname = "heap_stack_gap",
94340 + .data = &sysctl_heap_stack_gap,
94341 + .maxlen = sizeof(sysctl_heap_stack_gap),
94342 + .mode = 0644,
94343 + .proc_handler = proc_doulongvec_minmax,
94344 + },
94345 #else
94346 {
94347 .procname = "nr_trim_pages",
94348 @@ -1824,6 +1872,16 @@ int proc_dostring(struct ctl_table *table, int write,
94349 (char __user *)buffer, lenp, ppos);
94350 }
94351
94352 +int proc_dostring_modpriv(struct ctl_table *table, int write,
94353 + void __user *buffer, size_t *lenp, loff_t *ppos)
94354 +{
94355 + if (write && !capable(CAP_SYS_MODULE))
94356 + return -EPERM;
94357 +
94358 + return _proc_do_string(table->data, table->maxlen, write,
94359 + buffer, lenp, ppos);
94360 +}
94361 +
94362 static size_t proc_skip_spaces(char **buf)
94363 {
94364 size_t ret;
94365 @@ -1929,6 +1987,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
94366 len = strlen(tmp);
94367 if (len > *size)
94368 len = *size;
94369 + if (len > sizeof(tmp))
94370 + len = sizeof(tmp);
94371 if (copy_to_user(*buf, tmp, len))
94372 return -EFAULT;
94373 *size -= len;
94374 @@ -2106,7 +2166,7 @@ int proc_dointvec(struct ctl_table *table, int write,
94375 static int proc_taint(struct ctl_table *table, int write,
94376 void __user *buffer, size_t *lenp, loff_t *ppos)
94377 {
94378 - struct ctl_table t;
94379 + ctl_table_no_const t;
94380 unsigned long tmptaint = get_taint();
94381 int err;
94382
94383 @@ -2134,7 +2194,6 @@ static int proc_taint(struct ctl_table *table, int write,
94384 return err;
94385 }
94386
94387 -#ifdef CONFIG_PRINTK
94388 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
94389 void __user *buffer, size_t *lenp, loff_t *ppos)
94390 {
94391 @@ -2143,7 +2202,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
94392
94393 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
94394 }
94395 -#endif
94396
94397 struct do_proc_dointvec_minmax_conv_param {
94398 int *min;
94399 @@ -2703,6 +2761,12 @@ int proc_dostring(struct ctl_table *table, int write,
94400 return -ENOSYS;
94401 }
94402
94403 +int proc_dostring_modpriv(struct ctl_table *table, int write,
94404 + void __user *buffer, size_t *lenp, loff_t *ppos)
94405 +{
94406 + return -ENOSYS;
94407 +}
94408 +
94409 int proc_dointvec(struct ctl_table *table, int write,
94410 void __user *buffer, size_t *lenp, loff_t *ppos)
94411 {
94412 @@ -2759,5 +2823,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
94413 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
94414 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
94415 EXPORT_SYMBOL(proc_dostring);
94416 +EXPORT_SYMBOL(proc_dostring_modpriv);
94417 EXPORT_SYMBOL(proc_doulongvec_minmax);
94418 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
94419 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
94420 index 13d2f7c..c93d0b0 100644
94421 --- a/kernel/taskstats.c
94422 +++ b/kernel/taskstats.c
94423 @@ -28,9 +28,12 @@
94424 #include <linux/fs.h>
94425 #include <linux/file.h>
94426 #include <linux/pid_namespace.h>
94427 +#include <linux/grsecurity.h>
94428 #include <net/genetlink.h>
94429 #include <linux/atomic.h>
94430
94431 +extern int gr_is_taskstats_denied(int pid);
94432 +
94433 /*
94434 * Maximum length of a cpumask that can be specified in
94435 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
94436 @@ -576,6 +579,9 @@ err:
94437
94438 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
94439 {
94440 + if (gr_is_taskstats_denied(current->pid))
94441 + return -EACCES;
94442 +
94443 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
94444 return cmd_attr_register_cpumask(info);
94445 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
94446 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
94447 index a7077d3..dd48a49 100644
94448 --- a/kernel/time/alarmtimer.c
94449 +++ b/kernel/time/alarmtimer.c
94450 @@ -823,7 +823,7 @@ static int __init alarmtimer_init(void)
94451 struct platform_device *pdev;
94452 int error = 0;
94453 int i;
94454 - struct k_clock alarm_clock = {
94455 + static struct k_clock alarm_clock = {
94456 .clock_getres = alarm_clock_getres,
94457 .clock_get = alarm_clock_get,
94458 .timer_create = alarm_timer_create,
94459 diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c
94460 index 1c2fe7d..ce7483d 100644
94461 --- a/kernel/time/hrtimer.c
94462 +++ b/kernel/time/hrtimer.c
94463 @@ -1399,7 +1399,7 @@ void hrtimer_peek_ahead_timers(void)
94464 local_irq_restore(flags);
94465 }
94466
94467 -static void run_hrtimer_softirq(struct softirq_action *h)
94468 +static __latent_entropy void run_hrtimer_softirq(void)
94469 {
94470 hrtimer_peek_ahead_timers();
94471 }
94472 diff --git a/kernel/time/posix-cpu-timers.c b/kernel/time/posix-cpu-timers.c
94473 index 3b89464..5e38379 100644
94474 --- a/kernel/time/posix-cpu-timers.c
94475 +++ b/kernel/time/posix-cpu-timers.c
94476 @@ -1464,14 +1464,14 @@ struct k_clock clock_posix_cpu = {
94477
94478 static __init int init_posix_cpu_timers(void)
94479 {
94480 - struct k_clock process = {
94481 + static struct k_clock process = {
94482 .clock_getres = process_cpu_clock_getres,
94483 .clock_get = process_cpu_clock_get,
94484 .timer_create = process_cpu_timer_create,
94485 .nsleep = process_cpu_nsleep,
94486 .nsleep_restart = process_cpu_nsleep_restart,
94487 };
94488 - struct k_clock thread = {
94489 + static struct k_clock thread = {
94490 .clock_getres = thread_cpu_clock_getres,
94491 .clock_get = thread_cpu_clock_get,
94492 .timer_create = thread_cpu_timer_create,
94493 diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
94494 index 31ea01f..7fc61ef 100644
94495 --- a/kernel/time/posix-timers.c
94496 +++ b/kernel/time/posix-timers.c
94497 @@ -43,6 +43,7 @@
94498 #include <linux/hash.h>
94499 #include <linux/posix-clock.h>
94500 #include <linux/posix-timers.h>
94501 +#include <linux/grsecurity.h>
94502 #include <linux/syscalls.h>
94503 #include <linux/wait.h>
94504 #include <linux/workqueue.h>
94505 @@ -124,7 +125,7 @@ static DEFINE_SPINLOCK(hash_lock);
94506 * which we beg off on and pass to do_sys_settimeofday().
94507 */
94508
94509 -static struct k_clock posix_clocks[MAX_CLOCKS];
94510 +static struct k_clock *posix_clocks[MAX_CLOCKS];
94511
94512 /*
94513 * These ones are defined below.
94514 @@ -277,7 +278,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
94515 */
94516 static __init int init_posix_timers(void)
94517 {
94518 - struct k_clock clock_realtime = {
94519 + static struct k_clock clock_realtime = {
94520 .clock_getres = hrtimer_get_res,
94521 .clock_get = posix_clock_realtime_get,
94522 .clock_set = posix_clock_realtime_set,
94523 @@ -289,7 +290,7 @@ static __init int init_posix_timers(void)
94524 .timer_get = common_timer_get,
94525 .timer_del = common_timer_del,
94526 };
94527 - struct k_clock clock_monotonic = {
94528 + static struct k_clock clock_monotonic = {
94529 .clock_getres = hrtimer_get_res,
94530 .clock_get = posix_ktime_get_ts,
94531 .nsleep = common_nsleep,
94532 @@ -299,19 +300,19 @@ static __init int init_posix_timers(void)
94533 .timer_get = common_timer_get,
94534 .timer_del = common_timer_del,
94535 };
94536 - struct k_clock clock_monotonic_raw = {
94537 + static struct k_clock clock_monotonic_raw = {
94538 .clock_getres = hrtimer_get_res,
94539 .clock_get = posix_get_monotonic_raw,
94540 };
94541 - struct k_clock clock_realtime_coarse = {
94542 + static struct k_clock clock_realtime_coarse = {
94543 .clock_getres = posix_get_coarse_res,
94544 .clock_get = posix_get_realtime_coarse,
94545 };
94546 - struct k_clock clock_monotonic_coarse = {
94547 + static struct k_clock clock_monotonic_coarse = {
94548 .clock_getres = posix_get_coarse_res,
94549 .clock_get = posix_get_monotonic_coarse,
94550 };
94551 - struct k_clock clock_tai = {
94552 + static struct k_clock clock_tai = {
94553 .clock_getres = hrtimer_get_res,
94554 .clock_get = posix_get_tai,
94555 .nsleep = common_nsleep,
94556 @@ -321,7 +322,7 @@ static __init int init_posix_timers(void)
94557 .timer_get = common_timer_get,
94558 .timer_del = common_timer_del,
94559 };
94560 - struct k_clock clock_boottime = {
94561 + static struct k_clock clock_boottime = {
94562 .clock_getres = hrtimer_get_res,
94563 .clock_get = posix_get_boottime,
94564 .nsleep = common_nsleep,
94565 @@ -533,7 +534,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
94566 return;
94567 }
94568
94569 - posix_clocks[clock_id] = *new_clock;
94570 + posix_clocks[clock_id] = new_clock;
94571 }
94572 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
94573
94574 @@ -579,9 +580,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
94575 return (id & CLOCKFD_MASK) == CLOCKFD ?
94576 &clock_posix_dynamic : &clock_posix_cpu;
94577
94578 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
94579 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
94580 return NULL;
94581 - return &posix_clocks[id];
94582 + return posix_clocks[id];
94583 }
94584
94585 static int common_timer_create(struct k_itimer *new_timer)
94586 @@ -599,7 +600,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
94587 struct k_clock *kc = clockid_to_kclock(which_clock);
94588 struct k_itimer *new_timer;
94589 int error, new_timer_id;
94590 - sigevent_t event;
94591 + sigevent_t event = { };
94592 int it_id_set = IT_ID_NOT_SET;
94593
94594 if (!kc)
94595 @@ -1014,6 +1015,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
94596 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
94597 return -EFAULT;
94598
94599 + /* only the CLOCK_REALTIME clock can be set, all other clocks
94600 + have their clock_set fptr set to a nosettime dummy function
94601 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
94602 + call common_clock_set, which calls do_sys_settimeofday, which
94603 + we hook
94604 + */
94605 +
94606 return kc->clock_set(which_clock, &new_tp);
94607 }
94608
94609 diff --git a/kernel/time/time.c b/kernel/time/time.c
94610 index a9ae20f..d3fbde7 100644
94611 --- a/kernel/time/time.c
94612 +++ b/kernel/time/time.c
94613 @@ -173,6 +173,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
94614 return error;
94615
94616 if (tz) {
94617 + /* we log in do_settimeofday called below, so don't log twice
94618 + */
94619 + if (!tv)
94620 + gr_log_timechange();
94621 +
94622 sys_tz = *tz;
94623 update_vsyscall_tz();
94624 if (firsttime) {
94625 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
94626 index ec1791f..6a086cd 100644
94627 --- a/kernel/time/timekeeping.c
94628 +++ b/kernel/time/timekeeping.c
94629 @@ -15,6 +15,7 @@
94630 #include <linux/init.h>
94631 #include <linux/mm.h>
94632 #include <linux/sched.h>
94633 +#include <linux/grsecurity.h>
94634 #include <linux/syscore_ops.h>
94635 #include <linux/clocksource.h>
94636 #include <linux/jiffies.h>
94637 @@ -717,6 +718,8 @@ int do_settimeofday(const struct timespec *tv)
94638 if (!timespec_valid_strict(tv))
94639 return -EINVAL;
94640
94641 + gr_log_timechange();
94642 +
94643 raw_spin_lock_irqsave(&timekeeper_lock, flags);
94644 write_seqcount_begin(&tk_core.seq);
94645
94646 diff --git a/kernel/time/timer.c b/kernel/time/timer.c
94647 index 9bbb834..3caa8ed 100644
94648 --- a/kernel/time/timer.c
94649 +++ b/kernel/time/timer.c
94650 @@ -1394,7 +1394,7 @@ void update_process_times(int user_tick)
94651 /*
94652 * This function runs timers and the timer-tq in bottom half context.
94653 */
94654 -static void run_timer_softirq(struct softirq_action *h)
94655 +static __latent_entropy void run_timer_softirq(void)
94656 {
94657 struct tvec_base *base = __this_cpu_read(tvec_bases);
94658
94659 @@ -1457,7 +1457,7 @@ static void process_timeout(unsigned long __data)
94660 *
94661 * In all cases the return value is guaranteed to be non-negative.
94662 */
94663 -signed long __sched schedule_timeout(signed long timeout)
94664 +signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
94665 {
94666 struct timer_list timer;
94667 unsigned long expire;
94668 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
94669 index 61ed862..3b52c65 100644
94670 --- a/kernel/time/timer_list.c
94671 +++ b/kernel/time/timer_list.c
94672 @@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
94673
94674 static void print_name_offset(struct seq_file *m, void *sym)
94675 {
94676 +#ifdef CONFIG_GRKERNSEC_HIDESYM
94677 + SEQ_printf(m, "<%p>", NULL);
94678 +#else
94679 char symname[KSYM_NAME_LEN];
94680
94681 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
94682 SEQ_printf(m, "<%pK>", sym);
94683 else
94684 SEQ_printf(m, "%s", symname);
94685 +#endif
94686 }
94687
94688 static void
94689 @@ -119,7 +123,11 @@ next_one:
94690 static void
94691 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
94692 {
94693 +#ifdef CONFIG_GRKERNSEC_HIDESYM
94694 + SEQ_printf(m, " .base: %p\n", NULL);
94695 +#else
94696 SEQ_printf(m, " .base: %pK\n", base);
94697 +#endif
94698 SEQ_printf(m, " .index: %d\n",
94699 base->index);
94700 SEQ_printf(m, " .resolution: %Lu nsecs\n",
94701 @@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
94702 {
94703 struct proc_dir_entry *pe;
94704
94705 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
94706 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
94707 +#else
94708 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
94709 +#endif
94710 if (!pe)
94711 return -ENOMEM;
94712 return 0;
94713 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
94714 index 1fb08f2..ca4bb1e 100644
94715 --- a/kernel/time/timer_stats.c
94716 +++ b/kernel/time/timer_stats.c
94717 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
94718 static unsigned long nr_entries;
94719 static struct entry entries[MAX_ENTRIES];
94720
94721 -static atomic_t overflow_count;
94722 +static atomic_unchecked_t overflow_count;
94723
94724 /*
94725 * The entries are in a hash-table, for fast lookup:
94726 @@ -140,7 +140,7 @@ static void reset_entries(void)
94727 nr_entries = 0;
94728 memset(entries, 0, sizeof(entries));
94729 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
94730 - atomic_set(&overflow_count, 0);
94731 + atomic_set_unchecked(&overflow_count, 0);
94732 }
94733
94734 static struct entry *alloc_entry(void)
94735 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
94736 if (likely(entry))
94737 entry->count++;
94738 else
94739 - atomic_inc(&overflow_count);
94740 + atomic_inc_unchecked(&overflow_count);
94741
94742 out_unlock:
94743 raw_spin_unlock_irqrestore(lock, flags);
94744 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
94745
94746 static void print_name_offset(struct seq_file *m, unsigned long addr)
94747 {
94748 +#ifdef CONFIG_GRKERNSEC_HIDESYM
94749 + seq_printf(m, "<%p>", NULL);
94750 +#else
94751 char symname[KSYM_NAME_LEN];
94752
94753 if (lookup_symbol_name(addr, symname) < 0)
94754 - seq_printf(m, "<%p>", (void *)addr);
94755 + seq_printf(m, "<%pK>", (void *)addr);
94756 else
94757 seq_printf(m, "%s", symname);
94758 +#endif
94759 }
94760
94761 static int tstats_show(struct seq_file *m, void *v)
94762 @@ -300,8 +304,8 @@ static int tstats_show(struct seq_file *m, void *v)
94763
94764 seq_puts(m, "Timer Stats Version: v0.3\n");
94765 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
94766 - if (atomic_read(&overflow_count))
94767 - seq_printf(m, "Overflow: %d entries\n", atomic_read(&overflow_count));
94768 + if (atomic_read_unchecked(&overflow_count))
94769 + seq_printf(m, "Overflow: %d entries\n", atomic_read_unchecked(&overflow_count));
94770 seq_printf(m, "Collection: %s\n", timer_stats_active ? "active" : "inactive");
94771
94772 for (i = 0; i < nr_entries; i++) {
94773 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
94774 {
94775 struct proc_dir_entry *pe;
94776
94777 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
94778 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
94779 +#else
94780 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
94781 +#endif
94782 if (!pe)
94783 return -ENOMEM;
94784 return 0;
94785 diff --git a/kernel/torture.c b/kernel/torture.c
94786 index d600af2..27a4e9d 100644
94787 --- a/kernel/torture.c
94788 +++ b/kernel/torture.c
94789 @@ -484,7 +484,7 @@ static int torture_shutdown_notify(struct notifier_block *unused1,
94790 mutex_lock(&fullstop_mutex);
94791 if (ACCESS_ONCE(fullstop) == FULLSTOP_DONTSTOP) {
94792 VERBOSE_TOROUT_STRING("Unscheduled system shutdown detected");
94793 - ACCESS_ONCE(fullstop) = FULLSTOP_SHUTDOWN;
94794 + ACCESS_ONCE_RW(fullstop) = FULLSTOP_SHUTDOWN;
94795 } else {
94796 pr_warn("Concurrent rmmod and shutdown illegal!\n");
94797 }
94798 @@ -551,14 +551,14 @@ static int torture_stutter(void *arg)
94799 if (!torture_must_stop()) {
94800 if (stutter > 1) {
94801 schedule_timeout_interruptible(stutter - 1);
94802 - ACCESS_ONCE(stutter_pause_test) = 2;
94803 + ACCESS_ONCE_RW(stutter_pause_test) = 2;
94804 }
94805 schedule_timeout_interruptible(1);
94806 - ACCESS_ONCE(stutter_pause_test) = 1;
94807 + ACCESS_ONCE_RW(stutter_pause_test) = 1;
94808 }
94809 if (!torture_must_stop())
94810 schedule_timeout_interruptible(stutter);
94811 - ACCESS_ONCE(stutter_pause_test) = 0;
94812 + ACCESS_ONCE_RW(stutter_pause_test) = 0;
94813 torture_shutdown_absorb("torture_stutter");
94814 } while (!torture_must_stop());
94815 torture_kthread_stopping("torture_stutter");
94816 @@ -645,7 +645,7 @@ bool torture_cleanup(void)
94817 schedule_timeout_uninterruptible(10);
94818 return true;
94819 }
94820 - ACCESS_ONCE(fullstop) = FULLSTOP_RMMOD;
94821 + ACCESS_ONCE_RW(fullstop) = FULLSTOP_RMMOD;
94822 mutex_unlock(&fullstop_mutex);
94823 torture_shutdown_cleanup();
94824 torture_shuffle_cleanup();
94825 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
94826 index c1bd4ad..4b861dc 100644
94827 --- a/kernel/trace/blktrace.c
94828 +++ b/kernel/trace/blktrace.c
94829 @@ -328,7 +328,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
94830 struct blk_trace *bt = filp->private_data;
94831 char buf[16];
94832
94833 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
94834 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
94835
94836 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
94837 }
94838 @@ -386,7 +386,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
94839 return 1;
94840
94841 bt = buf->chan->private_data;
94842 - atomic_inc(&bt->dropped);
94843 + atomic_inc_unchecked(&bt->dropped);
94844 return 0;
94845 }
94846
94847 @@ -487,7 +487,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
94848
94849 bt->dir = dir;
94850 bt->dev = dev;
94851 - atomic_set(&bt->dropped, 0);
94852 + atomic_set_unchecked(&bt->dropped, 0);
94853 INIT_LIST_HEAD(&bt->running_list);
94854
94855 ret = -EIO;
94856 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
94857 index 5916a8e..220c9c2 100644
94858 --- a/kernel/trace/ftrace.c
94859 +++ b/kernel/trace/ftrace.c
94860 @@ -2128,12 +2128,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
94861 if (unlikely(ftrace_disabled))
94862 return 0;
94863
94864 + ret = ftrace_arch_code_modify_prepare();
94865 + FTRACE_WARN_ON(ret);
94866 + if (ret)
94867 + return 0;
94868 +
94869 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
94870 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
94871 if (ret) {
94872 ftrace_bug(ret, ip);
94873 - return 0;
94874 }
94875 - return 1;
94876 + return ret ? 0 : 1;
94877 }
94878
94879 /*
94880 @@ -4458,8 +4463,10 @@ static int ftrace_process_locs(struct module *mod,
94881 if (!count)
94882 return 0;
94883
94884 + pax_open_kernel();
94885 sort(start, count, sizeof(*start),
94886 ftrace_cmp_ips, ftrace_swap_ips);
94887 + pax_close_kernel();
94888
94889 start_pg = ftrace_allocate_pages(count);
94890 if (!start_pg)
94891 @@ -5254,7 +5261,7 @@ static int alloc_retstack_tasklist(struct ftrace_ret_stack **ret_stack_list)
94892
94893 if (t->ret_stack == NULL) {
94894 atomic_set(&t->tracing_graph_pause, 0);
94895 - atomic_set(&t->trace_overrun, 0);
94896 + atomic_set_unchecked(&t->trace_overrun, 0);
94897 t->curr_ret_stack = -1;
94898 /* Make sure the tasks see the -1 first: */
94899 smp_wmb();
94900 @@ -5467,7 +5474,7 @@ static void
94901 graph_init_task(struct task_struct *t, struct ftrace_ret_stack *ret_stack)
94902 {
94903 atomic_set(&t->tracing_graph_pause, 0);
94904 - atomic_set(&t->trace_overrun, 0);
94905 + atomic_set_unchecked(&t->trace_overrun, 0);
94906 t->ftrace_timestamp = 0;
94907 /* make curr_ret_stack visible before we add the ret_stack */
94908 smp_wmb();
94909 diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
94910 index a56e07c..d46f0ba 100644
94911 --- a/kernel/trace/ring_buffer.c
94912 +++ b/kernel/trace/ring_buffer.c
94913 @@ -352,9 +352,9 @@ struct buffer_data_page {
94914 */
94915 struct buffer_page {
94916 struct list_head list; /* list of buffer pages */
94917 - local_t write; /* index for next write */
94918 + local_unchecked_t write; /* index for next write */
94919 unsigned read; /* index for next read */
94920 - local_t entries; /* entries on this page */
94921 + local_unchecked_t entries; /* entries on this page */
94922 unsigned long real_end; /* real end of data */
94923 struct buffer_data_page *page; /* Actual data page */
94924 };
94925 @@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
94926 unsigned long last_overrun;
94927 local_t entries_bytes;
94928 local_t entries;
94929 - local_t overrun;
94930 - local_t commit_overrun;
94931 + local_unchecked_t overrun;
94932 + local_unchecked_t commit_overrun;
94933 local_t dropped_events;
94934 local_t committing;
94935 local_t commits;
94936 @@ -1032,8 +1032,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
94937 *
94938 * We add a counter to the write field to denote this.
94939 */
94940 - old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
94941 - old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
94942 + old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
94943 + old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
94944
94945 /*
94946 * Just make sure we have seen our old_write and synchronize
94947 @@ -1061,8 +1061,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
94948 * cmpxchg to only update if an interrupt did not already
94949 * do it for us. If the cmpxchg fails, we don't care.
94950 */
94951 - (void)local_cmpxchg(&next_page->write, old_write, val);
94952 - (void)local_cmpxchg(&next_page->entries, old_entries, eval);
94953 + (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
94954 + (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
94955
94956 /*
94957 * No need to worry about races with clearing out the commit.
94958 @@ -1429,12 +1429,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
94959
94960 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
94961 {
94962 - return local_read(&bpage->entries) & RB_WRITE_MASK;
94963 + return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
94964 }
94965
94966 static inline unsigned long rb_page_write(struct buffer_page *bpage)
94967 {
94968 - return local_read(&bpage->write) & RB_WRITE_MASK;
94969 + return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
94970 }
94971
94972 static int
94973 @@ -1529,7 +1529,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
94974 * bytes consumed in ring buffer from here.
94975 * Increment overrun to account for the lost events.
94976 */
94977 - local_add(page_entries, &cpu_buffer->overrun);
94978 + local_add_unchecked(page_entries, &cpu_buffer->overrun);
94979 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
94980 }
94981
94982 @@ -2091,7 +2091,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
94983 * it is our responsibility to update
94984 * the counters.
94985 */
94986 - local_add(entries, &cpu_buffer->overrun);
94987 + local_add_unchecked(entries, &cpu_buffer->overrun);
94988 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
94989
94990 /*
94991 @@ -2241,7 +2241,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
94992 if (tail == BUF_PAGE_SIZE)
94993 tail_page->real_end = 0;
94994
94995 - local_sub(length, &tail_page->write);
94996 + local_sub_unchecked(length, &tail_page->write);
94997 return;
94998 }
94999
95000 @@ -2276,7 +2276,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
95001 rb_event_set_padding(event);
95002
95003 /* Set the write back to the previous setting */
95004 - local_sub(length, &tail_page->write);
95005 + local_sub_unchecked(length, &tail_page->write);
95006 return;
95007 }
95008
95009 @@ -2288,7 +2288,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
95010
95011 /* Set write to end of buffer */
95012 length = (tail + length) - BUF_PAGE_SIZE;
95013 - local_sub(length, &tail_page->write);
95014 + local_sub_unchecked(length, &tail_page->write);
95015 }
95016
95017 /*
95018 @@ -2314,7 +2314,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
95019 * about it.
95020 */
95021 if (unlikely(next_page == commit_page)) {
95022 - local_inc(&cpu_buffer->commit_overrun);
95023 + local_inc_unchecked(&cpu_buffer->commit_overrun);
95024 goto out_reset;
95025 }
95026
95027 @@ -2370,7 +2370,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
95028 cpu_buffer->tail_page) &&
95029 (cpu_buffer->commit_page ==
95030 cpu_buffer->reader_page))) {
95031 - local_inc(&cpu_buffer->commit_overrun);
95032 + local_inc_unchecked(&cpu_buffer->commit_overrun);
95033 goto out_reset;
95034 }
95035 }
95036 @@ -2418,7 +2418,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
95037 length += RB_LEN_TIME_EXTEND;
95038
95039 tail_page = cpu_buffer->tail_page;
95040 - write = local_add_return(length, &tail_page->write);
95041 + write = local_add_return_unchecked(length, &tail_page->write);
95042
95043 /* set write to only the index of the write */
95044 write &= RB_WRITE_MASK;
95045 @@ -2442,7 +2442,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
95046 kmemcheck_annotate_bitfield(event, bitfield);
95047 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
95048
95049 - local_inc(&tail_page->entries);
95050 + local_inc_unchecked(&tail_page->entries);
95051
95052 /*
95053 * If this is the first commit on the page, then update
95054 @@ -2475,7 +2475,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
95055
95056 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
95057 unsigned long write_mask =
95058 - local_read(&bpage->write) & ~RB_WRITE_MASK;
95059 + local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
95060 unsigned long event_length = rb_event_length(event);
95061 /*
95062 * This is on the tail page. It is possible that
95063 @@ -2485,7 +2485,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
95064 */
95065 old_index += write_mask;
95066 new_index += write_mask;
95067 - index = local_cmpxchg(&bpage->write, old_index, new_index);
95068 + index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
95069 if (index == old_index) {
95070 /* update counters */
95071 local_sub(event_length, &cpu_buffer->entries_bytes);
95072 @@ -2877,7 +2877,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
95073
95074 /* Do the likely case first */
95075 if (likely(bpage->page == (void *)addr)) {
95076 - local_dec(&bpage->entries);
95077 + local_dec_unchecked(&bpage->entries);
95078 return;
95079 }
95080
95081 @@ -2889,7 +2889,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
95082 start = bpage;
95083 do {
95084 if (bpage->page == (void *)addr) {
95085 - local_dec(&bpage->entries);
95086 + local_dec_unchecked(&bpage->entries);
95087 return;
95088 }
95089 rb_inc_page(cpu_buffer, &bpage);
95090 @@ -3173,7 +3173,7 @@ static inline unsigned long
95091 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
95092 {
95093 return local_read(&cpu_buffer->entries) -
95094 - (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
95095 + (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
95096 }
95097
95098 /**
95099 @@ -3262,7 +3262,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
95100 return 0;
95101
95102 cpu_buffer = buffer->buffers[cpu];
95103 - ret = local_read(&cpu_buffer->overrun);
95104 + ret = local_read_unchecked(&cpu_buffer->overrun);
95105
95106 return ret;
95107 }
95108 @@ -3285,7 +3285,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
95109 return 0;
95110
95111 cpu_buffer = buffer->buffers[cpu];
95112 - ret = local_read(&cpu_buffer->commit_overrun);
95113 + ret = local_read_unchecked(&cpu_buffer->commit_overrun);
95114
95115 return ret;
95116 }
95117 @@ -3370,7 +3370,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
95118 /* if you care about this being correct, lock the buffer */
95119 for_each_buffer_cpu(buffer, cpu) {
95120 cpu_buffer = buffer->buffers[cpu];
95121 - overruns += local_read(&cpu_buffer->overrun);
95122 + overruns += local_read_unchecked(&cpu_buffer->overrun);
95123 }
95124
95125 return overruns;
95126 @@ -3541,8 +3541,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
95127 /*
95128 * Reset the reader page to size zero.
95129 */
95130 - local_set(&cpu_buffer->reader_page->write, 0);
95131 - local_set(&cpu_buffer->reader_page->entries, 0);
95132 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
95133 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
95134 local_set(&cpu_buffer->reader_page->page->commit, 0);
95135 cpu_buffer->reader_page->real_end = 0;
95136
95137 @@ -3576,7 +3576,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
95138 * want to compare with the last_overrun.
95139 */
95140 smp_mb();
95141 - overwrite = local_read(&(cpu_buffer->overrun));
95142 + overwrite = local_read_unchecked(&(cpu_buffer->overrun));
95143
95144 /*
95145 * Here's the tricky part.
95146 @@ -4148,8 +4148,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
95147
95148 cpu_buffer->head_page
95149 = list_entry(cpu_buffer->pages, struct buffer_page, list);
95150 - local_set(&cpu_buffer->head_page->write, 0);
95151 - local_set(&cpu_buffer->head_page->entries, 0);
95152 + local_set_unchecked(&cpu_buffer->head_page->write, 0);
95153 + local_set_unchecked(&cpu_buffer->head_page->entries, 0);
95154 local_set(&cpu_buffer->head_page->page->commit, 0);
95155
95156 cpu_buffer->head_page->read = 0;
95157 @@ -4159,14 +4159,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
95158
95159 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
95160 INIT_LIST_HEAD(&cpu_buffer->new_pages);
95161 - local_set(&cpu_buffer->reader_page->write, 0);
95162 - local_set(&cpu_buffer->reader_page->entries, 0);
95163 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
95164 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
95165 local_set(&cpu_buffer->reader_page->page->commit, 0);
95166 cpu_buffer->reader_page->read = 0;
95167
95168 local_set(&cpu_buffer->entries_bytes, 0);
95169 - local_set(&cpu_buffer->overrun, 0);
95170 - local_set(&cpu_buffer->commit_overrun, 0);
95171 + local_set_unchecked(&cpu_buffer->overrun, 0);
95172 + local_set_unchecked(&cpu_buffer->commit_overrun, 0);
95173 local_set(&cpu_buffer->dropped_events, 0);
95174 local_set(&cpu_buffer->entries, 0);
95175 local_set(&cpu_buffer->committing, 0);
95176 @@ -4571,8 +4571,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
95177 rb_init_page(bpage);
95178 bpage = reader->page;
95179 reader->page = *data_page;
95180 - local_set(&reader->write, 0);
95181 - local_set(&reader->entries, 0);
95182 + local_set_unchecked(&reader->write, 0);
95183 + local_set_unchecked(&reader->entries, 0);
95184 reader->read = 0;
95185 *data_page = bpage;
95186
95187 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
95188 index 1520933..c651ebc 100644
95189 --- a/kernel/trace/trace.c
95190 +++ b/kernel/trace/trace.c
95191 @@ -3488,7 +3488,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
95192 return 0;
95193 }
95194
95195 -int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
95196 +int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
95197 {
95198 /* do nothing if flag is already set */
95199 if (!!(trace_flags & mask) == !!enabled)
95200 diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
95201 index 385391f..8d2250f 100644
95202 --- a/kernel/trace/trace.h
95203 +++ b/kernel/trace/trace.h
95204 @@ -1280,7 +1280,7 @@ extern const char *__stop___tracepoint_str[];
95205 void trace_printk_init_buffers(void);
95206 void trace_printk_start_comm(void);
95207 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
95208 -int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
95209 +int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
95210
95211 /*
95212 * Normal trace_printk() and friends allocates special buffers
95213 diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
95214 index 57b67b1..66082a9 100644
95215 --- a/kernel/trace/trace_clock.c
95216 +++ b/kernel/trace/trace_clock.c
95217 @@ -124,7 +124,7 @@ u64 notrace trace_clock_global(void)
95218 return now;
95219 }
95220
95221 -static atomic64_t trace_counter;
95222 +static atomic64_unchecked_t trace_counter;
95223
95224 /*
95225 * trace_clock_counter(): simply an atomic counter.
95226 @@ -133,5 +133,5 @@ static atomic64_t trace_counter;
95227 */
95228 u64 notrace trace_clock_counter(void)
95229 {
95230 - return atomic64_add_return(1, &trace_counter);
95231 + return atomic64_inc_return_unchecked(&trace_counter);
95232 }
95233 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
95234 index ef06ce7..3ea161d 100644
95235 --- a/kernel/trace/trace_events.c
95236 +++ b/kernel/trace/trace_events.c
95237 @@ -1720,7 +1720,6 @@ __trace_early_add_new_event(struct ftrace_event_call *call,
95238 return 0;
95239 }
95240
95241 -struct ftrace_module_file_ops;
95242 static void __add_event_to_tracers(struct ftrace_event_call *call);
95243
95244 /* Add an additional event_call dynamically */
95245 diff --git a/kernel/trace/trace_functions_graph.c b/kernel/trace/trace_functions_graph.c
95246 index f0a0c98..3692dc8 100644
95247 --- a/kernel/trace/trace_functions_graph.c
95248 +++ b/kernel/trace/trace_functions_graph.c
95249 @@ -133,7 +133,7 @@ ftrace_push_return_trace(unsigned long ret, unsigned long func, int *depth,
95250
95251 /* The return trace stack is full */
95252 if (current->curr_ret_stack == FTRACE_RETFUNC_DEPTH - 1) {
95253 - atomic_inc(&current->trace_overrun);
95254 + atomic_inc_unchecked(&current->trace_overrun);
95255 return -EBUSY;
95256 }
95257
95258 @@ -230,7 +230,7 @@ ftrace_pop_return_trace(struct ftrace_graph_ret *trace, unsigned long *ret,
95259 *ret = current->ret_stack[index].ret;
95260 trace->func = current->ret_stack[index].func;
95261 trace->calltime = current->ret_stack[index].calltime;
95262 - trace->overrun = atomic_read(&current->trace_overrun);
95263 + trace->overrun = atomic_read_unchecked(&current->trace_overrun);
95264 trace->depth = index;
95265 }
95266
95267 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
95268 index 0abd9b8..6a663a2 100644
95269 --- a/kernel/trace/trace_mmiotrace.c
95270 +++ b/kernel/trace/trace_mmiotrace.c
95271 @@ -24,7 +24,7 @@ struct header_iter {
95272 static struct trace_array *mmio_trace_array;
95273 static bool overrun_detected;
95274 static unsigned long prev_overruns;
95275 -static atomic_t dropped_count;
95276 +static atomic_unchecked_t dropped_count;
95277
95278 static void mmio_reset_data(struct trace_array *tr)
95279 {
95280 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
95281
95282 static unsigned long count_overruns(struct trace_iterator *iter)
95283 {
95284 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
95285 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
95286 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
95287
95288 if (over > prev_overruns)
95289 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
95290 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
95291 sizeof(*entry), 0, pc);
95292 if (!event) {
95293 - atomic_inc(&dropped_count);
95294 + atomic_inc_unchecked(&dropped_count);
95295 return;
95296 }
95297 entry = ring_buffer_event_data(event);
95298 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
95299 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
95300 sizeof(*entry), 0, pc);
95301 if (!event) {
95302 - atomic_inc(&dropped_count);
95303 + atomic_inc_unchecked(&dropped_count);
95304 return;
95305 }
95306 entry = ring_buffer_event_data(event);
95307 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
95308 index c6977d5..d243785 100644
95309 --- a/kernel/trace/trace_output.c
95310 +++ b/kernel/trace/trace_output.c
95311 @@ -712,14 +712,16 @@ int register_ftrace_event(struct trace_event *event)
95312 goto out;
95313 }
95314
95315 + pax_open_kernel();
95316 if (event->funcs->trace == NULL)
95317 - event->funcs->trace = trace_nop_print;
95318 + *(void **)&event->funcs->trace = trace_nop_print;
95319 if (event->funcs->raw == NULL)
95320 - event->funcs->raw = trace_nop_print;
95321 + *(void **)&event->funcs->raw = trace_nop_print;
95322 if (event->funcs->hex == NULL)
95323 - event->funcs->hex = trace_nop_print;
95324 + *(void **)&event->funcs->hex = trace_nop_print;
95325 if (event->funcs->binary == NULL)
95326 - event->funcs->binary = trace_nop_print;
95327 + *(void **)&event->funcs->binary = trace_nop_print;
95328 + pax_close_kernel();
95329
95330 key = event->type & (EVENT_HASHSIZE - 1);
95331
95332 diff --git a/kernel/trace/trace_seq.c b/kernel/trace/trace_seq.c
95333 index 1f24ed9..10407ec 100644
95334 --- a/kernel/trace/trace_seq.c
95335 +++ b/kernel/trace/trace_seq.c
95336 @@ -367,7 +367,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
95337
95338 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
95339 if (!IS_ERR(p)) {
95340 - p = mangle_path(s->buffer + s->len, p, "\n");
95341 + p = mangle_path(s->buffer + s->len, p, "\n\\");
95342 if (p) {
95343 s->len = p - s->buffer;
95344 return 1;
95345 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
95346 index 8a4e5cb..64f270d 100644
95347 --- a/kernel/trace/trace_stack.c
95348 +++ b/kernel/trace/trace_stack.c
95349 @@ -91,7 +91,7 @@ check_stack(unsigned long ip, unsigned long *stack)
95350 return;
95351
95352 /* we do not handle interrupt stacks yet */
95353 - if (!object_is_on_stack(stack))
95354 + if (!object_starts_on_stack(stack))
95355 return;
95356
95357 local_irq_save(flags);
95358 diff --git a/kernel/trace/trace_syscalls.c b/kernel/trace/trace_syscalls.c
95359 index 7e3cd7a..5156a5fe 100644
95360 --- a/kernel/trace/trace_syscalls.c
95361 +++ b/kernel/trace/trace_syscalls.c
95362 @@ -602,6 +602,8 @@ static int perf_sysenter_enable(struct ftrace_event_call *call)
95363 int num;
95364
95365 num = ((struct syscall_metadata *)call->data)->syscall_nr;
95366 + if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls))
95367 + return -EINVAL;
95368
95369 mutex_lock(&syscall_trace_lock);
95370 if (!sys_perf_refcount_enter)
95371 @@ -622,6 +624,8 @@ static void perf_sysenter_disable(struct ftrace_event_call *call)
95372 int num;
95373
95374 num = ((struct syscall_metadata *)call->data)->syscall_nr;
95375 + if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls))
95376 + return;
95377
95378 mutex_lock(&syscall_trace_lock);
95379 sys_perf_refcount_enter--;
95380 @@ -674,6 +678,8 @@ static int perf_sysexit_enable(struct ftrace_event_call *call)
95381 int num;
95382
95383 num = ((struct syscall_metadata *)call->data)->syscall_nr;
95384 + if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls))
95385 + return -EINVAL;
95386
95387 mutex_lock(&syscall_trace_lock);
95388 if (!sys_perf_refcount_exit)
95389 @@ -694,6 +700,8 @@ static void perf_sysexit_disable(struct ftrace_event_call *call)
95390 int num;
95391
95392 num = ((struct syscall_metadata *)call->data)->syscall_nr;
95393 + if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls))
95394 + return;
95395
95396 mutex_lock(&syscall_trace_lock);
95397 sys_perf_refcount_exit--;
95398 diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
95399 index aa312b0..395f343 100644
95400 --- a/kernel/user_namespace.c
95401 +++ b/kernel/user_namespace.c
95402 @@ -82,6 +82,21 @@ int create_user_ns(struct cred *new)
95403 !kgid_has_mapping(parent_ns, group))
95404 return -EPERM;
95405
95406 +#ifdef CONFIG_GRKERNSEC
95407 + /*
95408 + * This doesn't really inspire confidence:
95409 + * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
95410 + * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
95411 + * Increases kernel attack surface in areas developers
95412 + * previously cared little about ("low importance due
95413 + * to requiring "root" capability")
95414 + * To be removed when this code receives *proper* review
95415 + */
95416 + if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
95417 + !capable(CAP_SETGID))
95418 + return -EPERM;
95419 +#endif
95420 +
95421 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
95422 if (!ns)
95423 return -ENOMEM;
95424 @@ -872,7 +887,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
95425 if (atomic_read(&current->mm->mm_users) > 1)
95426 return -EINVAL;
95427
95428 - if (current->fs->users != 1)
95429 + if (atomic_read(&current->fs->users) != 1)
95430 return -EINVAL;
95431
95432 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
95433 diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
95434 index c8eac43..4b5f08f 100644
95435 --- a/kernel/utsname_sysctl.c
95436 +++ b/kernel/utsname_sysctl.c
95437 @@ -47,7 +47,7 @@ static void put_uts(struct ctl_table *table, int write, void *which)
95438 static int proc_do_uts_string(struct ctl_table *table, int write,
95439 void __user *buffer, size_t *lenp, loff_t *ppos)
95440 {
95441 - struct ctl_table uts_table;
95442 + ctl_table_no_const uts_table;
95443 int r;
95444 memcpy(&uts_table, table, sizeof(uts_table));
95445 uts_table.data = get_uts(table, write);
95446 diff --git a/kernel/watchdog.c b/kernel/watchdog.c
95447 index a8d6914..8fbdb13 100644
95448 --- a/kernel/watchdog.c
95449 +++ b/kernel/watchdog.c
95450 @@ -521,7 +521,7 @@ static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
95451 static void watchdog_nmi_disable(unsigned int cpu) { return; }
95452 #endif /* CONFIG_HARDLOCKUP_DETECTOR */
95453
95454 -static struct smp_hotplug_thread watchdog_threads = {
95455 +static struct smp_hotplug_thread watchdog_threads __read_only = {
95456 .store = &softlockup_watchdog,
95457 .thread_should_run = watchdog_should_run,
95458 .thread_fn = watchdog,
95459 diff --git a/kernel/workqueue.c b/kernel/workqueue.c
95460 index 5dbe22a..872413c 100644
95461 --- a/kernel/workqueue.c
95462 +++ b/kernel/workqueue.c
95463 @@ -4507,7 +4507,7 @@ static void rebind_workers(struct worker_pool *pool)
95464 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
95465 worker_flags |= WORKER_REBOUND;
95466 worker_flags &= ~WORKER_UNBOUND;
95467 - ACCESS_ONCE(worker->flags) = worker_flags;
95468 + ACCESS_ONCE_RW(worker->flags) = worker_flags;
95469 }
95470
95471 spin_unlock_irq(&pool->lock);
95472 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
95473 index a285900..5e3b26b 100644
95474 --- a/lib/Kconfig.debug
95475 +++ b/lib/Kconfig.debug
95476 @@ -882,7 +882,7 @@ config DEBUG_MUTEXES
95477
95478 config DEBUG_WW_MUTEX_SLOWPATH
95479 bool "Wait/wound mutex debugging: Slowpath testing"
95480 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
95481 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
95482 select DEBUG_LOCK_ALLOC
95483 select DEBUG_SPINLOCK
95484 select DEBUG_MUTEXES
95485 @@ -899,7 +899,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
95486
95487 config DEBUG_LOCK_ALLOC
95488 bool "Lock debugging: detect incorrect freeing of live locks"
95489 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
95490 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
95491 select DEBUG_SPINLOCK
95492 select DEBUG_MUTEXES
95493 select LOCKDEP
95494 @@ -913,7 +913,7 @@ config DEBUG_LOCK_ALLOC
95495
95496 config PROVE_LOCKING
95497 bool "Lock debugging: prove locking correctness"
95498 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
95499 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
95500 select LOCKDEP
95501 select DEBUG_SPINLOCK
95502 select DEBUG_MUTEXES
95503 @@ -964,7 +964,7 @@ config LOCKDEP
95504
95505 config LOCK_STAT
95506 bool "Lock usage statistics"
95507 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
95508 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
95509 select LOCKDEP
95510 select DEBUG_SPINLOCK
95511 select DEBUG_MUTEXES
95512 @@ -1437,6 +1437,7 @@ config LATENCYTOP
95513 depends on DEBUG_KERNEL
95514 depends on STACKTRACE_SUPPORT
95515 depends on PROC_FS
95516 + depends on !GRKERNSEC_HIDESYM
95517 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND && !ARC
95518 select KALLSYMS
95519 select KALLSYMS_ALL
95520 @@ -1453,7 +1454,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
95521 config DEBUG_STRICT_USER_COPY_CHECKS
95522 bool "Strict user copy size checks"
95523 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
95524 - depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
95525 + depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
95526 help
95527 Enabling this option turns a certain set of sanity checks for user
95528 copy operations into compile time failures.
95529 @@ -1581,7 +1582,7 @@ endmenu # runtime tests
95530
95531 config PROVIDE_OHCI1394_DMA_INIT
95532 bool "Remote debugging over FireWire early on boot"
95533 - depends on PCI && X86
95534 + depends on PCI && X86 && !GRKERNSEC
95535 help
95536 If you want to debug problems which hang or crash the kernel early
95537 on boot and the crashing machine has a FireWire port, you can use
95538 diff --git a/lib/Makefile b/lib/Makefile
95539 index d6b4bc4..a3724eb 100644
95540 --- a/lib/Makefile
95541 +++ b/lib/Makefile
95542 @@ -55,7 +55,7 @@ obj-$(CONFIG_BTREE) += btree.o
95543 obj-$(CONFIG_INTERVAL_TREE) += interval_tree.o
95544 obj-$(CONFIG_ASSOCIATIVE_ARRAY) += assoc_array.o
95545 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
95546 -obj-$(CONFIG_DEBUG_LIST) += list_debug.o
95547 +obj-y += list_debug.o
95548 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
95549
95550 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
95551 diff --git a/lib/average.c b/lib/average.c
95552 index 114d1be..ab0350c 100644
95553 --- a/lib/average.c
95554 +++ b/lib/average.c
95555 @@ -55,7 +55,7 @@ struct ewma *ewma_add(struct ewma *avg, unsigned long val)
95556 {
95557 unsigned long internal = ACCESS_ONCE(avg->internal);
95558
95559 - ACCESS_ONCE(avg->internal) = internal ?
95560 + ACCESS_ONCE_RW(avg->internal) = internal ?
95561 (((internal << avg->weight) - internal) +
95562 (val << avg->factor)) >> avg->weight :
95563 (val << avg->factor);
95564 diff --git a/lib/bitmap.c b/lib/bitmap.c
95565 index 33ce011..89e3d6f 100644
95566 --- a/lib/bitmap.c
95567 +++ b/lib/bitmap.c
95568 @@ -433,7 +433,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
95569 {
95570 int c, old_c, totaldigits, ndigits, nchunks, nbits;
95571 u32 chunk;
95572 - const char __user __force *ubuf = (const char __user __force *)buf;
95573 + const char __user *ubuf = (const char __force_user *)buf;
95574
95575 bitmap_zero(maskp, nmaskbits);
95576
95577 @@ -518,7 +518,7 @@ int bitmap_parse_user(const char __user *ubuf,
95578 {
95579 if (!access_ok(VERIFY_READ, ubuf, ulen))
95580 return -EFAULT;
95581 - return __bitmap_parse((const char __force *)ubuf,
95582 + return __bitmap_parse((const char __force_kernel *)ubuf,
95583 ulen, 1, maskp, nmaskbits);
95584
95585 }
95586 @@ -609,7 +609,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
95587 {
95588 unsigned a, b;
95589 int c, old_c, totaldigits;
95590 - const char __user __force *ubuf = (const char __user __force *)buf;
95591 + const char __user *ubuf = (const char __force_user *)buf;
95592 int exp_digit, in_range;
95593
95594 totaldigits = c = 0;
95595 @@ -704,7 +704,7 @@ int bitmap_parselist_user(const char __user *ubuf,
95596 {
95597 if (!access_ok(VERIFY_READ, ubuf, ulen))
95598 return -EFAULT;
95599 - return __bitmap_parselist((const char __force *)ubuf,
95600 + return __bitmap_parselist((const char __force_kernel *)ubuf,
95601 ulen, 1, maskp, nmaskbits);
95602 }
95603 EXPORT_SYMBOL(bitmap_parselist_user);
95604 diff --git a/lib/bug.c b/lib/bug.c
95605 index d1d7c78..b354235 100644
95606 --- a/lib/bug.c
95607 +++ b/lib/bug.c
95608 @@ -137,6 +137,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
95609 return BUG_TRAP_TYPE_NONE;
95610
95611 bug = find_bug(bugaddr);
95612 + if (!bug)
95613 + return BUG_TRAP_TYPE_NONE;
95614
95615 file = NULL;
95616 line = 0;
95617 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
95618 index 547f7f9..a6d4ba0 100644
95619 --- a/lib/debugobjects.c
95620 +++ b/lib/debugobjects.c
95621 @@ -289,7 +289,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
95622 if (limit > 4)
95623 return;
95624
95625 - is_on_stack = object_is_on_stack(addr);
95626 + is_on_stack = object_starts_on_stack(addr);
95627 if (is_on_stack == onstack)
95628 return;
95629
95630 diff --git a/lib/div64.c b/lib/div64.c
95631 index 4382ad7..08aa558 100644
95632 --- a/lib/div64.c
95633 +++ b/lib/div64.c
95634 @@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
95635 EXPORT_SYMBOL(__div64_32);
95636
95637 #ifndef div_s64_rem
95638 -s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
95639 +s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
95640 {
95641 u64 quotient;
95642
95643 @@ -130,7 +130,7 @@ EXPORT_SYMBOL(div64_u64_rem);
95644 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
95645 */
95646 #ifndef div64_u64
95647 -u64 div64_u64(u64 dividend, u64 divisor)
95648 +u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
95649 {
95650 u32 high = divisor >> 32;
95651 u64 quot;
95652 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
95653 index 98f2d7e..899da5c 100644
95654 --- a/lib/dma-debug.c
95655 +++ b/lib/dma-debug.c
95656 @@ -971,7 +971,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
95657
95658 void dma_debug_add_bus(struct bus_type *bus)
95659 {
95660 - struct notifier_block *nb;
95661 + notifier_block_no_const *nb;
95662
95663 if (global_disable)
95664 return;
95665 @@ -1148,7 +1148,7 @@ static void check_unmap(struct dma_debug_entry *ref)
95666
95667 static void check_for_stack(struct device *dev, void *addr)
95668 {
95669 - if (object_is_on_stack(addr))
95670 + if (object_starts_on_stack(addr))
95671 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
95672 "stack [addr=%p]\n", addr);
95673 }
95674 diff --git a/lib/hash.c b/lib/hash.c
95675 index fea973f..386626f 100644
95676 --- a/lib/hash.c
95677 +++ b/lib/hash.c
95678 @@ -14,7 +14,7 @@
95679 #include <linux/hash.h>
95680 #include <linux/cache.h>
95681
95682 -static struct fast_hash_ops arch_hash_ops __read_mostly = {
95683 +static struct fast_hash_ops arch_hash_ops __read_only = {
95684 .hash = jhash,
95685 .hash2 = jhash2,
95686 };
95687 diff --git a/lib/inflate.c b/lib/inflate.c
95688 index 013a761..c28f3fc 100644
95689 --- a/lib/inflate.c
95690 +++ b/lib/inflate.c
95691 @@ -269,7 +269,7 @@ static void free(void *where)
95692 malloc_ptr = free_mem_ptr;
95693 }
95694 #else
95695 -#define malloc(a) kmalloc(a, GFP_KERNEL)
95696 +#define malloc(a) kmalloc((a), GFP_KERNEL)
95697 #define free(a) kfree(a)
95698 #endif
95699
95700 diff --git a/lib/ioremap.c b/lib/ioremap.c
95701 index 0c9216c..863bd89 100644
95702 --- a/lib/ioremap.c
95703 +++ b/lib/ioremap.c
95704 @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
95705 unsigned long next;
95706
95707 phys_addr -= addr;
95708 - pmd = pmd_alloc(&init_mm, pud, addr);
95709 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
95710 if (!pmd)
95711 return -ENOMEM;
95712 do {
95713 @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
95714 unsigned long next;
95715
95716 phys_addr -= addr;
95717 - pud = pud_alloc(&init_mm, pgd, addr);
95718 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
95719 if (!pud)
95720 return -ENOMEM;
95721 do {
95722 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
95723 index bd2bea9..6b3c95e 100644
95724 --- a/lib/is_single_threaded.c
95725 +++ b/lib/is_single_threaded.c
95726 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
95727 struct task_struct *p, *t;
95728 bool ret;
95729
95730 + if (!mm)
95731 + return true;
95732 +
95733 if (atomic_read(&task->signal->live) != 1)
95734 return false;
95735
95736 diff --git a/lib/kobject.c b/lib/kobject.c
95737 index 58751bb..93a1853 100644
95738 --- a/lib/kobject.c
95739 +++ b/lib/kobject.c
95740 @@ -931,9 +931,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
95741
95742
95743 static DEFINE_SPINLOCK(kobj_ns_type_lock);
95744 -static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
95745 +static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
95746
95747 -int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
95748 +int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
95749 {
95750 enum kobj_ns_type type = ops->type;
95751 int error;
95752 diff --git a/lib/list_debug.c b/lib/list_debug.c
95753 index c24c2f7..f0296f4 100644
95754 --- a/lib/list_debug.c
95755 +++ b/lib/list_debug.c
95756 @@ -11,7 +11,9 @@
95757 #include <linux/bug.h>
95758 #include <linux/kernel.h>
95759 #include <linux/rculist.h>
95760 +#include <linux/mm.h>
95761
95762 +#ifdef CONFIG_DEBUG_LIST
95763 /*
95764 * Insert a new entry between two known consecutive entries.
95765 *
95766 @@ -19,21 +21,40 @@
95767 * the prev/next entries already!
95768 */
95769
95770 +static bool __list_add_debug(struct list_head *new,
95771 + struct list_head *prev,
95772 + struct list_head *next)
95773 +{
95774 + if (unlikely(next->prev != prev)) {
95775 + printk(KERN_ERR "list_add corruption. next->prev should be "
95776 + "prev (%p), but was %p. (next=%p).\n",
95777 + prev, next->prev, next);
95778 + BUG();
95779 + return false;
95780 + }
95781 + if (unlikely(prev->next != next)) {
95782 + printk(KERN_ERR "list_add corruption. prev->next should be "
95783 + "next (%p), but was %p. (prev=%p).\n",
95784 + next, prev->next, prev);
95785 + BUG();
95786 + return false;
95787 + }
95788 + if (unlikely(new == prev || new == next)) {
95789 + printk(KERN_ERR "list_add double add: new=%p, prev=%p, next=%p.\n",
95790 + new, prev, next);
95791 + BUG();
95792 + return false;
95793 + }
95794 + return true;
95795 +}
95796 +
95797 void __list_add(struct list_head *new,
95798 - struct list_head *prev,
95799 - struct list_head *next)
95800 + struct list_head *prev,
95801 + struct list_head *next)
95802 {
95803 - WARN(next->prev != prev,
95804 - "list_add corruption. next->prev should be "
95805 - "prev (%p), but was %p. (next=%p).\n",
95806 - prev, next->prev, next);
95807 - WARN(prev->next != next,
95808 - "list_add corruption. prev->next should be "
95809 - "next (%p), but was %p. (prev=%p).\n",
95810 - next, prev->next, prev);
95811 - WARN(new == prev || new == next,
95812 - "list_add double add: new=%p, prev=%p, next=%p.\n",
95813 - new, prev, next);
95814 + if (!__list_add_debug(new, prev, next))
95815 + return;
95816 +
95817 next->prev = new;
95818 new->next = next;
95819 new->prev = prev;
95820 @@ -41,28 +62,46 @@ void __list_add(struct list_head *new,
95821 }
95822 EXPORT_SYMBOL(__list_add);
95823
95824 -void __list_del_entry(struct list_head *entry)
95825 +static bool __list_del_entry_debug(struct list_head *entry)
95826 {
95827 struct list_head *prev, *next;
95828
95829 prev = entry->prev;
95830 next = entry->next;
95831
95832 - if (WARN(next == LIST_POISON1,
95833 - "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
95834 - entry, LIST_POISON1) ||
95835 - WARN(prev == LIST_POISON2,
95836 - "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
95837 - entry, LIST_POISON2) ||
95838 - WARN(prev->next != entry,
95839 - "list_del corruption. prev->next should be %p, "
95840 - "but was %p\n", entry, prev->next) ||
95841 - WARN(next->prev != entry,
95842 - "list_del corruption. next->prev should be %p, "
95843 - "but was %p\n", entry, next->prev))
95844 + if (unlikely(next == LIST_POISON1)) {
95845 + printk(KERN_ERR "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
95846 + entry, LIST_POISON1);
95847 + BUG();
95848 + return false;
95849 + }
95850 + if (unlikely(prev == LIST_POISON2)) {
95851 + printk(KERN_ERR "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
95852 + entry, LIST_POISON2);
95853 + BUG();
95854 + return false;
95855 + }
95856 + if (unlikely(entry->prev->next != entry)) {
95857 + printk(KERN_ERR "list_del corruption. prev->next should be %p, "
95858 + "but was %p\n", entry, prev->next);
95859 + BUG();
95860 + return false;
95861 + }
95862 + if (unlikely(entry->next->prev != entry)) {
95863 + printk(KERN_ERR "list_del corruption. next->prev should be %p, "
95864 + "but was %p\n", entry, next->prev);
95865 + BUG();
95866 + return false;
95867 + }
95868 + return true;
95869 +}
95870 +
95871 +void __list_del_entry(struct list_head *entry)
95872 +{
95873 + if (!__list_del_entry_debug(entry))
95874 return;
95875
95876 - __list_del(prev, next);
95877 + __list_del(entry->prev, entry->next);
95878 }
95879 EXPORT_SYMBOL(__list_del_entry);
95880
95881 @@ -86,15 +125,85 @@ EXPORT_SYMBOL(list_del);
95882 void __list_add_rcu(struct list_head *new,
95883 struct list_head *prev, struct list_head *next)
95884 {
95885 - WARN(next->prev != prev,
95886 - "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
95887 - prev, next->prev, next);
95888 - WARN(prev->next != next,
95889 - "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
95890 - next, prev->next, prev);
95891 + if (!__list_add_debug(new, prev, next))
95892 + return;
95893 +
95894 new->next = next;
95895 new->prev = prev;
95896 rcu_assign_pointer(list_next_rcu(prev), new);
95897 next->prev = new;
95898 }
95899 EXPORT_SYMBOL(__list_add_rcu);
95900 +#endif
95901 +
95902 +void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
95903 +{
95904 +#ifdef CONFIG_DEBUG_LIST
95905 + if (!__list_add_debug(new, prev, next))
95906 + return;
95907 +#endif
95908 +
95909 + pax_open_kernel();
95910 + next->prev = new;
95911 + new->next = next;
95912 + new->prev = prev;
95913 + prev->next = new;
95914 + pax_close_kernel();
95915 +}
95916 +EXPORT_SYMBOL(__pax_list_add);
95917 +
95918 +void pax_list_del(struct list_head *entry)
95919 +{
95920 +#ifdef CONFIG_DEBUG_LIST
95921 + if (!__list_del_entry_debug(entry))
95922 + return;
95923 +#endif
95924 +
95925 + pax_open_kernel();
95926 + __list_del(entry->prev, entry->next);
95927 + entry->next = LIST_POISON1;
95928 + entry->prev = LIST_POISON2;
95929 + pax_close_kernel();
95930 +}
95931 +EXPORT_SYMBOL(pax_list_del);
95932 +
95933 +void pax_list_del_init(struct list_head *entry)
95934 +{
95935 + pax_open_kernel();
95936 + __list_del(entry->prev, entry->next);
95937 + INIT_LIST_HEAD(entry);
95938 + pax_close_kernel();
95939 +}
95940 +EXPORT_SYMBOL(pax_list_del_init);
95941 +
95942 +void __pax_list_add_rcu(struct list_head *new,
95943 + struct list_head *prev, struct list_head *next)
95944 +{
95945 +#ifdef CONFIG_DEBUG_LIST
95946 + if (!__list_add_debug(new, prev, next))
95947 + return;
95948 +#endif
95949 +
95950 + pax_open_kernel();
95951 + new->next = next;
95952 + new->prev = prev;
95953 + rcu_assign_pointer(list_next_rcu(prev), new);
95954 + next->prev = new;
95955 + pax_close_kernel();
95956 +}
95957 +EXPORT_SYMBOL(__pax_list_add_rcu);
95958 +
95959 +void pax_list_del_rcu(struct list_head *entry)
95960 +{
95961 +#ifdef CONFIG_DEBUG_LIST
95962 + if (!__list_del_entry_debug(entry))
95963 + return;
95964 +#endif
95965 +
95966 + pax_open_kernel();
95967 + __list_del(entry->prev, entry->next);
95968 + entry->next = LIST_POISON1;
95969 + entry->prev = LIST_POISON2;
95970 + pax_close_kernel();
95971 +}
95972 +EXPORT_SYMBOL(pax_list_del_rcu);
95973 diff --git a/lib/lockref.c b/lib/lockref.c
95974 index d2233de..fa1a2f6 100644
95975 --- a/lib/lockref.c
95976 +++ b/lib/lockref.c
95977 @@ -48,13 +48,13 @@
95978 void lockref_get(struct lockref *lockref)
95979 {
95980 CMPXCHG_LOOP(
95981 - new.count++;
95982 + __lockref_inc(&new);
95983 ,
95984 return;
95985 );
95986
95987 spin_lock(&lockref->lock);
95988 - lockref->count++;
95989 + __lockref_inc(lockref);
95990 spin_unlock(&lockref->lock);
95991 }
95992 EXPORT_SYMBOL(lockref_get);
95993 @@ -69,7 +69,7 @@ int lockref_get_not_zero(struct lockref *lockref)
95994 int retval;
95995
95996 CMPXCHG_LOOP(
95997 - new.count++;
95998 + __lockref_inc(&new);
95999 if (!old.count)
96000 return 0;
96001 ,
96002 @@ -79,7 +79,7 @@ int lockref_get_not_zero(struct lockref *lockref)
96003 spin_lock(&lockref->lock);
96004 retval = 0;
96005 if (lockref->count) {
96006 - lockref->count++;
96007 + __lockref_inc(lockref);
96008 retval = 1;
96009 }
96010 spin_unlock(&lockref->lock);
96011 @@ -96,7 +96,7 @@ EXPORT_SYMBOL(lockref_get_not_zero);
96012 int lockref_get_or_lock(struct lockref *lockref)
96013 {
96014 CMPXCHG_LOOP(
96015 - new.count++;
96016 + __lockref_inc(&new);
96017 if (!old.count)
96018 break;
96019 ,
96020 @@ -106,7 +106,7 @@ int lockref_get_or_lock(struct lockref *lockref)
96021 spin_lock(&lockref->lock);
96022 if (!lockref->count)
96023 return 0;
96024 - lockref->count++;
96025 + __lockref_inc(lockref);
96026 spin_unlock(&lockref->lock);
96027 return 1;
96028 }
96029 @@ -120,7 +120,7 @@ EXPORT_SYMBOL(lockref_get_or_lock);
96030 int lockref_put_or_lock(struct lockref *lockref)
96031 {
96032 CMPXCHG_LOOP(
96033 - new.count--;
96034 + __lockref_dec(&new);
96035 if (old.count <= 1)
96036 break;
96037 ,
96038 @@ -130,7 +130,7 @@ int lockref_put_or_lock(struct lockref *lockref)
96039 spin_lock(&lockref->lock);
96040 if (lockref->count <= 1)
96041 return 0;
96042 - lockref->count--;
96043 + __lockref_dec(lockref);
96044 spin_unlock(&lockref->lock);
96045 return 1;
96046 }
96047 @@ -157,7 +157,7 @@ int lockref_get_not_dead(struct lockref *lockref)
96048 int retval;
96049
96050 CMPXCHG_LOOP(
96051 - new.count++;
96052 + __lockref_inc(&new);
96053 if ((int)old.count < 0)
96054 return 0;
96055 ,
96056 @@ -167,7 +167,7 @@ int lockref_get_not_dead(struct lockref *lockref)
96057 spin_lock(&lockref->lock);
96058 retval = 0;
96059 if ((int) lockref->count >= 0) {
96060 - lockref->count++;
96061 + __lockref_inc(lockref);
96062 retval = 1;
96063 }
96064 spin_unlock(&lockref->lock);
96065 diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
96066 index a89cf09..1a42c2d 100644
96067 --- a/lib/percpu-refcount.c
96068 +++ b/lib/percpu-refcount.c
96069 @@ -29,7 +29,7 @@
96070 * can't hit 0 before we've added up all the percpu refs.
96071 */
96072
96073 -#define PCPU_COUNT_BIAS (1U << 31)
96074 +#define PCPU_COUNT_BIAS (1U << 30)
96075
96076 static unsigned __percpu *pcpu_count_ptr(struct percpu_ref *ref)
96077 {
96078 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
96079 index 3291a8e..346a91e 100644
96080 --- a/lib/radix-tree.c
96081 +++ b/lib/radix-tree.c
96082 @@ -67,7 +67,7 @@ struct radix_tree_preload {
96083 int nr;
96084 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
96085 };
96086 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
96087 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
96088
96089 static inline void *ptr_to_indirect(void *ptr)
96090 {
96091 diff --git a/lib/random32.c b/lib/random32.c
96092 index c9b6bf3..4752c6d4 100644
96093 --- a/lib/random32.c
96094 +++ b/lib/random32.c
96095 @@ -46,7 +46,7 @@ static inline void prandom_state_selftest(void)
96096 }
96097 #endif
96098
96099 -static DEFINE_PER_CPU(struct rnd_state, net_rand_state);
96100 +static DEFINE_PER_CPU(struct rnd_state, net_rand_state) __latent_entropy;
96101
96102 /**
96103 * prandom_u32_state - seeded pseudo-random number generator.
96104 diff --git a/lib/rbtree.c b/lib/rbtree.c
96105 index c16c81a..4dcbda1 100644
96106 --- a/lib/rbtree.c
96107 +++ b/lib/rbtree.c
96108 @@ -380,7 +380,9 @@ static inline void dummy_copy(struct rb_node *old, struct rb_node *new) {}
96109 static inline void dummy_rotate(struct rb_node *old, struct rb_node *new) {}
96110
96111 static const struct rb_augment_callbacks dummy_callbacks = {
96112 - dummy_propagate, dummy_copy, dummy_rotate
96113 + .propagate = dummy_propagate,
96114 + .copy = dummy_copy,
96115 + .rotate = dummy_rotate
96116 };
96117
96118 void rb_insert_color(struct rb_node *node, struct rb_root *root)
96119 diff --git a/lib/show_mem.c b/lib/show_mem.c
96120 index 0922579..9d7adb9 100644
96121 --- a/lib/show_mem.c
96122 +++ b/lib/show_mem.c
96123 @@ -44,6 +44,6 @@ void show_mem(unsigned int filter)
96124 quicklist_total_size());
96125 #endif
96126 #ifdef CONFIG_MEMORY_FAILURE
96127 - printk("%lu pages hwpoisoned\n", atomic_long_read(&num_poisoned_pages));
96128 + printk("%lu pages hwpoisoned\n", atomic_long_read_unchecked(&num_poisoned_pages));
96129 #endif
96130 }
96131 diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
96132 index bb2b201..46abaf9 100644
96133 --- a/lib/strncpy_from_user.c
96134 +++ b/lib/strncpy_from_user.c
96135 @@ -21,7 +21,7 @@
96136 */
96137 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
96138 {
96139 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
96140 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
96141 long res = 0;
96142
96143 /*
96144 diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
96145 index a28df52..3d55877 100644
96146 --- a/lib/strnlen_user.c
96147 +++ b/lib/strnlen_user.c
96148 @@ -26,7 +26,7 @@
96149 */
96150 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
96151 {
96152 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
96153 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
96154 long align, res = 0;
96155 unsigned long c;
96156
96157 diff --git a/lib/swiotlb.c b/lib/swiotlb.c
96158 index 4abda07..b9d3765 100644
96159 --- a/lib/swiotlb.c
96160 +++ b/lib/swiotlb.c
96161 @@ -682,7 +682,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
96162
96163 void
96164 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
96165 - dma_addr_t dev_addr)
96166 + dma_addr_t dev_addr, struct dma_attrs *attrs)
96167 {
96168 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
96169
96170 diff --git a/lib/test_bpf.c b/lib/test_bpf.c
96171 index 89e0345..3347efe 100644
96172 --- a/lib/test_bpf.c
96173 +++ b/lib/test_bpf.c
96174 @@ -1798,7 +1798,7 @@ static struct bpf_prog *generate_filter(int which, int *err)
96175 break;
96176
96177 case INTERNAL:
96178 - fp = kzalloc(bpf_prog_size(flen), GFP_KERNEL);
96179 + fp = bpf_prog_alloc(bpf_prog_size(flen), 0);
96180 if (fp == NULL) {
96181 pr_cont("UNEXPECTED_FAIL no memory left\n");
96182 *err = -ENOMEM;
96183 diff --git a/lib/usercopy.c b/lib/usercopy.c
96184 index 4f5b1dd..7cab418 100644
96185 --- a/lib/usercopy.c
96186 +++ b/lib/usercopy.c
96187 @@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
96188 WARN(1, "Buffer overflow detected!\n");
96189 }
96190 EXPORT_SYMBOL(copy_from_user_overflow);
96191 +
96192 +void copy_to_user_overflow(void)
96193 +{
96194 + WARN(1, "Buffer overflow detected!\n");
96195 +}
96196 +EXPORT_SYMBOL(copy_to_user_overflow);
96197 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
96198 index 6fe2c84..2fe5ec6 100644
96199 --- a/lib/vsprintf.c
96200 +++ b/lib/vsprintf.c
96201 @@ -16,6 +16,9 @@
96202 * - scnprintf and vscnprintf
96203 */
96204
96205 +#ifdef CONFIG_GRKERNSEC_HIDESYM
96206 +#define __INCLUDED_BY_HIDESYM 1
96207 +#endif
96208 #include <stdarg.h>
96209 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
96210 #include <linux/types.h>
96211 @@ -624,7 +627,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
96212 #ifdef CONFIG_KALLSYMS
96213 if (*fmt == 'B')
96214 sprint_backtrace(sym, value);
96215 - else if (*fmt != 'f' && *fmt != 's')
96216 + else if (*fmt != 'f' && *fmt != 's' && *fmt != 'X')
96217 sprint_symbol(sym, value);
96218 else
96219 sprint_symbol_no_offset(sym, value);
96220 @@ -1183,7 +1186,11 @@ char *address_val(char *buf, char *end, const void *addr,
96221 return number(buf, end, num, spec);
96222 }
96223
96224 +#ifdef CONFIG_GRKERNSEC_HIDESYM
96225 +int kptr_restrict __read_mostly = 2;
96226 +#else
96227 int kptr_restrict __read_mostly;
96228 +#endif
96229
96230 /*
96231 * Show a '%p' thing. A kernel extension is that the '%p' is followed
96232 @@ -1194,8 +1201,10 @@ int kptr_restrict __read_mostly;
96233 *
96234 * - 'F' For symbolic function descriptor pointers with offset
96235 * - 'f' For simple symbolic function names without offset
96236 + * - 'X' For simple symbolic function names without offset approved for use with GRKERNSEC_HIDESYM
96237 * - 'S' For symbolic direct pointers with offset
96238 * - 's' For symbolic direct pointers without offset
96239 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
96240 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
96241 * - 'B' For backtraced symbolic direct pointers with offset
96242 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
96243 @@ -1263,12 +1272,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
96244
96245 if (!ptr && *fmt != 'K') {
96246 /*
96247 - * Print (null) with the same width as a pointer so it makes
96248 + * Print (nil) with the same width as a pointer so it makes
96249 * tabular output look nice.
96250 */
96251 if (spec.field_width == -1)
96252 spec.field_width = default_width;
96253 - return string(buf, end, "(null)", spec);
96254 + return string(buf, end, "(nil)", spec);
96255 }
96256
96257 switch (*fmt) {
96258 @@ -1278,6 +1287,14 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
96259 /* Fallthrough */
96260 case 'S':
96261 case 's':
96262 +#ifdef CONFIG_GRKERNSEC_HIDESYM
96263 + break;
96264 +#else
96265 + return symbol_string(buf, end, ptr, spec, fmt);
96266 +#endif
96267 + case 'X':
96268 + ptr = dereference_function_descriptor(ptr);
96269 + case 'A':
96270 case 'B':
96271 return symbol_string(buf, end, ptr, spec, fmt);
96272 case 'R':
96273 @@ -1333,6 +1350,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
96274 va_end(va);
96275 return buf;
96276 }
96277 + case 'P':
96278 + break;
96279 case 'K':
96280 /*
96281 * %pK cannot be used in IRQ context because its test
96282 @@ -1390,6 +1409,22 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
96283 ((const struct file *)ptr)->f_path.dentry,
96284 spec, fmt);
96285 }
96286 +
96287 +#ifdef CONFIG_GRKERNSEC_HIDESYM
96288 + /* 'P' = approved pointers to copy to userland,
96289 + as in the /proc/kallsyms case, as we make it display nothing
96290 + for non-root users, and the real contents for root users
96291 + 'X' = approved simple symbols
96292 + Also ignore 'K' pointers, since we force their NULLing for non-root users
96293 + above
96294 + */
96295 + if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'X' && *fmt != 'K' && is_usercopy_object(buf)) {
96296 + printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
96297 + dump_stack();
96298 + ptr = NULL;
96299 + }
96300 +#endif
96301 +
96302 spec.flags |= SMALL;
96303 if (spec.field_width == -1) {
96304 spec.field_width = default_width;
96305 @@ -2089,11 +2124,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
96306 typeof(type) value; \
96307 if (sizeof(type) == 8) { \
96308 args = PTR_ALIGN(args, sizeof(u32)); \
96309 - *(u32 *)&value = *(u32 *)args; \
96310 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
96311 + *(u32 *)&value = *(const u32 *)args; \
96312 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
96313 } else { \
96314 args = PTR_ALIGN(args, sizeof(type)); \
96315 - value = *(typeof(type) *)args; \
96316 + value = *(const typeof(type) *)args; \
96317 } \
96318 args += sizeof(type); \
96319 value; \
96320 @@ -2156,7 +2191,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
96321 case FORMAT_TYPE_STR: {
96322 const char *str_arg = args;
96323 args += strlen(str_arg) + 1;
96324 - str = string(str, end, (char *)str_arg, spec);
96325 + str = string(str, end, str_arg, spec);
96326 break;
96327 }
96328
96329 diff --git a/localversion-grsec b/localversion-grsec
96330 new file mode 100644
96331 index 0000000..7cd6065
96332 --- /dev/null
96333 +++ b/localversion-grsec
96334 @@ -0,0 +1 @@
96335 +-grsec
96336 diff --git a/mm/Kconfig b/mm/Kconfig
96337 index 886db21..f514de2 100644
96338 --- a/mm/Kconfig
96339 +++ b/mm/Kconfig
96340 @@ -333,10 +333,11 @@ config KSM
96341 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
96342
96343 config DEFAULT_MMAP_MIN_ADDR
96344 - int "Low address space to protect from user allocation"
96345 + int "Low address space to protect from user allocation"
96346 depends on MMU
96347 - default 4096
96348 - help
96349 + default 32768 if ALPHA || ARM || PARISC || SPARC32
96350 + default 65536
96351 + help
96352 This is the portion of low virtual memory which should be protected
96353 from userspace allocation. Keeping a user from writing to low pages
96354 can help reduce the impact of kernel NULL pointer bugs.
96355 @@ -367,7 +368,7 @@ config MEMORY_FAILURE
96356
96357 config HWPOISON_INJECT
96358 tristate "HWPoison pages injector"
96359 - depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
96360 + depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
96361 select PROC_PAGE_MONITOR
96362
96363 config NOMMU_INITIAL_TRIM_EXCESS
96364 diff --git a/mm/backing-dev.c b/mm/backing-dev.c
96365 index 1706cbb..f89dbca 100644
96366 --- a/mm/backing-dev.c
96367 +++ b/mm/backing-dev.c
96368 @@ -12,7 +12,7 @@
96369 #include <linux/device.h>
96370 #include <trace/events/writeback.h>
96371
96372 -static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
96373 +static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
96374
96375 struct backing_dev_info default_backing_dev_info = {
96376 .name = "default",
96377 @@ -533,7 +533,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
96378 return err;
96379
96380 err = bdi_register(bdi, NULL, "%.28s-%ld", name,
96381 - atomic_long_inc_return(&bdi_seq));
96382 + atomic_long_inc_return_unchecked(&bdi_seq));
96383 if (err) {
96384 bdi_destroy(bdi);
96385 return err;
96386 diff --git a/mm/filemap.c b/mm/filemap.c
96387 index 90effcd..539aa64 100644
96388 --- a/mm/filemap.c
96389 +++ b/mm/filemap.c
96390 @@ -2092,7 +2092,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
96391 struct address_space *mapping = file->f_mapping;
96392
96393 if (!mapping->a_ops->readpage)
96394 - return -ENOEXEC;
96395 + return -ENODEV;
96396 file_accessed(file);
96397 vma->vm_ops = &generic_file_vm_ops;
96398 return 0;
96399 @@ -2270,6 +2270,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
96400 *pos = i_size_read(inode);
96401
96402 if (limit != RLIM_INFINITY) {
96403 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
96404 if (*pos >= limit) {
96405 send_sig(SIGXFSZ, current, 0);
96406 return -EFBIG;
96407 diff --git a/mm/fremap.c b/mm/fremap.c
96408 index 72b8fa3..c5b39f1 100644
96409 --- a/mm/fremap.c
96410 +++ b/mm/fremap.c
96411 @@ -180,6 +180,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
96412 retry:
96413 vma = find_vma(mm, start);
96414
96415 +#ifdef CONFIG_PAX_SEGMEXEC
96416 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
96417 + goto out;
96418 +#endif
96419 +
96420 /*
96421 * Make sure the vma is shared, that it supports prefaulting,
96422 * and that the remapped range is valid and fully within
96423 diff --git a/mm/gup.c b/mm/gup.c
96424 index 91d044b..a58ecf6 100644
96425 --- a/mm/gup.c
96426 +++ b/mm/gup.c
96427 @@ -270,11 +270,6 @@ static int faultin_page(struct task_struct *tsk, struct vm_area_struct *vma,
96428 unsigned int fault_flags = 0;
96429 int ret;
96430
96431 - /* For mlock, just skip the stack guard page. */
96432 - if ((*flags & FOLL_MLOCK) &&
96433 - (stack_guard_page_start(vma, address) ||
96434 - stack_guard_page_end(vma, address + PAGE_SIZE)))
96435 - return -ENOENT;
96436 if (*flags & FOLL_WRITE)
96437 fault_flags |= FAULT_FLAG_WRITE;
96438 if (nonblocking)
96439 @@ -436,14 +431,14 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
96440 if (!(gup_flags & FOLL_FORCE))
96441 gup_flags |= FOLL_NUMA;
96442
96443 - do {
96444 + while (nr_pages) {
96445 struct page *page;
96446 unsigned int foll_flags = gup_flags;
96447 unsigned int page_increm;
96448
96449 /* first iteration or cross vma bound */
96450 if (!vma || start >= vma->vm_end) {
96451 - vma = find_extend_vma(mm, start);
96452 + vma = find_vma(mm, start);
96453 if (!vma && in_gate_area(mm, start)) {
96454 int ret;
96455 ret = get_gate_page(mm, start & PAGE_MASK,
96456 @@ -455,7 +450,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
96457 goto next_page;
96458 }
96459
96460 - if (!vma || check_vma_flags(vma, gup_flags))
96461 + if (!vma || start < vma->vm_start || check_vma_flags(vma, gup_flags))
96462 return i ? : -EFAULT;
96463 if (is_vm_hugetlb_page(vma)) {
96464 i = follow_hugetlb_page(mm, vma, pages, vmas,
96465 @@ -510,7 +505,7 @@ next_page:
96466 i += page_increm;
96467 start += page_increm * PAGE_SIZE;
96468 nr_pages -= page_increm;
96469 - } while (nr_pages);
96470 + }
96471 return i;
96472 }
96473 EXPORT_SYMBOL(__get_user_pages);
96474 diff --git a/mm/highmem.c b/mm/highmem.c
96475 index 123bcd3..0de52ba 100644
96476 --- a/mm/highmem.c
96477 +++ b/mm/highmem.c
96478 @@ -195,8 +195,9 @@ static void flush_all_zero_pkmaps(void)
96479 * So no dangers, even with speculative execution.
96480 */
96481 page = pte_page(pkmap_page_table[i]);
96482 + pax_open_kernel();
96483 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
96484 -
96485 + pax_close_kernel();
96486 set_page_address(page, NULL);
96487 need_flush = 1;
96488 }
96489 @@ -259,9 +260,11 @@ start:
96490 }
96491 }
96492 vaddr = PKMAP_ADDR(last_pkmap_nr);
96493 +
96494 + pax_open_kernel();
96495 set_pte_at(&init_mm, vaddr,
96496 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
96497 -
96498 + pax_close_kernel();
96499 pkmap_count[last_pkmap_nr] = 1;
96500 set_page_address(page, (void *)vaddr);
96501
96502 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
96503 index eeceeeb..a209d58 100644
96504 --- a/mm/hugetlb.c
96505 +++ b/mm/hugetlb.c
96506 @@ -2258,6 +2258,7 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
96507 struct ctl_table *table, int write,
96508 void __user *buffer, size_t *length, loff_t *ppos)
96509 {
96510 + ctl_table_no_const t;
96511 struct hstate *h = &default_hstate;
96512 unsigned long tmp = h->max_huge_pages;
96513 int ret;
96514 @@ -2265,9 +2266,10 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
96515 if (!hugepages_supported())
96516 return -ENOTSUPP;
96517
96518 - table->data = &tmp;
96519 - table->maxlen = sizeof(unsigned long);
96520 - ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
96521 + t = *table;
96522 + t.data = &tmp;
96523 + t.maxlen = sizeof(unsigned long);
96524 + ret = proc_doulongvec_minmax(&t, write, buffer, length, ppos);
96525 if (ret)
96526 goto out;
96527
96528 @@ -2302,6 +2304,7 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
96529 struct hstate *h = &default_hstate;
96530 unsigned long tmp;
96531 int ret;
96532 + ctl_table_no_const hugetlb_table;
96533
96534 if (!hugepages_supported())
96535 return -ENOTSUPP;
96536 @@ -2311,9 +2314,10 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
96537 if (write && hstate_is_gigantic(h))
96538 return -EINVAL;
96539
96540 - table->data = &tmp;
96541 - table->maxlen = sizeof(unsigned long);
96542 - ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
96543 + hugetlb_table = *table;
96544 + hugetlb_table.data = &tmp;
96545 + hugetlb_table.maxlen = sizeof(unsigned long);
96546 + ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
96547 if (ret)
96548 goto out;
96549
96550 @@ -2792,6 +2796,27 @@ static void unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
96551 mutex_unlock(&mapping->i_mmap_mutex);
96552 }
96553
96554 +#ifdef CONFIG_PAX_SEGMEXEC
96555 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
96556 +{
96557 + struct mm_struct *mm = vma->vm_mm;
96558 + struct vm_area_struct *vma_m;
96559 + unsigned long address_m;
96560 + pte_t *ptep_m;
96561 +
96562 + vma_m = pax_find_mirror_vma(vma);
96563 + if (!vma_m)
96564 + return;
96565 +
96566 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
96567 + address_m = address + SEGMEXEC_TASK_SIZE;
96568 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
96569 + get_page(page_m);
96570 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
96571 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
96572 +}
96573 +#endif
96574 +
96575 /*
96576 * Hugetlb_cow() should be called with page lock of the original hugepage held.
96577 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
96578 @@ -2903,6 +2928,11 @@ retry_avoidcopy:
96579 make_huge_pte(vma, new_page, 1));
96580 page_remove_rmap(old_page);
96581 hugepage_add_new_anon_rmap(new_page, vma, address);
96582 +
96583 +#ifdef CONFIG_PAX_SEGMEXEC
96584 + pax_mirror_huge_pte(vma, address, new_page);
96585 +#endif
96586 +
96587 /* Make the old page be freed below */
96588 new_page = old_page;
96589 }
96590 @@ -3063,6 +3093,10 @@ retry:
96591 && (vma->vm_flags & VM_SHARED)));
96592 set_huge_pte_at(mm, address, ptep, new_pte);
96593
96594 +#ifdef CONFIG_PAX_SEGMEXEC
96595 + pax_mirror_huge_pte(vma, address, page);
96596 +#endif
96597 +
96598 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
96599 /* Optimization, do the COW without a second fault */
96600 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page, ptl);
96601 @@ -3129,6 +3163,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
96602 struct hstate *h = hstate_vma(vma);
96603 struct address_space *mapping;
96604
96605 +#ifdef CONFIG_PAX_SEGMEXEC
96606 + struct vm_area_struct *vma_m;
96607 +#endif
96608 +
96609 address &= huge_page_mask(h);
96610
96611 ptep = huge_pte_offset(mm, address);
96612 @@ -3142,6 +3180,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
96613 VM_FAULT_SET_HINDEX(hstate_index(h));
96614 }
96615
96616 +#ifdef CONFIG_PAX_SEGMEXEC
96617 + vma_m = pax_find_mirror_vma(vma);
96618 + if (vma_m) {
96619 + unsigned long address_m;
96620 +
96621 + if (vma->vm_start > vma_m->vm_start) {
96622 + address_m = address;
96623 + address -= SEGMEXEC_TASK_SIZE;
96624 + vma = vma_m;
96625 + h = hstate_vma(vma);
96626 + } else
96627 + address_m = address + SEGMEXEC_TASK_SIZE;
96628 +
96629 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
96630 + return VM_FAULT_OOM;
96631 + address_m &= HPAGE_MASK;
96632 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
96633 + }
96634 +#endif
96635 +
96636 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
96637 if (!ptep)
96638 return VM_FAULT_OOM;
96639 diff --git a/mm/internal.h b/mm/internal.h
96640 index 5f2772f..4c3882c 100644
96641 --- a/mm/internal.h
96642 +++ b/mm/internal.h
96643 @@ -134,6 +134,7 @@ __find_buddy_index(unsigned long page_idx, unsigned int order)
96644
96645 extern int __isolate_free_page(struct page *page, unsigned int order);
96646 extern void __free_pages_bootmem(struct page *page, unsigned int order);
96647 +extern void free_compound_page(struct page *page);
96648 extern void prep_compound_page(struct page *page, unsigned long order);
96649 #ifdef CONFIG_MEMORY_FAILURE
96650 extern bool is_free_buddy_page(struct page *page);
96651 @@ -376,7 +377,7 @@ extern u32 hwpoison_filter_enable;
96652
96653 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
96654 unsigned long, unsigned long,
96655 - unsigned long, unsigned long);
96656 + unsigned long, unsigned long) __intentional_overflow(-1);
96657
96658 extern void set_pageblock_order(void);
96659 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
96660 diff --git a/mm/iov_iter.c b/mm/iov_iter.c
96661 index 141dcf7..7327fd3 100644
96662 --- a/mm/iov_iter.c
96663 +++ b/mm/iov_iter.c
96664 @@ -173,7 +173,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
96665
96666 while (bytes) {
96667 char __user *buf = iov->iov_base + base;
96668 - int copy = min(bytes, iov->iov_len - base);
96669 + size_t copy = min(bytes, iov->iov_len - base);
96670
96671 base = 0;
96672 left = __copy_from_user_inatomic(vaddr, buf, copy);
96673 @@ -201,7 +201,7 @@ static size_t copy_from_user_atomic_iovec(struct page *page,
96674
96675 kaddr = kmap_atomic(page);
96676 if (likely(i->nr_segs == 1)) {
96677 - int left;
96678 + size_t left;
96679 char __user *buf = i->iov->iov_base + i->iov_offset;
96680 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
96681 copied = bytes - left;
96682 @@ -231,7 +231,7 @@ static void advance_iovec(struct iov_iter *i, size_t bytes)
96683 * zero-length segments (without overruning the iovec).
96684 */
96685 while (bytes || unlikely(i->count && !iov->iov_len)) {
96686 - int copy;
96687 + size_t copy;
96688
96689 copy = min(bytes, iov->iov_len - base);
96690 BUG_ON(!i->count || i->count < copy);
96691 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
96692 index 3cda50c..032ba634 100644
96693 --- a/mm/kmemleak.c
96694 +++ b/mm/kmemleak.c
96695 @@ -364,7 +364,7 @@ static void print_unreferenced(struct seq_file *seq,
96696
96697 for (i = 0; i < object->trace_len; i++) {
96698 void *ptr = (void *)object->trace[i];
96699 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
96700 + seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
96701 }
96702 }
96703
96704 @@ -1905,7 +1905,7 @@ static int __init kmemleak_late_init(void)
96705 return -ENOMEM;
96706 }
96707
96708 - dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
96709 + dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
96710 &kmemleak_fops);
96711 if (!dentry)
96712 pr_warning("Failed to create the debugfs kmemleak file\n");
96713 diff --git a/mm/maccess.c b/mm/maccess.c
96714 index d53adf9..03a24bf 100644
96715 --- a/mm/maccess.c
96716 +++ b/mm/maccess.c
96717 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
96718 set_fs(KERNEL_DS);
96719 pagefault_disable();
96720 ret = __copy_from_user_inatomic(dst,
96721 - (__force const void __user *)src, size);
96722 + (const void __force_user *)src, size);
96723 pagefault_enable();
96724 set_fs(old_fs);
96725
96726 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
96727
96728 set_fs(KERNEL_DS);
96729 pagefault_disable();
96730 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
96731 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
96732 pagefault_enable();
96733 set_fs(old_fs);
96734
96735 diff --git a/mm/madvise.c b/mm/madvise.c
96736 index 0938b30..199abe8 100644
96737 --- a/mm/madvise.c
96738 +++ b/mm/madvise.c
96739 @@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct *vma,
96740 pgoff_t pgoff;
96741 unsigned long new_flags = vma->vm_flags;
96742
96743 +#ifdef CONFIG_PAX_SEGMEXEC
96744 + struct vm_area_struct *vma_m;
96745 +#endif
96746 +
96747 switch (behavior) {
96748 case MADV_NORMAL:
96749 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
96750 @@ -126,6 +130,13 @@ success:
96751 /*
96752 * vm_flags is protected by the mmap_sem held in write mode.
96753 */
96754 +
96755 +#ifdef CONFIG_PAX_SEGMEXEC
96756 + vma_m = pax_find_mirror_vma(vma);
96757 + if (vma_m)
96758 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
96759 +#endif
96760 +
96761 vma->vm_flags = new_flags;
96762
96763 out:
96764 @@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct *vma,
96765 struct vm_area_struct **prev,
96766 unsigned long start, unsigned long end)
96767 {
96768 +
96769 +#ifdef CONFIG_PAX_SEGMEXEC
96770 + struct vm_area_struct *vma_m;
96771 +#endif
96772 +
96773 *prev = vma;
96774 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
96775 return -EINVAL;
96776 @@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct *vma,
96777 zap_page_range(vma, start, end - start, &details);
96778 } else
96779 zap_page_range(vma, start, end - start, NULL);
96780 +
96781 +#ifdef CONFIG_PAX_SEGMEXEC
96782 + vma_m = pax_find_mirror_vma(vma);
96783 + if (vma_m) {
96784 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
96785 + struct zap_details details = {
96786 + .nonlinear_vma = vma_m,
96787 + .last_index = ULONG_MAX,
96788 + };
96789 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
96790 + } else
96791 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
96792 + }
96793 +#endif
96794 +
96795 return 0;
96796 }
96797
96798 @@ -488,6 +519,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
96799 if (end < start)
96800 return error;
96801
96802 +#ifdef CONFIG_PAX_SEGMEXEC
96803 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
96804 + if (end > SEGMEXEC_TASK_SIZE)
96805 + return error;
96806 + } else
96807 +#endif
96808 +
96809 + if (end > TASK_SIZE)
96810 + return error;
96811 +
96812 error = 0;
96813 if (end == start)
96814 return error;
96815 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
96816 index 44c6bd2..60369dc3 100644
96817 --- a/mm/memory-failure.c
96818 +++ b/mm/memory-failure.c
96819 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
96820
96821 int sysctl_memory_failure_recovery __read_mostly = 1;
96822
96823 -atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
96824 +atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
96825
96826 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
96827
96828 @@ -198,7 +198,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
96829 pfn, t->comm, t->pid);
96830 si.si_signo = SIGBUS;
96831 si.si_errno = 0;
96832 - si.si_addr = (void *)addr;
96833 + si.si_addr = (void __user *)addr;
96834 #ifdef __ARCH_SI_TRAPNO
96835 si.si_trapno = trapno;
96836 #endif
96837 @@ -791,7 +791,7 @@ static struct page_state {
96838 unsigned long res;
96839 char *msg;
96840 int (*action)(struct page *p, unsigned long pfn);
96841 -} error_states[] = {
96842 +} __do_const error_states[] = {
96843 { reserved, reserved, "reserved kernel", me_kernel },
96844 /*
96845 * free pages are specially detected outside this table:
96846 @@ -1099,7 +1099,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
96847 nr_pages = 1 << compound_order(hpage);
96848 else /* normal page or thp */
96849 nr_pages = 1;
96850 - atomic_long_add(nr_pages, &num_poisoned_pages);
96851 + atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
96852
96853 /*
96854 * We need/can do nothing about count=0 pages.
96855 @@ -1128,7 +1128,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
96856 if (PageHWPoison(hpage)) {
96857 if ((hwpoison_filter(p) && TestClearPageHWPoison(p))
96858 || (p != hpage && TestSetPageHWPoison(hpage))) {
96859 - atomic_long_sub(nr_pages, &num_poisoned_pages);
96860 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
96861 unlock_page(hpage);
96862 return 0;
96863 }
96864 @@ -1196,14 +1196,14 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
96865 */
96866 if (!PageHWPoison(p)) {
96867 printk(KERN_ERR "MCE %#lx: just unpoisoned\n", pfn);
96868 - atomic_long_sub(nr_pages, &num_poisoned_pages);
96869 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
96870 put_page(hpage);
96871 res = 0;
96872 goto out;
96873 }
96874 if (hwpoison_filter(p)) {
96875 if (TestClearPageHWPoison(p))
96876 - atomic_long_sub(nr_pages, &num_poisoned_pages);
96877 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
96878 unlock_page(hpage);
96879 put_page(hpage);
96880 return 0;
96881 @@ -1433,7 +1433,7 @@ int unpoison_memory(unsigned long pfn)
96882 return 0;
96883 }
96884 if (TestClearPageHWPoison(p))
96885 - atomic_long_dec(&num_poisoned_pages);
96886 + atomic_long_dec_unchecked(&num_poisoned_pages);
96887 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
96888 return 0;
96889 }
96890 @@ -1447,7 +1447,7 @@ int unpoison_memory(unsigned long pfn)
96891 */
96892 if (TestClearPageHWPoison(page)) {
96893 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
96894 - atomic_long_sub(nr_pages, &num_poisoned_pages);
96895 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
96896 freeit = 1;
96897 if (PageHuge(page))
96898 clear_page_hwpoison_huge_page(page);
96899 @@ -1572,11 +1572,11 @@ static int soft_offline_huge_page(struct page *page, int flags)
96900 if (PageHuge(page)) {
96901 set_page_hwpoison_huge_page(hpage);
96902 dequeue_hwpoisoned_huge_page(hpage);
96903 - atomic_long_add(1 << compound_order(hpage),
96904 + atomic_long_add_unchecked(1 << compound_order(hpage),
96905 &num_poisoned_pages);
96906 } else {
96907 SetPageHWPoison(page);
96908 - atomic_long_inc(&num_poisoned_pages);
96909 + atomic_long_inc_unchecked(&num_poisoned_pages);
96910 }
96911 }
96912 return ret;
96913 @@ -1615,7 +1615,7 @@ static int __soft_offline_page(struct page *page, int flags)
96914 put_page(page);
96915 pr_info("soft_offline: %#lx: invalidated\n", pfn);
96916 SetPageHWPoison(page);
96917 - atomic_long_inc(&num_poisoned_pages);
96918 + atomic_long_inc_unchecked(&num_poisoned_pages);
96919 return 0;
96920 }
96921
96922 @@ -1666,7 +1666,7 @@ static int __soft_offline_page(struct page *page, int flags)
96923 if (!is_free_buddy_page(page))
96924 pr_info("soft offline: %#lx: page leaked\n",
96925 pfn);
96926 - atomic_long_inc(&num_poisoned_pages);
96927 + atomic_long_inc_unchecked(&num_poisoned_pages);
96928 }
96929 } else {
96930 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
96931 @@ -1736,11 +1736,11 @@ int soft_offline_page(struct page *page, int flags)
96932 if (PageHuge(page)) {
96933 set_page_hwpoison_huge_page(hpage);
96934 dequeue_hwpoisoned_huge_page(hpage);
96935 - atomic_long_add(1 << compound_order(hpage),
96936 + atomic_long_add_unchecked(1 << compound_order(hpage),
96937 &num_poisoned_pages);
96938 } else {
96939 SetPageHWPoison(page);
96940 - atomic_long_inc(&num_poisoned_pages);
96941 + atomic_long_inc_unchecked(&num_poisoned_pages);
96942 }
96943 }
96944 unset_migratetype_isolate(page, MIGRATE_MOVABLE);
96945 diff --git a/mm/memory.c b/mm/memory.c
96946 index e497def..9cdef79 100644
96947 --- a/mm/memory.c
96948 +++ b/mm/memory.c
96949 @@ -415,6 +415,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
96950 free_pte_range(tlb, pmd, addr);
96951 } while (pmd++, addr = next, addr != end);
96952
96953 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
96954 start &= PUD_MASK;
96955 if (start < floor)
96956 return;
96957 @@ -429,6 +430,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
96958 pmd = pmd_offset(pud, start);
96959 pud_clear(pud);
96960 pmd_free_tlb(tlb, pmd, start);
96961 +#endif
96962 +
96963 }
96964
96965 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
96966 @@ -448,6 +451,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
96967 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
96968 } while (pud++, addr = next, addr != end);
96969
96970 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
96971 start &= PGDIR_MASK;
96972 if (start < floor)
96973 return;
96974 @@ -462,6 +466,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
96975 pud = pud_offset(pgd, start);
96976 pgd_clear(pgd);
96977 pud_free_tlb(tlb, pud, start);
96978 +#endif
96979 +
96980 }
96981
96982 /*
96983 @@ -691,10 +697,10 @@ static void print_bad_pte(struct vm_area_struct *vma, unsigned long addr,
96984 * Choose text because data symbols depend on CONFIG_KALLSYMS_ALL=y
96985 */
96986 if (vma->vm_ops)
96987 - printk(KERN_ALERT "vma->vm_ops->fault: %pSR\n",
96988 + printk(KERN_ALERT "vma->vm_ops->fault: %pAR\n",
96989 vma->vm_ops->fault);
96990 if (vma->vm_file)
96991 - printk(KERN_ALERT "vma->vm_file->f_op->mmap: %pSR\n",
96992 + printk(KERN_ALERT "vma->vm_file->f_op->mmap: %pAR\n",
96993 vma->vm_file->f_op->mmap);
96994 dump_stack();
96995 add_taint(TAINT_BAD_PAGE, LOCKDEP_NOW_UNRELIABLE);
96996 @@ -1501,6 +1507,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
96997 page_add_file_rmap(page);
96998 set_pte_at(mm, addr, pte, mk_pte(page, prot));
96999
97000 +#ifdef CONFIG_PAX_SEGMEXEC
97001 + pax_mirror_file_pte(vma, addr, page, ptl);
97002 +#endif
97003 +
97004 retval = 0;
97005 pte_unmap_unlock(pte, ptl);
97006 return retval;
97007 @@ -1545,9 +1555,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
97008 if (!page_count(page))
97009 return -EINVAL;
97010 if (!(vma->vm_flags & VM_MIXEDMAP)) {
97011 +
97012 +#ifdef CONFIG_PAX_SEGMEXEC
97013 + struct vm_area_struct *vma_m;
97014 +#endif
97015 +
97016 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
97017 BUG_ON(vma->vm_flags & VM_PFNMAP);
97018 vma->vm_flags |= VM_MIXEDMAP;
97019 +
97020 +#ifdef CONFIG_PAX_SEGMEXEC
97021 + vma_m = pax_find_mirror_vma(vma);
97022 + if (vma_m)
97023 + vma_m->vm_flags |= VM_MIXEDMAP;
97024 +#endif
97025 +
97026 }
97027 return insert_page(vma, addr, page, vma->vm_page_prot);
97028 }
97029 @@ -1630,6 +1652,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
97030 unsigned long pfn)
97031 {
97032 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
97033 + BUG_ON(vma->vm_mirror);
97034
97035 if (addr < vma->vm_start || addr >= vma->vm_end)
97036 return -EFAULT;
97037 @@ -1877,7 +1900,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
97038
97039 BUG_ON(pud_huge(*pud));
97040
97041 - pmd = pmd_alloc(mm, pud, addr);
97042 + pmd = (mm == &init_mm) ?
97043 + pmd_alloc_kernel(mm, pud, addr) :
97044 + pmd_alloc(mm, pud, addr);
97045 if (!pmd)
97046 return -ENOMEM;
97047 do {
97048 @@ -1897,7 +1922,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
97049 unsigned long next;
97050 int err;
97051
97052 - pud = pud_alloc(mm, pgd, addr);
97053 + pud = (mm == &init_mm) ?
97054 + pud_alloc_kernel(mm, pgd, addr) :
97055 + pud_alloc(mm, pgd, addr);
97056 if (!pud)
97057 return -ENOMEM;
97058 do {
97059 @@ -2019,6 +2046,186 @@ static int do_page_mkwrite(struct vm_area_struct *vma, struct page *page,
97060 return ret;
97061 }
97062
97063 +#ifdef CONFIG_PAX_SEGMEXEC
97064 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
97065 +{
97066 + struct mm_struct *mm = vma->vm_mm;
97067 + spinlock_t *ptl;
97068 + pte_t *pte, entry;
97069 +
97070 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
97071 + entry = *pte;
97072 + if (!pte_present(entry)) {
97073 + if (!pte_none(entry)) {
97074 + BUG_ON(pte_file(entry));
97075 + free_swap_and_cache(pte_to_swp_entry(entry));
97076 + pte_clear_not_present_full(mm, address, pte, 0);
97077 + }
97078 + } else {
97079 + struct page *page;
97080 +
97081 + flush_cache_page(vma, address, pte_pfn(entry));
97082 + entry = ptep_clear_flush(vma, address, pte);
97083 + BUG_ON(pte_dirty(entry));
97084 + page = vm_normal_page(vma, address, entry);
97085 + if (page) {
97086 + update_hiwater_rss(mm);
97087 + if (PageAnon(page))
97088 + dec_mm_counter_fast(mm, MM_ANONPAGES);
97089 + else
97090 + dec_mm_counter_fast(mm, MM_FILEPAGES);
97091 + page_remove_rmap(page);
97092 + page_cache_release(page);
97093 + }
97094 + }
97095 + pte_unmap_unlock(pte, ptl);
97096 +}
97097 +
97098 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
97099 + *
97100 + * the ptl of the lower mapped page is held on entry and is not released on exit
97101 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
97102 + */
97103 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
97104 +{
97105 + struct mm_struct *mm = vma->vm_mm;
97106 + unsigned long address_m;
97107 + spinlock_t *ptl_m;
97108 + struct vm_area_struct *vma_m;
97109 + pmd_t *pmd_m;
97110 + pte_t *pte_m, entry_m;
97111 +
97112 + BUG_ON(!page_m || !PageAnon(page_m));
97113 +
97114 + vma_m = pax_find_mirror_vma(vma);
97115 + if (!vma_m)
97116 + return;
97117 +
97118 + BUG_ON(!PageLocked(page_m));
97119 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
97120 + address_m = address + SEGMEXEC_TASK_SIZE;
97121 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
97122 + pte_m = pte_offset_map(pmd_m, address_m);
97123 + ptl_m = pte_lockptr(mm, pmd_m);
97124 + if (ptl != ptl_m) {
97125 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
97126 + if (!pte_none(*pte_m))
97127 + goto out;
97128 + }
97129 +
97130 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
97131 + page_cache_get(page_m);
97132 + page_add_anon_rmap(page_m, vma_m, address_m);
97133 + inc_mm_counter_fast(mm, MM_ANONPAGES);
97134 + set_pte_at(mm, address_m, pte_m, entry_m);
97135 + update_mmu_cache(vma_m, address_m, pte_m);
97136 +out:
97137 + if (ptl != ptl_m)
97138 + spin_unlock(ptl_m);
97139 + pte_unmap(pte_m);
97140 + unlock_page(page_m);
97141 +}
97142 +
97143 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
97144 +{
97145 + struct mm_struct *mm = vma->vm_mm;
97146 + unsigned long address_m;
97147 + spinlock_t *ptl_m;
97148 + struct vm_area_struct *vma_m;
97149 + pmd_t *pmd_m;
97150 + pte_t *pte_m, entry_m;
97151 +
97152 + BUG_ON(!page_m || PageAnon(page_m));
97153 +
97154 + vma_m = pax_find_mirror_vma(vma);
97155 + if (!vma_m)
97156 + return;
97157 +
97158 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
97159 + address_m = address + SEGMEXEC_TASK_SIZE;
97160 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
97161 + pte_m = pte_offset_map(pmd_m, address_m);
97162 + ptl_m = pte_lockptr(mm, pmd_m);
97163 + if (ptl != ptl_m) {
97164 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
97165 + if (!pte_none(*pte_m))
97166 + goto out;
97167 + }
97168 +
97169 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
97170 + page_cache_get(page_m);
97171 + page_add_file_rmap(page_m);
97172 + inc_mm_counter_fast(mm, MM_FILEPAGES);
97173 + set_pte_at(mm, address_m, pte_m, entry_m);
97174 + update_mmu_cache(vma_m, address_m, pte_m);
97175 +out:
97176 + if (ptl != ptl_m)
97177 + spin_unlock(ptl_m);
97178 + pte_unmap(pte_m);
97179 +}
97180 +
97181 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
97182 +{
97183 + struct mm_struct *mm = vma->vm_mm;
97184 + unsigned long address_m;
97185 + spinlock_t *ptl_m;
97186 + struct vm_area_struct *vma_m;
97187 + pmd_t *pmd_m;
97188 + pte_t *pte_m, entry_m;
97189 +
97190 + vma_m = pax_find_mirror_vma(vma);
97191 + if (!vma_m)
97192 + return;
97193 +
97194 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
97195 + address_m = address + SEGMEXEC_TASK_SIZE;
97196 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
97197 + pte_m = pte_offset_map(pmd_m, address_m);
97198 + ptl_m = pte_lockptr(mm, pmd_m);
97199 + if (ptl != ptl_m) {
97200 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
97201 + if (!pte_none(*pte_m))
97202 + goto out;
97203 + }
97204 +
97205 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
97206 + set_pte_at(mm, address_m, pte_m, entry_m);
97207 +out:
97208 + if (ptl != ptl_m)
97209 + spin_unlock(ptl_m);
97210 + pte_unmap(pte_m);
97211 +}
97212 +
97213 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
97214 +{
97215 + struct page *page_m;
97216 + pte_t entry;
97217 +
97218 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
97219 + goto out;
97220 +
97221 + entry = *pte;
97222 + page_m = vm_normal_page(vma, address, entry);
97223 + if (!page_m)
97224 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
97225 + else if (PageAnon(page_m)) {
97226 + if (pax_find_mirror_vma(vma)) {
97227 + pte_unmap_unlock(pte, ptl);
97228 + lock_page(page_m);
97229 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
97230 + if (pte_same(entry, *pte))
97231 + pax_mirror_anon_pte(vma, address, page_m, ptl);
97232 + else
97233 + unlock_page(page_m);
97234 + }
97235 + } else
97236 + pax_mirror_file_pte(vma, address, page_m, ptl);
97237 +
97238 +out:
97239 + pte_unmap_unlock(pte, ptl);
97240 +}
97241 +#endif
97242 +
97243 /*
97244 * This routine handles present pages, when users try to write
97245 * to a shared page. It is done by copying the page to a new address
97246 @@ -2217,6 +2424,12 @@ gotten:
97247 */
97248 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
97249 if (likely(pte_same(*page_table, orig_pte))) {
97250 +
97251 +#ifdef CONFIG_PAX_SEGMEXEC
97252 + if (pax_find_mirror_vma(vma))
97253 + BUG_ON(!trylock_page(new_page));
97254 +#endif
97255 +
97256 if (old_page) {
97257 if (!PageAnon(old_page)) {
97258 dec_mm_counter_fast(mm, MM_FILEPAGES);
97259 @@ -2270,6 +2483,10 @@ gotten:
97260 page_remove_rmap(old_page);
97261 }
97262
97263 +#ifdef CONFIG_PAX_SEGMEXEC
97264 + pax_mirror_anon_pte(vma, address, new_page, ptl);
97265 +#endif
97266 +
97267 /* Free the old page.. */
97268 new_page = old_page;
97269 ret |= VM_FAULT_WRITE;
97270 @@ -2544,6 +2761,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
97271 swap_free(entry);
97272 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
97273 try_to_free_swap(page);
97274 +
97275 +#ifdef CONFIG_PAX_SEGMEXEC
97276 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
97277 +#endif
97278 +
97279 unlock_page(page);
97280 if (page != swapcache) {
97281 /*
97282 @@ -2567,6 +2789,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
97283
97284 /* No need to invalidate - it was non-present before */
97285 update_mmu_cache(vma, address, page_table);
97286 +
97287 +#ifdef CONFIG_PAX_SEGMEXEC
97288 + pax_mirror_anon_pte(vma, address, page, ptl);
97289 +#endif
97290 +
97291 unlock:
97292 pte_unmap_unlock(page_table, ptl);
97293 out:
97294 @@ -2586,40 +2813,6 @@ out_release:
97295 }
97296
97297 /*
97298 - * This is like a special single-page "expand_{down|up}wards()",
97299 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
97300 - * doesn't hit another vma.
97301 - */
97302 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
97303 -{
97304 - address &= PAGE_MASK;
97305 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
97306 - struct vm_area_struct *prev = vma->vm_prev;
97307 -
97308 - /*
97309 - * Is there a mapping abutting this one below?
97310 - *
97311 - * That's only ok if it's the same stack mapping
97312 - * that has gotten split..
97313 - */
97314 - if (prev && prev->vm_end == address)
97315 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
97316 -
97317 - expand_downwards(vma, address - PAGE_SIZE);
97318 - }
97319 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
97320 - struct vm_area_struct *next = vma->vm_next;
97321 -
97322 - /* As VM_GROWSDOWN but s/below/above/ */
97323 - if (next && next->vm_start == address + PAGE_SIZE)
97324 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
97325 -
97326 - expand_upwards(vma, address + PAGE_SIZE);
97327 - }
97328 - return 0;
97329 -}
97330 -
97331 -/*
97332 * We enter with non-exclusive mmap_sem (to exclude vma changes,
97333 * but allow concurrent faults), and pte mapped but not yet locked.
97334 * We return with mmap_sem still held, but pte unmapped and unlocked.
97335 @@ -2629,27 +2822,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
97336 unsigned int flags)
97337 {
97338 struct mem_cgroup *memcg;
97339 - struct page *page;
97340 + struct page *page = NULL;
97341 spinlock_t *ptl;
97342 pte_t entry;
97343
97344 - pte_unmap(page_table);
97345 -
97346 - /* Check if we need to add a guard page to the stack */
97347 - if (check_stack_guard_page(vma, address) < 0)
97348 - return VM_FAULT_SIGBUS;
97349 -
97350 - /* Use the zero-page for reads */
97351 if (!(flags & FAULT_FLAG_WRITE)) {
97352 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
97353 vma->vm_page_prot));
97354 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
97355 + ptl = pte_lockptr(mm, pmd);
97356 + spin_lock(ptl);
97357 if (!pte_none(*page_table))
97358 goto unlock;
97359 goto setpte;
97360 }
97361
97362 /* Allocate our own private page. */
97363 + pte_unmap(page_table);
97364 +
97365 if (unlikely(anon_vma_prepare(vma)))
97366 goto oom;
97367 page = alloc_zeroed_user_highpage_movable(vma, address);
97368 @@ -2673,6 +2862,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
97369 if (!pte_none(*page_table))
97370 goto release;
97371
97372 +#ifdef CONFIG_PAX_SEGMEXEC
97373 + if (pax_find_mirror_vma(vma))
97374 + BUG_ON(!trylock_page(page));
97375 +#endif
97376 +
97377 inc_mm_counter_fast(mm, MM_ANONPAGES);
97378 page_add_new_anon_rmap(page, vma, address);
97379 mem_cgroup_commit_charge(page, memcg, false);
97380 @@ -2682,6 +2876,12 @@ setpte:
97381
97382 /* No need to invalidate - it was non-present before */
97383 update_mmu_cache(vma, address, page_table);
97384 +
97385 +#ifdef CONFIG_PAX_SEGMEXEC
97386 + if (page)
97387 + pax_mirror_anon_pte(vma, address, page, ptl);
97388 +#endif
97389 +
97390 unlock:
97391 pte_unmap_unlock(page_table, ptl);
97392 return 0;
97393 @@ -2912,6 +3112,11 @@ static int do_read_fault(struct mm_struct *mm, struct vm_area_struct *vma,
97394 return ret;
97395 }
97396 do_set_pte(vma, address, fault_page, pte, false, false);
97397 +
97398 +#ifdef CONFIG_PAX_SEGMEXEC
97399 + pax_mirror_file_pte(vma, address, fault_page, ptl);
97400 +#endif
97401 +
97402 unlock_page(fault_page);
97403 unlock_out:
97404 pte_unmap_unlock(pte, ptl);
97405 @@ -2954,7 +3159,18 @@ static int do_cow_fault(struct mm_struct *mm, struct vm_area_struct *vma,
97406 page_cache_release(fault_page);
97407 goto uncharge_out;
97408 }
97409 +
97410 +#ifdef CONFIG_PAX_SEGMEXEC
97411 + if (pax_find_mirror_vma(vma))
97412 + BUG_ON(!trylock_page(new_page));
97413 +#endif
97414 +
97415 do_set_pte(vma, address, new_page, pte, true, true);
97416 +
97417 +#ifdef CONFIG_PAX_SEGMEXEC
97418 + pax_mirror_anon_pte(vma, address, new_page, ptl);
97419 +#endif
97420 +
97421 mem_cgroup_commit_charge(new_page, memcg, false);
97422 lru_cache_add_active_or_unevictable(new_page, vma);
97423 pte_unmap_unlock(pte, ptl);
97424 @@ -3004,6 +3220,11 @@ static int do_shared_fault(struct mm_struct *mm, struct vm_area_struct *vma,
97425 return ret;
97426 }
97427 do_set_pte(vma, address, fault_page, pte, true, false);
97428 +
97429 +#ifdef CONFIG_PAX_SEGMEXEC
97430 + pax_mirror_file_pte(vma, address, fault_page, ptl);
97431 +#endif
97432 +
97433 pte_unmap_unlock(pte, ptl);
97434
97435 if (set_page_dirty(fault_page))
97436 @@ -3245,6 +3466,12 @@ static int handle_pte_fault(struct mm_struct *mm,
97437 if (flags & FAULT_FLAG_WRITE)
97438 flush_tlb_fix_spurious_fault(vma, address);
97439 }
97440 +
97441 +#ifdef CONFIG_PAX_SEGMEXEC
97442 + pax_mirror_pte(vma, address, pte, pmd, ptl);
97443 + return 0;
97444 +#endif
97445 +
97446 unlock:
97447 pte_unmap_unlock(pte, ptl);
97448 return 0;
97449 @@ -3264,9 +3491,41 @@ static int __handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
97450 pmd_t *pmd;
97451 pte_t *pte;
97452
97453 +#ifdef CONFIG_PAX_SEGMEXEC
97454 + struct vm_area_struct *vma_m;
97455 +#endif
97456 +
97457 if (unlikely(is_vm_hugetlb_page(vma)))
97458 return hugetlb_fault(mm, vma, address, flags);
97459
97460 +#ifdef CONFIG_PAX_SEGMEXEC
97461 + vma_m = pax_find_mirror_vma(vma);
97462 + if (vma_m) {
97463 + unsigned long address_m;
97464 + pgd_t *pgd_m;
97465 + pud_t *pud_m;
97466 + pmd_t *pmd_m;
97467 +
97468 + if (vma->vm_start > vma_m->vm_start) {
97469 + address_m = address;
97470 + address -= SEGMEXEC_TASK_SIZE;
97471 + vma = vma_m;
97472 + } else
97473 + address_m = address + SEGMEXEC_TASK_SIZE;
97474 +
97475 + pgd_m = pgd_offset(mm, address_m);
97476 + pud_m = pud_alloc(mm, pgd_m, address_m);
97477 + if (!pud_m)
97478 + return VM_FAULT_OOM;
97479 + pmd_m = pmd_alloc(mm, pud_m, address_m);
97480 + if (!pmd_m)
97481 + return VM_FAULT_OOM;
97482 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
97483 + return VM_FAULT_OOM;
97484 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
97485 + }
97486 +#endif
97487 +
97488 pgd = pgd_offset(mm, address);
97489 pud = pud_alloc(mm, pgd, address);
97490 if (!pud)
97491 @@ -3400,6 +3659,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
97492 spin_unlock(&mm->page_table_lock);
97493 return 0;
97494 }
97495 +
97496 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
97497 +{
97498 + pud_t *new = pud_alloc_one(mm, address);
97499 + if (!new)
97500 + return -ENOMEM;
97501 +
97502 + smp_wmb(); /* See comment in __pte_alloc */
97503 +
97504 + spin_lock(&mm->page_table_lock);
97505 + if (pgd_present(*pgd)) /* Another has populated it */
97506 + pud_free(mm, new);
97507 + else
97508 + pgd_populate_kernel(mm, pgd, new);
97509 + spin_unlock(&mm->page_table_lock);
97510 + return 0;
97511 +}
97512 #endif /* __PAGETABLE_PUD_FOLDED */
97513
97514 #ifndef __PAGETABLE_PMD_FOLDED
97515 @@ -3430,6 +3706,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
97516 spin_unlock(&mm->page_table_lock);
97517 return 0;
97518 }
97519 +
97520 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
97521 +{
97522 + pmd_t *new = pmd_alloc_one(mm, address);
97523 + if (!new)
97524 + return -ENOMEM;
97525 +
97526 + smp_wmb(); /* See comment in __pte_alloc */
97527 +
97528 + spin_lock(&mm->page_table_lock);
97529 +#ifndef __ARCH_HAS_4LEVEL_HACK
97530 + if (pud_present(*pud)) /* Another has populated it */
97531 + pmd_free(mm, new);
97532 + else
97533 + pud_populate_kernel(mm, pud, new);
97534 +#else
97535 + if (pgd_present(*pud)) /* Another has populated it */
97536 + pmd_free(mm, new);
97537 + else
97538 + pgd_populate_kernel(mm, pud, new);
97539 +#endif /* __ARCH_HAS_4LEVEL_HACK */
97540 + spin_unlock(&mm->page_table_lock);
97541 + return 0;
97542 +}
97543 #endif /* __PAGETABLE_PMD_FOLDED */
97544
97545 static int __follow_pte(struct mm_struct *mm, unsigned long address,
97546 @@ -3539,8 +3839,8 @@ out:
97547 return ret;
97548 }
97549
97550 -int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
97551 - void *buf, int len, int write)
97552 +ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
97553 + void *buf, size_t len, int write)
97554 {
97555 resource_size_t phys_addr;
97556 unsigned long prot = 0;
97557 @@ -3566,8 +3866,8 @@ EXPORT_SYMBOL_GPL(generic_access_phys);
97558 * Access another process' address space as given in mm. If non-NULL, use the
97559 * given task for page fault accounting.
97560 */
97561 -static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
97562 - unsigned long addr, void *buf, int len, int write)
97563 +static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
97564 + unsigned long addr, void *buf, size_t len, int write)
97565 {
97566 struct vm_area_struct *vma;
97567 void *old_buf = buf;
97568 @@ -3575,7 +3875,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
97569 down_read(&mm->mmap_sem);
97570 /* ignore errors, just check how much was successfully transferred */
97571 while (len) {
97572 - int bytes, ret, offset;
97573 + ssize_t bytes, ret, offset;
97574 void *maddr;
97575 struct page *page = NULL;
97576
97577 @@ -3636,8 +3936,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
97578 *
97579 * The caller must hold a reference on @mm.
97580 */
97581 -int access_remote_vm(struct mm_struct *mm, unsigned long addr,
97582 - void *buf, int len, int write)
97583 +ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
97584 + void *buf, size_t len, int write)
97585 {
97586 return __access_remote_vm(NULL, mm, addr, buf, len, write);
97587 }
97588 @@ -3647,11 +3947,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
97589 * Source/target buffer must be kernel space,
97590 * Do not walk the page table directly, use get_user_pages
97591 */
97592 -int access_process_vm(struct task_struct *tsk, unsigned long addr,
97593 - void *buf, int len, int write)
97594 +ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
97595 + void *buf, size_t len, int write)
97596 {
97597 struct mm_struct *mm;
97598 - int ret;
97599 + ssize_t ret;
97600
97601 mm = get_task_mm(tsk);
97602 if (!mm)
97603 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
97604 index 8f5330d..b41914b 100644
97605 --- a/mm/mempolicy.c
97606 +++ b/mm/mempolicy.c
97607 @@ -750,6 +750,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
97608 unsigned long vmstart;
97609 unsigned long vmend;
97610
97611 +#ifdef CONFIG_PAX_SEGMEXEC
97612 + struct vm_area_struct *vma_m;
97613 +#endif
97614 +
97615 vma = find_vma(mm, start);
97616 if (!vma || vma->vm_start > start)
97617 return -EFAULT;
97618 @@ -793,6 +797,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
97619 err = vma_replace_policy(vma, new_pol);
97620 if (err)
97621 goto out;
97622 +
97623 +#ifdef CONFIG_PAX_SEGMEXEC
97624 + vma_m = pax_find_mirror_vma(vma);
97625 + if (vma_m) {
97626 + err = vma_replace_policy(vma_m, new_pol);
97627 + if (err)
97628 + goto out;
97629 + }
97630 +#endif
97631 +
97632 }
97633
97634 out:
97635 @@ -1225,6 +1239,17 @@ static long do_mbind(unsigned long start, unsigned long len,
97636
97637 if (end < start)
97638 return -EINVAL;
97639 +
97640 +#ifdef CONFIG_PAX_SEGMEXEC
97641 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
97642 + if (end > SEGMEXEC_TASK_SIZE)
97643 + return -EINVAL;
97644 + } else
97645 +#endif
97646 +
97647 + if (end > TASK_SIZE)
97648 + return -EINVAL;
97649 +
97650 if (end == start)
97651 return 0;
97652
97653 @@ -1450,8 +1475,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
97654 */
97655 tcred = __task_cred(task);
97656 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
97657 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
97658 - !capable(CAP_SYS_NICE)) {
97659 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
97660 rcu_read_unlock();
97661 err = -EPERM;
97662 goto out_put;
97663 @@ -1482,6 +1506,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
97664 goto out;
97665 }
97666
97667 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
97668 + if (mm != current->mm &&
97669 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
97670 + mmput(mm);
97671 + err = -EPERM;
97672 + goto out;
97673 + }
97674 +#endif
97675 +
97676 err = do_migrate_pages(mm, old, new,
97677 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
97678
97679 diff --git a/mm/migrate.c b/mm/migrate.c
97680 index 0143995..b294728 100644
97681 --- a/mm/migrate.c
97682 +++ b/mm/migrate.c
97683 @@ -1495,8 +1495,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
97684 */
97685 tcred = __task_cred(task);
97686 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
97687 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
97688 - !capable(CAP_SYS_NICE)) {
97689 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
97690 rcu_read_unlock();
97691 err = -EPERM;
97692 goto out;
97693 diff --git a/mm/mlock.c b/mm/mlock.c
97694 index ce84cb0..6d5a9aa 100644
97695 --- a/mm/mlock.c
97696 +++ b/mm/mlock.c
97697 @@ -14,6 +14,7 @@
97698 #include <linux/pagevec.h>
97699 #include <linux/mempolicy.h>
97700 #include <linux/syscalls.h>
97701 +#include <linux/security.h>
97702 #include <linux/sched.h>
97703 #include <linux/export.h>
97704 #include <linux/rmap.h>
97705 @@ -613,7 +614,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
97706 {
97707 unsigned long nstart, end, tmp;
97708 struct vm_area_struct * vma, * prev;
97709 - int error;
97710 + int error = 0;
97711
97712 VM_BUG_ON(start & ~PAGE_MASK);
97713 VM_BUG_ON(len != PAGE_ALIGN(len));
97714 @@ -622,6 +623,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
97715 return -EINVAL;
97716 if (end == start)
97717 return 0;
97718 + if (end > TASK_SIZE)
97719 + return -EINVAL;
97720 +
97721 vma = find_vma(current->mm, start);
97722 if (!vma || vma->vm_start > start)
97723 return -ENOMEM;
97724 @@ -633,6 +637,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
97725 for (nstart = start ; ; ) {
97726 vm_flags_t newflags;
97727
97728 +#ifdef CONFIG_PAX_SEGMEXEC
97729 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
97730 + break;
97731 +#endif
97732 +
97733 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
97734
97735 newflags = vma->vm_flags & ~VM_LOCKED;
97736 @@ -746,6 +755,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
97737 locked += current->mm->locked_vm;
97738
97739 /* check against resource limits */
97740 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
97741 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
97742 error = do_mlock(start, len, 1);
97743
97744 @@ -783,6 +793,11 @@ static int do_mlockall(int flags)
97745 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
97746 vm_flags_t newflags;
97747
97748 +#ifdef CONFIG_PAX_SEGMEXEC
97749 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
97750 + break;
97751 +#endif
97752 +
97753 newflags = vma->vm_flags & ~VM_LOCKED;
97754 if (flags & MCL_CURRENT)
97755 newflags |= VM_LOCKED;
97756 @@ -814,8 +829,10 @@ SYSCALL_DEFINE1(mlockall, int, flags)
97757 lock_limit >>= PAGE_SHIFT;
97758
97759 ret = -ENOMEM;
97760 +
97761 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
97762 +
97763 down_write(&current->mm->mmap_sem);
97764 -
97765 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
97766 capable(CAP_IPC_LOCK))
97767 ret = do_mlockall(flags);
97768 diff --git a/mm/mmap.c b/mm/mmap.c
97769 index a226d31..9135e65 100644
97770 --- a/mm/mmap.c
97771 +++ b/mm/mmap.c
97772 @@ -41,6 +41,7 @@
97773 #include <linux/notifier.h>
97774 #include <linux/memory.h>
97775 #include <linux/printk.h>
97776 +#include <linux/random.h>
97777
97778 #include <asm/uaccess.h>
97779 #include <asm/cacheflush.h>
97780 @@ -57,6 +58,16 @@
97781 #define arch_rebalance_pgtables(addr, len) (addr)
97782 #endif
97783
97784 +static inline void verify_mm_writelocked(struct mm_struct *mm)
97785 +{
97786 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
97787 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
97788 + up_read(&mm->mmap_sem);
97789 + BUG();
97790 + }
97791 +#endif
97792 +}
97793 +
97794 static void unmap_region(struct mm_struct *mm,
97795 struct vm_area_struct *vma, struct vm_area_struct *prev,
97796 unsigned long start, unsigned long end);
97797 @@ -76,16 +87,25 @@ static void unmap_region(struct mm_struct *mm,
97798 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
97799 *
97800 */
97801 -pgprot_t protection_map[16] = {
97802 +pgprot_t protection_map[16] __read_only = {
97803 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
97804 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
97805 };
97806
97807 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
97808 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
97809 {
97810 - return __pgprot(pgprot_val(protection_map[vm_flags &
97811 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
97812 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
97813 pgprot_val(arch_vm_get_page_prot(vm_flags)));
97814 +
97815 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
97816 + if (!(__supported_pte_mask & _PAGE_NX) &&
97817 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
97818 + (vm_flags & (VM_READ | VM_WRITE)))
97819 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
97820 +#endif
97821 +
97822 + return prot;
97823 }
97824 EXPORT_SYMBOL(vm_get_page_prot);
97825
97826 @@ -95,6 +115,7 @@ unsigned long sysctl_overcommit_kbytes __read_mostly;
97827 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
97828 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
97829 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
97830 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
97831 /*
97832 * Make sure vm_committed_as in one cacheline and not cacheline shared with
97833 * other variables. It can be updated by several CPUs frequently.
97834 @@ -255,6 +276,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
97835 struct vm_area_struct *next = vma->vm_next;
97836
97837 might_sleep();
97838 + BUG_ON(vma->vm_mirror);
97839 if (vma->vm_ops && vma->vm_ops->close)
97840 vma->vm_ops->close(vma);
97841 if (vma->vm_file)
97842 @@ -299,6 +321,12 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
97843 * not page aligned -Ram Gupta
97844 */
97845 rlim = rlimit(RLIMIT_DATA);
97846 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
97847 + /* force a minimum 16MB brk heap on setuid/setgid binaries */
97848 + if (rlim < PAGE_SIZE && (get_dumpable(mm) != SUID_DUMP_USER) && gr_is_global_nonroot(current_uid()))
97849 + rlim = 4096 * PAGE_SIZE;
97850 +#endif
97851 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
97852 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
97853 (mm->end_data - mm->start_data) > rlim)
97854 goto out;
97855 @@ -952,6 +980,12 @@ static int
97856 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
97857 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
97858 {
97859 +
97860 +#ifdef CONFIG_PAX_SEGMEXEC
97861 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
97862 + return 0;
97863 +#endif
97864 +
97865 if (is_mergeable_vma(vma, file, vm_flags) &&
97866 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
97867 if (vma->vm_pgoff == vm_pgoff)
97868 @@ -971,6 +1005,12 @@ static int
97869 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
97870 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
97871 {
97872 +
97873 +#ifdef CONFIG_PAX_SEGMEXEC
97874 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
97875 + return 0;
97876 +#endif
97877 +
97878 if (is_mergeable_vma(vma, file, vm_flags) &&
97879 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
97880 pgoff_t vm_pglen;
97881 @@ -1013,13 +1053,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
97882 struct vm_area_struct *vma_merge(struct mm_struct *mm,
97883 struct vm_area_struct *prev, unsigned long addr,
97884 unsigned long end, unsigned long vm_flags,
97885 - struct anon_vma *anon_vma, struct file *file,
97886 + struct anon_vma *anon_vma, struct file *file,
97887 pgoff_t pgoff, struct mempolicy *policy)
97888 {
97889 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
97890 struct vm_area_struct *area, *next;
97891 int err;
97892
97893 +#ifdef CONFIG_PAX_SEGMEXEC
97894 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
97895 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
97896 +
97897 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
97898 +#endif
97899 +
97900 /*
97901 * We later require that vma->vm_flags == vm_flags,
97902 * so this tests vma->vm_flags & VM_SPECIAL, too.
97903 @@ -1035,6 +1082,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
97904 if (next && next->vm_end == end) /* cases 6, 7, 8 */
97905 next = next->vm_next;
97906
97907 +#ifdef CONFIG_PAX_SEGMEXEC
97908 + if (prev)
97909 + prev_m = pax_find_mirror_vma(prev);
97910 + if (area)
97911 + area_m = pax_find_mirror_vma(area);
97912 + if (next)
97913 + next_m = pax_find_mirror_vma(next);
97914 +#endif
97915 +
97916 /*
97917 * Can it merge with the predecessor?
97918 */
97919 @@ -1054,9 +1110,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
97920 /* cases 1, 6 */
97921 err = vma_adjust(prev, prev->vm_start,
97922 next->vm_end, prev->vm_pgoff, NULL);
97923 - } else /* cases 2, 5, 7 */
97924 +
97925 +#ifdef CONFIG_PAX_SEGMEXEC
97926 + if (!err && prev_m)
97927 + err = vma_adjust(prev_m, prev_m->vm_start,
97928 + next_m->vm_end, prev_m->vm_pgoff, NULL);
97929 +#endif
97930 +
97931 + } else { /* cases 2, 5, 7 */
97932 err = vma_adjust(prev, prev->vm_start,
97933 end, prev->vm_pgoff, NULL);
97934 +
97935 +#ifdef CONFIG_PAX_SEGMEXEC
97936 + if (!err && prev_m)
97937 + err = vma_adjust(prev_m, prev_m->vm_start,
97938 + end_m, prev_m->vm_pgoff, NULL);
97939 +#endif
97940 +
97941 + }
97942 if (err)
97943 return NULL;
97944 khugepaged_enter_vma_merge(prev, vm_flags);
97945 @@ -1070,12 +1141,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
97946 mpol_equal(policy, vma_policy(next)) &&
97947 can_vma_merge_before(next, vm_flags,
97948 anon_vma, file, pgoff+pglen)) {
97949 - if (prev && addr < prev->vm_end) /* case 4 */
97950 + if (prev && addr < prev->vm_end) { /* case 4 */
97951 err = vma_adjust(prev, prev->vm_start,
97952 addr, prev->vm_pgoff, NULL);
97953 - else /* cases 3, 8 */
97954 +
97955 +#ifdef CONFIG_PAX_SEGMEXEC
97956 + if (!err && prev_m)
97957 + err = vma_adjust(prev_m, prev_m->vm_start,
97958 + addr_m, prev_m->vm_pgoff, NULL);
97959 +#endif
97960 +
97961 + } else { /* cases 3, 8 */
97962 err = vma_adjust(area, addr, next->vm_end,
97963 next->vm_pgoff - pglen, NULL);
97964 +
97965 +#ifdef CONFIG_PAX_SEGMEXEC
97966 + if (!err && area_m)
97967 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
97968 + next_m->vm_pgoff - pglen, NULL);
97969 +#endif
97970 +
97971 + }
97972 if (err)
97973 return NULL;
97974 khugepaged_enter_vma_merge(area, vm_flags);
97975 @@ -1184,8 +1270,10 @@ none:
97976 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
97977 struct file *file, long pages)
97978 {
97979 - const unsigned long stack_flags
97980 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
97981 +
97982 +#ifdef CONFIG_PAX_RANDMMAP
97983 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
97984 +#endif
97985
97986 mm->total_vm += pages;
97987
97988 @@ -1193,7 +1281,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
97989 mm->shared_vm += pages;
97990 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
97991 mm->exec_vm += pages;
97992 - } else if (flags & stack_flags)
97993 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
97994 mm->stack_vm += pages;
97995 }
97996 #endif /* CONFIG_PROC_FS */
97997 @@ -1223,6 +1311,7 @@ static inline int mlock_future_check(struct mm_struct *mm,
97998 locked += mm->locked_vm;
97999 lock_limit = rlimit(RLIMIT_MEMLOCK);
98000 lock_limit >>= PAGE_SHIFT;
98001 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
98002 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
98003 return -EAGAIN;
98004 }
98005 @@ -1249,7 +1338,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
98006 * (the exception is when the underlying filesystem is noexec
98007 * mounted, in which case we dont add PROT_EXEC.)
98008 */
98009 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
98010 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
98011 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
98012 prot |= PROT_EXEC;
98013
98014 @@ -1275,7 +1364,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
98015 /* Obtain the address to map to. we verify (or select) it and ensure
98016 * that it represents a valid section of the address space.
98017 */
98018 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
98019 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
98020 if (addr & ~PAGE_MASK)
98021 return addr;
98022
98023 @@ -1286,6 +1375,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
98024 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
98025 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
98026
98027 +#ifdef CONFIG_PAX_MPROTECT
98028 + if (mm->pax_flags & MF_PAX_MPROTECT) {
98029 +
98030 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
98031 + if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
98032 + mm->binfmt->handle_mmap)
98033 + mm->binfmt->handle_mmap(file);
98034 +#endif
98035 +
98036 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
98037 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
98038 + gr_log_rwxmmap(file);
98039 +
98040 +#ifdef CONFIG_PAX_EMUPLT
98041 + vm_flags &= ~VM_EXEC;
98042 +#else
98043 + return -EPERM;
98044 +#endif
98045 +
98046 + }
98047 +
98048 + if (!(vm_flags & VM_EXEC))
98049 + vm_flags &= ~VM_MAYEXEC;
98050 +#else
98051 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
98052 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
98053 +#endif
98054 + else
98055 + vm_flags &= ~VM_MAYWRITE;
98056 + }
98057 +#endif
98058 +
98059 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
98060 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
98061 + vm_flags &= ~VM_PAGEEXEC;
98062 +#endif
98063 +
98064 if (flags & MAP_LOCKED)
98065 if (!can_do_mlock())
98066 return -EPERM;
98067 @@ -1373,6 +1499,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
98068 vm_flags |= VM_NORESERVE;
98069 }
98070
98071 + if (!gr_acl_handle_mmap(file, prot))
98072 + return -EACCES;
98073 +
98074 addr = mmap_region(file, addr, len, vm_flags, pgoff);
98075 if (!IS_ERR_VALUE(addr) &&
98076 ((vm_flags & VM_LOCKED) ||
98077 @@ -1466,7 +1595,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
98078 vm_flags_t vm_flags = vma->vm_flags;
98079
98080 /* If it was private or non-writable, the write bit is already clear */
98081 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
98082 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
98083 return 0;
98084
98085 /* The backer wishes to know when pages are first written to? */
98086 @@ -1512,7 +1641,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
98087 struct rb_node **rb_link, *rb_parent;
98088 unsigned long charged = 0;
98089
98090 +#ifdef CONFIG_PAX_SEGMEXEC
98091 + struct vm_area_struct *vma_m = NULL;
98092 +#endif
98093 +
98094 + /*
98095 + * mm->mmap_sem is required to protect against another thread
98096 + * changing the mappings in case we sleep.
98097 + */
98098 + verify_mm_writelocked(mm);
98099 +
98100 /* Check against address space limit. */
98101 +
98102 +#ifdef CONFIG_PAX_RANDMMAP
98103 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
98104 +#endif
98105 +
98106 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
98107 unsigned long nr_pages;
98108
98109 @@ -1531,11 +1675,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
98110
98111 /* Clear old maps */
98112 error = -ENOMEM;
98113 -munmap_back:
98114 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
98115 if (do_munmap(mm, addr, len))
98116 return -ENOMEM;
98117 - goto munmap_back;
98118 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
98119 }
98120
98121 /*
98122 @@ -1566,6 +1709,16 @@ munmap_back:
98123 goto unacct_error;
98124 }
98125
98126 +#ifdef CONFIG_PAX_SEGMEXEC
98127 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
98128 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
98129 + if (!vma_m) {
98130 + error = -ENOMEM;
98131 + goto free_vma;
98132 + }
98133 + }
98134 +#endif
98135 +
98136 vma->vm_mm = mm;
98137 vma->vm_start = addr;
98138 vma->vm_end = addr + len;
98139 @@ -1596,6 +1749,13 @@ munmap_back:
98140 if (error)
98141 goto unmap_and_free_vma;
98142
98143 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
98144 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
98145 + vma->vm_flags |= VM_PAGEEXEC;
98146 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
98147 + }
98148 +#endif
98149 +
98150 /* Can addr have changed??
98151 *
98152 * Answer: Yes, several device drivers can do it in their
98153 @@ -1629,6 +1789,12 @@ munmap_back:
98154 }
98155
98156 vma_link(mm, vma, prev, rb_link, rb_parent);
98157 +
98158 +#ifdef CONFIG_PAX_SEGMEXEC
98159 + if (vma_m)
98160 + BUG_ON(pax_mirror_vma(vma_m, vma));
98161 +#endif
98162 +
98163 /* Once vma denies write, undo our temporary denial count */
98164 if (file) {
98165 if (vm_flags & VM_SHARED)
98166 @@ -1641,6 +1807,7 @@ out:
98167 perf_event_mmap(vma);
98168
98169 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
98170 + track_exec_limit(mm, addr, addr + len, vm_flags);
98171 if (vm_flags & VM_LOCKED) {
98172 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
98173 vma == get_gate_vma(current->mm)))
98174 @@ -1676,6 +1843,12 @@ allow_write_and_free_vma:
98175 if (vm_flags & VM_DENYWRITE)
98176 allow_write_access(file);
98177 free_vma:
98178 +
98179 +#ifdef CONFIG_PAX_SEGMEXEC
98180 + if (vma_m)
98181 + kmem_cache_free(vm_area_cachep, vma_m);
98182 +#endif
98183 +
98184 kmem_cache_free(vm_area_cachep, vma);
98185 unacct_error:
98186 if (charged)
98187 @@ -1683,7 +1856,63 @@ unacct_error:
98188 return error;
98189 }
98190
98191 -unsigned long unmapped_area(struct vm_unmapped_area_info *info)
98192 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
98193 +unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
98194 +{
98195 + if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
98196 + return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
98197 +
98198 + return 0;
98199 +}
98200 +#endif
98201 +
98202 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
98203 +{
98204 + if (!vma) {
98205 +#ifdef CONFIG_STACK_GROWSUP
98206 + if (addr > sysctl_heap_stack_gap)
98207 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
98208 + else
98209 + vma = find_vma(current->mm, 0);
98210 + if (vma && (vma->vm_flags & VM_GROWSUP))
98211 + return false;
98212 +#endif
98213 + return true;
98214 + }
98215 +
98216 + if (addr + len > vma->vm_start)
98217 + return false;
98218 +
98219 + if (vma->vm_flags & VM_GROWSDOWN)
98220 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
98221 +#ifdef CONFIG_STACK_GROWSUP
98222 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
98223 + return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
98224 +#endif
98225 + else if (offset)
98226 + return offset <= vma->vm_start - addr - len;
98227 +
98228 + return true;
98229 +}
98230 +
98231 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
98232 +{
98233 + if (vma->vm_start < len)
98234 + return -ENOMEM;
98235 +
98236 + if (!(vma->vm_flags & VM_GROWSDOWN)) {
98237 + if (offset <= vma->vm_start - len)
98238 + return vma->vm_start - len - offset;
98239 + else
98240 + return -ENOMEM;
98241 + }
98242 +
98243 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
98244 + return vma->vm_start - len - sysctl_heap_stack_gap;
98245 + return -ENOMEM;
98246 +}
98247 +
98248 +unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
98249 {
98250 /*
98251 * We implement the search by looking for an rbtree node that
98252 @@ -1731,11 +1960,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
98253 }
98254 }
98255
98256 - gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
98257 + gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
98258 check_current:
98259 /* Check if current node has a suitable gap */
98260 if (gap_start > high_limit)
98261 return -ENOMEM;
98262 +
98263 + if (gap_end - gap_start > info->threadstack_offset)
98264 + gap_start += info->threadstack_offset;
98265 + else
98266 + gap_start = gap_end;
98267 +
98268 + if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
98269 + if (gap_end - gap_start > sysctl_heap_stack_gap)
98270 + gap_start += sysctl_heap_stack_gap;
98271 + else
98272 + gap_start = gap_end;
98273 + }
98274 + if (vma->vm_flags & VM_GROWSDOWN) {
98275 + if (gap_end - gap_start > sysctl_heap_stack_gap)
98276 + gap_end -= sysctl_heap_stack_gap;
98277 + else
98278 + gap_end = gap_start;
98279 + }
98280 if (gap_end >= low_limit && gap_end - gap_start >= length)
98281 goto found;
98282
98283 @@ -1785,7 +2032,7 @@ found:
98284 return gap_start;
98285 }
98286
98287 -unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
98288 +unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
98289 {
98290 struct mm_struct *mm = current->mm;
98291 struct vm_area_struct *vma;
98292 @@ -1839,6 +2086,24 @@ check_current:
98293 gap_end = vma->vm_start;
98294 if (gap_end < low_limit)
98295 return -ENOMEM;
98296 +
98297 + if (gap_end - gap_start > info->threadstack_offset)
98298 + gap_end -= info->threadstack_offset;
98299 + else
98300 + gap_end = gap_start;
98301 +
98302 + if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
98303 + if (gap_end - gap_start > sysctl_heap_stack_gap)
98304 + gap_start += sysctl_heap_stack_gap;
98305 + else
98306 + gap_start = gap_end;
98307 + }
98308 + if (vma->vm_flags & VM_GROWSDOWN) {
98309 + if (gap_end - gap_start > sysctl_heap_stack_gap)
98310 + gap_end -= sysctl_heap_stack_gap;
98311 + else
98312 + gap_end = gap_start;
98313 + }
98314 if (gap_start <= high_limit && gap_end - gap_start >= length)
98315 goto found;
98316
98317 @@ -1902,6 +2167,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
98318 struct mm_struct *mm = current->mm;
98319 struct vm_area_struct *vma;
98320 struct vm_unmapped_area_info info;
98321 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
98322
98323 if (len > TASK_SIZE - mmap_min_addr)
98324 return -ENOMEM;
98325 @@ -1909,11 +2175,15 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
98326 if (flags & MAP_FIXED)
98327 return addr;
98328
98329 +#ifdef CONFIG_PAX_RANDMMAP
98330 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
98331 +#endif
98332 +
98333 if (addr) {
98334 addr = PAGE_ALIGN(addr);
98335 vma = find_vma(mm, addr);
98336 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
98337 - (!vma || addr + len <= vma->vm_start))
98338 + check_heap_stack_gap(vma, addr, len, offset))
98339 return addr;
98340 }
98341
98342 @@ -1922,6 +2192,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
98343 info.low_limit = mm->mmap_base;
98344 info.high_limit = TASK_SIZE;
98345 info.align_mask = 0;
98346 + info.threadstack_offset = offset;
98347 return vm_unmapped_area(&info);
98348 }
98349 #endif
98350 @@ -1940,6 +2211,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
98351 struct mm_struct *mm = current->mm;
98352 unsigned long addr = addr0;
98353 struct vm_unmapped_area_info info;
98354 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
98355
98356 /* requested length too big for entire address space */
98357 if (len > TASK_SIZE - mmap_min_addr)
98358 @@ -1948,12 +2220,16 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
98359 if (flags & MAP_FIXED)
98360 return addr;
98361
98362 +#ifdef CONFIG_PAX_RANDMMAP
98363 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
98364 +#endif
98365 +
98366 /* requesting a specific address */
98367 if (addr) {
98368 addr = PAGE_ALIGN(addr);
98369 vma = find_vma(mm, addr);
98370 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
98371 - (!vma || addr + len <= vma->vm_start))
98372 + check_heap_stack_gap(vma, addr, len, offset))
98373 return addr;
98374 }
98375
98376 @@ -1962,6 +2238,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
98377 info.low_limit = max(PAGE_SIZE, mmap_min_addr);
98378 info.high_limit = mm->mmap_base;
98379 info.align_mask = 0;
98380 + info.threadstack_offset = offset;
98381 addr = vm_unmapped_area(&info);
98382
98383 /*
98384 @@ -1974,6 +2251,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
98385 VM_BUG_ON(addr != -ENOMEM);
98386 info.flags = 0;
98387 info.low_limit = TASK_UNMAPPED_BASE;
98388 +
98389 +#ifdef CONFIG_PAX_RANDMMAP
98390 + if (mm->pax_flags & MF_PAX_RANDMMAP)
98391 + info.low_limit += mm->delta_mmap;
98392 +#endif
98393 +
98394 info.high_limit = TASK_SIZE;
98395 addr = vm_unmapped_area(&info);
98396 }
98397 @@ -2074,6 +2357,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
98398 return vma;
98399 }
98400
98401 +#ifdef CONFIG_PAX_SEGMEXEC
98402 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
98403 +{
98404 + struct vm_area_struct *vma_m;
98405 +
98406 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
98407 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
98408 + BUG_ON(vma->vm_mirror);
98409 + return NULL;
98410 + }
98411 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
98412 + vma_m = vma->vm_mirror;
98413 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
98414 + BUG_ON(vma->vm_file != vma_m->vm_file);
98415 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
98416 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
98417 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
98418 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
98419 + return vma_m;
98420 +}
98421 +#endif
98422 +
98423 /*
98424 * Verify that the stack growth is acceptable and
98425 * update accounting. This is shared with both the
98426 @@ -2090,6 +2395,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
98427 return -ENOMEM;
98428
98429 /* Stack limit test */
98430 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
98431 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
98432 return -ENOMEM;
98433
98434 @@ -2100,6 +2406,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
98435 locked = mm->locked_vm + grow;
98436 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
98437 limit >>= PAGE_SHIFT;
98438 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
98439 if (locked > limit && !capable(CAP_IPC_LOCK))
98440 return -ENOMEM;
98441 }
98442 @@ -2129,37 +2436,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
98443 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
98444 * vma is the last one with address > vma->vm_end. Have to extend vma.
98445 */
98446 +#ifndef CONFIG_IA64
98447 +static
98448 +#endif
98449 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
98450 {
98451 int error;
98452 + bool locknext;
98453
98454 if (!(vma->vm_flags & VM_GROWSUP))
98455 return -EFAULT;
98456
98457 + /* Also guard against wrapping around to address 0. */
98458 + if (address < PAGE_ALIGN(address+1))
98459 + address = PAGE_ALIGN(address+1);
98460 + else
98461 + return -ENOMEM;
98462 +
98463 /*
98464 * We must make sure the anon_vma is allocated
98465 * so that the anon_vma locking is not a noop.
98466 */
98467 if (unlikely(anon_vma_prepare(vma)))
98468 return -ENOMEM;
98469 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
98470 + if (locknext && anon_vma_prepare(vma->vm_next))
98471 + return -ENOMEM;
98472 vma_lock_anon_vma(vma);
98473 + if (locknext)
98474 + vma_lock_anon_vma(vma->vm_next);
98475
98476 /*
98477 * vma->vm_start/vm_end cannot change under us because the caller
98478 * is required to hold the mmap_sem in read mode. We need the
98479 - * anon_vma lock to serialize against concurrent expand_stacks.
98480 - * Also guard against wrapping around to address 0.
98481 + * anon_vma locks to serialize against concurrent expand_stacks
98482 + * and expand_upwards.
98483 */
98484 - if (address < PAGE_ALIGN(address+4))
98485 - address = PAGE_ALIGN(address+4);
98486 - else {
98487 - vma_unlock_anon_vma(vma);
98488 - return -ENOMEM;
98489 - }
98490 error = 0;
98491
98492 /* Somebody else might have raced and expanded it already */
98493 - if (address > vma->vm_end) {
98494 + 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)
98495 + error = -ENOMEM;
98496 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
98497 unsigned long size, grow;
98498
98499 size = address - vma->vm_start;
98500 @@ -2194,6 +2512,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
98501 }
98502 }
98503 }
98504 + if (locknext)
98505 + vma_unlock_anon_vma(vma->vm_next);
98506 vma_unlock_anon_vma(vma);
98507 khugepaged_enter_vma_merge(vma, vma->vm_flags);
98508 validate_mm(vma->vm_mm);
98509 @@ -2208,6 +2528,8 @@ int expand_downwards(struct vm_area_struct *vma,
98510 unsigned long address)
98511 {
98512 int error;
98513 + bool lockprev = false;
98514 + struct vm_area_struct *prev;
98515
98516 /*
98517 * We must make sure the anon_vma is allocated
98518 @@ -2221,6 +2543,15 @@ int expand_downwards(struct vm_area_struct *vma,
98519 if (error)
98520 return error;
98521
98522 + prev = vma->vm_prev;
98523 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
98524 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
98525 +#endif
98526 + if (lockprev && anon_vma_prepare(prev))
98527 + return -ENOMEM;
98528 + if (lockprev)
98529 + vma_lock_anon_vma(prev);
98530 +
98531 vma_lock_anon_vma(vma);
98532
98533 /*
98534 @@ -2230,9 +2561,17 @@ int expand_downwards(struct vm_area_struct *vma,
98535 */
98536
98537 /* Somebody else might have raced and expanded it already */
98538 - if (address < vma->vm_start) {
98539 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
98540 + error = -ENOMEM;
98541 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
98542 unsigned long size, grow;
98543
98544 +#ifdef CONFIG_PAX_SEGMEXEC
98545 + struct vm_area_struct *vma_m;
98546 +
98547 + vma_m = pax_find_mirror_vma(vma);
98548 +#endif
98549 +
98550 size = vma->vm_end - address;
98551 grow = (vma->vm_start - address) >> PAGE_SHIFT;
98552
98553 @@ -2257,13 +2596,27 @@ int expand_downwards(struct vm_area_struct *vma,
98554 vma->vm_pgoff -= grow;
98555 anon_vma_interval_tree_post_update_vma(vma);
98556 vma_gap_update(vma);
98557 +
98558 +#ifdef CONFIG_PAX_SEGMEXEC
98559 + if (vma_m) {
98560 + anon_vma_interval_tree_pre_update_vma(vma_m);
98561 + vma_m->vm_start -= grow << PAGE_SHIFT;
98562 + vma_m->vm_pgoff -= grow;
98563 + anon_vma_interval_tree_post_update_vma(vma_m);
98564 + vma_gap_update(vma_m);
98565 + }
98566 +#endif
98567 +
98568 spin_unlock(&vma->vm_mm->page_table_lock);
98569
98570 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
98571 perf_event_mmap(vma);
98572 }
98573 }
98574 }
98575 vma_unlock_anon_vma(vma);
98576 + if (lockprev)
98577 + vma_unlock_anon_vma(prev);
98578 khugepaged_enter_vma_merge(vma, vma->vm_flags);
98579 validate_mm(vma->vm_mm);
98580 return error;
98581 @@ -2361,6 +2714,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
98582 do {
98583 long nrpages = vma_pages(vma);
98584
98585 +#ifdef CONFIG_PAX_SEGMEXEC
98586 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
98587 + vma = remove_vma(vma);
98588 + continue;
98589 + }
98590 +#endif
98591 +
98592 if (vma->vm_flags & VM_ACCOUNT)
98593 nr_accounted += nrpages;
98594 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
98595 @@ -2405,6 +2765,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
98596 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
98597 vma->vm_prev = NULL;
98598 do {
98599 +
98600 +#ifdef CONFIG_PAX_SEGMEXEC
98601 + if (vma->vm_mirror) {
98602 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
98603 + vma->vm_mirror->vm_mirror = NULL;
98604 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
98605 + vma->vm_mirror = NULL;
98606 + }
98607 +#endif
98608 +
98609 vma_rb_erase(vma, &mm->mm_rb);
98610 mm->map_count--;
98611 tail_vma = vma;
98612 @@ -2432,14 +2802,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
98613 struct vm_area_struct *new;
98614 int err = -ENOMEM;
98615
98616 +#ifdef CONFIG_PAX_SEGMEXEC
98617 + struct vm_area_struct *vma_m, *new_m = NULL;
98618 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
98619 +#endif
98620 +
98621 if (is_vm_hugetlb_page(vma) && (addr &
98622 ~(huge_page_mask(hstate_vma(vma)))))
98623 return -EINVAL;
98624
98625 +#ifdef CONFIG_PAX_SEGMEXEC
98626 + vma_m = pax_find_mirror_vma(vma);
98627 +#endif
98628 +
98629 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
98630 if (!new)
98631 goto out_err;
98632
98633 +#ifdef CONFIG_PAX_SEGMEXEC
98634 + if (vma_m) {
98635 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
98636 + if (!new_m) {
98637 + kmem_cache_free(vm_area_cachep, new);
98638 + goto out_err;
98639 + }
98640 + }
98641 +#endif
98642 +
98643 /* most fields are the same, copy all, and then fixup */
98644 *new = *vma;
98645
98646 @@ -2452,6 +2841,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
98647 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
98648 }
98649
98650 +#ifdef CONFIG_PAX_SEGMEXEC
98651 + if (vma_m) {
98652 + *new_m = *vma_m;
98653 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
98654 + new_m->vm_mirror = new;
98655 + new->vm_mirror = new_m;
98656 +
98657 + if (new_below)
98658 + new_m->vm_end = addr_m;
98659 + else {
98660 + new_m->vm_start = addr_m;
98661 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
98662 + }
98663 + }
98664 +#endif
98665 +
98666 err = vma_dup_policy(vma, new);
98667 if (err)
98668 goto out_free_vma;
98669 @@ -2472,6 +2877,38 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
98670 else
98671 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
98672
98673 +#ifdef CONFIG_PAX_SEGMEXEC
98674 + if (!err && vma_m) {
98675 + struct mempolicy *pol = vma_policy(new);
98676 +
98677 + if (anon_vma_clone(new_m, vma_m))
98678 + goto out_free_mpol;
98679 +
98680 + mpol_get(pol);
98681 + set_vma_policy(new_m, pol);
98682 +
98683 + if (new_m->vm_file)
98684 + get_file(new_m->vm_file);
98685 +
98686 + if (new_m->vm_ops && new_m->vm_ops->open)
98687 + new_m->vm_ops->open(new_m);
98688 +
98689 + if (new_below)
98690 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
98691 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
98692 + else
98693 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
98694 +
98695 + if (err) {
98696 + if (new_m->vm_ops && new_m->vm_ops->close)
98697 + new_m->vm_ops->close(new_m);
98698 + if (new_m->vm_file)
98699 + fput(new_m->vm_file);
98700 + mpol_put(pol);
98701 + }
98702 + }
98703 +#endif
98704 +
98705 /* Success. */
98706 if (!err)
98707 return 0;
98708 @@ -2481,10 +2918,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
98709 new->vm_ops->close(new);
98710 if (new->vm_file)
98711 fput(new->vm_file);
98712 - unlink_anon_vmas(new);
98713 out_free_mpol:
98714 mpol_put(vma_policy(new));
98715 out_free_vma:
98716 +
98717 +#ifdef CONFIG_PAX_SEGMEXEC
98718 + if (new_m) {
98719 + unlink_anon_vmas(new_m);
98720 + kmem_cache_free(vm_area_cachep, new_m);
98721 + }
98722 +#endif
98723 +
98724 + unlink_anon_vmas(new);
98725 kmem_cache_free(vm_area_cachep, new);
98726 out_err:
98727 return err;
98728 @@ -2497,6 +2942,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
98729 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
98730 unsigned long addr, int new_below)
98731 {
98732 +
98733 +#ifdef CONFIG_PAX_SEGMEXEC
98734 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
98735 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
98736 + if (mm->map_count >= sysctl_max_map_count-1)
98737 + return -ENOMEM;
98738 + } else
98739 +#endif
98740 +
98741 if (mm->map_count >= sysctl_max_map_count)
98742 return -ENOMEM;
98743
98744 @@ -2508,11 +2962,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
98745 * work. This now handles partial unmappings.
98746 * Jeremy Fitzhardinge <jeremy@goop.org>
98747 */
98748 +#ifdef CONFIG_PAX_SEGMEXEC
98749 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
98750 {
98751 + int ret = __do_munmap(mm, start, len);
98752 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
98753 + return ret;
98754 +
98755 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
98756 +}
98757 +
98758 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
98759 +#else
98760 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
98761 +#endif
98762 +{
98763 unsigned long end;
98764 struct vm_area_struct *vma, *prev, *last;
98765
98766 + /*
98767 + * mm->mmap_sem is required to protect against another thread
98768 + * changing the mappings in case we sleep.
98769 + */
98770 + verify_mm_writelocked(mm);
98771 +
98772 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
98773 return -EINVAL;
98774
98775 @@ -2587,6 +3060,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
98776 /* Fix up all other VM information */
98777 remove_vma_list(mm, vma);
98778
98779 + track_exec_limit(mm, start, end, 0UL);
98780 +
98781 return 0;
98782 }
98783
98784 @@ -2595,6 +3070,13 @@ int vm_munmap(unsigned long start, size_t len)
98785 int ret;
98786 struct mm_struct *mm = current->mm;
98787
98788 +
98789 +#ifdef CONFIG_PAX_SEGMEXEC
98790 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
98791 + (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
98792 + return -EINVAL;
98793 +#endif
98794 +
98795 down_write(&mm->mmap_sem);
98796 ret = do_munmap(mm, start, len);
98797 up_write(&mm->mmap_sem);
98798 @@ -2608,16 +3090,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
98799 return vm_munmap(addr, len);
98800 }
98801
98802 -static inline void verify_mm_writelocked(struct mm_struct *mm)
98803 -{
98804 -#ifdef CONFIG_DEBUG_VM
98805 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
98806 - WARN_ON(1);
98807 - up_read(&mm->mmap_sem);
98808 - }
98809 -#endif
98810 -}
98811 -
98812 /*
98813 * this is really a simplified "do_mmap". it only handles
98814 * anonymous maps. eventually we may be able to do some
98815 @@ -2631,6 +3103,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
98816 struct rb_node ** rb_link, * rb_parent;
98817 pgoff_t pgoff = addr >> PAGE_SHIFT;
98818 int error;
98819 + unsigned long charged;
98820
98821 len = PAGE_ALIGN(len);
98822 if (!len)
98823 @@ -2638,10 +3111,24 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
98824
98825 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
98826
98827 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
98828 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
98829 + flags &= ~VM_EXEC;
98830 +
98831 +#ifdef CONFIG_PAX_MPROTECT
98832 + if (mm->pax_flags & MF_PAX_MPROTECT)
98833 + flags &= ~VM_MAYEXEC;
98834 +#endif
98835 +
98836 + }
98837 +#endif
98838 +
98839 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
98840 if (error & ~PAGE_MASK)
98841 return error;
98842
98843 + charged = len >> PAGE_SHIFT;
98844 +
98845 error = mlock_future_check(mm, mm->def_flags, len);
98846 if (error)
98847 return error;
98848 @@ -2655,21 +3142,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
98849 /*
98850 * Clear old maps. this also does some error checking for us
98851 */
98852 - munmap_back:
98853 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
98854 if (do_munmap(mm, addr, len))
98855 return -ENOMEM;
98856 - goto munmap_back;
98857 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
98858 }
98859
98860 /* Check against address space limits *after* clearing old maps... */
98861 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
98862 + if (!may_expand_vm(mm, charged))
98863 return -ENOMEM;
98864
98865 if (mm->map_count > sysctl_max_map_count)
98866 return -ENOMEM;
98867
98868 - if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
98869 + if (security_vm_enough_memory_mm(mm, charged))
98870 return -ENOMEM;
98871
98872 /* Can we just expand an old private anonymous mapping? */
98873 @@ -2683,7 +3169,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
98874 */
98875 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
98876 if (!vma) {
98877 - vm_unacct_memory(len >> PAGE_SHIFT);
98878 + vm_unacct_memory(charged);
98879 return -ENOMEM;
98880 }
98881
98882 @@ -2697,10 +3183,11 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
98883 vma_link(mm, vma, prev, rb_link, rb_parent);
98884 out:
98885 perf_event_mmap(vma);
98886 - mm->total_vm += len >> PAGE_SHIFT;
98887 + mm->total_vm += charged;
98888 if (flags & VM_LOCKED)
98889 - mm->locked_vm += (len >> PAGE_SHIFT);
98890 + mm->locked_vm += charged;
98891 vma->vm_flags |= VM_SOFTDIRTY;
98892 + track_exec_limit(mm, addr, addr + len, flags);
98893 return addr;
98894 }
98895
98896 @@ -2762,6 +3249,7 @@ void exit_mmap(struct mm_struct *mm)
98897 while (vma) {
98898 if (vma->vm_flags & VM_ACCOUNT)
98899 nr_accounted += vma_pages(vma);
98900 + vma->vm_mirror = NULL;
98901 vma = remove_vma(vma);
98902 }
98903 vm_unacct_memory(nr_accounted);
98904 @@ -2779,6 +3267,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
98905 struct vm_area_struct *prev;
98906 struct rb_node **rb_link, *rb_parent;
98907
98908 +#ifdef CONFIG_PAX_SEGMEXEC
98909 + struct vm_area_struct *vma_m = NULL;
98910 +#endif
98911 +
98912 + if (security_mmap_addr(vma->vm_start))
98913 + return -EPERM;
98914 +
98915 /*
98916 * The vm_pgoff of a purely anonymous vma should be irrelevant
98917 * until its first write fault, when page's anon_vma and index
98918 @@ -2802,7 +3297,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
98919 security_vm_enough_memory_mm(mm, vma_pages(vma)))
98920 return -ENOMEM;
98921
98922 +#ifdef CONFIG_PAX_SEGMEXEC
98923 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
98924 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
98925 + if (!vma_m)
98926 + return -ENOMEM;
98927 + }
98928 +#endif
98929 +
98930 vma_link(mm, vma, prev, rb_link, rb_parent);
98931 +
98932 +#ifdef CONFIG_PAX_SEGMEXEC
98933 + if (vma_m)
98934 + BUG_ON(pax_mirror_vma(vma_m, vma));
98935 +#endif
98936 +
98937 return 0;
98938 }
98939
98940 @@ -2821,6 +3330,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
98941 struct rb_node **rb_link, *rb_parent;
98942 bool faulted_in_anon_vma = true;
98943
98944 + BUG_ON(vma->vm_mirror);
98945 +
98946 /*
98947 * If anonymous vma has not yet been faulted, update new pgoff
98948 * to match new location, to increase its chance of merging.
98949 @@ -2885,6 +3396,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
98950 return NULL;
98951 }
98952
98953 +#ifdef CONFIG_PAX_SEGMEXEC
98954 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
98955 +{
98956 + struct vm_area_struct *prev_m;
98957 + struct rb_node **rb_link_m, *rb_parent_m;
98958 + struct mempolicy *pol_m;
98959 +
98960 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
98961 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
98962 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
98963 + *vma_m = *vma;
98964 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
98965 + if (anon_vma_clone(vma_m, vma))
98966 + return -ENOMEM;
98967 + pol_m = vma_policy(vma_m);
98968 + mpol_get(pol_m);
98969 + set_vma_policy(vma_m, pol_m);
98970 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
98971 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
98972 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
98973 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
98974 + if (vma_m->vm_file)
98975 + get_file(vma_m->vm_file);
98976 + if (vma_m->vm_ops && vma_m->vm_ops->open)
98977 + vma_m->vm_ops->open(vma_m);
98978 + BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
98979 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
98980 + vma_m->vm_mirror = vma;
98981 + vma->vm_mirror = vma_m;
98982 + return 0;
98983 +}
98984 +#endif
98985 +
98986 /*
98987 * Return true if the calling process may expand its vm space by the passed
98988 * number of pages
98989 @@ -2896,6 +3440,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
98990
98991 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
98992
98993 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
98994 if (cur + npages > lim)
98995 return 0;
98996 return 1;
98997 @@ -2978,6 +3523,22 @@ static struct vm_area_struct *__install_special_mapping(
98998 vma->vm_start = addr;
98999 vma->vm_end = addr + len;
99000
99001 +#ifdef CONFIG_PAX_MPROTECT
99002 + if (mm->pax_flags & MF_PAX_MPROTECT) {
99003 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
99004 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
99005 + return ERR_PTR(-EPERM);
99006 + if (!(vm_flags & VM_EXEC))
99007 + vm_flags &= ~VM_MAYEXEC;
99008 +#else
99009 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
99010 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
99011 +#endif
99012 + else
99013 + vm_flags &= ~VM_MAYWRITE;
99014 + }
99015 +#endif
99016 +
99017 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND | VM_SOFTDIRTY;
99018 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
99019
99020 diff --git a/mm/mprotect.c b/mm/mprotect.c
99021 index c43d557..0b7ccd2 100644
99022 --- a/mm/mprotect.c
99023 +++ b/mm/mprotect.c
99024 @@ -24,10 +24,18 @@
99025 #include <linux/migrate.h>
99026 #include <linux/perf_event.h>
99027 #include <linux/ksm.h>
99028 +#include <linux/sched/sysctl.h>
99029 +
99030 +#ifdef CONFIG_PAX_MPROTECT
99031 +#include <linux/elf.h>
99032 +#include <linux/binfmts.h>
99033 +#endif
99034 +
99035 #include <asm/uaccess.h>
99036 #include <asm/pgtable.h>
99037 #include <asm/cacheflush.h>
99038 #include <asm/tlbflush.h>
99039 +#include <asm/mmu_context.h>
99040
99041 #ifndef pgprot_modify
99042 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
99043 @@ -256,6 +264,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
99044 return pages;
99045 }
99046
99047 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
99048 +/* called while holding the mmap semaphor for writing except stack expansion */
99049 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
99050 +{
99051 + unsigned long oldlimit, newlimit = 0UL;
99052 +
99053 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
99054 + return;
99055 +
99056 + spin_lock(&mm->page_table_lock);
99057 + oldlimit = mm->context.user_cs_limit;
99058 + if ((prot & VM_EXEC) && oldlimit < end)
99059 + /* USER_CS limit moved up */
99060 + newlimit = end;
99061 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
99062 + /* USER_CS limit moved down */
99063 + newlimit = start;
99064 +
99065 + if (newlimit) {
99066 + mm->context.user_cs_limit = newlimit;
99067 +
99068 +#ifdef CONFIG_SMP
99069 + wmb();
99070 + cpus_clear(mm->context.cpu_user_cs_mask);
99071 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
99072 +#endif
99073 +
99074 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
99075 + }
99076 + spin_unlock(&mm->page_table_lock);
99077 + if (newlimit == end) {
99078 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
99079 +
99080 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
99081 + if (is_vm_hugetlb_page(vma))
99082 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
99083 + else
99084 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
99085 + }
99086 +}
99087 +#endif
99088 +
99089 int
99090 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
99091 unsigned long start, unsigned long end, unsigned long newflags)
99092 @@ -268,11 +318,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
99093 int error;
99094 int dirty_accountable = 0;
99095
99096 +#ifdef CONFIG_PAX_SEGMEXEC
99097 + struct vm_area_struct *vma_m = NULL;
99098 + unsigned long start_m, end_m;
99099 +
99100 + start_m = start + SEGMEXEC_TASK_SIZE;
99101 + end_m = end + SEGMEXEC_TASK_SIZE;
99102 +#endif
99103 +
99104 if (newflags == oldflags) {
99105 *pprev = vma;
99106 return 0;
99107 }
99108
99109 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
99110 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
99111 +
99112 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
99113 + return -ENOMEM;
99114 +
99115 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
99116 + return -ENOMEM;
99117 + }
99118 +
99119 /*
99120 * If we make a private mapping writable we increase our commit;
99121 * but (without finer accounting) cannot reduce our commit if we
99122 @@ -289,6 +357,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
99123 }
99124 }
99125
99126 +#ifdef CONFIG_PAX_SEGMEXEC
99127 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
99128 + if (start != vma->vm_start) {
99129 + error = split_vma(mm, vma, start, 1);
99130 + if (error)
99131 + goto fail;
99132 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
99133 + *pprev = (*pprev)->vm_next;
99134 + }
99135 +
99136 + if (end != vma->vm_end) {
99137 + error = split_vma(mm, vma, end, 0);
99138 + if (error)
99139 + goto fail;
99140 + }
99141 +
99142 + if (pax_find_mirror_vma(vma)) {
99143 + error = __do_munmap(mm, start_m, end_m - start_m);
99144 + if (error)
99145 + goto fail;
99146 + } else {
99147 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
99148 + if (!vma_m) {
99149 + error = -ENOMEM;
99150 + goto fail;
99151 + }
99152 + vma->vm_flags = newflags;
99153 + error = pax_mirror_vma(vma_m, vma);
99154 + if (error) {
99155 + vma->vm_flags = oldflags;
99156 + goto fail;
99157 + }
99158 + }
99159 + }
99160 +#endif
99161 +
99162 /*
99163 * First try to merge with previous and/or next vma.
99164 */
99165 @@ -319,9 +423,21 @@ success:
99166 * vm_flags and vm_page_prot are protected by the mmap_sem
99167 * held in write mode.
99168 */
99169 +
99170 +#ifdef CONFIG_PAX_SEGMEXEC
99171 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
99172 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
99173 +#endif
99174 +
99175 vma->vm_flags = newflags;
99176 +
99177 +#ifdef CONFIG_PAX_MPROTECT
99178 + if (mm->binfmt && mm->binfmt->handle_mprotect)
99179 + mm->binfmt->handle_mprotect(vma, newflags);
99180 +#endif
99181 +
99182 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
99183 - vm_get_page_prot(newflags));
99184 + vm_get_page_prot(vma->vm_flags));
99185
99186 if (vma_wants_writenotify(vma)) {
99187 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
99188 @@ -360,6 +476,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
99189 end = start + len;
99190 if (end <= start)
99191 return -ENOMEM;
99192 +
99193 +#ifdef CONFIG_PAX_SEGMEXEC
99194 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
99195 + if (end > SEGMEXEC_TASK_SIZE)
99196 + return -EINVAL;
99197 + } else
99198 +#endif
99199 +
99200 + if (end > TASK_SIZE)
99201 + return -EINVAL;
99202 +
99203 if (!arch_validate_prot(prot))
99204 return -EINVAL;
99205
99206 @@ -367,7 +494,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
99207 /*
99208 * Does the application expect PROT_READ to imply PROT_EXEC:
99209 */
99210 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
99211 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
99212 prot |= PROT_EXEC;
99213
99214 vm_flags = calc_vm_prot_bits(prot);
99215 @@ -399,6 +526,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
99216 if (start > vma->vm_start)
99217 prev = vma;
99218
99219 +#ifdef CONFIG_PAX_MPROTECT
99220 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
99221 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
99222 +#endif
99223 +
99224 for (nstart = start ; ; ) {
99225 unsigned long newflags;
99226
99227 @@ -409,6 +541,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
99228
99229 /* newflags >> 4 shift VM_MAY% in place of VM_% */
99230 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
99231 + if (prot & (PROT_WRITE | PROT_EXEC))
99232 + gr_log_rwxmprotect(vma);
99233 +
99234 + error = -EACCES;
99235 + goto out;
99236 + }
99237 +
99238 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
99239 error = -EACCES;
99240 goto out;
99241 }
99242 @@ -423,6 +563,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
99243 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
99244 if (error)
99245 goto out;
99246 +
99247 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
99248 +
99249 nstart = tmp;
99250
99251 if (nstart < prev->vm_end)
99252 diff --git a/mm/mremap.c b/mm/mremap.c
99253 index 05f1180..c3cde48 100644
99254 --- a/mm/mremap.c
99255 +++ b/mm/mremap.c
99256 @@ -144,6 +144,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
99257 continue;
99258 pte = ptep_get_and_clear(mm, old_addr, old_pte);
99259 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
99260 +
99261 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
99262 + if (!(__supported_pte_mask & _PAGE_NX) && pte_present(pte) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
99263 + pte = pte_exprotect(pte);
99264 +#endif
99265 +
99266 pte = move_soft_dirty_pte(pte);
99267 set_pte_at(mm, new_addr, new_pte, pte);
99268 }
99269 @@ -344,6 +350,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
99270 if (is_vm_hugetlb_page(vma))
99271 goto Einval;
99272
99273 +#ifdef CONFIG_PAX_SEGMEXEC
99274 + if (pax_find_mirror_vma(vma))
99275 + goto Einval;
99276 +#endif
99277 +
99278 /* We can't remap across vm area boundaries */
99279 if (old_len > vma->vm_end - addr)
99280 goto Efault;
99281 @@ -399,20 +410,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
99282 unsigned long ret = -EINVAL;
99283 unsigned long charged = 0;
99284 unsigned long map_flags;
99285 + unsigned long pax_task_size = TASK_SIZE;
99286
99287 if (new_addr & ~PAGE_MASK)
99288 goto out;
99289
99290 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
99291 +#ifdef CONFIG_PAX_SEGMEXEC
99292 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
99293 + pax_task_size = SEGMEXEC_TASK_SIZE;
99294 +#endif
99295 +
99296 + pax_task_size -= PAGE_SIZE;
99297 +
99298 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
99299 goto out;
99300
99301 /* Check if the location we're moving into overlaps the
99302 * old location at all, and fail if it does.
99303 */
99304 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
99305 - goto out;
99306 -
99307 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
99308 + if (addr + old_len > new_addr && new_addr + new_len > addr)
99309 goto out;
99310
99311 ret = do_munmap(mm, new_addr, new_len);
99312 @@ -481,6 +497,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
99313 unsigned long ret = -EINVAL;
99314 unsigned long charged = 0;
99315 bool locked = false;
99316 + unsigned long pax_task_size = TASK_SIZE;
99317
99318 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
99319 return ret;
99320 @@ -502,6 +519,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
99321 if (!new_len)
99322 return ret;
99323
99324 +#ifdef CONFIG_PAX_SEGMEXEC
99325 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
99326 + pax_task_size = SEGMEXEC_TASK_SIZE;
99327 +#endif
99328 +
99329 + pax_task_size -= PAGE_SIZE;
99330 +
99331 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
99332 + old_len > pax_task_size || addr > pax_task_size-old_len)
99333 + return ret;
99334 +
99335 down_write(&current->mm->mmap_sem);
99336
99337 if (flags & MREMAP_FIXED) {
99338 @@ -552,6 +580,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
99339 new_addr = addr;
99340 }
99341 ret = addr;
99342 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
99343 goto out;
99344 }
99345 }
99346 @@ -575,7 +604,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
99347 goto out;
99348 }
99349
99350 + map_flags = vma->vm_flags;
99351 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
99352 + if (!(ret & ~PAGE_MASK)) {
99353 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
99354 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
99355 + }
99356 }
99357 out:
99358 if (ret & ~PAGE_MASK)
99359 diff --git a/mm/nommu.c b/mm/nommu.c
99360 index a881d96..e5932cd 100644
99361 --- a/mm/nommu.c
99362 +++ b/mm/nommu.c
99363 @@ -70,7 +70,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
99364 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
99365 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
99366 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
99367 -int heap_stack_gap = 0;
99368
99369 atomic_long_t mmap_pages_allocated;
99370
99371 @@ -857,15 +856,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
99372 EXPORT_SYMBOL(find_vma);
99373
99374 /*
99375 - * find a VMA
99376 - * - we don't extend stack VMAs under NOMMU conditions
99377 - */
99378 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
99379 -{
99380 - return find_vma(mm, addr);
99381 -}
99382 -
99383 -/*
99384 * expand a stack to a given address
99385 * - not supported under NOMMU conditions
99386 */
99387 @@ -1572,6 +1562,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
99388
99389 /* most fields are the same, copy all, and then fixup */
99390 *new = *vma;
99391 + INIT_LIST_HEAD(&new->anon_vma_chain);
99392 *region = *vma->vm_region;
99393 new->vm_region = region;
99394
99395 @@ -2002,8 +1993,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
99396 }
99397 EXPORT_SYMBOL(generic_file_remap_pages);
99398
99399 -static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
99400 - unsigned long addr, void *buf, int len, int write)
99401 +static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
99402 + unsigned long addr, void *buf, size_t len, int write)
99403 {
99404 struct vm_area_struct *vma;
99405
99406 @@ -2044,8 +2035,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
99407 *
99408 * The caller must hold a reference on @mm.
99409 */
99410 -int access_remote_vm(struct mm_struct *mm, unsigned long addr,
99411 - void *buf, int len, int write)
99412 +ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
99413 + void *buf, size_t len, int write)
99414 {
99415 return __access_remote_vm(NULL, mm, addr, buf, len, write);
99416 }
99417 @@ -2054,7 +2045,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
99418 * Access another process' address space.
99419 * - source/target buffer must be kernel space
99420 */
99421 -int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
99422 +ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
99423 {
99424 struct mm_struct *mm;
99425
99426 diff --git a/mm/page-writeback.c b/mm/page-writeback.c
99427 index ba5fd97..5a95869 100644
99428 --- a/mm/page-writeback.c
99429 +++ b/mm/page-writeback.c
99430 @@ -664,7 +664,7 @@ static long long pos_ratio_polynom(unsigned long setpoint,
99431 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
99432 * - the bdi dirty thresh drops quickly due to change of JBOD workload
99433 */
99434 -static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
99435 +static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
99436 unsigned long thresh,
99437 unsigned long bg_thresh,
99438 unsigned long dirty,
99439 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
99440 index c5fe124..2cf7f17 100644
99441 --- a/mm/page_alloc.c
99442 +++ b/mm/page_alloc.c
99443 @@ -61,6 +61,7 @@
99444 #include <linux/page-debug-flags.h>
99445 #include <linux/hugetlb.h>
99446 #include <linux/sched/rt.h>
99447 +#include <linux/random.h>
99448
99449 #include <asm/sections.h>
99450 #include <asm/tlbflush.h>
99451 @@ -357,7 +358,7 @@ out:
99452 * This usage means that zero-order pages may not be compound.
99453 */
99454
99455 -static void free_compound_page(struct page *page)
99456 +void free_compound_page(struct page *page)
99457 {
99458 __free_pages_ok(page, compound_order(page));
99459 }
99460 @@ -740,6 +741,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
99461 int i;
99462 int bad = 0;
99463
99464 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99465 + unsigned long index = 1UL << order;
99466 +#endif
99467 +
99468 trace_mm_page_free(page, order);
99469 kmemcheck_free_shadow(page, order);
99470
99471 @@ -756,6 +761,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
99472 debug_check_no_obj_freed(page_address(page),
99473 PAGE_SIZE << order);
99474 }
99475 +
99476 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99477 + for (; index; --index)
99478 + sanitize_highpage(page + index - 1);
99479 +#endif
99480 +
99481 arch_free_page(page, order);
99482 kernel_map_pages(page, 1 << order, 0);
99483
99484 @@ -779,6 +790,20 @@ static void __free_pages_ok(struct page *page, unsigned int order)
99485 local_irq_restore(flags);
99486 }
99487
99488 +#ifdef CONFIG_PAX_LATENT_ENTROPY
99489 +bool __meminitdata extra_latent_entropy;
99490 +
99491 +static int __init setup_pax_extra_latent_entropy(char *str)
99492 +{
99493 + extra_latent_entropy = true;
99494 + return 0;
99495 +}
99496 +early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
99497 +
99498 +volatile u64 latent_entropy __latent_entropy;
99499 +EXPORT_SYMBOL(latent_entropy);
99500 +#endif
99501 +
99502 void __init __free_pages_bootmem(struct page *page, unsigned int order)
99503 {
99504 unsigned int nr_pages = 1 << order;
99505 @@ -794,6 +819,19 @@ void __init __free_pages_bootmem(struct page *page, unsigned int order)
99506 __ClearPageReserved(p);
99507 set_page_count(p, 0);
99508
99509 +#ifdef CONFIG_PAX_LATENT_ENTROPY
99510 + if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
99511 + u64 hash = 0;
99512 + size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
99513 + const u64 *data = lowmem_page_address(page);
99514 +
99515 + for (index = 0; index < end; index++)
99516 + hash ^= hash + data[index];
99517 + latent_entropy ^= hash;
99518 + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
99519 + }
99520 +#endif
99521 +
99522 page_zone(page)->managed_pages += nr_pages;
99523 set_page_refcounted(page);
99524 __free_pages(page, order);
99525 @@ -922,8 +960,10 @@ static int prep_new_page(struct page *page, unsigned int order, gfp_t gfp_flags)
99526 arch_alloc_page(page, order);
99527 kernel_map_pages(page, 1 << order, 1);
99528
99529 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
99530 if (gfp_flags & __GFP_ZERO)
99531 prep_zero_page(page, order, gfp_flags);
99532 +#endif
99533
99534 if (order && (gfp_flags & __GFP_COMP))
99535 prep_compound_page(page, order);
99536 @@ -1601,7 +1641,7 @@ again:
99537 }
99538
99539 __mod_zone_page_state(zone, NR_ALLOC_BATCH, -(1 << order));
99540 - if (atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]) <= 0 &&
99541 + if (atomic_long_read_unchecked(&zone->vm_stat[NR_ALLOC_BATCH]) <= 0 &&
99542 !zone_is_fair_depleted(zone))
99543 zone_set_flag(zone, ZONE_FAIR_DEPLETED);
99544
99545 @@ -1922,7 +1962,7 @@ static void reset_alloc_batches(struct zone *preferred_zone)
99546 do {
99547 mod_zone_page_state(zone, NR_ALLOC_BATCH,
99548 high_wmark_pages(zone) - low_wmark_pages(zone) -
99549 - atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]));
99550 + atomic_long_read_unchecked(&zone->vm_stat[NR_ALLOC_BATCH]));
99551 zone_clear_flag(zone, ZONE_FAIR_DEPLETED);
99552 } while (zone++ != preferred_zone);
99553 }
99554 @@ -5699,7 +5739,7 @@ static void __setup_per_zone_wmarks(void)
99555
99556 __mod_zone_page_state(zone, NR_ALLOC_BATCH,
99557 high_wmark_pages(zone) - low_wmark_pages(zone) -
99558 - atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]));
99559 + atomic_long_read_unchecked(&zone->vm_stat[NR_ALLOC_BATCH]));
99560
99561 setup_zone_migrate_reserve(zone);
99562 spin_unlock_irqrestore(&zone->lock, flags);
99563 diff --git a/mm/percpu.c b/mm/percpu.c
99564 index 2139e30..1d45bce 100644
99565 --- a/mm/percpu.c
99566 +++ b/mm/percpu.c
99567 @@ -123,7 +123,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
99568 static unsigned int pcpu_high_unit_cpu __read_mostly;
99569
99570 /* the address of the first chunk which starts with the kernel static area */
99571 -void *pcpu_base_addr __read_mostly;
99572 +void *pcpu_base_addr __read_only;
99573 EXPORT_SYMBOL_GPL(pcpu_base_addr);
99574
99575 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
99576 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
99577 index 5077afc..846c9ef 100644
99578 --- a/mm/process_vm_access.c
99579 +++ b/mm/process_vm_access.c
99580 @@ -13,6 +13,7 @@
99581 #include <linux/uio.h>
99582 #include <linux/sched.h>
99583 #include <linux/highmem.h>
99584 +#include <linux/security.h>
99585 #include <linux/ptrace.h>
99586 #include <linux/slab.h>
99587 #include <linux/syscalls.h>
99588 @@ -157,19 +158,19 @@ static ssize_t process_vm_rw_core(pid_t pid, struct iov_iter *iter,
99589 ssize_t iov_len;
99590 size_t total_len = iov_iter_count(iter);
99591
99592 + return -ENOSYS; // PaX: until properly audited
99593 +
99594 /*
99595 * Work out how many pages of struct pages we're going to need
99596 * when eventually calling get_user_pages
99597 */
99598 for (i = 0; i < riovcnt; i++) {
99599 iov_len = rvec[i].iov_len;
99600 - if (iov_len > 0) {
99601 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
99602 - + iov_len)
99603 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
99604 - / PAGE_SIZE + 1;
99605 - nr_pages = max(nr_pages, nr_pages_iov);
99606 - }
99607 + if (iov_len <= 0)
99608 + continue;
99609 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
99610 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
99611 + nr_pages = max(nr_pages, nr_pages_iov);
99612 }
99613
99614 if (nr_pages == 0)
99615 @@ -197,6 +198,11 @@ static ssize_t process_vm_rw_core(pid_t pid, struct iov_iter *iter,
99616 goto free_proc_pages;
99617 }
99618
99619 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
99620 + rc = -EPERM;
99621 + goto put_task_struct;
99622 + }
99623 +
99624 mm = mm_access(task, PTRACE_MODE_ATTACH);
99625 if (!mm || IS_ERR(mm)) {
99626 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
99627 diff --git a/mm/rmap.c b/mm/rmap.c
99628 index 1807ca3..7a532bd 100644
99629 --- a/mm/rmap.c
99630 +++ b/mm/rmap.c
99631 @@ -164,6 +164,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
99632 struct anon_vma *anon_vma = vma->anon_vma;
99633 struct anon_vma_chain *avc;
99634
99635 +#ifdef CONFIG_PAX_SEGMEXEC
99636 + struct anon_vma_chain *avc_m = NULL;
99637 +#endif
99638 +
99639 might_sleep();
99640 if (unlikely(!anon_vma)) {
99641 struct mm_struct *mm = vma->vm_mm;
99642 @@ -173,6 +177,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
99643 if (!avc)
99644 goto out_enomem;
99645
99646 +#ifdef CONFIG_PAX_SEGMEXEC
99647 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
99648 + if (!avc_m)
99649 + goto out_enomem_free_avc;
99650 +#endif
99651 +
99652 anon_vma = find_mergeable_anon_vma(vma);
99653 allocated = NULL;
99654 if (!anon_vma) {
99655 @@ -186,6 +196,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
99656 /* page_table_lock to protect against threads */
99657 spin_lock(&mm->page_table_lock);
99658 if (likely(!vma->anon_vma)) {
99659 +
99660 +#ifdef CONFIG_PAX_SEGMEXEC
99661 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
99662 +
99663 + if (vma_m) {
99664 + BUG_ON(vma_m->anon_vma);
99665 + vma_m->anon_vma = anon_vma;
99666 + anon_vma_chain_link(vma_m, avc_m, anon_vma);
99667 + avc_m = NULL;
99668 + }
99669 +#endif
99670 +
99671 vma->anon_vma = anon_vma;
99672 anon_vma_chain_link(vma, avc, anon_vma);
99673 allocated = NULL;
99674 @@ -196,12 +218,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
99675
99676 if (unlikely(allocated))
99677 put_anon_vma(allocated);
99678 +
99679 +#ifdef CONFIG_PAX_SEGMEXEC
99680 + if (unlikely(avc_m))
99681 + anon_vma_chain_free(avc_m);
99682 +#endif
99683 +
99684 if (unlikely(avc))
99685 anon_vma_chain_free(avc);
99686 }
99687 return 0;
99688
99689 out_enomem_free_avc:
99690 +
99691 +#ifdef CONFIG_PAX_SEGMEXEC
99692 + if (avc_m)
99693 + anon_vma_chain_free(avc_m);
99694 +#endif
99695 +
99696 anon_vma_chain_free(avc);
99697 out_enomem:
99698 return -ENOMEM;
99699 @@ -237,7 +271,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
99700 * Attach the anon_vmas from src to dst.
99701 * Returns 0 on success, -ENOMEM on failure.
99702 */
99703 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
99704 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
99705 {
99706 struct anon_vma_chain *avc, *pavc;
99707 struct anon_vma *root = NULL;
99708 @@ -270,7 +304,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
99709 * the corresponding VMA in the parent process is attached to.
99710 * Returns 0 on success, non-zero on failure.
99711 */
99712 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
99713 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
99714 {
99715 struct anon_vma_chain *avc;
99716 struct anon_vma *anon_vma;
99717 @@ -376,8 +410,10 @@ static void anon_vma_ctor(void *data)
99718 void __init anon_vma_init(void)
99719 {
99720 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
99721 - 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
99722 - anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
99723 + 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
99724 + anon_vma_ctor);
99725 + anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
99726 + SLAB_PANIC|SLAB_NO_SANITIZE);
99727 }
99728
99729 /*
99730 diff --git a/mm/shmem.c b/mm/shmem.c
99731 index 469f90d..34a09ee 100644
99732 --- a/mm/shmem.c
99733 +++ b/mm/shmem.c
99734 @@ -33,7 +33,7 @@
99735 #include <linux/swap.h>
99736 #include <linux/aio.h>
99737
99738 -static struct vfsmount *shm_mnt;
99739 +struct vfsmount *shm_mnt;
99740
99741 #ifdef CONFIG_SHMEM
99742 /*
99743 @@ -80,7 +80,7 @@ static struct vfsmount *shm_mnt;
99744 #define BOGO_DIRENT_SIZE 20
99745
99746 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
99747 -#define SHORT_SYMLINK_LEN 128
99748 +#define SHORT_SYMLINK_LEN 64
99749
99750 /*
99751 * shmem_fallocate communicates with shmem_fault or shmem_writepage via
99752 @@ -2524,6 +2524,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
99753 static int shmem_xattr_validate(const char *name)
99754 {
99755 struct { const char *prefix; size_t len; } arr[] = {
99756 +
99757 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
99758 + { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
99759 +#endif
99760 +
99761 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
99762 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
99763 };
99764 @@ -2579,6 +2584,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
99765 if (err)
99766 return err;
99767
99768 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
99769 + if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
99770 + if (strcmp(name, XATTR_NAME_PAX_FLAGS))
99771 + return -EOPNOTSUPP;
99772 + if (size > 8)
99773 + return -EINVAL;
99774 + }
99775 +#endif
99776 +
99777 return simple_xattr_set(&info->xattrs, name, value, size, flags);
99778 }
99779
99780 @@ -2962,8 +2976,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
99781 int err = -ENOMEM;
99782
99783 /* Round up to L1_CACHE_BYTES to resist false sharing */
99784 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
99785 - L1_CACHE_BYTES), GFP_KERNEL);
99786 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
99787 if (!sbinfo)
99788 return -ENOMEM;
99789
99790 diff --git a/mm/slab.c b/mm/slab.c
99791 index cc91c1e..0676592 100644
99792 --- a/mm/slab.c
99793 +++ b/mm/slab.c
99794 @@ -316,10 +316,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
99795 if ((x)->max_freeable < i) \
99796 (x)->max_freeable = i; \
99797 } while (0)
99798 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
99799 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
99800 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
99801 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
99802 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
99803 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
99804 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
99805 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
99806 +#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
99807 +#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
99808 #else
99809 #define STATS_INC_ACTIVE(x) do { } while (0)
99810 #define STATS_DEC_ACTIVE(x) do { } while (0)
99811 @@ -336,6 +338,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
99812 #define STATS_INC_ALLOCMISS(x) do { } while (0)
99813 #define STATS_INC_FREEHIT(x) do { } while (0)
99814 #define STATS_INC_FREEMISS(x) do { } while (0)
99815 +#define STATS_INC_SANITIZED(x) do { } while (0)
99816 +#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
99817 #endif
99818
99819 #if DEBUG
99820 @@ -452,7 +456,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct page *page,
99821 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
99822 */
99823 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
99824 - const struct page *page, void *obj)
99825 + const struct page *page, const void *obj)
99826 {
99827 u32 offset = (obj - page->s_mem);
99828 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
99829 @@ -1462,12 +1466,12 @@ void __init kmem_cache_init(void)
99830 */
99831
99832 kmalloc_caches[INDEX_AC] = create_kmalloc_cache("kmalloc-ac",
99833 - kmalloc_size(INDEX_AC), ARCH_KMALLOC_FLAGS);
99834 + kmalloc_size(INDEX_AC), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
99835
99836 if (INDEX_AC != INDEX_NODE)
99837 kmalloc_caches[INDEX_NODE] =
99838 create_kmalloc_cache("kmalloc-node",
99839 - kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
99840 + kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
99841
99842 slab_early_init = 0;
99843
99844 @@ -3384,6 +3388,20 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
99845 struct array_cache *ac = cpu_cache_get(cachep);
99846
99847 check_irq_off();
99848 +
99849 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99850 + if (cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))
99851 + STATS_INC_NOT_SANITIZED(cachep);
99852 + else {
99853 + memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
99854 +
99855 + if (cachep->ctor)
99856 + cachep->ctor(objp);
99857 +
99858 + STATS_INC_SANITIZED(cachep);
99859 + }
99860 +#endif
99861 +
99862 kmemleak_free_recursive(objp, cachep->flags);
99863 objp = cache_free_debugcheck(cachep, objp, caller);
99864
99865 @@ -3607,6 +3625,7 @@ void kfree(const void *objp)
99866
99867 if (unlikely(ZERO_OR_NULL_PTR(objp)))
99868 return;
99869 + VM_BUG_ON(!virt_addr_valid(objp));
99870 local_irq_save(flags);
99871 kfree_debugcheck(objp);
99872 c = virt_to_cache(objp);
99873 @@ -4056,14 +4075,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
99874 }
99875 /* cpu stats */
99876 {
99877 - unsigned long allochit = atomic_read(&cachep->allochit);
99878 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
99879 - unsigned long freehit = atomic_read(&cachep->freehit);
99880 - unsigned long freemiss = atomic_read(&cachep->freemiss);
99881 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
99882 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
99883 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
99884 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
99885
99886 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
99887 allochit, allocmiss, freehit, freemiss);
99888 }
99889 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99890 + {
99891 + unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
99892 + unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
99893 +
99894 + seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
99895 + }
99896 +#endif
99897 #endif
99898 }
99899
99900 @@ -4281,13 +4308,69 @@ static const struct file_operations proc_slabstats_operations = {
99901 static int __init slab_proc_init(void)
99902 {
99903 #ifdef CONFIG_DEBUG_SLAB_LEAK
99904 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
99905 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
99906 #endif
99907 return 0;
99908 }
99909 module_init(slab_proc_init);
99910 #endif
99911
99912 +bool is_usercopy_object(const void *ptr)
99913 +{
99914 + struct page *page;
99915 + struct kmem_cache *cachep;
99916 +
99917 + if (ZERO_OR_NULL_PTR(ptr))
99918 + return false;
99919 +
99920 + if (!slab_is_available())
99921 + return false;
99922 +
99923 + if (!virt_addr_valid(ptr))
99924 + return false;
99925 +
99926 + page = virt_to_head_page(ptr);
99927 +
99928 + if (!PageSlab(page))
99929 + return false;
99930 +
99931 + cachep = page->slab_cache;
99932 + return cachep->flags & SLAB_USERCOPY;
99933 +}
99934 +
99935 +#ifdef CONFIG_PAX_USERCOPY
99936 +const char *check_heap_object(const void *ptr, unsigned long n)
99937 +{
99938 + struct page *page;
99939 + struct kmem_cache *cachep;
99940 + unsigned int objnr;
99941 + unsigned long offset;
99942 +
99943 + if (ZERO_OR_NULL_PTR(ptr))
99944 + return "<null>";
99945 +
99946 + if (!virt_addr_valid(ptr))
99947 + return NULL;
99948 +
99949 + page = virt_to_head_page(ptr);
99950 +
99951 + if (!PageSlab(page))
99952 + return NULL;
99953 +
99954 + cachep = page->slab_cache;
99955 + if (!(cachep->flags & SLAB_USERCOPY))
99956 + return cachep->name;
99957 +
99958 + objnr = obj_to_index(cachep, page, ptr);
99959 + BUG_ON(objnr >= cachep->num);
99960 + offset = ptr - index_to_obj(cachep, page, objnr) - obj_offset(cachep);
99961 + if (offset <= cachep->object_size && n <= cachep->object_size - offset)
99962 + return NULL;
99963 +
99964 + return cachep->name;
99965 +}
99966 +#endif
99967 +
99968 /**
99969 * ksize - get the actual amount of memory allocated for a given object
99970 * @objp: Pointer to the object
99971 diff --git a/mm/slab.h b/mm/slab.h
99972 index 0e0fdd3..d0fd761 100644
99973 --- a/mm/slab.h
99974 +++ b/mm/slab.h
99975 @@ -32,6 +32,20 @@ extern struct list_head slab_caches;
99976 /* The slab cache that manages slab cache information */
99977 extern struct kmem_cache *kmem_cache;
99978
99979 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99980 +#ifdef CONFIG_X86_64
99981 +#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
99982 +#else
99983 +#define PAX_MEMORY_SANITIZE_VALUE '\xff'
99984 +#endif
99985 +enum pax_sanitize_mode {
99986 + PAX_SANITIZE_SLAB_OFF = 0,
99987 + PAX_SANITIZE_SLAB_FAST,
99988 + PAX_SANITIZE_SLAB_FULL,
99989 +};
99990 +extern enum pax_sanitize_mode pax_sanitize_slab;
99991 +#endif
99992 +
99993 unsigned long calculate_alignment(unsigned long flags,
99994 unsigned long align, unsigned long size);
99995
99996 @@ -67,7 +81,8 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
99997
99998 /* Legal flag mask for kmem_cache_create(), for various configurations */
99999 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
100000 - SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
100001 + SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
100002 + SLAB_USERCOPY | SLAB_NO_SANITIZE)
100003
100004 #if defined(CONFIG_DEBUG_SLAB)
100005 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
100006 @@ -251,6 +266,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
100007 return s;
100008
100009 page = virt_to_head_page(x);
100010 +
100011 + BUG_ON(!PageSlab(page));
100012 +
100013 cachep = page->slab_cache;
100014 if (slab_equal_or_root(cachep, s))
100015 return cachep;
100016 diff --git a/mm/slab_common.c b/mm/slab_common.c
100017 index d319502..da7714e 100644
100018 --- a/mm/slab_common.c
100019 +++ b/mm/slab_common.c
100020 @@ -25,11 +25,35 @@
100021
100022 #include "slab.h"
100023
100024 -enum slab_state slab_state;
100025 +enum slab_state slab_state __read_only;
100026 LIST_HEAD(slab_caches);
100027 DEFINE_MUTEX(slab_mutex);
100028 struct kmem_cache *kmem_cache;
100029
100030 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
100031 +enum pax_sanitize_mode pax_sanitize_slab __read_only = PAX_SANITIZE_SLAB_FAST;
100032 +static int __init pax_sanitize_slab_setup(char *str)
100033 +{
100034 + if (!str)
100035 + return 0;
100036 +
100037 + if (!strcmp(str, "0") || !strcmp(str, "off")) {
100038 + pr_info("PaX slab sanitization: %s\n", "disabled");
100039 + pax_sanitize_slab = PAX_SANITIZE_SLAB_OFF;
100040 + } else if (!strcmp(str, "1") || !strcmp(str, "fast")) {
100041 + pr_info("PaX slab sanitization: %s\n", "fast");
100042 + pax_sanitize_slab = PAX_SANITIZE_SLAB_FAST;
100043 + } else if (!strcmp(str, "full")) {
100044 + pr_info("PaX slab sanitization: %s\n", "full");
100045 + pax_sanitize_slab = PAX_SANITIZE_SLAB_FULL;
100046 + } else
100047 + pr_err("PaX slab sanitization: unsupported option '%s'\n", str);
100048 +
100049 + return 0;
100050 +}
100051 +early_param("pax_sanitize_slab", pax_sanitize_slab_setup);
100052 +#endif
100053 +
100054 #ifdef CONFIG_DEBUG_VM
100055 static int kmem_cache_sanity_check(const char *name, size_t size)
100056 {
100057 @@ -160,7 +184,7 @@ do_kmem_cache_create(char *name, size_t object_size, size_t size, size_t align,
100058 if (err)
100059 goto out_free_cache;
100060
100061 - s->refcount = 1;
100062 + atomic_set(&s->refcount, 1);
100063 list_add(&s->list, &slab_caches);
100064 out:
100065 if (err)
100066 @@ -222,6 +246,13 @@ kmem_cache_create(const char *name, size_t size, size_t align,
100067 */
100068 flags &= CACHE_CREATE_MASK;
100069
100070 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
100071 + if (pax_sanitize_slab == PAX_SANITIZE_SLAB_OFF || (flags & SLAB_DESTROY_BY_RCU))
100072 + flags |= SLAB_NO_SANITIZE;
100073 + else if (pax_sanitize_slab == PAX_SANITIZE_SLAB_FULL)
100074 + flags &= ~SLAB_NO_SANITIZE;
100075 +#endif
100076 +
100077 s = __kmem_cache_alias(name, size, align, flags, ctor);
100078 if (s)
100079 goto out_unlock;
100080 @@ -341,8 +372,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
100081
100082 mutex_lock(&slab_mutex);
100083
100084 - s->refcount--;
100085 - if (s->refcount)
100086 + if (!atomic_dec_and_test(&s->refcount))
100087 goto out_unlock;
100088
100089 if (memcg_cleanup_cache_params(s) != 0)
100090 @@ -362,7 +392,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
100091 rcu_barrier();
100092
100093 memcg_free_cache_params(s);
100094 -#ifdef SLAB_SUPPORTS_SYSFS
100095 +#if defined(SLAB_SUPPORTS_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
100096 sysfs_slab_remove(s);
100097 #else
100098 slab_kmem_cache_release(s);
100099 @@ -418,7 +448,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
100100 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
100101 name, size, err);
100102
100103 - s->refcount = -1; /* Exempt from merging for now */
100104 + atomic_set(&s->refcount, -1); /* Exempt from merging for now */
100105 }
100106
100107 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
100108 @@ -431,7 +461,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
100109
100110 create_boot_cache(s, name, size, flags);
100111 list_add(&s->list, &slab_caches);
100112 - s->refcount = 1;
100113 + atomic_set(&s->refcount, 1);
100114 return s;
100115 }
100116
100117 @@ -443,6 +473,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
100118 EXPORT_SYMBOL(kmalloc_dma_caches);
100119 #endif
100120
100121 +#ifdef CONFIG_PAX_USERCOPY_SLABS
100122 +struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
100123 +EXPORT_SYMBOL(kmalloc_usercopy_caches);
100124 +#endif
100125 +
100126 /*
100127 * Conversion table for small slabs sizes / 8 to the index in the
100128 * kmalloc array. This is necessary for slabs < 192 since we have non power
100129 @@ -507,6 +542,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
100130 return kmalloc_dma_caches[index];
100131
100132 #endif
100133 +
100134 +#ifdef CONFIG_PAX_USERCOPY_SLABS
100135 + if (unlikely((flags & GFP_USERCOPY)))
100136 + return kmalloc_usercopy_caches[index];
100137 +
100138 +#endif
100139 +
100140 return kmalloc_caches[index];
100141 }
100142
100143 @@ -563,7 +605,7 @@ void __init create_kmalloc_caches(unsigned long flags)
100144 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
100145 if (!kmalloc_caches[i]) {
100146 kmalloc_caches[i] = create_kmalloc_cache(NULL,
100147 - 1 << i, flags);
100148 + 1 << i, SLAB_USERCOPY | flags);
100149 }
100150
100151 /*
100152 @@ -572,10 +614,10 @@ void __init create_kmalloc_caches(unsigned long flags)
100153 * earlier power of two caches
100154 */
100155 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
100156 - kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
100157 + kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
100158
100159 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
100160 - kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
100161 + kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
100162 }
100163
100164 /* Kmalloc array is now usable */
100165 @@ -608,6 +650,23 @@ void __init create_kmalloc_caches(unsigned long flags)
100166 }
100167 }
100168 #endif
100169 +
100170 +#ifdef CONFIG_PAX_USERCOPY_SLABS
100171 + for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
100172 + struct kmem_cache *s = kmalloc_caches[i];
100173 +
100174 + if (s) {
100175 + int size = kmalloc_size(i);
100176 + char *n = kasprintf(GFP_NOWAIT,
100177 + "usercopy-kmalloc-%d", size);
100178 +
100179 + BUG_ON(!n);
100180 + kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
100181 + size, SLAB_USERCOPY | flags);
100182 + }
100183 + }
100184 +#endif
100185 +
100186 }
100187 #endif /* !CONFIG_SLOB */
100188
100189 @@ -666,6 +725,9 @@ void print_slabinfo_header(struct seq_file *m)
100190 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
100191 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
100192 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
100193 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
100194 + seq_puts(m, " : pax <sanitized> <not_sanitized>");
100195 +#endif
100196 #endif
100197 seq_putc(m, '\n');
100198 }
100199 diff --git a/mm/slob.c b/mm/slob.c
100200 index 21980e0..975f1bf 100644
100201 --- a/mm/slob.c
100202 +++ b/mm/slob.c
100203 @@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
100204 /*
100205 * Return the size of a slob block.
100206 */
100207 -static slobidx_t slob_units(slob_t *s)
100208 +static slobidx_t slob_units(const slob_t *s)
100209 {
100210 if (s->units > 0)
100211 return s->units;
100212 @@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
100213 /*
100214 * Return the next free slob block pointer after this one.
100215 */
100216 -static slob_t *slob_next(slob_t *s)
100217 +static slob_t *slob_next(const slob_t *s)
100218 {
100219 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
100220 slobidx_t next;
100221 @@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
100222 /*
100223 * Returns true if s is the last free block in its page.
100224 */
100225 -static int slob_last(slob_t *s)
100226 +static int slob_last(const slob_t *s)
100227 {
100228 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
100229 }
100230
100231 -static void *slob_new_pages(gfp_t gfp, int order, int node)
100232 +static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
100233 {
100234 - void *page;
100235 + struct page *page;
100236
100237 #ifdef CONFIG_NUMA
100238 if (node != NUMA_NO_NODE)
100239 @@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
100240 if (!page)
100241 return NULL;
100242
100243 - return page_address(page);
100244 + __SetPageSlab(page);
100245 + return page;
100246 }
100247
100248 -static void slob_free_pages(void *b, int order)
100249 +static void slob_free_pages(struct page *sp, int order)
100250 {
100251 if (current->reclaim_state)
100252 current->reclaim_state->reclaimed_slab += 1 << order;
100253 - free_pages((unsigned long)b, order);
100254 + __ClearPageSlab(sp);
100255 + page_mapcount_reset(sp);
100256 + sp->private = 0;
100257 + __free_pages(sp, order);
100258 }
100259
100260 /*
100261 @@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
100262
100263 /* Not enough space: must allocate a new page */
100264 if (!b) {
100265 - b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
100266 - if (!b)
100267 + sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
100268 + if (!sp)
100269 return NULL;
100270 - sp = virt_to_page(b);
100271 - __SetPageSlab(sp);
100272 + b = page_address(sp);
100273
100274 spin_lock_irqsave(&slob_lock, flags);
100275 sp->units = SLOB_UNITS(PAGE_SIZE);
100276 sp->freelist = b;
100277 + sp->private = 0;
100278 INIT_LIST_HEAD(&sp->lru);
100279 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
100280 set_slob_page_free(sp, slob_list);
100281 @@ -337,7 +341,7 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
100282 /*
100283 * slob_free: entry point into the slob allocator.
100284 */
100285 -static void slob_free(void *block, int size)
100286 +static void slob_free(struct kmem_cache *c, void *block, int size)
100287 {
100288 struct page *sp;
100289 slob_t *prev, *next, *b = (slob_t *)block;
100290 @@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
100291 if (slob_page_free(sp))
100292 clear_slob_page_free(sp);
100293 spin_unlock_irqrestore(&slob_lock, flags);
100294 - __ClearPageSlab(sp);
100295 - page_mapcount_reset(sp);
100296 - slob_free_pages(b, 0);
100297 + slob_free_pages(sp, 0);
100298 return;
100299 }
100300
100301 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
100302 + if (pax_sanitize_slab && !(c && (c->flags & SLAB_NO_SANITIZE)))
100303 + memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
100304 +#endif
100305 +
100306 if (!slob_page_free(sp)) {
100307 /* This slob page is about to become partially free. Easy! */
100308 sp->units = units;
100309 @@ -424,11 +431,10 @@ out:
100310 */
100311
100312 static __always_inline void *
100313 -__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
100314 +__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
100315 {
100316 - unsigned int *m;
100317 - int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
100318 - void *ret;
100319 + slob_t *m;
100320 + void *ret = NULL;
100321
100322 gfp &= gfp_allowed_mask;
100323
100324 @@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
100325
100326 if (!m)
100327 return NULL;
100328 - *m = size;
100329 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
100330 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
100331 + m[0].units = size;
100332 + m[1].units = align;
100333 ret = (void *)m + align;
100334
100335 trace_kmalloc_node(caller, ret,
100336 size, size + align, gfp, node);
100337 } else {
100338 unsigned int order = get_order(size);
100339 + struct page *page;
100340
100341 if (likely(order))
100342 gfp |= __GFP_COMP;
100343 - ret = slob_new_pages(gfp, order, node);
100344 + page = slob_new_pages(gfp, order, node);
100345 + if (page) {
100346 + ret = page_address(page);
100347 + page->private = size;
100348 + }
100349
100350 trace_kmalloc_node(caller, ret,
100351 size, PAGE_SIZE << order, gfp, node);
100352 }
100353
100354 - kmemleak_alloc(ret, size, 1, gfp);
100355 + return ret;
100356 +}
100357 +
100358 +static __always_inline void *
100359 +__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
100360 +{
100361 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
100362 + void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
100363 +
100364 + if (!ZERO_OR_NULL_PTR(ret))
100365 + kmemleak_alloc(ret, size, 1, gfp);
100366 return ret;
100367 }
100368
100369 @@ -493,34 +517,112 @@ void kfree(const void *block)
100370 return;
100371 kmemleak_free(block);
100372
100373 + VM_BUG_ON(!virt_addr_valid(block));
100374 sp = virt_to_page(block);
100375 - if (PageSlab(sp)) {
100376 + VM_BUG_ON(!PageSlab(sp));
100377 + if (!sp->private) {
100378 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
100379 - unsigned int *m = (unsigned int *)(block - align);
100380 - slob_free(m, *m + align);
100381 - } else
100382 + slob_t *m = (slob_t *)(block - align);
100383 + slob_free(NULL, m, m[0].units + align);
100384 + } else {
100385 + __ClearPageSlab(sp);
100386 + page_mapcount_reset(sp);
100387 + sp->private = 0;
100388 __free_pages(sp, compound_order(sp));
100389 + }
100390 }
100391 EXPORT_SYMBOL(kfree);
100392
100393 +bool is_usercopy_object(const void *ptr)
100394 +{
100395 + if (!slab_is_available())
100396 + return false;
100397 +
100398 + // PAX: TODO
100399 +
100400 + return false;
100401 +}
100402 +
100403 +#ifdef CONFIG_PAX_USERCOPY
100404 +const char *check_heap_object(const void *ptr, unsigned long n)
100405 +{
100406 + struct page *page;
100407 + const slob_t *free;
100408 + const void *base;
100409 + unsigned long flags;
100410 +
100411 + if (ZERO_OR_NULL_PTR(ptr))
100412 + return "<null>";
100413 +
100414 + if (!virt_addr_valid(ptr))
100415 + return NULL;
100416 +
100417 + page = virt_to_head_page(ptr);
100418 + if (!PageSlab(page))
100419 + return NULL;
100420 +
100421 + if (page->private) {
100422 + base = page;
100423 + if (base <= ptr && n <= page->private - (ptr - base))
100424 + return NULL;
100425 + return "<slob>";
100426 + }
100427 +
100428 + /* some tricky double walking to find the chunk */
100429 + spin_lock_irqsave(&slob_lock, flags);
100430 + base = (void *)((unsigned long)ptr & PAGE_MASK);
100431 + free = page->freelist;
100432 +
100433 + while (!slob_last(free) && (void *)free <= ptr) {
100434 + base = free + slob_units(free);
100435 + free = slob_next(free);
100436 + }
100437 +
100438 + while (base < (void *)free) {
100439 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
100440 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
100441 + int offset;
100442 +
100443 + if (ptr < base + align)
100444 + break;
100445 +
100446 + offset = ptr - base - align;
100447 + if (offset >= m) {
100448 + base += size;
100449 + continue;
100450 + }
100451 +
100452 + if (n > m - offset)
100453 + break;
100454 +
100455 + spin_unlock_irqrestore(&slob_lock, flags);
100456 + return NULL;
100457 + }
100458 +
100459 + spin_unlock_irqrestore(&slob_lock, flags);
100460 + return "<slob>";
100461 +}
100462 +#endif
100463 +
100464 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
100465 size_t ksize(const void *block)
100466 {
100467 struct page *sp;
100468 int align;
100469 - unsigned int *m;
100470 + slob_t *m;
100471
100472 BUG_ON(!block);
100473 if (unlikely(block == ZERO_SIZE_PTR))
100474 return 0;
100475
100476 sp = virt_to_page(block);
100477 - if (unlikely(!PageSlab(sp)))
100478 - return PAGE_SIZE << compound_order(sp);
100479 + VM_BUG_ON(!PageSlab(sp));
100480 + if (sp->private)
100481 + return sp->private;
100482
100483 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
100484 - m = (unsigned int *)(block - align);
100485 - return SLOB_UNITS(*m) * SLOB_UNIT;
100486 + m = (slob_t *)(block - align);
100487 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
100488 }
100489 EXPORT_SYMBOL(ksize);
100490
100491 @@ -536,23 +638,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
100492
100493 void *slob_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
100494 {
100495 - void *b;
100496 + void *b = NULL;
100497
100498 flags &= gfp_allowed_mask;
100499
100500 lockdep_trace_alloc(flags);
100501
100502 +#ifdef CONFIG_PAX_USERCOPY_SLABS
100503 + b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
100504 +#else
100505 if (c->size < PAGE_SIZE) {
100506 b = slob_alloc(c->size, flags, c->align, node);
100507 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
100508 SLOB_UNITS(c->size) * SLOB_UNIT,
100509 flags, node);
100510 } else {
100511 - b = slob_new_pages(flags, get_order(c->size), node);
100512 + struct page *sp;
100513 +
100514 + sp = slob_new_pages(flags, get_order(c->size), node);
100515 + if (sp) {
100516 + b = page_address(sp);
100517 + sp->private = c->size;
100518 + }
100519 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
100520 PAGE_SIZE << get_order(c->size),
100521 flags, node);
100522 }
100523 +#endif
100524
100525 if (b && c->ctor)
100526 c->ctor(b);
100527 @@ -582,12 +694,16 @@ void *kmem_cache_alloc_node(struct kmem_cache *cachep, gfp_t gfp, int node)
100528 EXPORT_SYMBOL(kmem_cache_alloc_node);
100529 #endif
100530
100531 -static void __kmem_cache_free(void *b, int size)
100532 +static void __kmem_cache_free(struct kmem_cache *c, void *b, int size)
100533 {
100534 - if (size < PAGE_SIZE)
100535 - slob_free(b, size);
100536 + struct page *sp;
100537 +
100538 + sp = virt_to_page(b);
100539 + BUG_ON(!PageSlab(sp));
100540 + if (!sp->private)
100541 + slob_free(c, b, size);
100542 else
100543 - slob_free_pages(b, get_order(size));
100544 + slob_free_pages(sp, get_order(size));
100545 }
100546
100547 static void kmem_rcu_free(struct rcu_head *head)
100548 @@ -595,22 +711,36 @@ static void kmem_rcu_free(struct rcu_head *head)
100549 struct slob_rcu *slob_rcu = (struct slob_rcu *)head;
100550 void *b = (void *)slob_rcu - (slob_rcu->size - sizeof(struct slob_rcu));
100551
100552 - __kmem_cache_free(b, slob_rcu->size);
100553 + __kmem_cache_free(NULL, b, slob_rcu->size);
100554 }
100555
100556 void kmem_cache_free(struct kmem_cache *c, void *b)
100557 {
100558 + int size = c->size;
100559 +
100560 +#ifdef CONFIG_PAX_USERCOPY_SLABS
100561 + if (size + c->align < PAGE_SIZE) {
100562 + size += c->align;
100563 + b -= c->align;
100564 + }
100565 +#endif
100566 +
100567 kmemleak_free_recursive(b, c->flags);
100568 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
100569 struct slob_rcu *slob_rcu;
100570 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
100571 - slob_rcu->size = c->size;
100572 + slob_rcu = b + (size - sizeof(struct slob_rcu));
100573 + slob_rcu->size = size;
100574 call_rcu(&slob_rcu->head, kmem_rcu_free);
100575 } else {
100576 - __kmem_cache_free(b, c->size);
100577 + __kmem_cache_free(c, b, size);
100578 }
100579
100580 +#ifdef CONFIG_PAX_USERCOPY_SLABS
100581 + trace_kfree(_RET_IP_, b);
100582 +#else
100583 trace_kmem_cache_free(_RET_IP_, b);
100584 +#endif
100585 +
100586 }
100587 EXPORT_SYMBOL(kmem_cache_free);
100588
100589 diff --git a/mm/slub.c b/mm/slub.c
100590 index 3e8afcc..d6e2c89 100644
100591 --- a/mm/slub.c
100592 +++ b/mm/slub.c
100593 @@ -207,7 +207,7 @@ struct track {
100594
100595 enum track_item { TRACK_ALLOC, TRACK_FREE };
100596
100597 -#ifdef CONFIG_SYSFS
100598 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
100599 static int sysfs_slab_add(struct kmem_cache *);
100600 static int sysfs_slab_alias(struct kmem_cache *, const char *);
100601 static void memcg_propagate_slab_attrs(struct kmem_cache *s);
100602 @@ -545,7 +545,7 @@ static void print_track(const char *s, struct track *t)
100603 if (!t->addr)
100604 return;
100605
100606 - pr_err("INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
100607 + pr_err("INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
100608 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
100609 #ifdef CONFIG_STACKTRACE
100610 {
100611 @@ -2643,6 +2643,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
100612
100613 slab_free_hook(s, x);
100614
100615 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
100616 + if (!(s->flags & SLAB_NO_SANITIZE)) {
100617 + memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
100618 + if (s->ctor)
100619 + s->ctor(x);
100620 + }
100621 +#endif
100622 +
100623 redo:
100624 /*
100625 * Determine the currently cpus per cpu slab.
100626 @@ -2710,7 +2718,7 @@ static int slub_min_objects;
100627 * Merge control. If this is set then no merging of slab caches will occur.
100628 * (Could be removed. This was introduced to pacify the merge skeptics.)
100629 */
100630 -static int slub_nomerge;
100631 +static int slub_nomerge = 1;
100632
100633 /*
100634 * Calculate the order of allocation given an slab object size.
100635 @@ -2986,6 +2994,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
100636 s->inuse = size;
100637
100638 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
100639 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
100640 + (!(flags & SLAB_NO_SANITIZE)) ||
100641 +#endif
100642 s->ctor)) {
100643 /*
100644 * Relocate free pointer after the object if it is not
100645 @@ -3313,6 +3324,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
100646 EXPORT_SYMBOL(__kmalloc_node);
100647 #endif
100648
100649 +bool is_usercopy_object(const void *ptr)
100650 +{
100651 + struct page *page;
100652 + struct kmem_cache *s;
100653 +
100654 + if (ZERO_OR_NULL_PTR(ptr))
100655 + return false;
100656 +
100657 + if (!slab_is_available())
100658 + return false;
100659 +
100660 + if (!virt_addr_valid(ptr))
100661 + return false;
100662 +
100663 + page = virt_to_head_page(ptr);
100664 +
100665 + if (!PageSlab(page))
100666 + return false;
100667 +
100668 + s = page->slab_cache;
100669 + return s->flags & SLAB_USERCOPY;
100670 +}
100671 +
100672 +#ifdef CONFIG_PAX_USERCOPY
100673 +const char *check_heap_object(const void *ptr, unsigned long n)
100674 +{
100675 + struct page *page;
100676 + struct kmem_cache *s;
100677 + unsigned long offset;
100678 +
100679 + if (ZERO_OR_NULL_PTR(ptr))
100680 + return "<null>";
100681 +
100682 + if (!virt_addr_valid(ptr))
100683 + return NULL;
100684 +
100685 + page = virt_to_head_page(ptr);
100686 +
100687 + if (!PageSlab(page))
100688 + return NULL;
100689 +
100690 + s = page->slab_cache;
100691 + if (!(s->flags & SLAB_USERCOPY))
100692 + return s->name;
100693 +
100694 + offset = (ptr - page_address(page)) % s->size;
100695 + if (offset <= s->object_size && n <= s->object_size - offset)
100696 + return NULL;
100697 +
100698 + return s->name;
100699 +}
100700 +#endif
100701 +
100702 size_t ksize(const void *object)
100703 {
100704 struct page *page;
100705 @@ -3341,6 +3405,7 @@ void kfree(const void *x)
100706 if (unlikely(ZERO_OR_NULL_PTR(x)))
100707 return;
100708
100709 + VM_BUG_ON(!virt_addr_valid(x));
100710 page = virt_to_head_page(x);
100711 if (unlikely(!PageSlab(page))) {
100712 BUG_ON(!PageCompound(page));
100713 @@ -3642,7 +3707,7 @@ static int slab_unmergeable(struct kmem_cache *s)
100714 /*
100715 * We may have set a slab to be unmergeable during bootstrap.
100716 */
100717 - if (s->refcount < 0)
100718 + if (atomic_read(&s->refcount) < 0)
100719 return 1;
100720
100721 return 0;
100722 @@ -3699,7 +3764,7 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
100723 int i;
100724 struct kmem_cache *c;
100725
100726 - s->refcount++;
100727 + atomic_inc(&s->refcount);
100728
100729 /*
100730 * Adjust the object sizes so that we clear
100731 @@ -3718,7 +3783,7 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
100732 }
100733
100734 if (sysfs_slab_alias(s, name)) {
100735 - s->refcount--;
100736 + atomic_dec(&s->refcount);
100737 s = NULL;
100738 }
100739 }
100740 @@ -3835,7 +3900,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
100741 }
100742 #endif
100743
100744 -#ifdef CONFIG_SYSFS
100745 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
100746 static int count_inuse(struct page *page)
100747 {
100748 return page->inuse;
100749 @@ -4116,7 +4181,11 @@ static int list_locations(struct kmem_cache *s, char *buf,
100750 len += sprintf(buf + len, "%7ld ", l->count);
100751
100752 if (l->addr)
100753 +#ifdef CONFIG_GRKERNSEC_HIDESYM
100754 + len += sprintf(buf + len, "%pS", NULL);
100755 +#else
100756 len += sprintf(buf + len, "%pS", (void *)l->addr);
100757 +#endif
100758 else
100759 len += sprintf(buf + len, "<not-available>");
100760
100761 @@ -4218,12 +4287,12 @@ static void __init resiliency_test(void)
100762 validate_slab_cache(kmalloc_caches[9]);
100763 }
100764 #else
100765 -#ifdef CONFIG_SYSFS
100766 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
100767 static void resiliency_test(void) {};
100768 #endif
100769 #endif
100770
100771 -#ifdef CONFIG_SYSFS
100772 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
100773 enum slab_stat_type {
100774 SL_ALL, /* All slabs */
100775 SL_PARTIAL, /* Only partially allocated slabs */
100776 @@ -4460,13 +4529,17 @@ static ssize_t ctor_show(struct kmem_cache *s, char *buf)
100777 {
100778 if (!s->ctor)
100779 return 0;
100780 +#ifdef CONFIG_GRKERNSEC_HIDESYM
100781 + return sprintf(buf, "%pS\n", NULL);
100782 +#else
100783 return sprintf(buf, "%pS\n", s->ctor);
100784 +#endif
100785 }
100786 SLAB_ATTR_RO(ctor);
100787
100788 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
100789 {
100790 - return sprintf(buf, "%d\n", s->refcount < 0 ? 0 : s->refcount - 1);
100791 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) < 0 ? 0 : atomic_read(&s->refcount) - 1);
100792 }
100793 SLAB_ATTR_RO(aliases);
100794
100795 @@ -4554,6 +4627,22 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
100796 SLAB_ATTR_RO(cache_dma);
100797 #endif
100798
100799 +#ifdef CONFIG_PAX_USERCOPY_SLABS
100800 +static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
100801 +{
100802 + return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
100803 +}
100804 +SLAB_ATTR_RO(usercopy);
100805 +#endif
100806 +
100807 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
100808 +static ssize_t sanitize_show(struct kmem_cache *s, char *buf)
100809 +{
100810 + return sprintf(buf, "%d\n", !(s->flags & SLAB_NO_SANITIZE));
100811 +}
100812 +SLAB_ATTR_RO(sanitize);
100813 +#endif
100814 +
100815 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
100816 {
100817 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
100818 @@ -4888,6 +4977,12 @@ static struct attribute *slab_attrs[] = {
100819 #ifdef CONFIG_ZONE_DMA
100820 &cache_dma_attr.attr,
100821 #endif
100822 +#ifdef CONFIG_PAX_USERCOPY_SLABS
100823 + &usercopy_attr.attr,
100824 +#endif
100825 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
100826 + &sanitize_attr.attr,
100827 +#endif
100828 #ifdef CONFIG_NUMA
100829 &remote_node_defrag_ratio_attr.attr,
100830 #endif
100831 @@ -5132,6 +5227,7 @@ static char *create_unique_id(struct kmem_cache *s)
100832 return name;
100833 }
100834
100835 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
100836 static int sysfs_slab_add(struct kmem_cache *s)
100837 {
100838 int err;
100839 @@ -5205,6 +5301,7 @@ void sysfs_slab_remove(struct kmem_cache *s)
100840 kobject_del(&s->kobj);
100841 kobject_put(&s->kobj);
100842 }
100843 +#endif
100844
100845 /*
100846 * Need to buffer aliases during bootup until sysfs becomes
100847 @@ -5218,6 +5315,7 @@ struct saved_alias {
100848
100849 static struct saved_alias *alias_list;
100850
100851 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
100852 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
100853 {
100854 struct saved_alias *al;
100855 @@ -5240,6 +5338,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
100856 alias_list = al;
100857 return 0;
100858 }
100859 +#endif
100860
100861 static int __init slab_sysfs_init(void)
100862 {
100863 diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
100864 index 4cba9c2..b4f9fcc 100644
100865 --- a/mm/sparse-vmemmap.c
100866 +++ b/mm/sparse-vmemmap.c
100867 @@ -131,7 +131,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
100868 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
100869 if (!p)
100870 return NULL;
100871 - pud_populate(&init_mm, pud, p);
100872 + pud_populate_kernel(&init_mm, pud, p);
100873 }
100874 return pud;
100875 }
100876 @@ -143,7 +143,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
100877 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
100878 if (!p)
100879 return NULL;
100880 - pgd_populate(&init_mm, pgd, p);
100881 + pgd_populate_kernel(&init_mm, pgd, p);
100882 }
100883 return pgd;
100884 }
100885 diff --git a/mm/sparse.c b/mm/sparse.c
100886 index d1b48b6..6e8590e 100644
100887 --- a/mm/sparse.c
100888 +++ b/mm/sparse.c
100889 @@ -750,7 +750,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
100890
100891 for (i = 0; i < PAGES_PER_SECTION; i++) {
100892 if (PageHWPoison(&memmap[i])) {
100893 - atomic_long_sub(1, &num_poisoned_pages);
100894 + atomic_long_sub_unchecked(1, &num_poisoned_pages);
100895 ClearPageHWPoison(&memmap[i]);
100896 }
100897 }
100898 diff --git a/mm/swap.c b/mm/swap.c
100899 index 6b2dc38..46b79ba 100644
100900 --- a/mm/swap.c
100901 +++ b/mm/swap.c
100902 @@ -31,6 +31,7 @@
100903 #include <linux/memcontrol.h>
100904 #include <linux/gfp.h>
100905 #include <linux/uio.h>
100906 +#include <linux/hugetlb.h>
100907
100908 #include "internal.h"
100909
100910 @@ -77,6 +78,8 @@ static void __put_compound_page(struct page *page)
100911
100912 __page_cache_release(page);
100913 dtor = get_compound_page_dtor(page);
100914 + if (!PageHuge(page))
100915 + BUG_ON(dtor != free_compound_page);
100916 (*dtor)(page);
100917 }
100918
100919 diff --git a/mm/swapfile.c b/mm/swapfile.c
100920 index 8798b2e..348f9dd 100644
100921 --- a/mm/swapfile.c
100922 +++ b/mm/swapfile.c
100923 @@ -84,7 +84,7 @@ static DEFINE_MUTEX(swapon_mutex);
100924
100925 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
100926 /* Activity counter to indicate that a swapon or swapoff has occurred */
100927 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
100928 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
100929
100930 static inline unsigned char swap_count(unsigned char ent)
100931 {
100932 @@ -1944,7 +1944,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
100933 spin_unlock(&swap_lock);
100934
100935 err = 0;
100936 - atomic_inc(&proc_poll_event);
100937 + atomic_inc_unchecked(&proc_poll_event);
100938 wake_up_interruptible(&proc_poll_wait);
100939
100940 out_dput:
100941 @@ -1961,8 +1961,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
100942
100943 poll_wait(file, &proc_poll_wait, wait);
100944
100945 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
100946 - seq->poll_event = atomic_read(&proc_poll_event);
100947 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
100948 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
100949 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
100950 }
100951
100952 @@ -2060,7 +2060,7 @@ static int swaps_open(struct inode *inode, struct file *file)
100953 return ret;
100954
100955 seq = file->private_data;
100956 - seq->poll_event = atomic_read(&proc_poll_event);
100957 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
100958 return 0;
100959 }
100960
100961 @@ -2520,7 +2520,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
100962 (frontswap_map) ? "FS" : "");
100963
100964 mutex_unlock(&swapon_mutex);
100965 - atomic_inc(&proc_poll_event);
100966 + atomic_inc_unchecked(&proc_poll_event);
100967 wake_up_interruptible(&proc_poll_wait);
100968
100969 if (S_ISREG(inode->i_mode))
100970 diff --git a/mm/util.c b/mm/util.c
100971 index 093c973..b70a268 100644
100972 --- a/mm/util.c
100973 +++ b/mm/util.c
100974 @@ -202,6 +202,12 @@ done:
100975 void arch_pick_mmap_layout(struct mm_struct *mm)
100976 {
100977 mm->mmap_base = TASK_UNMAPPED_BASE;
100978 +
100979 +#ifdef CONFIG_PAX_RANDMMAP
100980 + if (mm->pax_flags & MF_PAX_RANDMMAP)
100981 + mm->mmap_base += mm->delta_mmap;
100982 +#endif
100983 +
100984 mm->get_unmapped_area = arch_get_unmapped_area;
100985 }
100986 #endif
100987 @@ -378,6 +384,9 @@ int get_cmdline(struct task_struct *task, char *buffer, int buflen)
100988 if (!mm->arg_end)
100989 goto out_mm; /* Shh! No looking before we're done */
100990
100991 + if (gr_acl_handle_procpidmem(task))
100992 + goto out_mm;
100993 +
100994 len = mm->arg_end - mm->arg_start;
100995
100996 if (len > buflen)
100997 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
100998 index 2b0aa54..b451f74 100644
100999 --- a/mm/vmalloc.c
101000 +++ b/mm/vmalloc.c
101001 @@ -40,6 +40,21 @@ struct vfree_deferred {
101002 };
101003 static DEFINE_PER_CPU(struct vfree_deferred, vfree_deferred);
101004
101005 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
101006 +struct stack_deferred_llist {
101007 + struct llist_head list;
101008 + void *stack;
101009 + void *lowmem_stack;
101010 +};
101011 +
101012 +struct stack_deferred {
101013 + struct stack_deferred_llist list;
101014 + struct work_struct wq;
101015 +};
101016 +
101017 +static DEFINE_PER_CPU(struct stack_deferred, stack_deferred);
101018 +#endif
101019 +
101020 static void __vunmap(const void *, int);
101021
101022 static void free_work(struct work_struct *w)
101023 @@ -47,12 +62,30 @@ static void free_work(struct work_struct *w)
101024 struct vfree_deferred *p = container_of(w, struct vfree_deferred, wq);
101025 struct llist_node *llnode = llist_del_all(&p->list);
101026 while (llnode) {
101027 - void *p = llnode;
101028 + void *x = llnode;
101029 llnode = llist_next(llnode);
101030 - __vunmap(p, 1);
101031 + __vunmap(x, 1);
101032 }
101033 }
101034
101035 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
101036 +static void unmap_work(struct work_struct *w)
101037 +{
101038 + struct stack_deferred *p = container_of(w, struct stack_deferred, wq);
101039 + struct llist_node *llnode = llist_del_all(&p->list.list);
101040 + while (llnode) {
101041 + struct stack_deferred_llist *x =
101042 + llist_entry((struct llist_head *)llnode,
101043 + struct stack_deferred_llist, list);
101044 + void *stack = ACCESS_ONCE(x->stack);
101045 + void *lowmem_stack = ACCESS_ONCE(x->lowmem_stack);
101046 + llnode = llist_next(llnode);
101047 + __vunmap(stack, 0);
101048 + free_kmem_pages((unsigned long)lowmem_stack, THREAD_SIZE_ORDER);
101049 + }
101050 +}
101051 +#endif
101052 +
101053 /*** Page table manipulation functions ***/
101054
101055 static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
101056 @@ -61,8 +94,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
101057
101058 pte = pte_offset_kernel(pmd, addr);
101059 do {
101060 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
101061 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
101062 +
101063 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
101064 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
101065 + BUG_ON(!pte_exec(*pte));
101066 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
101067 + continue;
101068 + }
101069 +#endif
101070 +
101071 + {
101072 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
101073 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
101074 + }
101075 } while (pte++, addr += PAGE_SIZE, addr != end);
101076 }
101077
101078 @@ -122,16 +166,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
101079 pte = pte_alloc_kernel(pmd, addr);
101080 if (!pte)
101081 return -ENOMEM;
101082 +
101083 + pax_open_kernel();
101084 do {
101085 struct page *page = pages[*nr];
101086
101087 - if (WARN_ON(!pte_none(*pte)))
101088 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
101089 + if (pgprot_val(prot) & _PAGE_NX)
101090 +#endif
101091 +
101092 + if (!pte_none(*pte)) {
101093 + pax_close_kernel();
101094 + WARN_ON(1);
101095 return -EBUSY;
101096 - if (WARN_ON(!page))
101097 + }
101098 + if (!page) {
101099 + pax_close_kernel();
101100 + WARN_ON(1);
101101 return -ENOMEM;
101102 + }
101103 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
101104 (*nr)++;
101105 } while (pte++, addr += PAGE_SIZE, addr != end);
101106 + pax_close_kernel();
101107 return 0;
101108 }
101109
101110 @@ -141,7 +198,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
101111 pmd_t *pmd;
101112 unsigned long next;
101113
101114 - pmd = pmd_alloc(&init_mm, pud, addr);
101115 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
101116 if (!pmd)
101117 return -ENOMEM;
101118 do {
101119 @@ -158,7 +215,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
101120 pud_t *pud;
101121 unsigned long next;
101122
101123 - pud = pud_alloc(&init_mm, pgd, addr);
101124 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
101125 if (!pud)
101126 return -ENOMEM;
101127 do {
101128 @@ -218,6 +275,12 @@ int is_vmalloc_or_module_addr(const void *x)
101129 if (addr >= MODULES_VADDR && addr < MODULES_END)
101130 return 1;
101131 #endif
101132 +
101133 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
101134 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
101135 + return 1;
101136 +#endif
101137 +
101138 return is_vmalloc_addr(x);
101139 }
101140
101141 @@ -238,8 +301,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
101142
101143 if (!pgd_none(*pgd)) {
101144 pud_t *pud = pud_offset(pgd, addr);
101145 +#ifdef CONFIG_X86
101146 + if (!pud_large(*pud))
101147 +#endif
101148 if (!pud_none(*pud)) {
101149 pmd_t *pmd = pmd_offset(pud, addr);
101150 +#ifdef CONFIG_X86
101151 + if (!pmd_large(*pmd))
101152 +#endif
101153 if (!pmd_none(*pmd)) {
101154 pte_t *ptep, pte;
101155
101156 @@ -1183,13 +1252,23 @@ void __init vmalloc_init(void)
101157 for_each_possible_cpu(i) {
101158 struct vmap_block_queue *vbq;
101159 struct vfree_deferred *p;
101160 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
101161 + struct stack_deferred *p2;
101162 +#endif
101163
101164 vbq = &per_cpu(vmap_block_queue, i);
101165 spin_lock_init(&vbq->lock);
101166 INIT_LIST_HEAD(&vbq->free);
101167 +
101168 p = &per_cpu(vfree_deferred, i);
101169 init_llist_head(&p->list);
101170 INIT_WORK(&p->wq, free_work);
101171 +
101172 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
101173 + p2 = &per_cpu(stack_deferred, i);
101174 + init_llist_head(&p2->list.list);
101175 + INIT_WORK(&p2->wq, unmap_work);
101176 +#endif
101177 }
101178
101179 /* Import existing vmlist entries. */
101180 @@ -1314,6 +1393,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
101181 struct vm_struct *area;
101182
101183 BUG_ON(in_interrupt());
101184 +
101185 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
101186 + if (flags & VM_KERNEXEC) {
101187 + if (start != VMALLOC_START || end != VMALLOC_END)
101188 + return NULL;
101189 + start = (unsigned long)MODULES_EXEC_VADDR;
101190 + end = (unsigned long)MODULES_EXEC_END;
101191 + }
101192 +#endif
101193 +
101194 if (flags & VM_IOREMAP)
101195 align = 1ul << clamp(fls(size), PAGE_SHIFT, IOREMAP_MAX_ORDER);
101196
101197 @@ -1519,6 +1608,23 @@ void vunmap(const void *addr)
101198 }
101199 EXPORT_SYMBOL(vunmap);
101200
101201 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
101202 +void unmap_process_stacks(struct task_struct *task)
101203 +{
101204 + if (unlikely(in_interrupt())) {
101205 + struct stack_deferred *p = &__get_cpu_var(stack_deferred);
101206 + struct stack_deferred_llist *list = task->stack;
101207 + list->stack = task->stack;
101208 + list->lowmem_stack = task->lowmem_stack;
101209 + if (llist_add((struct llist_node *)&list->list, &p->list.list))
101210 + schedule_work(&p->wq);
101211 + } else {
101212 + __vunmap(task->stack, 0);
101213 + free_kmem_pages((unsigned long)task->lowmem_stack, THREAD_SIZE_ORDER);
101214 + }
101215 +}
101216 +#endif
101217 +
101218 /**
101219 * vmap - map an array of pages into virtually contiguous space
101220 * @pages: array of page pointers
101221 @@ -1539,6 +1645,11 @@ void *vmap(struct page **pages, unsigned int count,
101222 if (count > totalram_pages)
101223 return NULL;
101224
101225 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
101226 + if (!(pgprot_val(prot) & _PAGE_NX))
101227 + flags |= VM_KERNEXEC;
101228 +#endif
101229 +
101230 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
101231 __builtin_return_address(0));
101232 if (!area)
101233 @@ -1641,6 +1752,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
101234 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
101235 goto fail;
101236
101237 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
101238 + if (!(pgprot_val(prot) & _PAGE_NX))
101239 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | VM_KERNEXEC,
101240 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
101241 + else
101242 +#endif
101243 +
101244 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED,
101245 start, end, node, gfp_mask, caller);
101246 if (!area)
101247 @@ -1817,10 +1935,9 @@ EXPORT_SYMBOL(vzalloc_node);
101248 * For tight control over page level allocator and protection flags
101249 * use __vmalloc() instead.
101250 */
101251 -
101252 void *vmalloc_exec(unsigned long size)
101253 {
101254 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
101255 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
101256 NUMA_NO_NODE, __builtin_return_address(0));
101257 }
101258
101259 @@ -2127,6 +2244,8 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
101260 {
101261 struct vm_struct *area;
101262
101263 + BUG_ON(vma->vm_mirror);
101264 +
101265 size = PAGE_ALIGN(size);
101266
101267 if (!PAGE_ALIGNED(uaddr) || !PAGE_ALIGNED(kaddr))
101268 @@ -2609,7 +2728,11 @@ static int s_show(struct seq_file *m, void *p)
101269 v->addr, v->addr + v->size, v->size);
101270
101271 if (v->caller)
101272 +#ifdef CONFIG_GRKERNSEC_HIDESYM
101273 + seq_printf(m, " %pK", v->caller);
101274 +#else
101275 seq_printf(m, " %pS", v->caller);
101276 +#endif
101277
101278 if (v->nr_pages)
101279 seq_printf(m, " pages=%d", v->nr_pages);
101280 diff --git a/mm/vmstat.c b/mm/vmstat.c
101281 index e9ab104..de275bd 100644
101282 --- a/mm/vmstat.c
101283 +++ b/mm/vmstat.c
101284 @@ -20,6 +20,7 @@
101285 #include <linux/writeback.h>
101286 #include <linux/compaction.h>
101287 #include <linux/mm_inline.h>
101288 +#include <linux/grsecurity.h>
101289
101290 #include "internal.h"
101291
101292 @@ -79,7 +80,7 @@ void vm_events_fold_cpu(int cpu)
101293 *
101294 * vm_stat contains the global counters
101295 */
101296 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
101297 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
101298 EXPORT_SYMBOL(vm_stat);
101299
101300 #ifdef CONFIG_SMP
101301 @@ -425,7 +426,7 @@ static inline void fold_diff(int *diff)
101302
101303 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
101304 if (diff[i])
101305 - atomic_long_add(diff[i], &vm_stat[i]);
101306 + atomic_long_add_unchecked(diff[i], &vm_stat[i]);
101307 }
101308
101309 /*
101310 @@ -457,7 +458,7 @@ static void refresh_cpu_vm_stats(void)
101311 v = this_cpu_xchg(p->vm_stat_diff[i], 0);
101312 if (v) {
101313
101314 - atomic_long_add(v, &zone->vm_stat[i]);
101315 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
101316 global_diff[i] += v;
101317 #ifdef CONFIG_NUMA
101318 /* 3 seconds idle till flush */
101319 @@ -519,7 +520,7 @@ void cpu_vm_stats_fold(int cpu)
101320
101321 v = p->vm_stat_diff[i];
101322 p->vm_stat_diff[i] = 0;
101323 - atomic_long_add(v, &zone->vm_stat[i]);
101324 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
101325 global_diff[i] += v;
101326 }
101327 }
101328 @@ -539,8 +540,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
101329 if (pset->vm_stat_diff[i]) {
101330 int v = pset->vm_stat_diff[i];
101331 pset->vm_stat_diff[i] = 0;
101332 - atomic_long_add(v, &zone->vm_stat[i]);
101333 - atomic_long_add(v, &vm_stat[i]);
101334 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
101335 + atomic_long_add_unchecked(v, &vm_stat[i]);
101336 }
101337 }
101338 #endif
101339 @@ -1163,10 +1164,22 @@ static void *vmstat_start(struct seq_file *m, loff_t *pos)
101340 stat_items_size += sizeof(struct vm_event_state);
101341 #endif
101342
101343 - v = kmalloc(stat_items_size, GFP_KERNEL);
101344 + v = kzalloc(stat_items_size, GFP_KERNEL);
101345 m->private = v;
101346 if (!v)
101347 return ERR_PTR(-ENOMEM);
101348 +
101349 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
101350 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
101351 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
101352 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
101353 + && !in_group_p(grsec_proc_gid)
101354 +#endif
101355 + )
101356 + return (unsigned long *)m->private + *pos;
101357 +#endif
101358 +#endif
101359 +
101360 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
101361 v[i] = global_page_state(i);
101362 v += NR_VM_ZONE_STAT_ITEMS;
101363 @@ -1315,10 +1328,16 @@ static int __init setup_vmstat(void)
101364 cpu_notifier_register_done();
101365 #endif
101366 #ifdef CONFIG_PROC_FS
101367 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
101368 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
101369 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
101370 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
101371 + {
101372 + mode_t gr_mode = S_IRUGO;
101373 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
101374 + gr_mode = S_IRUSR;
101375 +#endif
101376 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
101377 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
101378 + proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
101379 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
101380 + }
101381 #endif
101382 return 0;
101383 }
101384 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
101385 index 64c6bed..b79a5de 100644
101386 --- a/net/8021q/vlan.c
101387 +++ b/net/8021q/vlan.c
101388 @@ -481,7 +481,7 @@ out:
101389 return NOTIFY_DONE;
101390 }
101391
101392 -static struct notifier_block vlan_notifier_block __read_mostly = {
101393 +static struct notifier_block vlan_notifier_block = {
101394 .notifier_call = vlan_device_event,
101395 };
101396
101397 @@ -556,8 +556,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
101398 err = -EPERM;
101399 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
101400 break;
101401 - if ((args.u.name_type >= 0) &&
101402 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
101403 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
101404 struct vlan_net *vn;
101405
101406 vn = net_generic(net, vlan_net_id);
101407 diff --git a/net/8021q/vlan_netlink.c b/net/8021q/vlan_netlink.c
101408 index 8ac8a5c..991defc 100644
101409 --- a/net/8021q/vlan_netlink.c
101410 +++ b/net/8021q/vlan_netlink.c
101411 @@ -238,7 +238,7 @@ nla_put_failure:
101412 return -EMSGSIZE;
101413 }
101414
101415 -struct rtnl_link_ops vlan_link_ops __read_mostly = {
101416 +struct rtnl_link_ops vlan_link_ops = {
101417 .kind = "vlan",
101418 .maxtype = IFLA_VLAN_MAX,
101419 .policy = vlan_policy,
101420 diff --git a/net/9p/client.c b/net/9p/client.c
101421 index e86a9bea..e91f70e 100644
101422 --- a/net/9p/client.c
101423 +++ b/net/9p/client.c
101424 @@ -596,7 +596,7 @@ static int p9_check_zc_errors(struct p9_client *c, struct p9_req_t *req,
101425 len - inline_len);
101426 } else {
101427 err = copy_from_user(ename + inline_len,
101428 - uidata, len - inline_len);
101429 + (char __force_user *)uidata, len - inline_len);
101430 if (err) {
101431 err = -EFAULT;
101432 goto out_err;
101433 @@ -1570,7 +1570,7 @@ p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
101434 kernel_buf = 1;
101435 indata = data;
101436 } else
101437 - indata = (__force char *)udata;
101438 + indata = (__force_kernel char *)udata;
101439 /*
101440 * response header len is 11
101441 * PDU Header(7) + IO Size (4)
101442 @@ -1645,7 +1645,7 @@ p9_client_write(struct p9_fid *fid, char *data, const char __user *udata,
101443 kernel_buf = 1;
101444 odata = data;
101445 } else
101446 - odata = (char *)udata;
101447 + odata = (char __force_kernel *)udata;
101448 req = p9_client_zc_rpc(clnt, P9_TWRITE, NULL, odata, 0, rsize,
101449 P9_ZC_HDR_SZ, kernel_buf, "dqd",
101450 fid->fid, offset, rsize);
101451 diff --git a/net/9p/mod.c b/net/9p/mod.c
101452 index 6ab36ae..6f1841b 100644
101453 --- a/net/9p/mod.c
101454 +++ b/net/9p/mod.c
101455 @@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
101456 void v9fs_register_trans(struct p9_trans_module *m)
101457 {
101458 spin_lock(&v9fs_trans_lock);
101459 - list_add_tail(&m->list, &v9fs_trans_list);
101460 + pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
101461 spin_unlock(&v9fs_trans_lock);
101462 }
101463 EXPORT_SYMBOL(v9fs_register_trans);
101464 @@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
101465 void v9fs_unregister_trans(struct p9_trans_module *m)
101466 {
101467 spin_lock(&v9fs_trans_lock);
101468 - list_del_init(&m->list);
101469 + pax_list_del_init((struct list_head *)&m->list);
101470 spin_unlock(&v9fs_trans_lock);
101471 }
101472 EXPORT_SYMBOL(v9fs_unregister_trans);
101473 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
101474 index 80d08f6..de63fd1 100644
101475 --- a/net/9p/trans_fd.c
101476 +++ b/net/9p/trans_fd.c
101477 @@ -428,7 +428,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
101478 oldfs = get_fs();
101479 set_fs(get_ds());
101480 /* The cast to a user pointer is valid due to the set_fs() */
101481 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
101482 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
101483 set_fs(oldfs);
101484
101485 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
101486 diff --git a/net/appletalk/atalk_proc.c b/net/appletalk/atalk_proc.c
101487 index af46bc4..f9adfcd 100644
101488 --- a/net/appletalk/atalk_proc.c
101489 +++ b/net/appletalk/atalk_proc.c
101490 @@ -256,7 +256,7 @@ int __init atalk_proc_init(void)
101491 struct proc_dir_entry *p;
101492 int rc = -ENOMEM;
101493
101494 - atalk_proc_dir = proc_mkdir("atalk", init_net.proc_net);
101495 + atalk_proc_dir = proc_mkdir_restrict("atalk", init_net.proc_net);
101496 if (!atalk_proc_dir)
101497 goto out;
101498
101499 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
101500 index 876fbe8..8bbea9f 100644
101501 --- a/net/atm/atm_misc.c
101502 +++ b/net/atm/atm_misc.c
101503 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
101504 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
101505 return 1;
101506 atm_return(vcc, truesize);
101507 - atomic_inc(&vcc->stats->rx_drop);
101508 + atomic_inc_unchecked(&vcc->stats->rx_drop);
101509 return 0;
101510 }
101511 EXPORT_SYMBOL(atm_charge);
101512 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
101513 }
101514 }
101515 atm_return(vcc, guess);
101516 - atomic_inc(&vcc->stats->rx_drop);
101517 + atomic_inc_unchecked(&vcc->stats->rx_drop);
101518 return NULL;
101519 }
101520 EXPORT_SYMBOL(atm_alloc_charge);
101521 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
101522
101523 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
101524 {
101525 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
101526 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
101527 __SONET_ITEMS
101528 #undef __HANDLE_ITEM
101529 }
101530 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
101531
101532 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
101533 {
101534 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
101535 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
101536 __SONET_ITEMS
101537 #undef __HANDLE_ITEM
101538 }
101539 diff --git a/net/atm/lec.c b/net/atm/lec.c
101540 index 4b98f89..5a2f6cb 100644
101541 --- a/net/atm/lec.c
101542 +++ b/net/atm/lec.c
101543 @@ -111,9 +111,9 @@ static inline void lec_arp_put(struct lec_arp_table *entry)
101544 }
101545
101546 static struct lane2_ops lane2_ops = {
101547 - lane2_resolve, /* resolve, spec 3.1.3 */
101548 - lane2_associate_req, /* associate_req, spec 3.1.4 */
101549 - NULL /* associate indicator, spec 3.1.5 */
101550 + .resolve = lane2_resolve,
101551 + .associate_req = lane2_associate_req,
101552 + .associate_indicator = NULL
101553 };
101554
101555 static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
101556 diff --git a/net/atm/lec.h b/net/atm/lec.h
101557 index 4149db1..f2ab682 100644
101558 --- a/net/atm/lec.h
101559 +++ b/net/atm/lec.h
101560 @@ -48,7 +48,7 @@ struct lane2_ops {
101561 const u8 *tlvs, u32 sizeoftlvs);
101562 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
101563 const u8 *tlvs, u32 sizeoftlvs);
101564 -};
101565 +} __no_const;
101566
101567 /*
101568 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
101569 diff --git a/net/atm/mpoa_caches.c b/net/atm/mpoa_caches.c
101570 index d1b2d9a..d549f7f 100644
101571 --- a/net/atm/mpoa_caches.c
101572 +++ b/net/atm/mpoa_caches.c
101573 @@ -535,30 +535,30 @@ static void eg_destroy_cache(struct mpoa_client *mpc)
101574
101575
101576 static struct in_cache_ops ingress_ops = {
101577 - in_cache_add_entry, /* add_entry */
101578 - in_cache_get, /* get */
101579 - in_cache_get_with_mask, /* get_with_mask */
101580 - in_cache_get_by_vcc, /* get_by_vcc */
101581 - in_cache_put, /* put */
101582 - in_cache_remove_entry, /* remove_entry */
101583 - cache_hit, /* cache_hit */
101584 - clear_count_and_expired, /* clear_count */
101585 - check_resolving_entries, /* check_resolving */
101586 - refresh_entries, /* refresh */
101587 - in_destroy_cache /* destroy_cache */
101588 + .add_entry = in_cache_add_entry,
101589 + .get = in_cache_get,
101590 + .get_with_mask = in_cache_get_with_mask,
101591 + .get_by_vcc = in_cache_get_by_vcc,
101592 + .put = in_cache_put,
101593 + .remove_entry = in_cache_remove_entry,
101594 + .cache_hit = cache_hit,
101595 + .clear_count = clear_count_and_expired,
101596 + .check_resolving = check_resolving_entries,
101597 + .refresh = refresh_entries,
101598 + .destroy_cache = in_destroy_cache
101599 };
101600
101601 static struct eg_cache_ops egress_ops = {
101602 - eg_cache_add_entry, /* add_entry */
101603 - eg_cache_get_by_cache_id, /* get_by_cache_id */
101604 - eg_cache_get_by_tag, /* get_by_tag */
101605 - eg_cache_get_by_vcc, /* get_by_vcc */
101606 - eg_cache_get_by_src_ip, /* get_by_src_ip */
101607 - eg_cache_put, /* put */
101608 - eg_cache_remove_entry, /* remove_entry */
101609 - update_eg_cache_entry, /* update */
101610 - clear_expired, /* clear_expired */
101611 - eg_destroy_cache /* destroy_cache */
101612 + .add_entry = eg_cache_add_entry,
101613 + .get_by_cache_id = eg_cache_get_by_cache_id,
101614 + .get_by_tag = eg_cache_get_by_tag,
101615 + .get_by_vcc = eg_cache_get_by_vcc,
101616 + .get_by_src_ip = eg_cache_get_by_src_ip,
101617 + .put = eg_cache_put,
101618 + .remove_entry = eg_cache_remove_entry,
101619 + .update = update_eg_cache_entry,
101620 + .clear_expired = clear_expired,
101621 + .destroy_cache = eg_destroy_cache
101622 };
101623
101624
101625 diff --git a/net/atm/proc.c b/net/atm/proc.c
101626 index bbb6461..cf04016 100644
101627 --- a/net/atm/proc.c
101628 +++ b/net/atm/proc.c
101629 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
101630 const struct k_atm_aal_stats *stats)
101631 {
101632 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
101633 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
101634 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
101635 - atomic_read(&stats->rx_drop));
101636 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
101637 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
101638 + atomic_read_unchecked(&stats->rx_drop));
101639 }
101640
101641 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
101642 diff --git a/net/atm/resources.c b/net/atm/resources.c
101643 index 0447d5d..3cf4728 100644
101644 --- a/net/atm/resources.c
101645 +++ b/net/atm/resources.c
101646 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
101647 static void copy_aal_stats(struct k_atm_aal_stats *from,
101648 struct atm_aal_stats *to)
101649 {
101650 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
101651 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
101652 __AAL_STAT_ITEMS
101653 #undef __HANDLE_ITEM
101654 }
101655 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
101656 static void subtract_aal_stats(struct k_atm_aal_stats *from,
101657 struct atm_aal_stats *to)
101658 {
101659 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
101660 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
101661 __AAL_STAT_ITEMS
101662 #undef __HANDLE_ITEM
101663 }
101664 diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
101665 index 919a5ce..cc6b444 100644
101666 --- a/net/ax25/sysctl_net_ax25.c
101667 +++ b/net/ax25/sysctl_net_ax25.c
101668 @@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
101669 {
101670 char path[sizeof("net/ax25/") + IFNAMSIZ];
101671 int k;
101672 - struct ctl_table *table;
101673 + ctl_table_no_const *table;
101674
101675 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
101676 if (!table)
101677 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
101678 index 1e80539..676c37a 100644
101679 --- a/net/batman-adv/bat_iv_ogm.c
101680 +++ b/net/batman-adv/bat_iv_ogm.c
101681 @@ -313,7 +313,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
101682
101683 /* randomize initial seqno to avoid collision */
101684 get_random_bytes(&random_seqno, sizeof(random_seqno));
101685 - atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
101686 + atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
101687
101688 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
101689 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
101690 @@ -918,9 +918,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
101691 batadv_ogm_packet->tvlv_len = htons(tvlv_len);
101692
101693 /* change sequence number to network order */
101694 - seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
101695 + seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
101696 batadv_ogm_packet->seqno = htonl(seqno);
101697 - atomic_inc(&hard_iface->bat_iv.ogm_seqno);
101698 + atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
101699
101700 batadv_iv_ogm_slide_own_bcast_window(hard_iface);
101701
101702 @@ -1597,7 +1597,7 @@ static void batadv_iv_ogm_process(const struct sk_buff *skb, int ogm_offset,
101703 return;
101704
101705 /* could be changed by schedule_own_packet() */
101706 - if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
101707 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
101708
101709 if (ogm_packet->flags & BATADV_DIRECTLINK)
101710 has_directlink_flag = true;
101711 diff --git a/net/batman-adv/fragmentation.c b/net/batman-adv/fragmentation.c
101712 index fc1835c..eead856 100644
101713 --- a/net/batman-adv/fragmentation.c
101714 +++ b/net/batman-adv/fragmentation.c
101715 @@ -450,7 +450,7 @@ bool batadv_frag_send_packet(struct sk_buff *skb,
101716 frag_header.packet_type = BATADV_UNICAST_FRAG;
101717 frag_header.version = BATADV_COMPAT_VERSION;
101718 frag_header.ttl = BATADV_TTL;
101719 - frag_header.seqno = htons(atomic_inc_return(&bat_priv->frag_seqno));
101720 + frag_header.seqno = htons(atomic_inc_return_unchecked(&bat_priv->frag_seqno));
101721 frag_header.reserved = 0;
101722 frag_header.no = 0;
101723 frag_header.total_size = htons(skb->len);
101724 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
101725 index 5467955..75ad4e3 100644
101726 --- a/net/batman-adv/soft-interface.c
101727 +++ b/net/batman-adv/soft-interface.c
101728 @@ -296,7 +296,7 @@ send:
101729 primary_if->net_dev->dev_addr);
101730
101731 /* set broadcast sequence number */
101732 - seqno = atomic_inc_return(&bat_priv->bcast_seqno);
101733 + seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
101734 bcast_packet->seqno = htonl(seqno);
101735
101736 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
101737 @@ -761,7 +761,7 @@ static int batadv_softif_init_late(struct net_device *dev)
101738 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
101739
101740 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
101741 - atomic_set(&bat_priv->bcast_seqno, 1);
101742 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
101743 atomic_set(&bat_priv->tt.vn, 0);
101744 atomic_set(&bat_priv->tt.local_changes, 0);
101745 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
101746 @@ -775,7 +775,7 @@ static int batadv_softif_init_late(struct net_device *dev)
101747
101748 /* randomize initial seqno to avoid collision */
101749 get_random_bytes(&random_seqno, sizeof(random_seqno));
101750 - atomic_set(&bat_priv->frag_seqno, random_seqno);
101751 + atomic_set_unchecked(&bat_priv->frag_seqno, random_seqno);
101752
101753 bat_priv->primary_if = NULL;
101754 bat_priv->num_ifaces = 0;
101755 @@ -983,7 +983,7 @@ int batadv_softif_is_valid(const struct net_device *net_dev)
101756 return 0;
101757 }
101758
101759 -struct rtnl_link_ops batadv_link_ops __read_mostly = {
101760 +struct rtnl_link_ops batadv_link_ops = {
101761 .kind = "batadv",
101762 .priv_size = sizeof(struct batadv_priv),
101763 .setup = batadv_softif_init_early,
101764 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
101765 index 8854c05..ee5d5497 100644
101766 --- a/net/batman-adv/types.h
101767 +++ b/net/batman-adv/types.h
101768 @@ -67,7 +67,7 @@ enum batadv_dhcp_recipient {
101769 struct batadv_hard_iface_bat_iv {
101770 unsigned char *ogm_buff;
101771 int ogm_buff_len;
101772 - atomic_t ogm_seqno;
101773 + atomic_unchecked_t ogm_seqno;
101774 };
101775
101776 /**
101777 @@ -768,7 +768,7 @@ struct batadv_priv {
101778 atomic_t bonding;
101779 atomic_t fragmentation;
101780 atomic_t packet_size_max;
101781 - atomic_t frag_seqno;
101782 + atomic_unchecked_t frag_seqno;
101783 #ifdef CONFIG_BATMAN_ADV_BLA
101784 atomic_t bridge_loop_avoidance;
101785 #endif
101786 @@ -787,7 +787,7 @@ struct batadv_priv {
101787 #endif
101788 uint32_t isolation_mark;
101789 uint32_t isolation_mark_mask;
101790 - atomic_t bcast_seqno;
101791 + atomic_unchecked_t bcast_seqno;
101792 atomic_t bcast_queue_left;
101793 atomic_t batman_queue_left;
101794 char num_ifaces;
101795 diff --git a/net/bluetooth/6lowpan.c b/net/bluetooth/6lowpan.c
101796 index 075f20d..62972c9 100644
101797 --- a/net/bluetooth/6lowpan.c
101798 +++ b/net/bluetooth/6lowpan.c
101799 @@ -367,7 +367,6 @@ static int recv_pkt(struct sk_buff *skb, struct net_device *dev,
101800
101801 drop:
101802 dev->stats.rx_dropped++;
101803 - kfree_skb(skb);
101804 return NET_RX_DROP;
101805 }
101806
101807 diff --git a/net/bluetooth/bnep/core.c b/net/bluetooth/bnep/core.c
101808 index 85bcc21..ce82722d 100644
101809 --- a/net/bluetooth/bnep/core.c
101810 +++ b/net/bluetooth/bnep/core.c
101811 @@ -533,6 +533,9 @@ int bnep_add_connection(struct bnep_connadd_req *req, struct socket *sock)
101812
101813 BT_DBG("");
101814
101815 + if (!l2cap_is_socket(sock))
101816 + return -EBADFD;
101817 +
101818 baswap((void *) dst, &l2cap_pi(sock->sk)->chan->dst);
101819 baswap((void *) src, &l2cap_pi(sock->sk)->chan->src);
101820
101821 diff --git a/net/bluetooth/cmtp/core.c b/net/bluetooth/cmtp/core.c
101822 index 67fe5e8..278a194 100644
101823 --- a/net/bluetooth/cmtp/core.c
101824 +++ b/net/bluetooth/cmtp/core.c
101825 @@ -334,6 +334,9 @@ int cmtp_add_connection(struct cmtp_connadd_req *req, struct socket *sock)
101826
101827 BT_DBG("");
101828
101829 + if (!l2cap_is_socket(sock))
101830 + return -EBADFD;
101831 +
101832 session = kzalloc(sizeof(struct cmtp_session), GFP_KERNEL);
101833 if (!session)
101834 return -ENOMEM;
101835 diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
101836 index 115f149..f0ba286 100644
101837 --- a/net/bluetooth/hci_sock.c
101838 +++ b/net/bluetooth/hci_sock.c
101839 @@ -1067,7 +1067,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
101840 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
101841 }
101842
101843 - len = min_t(unsigned int, len, sizeof(uf));
101844 + len = min((size_t)len, sizeof(uf));
101845 if (copy_from_user(&uf, optval, len)) {
101846 err = -EFAULT;
101847 break;
101848 diff --git a/net/bluetooth/hidp/core.c b/net/bluetooth/hidp/core.c
101849 index 6c7ecf1..cf765c7 100644
101850 --- a/net/bluetooth/hidp/core.c
101851 +++ b/net/bluetooth/hidp/core.c
101852 @@ -1318,13 +1318,14 @@ int hidp_connection_add(struct hidp_connadd_req *req,
101853 {
101854 struct hidp_session *session;
101855 struct l2cap_conn *conn;
101856 - struct l2cap_chan *chan = l2cap_pi(ctrl_sock->sk)->chan;
101857 + struct l2cap_chan *chan;
101858 int ret;
101859
101860 ret = hidp_verify_sockets(ctrl_sock, intr_sock);
101861 if (ret)
101862 return ret;
101863
101864 + chan = l2cap_pi(ctrl_sock->sk)->chan;
101865 conn = NULL;
101866 l2cap_chan_lock(chan);
101867 if (chan->conn) {
101868 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
101869 index 14ca8ae..262d49a 100644
101870 --- a/net/bluetooth/l2cap_core.c
101871 +++ b/net/bluetooth/l2cap_core.c
101872 @@ -3565,8 +3565,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
101873 break;
101874
101875 case L2CAP_CONF_RFC:
101876 - if (olen == sizeof(rfc))
101877 - memcpy(&rfc, (void *)val, olen);
101878 + if (olen != sizeof(rfc))
101879 + break;
101880 +
101881 + memcpy(&rfc, (void *)val, olen);
101882
101883 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
101884 rfc.mode != chan->mode)
101885 diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
101886 index 1884f72..b3b71f9 100644
101887 --- a/net/bluetooth/l2cap_sock.c
101888 +++ b/net/bluetooth/l2cap_sock.c
101889 @@ -629,7 +629,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
101890 struct sock *sk = sock->sk;
101891 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
101892 struct l2cap_options opts;
101893 - int len, err = 0;
101894 + int err = 0;
101895 + size_t len = optlen;
101896 u32 opt;
101897
101898 BT_DBG("sk %p", sk);
101899 @@ -656,7 +657,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
101900 opts.max_tx = chan->max_tx;
101901 opts.txwin_size = chan->tx_win;
101902
101903 - len = min_t(unsigned int, sizeof(opts), optlen);
101904 + len = min(sizeof(opts), len);
101905 if (copy_from_user((char *) &opts, optval, len)) {
101906 err = -EFAULT;
101907 break;
101908 @@ -743,7 +744,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
101909 struct bt_security sec;
101910 struct bt_power pwr;
101911 struct l2cap_conn *conn;
101912 - int len, err = 0;
101913 + int err = 0;
101914 + size_t len = optlen;
101915 u32 opt;
101916
101917 BT_DBG("sk %p", sk);
101918 @@ -767,7 +769,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
101919
101920 sec.level = BT_SECURITY_LOW;
101921
101922 - len = min_t(unsigned int, sizeof(sec), optlen);
101923 + len = min(sizeof(sec), len);
101924 if (copy_from_user((char *) &sec, optval, len)) {
101925 err = -EFAULT;
101926 break;
101927 @@ -862,7 +864,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
101928
101929 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
101930
101931 - len = min_t(unsigned int, sizeof(pwr), optlen);
101932 + len = min(sizeof(pwr), len);
101933 if (copy_from_user((char *) &pwr, optval, len)) {
101934 err = -EFAULT;
101935 break;
101936 diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
101937 index 8bbbb5e..6fc0950 100644
101938 --- a/net/bluetooth/rfcomm/sock.c
101939 +++ b/net/bluetooth/rfcomm/sock.c
101940 @@ -687,7 +687,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
101941 struct sock *sk = sock->sk;
101942 struct bt_security sec;
101943 int err = 0;
101944 - size_t len;
101945 + size_t len = optlen;
101946 u32 opt;
101947
101948 BT_DBG("sk %p", sk);
101949 @@ -709,7 +709,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
101950
101951 sec.level = BT_SECURITY_LOW;
101952
101953 - len = min_t(unsigned int, sizeof(sec), optlen);
101954 + len = min(sizeof(sec), len);
101955 if (copy_from_user((char *) &sec, optval, len)) {
101956 err = -EFAULT;
101957 break;
101958 diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
101959 index 8e385a0..a5bdd8e 100644
101960 --- a/net/bluetooth/rfcomm/tty.c
101961 +++ b/net/bluetooth/rfcomm/tty.c
101962 @@ -752,7 +752,7 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
101963 BT_DBG("tty %p id %d", tty, tty->index);
101964
101965 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
101966 - dev->channel, dev->port.count);
101967 + dev->channel, atomic_read(&dev->port.count));
101968
101969 err = tty_port_open(&dev->port, tty, filp);
101970 if (err)
101971 @@ -775,7 +775,7 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
101972 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
101973
101974 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
101975 - dev->port.count);
101976 + atomic_read(&dev->port.count));
101977
101978 tty_port_close(&dev->port, tty, filp);
101979 }
101980 diff --git a/net/bridge/br_netlink.c b/net/bridge/br_netlink.c
101981 index cb5fcf6..ad0a1a5 100644
101982 --- a/net/bridge/br_netlink.c
101983 +++ b/net/bridge/br_netlink.c
101984 @@ -484,7 +484,7 @@ static struct rtnl_af_ops br_af_ops = {
101985 .get_link_af_size = br_get_link_af_size,
101986 };
101987
101988 -struct rtnl_link_ops br_link_ops __read_mostly = {
101989 +struct rtnl_link_ops br_link_ops = {
101990 .kind = "bridge",
101991 .priv_size = sizeof(struct net_bridge),
101992 .setup = br_dev_setup,
101993 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
101994 index 6d69631..b8fdc85 100644
101995 --- a/net/bridge/netfilter/ebtables.c
101996 +++ b/net/bridge/netfilter/ebtables.c
101997 @@ -1518,7 +1518,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
101998 tmp.valid_hooks = t->table->valid_hooks;
101999 }
102000 mutex_unlock(&ebt_mutex);
102001 - if (copy_to_user(user, &tmp, *len) != 0) {
102002 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
102003 BUGPRINT("c2u Didn't work\n");
102004 ret = -EFAULT;
102005 break;
102006 @@ -2324,7 +2324,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
102007 goto out;
102008 tmp.valid_hooks = t->valid_hooks;
102009
102010 - if (copy_to_user(user, &tmp, *len) != 0) {
102011 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
102012 ret = -EFAULT;
102013 break;
102014 }
102015 @@ -2335,7 +2335,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
102016 tmp.entries_size = t->table->entries_size;
102017 tmp.valid_hooks = t->table->valid_hooks;
102018
102019 - if (copy_to_user(user, &tmp, *len) != 0) {
102020 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
102021 ret = -EFAULT;
102022 break;
102023 }
102024 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
102025 index f5afda1..dcf770a 100644
102026 --- a/net/caif/cfctrl.c
102027 +++ b/net/caif/cfctrl.c
102028 @@ -10,6 +10,7 @@
102029 #include <linux/spinlock.h>
102030 #include <linux/slab.h>
102031 #include <linux/pkt_sched.h>
102032 +#include <linux/sched.h>
102033 #include <net/caif/caif_layer.h>
102034 #include <net/caif/cfpkt.h>
102035 #include <net/caif/cfctrl.h>
102036 @@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
102037 memset(&dev_info, 0, sizeof(dev_info));
102038 dev_info.id = 0xff;
102039 cfsrvl_init(&this->serv, 0, &dev_info, false);
102040 - atomic_set(&this->req_seq_no, 1);
102041 - atomic_set(&this->rsp_seq_no, 1);
102042 + atomic_set_unchecked(&this->req_seq_no, 1);
102043 + atomic_set_unchecked(&this->rsp_seq_no, 1);
102044 this->serv.layer.receive = cfctrl_recv;
102045 sprintf(this->serv.layer.name, "ctrl");
102046 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
102047 @@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
102048 struct cfctrl_request_info *req)
102049 {
102050 spin_lock_bh(&ctrl->info_list_lock);
102051 - atomic_inc(&ctrl->req_seq_no);
102052 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
102053 + atomic_inc_unchecked(&ctrl->req_seq_no);
102054 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
102055 list_add_tail(&req->list, &ctrl->list);
102056 spin_unlock_bh(&ctrl->info_list_lock);
102057 }
102058 @@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
102059 if (p != first)
102060 pr_warn("Requests are not received in order\n");
102061
102062 - atomic_set(&ctrl->rsp_seq_no,
102063 + atomic_set_unchecked(&ctrl->rsp_seq_no,
102064 p->sequence_no);
102065 list_del(&p->list);
102066 goto out;
102067 diff --git a/net/caif/chnl_net.c b/net/caif/chnl_net.c
102068 index 4589ff67..46d6b8f 100644
102069 --- a/net/caif/chnl_net.c
102070 +++ b/net/caif/chnl_net.c
102071 @@ -516,7 +516,7 @@ static const struct nla_policy ipcaif_policy[IFLA_CAIF_MAX + 1] = {
102072 };
102073
102074
102075 -static struct rtnl_link_ops ipcaif_link_ops __read_mostly = {
102076 +static struct rtnl_link_ops ipcaif_link_ops = {
102077 .kind = "caif",
102078 .priv_size = sizeof(struct chnl_net),
102079 .setup = ipcaif_net_setup,
102080 diff --git a/net/can/af_can.c b/net/can/af_can.c
102081 index ce82337..5d17b4d 100644
102082 --- a/net/can/af_can.c
102083 +++ b/net/can/af_can.c
102084 @@ -884,7 +884,7 @@ static const struct net_proto_family can_family_ops = {
102085 };
102086
102087 /* notifier block for netdevice event */
102088 -static struct notifier_block can_netdev_notifier __read_mostly = {
102089 +static struct notifier_block can_netdev_notifier = {
102090 .notifier_call = can_notifier,
102091 };
102092
102093 diff --git a/net/can/bcm.c b/net/can/bcm.c
102094 index dcb75c0..24b1b43 100644
102095 --- a/net/can/bcm.c
102096 +++ b/net/can/bcm.c
102097 @@ -1624,7 +1624,7 @@ static int __init bcm_module_init(void)
102098 }
102099
102100 /* create /proc/net/can-bcm directory */
102101 - proc_dir = proc_mkdir("can-bcm", init_net.proc_net);
102102 + proc_dir = proc_mkdir_restrict("can-bcm", init_net.proc_net);
102103 return 0;
102104 }
102105
102106 diff --git a/net/can/gw.c b/net/can/gw.c
102107 index 050a211..bb9fe33 100644
102108 --- a/net/can/gw.c
102109 +++ b/net/can/gw.c
102110 @@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
102111 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
102112
102113 static HLIST_HEAD(cgw_list);
102114 -static struct notifier_block notifier;
102115
102116 static struct kmem_cache *cgw_cache __read_mostly;
102117
102118 @@ -947,6 +946,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
102119 return err;
102120 }
102121
102122 +static struct notifier_block notifier = {
102123 + .notifier_call = cgw_notifier
102124 +};
102125 +
102126 static __init int cgw_module_init(void)
102127 {
102128 /* sanitize given module parameter */
102129 @@ -962,7 +965,6 @@ static __init int cgw_module_init(void)
102130 return -ENOMEM;
102131
102132 /* set notifier */
102133 - notifier.notifier_call = cgw_notifier;
102134 register_netdevice_notifier(&notifier);
102135
102136 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
102137 diff --git a/net/can/proc.c b/net/can/proc.c
102138 index 1a19b98..df2b4ec 100644
102139 --- a/net/can/proc.c
102140 +++ b/net/can/proc.c
102141 @@ -514,7 +514,7 @@ static void can_remove_proc_readentry(const char *name)
102142 void can_init_proc(void)
102143 {
102144 /* create /proc/net/can directory */
102145 - can_dir = proc_mkdir("can", init_net.proc_net);
102146 + can_dir = proc_mkdir_restrict("can", init_net.proc_net);
102147
102148 if (!can_dir) {
102149 printk(KERN_INFO "can: failed to create /proc/net/can . "
102150 diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
102151 index 9f02369..e6160e9 100644
102152 --- a/net/ceph/messenger.c
102153 +++ b/net/ceph/messenger.c
102154 @@ -188,7 +188,7 @@ static void con_fault(struct ceph_connection *con);
102155 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
102156
102157 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
102158 -static atomic_t addr_str_seq = ATOMIC_INIT(0);
102159 +static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
102160
102161 static struct page *zero_page; /* used in certain error cases */
102162
102163 @@ -199,7 +199,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
102164 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
102165 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
102166
102167 - i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
102168 + i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
102169 s = addr_str[i];
102170
102171 switch (ss->ss_family) {
102172 diff --git a/net/compat.c b/net/compat.c
102173 index bc8aeef..f9c070c 100644
102174 --- a/net/compat.c
102175 +++ b/net/compat.c
102176 @@ -73,9 +73,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
102177 return -EFAULT;
102178 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
102179 kmsg->msg_namelen = sizeof(struct sockaddr_storage);
102180 - kmsg->msg_name = compat_ptr(tmp1);
102181 - kmsg->msg_iov = compat_ptr(tmp2);
102182 - kmsg->msg_control = compat_ptr(tmp3);
102183 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
102184 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
102185 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
102186 return 0;
102187 }
102188
102189 @@ -87,7 +87,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
102190
102191 if (kern_msg->msg_name && kern_msg->msg_namelen) {
102192 if (mode == VERIFY_READ) {
102193 - int err = move_addr_to_kernel(kern_msg->msg_name,
102194 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
102195 kern_msg->msg_namelen,
102196 kern_address);
102197 if (err < 0)
102198 @@ -100,7 +100,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
102199 }
102200
102201 tot_len = iov_from_user_compat_to_kern(kern_iov,
102202 - (struct compat_iovec __user *)kern_msg->msg_iov,
102203 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
102204 kern_msg->msg_iovlen);
102205 if (tot_len >= 0)
102206 kern_msg->msg_iov = kern_iov;
102207 @@ -120,20 +120,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
102208
102209 #define CMSG_COMPAT_FIRSTHDR(msg) \
102210 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
102211 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
102212 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
102213 (struct compat_cmsghdr __user *)NULL)
102214
102215 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
102216 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
102217 (ucmlen) <= (unsigned long) \
102218 ((mhdr)->msg_controllen - \
102219 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
102220 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
102221
102222 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
102223 struct compat_cmsghdr __user *cmsg, int cmsg_len)
102224 {
102225 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
102226 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
102227 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
102228 msg->msg_controllen)
102229 return NULL;
102230 return (struct compat_cmsghdr __user *)ptr;
102231 @@ -223,7 +223,7 @@ Efault:
102232
102233 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
102234 {
102235 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
102236 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
102237 struct compat_cmsghdr cmhdr;
102238 struct compat_timeval ctv;
102239 struct compat_timespec cts[3];
102240 @@ -279,7 +279,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
102241
102242 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
102243 {
102244 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
102245 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
102246 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
102247 int fdnum = scm->fp->count;
102248 struct file **fp = scm->fp->fp;
102249 @@ -367,7 +367,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
102250 return -EFAULT;
102251 old_fs = get_fs();
102252 set_fs(KERNEL_DS);
102253 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
102254 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
102255 set_fs(old_fs);
102256
102257 return err;
102258 @@ -428,7 +428,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
102259 len = sizeof(ktime);
102260 old_fs = get_fs();
102261 set_fs(KERNEL_DS);
102262 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
102263 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
102264 set_fs(old_fs);
102265
102266 if (!err) {
102267 @@ -571,7 +571,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
102268 case MCAST_JOIN_GROUP:
102269 case MCAST_LEAVE_GROUP:
102270 {
102271 - struct compat_group_req __user *gr32 = (void *)optval;
102272 + struct compat_group_req __user *gr32 = (void __user *)optval;
102273 struct group_req __user *kgr =
102274 compat_alloc_user_space(sizeof(struct group_req));
102275 u32 interface;
102276 @@ -592,7 +592,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
102277 case MCAST_BLOCK_SOURCE:
102278 case MCAST_UNBLOCK_SOURCE:
102279 {
102280 - struct compat_group_source_req __user *gsr32 = (void *)optval;
102281 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
102282 struct group_source_req __user *kgsr = compat_alloc_user_space(
102283 sizeof(struct group_source_req));
102284 u32 interface;
102285 @@ -613,7 +613,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
102286 }
102287 case MCAST_MSFILTER:
102288 {
102289 - struct compat_group_filter __user *gf32 = (void *)optval;
102290 + struct compat_group_filter __user *gf32 = (void __user *)optval;
102291 struct group_filter __user *kgf;
102292 u32 interface, fmode, numsrc;
102293
102294 @@ -651,7 +651,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
102295 char __user *optval, int __user *optlen,
102296 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
102297 {
102298 - struct compat_group_filter __user *gf32 = (void *)optval;
102299 + struct compat_group_filter __user *gf32 = (void __user *)optval;
102300 struct group_filter __user *kgf;
102301 int __user *koptlen;
102302 u32 interface, fmode, numsrc;
102303 @@ -804,7 +804,7 @@ COMPAT_SYSCALL_DEFINE2(socketcall, int, call, u32 __user *, args)
102304
102305 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
102306 return -EINVAL;
102307 - if (copy_from_user(a, args, nas[call]))
102308 + if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
102309 return -EFAULT;
102310 a0 = a[0];
102311 a1 = a[1];
102312 diff --git a/net/core/datagram.c b/net/core/datagram.c
102313 index fdbc9a8..cd6972c 100644
102314 --- a/net/core/datagram.c
102315 +++ b/net/core/datagram.c
102316 @@ -301,7 +301,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
102317 }
102318
102319 kfree_skb(skb);
102320 - atomic_inc(&sk->sk_drops);
102321 + atomic_inc_unchecked(&sk->sk_drops);
102322 sk_mem_reclaim_partial(sk);
102323
102324 return err;
102325 diff --git a/net/core/dev.c b/net/core/dev.c
102326 index cf8a95f..2837211 100644
102327 --- a/net/core/dev.c
102328 +++ b/net/core/dev.c
102329 @@ -1683,14 +1683,14 @@ int __dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
102330 {
102331 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
102332 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
102333 - atomic_long_inc(&dev->rx_dropped);
102334 + atomic_long_inc_unchecked(&dev->rx_dropped);
102335 kfree_skb(skb);
102336 return NET_RX_DROP;
102337 }
102338 }
102339
102340 if (unlikely(!is_skb_forwardable(dev, skb))) {
102341 - atomic_long_inc(&dev->rx_dropped);
102342 + atomic_long_inc_unchecked(&dev->rx_dropped);
102343 kfree_skb(skb);
102344 return NET_RX_DROP;
102345 }
102346 @@ -2487,7 +2487,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
102347
102348 struct dev_gso_cb {
102349 void (*destructor)(struct sk_buff *skb);
102350 -};
102351 +} __no_const;
102352
102353 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
102354
102355 @@ -2952,7 +2952,7 @@ recursion_alert:
102356 rc = -ENETDOWN;
102357 rcu_read_unlock_bh();
102358
102359 - atomic_long_inc(&dev->tx_dropped);
102360 + atomic_long_inc_unchecked(&dev->tx_dropped);
102361 kfree_skb(skb);
102362 return rc;
102363 out:
102364 @@ -3296,7 +3296,7 @@ enqueue:
102365
102366 local_irq_restore(flags);
102367
102368 - atomic_long_inc(&skb->dev->rx_dropped);
102369 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
102370 kfree_skb(skb);
102371 return NET_RX_DROP;
102372 }
102373 @@ -3373,7 +3373,7 @@ int netif_rx_ni(struct sk_buff *skb)
102374 }
102375 EXPORT_SYMBOL(netif_rx_ni);
102376
102377 -static void net_tx_action(struct softirq_action *h)
102378 +static __latent_entropy void net_tx_action(void)
102379 {
102380 struct softnet_data *sd = &__get_cpu_var(softnet_data);
102381
102382 @@ -3706,7 +3706,7 @@ ncls:
102383 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
102384 } else {
102385 drop:
102386 - atomic_long_inc(&skb->dev->rx_dropped);
102387 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
102388 kfree_skb(skb);
102389 /* Jamal, now you will not able to escape explaining
102390 * me how you were going to use this. :-)
102391 @@ -4426,7 +4426,7 @@ void netif_napi_del(struct napi_struct *napi)
102392 }
102393 EXPORT_SYMBOL(netif_napi_del);
102394
102395 -static void net_rx_action(struct softirq_action *h)
102396 +static __latent_entropy void net_rx_action(void)
102397 {
102398 struct softnet_data *sd = &__get_cpu_var(softnet_data);
102399 unsigned long time_limit = jiffies + 2;
102400 @@ -6480,8 +6480,8 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
102401 } else {
102402 netdev_stats_to_stats64(storage, &dev->stats);
102403 }
102404 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
102405 - storage->tx_dropped += atomic_long_read(&dev->tx_dropped);
102406 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
102407 + storage->tx_dropped += atomic_long_read_unchecked(&dev->tx_dropped);
102408 return storage;
102409 }
102410 EXPORT_SYMBOL(dev_get_stats);
102411 diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
102412 index cf999e0..c59a9754 100644
102413 --- a/net/core/dev_ioctl.c
102414 +++ b/net/core/dev_ioctl.c
102415 @@ -366,9 +366,13 @@ void dev_load(struct net *net, const char *name)
102416 if (no_module && capable(CAP_NET_ADMIN))
102417 no_module = request_module("netdev-%s", name);
102418 if (no_module && capable(CAP_SYS_MODULE)) {
102419 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
102420 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
102421 +#else
102422 if (!request_module("%s", name))
102423 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
102424 name);
102425 +#endif
102426 }
102427 }
102428 EXPORT_SYMBOL(dev_load);
102429 diff --git a/net/core/filter.c b/net/core/filter.c
102430 index d814b8a..b5ab778 100644
102431 --- a/net/core/filter.c
102432 +++ b/net/core/filter.c
102433 @@ -559,7 +559,11 @@ do_pass:
102434
102435 /* Unkown instruction. */
102436 default:
102437 - goto err;
102438 + WARN(1, KERN_ALERT "Unknown sock filter code:%u jt:%u tf:%u k:%u\n",
102439 + fp->code, fp->jt, fp->jf, fp->k);
102440 + kfree(addrs);
102441 + BUG();
102442 + return -EINVAL;
102443 }
102444
102445 insn++;
102446 @@ -606,7 +610,7 @@ static int check_load_and_stores(const struct sock_filter *filter, int flen)
102447 u16 *masks, memvalid = 0; /* One bit per cell, 16 cells */
102448 int pc, ret = 0;
102449
102450 - BUILD_BUG_ON(BPF_MEMWORDS > 16);
102451 + BUILD_BUG_ON(BPF_MEMWORDS != 16);
102452
102453 masks = kmalloc_array(flen, sizeof(*masks), GFP_KERNEL);
102454 if (!masks)
102455 @@ -933,7 +937,7 @@ static struct bpf_prog *bpf_migrate_filter(struct bpf_prog *fp)
102456
102457 /* Expand fp for appending the new filter representation. */
102458 old_fp = fp;
102459 - fp = krealloc(old_fp, bpf_prog_size(new_len), GFP_KERNEL);
102460 + fp = bpf_prog_realloc(old_fp, bpf_prog_size(new_len), 0);
102461 if (!fp) {
102462 /* The old_fp is still around in case we couldn't
102463 * allocate new memory, so uncharge on that one.
102464 @@ -1013,11 +1017,11 @@ int bpf_prog_create(struct bpf_prog **pfp, struct sock_fprog_kern *fprog)
102465 if (fprog->filter == NULL)
102466 return -EINVAL;
102467
102468 - fp = kmalloc(bpf_prog_size(fprog->len), GFP_KERNEL);
102469 + fp = bpf_prog_alloc(bpf_prog_size(fprog->len), 0);
102470 if (!fp)
102471 return -ENOMEM;
102472
102473 - memcpy(fp->insns, fprog->filter, fsize);
102474 + memcpy(fp->insns, (void __force_kernel *)fprog->filter, fsize);
102475
102476 fp->len = fprog->len;
102477 /* Since unattached filters are not copied back to user
102478 @@ -1069,12 +1073,12 @@ int sk_attach_filter(struct sock_fprog *fprog, struct sock *sk)
102479 if (fprog->filter == NULL)
102480 return -EINVAL;
102481
102482 - prog = kmalloc(bpf_fsize, GFP_KERNEL);
102483 + prog = bpf_prog_alloc(bpf_fsize, 0);
102484 if (!prog)
102485 return -ENOMEM;
102486
102487 if (copy_from_user(prog->insns, fprog->filter, fsize)) {
102488 - kfree(prog);
102489 + __bpf_prog_free(prog);
102490 return -EFAULT;
102491 }
102492
102493 @@ -1082,7 +1086,7 @@ int sk_attach_filter(struct sock_fprog *fprog, struct sock *sk)
102494
102495 err = bpf_prog_store_orig_filter(prog, fprog);
102496 if (err) {
102497 - kfree(prog);
102498 + __bpf_prog_free(prog);
102499 return -ENOMEM;
102500 }
102501
102502 diff --git a/net/core/flow.c b/net/core/flow.c
102503 index a0348fd..6951c76 100644
102504 --- a/net/core/flow.c
102505 +++ b/net/core/flow.c
102506 @@ -65,7 +65,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
102507 static int flow_entry_valid(struct flow_cache_entry *fle,
102508 struct netns_xfrm *xfrm)
102509 {
102510 - if (atomic_read(&xfrm->flow_cache_genid) != fle->genid)
102511 + if (atomic_read_unchecked(&xfrm->flow_cache_genid) != fle->genid)
102512 return 0;
102513 if (fle->object && !fle->object->ops->check(fle->object))
102514 return 0;
102515 @@ -242,7 +242,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
102516 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
102517 fcp->hash_count++;
102518 }
102519 - } else if (likely(fle->genid == atomic_read(&net->xfrm.flow_cache_genid))) {
102520 + } else if (likely(fle->genid == atomic_read_unchecked(&net->xfrm.flow_cache_genid))) {
102521 flo = fle->object;
102522 if (!flo)
102523 goto ret_object;
102524 @@ -263,7 +263,7 @@ nocache:
102525 }
102526 flo = resolver(net, key, family, dir, flo, ctx);
102527 if (fle) {
102528 - fle->genid = atomic_read(&net->xfrm.flow_cache_genid);
102529 + fle->genid = atomic_read_unchecked(&net->xfrm.flow_cache_genid);
102530 if (!IS_ERR(flo))
102531 fle->object = flo;
102532 else
102533 diff --git a/net/core/iovec.c b/net/core/iovec.c
102534 index e1ec45a..e5c6f16 100644
102535 --- a/net/core/iovec.c
102536 +++ b/net/core/iovec.c
102537 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
102538 if (m->msg_name && m->msg_namelen) {
102539 if (mode == VERIFY_READ) {
102540 void __user *namep;
102541 - namep = (void __user __force *) m->msg_name;
102542 + namep = (void __force_user *) m->msg_name;
102543 err = move_addr_to_kernel(namep, m->msg_namelen,
102544 address);
102545 if (err < 0)
102546 @@ -55,7 +55,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
102547 }
102548
102549 size = m->msg_iovlen * sizeof(struct iovec);
102550 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
102551 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
102552 return -EFAULT;
102553
102554 m->msg_iov = iov;
102555 diff --git a/net/core/neighbour.c b/net/core/neighbour.c
102556 index ef31fef..8be66d9 100644
102557 --- a/net/core/neighbour.c
102558 +++ b/net/core/neighbour.c
102559 @@ -2825,7 +2825,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
102560 void __user *buffer, size_t *lenp, loff_t *ppos)
102561 {
102562 int size, ret;
102563 - struct ctl_table tmp = *ctl;
102564 + ctl_table_no_const tmp = *ctl;
102565
102566 tmp.extra1 = &zero;
102567 tmp.extra2 = &unres_qlen_max;
102568 @@ -2887,7 +2887,7 @@ static int neigh_proc_dointvec_zero_intmax(struct ctl_table *ctl, int write,
102569 void __user *buffer,
102570 size_t *lenp, loff_t *ppos)
102571 {
102572 - struct ctl_table tmp = *ctl;
102573 + ctl_table_no_const tmp = *ctl;
102574 int ret;
102575
102576 tmp.extra1 = &zero;
102577 diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
102578 index 2bf8329..2eb1423 100644
102579 --- a/net/core/net-procfs.c
102580 +++ b/net/core/net-procfs.c
102581 @@ -79,7 +79,13 @@ static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
102582 struct rtnl_link_stats64 temp;
102583 const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
102584
102585 - seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
102586 + if (gr_proc_is_restricted())
102587 + seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
102588 + "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
102589 + dev->name, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL,
102590 + 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL);
102591 + else
102592 + seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
102593 "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
102594 dev->name, stats->rx_bytes, stats->rx_packets,
102595 stats->rx_errors,
102596 @@ -166,7 +172,7 @@ static int softnet_seq_show(struct seq_file *seq, void *v)
102597 return 0;
102598 }
102599
102600 -static const struct seq_operations dev_seq_ops = {
102601 +const struct seq_operations dev_seq_ops = {
102602 .start = dev_seq_start,
102603 .next = dev_seq_next,
102604 .stop = dev_seq_stop,
102605 @@ -196,7 +202,7 @@ static const struct seq_operations softnet_seq_ops = {
102606
102607 static int softnet_seq_open(struct inode *inode, struct file *file)
102608 {
102609 - return seq_open(file, &softnet_seq_ops);
102610 + return seq_open_restrict(file, &softnet_seq_ops);
102611 }
102612
102613 static const struct file_operations softnet_seq_fops = {
102614 @@ -283,8 +289,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
102615 else
102616 seq_printf(seq, "%04x", ntohs(pt->type));
102617
102618 +#ifdef CONFIG_GRKERNSEC_HIDESYM
102619 + seq_printf(seq, " %-8s %pf\n",
102620 + pt->dev ? pt->dev->name : "", NULL);
102621 +#else
102622 seq_printf(seq, " %-8s %pf\n",
102623 pt->dev ? pt->dev->name : "", pt->func);
102624 +#endif
102625 }
102626
102627 return 0;
102628 diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
102629 index 9dd0669..c52fb1b 100644
102630 --- a/net/core/net-sysfs.c
102631 +++ b/net/core/net-sysfs.c
102632 @@ -278,7 +278,7 @@ static ssize_t carrier_changes_show(struct device *dev,
102633 {
102634 struct net_device *netdev = to_net_dev(dev);
102635 return sprintf(buf, fmt_dec,
102636 - atomic_read(&netdev->carrier_changes));
102637 + atomic_read_unchecked(&netdev->carrier_changes));
102638 }
102639 static DEVICE_ATTR_RO(carrier_changes);
102640
102641 diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
102642 index 7c6b51a..e9dd57f 100644
102643 --- a/net/core/net_namespace.c
102644 +++ b/net/core/net_namespace.c
102645 @@ -445,7 +445,7 @@ static int __register_pernet_operations(struct list_head *list,
102646 int error;
102647 LIST_HEAD(net_exit_list);
102648
102649 - list_add_tail(&ops->list, list);
102650 + pax_list_add_tail((struct list_head *)&ops->list, list);
102651 if (ops->init || (ops->id && ops->size)) {
102652 for_each_net(net) {
102653 error = ops_init(ops, net);
102654 @@ -458,7 +458,7 @@ static int __register_pernet_operations(struct list_head *list,
102655
102656 out_undo:
102657 /* If I have an error cleanup all namespaces I initialized */
102658 - list_del(&ops->list);
102659 + pax_list_del((struct list_head *)&ops->list);
102660 ops_exit_list(ops, &net_exit_list);
102661 ops_free_list(ops, &net_exit_list);
102662 return error;
102663 @@ -469,7 +469,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
102664 struct net *net;
102665 LIST_HEAD(net_exit_list);
102666
102667 - list_del(&ops->list);
102668 + pax_list_del((struct list_head *)&ops->list);
102669 for_each_net(net)
102670 list_add_tail(&net->exit_list, &net_exit_list);
102671 ops_exit_list(ops, &net_exit_list);
102672 @@ -603,7 +603,7 @@ int register_pernet_device(struct pernet_operations *ops)
102673 mutex_lock(&net_mutex);
102674 error = register_pernet_operations(&pernet_list, ops);
102675 if (!error && (first_device == &pernet_list))
102676 - first_device = &ops->list;
102677 + first_device = (struct list_head *)&ops->list;
102678 mutex_unlock(&net_mutex);
102679 return error;
102680 }
102681 diff --git a/net/core/netpoll.c b/net/core/netpoll.c
102682 index 907fb5e..8260f040b 100644
102683 --- a/net/core/netpoll.c
102684 +++ b/net/core/netpoll.c
102685 @@ -382,7 +382,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
102686 struct udphdr *udph;
102687 struct iphdr *iph;
102688 struct ethhdr *eth;
102689 - static atomic_t ip_ident;
102690 + static atomic_unchecked_t ip_ident;
102691 struct ipv6hdr *ip6h;
102692
102693 udp_len = len + sizeof(*udph);
102694 @@ -453,7 +453,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
102695 put_unaligned(0x45, (unsigned char *)iph);
102696 iph->tos = 0;
102697 put_unaligned(htons(ip_len), &(iph->tot_len));
102698 - iph->id = htons(atomic_inc_return(&ip_ident));
102699 + iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
102700 iph->frag_off = 0;
102701 iph->ttl = 64;
102702 iph->protocol = IPPROTO_UDP;
102703 diff --git a/net/core/pktgen.c b/net/core/pktgen.c
102704 index 8b849dd..cd88bfc 100644
102705 --- a/net/core/pktgen.c
102706 +++ b/net/core/pktgen.c
102707 @@ -3723,7 +3723,7 @@ static int __net_init pg_net_init(struct net *net)
102708 pn->net = net;
102709 INIT_LIST_HEAD(&pn->pktgen_threads);
102710 pn->pktgen_exiting = false;
102711 - pn->proc_dir = proc_mkdir(PG_PROC_DIR, pn->net->proc_net);
102712 + pn->proc_dir = proc_mkdir_restrict(PG_PROC_DIR, pn->net->proc_net);
102713 if (!pn->proc_dir) {
102714 pr_warn("cannot create /proc/net/%s\n", PG_PROC_DIR);
102715 return -ENODEV;
102716 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
102717 index 4921b65..7cb175e 100644
102718 --- a/net/core/rtnetlink.c
102719 +++ b/net/core/rtnetlink.c
102720 @@ -58,7 +58,7 @@ struct rtnl_link {
102721 rtnl_doit_func doit;
102722 rtnl_dumpit_func dumpit;
102723 rtnl_calcit_func calcit;
102724 -};
102725 +} __no_const;
102726
102727 static DEFINE_MUTEX(rtnl_mutex);
102728
102729 @@ -304,10 +304,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
102730 * to use the ops for creating device. So do not
102731 * fill up dellink as well. That disables rtnl_dellink.
102732 */
102733 - if (ops->setup && !ops->dellink)
102734 - ops->dellink = unregister_netdevice_queue;
102735 + if (ops->setup && !ops->dellink) {
102736 + pax_open_kernel();
102737 + *(void **)&ops->dellink = unregister_netdevice_queue;
102738 + pax_close_kernel();
102739 + }
102740
102741 - list_add_tail(&ops->list, &link_ops);
102742 + pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
102743 return 0;
102744 }
102745 EXPORT_SYMBOL_GPL(__rtnl_link_register);
102746 @@ -354,7 +357,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
102747 for_each_net(net) {
102748 __rtnl_kill_links(net, ops);
102749 }
102750 - list_del(&ops->list);
102751 + pax_list_del((struct list_head *)&ops->list);
102752 }
102753 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
102754
102755 @@ -1014,7 +1017,7 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
102756 (dev->ifalias &&
102757 nla_put_string(skb, IFLA_IFALIAS, dev->ifalias)) ||
102758 nla_put_u32(skb, IFLA_CARRIER_CHANGES,
102759 - atomic_read(&dev->carrier_changes)))
102760 + atomic_read_unchecked(&dev->carrier_changes)))
102761 goto nla_put_failure;
102762
102763 if (1) {
102764 @@ -2781,6 +2784,9 @@ static int rtnl_bridge_setlink(struct sk_buff *skb, struct nlmsghdr *nlh)
102765 if (br_spec) {
102766 nla_for_each_nested(attr, br_spec, rem) {
102767 if (nla_type(attr) == IFLA_BRIDGE_FLAGS) {
102768 + if (nla_len(attr) < sizeof(flags))
102769 + return -EINVAL;
102770 +
102771 have_flags = true;
102772 flags = nla_get_u16(attr);
102773 break;
102774 @@ -2851,6 +2857,9 @@ static int rtnl_bridge_dellink(struct sk_buff *skb, struct nlmsghdr *nlh)
102775 if (br_spec) {
102776 nla_for_each_nested(attr, br_spec, rem) {
102777 if (nla_type(attr) == IFLA_BRIDGE_FLAGS) {
102778 + if (nla_len(attr) < sizeof(flags))
102779 + return -EINVAL;
102780 +
102781 have_flags = true;
102782 flags = nla_get_u16(attr);
102783 break;
102784 diff --git a/net/core/scm.c b/net/core/scm.c
102785 index b442e7e..6f5b5a2 100644
102786 --- a/net/core/scm.c
102787 +++ b/net/core/scm.c
102788 @@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
102789 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
102790 {
102791 struct cmsghdr __user *cm
102792 - = (__force struct cmsghdr __user *)msg->msg_control;
102793 + = (struct cmsghdr __force_user *)msg->msg_control;
102794 struct cmsghdr cmhdr;
102795 int cmlen = CMSG_LEN(len);
102796 int err;
102797 @@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
102798 err = -EFAULT;
102799 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
102800 goto out;
102801 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
102802 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
102803 goto out;
102804 cmlen = CMSG_SPACE(len);
102805 if (msg->msg_controllen < cmlen)
102806 @@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
102807 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
102808 {
102809 struct cmsghdr __user *cm
102810 - = (__force struct cmsghdr __user*)msg->msg_control;
102811 + = (struct cmsghdr __force_user *)msg->msg_control;
102812
102813 int fdmax = 0;
102814 int fdnum = scm->fp->count;
102815 @@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
102816 if (fdnum < fdmax)
102817 fdmax = fdnum;
102818
102819 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
102820 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
102821 i++, cmfptr++)
102822 {
102823 struct socket *sock;
102824 diff --git a/net/core/skbuff.c b/net/core/skbuff.c
102825 index 8d28969..4d36260 100644
102826 --- a/net/core/skbuff.c
102827 +++ b/net/core/skbuff.c
102828 @@ -360,18 +360,29 @@ refill:
102829 goto end;
102830 }
102831 nc->frag.size = PAGE_SIZE << order;
102832 -recycle:
102833 - atomic_set(&nc->frag.page->_count, NETDEV_PAGECNT_MAX_BIAS);
102834 + /* Even if we own the page, we do not use atomic_set().
102835 + * This would break get_page_unless_zero() users.
102836 + */
102837 + atomic_add(NETDEV_PAGECNT_MAX_BIAS - 1,
102838 + &nc->frag.page->_count);
102839 nc->pagecnt_bias = NETDEV_PAGECNT_MAX_BIAS;
102840 nc->frag.offset = 0;
102841 }
102842
102843 if (nc->frag.offset + fragsz > nc->frag.size) {
102844 - /* avoid unnecessary locked operations if possible */
102845 - if ((atomic_read(&nc->frag.page->_count) == nc->pagecnt_bias) ||
102846 - atomic_sub_and_test(nc->pagecnt_bias, &nc->frag.page->_count))
102847 - goto recycle;
102848 - goto refill;
102849 + if (atomic_read(&nc->frag.page->_count) != nc->pagecnt_bias) {
102850 + if (!atomic_sub_and_test(nc->pagecnt_bias,
102851 + &nc->frag.page->_count))
102852 + goto refill;
102853 + /* OK, page count is 0, we can safely set it */
102854 + atomic_set(&nc->frag.page->_count,
102855 + NETDEV_PAGECNT_MAX_BIAS);
102856 + } else {
102857 + atomic_add(NETDEV_PAGECNT_MAX_BIAS - nc->pagecnt_bias,
102858 + &nc->frag.page->_count);
102859 + }
102860 + nc->pagecnt_bias = NETDEV_PAGECNT_MAX_BIAS;
102861 + nc->frag.offset = 0;
102862 }
102863
102864 data = page_address(nc->frag.page) + nc->frag.offset;
102865 @@ -2011,7 +2022,7 @@ EXPORT_SYMBOL(__skb_checksum);
102866 __wsum skb_checksum(const struct sk_buff *skb, int offset,
102867 int len, __wsum csum)
102868 {
102869 - const struct skb_checksum_ops ops = {
102870 + static const struct skb_checksum_ops ops = {
102871 .update = csum_partial_ext,
102872 .combine = csum_block_add_ext,
102873 };
102874 @@ -3237,13 +3248,15 @@ void __init skb_init(void)
102875 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
102876 sizeof(struct sk_buff),
102877 0,
102878 - SLAB_HWCACHE_ALIGN|SLAB_PANIC,
102879 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|
102880 + SLAB_NO_SANITIZE,
102881 NULL);
102882 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
102883 (2*sizeof(struct sk_buff)) +
102884 sizeof(atomic_t),
102885 0,
102886 - SLAB_HWCACHE_ALIGN|SLAB_PANIC,
102887 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|
102888 + SLAB_NO_SANITIZE,
102889 NULL);
102890 }
102891
102892 diff --git a/net/core/sock.c b/net/core/sock.c
102893 index 9c3f823..bd8c884 100644
102894 --- a/net/core/sock.c
102895 +++ b/net/core/sock.c
102896 @@ -442,7 +442,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
102897 struct sk_buff_head *list = &sk->sk_receive_queue;
102898
102899 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
102900 - atomic_inc(&sk->sk_drops);
102901 + atomic_inc_unchecked(&sk->sk_drops);
102902 trace_sock_rcvqueue_full(sk, skb);
102903 return -ENOMEM;
102904 }
102905 @@ -452,7 +452,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
102906 return err;
102907
102908 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
102909 - atomic_inc(&sk->sk_drops);
102910 + atomic_inc_unchecked(&sk->sk_drops);
102911 return -ENOBUFS;
102912 }
102913
102914 @@ -472,7 +472,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
102915 skb_dst_force(skb);
102916
102917 spin_lock_irqsave(&list->lock, flags);
102918 - skb->dropcount = atomic_read(&sk->sk_drops);
102919 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
102920 __skb_queue_tail(list, skb);
102921 spin_unlock_irqrestore(&list->lock, flags);
102922
102923 @@ -492,7 +492,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
102924 skb->dev = NULL;
102925
102926 if (sk_rcvqueues_full(sk, sk->sk_rcvbuf)) {
102927 - atomic_inc(&sk->sk_drops);
102928 + atomic_inc_unchecked(&sk->sk_drops);
102929 goto discard_and_relse;
102930 }
102931 if (nested)
102932 @@ -510,7 +510,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
102933 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
102934 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
102935 bh_unlock_sock(sk);
102936 - atomic_inc(&sk->sk_drops);
102937 + atomic_inc_unchecked(&sk->sk_drops);
102938 goto discard_and_relse;
102939 }
102940
102941 @@ -999,12 +999,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
102942 struct timeval tm;
102943 } v;
102944
102945 - int lv = sizeof(int);
102946 - int len;
102947 + unsigned int lv = sizeof(int);
102948 + unsigned int len;
102949
102950 if (get_user(len, optlen))
102951 return -EFAULT;
102952 - if (len < 0)
102953 + if (len > INT_MAX)
102954 return -EINVAL;
102955
102956 memset(&v, 0, sizeof(v));
102957 @@ -1142,11 +1142,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
102958
102959 case SO_PEERNAME:
102960 {
102961 - char address[128];
102962 + char address[_K_SS_MAXSIZE];
102963
102964 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
102965 return -ENOTCONN;
102966 - if (lv < len)
102967 + if (lv < len || sizeof address < len)
102968 return -EINVAL;
102969 if (copy_to_user(optval, address, len))
102970 return -EFAULT;
102971 @@ -1227,7 +1227,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
102972
102973 if (len > lv)
102974 len = lv;
102975 - if (copy_to_user(optval, &v, len))
102976 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
102977 return -EFAULT;
102978 lenout:
102979 if (put_user(len, optlen))
102980 @@ -1723,6 +1723,8 @@ EXPORT_SYMBOL(sock_kmalloc);
102981 */
102982 void sock_kfree_s(struct sock *sk, void *mem, int size)
102983 {
102984 + if (WARN_ON_ONCE(!mem))
102985 + return;
102986 kfree(mem);
102987 atomic_sub(size, &sk->sk_omem_alloc);
102988 }
102989 @@ -2369,7 +2371,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
102990 */
102991 smp_wmb();
102992 atomic_set(&sk->sk_refcnt, 1);
102993 - atomic_set(&sk->sk_drops, 0);
102994 + atomic_set_unchecked(&sk->sk_drops, 0);
102995 }
102996 EXPORT_SYMBOL(sock_init_data);
102997
102998 @@ -2497,6 +2499,7 @@ void sock_enable_timestamp(struct sock *sk, int flag)
102999 int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
103000 int level, int type)
103001 {
103002 + struct sock_extended_err ee;
103003 struct sock_exterr_skb *serr;
103004 struct sk_buff *skb, *skb2;
103005 int copied, err;
103006 @@ -2518,7 +2521,8 @@ int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
103007 sock_recv_timestamp(msg, sk, skb);
103008
103009 serr = SKB_EXT_ERR(skb);
103010 - put_cmsg(msg, level, type, sizeof(serr->ee), &serr->ee);
103011 + ee = serr->ee;
103012 + put_cmsg(msg, level, type, sizeof ee, &ee);
103013
103014 msg->msg_flags |= MSG_ERRQUEUE;
103015 err = copied;
103016 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
103017 index ad704c7..ca48aff 100644
103018 --- a/net/core/sock_diag.c
103019 +++ b/net/core/sock_diag.c
103020 @@ -9,26 +9,33 @@
103021 #include <linux/inet_diag.h>
103022 #include <linux/sock_diag.h>
103023
103024 -static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
103025 +static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
103026 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
103027 static DEFINE_MUTEX(sock_diag_table_mutex);
103028
103029 int sock_diag_check_cookie(void *sk, __u32 *cookie)
103030 {
103031 +#ifndef CONFIG_GRKERNSEC_HIDESYM
103032 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
103033 cookie[1] != INET_DIAG_NOCOOKIE) &&
103034 ((u32)(unsigned long)sk != cookie[0] ||
103035 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
103036 return -ESTALE;
103037 else
103038 +#endif
103039 return 0;
103040 }
103041 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
103042
103043 void sock_diag_save_cookie(void *sk, __u32 *cookie)
103044 {
103045 +#ifdef CONFIG_GRKERNSEC_HIDESYM
103046 + cookie[0] = 0;
103047 + cookie[1] = 0;
103048 +#else
103049 cookie[0] = (u32)(unsigned long)sk;
103050 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
103051 +#endif
103052 }
103053 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
103054
103055 @@ -110,8 +117,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
103056 mutex_lock(&sock_diag_table_mutex);
103057 if (sock_diag_handlers[hndl->family])
103058 err = -EBUSY;
103059 - else
103060 + else {
103061 + pax_open_kernel();
103062 sock_diag_handlers[hndl->family] = hndl;
103063 + pax_close_kernel();
103064 + }
103065 mutex_unlock(&sock_diag_table_mutex);
103066
103067 return err;
103068 @@ -127,7 +137,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
103069
103070 mutex_lock(&sock_diag_table_mutex);
103071 BUG_ON(sock_diag_handlers[family] != hnld);
103072 + pax_open_kernel();
103073 sock_diag_handlers[family] = NULL;
103074 + pax_close_kernel();
103075 mutex_unlock(&sock_diag_table_mutex);
103076 }
103077 EXPORT_SYMBOL_GPL(sock_diag_unregister);
103078 diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
103079 index cf9cd13..50683950 100644
103080 --- a/net/core/sysctl_net_core.c
103081 +++ b/net/core/sysctl_net_core.c
103082 @@ -32,7 +32,7 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
103083 {
103084 unsigned int orig_size, size;
103085 int ret, i;
103086 - struct ctl_table tmp = {
103087 + ctl_table_no_const tmp = {
103088 .data = &size,
103089 .maxlen = sizeof(size),
103090 .mode = table->mode
103091 @@ -200,7 +200,7 @@ static int set_default_qdisc(struct ctl_table *table, int write,
103092 void __user *buffer, size_t *lenp, loff_t *ppos)
103093 {
103094 char id[IFNAMSIZ];
103095 - struct ctl_table tbl = {
103096 + ctl_table_no_const tbl = {
103097 .data = id,
103098 .maxlen = IFNAMSIZ,
103099 };
103100 @@ -263,7 +263,7 @@ static struct ctl_table net_core_table[] = {
103101 .mode = 0644,
103102 .proc_handler = proc_dointvec
103103 },
103104 -#ifdef CONFIG_BPF_JIT
103105 +#if defined(CONFIG_BPF_JIT) && !defined(CONFIG_GRKERNSEC_BPF_HARDEN)
103106 {
103107 .procname = "bpf_jit_enable",
103108 .data = &bpf_jit_enable,
103109 @@ -379,13 +379,12 @@ static struct ctl_table netns_core_table[] = {
103110
103111 static __net_init int sysctl_core_net_init(struct net *net)
103112 {
103113 - struct ctl_table *tbl;
103114 + ctl_table_no_const *tbl = NULL;
103115
103116 net->core.sysctl_somaxconn = SOMAXCONN;
103117
103118 - tbl = netns_core_table;
103119 if (!net_eq(net, &init_net)) {
103120 - tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
103121 + tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
103122 if (tbl == NULL)
103123 goto err_dup;
103124
103125 @@ -395,17 +394,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
103126 if (net->user_ns != &init_user_ns) {
103127 tbl[0].procname = NULL;
103128 }
103129 - }
103130 -
103131 - net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
103132 + net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
103133 + } else
103134 + net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
103135 if (net->core.sysctl_hdr == NULL)
103136 goto err_reg;
103137
103138 return 0;
103139
103140 err_reg:
103141 - if (tbl != netns_core_table)
103142 - kfree(tbl);
103143 + kfree(tbl);
103144 err_dup:
103145 return -ENOMEM;
103146 }
103147 @@ -420,7 +418,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
103148 kfree(tbl);
103149 }
103150
103151 -static __net_initdata struct pernet_operations sysctl_core_ops = {
103152 +static __net_initconst struct pernet_operations sysctl_core_ops = {
103153 .init = sysctl_core_net_init,
103154 .exit = sysctl_core_net_exit,
103155 };
103156 diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
103157 index ae011b4..d2d18bf 100644
103158 --- a/net/decnet/af_decnet.c
103159 +++ b/net/decnet/af_decnet.c
103160 @@ -465,6 +465,7 @@ static struct proto dn_proto = {
103161 .sysctl_rmem = sysctl_decnet_rmem,
103162 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
103163 .obj_size = sizeof(struct dn_sock),
103164 + .slab_flags = SLAB_USERCOPY,
103165 };
103166
103167 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
103168 diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c
103169 index 3b726f3..1af6368 100644
103170 --- a/net/decnet/dn_dev.c
103171 +++ b/net/decnet/dn_dev.c
103172 @@ -200,7 +200,7 @@ static struct dn_dev_sysctl_table {
103173 .extra1 = &min_t3,
103174 .extra2 = &max_t3
103175 },
103176 - {0}
103177 + { }
103178 },
103179 };
103180
103181 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
103182 index 5325b54..a0d4d69 100644
103183 --- a/net/decnet/sysctl_net_decnet.c
103184 +++ b/net/decnet/sysctl_net_decnet.c
103185 @@ -174,7 +174,7 @@ static int dn_node_address_handler(struct ctl_table *table, int write,
103186
103187 if (len > *lenp) len = *lenp;
103188
103189 - if (copy_to_user(buffer, addr, len))
103190 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
103191 return -EFAULT;
103192
103193 *lenp = len;
103194 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(struct ctl_table *table, int write,
103195
103196 if (len > *lenp) len = *lenp;
103197
103198 - if (copy_to_user(buffer, devname, len))
103199 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
103200 return -EFAULT;
103201
103202 *lenp = len;
103203 diff --git a/net/hsr/hsr_netlink.c b/net/hsr/hsr_netlink.c
103204 index a2c7e4c..3dc9f67 100644
103205 --- a/net/hsr/hsr_netlink.c
103206 +++ b/net/hsr/hsr_netlink.c
103207 @@ -102,7 +102,7 @@ nla_put_failure:
103208 return -EMSGSIZE;
103209 }
103210
103211 -static struct rtnl_link_ops hsr_link_ops __read_mostly = {
103212 +static struct rtnl_link_ops hsr_link_ops = {
103213 .kind = "hsr",
103214 .maxtype = IFLA_HSR_MAX,
103215 .policy = hsr_policy,
103216 diff --git a/net/ieee802154/6lowpan_rtnl.c b/net/ieee802154/6lowpan_rtnl.c
103217 index 6591d27..499b971 100644
103218 --- a/net/ieee802154/6lowpan_rtnl.c
103219 +++ b/net/ieee802154/6lowpan_rtnl.c
103220 @@ -590,7 +590,7 @@ static void lowpan_dellink(struct net_device *dev, struct list_head *head)
103221 dev_put(real_dev);
103222 }
103223
103224 -static struct rtnl_link_ops lowpan_link_ops __read_mostly = {
103225 +static struct rtnl_link_ops lowpan_link_ops = {
103226 .kind = "lowpan",
103227 .priv_size = sizeof(struct lowpan_dev_info),
103228 .setup = lowpan_setup,
103229 diff --git a/net/ieee802154/reassembly.c b/net/ieee802154/reassembly.c
103230 index 32755cb..236d827 100644
103231 --- a/net/ieee802154/reassembly.c
103232 +++ b/net/ieee802154/reassembly.c
103233 @@ -433,14 +433,13 @@ static struct ctl_table lowpan_frags_ctl_table[] = {
103234
103235 static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
103236 {
103237 - struct ctl_table *table;
103238 + ctl_table_no_const *table = NULL;
103239 struct ctl_table_header *hdr;
103240 struct netns_ieee802154_lowpan *ieee802154_lowpan =
103241 net_ieee802154_lowpan(net);
103242
103243 - table = lowpan_frags_ns_ctl_table;
103244 if (!net_eq(net, &init_net)) {
103245 - table = kmemdup(table, sizeof(lowpan_frags_ns_ctl_table),
103246 + table = kmemdup(lowpan_frags_ns_ctl_table, sizeof(lowpan_frags_ns_ctl_table),
103247 GFP_KERNEL);
103248 if (table == NULL)
103249 goto err_alloc;
103250 @@ -455,9 +454,9 @@ static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
103251 /* Don't export sysctls to unprivileged users */
103252 if (net->user_ns != &init_user_ns)
103253 table[0].procname = NULL;
103254 - }
103255 -
103256 - hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", table);
103257 + hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", table);
103258 + } else
103259 + hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", lowpan_frags_ns_ctl_table);
103260 if (hdr == NULL)
103261 goto err_reg;
103262
103263 @@ -465,8 +464,7 @@ static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
103264 return 0;
103265
103266 err_reg:
103267 - if (!net_eq(net, &init_net))
103268 - kfree(table);
103269 + kfree(table);
103270 err_alloc:
103271 return -ENOMEM;
103272 }
103273 diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
103274 index bf78bc3..f6dbf03 100644
103275 --- a/net/ipv4/af_inet.c
103276 +++ b/net/ipv4/af_inet.c
103277 @@ -1427,7 +1427,7 @@ int inet_recv_error(struct sock *sk, struct msghdr *msg, int len, int *addr_len)
103278 return ip_recv_error(sk, msg, len, addr_len);
103279 #if IS_ENABLED(CONFIG_IPV6)
103280 if (sk->sk_family == AF_INET6)
103281 - return pingv6_ops.ipv6_recv_error(sk, msg, len, addr_len);
103282 + return pingv6_ops->ipv6_recv_error(sk, msg, len, addr_len);
103283 #endif
103284 return -EINVAL;
103285 }
103286 diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
103287 index 214882e..ec032f6 100644
103288 --- a/net/ipv4/devinet.c
103289 +++ b/net/ipv4/devinet.c
103290 @@ -69,7 +69,8 @@
103291
103292 static struct ipv4_devconf ipv4_devconf = {
103293 .data = {
103294 - [IPV4_DEVCONF_ACCEPT_REDIRECTS - 1] = 1,
103295 + [IPV4_DEVCONF_ACCEPT_REDIRECTS - 1] = 0,
103296 + [IPV4_DEVCONF_RP_FILTER - 1] = 1,
103297 [IPV4_DEVCONF_SEND_REDIRECTS - 1] = 1,
103298 [IPV4_DEVCONF_SECURE_REDIRECTS - 1] = 1,
103299 [IPV4_DEVCONF_SHARED_MEDIA - 1] = 1,
103300 @@ -80,7 +81,8 @@ static struct ipv4_devconf ipv4_devconf = {
103301
103302 static struct ipv4_devconf ipv4_devconf_dflt = {
103303 .data = {
103304 - [IPV4_DEVCONF_ACCEPT_REDIRECTS - 1] = 1,
103305 + [IPV4_DEVCONF_ACCEPT_REDIRECTS - 1] = 0,
103306 + [IPV4_DEVCONF_RP_FILTER - 1] = 1,
103307 [IPV4_DEVCONF_SEND_REDIRECTS - 1] = 1,
103308 [IPV4_DEVCONF_SECURE_REDIRECTS - 1] = 1,
103309 [IPV4_DEVCONF_SHARED_MEDIA - 1] = 1,
103310 @@ -1548,7 +1550,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
103311 idx = 0;
103312 head = &net->dev_index_head[h];
103313 rcu_read_lock();
103314 - cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
103315 + cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
103316 net->dev_base_seq;
103317 hlist_for_each_entry_rcu(dev, head, index_hlist) {
103318 if (idx < s_idx)
103319 @@ -1866,7 +1868,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
103320 idx = 0;
103321 head = &net->dev_index_head[h];
103322 rcu_read_lock();
103323 - cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
103324 + cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
103325 net->dev_base_seq;
103326 hlist_for_each_entry_rcu(dev, head, index_hlist) {
103327 if (idx < s_idx)
103328 @@ -2101,7 +2103,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
103329 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
103330 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
103331
103332 -static struct devinet_sysctl_table {
103333 +static const struct devinet_sysctl_table {
103334 struct ctl_table_header *sysctl_header;
103335 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
103336 } devinet_sysctl = {
103337 @@ -2233,7 +2235,7 @@ static __net_init int devinet_init_net(struct net *net)
103338 int err;
103339 struct ipv4_devconf *all, *dflt;
103340 #ifdef CONFIG_SYSCTL
103341 - struct ctl_table *tbl = ctl_forward_entry;
103342 + ctl_table_no_const *tbl = NULL;
103343 struct ctl_table_header *forw_hdr;
103344 #endif
103345
103346 @@ -2251,7 +2253,7 @@ static __net_init int devinet_init_net(struct net *net)
103347 goto err_alloc_dflt;
103348
103349 #ifdef CONFIG_SYSCTL
103350 - tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
103351 + tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
103352 if (tbl == NULL)
103353 goto err_alloc_ctl;
103354
103355 @@ -2271,7 +2273,10 @@ static __net_init int devinet_init_net(struct net *net)
103356 goto err_reg_dflt;
103357
103358 err = -ENOMEM;
103359 - forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
103360 + if (!net_eq(net, &init_net))
103361 + forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
103362 + else
103363 + forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
103364 if (forw_hdr == NULL)
103365 goto err_reg_ctl;
103366 net->ipv4.forw_hdr = forw_hdr;
103367 @@ -2287,8 +2292,7 @@ err_reg_ctl:
103368 err_reg_dflt:
103369 __devinet_sysctl_unregister(all);
103370 err_reg_all:
103371 - if (tbl != ctl_forward_entry)
103372 - kfree(tbl);
103373 + kfree(tbl);
103374 err_alloc_ctl:
103375 #endif
103376 if (dflt != &ipv4_devconf_dflt)
103377 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
103378 index 255aa99..45c78f8 100644
103379 --- a/net/ipv4/fib_frontend.c
103380 +++ b/net/ipv4/fib_frontend.c
103381 @@ -1015,12 +1015,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
103382 #ifdef CONFIG_IP_ROUTE_MULTIPATH
103383 fib_sync_up(dev);
103384 #endif
103385 - atomic_inc(&net->ipv4.dev_addr_genid);
103386 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
103387 rt_cache_flush(dev_net(dev));
103388 break;
103389 case NETDEV_DOWN:
103390 fib_del_ifaddr(ifa, NULL);
103391 - atomic_inc(&net->ipv4.dev_addr_genid);
103392 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
103393 if (ifa->ifa_dev->ifa_list == NULL) {
103394 /* Last address was deleted from this interface.
103395 * Disable IP.
103396 @@ -1058,7 +1058,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
103397 #ifdef CONFIG_IP_ROUTE_MULTIPATH
103398 fib_sync_up(dev);
103399 #endif
103400 - atomic_inc(&net->ipv4.dev_addr_genid);
103401 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
103402 rt_cache_flush(net);
103403 break;
103404 case NETDEV_DOWN:
103405 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
103406 index 4a74ea8..32335a7 100644
103407 --- a/net/ipv4/fib_semantics.c
103408 +++ b/net/ipv4/fib_semantics.c
103409 @@ -768,7 +768,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
103410 nh->nh_saddr = inet_select_addr(nh->nh_dev,
103411 nh->nh_gw,
103412 nh->nh_parent->fib_scope);
103413 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
103414 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
103415
103416 return nh->nh_saddr;
103417 }
103418 diff --git a/net/ipv4/gre_offload.c b/net/ipv4/gre_offload.c
103419 index 657d80c..0ad744a 100644
103420 --- a/net/ipv4/gre_offload.c
103421 +++ b/net/ipv4/gre_offload.c
103422 @@ -59,13 +59,13 @@ static struct sk_buff *gre_gso_segment(struct sk_buff *skb,
103423 if (csum)
103424 skb->encap_hdr_csum = 1;
103425
103426 - if (unlikely(!pskb_may_pull(skb, ghl)))
103427 - goto out;
103428 -
103429 /* setup inner skb. */
103430 skb->protocol = greh->protocol;
103431 skb->encapsulation = 0;
103432
103433 + if (unlikely(!pskb_may_pull(skb, ghl)))
103434 + goto out;
103435 +
103436 __skb_pull(skb, ghl);
103437 skb_reset_mac_header(skb);
103438 skb_set_network_header(skb, skb_inner_network_offset(skb));
103439 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
103440 index 43116e8..ba0916a8 100644
103441 --- a/net/ipv4/inet_hashtables.c
103442 +++ b/net/ipv4/inet_hashtables.c
103443 @@ -18,6 +18,7 @@
103444 #include <linux/sched.h>
103445 #include <linux/slab.h>
103446 #include <linux/wait.h>
103447 +#include <linux/security.h>
103448
103449 #include <net/inet_connection_sock.h>
103450 #include <net/inet_hashtables.h>
103451 @@ -49,6 +50,8 @@ static unsigned int inet_sk_ehashfn(const struct sock *sk)
103452 return inet_ehashfn(net, laddr, lport, faddr, fport);
103453 }
103454
103455 +extern void gr_update_task_in_ip_table(const struct inet_sock *inet);
103456 +
103457 /*
103458 * Allocate and initialize a new local port bind bucket.
103459 * The bindhash mutex for snum's hash chain must be held here.
103460 @@ -554,6 +557,8 @@ ok:
103461 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
103462 spin_unlock(&head->lock);
103463
103464 + gr_update_task_in_ip_table(inet_sk(sk));
103465 +
103466 if (tw) {
103467 inet_twsk_deschedule(tw, death_row);
103468 while (twrefcnt) {
103469 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
103470 index bd5f592..e80e605 100644
103471 --- a/net/ipv4/inetpeer.c
103472 +++ b/net/ipv4/inetpeer.c
103473 @@ -482,7 +482,7 @@ relookup:
103474 if (p) {
103475 p->daddr = *daddr;
103476 atomic_set(&p->refcnt, 1);
103477 - atomic_set(&p->rid, 0);
103478 + atomic_set_unchecked(&p->rid, 0);
103479 p->metrics[RTAX_LOCK-1] = INETPEER_METRICS_NEW;
103480 p->rate_tokens = 0;
103481 /* 60*HZ is arbitrary, but chosen enough high so that the first
103482 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
103483 index 15f0e2b..8cf8177 100644
103484 --- a/net/ipv4/ip_fragment.c
103485 +++ b/net/ipv4/ip_fragment.c
103486 @@ -268,7 +268,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
103487 return 0;
103488
103489 start = qp->rid;
103490 - end = atomic_inc_return(&peer->rid);
103491 + end = atomic_inc_return_unchecked(&peer->rid);
103492 qp->rid = end;
103493
103494 rc = qp->q.fragments && (end - start) > max;
103495 @@ -746,12 +746,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
103496
103497 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
103498 {
103499 - struct ctl_table *table;
103500 + ctl_table_no_const *table = NULL;
103501 struct ctl_table_header *hdr;
103502
103503 - table = ip4_frags_ns_ctl_table;
103504 if (!net_eq(net, &init_net)) {
103505 - table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
103506 + table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
103507 if (table == NULL)
103508 goto err_alloc;
103509
103510 @@ -765,9 +764,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
103511 /* Don't export sysctls to unprivileged users */
103512 if (net->user_ns != &init_user_ns)
103513 table[0].procname = NULL;
103514 - }
103515 + hdr = register_net_sysctl(net, "net/ipv4", table);
103516 + } else
103517 + hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
103518
103519 - hdr = register_net_sysctl(net, "net/ipv4", table);
103520 if (hdr == NULL)
103521 goto err_reg;
103522
103523 @@ -775,8 +775,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
103524 return 0;
103525
103526 err_reg:
103527 - if (!net_eq(net, &init_net))
103528 - kfree(table);
103529 + kfree(table);
103530 err_alloc:
103531 return -ENOMEM;
103532 }
103533 diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
103534 index 9b84254..c776611 100644
103535 --- a/net/ipv4/ip_gre.c
103536 +++ b/net/ipv4/ip_gre.c
103537 @@ -115,7 +115,7 @@ static bool log_ecn_error = true;
103538 module_param(log_ecn_error, bool, 0644);
103539 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
103540
103541 -static struct rtnl_link_ops ipgre_link_ops __read_mostly;
103542 +static struct rtnl_link_ops ipgre_link_ops;
103543 static int ipgre_tunnel_init(struct net_device *dev);
103544
103545 static int ipgre_net_id __read_mostly;
103546 @@ -733,7 +733,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
103547 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
103548 };
103549
103550 -static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
103551 +static struct rtnl_link_ops ipgre_link_ops = {
103552 .kind = "gre",
103553 .maxtype = IFLA_GRE_MAX,
103554 .policy = ipgre_policy,
103555 @@ -747,7 +747,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
103556 .fill_info = ipgre_fill_info,
103557 };
103558
103559 -static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
103560 +static struct rtnl_link_ops ipgre_tap_ops = {
103561 .kind = "gretap",
103562 .maxtype = IFLA_GRE_MAX,
103563 .policy = ipgre_policy,
103564 diff --git a/net/ipv4/ip_input.c b/net/ipv4/ip_input.c
103565 index 3d4da2c..40f9c29 100644
103566 --- a/net/ipv4/ip_input.c
103567 +++ b/net/ipv4/ip_input.c
103568 @@ -147,6 +147,10 @@
103569 #include <linux/mroute.h>
103570 #include <linux/netlink.h>
103571
103572 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103573 +extern int grsec_enable_blackhole;
103574 +#endif
103575 +
103576 /*
103577 * Process Router Attention IP option (RFC 2113)
103578 */
103579 @@ -223,6 +227,9 @@ static int ip_local_deliver_finish(struct sk_buff *skb)
103580 if (!raw) {
103581 if (xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb)) {
103582 IP_INC_STATS_BH(net, IPSTATS_MIB_INUNKNOWNPROTOS);
103583 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103584 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
103585 +#endif
103586 icmp_send(skb, ICMP_DEST_UNREACH,
103587 ICMP_PROT_UNREACH, 0);
103588 }
103589 diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c
103590 index c43a1e2..73cbbe1 100644
103591 --- a/net/ipv4/ip_output.c
103592 +++ b/net/ipv4/ip_output.c
103593 @@ -231,7 +231,7 @@ static int ip_finish_output_gso(struct sk_buff *skb)
103594 */
103595 features = netif_skb_features(skb);
103596 segs = skb_gso_segment(skb, features & ~NETIF_F_GSO_MASK);
103597 - if (IS_ERR(segs)) {
103598 + if (IS_ERR_OR_NULL(segs)) {
103599 kfree_skb(skb);
103600 return -ENOMEM;
103601 }
103602 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
103603 index 2407e5d..edc2f1a 100644
103604 --- a/net/ipv4/ip_sockglue.c
103605 +++ b/net/ipv4/ip_sockglue.c
103606 @@ -1188,7 +1188,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
103607 len = min_t(unsigned int, len, opt->optlen);
103608 if (put_user(len, optlen))
103609 return -EFAULT;
103610 - if (copy_to_user(optval, opt->__data, len))
103611 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
103612 + copy_to_user(optval, opt->__data, len))
103613 return -EFAULT;
103614 return 0;
103615 }
103616 @@ -1319,7 +1320,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
103617 if (sk->sk_type != SOCK_STREAM)
103618 return -ENOPROTOOPT;
103619
103620 - msg.msg_control = (__force void *) optval;
103621 + msg.msg_control = (__force_kernel void *) optval;
103622 msg.msg_controllen = len;
103623 msg.msg_flags = flags;
103624
103625 diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
103626 index 6073952..8449cf5 100644
103627 --- a/net/ipv4/ip_vti.c
103628 +++ b/net/ipv4/ip_vti.c
103629 @@ -45,7 +45,7 @@
103630 #include <net/net_namespace.h>
103631 #include <net/netns/generic.h>
103632
103633 -static struct rtnl_link_ops vti_link_ops __read_mostly;
103634 +static struct rtnl_link_ops vti_link_ops;
103635
103636 static int vti_net_id __read_mostly;
103637 static int vti_tunnel_init(struct net_device *dev);
103638 @@ -519,7 +519,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
103639 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
103640 };
103641
103642 -static struct rtnl_link_ops vti_link_ops __read_mostly = {
103643 +static struct rtnl_link_ops vti_link_ops = {
103644 .kind = "vti",
103645 .maxtype = IFLA_VTI_MAX,
103646 .policy = vti_policy,
103647 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
103648 index 5bbef4f..5bc4fb6 100644
103649 --- a/net/ipv4/ipconfig.c
103650 +++ b/net/ipv4/ipconfig.c
103651 @@ -332,7 +332,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
103652
103653 mm_segment_t oldfs = get_fs();
103654 set_fs(get_ds());
103655 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
103656 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
103657 set_fs(oldfs);
103658 return res;
103659 }
103660 @@ -343,7 +343,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
103661
103662 mm_segment_t oldfs = get_fs();
103663 set_fs(get_ds());
103664 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
103665 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
103666 set_fs(oldfs);
103667 return res;
103668 }
103669 @@ -354,7 +354,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
103670
103671 mm_segment_t oldfs = get_fs();
103672 set_fs(get_ds());
103673 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
103674 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
103675 set_fs(oldfs);
103676 return res;
103677 }
103678 diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
103679 index 62eaa00..29b2dc2 100644
103680 --- a/net/ipv4/ipip.c
103681 +++ b/net/ipv4/ipip.c
103682 @@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
103683 static int ipip_net_id __read_mostly;
103684
103685 static int ipip_tunnel_init(struct net_device *dev);
103686 -static struct rtnl_link_ops ipip_link_ops __read_mostly;
103687 +static struct rtnl_link_ops ipip_link_ops;
103688
103689 static int ipip_err(struct sk_buff *skb, u32 info)
103690 {
103691 @@ -409,7 +409,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
103692 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
103693 };
103694
103695 -static struct rtnl_link_ops ipip_link_ops __read_mostly = {
103696 +static struct rtnl_link_ops ipip_link_ops = {
103697 .kind = "ipip",
103698 .maxtype = IFLA_IPTUN_MAX,
103699 .policy = ipip_policy,
103700 diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
103701 index f95b6f9..2ee2097 100644
103702 --- a/net/ipv4/netfilter/arp_tables.c
103703 +++ b/net/ipv4/netfilter/arp_tables.c
103704 @@ -885,14 +885,14 @@ static int compat_table_info(const struct xt_table_info *info,
103705 #endif
103706
103707 static int get_info(struct net *net, void __user *user,
103708 - const int *len, int compat)
103709 + int len, int compat)
103710 {
103711 char name[XT_TABLE_MAXNAMELEN];
103712 struct xt_table *t;
103713 int ret;
103714
103715 - if (*len != sizeof(struct arpt_getinfo)) {
103716 - duprintf("length %u != %Zu\n", *len,
103717 + if (len != sizeof(struct arpt_getinfo)) {
103718 + duprintf("length %u != %Zu\n", len,
103719 sizeof(struct arpt_getinfo));
103720 return -EINVAL;
103721 }
103722 @@ -929,7 +929,7 @@ static int get_info(struct net *net, void __user *user,
103723 info.size = private->size;
103724 strcpy(info.name, name);
103725
103726 - if (copy_to_user(user, &info, *len) != 0)
103727 + if (copy_to_user(user, &info, len) != 0)
103728 ret = -EFAULT;
103729 else
103730 ret = 0;
103731 @@ -1690,7 +1690,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
103732
103733 switch (cmd) {
103734 case ARPT_SO_GET_INFO:
103735 - ret = get_info(sock_net(sk), user, len, 1);
103736 + ret = get_info(sock_net(sk), user, *len, 1);
103737 break;
103738 case ARPT_SO_GET_ENTRIES:
103739 ret = compat_get_entries(sock_net(sk), user, len);
103740 @@ -1735,7 +1735,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
103741
103742 switch (cmd) {
103743 case ARPT_SO_GET_INFO:
103744 - ret = get_info(sock_net(sk), user, len, 0);
103745 + ret = get_info(sock_net(sk), user, *len, 0);
103746 break;
103747
103748 case ARPT_SO_GET_ENTRIES:
103749 diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
103750 index 99e810f..3711b81 100644
103751 --- a/net/ipv4/netfilter/ip_tables.c
103752 +++ b/net/ipv4/netfilter/ip_tables.c
103753 @@ -1073,14 +1073,14 @@ static int compat_table_info(const struct xt_table_info *info,
103754 #endif
103755
103756 static int get_info(struct net *net, void __user *user,
103757 - const int *len, int compat)
103758 + int len, int compat)
103759 {
103760 char name[XT_TABLE_MAXNAMELEN];
103761 struct xt_table *t;
103762 int ret;
103763
103764 - if (*len != sizeof(struct ipt_getinfo)) {
103765 - duprintf("length %u != %zu\n", *len,
103766 + if (len != sizeof(struct ipt_getinfo)) {
103767 + duprintf("length %u != %zu\n", len,
103768 sizeof(struct ipt_getinfo));
103769 return -EINVAL;
103770 }
103771 @@ -1117,7 +1117,7 @@ static int get_info(struct net *net, void __user *user,
103772 info.size = private->size;
103773 strcpy(info.name, name);
103774
103775 - if (copy_to_user(user, &info, *len) != 0)
103776 + if (copy_to_user(user, &info, len) != 0)
103777 ret = -EFAULT;
103778 else
103779 ret = 0;
103780 @@ -1973,7 +1973,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
103781
103782 switch (cmd) {
103783 case IPT_SO_GET_INFO:
103784 - ret = get_info(sock_net(sk), user, len, 1);
103785 + ret = get_info(sock_net(sk), user, *len, 1);
103786 break;
103787 case IPT_SO_GET_ENTRIES:
103788 ret = compat_get_entries(sock_net(sk), user, len);
103789 @@ -2020,7 +2020,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
103790
103791 switch (cmd) {
103792 case IPT_SO_GET_INFO:
103793 - ret = get_info(sock_net(sk), user, len, 0);
103794 + ret = get_info(sock_net(sk), user, *len, 0);
103795 break;
103796
103797 case IPT_SO_GET_ENTRIES:
103798 diff --git a/net/ipv4/netfilter/ipt_CLUSTERIP.c b/net/ipv4/netfilter/ipt_CLUSTERIP.c
103799 index 2510c02..cfb34fa 100644
103800 --- a/net/ipv4/netfilter/ipt_CLUSTERIP.c
103801 +++ b/net/ipv4/netfilter/ipt_CLUSTERIP.c
103802 @@ -720,7 +720,7 @@ static int clusterip_net_init(struct net *net)
103803 spin_lock_init(&cn->lock);
103804
103805 #ifdef CONFIG_PROC_FS
103806 - cn->procdir = proc_mkdir("ipt_CLUSTERIP", net->proc_net);
103807 + cn->procdir = proc_mkdir_restrict("ipt_CLUSTERIP", net->proc_net);
103808 if (!cn->procdir) {
103809 pr_err("Unable to proc dir entry\n");
103810 return -ENOMEM;
103811 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
103812 index b503a30..c43e3e1 100644
103813 --- a/net/ipv4/ping.c
103814 +++ b/net/ipv4/ping.c
103815 @@ -59,7 +59,7 @@ struct ping_table {
103816 };
103817
103818 static struct ping_table ping_table;
103819 -struct pingv6_ops pingv6_ops;
103820 +struct pingv6_ops *pingv6_ops;
103821 EXPORT_SYMBOL_GPL(pingv6_ops);
103822
103823 static u16 ping_port_rover;
103824 @@ -350,7 +350,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
103825 return -ENODEV;
103826 }
103827 }
103828 - has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
103829 + has_addr = pingv6_ops->ipv6_chk_addr(net, &addr->sin6_addr, dev,
103830 scoped);
103831 rcu_read_unlock();
103832
103833 @@ -558,7 +558,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
103834 }
103835 #if IS_ENABLED(CONFIG_IPV6)
103836 } else if (skb->protocol == htons(ETH_P_IPV6)) {
103837 - harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
103838 + harderr = pingv6_ops->icmpv6_err_convert(type, code, &err);
103839 #endif
103840 }
103841
103842 @@ -576,7 +576,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
103843 info, (u8 *)icmph);
103844 #if IS_ENABLED(CONFIG_IPV6)
103845 } else if (family == AF_INET6) {
103846 - pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
103847 + pingv6_ops->ipv6_icmp_error(sk, skb, err, 0,
103848 info, (u8 *)icmph);
103849 #endif
103850 }
103851 @@ -910,10 +910,10 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
103852 }
103853
103854 if (inet6_sk(sk)->rxopt.all)
103855 - pingv6_ops.ip6_datagram_recv_common_ctl(sk, msg, skb);
103856 + pingv6_ops->ip6_datagram_recv_common_ctl(sk, msg, skb);
103857 if (skb->protocol == htons(ETH_P_IPV6) &&
103858 inet6_sk(sk)->rxopt.all)
103859 - pingv6_ops.ip6_datagram_recv_specific_ctl(sk, msg, skb);
103860 + pingv6_ops->ip6_datagram_recv_specific_ctl(sk, msg, skb);
103861 else if (skb->protocol == htons(ETH_P_IP) && isk->cmsg_flags)
103862 ip_cmsg_recv(msg, skb);
103863 #endif
103864 @@ -1105,7 +1105,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
103865 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
103866 0, sock_i_ino(sp),
103867 atomic_read(&sp->sk_refcnt), sp,
103868 - atomic_read(&sp->sk_drops));
103869 + atomic_read_unchecked(&sp->sk_drops));
103870 }
103871
103872 static int ping_v4_seq_show(struct seq_file *seq, void *v)
103873 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
103874 index 739db31..74f0210 100644
103875 --- a/net/ipv4/raw.c
103876 +++ b/net/ipv4/raw.c
103877 @@ -314,7 +314,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
103878 int raw_rcv(struct sock *sk, struct sk_buff *skb)
103879 {
103880 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
103881 - atomic_inc(&sk->sk_drops);
103882 + atomic_inc_unchecked(&sk->sk_drops);
103883 kfree_skb(skb);
103884 return NET_RX_DROP;
103885 }
103886 @@ -755,16 +755,20 @@ static int raw_init(struct sock *sk)
103887
103888 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
103889 {
103890 + struct icmp_filter filter;
103891 +
103892 if (optlen > sizeof(struct icmp_filter))
103893 optlen = sizeof(struct icmp_filter);
103894 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
103895 + if (copy_from_user(&filter, optval, optlen))
103896 return -EFAULT;
103897 + raw_sk(sk)->filter = filter;
103898 return 0;
103899 }
103900
103901 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
103902 {
103903 int len, ret = -EFAULT;
103904 + struct icmp_filter filter;
103905
103906 if (get_user(len, optlen))
103907 goto out;
103908 @@ -774,8 +778,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
103909 if (len > sizeof(struct icmp_filter))
103910 len = sizeof(struct icmp_filter);
103911 ret = -EFAULT;
103912 - if (put_user(len, optlen) ||
103913 - copy_to_user(optval, &raw_sk(sk)->filter, len))
103914 + filter = raw_sk(sk)->filter;
103915 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
103916 goto out;
103917 ret = 0;
103918 out: return ret;
103919 @@ -1004,7 +1008,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
103920 0, 0L, 0,
103921 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
103922 0, sock_i_ino(sp),
103923 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
103924 + atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
103925 }
103926
103927 static int raw_seq_show(struct seq_file *seq, void *v)
103928 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
103929 index 29836f8..bd1e2ba 100644
103930 --- a/net/ipv4/route.c
103931 +++ b/net/ipv4/route.c
103932 @@ -228,7 +228,7 @@ static const struct seq_operations rt_cache_seq_ops = {
103933
103934 static int rt_cache_seq_open(struct inode *inode, struct file *file)
103935 {
103936 - return seq_open(file, &rt_cache_seq_ops);
103937 + return seq_open_restrict(file, &rt_cache_seq_ops);
103938 }
103939
103940 static const struct file_operations rt_cache_seq_fops = {
103941 @@ -319,7 +319,7 @@ static const struct seq_operations rt_cpu_seq_ops = {
103942
103943 static int rt_cpu_seq_open(struct inode *inode, struct file *file)
103944 {
103945 - return seq_open(file, &rt_cpu_seq_ops);
103946 + return seq_open_restrict(file, &rt_cpu_seq_ops);
103947 }
103948
103949 static const struct file_operations rt_cpu_seq_fops = {
103950 @@ -357,7 +357,7 @@ static int rt_acct_proc_show(struct seq_file *m, void *v)
103951
103952 static int rt_acct_proc_open(struct inode *inode, struct file *file)
103953 {
103954 - return single_open(file, rt_acct_proc_show, NULL);
103955 + return single_open_restrict(file, rt_acct_proc_show, NULL);
103956 }
103957
103958 static const struct file_operations rt_acct_proc_fops = {
103959 @@ -459,11 +459,11 @@ static struct neighbour *ipv4_neigh_lookup(const struct dst_entry *dst,
103960
103961 #define IP_IDENTS_SZ 2048u
103962 struct ip_ident_bucket {
103963 - atomic_t id;
103964 + atomic_unchecked_t id;
103965 u32 stamp32;
103966 };
103967
103968 -static struct ip_ident_bucket *ip_idents __read_mostly;
103969 +static struct ip_ident_bucket ip_idents[IP_IDENTS_SZ] __read_mostly;
103970
103971 /* In order to protect privacy, we add a perturbation to identifiers
103972 * if one generator is seldom used. This makes hard for an attacker
103973 @@ -479,7 +479,7 @@ u32 ip_idents_reserve(u32 hash, int segs)
103974 if (old != now && cmpxchg(&bucket->stamp32, old, now) == old)
103975 delta = prandom_u32_max(now - old);
103976
103977 - return atomic_add_return(segs + delta, &bucket->id) - segs;
103978 + return atomic_add_return_unchecked(segs + delta, &bucket->id) - segs;
103979 }
103980 EXPORT_SYMBOL(ip_idents_reserve);
103981
103982 @@ -2624,34 +2624,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
103983 .maxlen = sizeof(int),
103984 .mode = 0200,
103985 .proc_handler = ipv4_sysctl_rtcache_flush,
103986 + .extra1 = &init_net,
103987 },
103988 { },
103989 };
103990
103991 static __net_init int sysctl_route_net_init(struct net *net)
103992 {
103993 - struct ctl_table *tbl;
103994 + ctl_table_no_const *tbl = NULL;
103995
103996 - tbl = ipv4_route_flush_table;
103997 if (!net_eq(net, &init_net)) {
103998 - tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
103999 + tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
104000 if (tbl == NULL)
104001 goto err_dup;
104002
104003 /* Don't export sysctls to unprivileged users */
104004 if (net->user_ns != &init_user_ns)
104005 tbl[0].procname = NULL;
104006 - }
104007 - tbl[0].extra1 = net;
104008 + tbl[0].extra1 = net;
104009 + net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
104010 + } else
104011 + net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
104012
104013 - net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
104014 if (net->ipv4.route_hdr == NULL)
104015 goto err_reg;
104016 return 0;
104017
104018 err_reg:
104019 - if (tbl != ipv4_route_flush_table)
104020 - kfree(tbl);
104021 + kfree(tbl);
104022 err_dup:
104023 return -ENOMEM;
104024 }
104025 @@ -2674,8 +2674,8 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
104026
104027 static __net_init int rt_genid_init(struct net *net)
104028 {
104029 - atomic_set(&net->ipv4.rt_genid, 0);
104030 - atomic_set(&net->fnhe_genid, 0);
104031 + atomic_set_unchecked(&net->ipv4.rt_genid, 0);
104032 + atomic_set_unchecked(&net->fnhe_genid, 0);
104033 get_random_bytes(&net->ipv4.dev_addr_genid,
104034 sizeof(net->ipv4.dev_addr_genid));
104035 return 0;
104036 @@ -2718,11 +2718,7 @@ int __init ip_rt_init(void)
104037 {
104038 int rc = 0;
104039
104040 - ip_idents = kmalloc(IP_IDENTS_SZ * sizeof(*ip_idents), GFP_KERNEL);
104041 - if (!ip_idents)
104042 - panic("IP: failed to allocate ip_idents\n");
104043 -
104044 - prandom_bytes(ip_idents, IP_IDENTS_SZ * sizeof(*ip_idents));
104045 + prandom_bytes(ip_idents, sizeof(ip_idents));
104046
104047 #ifdef CONFIG_IP_ROUTE_CLASSID
104048 ip_rt_acct = __alloc_percpu(256 * sizeof(struct ip_rt_acct), __alignof__(struct ip_rt_acct));
104049 diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
104050 index 79a007c..5023029 100644
104051 --- a/net/ipv4/sysctl_net_ipv4.c
104052 +++ b/net/ipv4/sysctl_net_ipv4.c
104053 @@ -60,7 +60,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
104054 container_of(table->data, struct net, ipv4.ip_local_ports.range);
104055 int ret;
104056 int range[2];
104057 - struct ctl_table tmp = {
104058 + ctl_table_no_const tmp = {
104059 .data = &range,
104060 .maxlen = sizeof(range),
104061 .mode = table->mode,
104062 @@ -118,7 +118,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
104063 int ret;
104064 gid_t urange[2];
104065 kgid_t low, high;
104066 - struct ctl_table tmp = {
104067 + ctl_table_no_const tmp = {
104068 .data = &urange,
104069 .maxlen = sizeof(urange),
104070 .mode = table->mode,
104071 @@ -149,7 +149,7 @@ static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
104072 void __user *buffer, size_t *lenp, loff_t *ppos)
104073 {
104074 char val[TCP_CA_NAME_MAX];
104075 - struct ctl_table tbl = {
104076 + ctl_table_no_const tbl = {
104077 .data = val,
104078 .maxlen = TCP_CA_NAME_MAX,
104079 };
104080 @@ -168,7 +168,7 @@ static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
104081 void __user *buffer, size_t *lenp,
104082 loff_t *ppos)
104083 {
104084 - struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
104085 + ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
104086 int ret;
104087
104088 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
104089 @@ -185,7 +185,7 @@ static int proc_allowed_congestion_control(struct ctl_table *ctl,
104090 void __user *buffer, size_t *lenp,
104091 loff_t *ppos)
104092 {
104093 - struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
104094 + ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
104095 int ret;
104096
104097 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
104098 @@ -204,7 +204,7 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
104099 void __user *buffer, size_t *lenp,
104100 loff_t *ppos)
104101 {
104102 - struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
104103 + ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
104104 struct tcp_fastopen_context *ctxt;
104105 int ret;
104106 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
104107 @@ -857,13 +857,12 @@ static struct ctl_table ipv4_net_table[] = {
104108
104109 static __net_init int ipv4_sysctl_init_net(struct net *net)
104110 {
104111 - struct ctl_table *table;
104112 + ctl_table_no_const *table = NULL;
104113
104114 - table = ipv4_net_table;
104115 if (!net_eq(net, &init_net)) {
104116 int i;
104117
104118 - table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
104119 + table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
104120 if (table == NULL)
104121 goto err_alloc;
104122
104123 @@ -872,7 +871,10 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
104124 table[i].data += (void *)net - (void *)&init_net;
104125 }
104126
104127 - net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
104128 + if (!net_eq(net, &init_net))
104129 + net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
104130 + else
104131 + net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
104132 if (net->ipv4.ipv4_hdr == NULL)
104133 goto err_reg;
104134
104135 diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
104136 index a906e02..f3b6a0f 100644
104137 --- a/net/ipv4/tcp_input.c
104138 +++ b/net/ipv4/tcp_input.c
104139 @@ -755,7 +755,7 @@ static void tcp_update_pacing_rate(struct sock *sk)
104140 * without any lock. We want to make sure compiler wont store
104141 * intermediate values in this location.
104142 */
104143 - ACCESS_ONCE(sk->sk_pacing_rate) = min_t(u64, rate,
104144 + ACCESS_ONCE_RW(sk->sk_pacing_rate) = min_t(u64, rate,
104145 sk->sk_max_pacing_rate);
104146 }
104147
104148 @@ -4488,7 +4488,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
104149 * simplifies code)
104150 */
104151 static void
104152 -tcp_collapse(struct sock *sk, struct sk_buff_head *list,
104153 +__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
104154 struct sk_buff *head, struct sk_buff *tail,
104155 u32 start, u32 end)
104156 {
104157 @@ -5546,6 +5546,7 @@ discard:
104158 tcp_paws_reject(&tp->rx_opt, 0))
104159 goto discard_and_undo;
104160
104161 +#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
104162 if (th->syn) {
104163 /* We see SYN without ACK. It is attempt of
104164 * simultaneous connect with crossed SYNs.
104165 @@ -5596,6 +5597,7 @@ discard:
104166 goto discard;
104167 #endif
104168 }
104169 +#endif
104170 /* "fifth, if neither of the SYN or RST bits is set then
104171 * drop the segment and return."
104172 */
104173 @@ -5642,7 +5644,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
104174 goto discard;
104175
104176 if (th->syn) {
104177 - if (th->fin)
104178 + if (th->fin || th->urg || th->psh)
104179 goto discard;
104180 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
104181 return 1;
104182 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
104183 index 3f49eae..bde687a 100644
104184 --- a/net/ipv4/tcp_ipv4.c
104185 +++ b/net/ipv4/tcp_ipv4.c
104186 @@ -91,6 +91,10 @@ int sysctl_tcp_low_latency __read_mostly;
104187 EXPORT_SYMBOL(sysctl_tcp_low_latency);
104188
104189
104190 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104191 +extern int grsec_enable_blackhole;
104192 +#endif
104193 +
104194 #ifdef CONFIG_TCP_MD5SIG
104195 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
104196 __be32 daddr, __be32 saddr, const struct tcphdr *th);
104197 @@ -1487,6 +1491,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
104198 return 0;
104199
104200 reset:
104201 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104202 + if (!grsec_enable_blackhole)
104203 +#endif
104204 tcp_v4_send_reset(rsk, skb);
104205 discard:
104206 kfree_skb(skb);
104207 @@ -1633,12 +1640,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
104208 TCP_SKB_CB(skb)->sacked = 0;
104209
104210 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
104211 - if (!sk)
104212 + if (!sk) {
104213 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104214 + ret = 1;
104215 +#endif
104216 goto no_tcp_socket;
104217 -
104218 + }
104219 process:
104220 - if (sk->sk_state == TCP_TIME_WAIT)
104221 + if (sk->sk_state == TCP_TIME_WAIT) {
104222 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104223 + ret = 2;
104224 +#endif
104225 goto do_time_wait;
104226 + }
104227
104228 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
104229 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
104230 @@ -1704,6 +1718,10 @@ csum_error:
104231 bad_packet:
104232 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
104233 } else {
104234 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104235 + if (!grsec_enable_blackhole || (ret == 1 &&
104236 + (skb->dev->flags & IFF_LOOPBACK)))
104237 +#endif
104238 tcp_v4_send_reset(NULL, skb);
104239 }
104240
104241 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
104242 index 1649988..6251843 100644
104243 --- a/net/ipv4/tcp_minisocks.c
104244 +++ b/net/ipv4/tcp_minisocks.c
104245 @@ -27,6 +27,10 @@
104246 #include <net/inet_common.h>
104247 #include <net/xfrm.h>
104248
104249 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104250 +extern int grsec_enable_blackhole;
104251 +#endif
104252 +
104253 int sysctl_tcp_syncookies __read_mostly = 1;
104254 EXPORT_SYMBOL(sysctl_tcp_syncookies);
104255
104256 @@ -740,7 +744,10 @@ embryonic_reset:
104257 * avoid becoming vulnerable to outside attack aiming at
104258 * resetting legit local connections.
104259 */
104260 - req->rsk_ops->send_reset(sk, skb);
104261 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104262 + if (!grsec_enable_blackhole)
104263 +#endif
104264 + req->rsk_ops->send_reset(sk, skb);
104265 } else if (fastopen) { /* received a valid RST pkt */
104266 reqsk_fastopen_remove(sk, req, true);
104267 tcp_reset(sk);
104268 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
104269 index 3b66610..bfbe23a 100644
104270 --- a/net/ipv4/tcp_probe.c
104271 +++ b/net/ipv4/tcp_probe.c
104272 @@ -238,7 +238,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
104273 if (cnt + width >= len)
104274 break;
104275
104276 - if (copy_to_user(buf + cnt, tbuf, width))
104277 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
104278 return -EFAULT;
104279 cnt += width;
104280 }
104281 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
104282 index df90cd1..9ab2c9b 100644
104283 --- a/net/ipv4/tcp_timer.c
104284 +++ b/net/ipv4/tcp_timer.c
104285 @@ -22,6 +22,10 @@
104286 #include <linux/gfp.h>
104287 #include <net/tcp.h>
104288
104289 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104290 +extern int grsec_lastack_retries;
104291 +#endif
104292 +
104293 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
104294 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
104295 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
104296 @@ -192,6 +196,13 @@ static int tcp_write_timeout(struct sock *sk)
104297 }
104298 }
104299
104300 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104301 + if ((sk->sk_state == TCP_LAST_ACK) &&
104302 + (grsec_lastack_retries > 0) &&
104303 + (grsec_lastack_retries < retry_until))
104304 + retry_until = grsec_lastack_retries;
104305 +#endif
104306 +
104307 if (retransmits_timed_out(sk, retry_until,
104308 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
104309 /* Has it gone just too far? */
104310 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
104311 index f57c0e4..cf24bd0 100644
104312 --- a/net/ipv4/udp.c
104313 +++ b/net/ipv4/udp.c
104314 @@ -87,6 +87,7 @@
104315 #include <linux/types.h>
104316 #include <linux/fcntl.h>
104317 #include <linux/module.h>
104318 +#include <linux/security.h>
104319 #include <linux/socket.h>
104320 #include <linux/sockios.h>
104321 #include <linux/igmp.h>
104322 @@ -113,6 +114,10 @@
104323 #include <net/busy_poll.h>
104324 #include "udp_impl.h"
104325
104326 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104327 +extern int grsec_enable_blackhole;
104328 +#endif
104329 +
104330 struct udp_table udp_table __read_mostly;
104331 EXPORT_SYMBOL(udp_table);
104332
104333 @@ -594,6 +599,9 @@ static inline bool __udp_is_mcast_sock(struct net *net, struct sock *sk,
104334 return true;
104335 }
104336
104337 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
104338 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
104339 +
104340 /*
104341 * This routine is called by the ICMP module when it gets some
104342 * sort of error condition. If err < 0 then the socket should
104343 @@ -931,9 +939,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
104344 dport = usin->sin_port;
104345 if (dport == 0)
104346 return -EINVAL;
104347 +
104348 + err = gr_search_udp_sendmsg(sk, usin);
104349 + if (err)
104350 + return err;
104351 } else {
104352 if (sk->sk_state != TCP_ESTABLISHED)
104353 return -EDESTADDRREQ;
104354 +
104355 + err = gr_search_udp_sendmsg(sk, NULL);
104356 + if (err)
104357 + return err;
104358 +
104359 daddr = inet->inet_daddr;
104360 dport = inet->inet_dport;
104361 /* Open fast path for connected socket.
104362 @@ -1181,7 +1198,7 @@ static unsigned int first_packet_length(struct sock *sk)
104363 IS_UDPLITE(sk));
104364 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
104365 IS_UDPLITE(sk));
104366 - atomic_inc(&sk->sk_drops);
104367 + atomic_inc_unchecked(&sk->sk_drops);
104368 __skb_unlink(skb, rcvq);
104369 __skb_queue_tail(&list_kill, skb);
104370 }
104371 @@ -1261,6 +1278,10 @@ try_again:
104372 if (!skb)
104373 goto out;
104374
104375 + err = gr_search_udp_recvmsg(sk, skb);
104376 + if (err)
104377 + goto out_free;
104378 +
104379 ulen = skb->len - sizeof(struct udphdr);
104380 copied = len;
104381 if (copied > ulen)
104382 @@ -1294,7 +1315,7 @@ try_again:
104383 if (unlikely(err)) {
104384 trace_kfree_skb(skb, udp_recvmsg);
104385 if (!peeked) {
104386 - atomic_inc(&sk->sk_drops);
104387 + atomic_inc_unchecked(&sk->sk_drops);
104388 UDP_INC_STATS_USER(sock_net(sk),
104389 UDP_MIB_INERRORS, is_udplite);
104390 }
104391 @@ -1591,7 +1612,7 @@ csum_error:
104392 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
104393 drop:
104394 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
104395 - atomic_inc(&sk->sk_drops);
104396 + atomic_inc_unchecked(&sk->sk_drops);
104397 kfree_skb(skb);
104398 return -1;
104399 }
104400 @@ -1610,7 +1631,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
104401 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
104402
104403 if (!skb1) {
104404 - atomic_inc(&sk->sk_drops);
104405 + atomic_inc_unchecked(&sk->sk_drops);
104406 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
104407 IS_UDPLITE(sk));
104408 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
104409 @@ -1807,6 +1828,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
104410 goto csum_error;
104411
104412 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
104413 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104414 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
104415 +#endif
104416 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
104417
104418 /*
104419 @@ -2393,7 +2417,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
104420 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
104421 0, sock_i_ino(sp),
104422 atomic_read(&sp->sk_refcnt), sp,
104423 - atomic_read(&sp->sk_drops));
104424 + atomic_read_unchecked(&sp->sk_drops));
104425 }
104426
104427 int udp4_seq_show(struct seq_file *seq, void *v)
104428 diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
104429 index 6156f68..d6ab46d 100644
104430 --- a/net/ipv4/xfrm4_policy.c
104431 +++ b/net/ipv4/xfrm4_policy.c
104432 @@ -186,11 +186,11 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
104433 fl4->flowi4_tos = iph->tos;
104434 }
104435
104436 -static inline int xfrm4_garbage_collect(struct dst_ops *ops)
104437 +static int xfrm4_garbage_collect(struct dst_ops *ops)
104438 {
104439 struct net *net = container_of(ops, struct net, xfrm.xfrm4_dst_ops);
104440
104441 - xfrm4_policy_afinfo.garbage_collect(net);
104442 + xfrm_garbage_collect_deferred(net);
104443 return (dst_entries_get_slow(ops) > ops->gc_thresh * 2);
104444 }
104445
104446 @@ -269,19 +269,18 @@ static struct ctl_table xfrm4_policy_table[] = {
104447
104448 static int __net_init xfrm4_net_init(struct net *net)
104449 {
104450 - struct ctl_table *table;
104451 + ctl_table_no_const *table = NULL;
104452 struct ctl_table_header *hdr;
104453
104454 - table = xfrm4_policy_table;
104455 if (!net_eq(net, &init_net)) {
104456 - table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
104457 + table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
104458 if (!table)
104459 goto err_alloc;
104460
104461 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
104462 - }
104463 -
104464 - hdr = register_net_sysctl(net, "net/ipv4", table);
104465 + hdr = register_net_sysctl(net, "net/ipv4", table);
104466 + } else
104467 + hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
104468 if (!hdr)
104469 goto err_reg;
104470
104471 @@ -289,8 +288,7 @@ static int __net_init xfrm4_net_init(struct net *net)
104472 return 0;
104473
104474 err_reg:
104475 - if (!net_eq(net, &init_net))
104476 - kfree(table);
104477 + kfree(table);
104478 err_alloc:
104479 return -ENOMEM;
104480 }
104481 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
104482 index 3e118df..288a0d1 100644
104483 --- a/net/ipv6/addrconf.c
104484 +++ b/net/ipv6/addrconf.c
104485 @@ -171,7 +171,7 @@ static struct ipv6_devconf ipv6_devconf __read_mostly = {
104486 .hop_limit = IPV6_DEFAULT_HOPLIMIT,
104487 .mtu6 = IPV6_MIN_MTU,
104488 .accept_ra = 1,
104489 - .accept_redirects = 1,
104490 + .accept_redirects = 0,
104491 .autoconf = 1,
104492 .force_mld_version = 0,
104493 .mldv1_unsolicited_report_interval = 10 * HZ,
104494 @@ -208,7 +208,7 @@ static struct ipv6_devconf ipv6_devconf_dflt __read_mostly = {
104495 .hop_limit = IPV6_DEFAULT_HOPLIMIT,
104496 .mtu6 = IPV6_MIN_MTU,
104497 .accept_ra = 1,
104498 - .accept_redirects = 1,
104499 + .accept_redirects = 0,
104500 .autoconf = 1,
104501 .force_mld_version = 0,
104502 .mldv1_unsolicited_report_interval = 10 * HZ,
104503 @@ -604,7 +604,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
104504 idx = 0;
104505 head = &net->dev_index_head[h];
104506 rcu_read_lock();
104507 - cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
104508 + cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
104509 net->dev_base_seq;
104510 hlist_for_each_entry_rcu(dev, head, index_hlist) {
104511 if (idx < s_idx)
104512 @@ -2396,7 +2396,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
104513 p.iph.ihl = 5;
104514 p.iph.protocol = IPPROTO_IPV6;
104515 p.iph.ttl = 64;
104516 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
104517 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
104518
104519 if (ops->ndo_do_ioctl) {
104520 mm_segment_t oldfs = get_fs();
104521 @@ -3531,16 +3531,23 @@ static const struct file_operations if6_fops = {
104522 .release = seq_release_net,
104523 };
104524
104525 +extern void register_ipv6_seq_ops_addr(struct seq_operations *addr);
104526 +extern void unregister_ipv6_seq_ops_addr(void);
104527 +
104528 static int __net_init if6_proc_net_init(struct net *net)
104529 {
104530 - if (!proc_create("if_inet6", S_IRUGO, net->proc_net, &if6_fops))
104531 + register_ipv6_seq_ops_addr(&if6_seq_ops);
104532 + if (!proc_create("if_inet6", S_IRUGO, net->proc_net, &if6_fops)) {
104533 + unregister_ipv6_seq_ops_addr();
104534 return -ENOMEM;
104535 + }
104536 return 0;
104537 }
104538
104539 static void __net_exit if6_proc_net_exit(struct net *net)
104540 {
104541 remove_proc_entry("if_inet6", net->proc_net);
104542 + unregister_ipv6_seq_ops_addr();
104543 }
104544
104545 static struct pernet_operations if6_proc_net_ops = {
104546 @@ -4156,7 +4163,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
104547 s_ip_idx = ip_idx = cb->args[2];
104548
104549 rcu_read_lock();
104550 - cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
104551 + cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
104552 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
104553 idx = 0;
104554 head = &net->dev_index_head[h];
104555 @@ -4784,7 +4791,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
104556 rt_genid_bump_ipv6(net);
104557 break;
104558 }
104559 - atomic_inc(&net->ipv6.dev_addr_genid);
104560 + atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
104561 }
104562
104563 static void ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
104564 @@ -4804,7 +4811,7 @@ int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
104565 int *valp = ctl->data;
104566 int val = *valp;
104567 loff_t pos = *ppos;
104568 - struct ctl_table lctl;
104569 + ctl_table_no_const lctl;
104570 int ret;
104571
104572 /*
104573 @@ -4889,7 +4896,7 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
104574 int *valp = ctl->data;
104575 int val = *valp;
104576 loff_t pos = *ppos;
104577 - struct ctl_table lctl;
104578 + ctl_table_no_const lctl;
104579 int ret;
104580
104581 /*
104582 diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
104583 index 2daa3a1..341066c 100644
104584 --- a/net/ipv6/af_inet6.c
104585 +++ b/net/ipv6/af_inet6.c
104586 @@ -766,7 +766,7 @@ static int __net_init inet6_net_init(struct net *net)
104587 net->ipv6.sysctl.icmpv6_time = 1*HZ;
104588 net->ipv6.sysctl.flowlabel_consistency = 1;
104589 net->ipv6.sysctl.auto_flowlabels = 0;
104590 - atomic_set(&net->ipv6.rt_genid, 0);
104591 + atomic_set_unchecked(&net->ipv6.rt_genid, 0);
104592
104593 err = ipv6_init_mibs(net);
104594 if (err)
104595 diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
104596 index 2753319..b7e625c 100644
104597 --- a/net/ipv6/datagram.c
104598 +++ b/net/ipv6/datagram.c
104599 @@ -939,5 +939,5 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
104600 0,
104601 sock_i_ino(sp),
104602 atomic_read(&sp->sk_refcnt), sp,
104603 - atomic_read(&sp->sk_drops));
104604 + atomic_read_unchecked(&sp->sk_drops));
104605 }
104606 diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
104607 index 06ba3e5..5c08d38 100644
104608 --- a/net/ipv6/icmp.c
104609 +++ b/net/ipv6/icmp.c
104610 @@ -993,7 +993,7 @@ static struct ctl_table ipv6_icmp_table_template[] = {
104611
104612 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
104613 {
104614 - struct ctl_table *table;
104615 + ctl_table_no_const *table;
104616
104617 table = kmemdup(ipv6_icmp_table_template,
104618 sizeof(ipv6_icmp_table_template),
104619 diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
104620 index 33d08ab..585b825 100644
104621 --- a/net/ipv6/ip6_gre.c
104622 +++ b/net/ipv6/ip6_gre.c
104623 @@ -71,8 +71,8 @@ struct ip6gre_net {
104624 struct net_device *fb_tunnel_dev;
104625 };
104626
104627 -static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
104628 -static struct rtnl_link_ops ip6gre_tap_ops __read_mostly;
104629 +static struct rtnl_link_ops ip6gre_link_ops;
104630 +static struct rtnl_link_ops ip6gre_tap_ops;
104631 static int ip6gre_tunnel_init(struct net_device *dev);
104632 static void ip6gre_tunnel_setup(struct net_device *dev);
104633 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
104634 @@ -1285,7 +1285,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
104635 }
104636
104637
104638 -static struct inet6_protocol ip6gre_protocol __read_mostly = {
104639 +static struct inet6_protocol ip6gre_protocol = {
104640 .handler = ip6gre_rcv,
104641 .err_handler = ip6gre_err,
104642 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
104643 @@ -1646,7 +1646,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
104644 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
104645 };
104646
104647 -static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
104648 +static struct rtnl_link_ops ip6gre_link_ops = {
104649 .kind = "ip6gre",
104650 .maxtype = IFLA_GRE_MAX,
104651 .policy = ip6gre_policy,
104652 @@ -1660,7 +1660,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
104653 .fill_info = ip6gre_fill_info,
104654 };
104655
104656 -static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
104657 +static struct rtnl_link_ops ip6gre_tap_ops = {
104658 .kind = "ip6gretap",
104659 .maxtype = IFLA_GRE_MAX,
104660 .policy = ip6gre_policy,
104661 diff --git a/net/ipv6/ip6_offload.c b/net/ipv6/ip6_offload.c
104662 index 65eda2a..620a102 100644
104663 --- a/net/ipv6/ip6_offload.c
104664 +++ b/net/ipv6/ip6_offload.c
104665 @@ -46,6 +46,7 @@ static int ipv6_gso_pull_exthdrs(struct sk_buff *skb, int proto)
104666 if (unlikely(!pskb_may_pull(skb, len)))
104667 break;
104668
104669 + opth = (void *)skb->data;
104670 proto = opth->nexthdr;
104671 __skb_pull(skb, len);
104672 }
104673 diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
104674 index d2eeb3b..c186e9a 100644
104675 --- a/net/ipv6/ip6_tunnel.c
104676 +++ b/net/ipv6/ip6_tunnel.c
104677 @@ -86,7 +86,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
104678
104679 static int ip6_tnl_dev_init(struct net_device *dev);
104680 static void ip6_tnl_dev_setup(struct net_device *dev);
104681 -static struct rtnl_link_ops ip6_link_ops __read_mostly;
104682 +static struct rtnl_link_ops ip6_link_ops;
104683
104684 static int ip6_tnl_net_id __read_mostly;
104685 struct ip6_tnl_net {
104686 @@ -1706,7 +1706,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
104687 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
104688 };
104689
104690 -static struct rtnl_link_ops ip6_link_ops __read_mostly = {
104691 +static struct rtnl_link_ops ip6_link_ops = {
104692 .kind = "ip6tnl",
104693 .maxtype = IFLA_IPTUN_MAX,
104694 .policy = ip6_tnl_policy,
104695 diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c
104696 index 3abcd4a..cefa215 100644
104697 --- a/net/ipv6/ip6_vti.c
104698 +++ b/net/ipv6/ip6_vti.c
104699 @@ -62,7 +62,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
104700
104701 static int vti6_dev_init(struct net_device *dev);
104702 static void vti6_dev_setup(struct net_device *dev);
104703 -static struct rtnl_link_ops vti6_link_ops __read_mostly;
104704 +static struct rtnl_link_ops vti6_link_ops;
104705
104706 static int vti6_net_id __read_mostly;
104707 struct vti6_net {
104708 @@ -981,7 +981,7 @@ static const struct nla_policy vti6_policy[IFLA_VTI_MAX + 1] = {
104709 [IFLA_VTI_OKEY] = { .type = NLA_U32 },
104710 };
104711
104712 -static struct rtnl_link_ops vti6_link_ops __read_mostly = {
104713 +static struct rtnl_link_ops vti6_link_ops = {
104714 .kind = "vti6",
104715 .maxtype = IFLA_VTI_MAX,
104716 .policy = vti6_policy,
104717 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
104718 index 0c28998..d0a2ecd 100644
104719 --- a/net/ipv6/ipv6_sockglue.c
104720 +++ b/net/ipv6/ipv6_sockglue.c
104721 @@ -995,7 +995,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
104722 if (sk->sk_type != SOCK_STREAM)
104723 return -ENOPROTOOPT;
104724
104725 - msg.msg_control = optval;
104726 + msg.msg_control = (void __force_kernel *)optval;
104727 msg.msg_controllen = len;
104728 msg.msg_flags = flags;
104729
104730 diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
104731 index e080fbb..412b3cf 100644
104732 --- a/net/ipv6/netfilter/ip6_tables.c
104733 +++ b/net/ipv6/netfilter/ip6_tables.c
104734 @@ -1083,14 +1083,14 @@ static int compat_table_info(const struct xt_table_info *info,
104735 #endif
104736
104737 static int get_info(struct net *net, void __user *user,
104738 - const int *len, int compat)
104739 + int len, int compat)
104740 {
104741 char name[XT_TABLE_MAXNAMELEN];
104742 struct xt_table *t;
104743 int ret;
104744
104745 - if (*len != sizeof(struct ip6t_getinfo)) {
104746 - duprintf("length %u != %zu\n", *len,
104747 + if (len != sizeof(struct ip6t_getinfo)) {
104748 + duprintf("length %u != %zu\n", len,
104749 sizeof(struct ip6t_getinfo));
104750 return -EINVAL;
104751 }
104752 @@ -1127,7 +1127,7 @@ static int get_info(struct net *net, void __user *user,
104753 info.size = private->size;
104754 strcpy(info.name, name);
104755
104756 - if (copy_to_user(user, &info, *len) != 0)
104757 + if (copy_to_user(user, &info, len) != 0)
104758 ret = -EFAULT;
104759 else
104760 ret = 0;
104761 @@ -1983,7 +1983,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
104762
104763 switch (cmd) {
104764 case IP6T_SO_GET_INFO:
104765 - ret = get_info(sock_net(sk), user, len, 1);
104766 + ret = get_info(sock_net(sk), user, *len, 1);
104767 break;
104768 case IP6T_SO_GET_ENTRIES:
104769 ret = compat_get_entries(sock_net(sk), user, len);
104770 @@ -2030,7 +2030,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
104771
104772 switch (cmd) {
104773 case IP6T_SO_GET_INFO:
104774 - ret = get_info(sock_net(sk), user, len, 0);
104775 + ret = get_info(sock_net(sk), user, *len, 0);
104776 break;
104777
104778 case IP6T_SO_GET_ENTRIES:
104779 diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
104780 index 6f187c8..34b367f 100644
104781 --- a/net/ipv6/netfilter/nf_conntrack_reasm.c
104782 +++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
104783 @@ -96,12 +96,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
104784
104785 static int nf_ct_frag6_sysctl_register(struct net *net)
104786 {
104787 - struct ctl_table *table;
104788 + ctl_table_no_const *table = NULL;
104789 struct ctl_table_header *hdr;
104790
104791 - table = nf_ct_frag6_sysctl_table;
104792 if (!net_eq(net, &init_net)) {
104793 - table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
104794 + table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
104795 GFP_KERNEL);
104796 if (table == NULL)
104797 goto err_alloc;
104798 @@ -112,9 +111,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
104799 table[2].data = &net->nf_frag.frags.high_thresh;
104800 table[2].extra1 = &net->nf_frag.frags.low_thresh;
104801 table[2].extra2 = &init_net.nf_frag.frags.high_thresh;
104802 - }
104803 -
104804 - hdr = register_net_sysctl(net, "net/netfilter", table);
104805 + hdr = register_net_sysctl(net, "net/netfilter", table);
104806 + } else
104807 + hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
104808 if (hdr == NULL)
104809 goto err_reg;
104810
104811 @@ -122,8 +121,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
104812 return 0;
104813
104814 err_reg:
104815 - if (!net_eq(net, &init_net))
104816 - kfree(table);
104817 + kfree(table);
104818 err_alloc:
104819 return -ENOMEM;
104820 }
104821 diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
104822 index 5b7a1ed..d9da205 100644
104823 --- a/net/ipv6/ping.c
104824 +++ b/net/ipv6/ping.c
104825 @@ -240,6 +240,24 @@ static struct pernet_operations ping_v6_net_ops = {
104826 };
104827 #endif
104828
104829 +static struct pingv6_ops real_pingv6_ops = {
104830 + .ipv6_recv_error = ipv6_recv_error,
104831 + .ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl,
104832 + .ip6_datagram_recv_specific_ctl = ip6_datagram_recv_specific_ctl,
104833 + .icmpv6_err_convert = icmpv6_err_convert,
104834 + .ipv6_icmp_error = ipv6_icmp_error,
104835 + .ipv6_chk_addr = ipv6_chk_addr,
104836 +};
104837 +
104838 +static struct pingv6_ops dummy_pingv6_ops = {
104839 + .ipv6_recv_error = dummy_ipv6_recv_error,
104840 + .ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl,
104841 + .ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl,
104842 + .icmpv6_err_convert = dummy_icmpv6_err_convert,
104843 + .ipv6_icmp_error = dummy_ipv6_icmp_error,
104844 + .ipv6_chk_addr = dummy_ipv6_chk_addr,
104845 +};
104846 +
104847 int __init pingv6_init(void)
104848 {
104849 #ifdef CONFIG_PROC_FS
104850 @@ -247,13 +265,7 @@ int __init pingv6_init(void)
104851 if (ret)
104852 return ret;
104853 #endif
104854 - pingv6_ops.ipv6_recv_error = ipv6_recv_error;
104855 - pingv6_ops.ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl;
104856 - pingv6_ops.ip6_datagram_recv_specific_ctl =
104857 - ip6_datagram_recv_specific_ctl;
104858 - pingv6_ops.icmpv6_err_convert = icmpv6_err_convert;
104859 - pingv6_ops.ipv6_icmp_error = ipv6_icmp_error;
104860 - pingv6_ops.ipv6_chk_addr = ipv6_chk_addr;
104861 + pingv6_ops = &real_pingv6_ops;
104862 return inet6_register_protosw(&pingv6_protosw);
104863 }
104864
104865 @@ -262,14 +274,9 @@ int __init pingv6_init(void)
104866 */
104867 void pingv6_exit(void)
104868 {
104869 - pingv6_ops.ipv6_recv_error = dummy_ipv6_recv_error;
104870 - pingv6_ops.ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl;
104871 - pingv6_ops.ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl;
104872 - pingv6_ops.icmpv6_err_convert = dummy_icmpv6_err_convert;
104873 - pingv6_ops.ipv6_icmp_error = dummy_ipv6_icmp_error;
104874 - pingv6_ops.ipv6_chk_addr = dummy_ipv6_chk_addr;
104875 #ifdef CONFIG_PROC_FS
104876 unregister_pernet_subsys(&ping_v6_net_ops);
104877 #endif
104878 + pingv6_ops = &dummy_pingv6_ops;
104879 inet6_unregister_protosw(&pingv6_protosw);
104880 }
104881 diff --git a/net/ipv6/proc.c b/net/ipv6/proc.c
104882 index 2d6f860..b0165f5 100644
104883 --- a/net/ipv6/proc.c
104884 +++ b/net/ipv6/proc.c
104885 @@ -309,7 +309,7 @@ static int __net_init ipv6_proc_init_net(struct net *net)
104886 if (!proc_create("snmp6", S_IRUGO, net->proc_net, &snmp6_seq_fops))
104887 goto proc_snmp6_fail;
104888
104889 - net->mib.proc_net_devsnmp6 = proc_mkdir("dev_snmp6", net->proc_net);
104890 + net->mib.proc_net_devsnmp6 = proc_mkdir_restrict("dev_snmp6", net->proc_net);
104891 if (!net->mib.proc_net_devsnmp6)
104892 goto proc_dev_snmp6_fail;
104893 return 0;
104894 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
104895 index 39d4422..b0979547 100644
104896 --- a/net/ipv6/raw.c
104897 +++ b/net/ipv6/raw.c
104898 @@ -388,7 +388,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
104899 {
104900 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
104901 skb_checksum_complete(skb)) {
104902 - atomic_inc(&sk->sk_drops);
104903 + atomic_inc_unchecked(&sk->sk_drops);
104904 kfree_skb(skb);
104905 return NET_RX_DROP;
104906 }
104907 @@ -416,7 +416,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
104908 struct raw6_sock *rp = raw6_sk(sk);
104909
104910 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
104911 - atomic_inc(&sk->sk_drops);
104912 + atomic_inc_unchecked(&sk->sk_drops);
104913 kfree_skb(skb);
104914 return NET_RX_DROP;
104915 }
104916 @@ -440,7 +440,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
104917
104918 if (inet->hdrincl) {
104919 if (skb_checksum_complete(skb)) {
104920 - atomic_inc(&sk->sk_drops);
104921 + atomic_inc_unchecked(&sk->sk_drops);
104922 kfree_skb(skb);
104923 return NET_RX_DROP;
104924 }
104925 @@ -608,7 +608,7 @@ out:
104926 return err;
104927 }
104928
104929 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
104930 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
104931 struct flowi6 *fl6, struct dst_entry **dstp,
104932 unsigned int flags)
104933 {
104934 @@ -914,12 +914,15 @@ do_confirm:
104935 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
104936 char __user *optval, int optlen)
104937 {
104938 + struct icmp6_filter filter;
104939 +
104940 switch (optname) {
104941 case ICMPV6_FILTER:
104942 if (optlen > sizeof(struct icmp6_filter))
104943 optlen = sizeof(struct icmp6_filter);
104944 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
104945 + if (copy_from_user(&filter, optval, optlen))
104946 return -EFAULT;
104947 + raw6_sk(sk)->filter = filter;
104948 return 0;
104949 default:
104950 return -ENOPROTOOPT;
104951 @@ -932,6 +935,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
104952 char __user *optval, int __user *optlen)
104953 {
104954 int len;
104955 + struct icmp6_filter filter;
104956
104957 switch (optname) {
104958 case ICMPV6_FILTER:
104959 @@ -943,7 +947,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
104960 len = sizeof(struct icmp6_filter);
104961 if (put_user(len, optlen))
104962 return -EFAULT;
104963 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
104964 + filter = raw6_sk(sk)->filter;
104965 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
104966 return -EFAULT;
104967 return 0;
104968 default:
104969 diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
104970 index c6557d9..173e728 100644
104971 --- a/net/ipv6/reassembly.c
104972 +++ b/net/ipv6/reassembly.c
104973 @@ -627,12 +627,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
104974
104975 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
104976 {
104977 - struct ctl_table *table;
104978 + ctl_table_no_const *table = NULL;
104979 struct ctl_table_header *hdr;
104980
104981 - table = ip6_frags_ns_ctl_table;
104982 if (!net_eq(net, &init_net)) {
104983 - table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
104984 + table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
104985 if (table == NULL)
104986 goto err_alloc;
104987
104988 @@ -646,9 +645,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
104989 /* Don't export sysctls to unprivileged users */
104990 if (net->user_ns != &init_user_ns)
104991 table[0].procname = NULL;
104992 - }
104993 + hdr = register_net_sysctl(net, "net/ipv6", table);
104994 + } else
104995 + hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
104996
104997 - hdr = register_net_sysctl(net, "net/ipv6", table);
104998 if (hdr == NULL)
104999 goto err_reg;
105000
105001 @@ -656,8 +656,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
105002 return 0;
105003
105004 err_reg:
105005 - if (!net_eq(net, &init_net))
105006 - kfree(table);
105007 + kfree(table);
105008 err_alloc:
105009 return -ENOMEM;
105010 }
105011 diff --git a/net/ipv6/route.c b/net/ipv6/route.c
105012 index bafde82..af2c91f 100644
105013 --- a/net/ipv6/route.c
105014 +++ b/net/ipv6/route.c
105015 @@ -2967,7 +2967,7 @@ struct ctl_table ipv6_route_table_template[] = {
105016
105017 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
105018 {
105019 - struct ctl_table *table;
105020 + ctl_table_no_const *table;
105021
105022 table = kmemdup(ipv6_route_table_template,
105023 sizeof(ipv6_route_table_template),
105024 diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
105025 index ca1c7c4..37fba59 100644
105026 --- a/net/ipv6/sit.c
105027 +++ b/net/ipv6/sit.c
105028 @@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
105029 static void ipip6_dev_free(struct net_device *dev);
105030 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
105031 __be32 *v4dst);
105032 -static struct rtnl_link_ops sit_link_ops __read_mostly;
105033 +static struct rtnl_link_ops sit_link_ops;
105034
105035 static int sit_net_id __read_mostly;
105036 struct sit_net {
105037 @@ -484,11 +484,11 @@ static void ipip6_tunnel_uninit(struct net_device *dev)
105038 */
105039 static int ipip6_err_gen_icmpv6_unreach(struct sk_buff *skb)
105040 {
105041 - const struct iphdr *iph = (const struct iphdr *) skb->data;
105042 + int ihl = ((const struct iphdr *)skb->data)->ihl*4;
105043 struct rt6_info *rt;
105044 struct sk_buff *skb2;
105045
105046 - if (!pskb_may_pull(skb, iph->ihl * 4 + sizeof(struct ipv6hdr) + 8))
105047 + if (!pskb_may_pull(skb, ihl + sizeof(struct ipv6hdr) + 8))
105048 return 1;
105049
105050 skb2 = skb_clone(skb, GFP_ATOMIC);
105051 @@ -497,7 +497,7 @@ static int ipip6_err_gen_icmpv6_unreach(struct sk_buff *skb)
105052 return 1;
105053
105054 skb_dst_drop(skb2);
105055 - skb_pull(skb2, iph->ihl * 4);
105056 + skb_pull(skb2, ihl);
105057 skb_reset_network_header(skb2);
105058
105059 rt = rt6_lookup(dev_net(skb->dev), &ipv6_hdr(skb2)->saddr, NULL, 0, 0);
105060 @@ -1659,7 +1659,7 @@ static void ipip6_dellink(struct net_device *dev, struct list_head *head)
105061 unregister_netdevice_queue(dev, head);
105062 }
105063
105064 -static struct rtnl_link_ops sit_link_ops __read_mostly = {
105065 +static struct rtnl_link_ops sit_link_ops = {
105066 .kind = "sit",
105067 .maxtype = IFLA_IPTUN_MAX,
105068 .policy = ipip6_policy,
105069 diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
105070 index 0c56c93..ece50df 100644
105071 --- a/net/ipv6/sysctl_net_ipv6.c
105072 +++ b/net/ipv6/sysctl_net_ipv6.c
105073 @@ -68,7 +68,7 @@ static struct ctl_table ipv6_rotable[] = {
105074
105075 static int __net_init ipv6_sysctl_net_init(struct net *net)
105076 {
105077 - struct ctl_table *ipv6_table;
105078 + ctl_table_no_const *ipv6_table;
105079 struct ctl_table *ipv6_route_table;
105080 struct ctl_table *ipv6_icmp_table;
105081 int err;
105082 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
105083 index 264c0f2..b6512c6 100644
105084 --- a/net/ipv6/tcp_ipv6.c
105085 +++ b/net/ipv6/tcp_ipv6.c
105086 @@ -102,6 +102,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
105087 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
105088 }
105089
105090 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
105091 +extern int grsec_enable_blackhole;
105092 +#endif
105093 +
105094 static void tcp_v6_hash(struct sock *sk)
105095 {
105096 if (sk->sk_state != TCP_CLOSE) {
105097 @@ -1333,6 +1337,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
105098 return 0;
105099
105100 reset:
105101 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
105102 + if (!grsec_enable_blackhole)
105103 +#endif
105104 tcp_v6_send_reset(sk, skb);
105105 discard:
105106 if (opt_skb)
105107 @@ -1417,12 +1424,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
105108 TCP_SKB_CB(skb)->sacked = 0;
105109
105110 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
105111 - if (!sk)
105112 + if (!sk) {
105113 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
105114 + ret = 1;
105115 +#endif
105116 goto no_tcp_socket;
105117 + }
105118
105119 process:
105120 - if (sk->sk_state == TCP_TIME_WAIT)
105121 + if (sk->sk_state == TCP_TIME_WAIT) {
105122 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
105123 + ret = 2;
105124 +#endif
105125 goto do_time_wait;
105126 + }
105127
105128 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
105129 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
105130 @@ -1479,6 +1494,10 @@ csum_error:
105131 bad_packet:
105132 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
105133 } else {
105134 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
105135 + if (!grsec_enable_blackhole || (ret == 1 &&
105136 + (skb->dev->flags & IFF_LOOPBACK)))
105137 +#endif
105138 tcp_v6_send_reset(NULL, skb);
105139 }
105140
105141 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
105142 index 4836af8..0e52bbd 100644
105143 --- a/net/ipv6/udp.c
105144 +++ b/net/ipv6/udp.c
105145 @@ -76,6 +76,10 @@ static unsigned int udp6_ehashfn(struct net *net,
105146 udp_ipv6_hash_secret + net_hash_mix(net));
105147 }
105148
105149 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
105150 +extern int grsec_enable_blackhole;
105151 +#endif
105152 +
105153 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
105154 {
105155 const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
105156 @@ -434,7 +438,7 @@ try_again:
105157 if (unlikely(err)) {
105158 trace_kfree_skb(skb, udpv6_recvmsg);
105159 if (!peeked) {
105160 - atomic_inc(&sk->sk_drops);
105161 + atomic_inc_unchecked(&sk->sk_drops);
105162 if (is_udp4)
105163 UDP_INC_STATS_USER(sock_net(sk),
105164 UDP_MIB_INERRORS,
105165 @@ -701,7 +705,7 @@ csum_error:
105166 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
105167 drop:
105168 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
105169 - atomic_inc(&sk->sk_drops);
105170 + atomic_inc_unchecked(&sk->sk_drops);
105171 kfree_skb(skb);
105172 return -1;
105173 }
105174 @@ -740,7 +744,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
105175 if (likely(skb1 == NULL))
105176 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
105177 if (!skb1) {
105178 - atomic_inc(&sk->sk_drops);
105179 + atomic_inc_unchecked(&sk->sk_drops);
105180 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
105181 IS_UDPLITE(sk));
105182 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
105183 @@ -915,6 +919,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
105184 goto csum_error;
105185
105186 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
105187 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
105188 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
105189 +#endif
105190 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
105191
105192 kfree_skb(skb);
105193 diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
105194 index 2a0bbda..fcd5396 100644
105195 --- a/net/ipv6/xfrm6_policy.c
105196 +++ b/net/ipv6/xfrm6_policy.c
105197 @@ -130,8 +130,8 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
105198 {
105199 struct flowi6 *fl6 = &fl->u.ip6;
105200 int onlyproto = 0;
105201 - u16 offset = skb_network_header_len(skb);
105202 const struct ipv6hdr *hdr = ipv6_hdr(skb);
105203 + u16 offset = sizeof(*hdr);
105204 struct ipv6_opt_hdr *exthdr;
105205 const unsigned char *nh = skb_network_header(skb);
105206 u8 nexthdr = nh[IP6CB(skb)->nhoff];
105207 @@ -170,8 +170,10 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
105208 case IPPROTO_DCCP:
105209 if (!onlyproto && (nh + offset + 4 < skb->data ||
105210 pskb_may_pull(skb, nh + offset + 4 - skb->data))) {
105211 - __be16 *ports = (__be16 *)exthdr;
105212 + __be16 *ports;
105213
105214 + nh = skb_network_header(skb);
105215 + ports = (__be16 *)(nh + offset);
105216 fl6->fl6_sport = ports[!!reverse];
105217 fl6->fl6_dport = ports[!reverse];
105218 }
105219 @@ -180,8 +182,10 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
105220
105221 case IPPROTO_ICMPV6:
105222 if (!onlyproto && pskb_may_pull(skb, nh + offset + 2 - skb->data)) {
105223 - u8 *icmp = (u8 *)exthdr;
105224 + u8 *icmp;
105225
105226 + nh = skb_network_header(skb);
105227 + icmp = (u8 *)(nh + offset);
105228 fl6->fl6_icmp_type = icmp[0];
105229 fl6->fl6_icmp_code = icmp[1];
105230 }
105231 @@ -192,8 +196,9 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
105232 case IPPROTO_MH:
105233 if (!onlyproto && pskb_may_pull(skb, nh + offset + 3 - skb->data)) {
105234 struct ip6_mh *mh;
105235 - mh = (struct ip6_mh *)exthdr;
105236
105237 + nh = skb_network_header(skb);
105238 + mh = (struct ip6_mh *)(nh + offset);
105239 fl6->fl6_mh_type = mh->ip6mh_type;
105240 }
105241 fl6->flowi6_proto = nexthdr;
105242 @@ -212,11 +217,11 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
105243 }
105244 }
105245
105246 -static inline int xfrm6_garbage_collect(struct dst_ops *ops)
105247 +static int xfrm6_garbage_collect(struct dst_ops *ops)
105248 {
105249 struct net *net = container_of(ops, struct net, xfrm.xfrm6_dst_ops);
105250
105251 - xfrm6_policy_afinfo.garbage_collect(net);
105252 + xfrm_garbage_collect_deferred(net);
105253 return dst_entries_get_fast(ops) > ops->gc_thresh * 2;
105254 }
105255
105256 @@ -329,19 +334,19 @@ static struct ctl_table xfrm6_policy_table[] = {
105257
105258 static int __net_init xfrm6_net_init(struct net *net)
105259 {
105260 - struct ctl_table *table;
105261 + ctl_table_no_const *table = NULL;
105262 struct ctl_table_header *hdr;
105263
105264 - table = xfrm6_policy_table;
105265 if (!net_eq(net, &init_net)) {
105266 - table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
105267 + table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
105268 if (!table)
105269 goto err_alloc;
105270
105271 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
105272 - }
105273 + hdr = register_net_sysctl(net, "net/ipv6", table);
105274 + } else
105275 + hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
105276
105277 - hdr = register_net_sysctl(net, "net/ipv6", table);
105278 if (!hdr)
105279 goto err_reg;
105280
105281 @@ -349,8 +354,7 @@ static int __net_init xfrm6_net_init(struct net *net)
105282 return 0;
105283
105284 err_reg:
105285 - if (!net_eq(net, &init_net))
105286 - kfree(table);
105287 + kfree(table);
105288 err_alloc:
105289 return -ENOMEM;
105290 }
105291 diff --git a/net/ipx/ipx_proc.c b/net/ipx/ipx_proc.c
105292 index e15c16a..7cf07aa 100644
105293 --- a/net/ipx/ipx_proc.c
105294 +++ b/net/ipx/ipx_proc.c
105295 @@ -289,7 +289,7 @@ int __init ipx_proc_init(void)
105296 struct proc_dir_entry *p;
105297 int rc = -ENOMEM;
105298
105299 - ipx_proc_dir = proc_mkdir("ipx", init_net.proc_net);
105300 + ipx_proc_dir = proc_mkdir_restrict("ipx", init_net.proc_net);
105301
105302 if (!ipx_proc_dir)
105303 goto out;
105304 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
105305 index 61ceb4c..e788eb8 100644
105306 --- a/net/irda/ircomm/ircomm_tty.c
105307 +++ b/net/irda/ircomm/ircomm_tty.c
105308 @@ -317,10 +317,10 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
105309 add_wait_queue(&port->open_wait, &wait);
105310
105311 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
105312 - __FILE__, __LINE__, tty->driver->name, port->count);
105313 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
105314
105315 spin_lock_irqsave(&port->lock, flags);
105316 - port->count--;
105317 + atomic_dec(&port->count);
105318 port->blocked_open++;
105319 spin_unlock_irqrestore(&port->lock, flags);
105320
105321 @@ -355,7 +355,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
105322 }
105323
105324 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
105325 - __FILE__, __LINE__, tty->driver->name, port->count);
105326 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
105327
105328 schedule();
105329 }
105330 @@ -365,12 +365,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
105331
105332 spin_lock_irqsave(&port->lock, flags);
105333 if (!tty_hung_up_p(filp))
105334 - port->count++;
105335 + atomic_inc(&port->count);
105336 port->blocked_open--;
105337 spin_unlock_irqrestore(&port->lock, flags);
105338
105339 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
105340 - __FILE__, __LINE__, tty->driver->name, port->count);
105341 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
105342
105343 if (!retval)
105344 port->flags |= ASYNC_NORMAL_ACTIVE;
105345 @@ -444,12 +444,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
105346
105347 /* ++ is not atomic, so this should be protected - Jean II */
105348 spin_lock_irqsave(&self->port.lock, flags);
105349 - self->port.count++;
105350 + atomic_inc(&self->port.count);
105351 spin_unlock_irqrestore(&self->port.lock, flags);
105352 tty_port_tty_set(&self->port, tty);
105353
105354 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
105355 - self->line, self->port.count);
105356 + self->line, atomic_read(&self->port.count));
105357
105358 /* Not really used by us, but lets do it anyway */
105359 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
105360 @@ -985,7 +985,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
105361 tty_kref_put(port->tty);
105362 }
105363 port->tty = NULL;
105364 - port->count = 0;
105365 + atomic_set(&port->count, 0);
105366 spin_unlock_irqrestore(&port->lock, flags);
105367
105368 wake_up_interruptible(&port->open_wait);
105369 @@ -1342,7 +1342,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
105370 seq_putc(m, '\n');
105371
105372 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
105373 - seq_printf(m, "Open count: %d\n", self->port.count);
105374 + seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
105375 seq_printf(m, "Max data size: %d\n", self->max_data_size);
105376 seq_printf(m, "Max header size: %d\n", self->max_header_size);
105377
105378 diff --git a/net/irda/irproc.c b/net/irda/irproc.c
105379 index b9ac598..f88cc56 100644
105380 --- a/net/irda/irproc.c
105381 +++ b/net/irda/irproc.c
105382 @@ -66,7 +66,7 @@ void __init irda_proc_register(void)
105383 {
105384 int i;
105385
105386 - proc_irda = proc_mkdir("irda", init_net.proc_net);
105387 + proc_irda = proc_mkdir_restrict("irda", init_net.proc_net);
105388 if (proc_irda == NULL)
105389 return;
105390
105391 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
105392 index a089b6b..3ca3b60 100644
105393 --- a/net/iucv/af_iucv.c
105394 +++ b/net/iucv/af_iucv.c
105395 @@ -686,10 +686,10 @@ static void __iucv_auto_name(struct iucv_sock *iucv)
105396 {
105397 char name[12];
105398
105399 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
105400 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
105401 while (__iucv_get_sock_by_name(name)) {
105402 sprintf(name, "%08x",
105403 - atomic_inc_return(&iucv_sk_list.autobind_name));
105404 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
105405 }
105406 memcpy(iucv->src_name, name, 8);
105407 }
105408 diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
105409 index da78793..bdd78cf 100644
105410 --- a/net/iucv/iucv.c
105411 +++ b/net/iucv/iucv.c
105412 @@ -702,7 +702,7 @@ static int iucv_cpu_notify(struct notifier_block *self,
105413 return NOTIFY_OK;
105414 }
105415
105416 -static struct notifier_block __refdata iucv_cpu_notifier = {
105417 +static struct notifier_block iucv_cpu_notifier = {
105418 .notifier_call = iucv_cpu_notify,
105419 };
105420
105421 diff --git a/net/key/af_key.c b/net/key/af_key.c
105422 index 1847ec4..26ef732 100644
105423 --- a/net/key/af_key.c
105424 +++ b/net/key/af_key.c
105425 @@ -3049,10 +3049,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
105426 static u32 get_acqseq(void)
105427 {
105428 u32 res;
105429 - static atomic_t acqseq;
105430 + static atomic_unchecked_t acqseq;
105431
105432 do {
105433 - res = atomic_inc_return(&acqseq);
105434 + res = atomic_inc_return_unchecked(&acqseq);
105435 } while (!res);
105436 return res;
105437 }
105438 diff --git a/net/l2tp/l2tp_eth.c b/net/l2tp/l2tp_eth.c
105439 index edb78e6..8dc654a 100644
105440 --- a/net/l2tp/l2tp_eth.c
105441 +++ b/net/l2tp/l2tp_eth.c
105442 @@ -42,12 +42,12 @@ struct l2tp_eth {
105443 struct sock *tunnel_sock;
105444 struct l2tp_session *session;
105445 struct list_head list;
105446 - atomic_long_t tx_bytes;
105447 - atomic_long_t tx_packets;
105448 - atomic_long_t tx_dropped;
105449 - atomic_long_t rx_bytes;
105450 - atomic_long_t rx_packets;
105451 - atomic_long_t rx_errors;
105452 + atomic_long_unchecked_t tx_bytes;
105453 + atomic_long_unchecked_t tx_packets;
105454 + atomic_long_unchecked_t tx_dropped;
105455 + atomic_long_unchecked_t rx_bytes;
105456 + atomic_long_unchecked_t rx_packets;
105457 + atomic_long_unchecked_t rx_errors;
105458 };
105459
105460 /* via l2tp_session_priv() */
105461 @@ -98,10 +98,10 @@ static int l2tp_eth_dev_xmit(struct sk_buff *skb, struct net_device *dev)
105462 int ret = l2tp_xmit_skb(session, skb, session->hdr_len);
105463
105464 if (likely(ret == NET_XMIT_SUCCESS)) {
105465 - atomic_long_add(len, &priv->tx_bytes);
105466 - atomic_long_inc(&priv->tx_packets);
105467 + atomic_long_add_unchecked(len, &priv->tx_bytes);
105468 + atomic_long_inc_unchecked(&priv->tx_packets);
105469 } else {
105470 - atomic_long_inc(&priv->tx_dropped);
105471 + atomic_long_inc_unchecked(&priv->tx_dropped);
105472 }
105473 return NETDEV_TX_OK;
105474 }
105475 @@ -111,12 +111,12 @@ static struct rtnl_link_stats64 *l2tp_eth_get_stats64(struct net_device *dev,
105476 {
105477 struct l2tp_eth *priv = netdev_priv(dev);
105478
105479 - stats->tx_bytes = atomic_long_read(&priv->tx_bytes);
105480 - stats->tx_packets = atomic_long_read(&priv->tx_packets);
105481 - stats->tx_dropped = atomic_long_read(&priv->tx_dropped);
105482 - stats->rx_bytes = atomic_long_read(&priv->rx_bytes);
105483 - stats->rx_packets = atomic_long_read(&priv->rx_packets);
105484 - stats->rx_errors = atomic_long_read(&priv->rx_errors);
105485 + stats->tx_bytes = atomic_long_read_unchecked(&priv->tx_bytes);
105486 + stats->tx_packets = atomic_long_read_unchecked(&priv->tx_packets);
105487 + stats->tx_dropped = atomic_long_read_unchecked(&priv->tx_dropped);
105488 + stats->rx_bytes = atomic_long_read_unchecked(&priv->rx_bytes);
105489 + stats->rx_packets = atomic_long_read_unchecked(&priv->rx_packets);
105490 + stats->rx_errors = atomic_long_read_unchecked(&priv->rx_errors);
105491 return stats;
105492 }
105493
105494 @@ -166,15 +166,15 @@ static void l2tp_eth_dev_recv(struct l2tp_session *session, struct sk_buff *skb,
105495 nf_reset(skb);
105496
105497 if (dev_forward_skb(dev, skb) == NET_RX_SUCCESS) {
105498 - atomic_long_inc(&priv->rx_packets);
105499 - atomic_long_add(data_len, &priv->rx_bytes);
105500 + atomic_long_inc_unchecked(&priv->rx_packets);
105501 + atomic_long_add_unchecked(data_len, &priv->rx_bytes);
105502 } else {
105503 - atomic_long_inc(&priv->rx_errors);
105504 + atomic_long_inc_unchecked(&priv->rx_errors);
105505 }
105506 return;
105507
105508 error:
105509 - atomic_long_inc(&priv->rx_errors);
105510 + atomic_long_inc_unchecked(&priv->rx_errors);
105511 kfree_skb(skb);
105512 }
105513
105514 diff --git a/net/llc/llc_proc.c b/net/llc/llc_proc.c
105515 index 1a3c7e0..80f8b0c 100644
105516 --- a/net/llc/llc_proc.c
105517 +++ b/net/llc/llc_proc.c
105518 @@ -247,7 +247,7 @@ int __init llc_proc_init(void)
105519 int rc = -ENOMEM;
105520 struct proc_dir_entry *p;
105521
105522 - llc_proc_dir = proc_mkdir("llc", init_net.proc_net);
105523 + llc_proc_dir = proc_mkdir_restrict("llc", init_net.proc_net);
105524 if (!llc_proc_dir)
105525 goto out;
105526
105527 diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
105528 index 927b4ea..88a30e2 100644
105529 --- a/net/mac80211/cfg.c
105530 +++ b/net/mac80211/cfg.c
105531 @@ -540,7 +540,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
105532 ret = ieee80211_vif_use_channel(sdata, chandef,
105533 IEEE80211_CHANCTX_EXCLUSIVE);
105534 }
105535 - } else if (local->open_count == local->monitors) {
105536 + } else if (local_read(&local->open_count) == local->monitors) {
105537 local->_oper_chandef = *chandef;
105538 ieee80211_hw_config(local, 0);
105539 }
105540 @@ -3286,7 +3286,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
105541 else
105542 local->probe_req_reg--;
105543
105544 - if (!local->open_count)
105545 + if (!local_read(&local->open_count))
105546 break;
105547
105548 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
105549 @@ -3420,8 +3420,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
105550 if (chanctx_conf) {
105551 *chandef = chanctx_conf->def;
105552 ret = 0;
105553 - } else if (local->open_count > 0 &&
105554 - local->open_count == local->monitors &&
105555 + } else if (local_read(&local->open_count) > 0 &&
105556 + local_read(&local->open_count) == local->monitors &&
105557 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
105558 if (local->use_chanctx)
105559 *chandef = local->monitor_chandef;
105560 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
105561 index 5d102b5..6199fca 100644
105562 --- a/net/mac80211/ieee80211_i.h
105563 +++ b/net/mac80211/ieee80211_i.h
105564 @@ -28,6 +28,7 @@
105565 #include <net/ieee80211_radiotap.h>
105566 #include <net/cfg80211.h>
105567 #include <net/mac80211.h>
105568 +#include <asm/local.h>
105569 #include "key.h"
105570 #include "sta_info.h"
105571 #include "debug.h"
105572 @@ -1055,7 +1056,7 @@ struct ieee80211_local {
105573 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
105574 spinlock_t queue_stop_reason_lock;
105575
105576 - int open_count;
105577 + local_t open_count;
105578 int monitors, cooked_mntrs;
105579 /* number of interfaces with corresponding FIF_ flags */
105580 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
105581 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
105582 index 3538e5e..0aa7879 100644
105583 --- a/net/mac80211/iface.c
105584 +++ b/net/mac80211/iface.c
105585 @@ -531,7 +531,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
105586 break;
105587 }
105588
105589 - if (local->open_count == 0) {
105590 + if (local_read(&local->open_count) == 0) {
105591 res = drv_start(local);
105592 if (res)
105593 goto err_del_bss;
105594 @@ -578,7 +578,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
105595 res = drv_add_interface(local, sdata);
105596 if (res)
105597 goto err_stop;
105598 - } else if (local->monitors == 0 && local->open_count == 0) {
105599 + } else if (local->monitors == 0 && local_read(&local->open_count) == 0) {
105600 res = ieee80211_add_virtual_monitor(local);
105601 if (res)
105602 goto err_stop;
105603 @@ -687,7 +687,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
105604 atomic_inc(&local->iff_promiscs);
105605
105606 if (coming_up)
105607 - local->open_count++;
105608 + local_inc(&local->open_count);
105609
105610 if (hw_reconf_flags)
105611 ieee80211_hw_config(local, hw_reconf_flags);
105612 @@ -725,7 +725,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
105613 err_del_interface:
105614 drv_remove_interface(local, sdata);
105615 err_stop:
105616 - if (!local->open_count)
105617 + if (!local_read(&local->open_count))
105618 drv_stop(local);
105619 err_del_bss:
105620 sdata->bss = NULL;
105621 @@ -891,7 +891,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
105622 }
105623
105624 if (going_down)
105625 - local->open_count--;
105626 + local_dec(&local->open_count);
105627
105628 switch (sdata->vif.type) {
105629 case NL80211_IFTYPE_AP_VLAN:
105630 @@ -952,7 +952,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
105631 }
105632 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
105633
105634 - if (local->open_count == 0)
105635 + if (local_read(&local->open_count) == 0)
105636 ieee80211_clear_tx_pending(local);
105637
105638 /*
105639 @@ -995,7 +995,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
105640 if (cancel_scan)
105641 flush_delayed_work(&local->scan_work);
105642
105643 - if (local->open_count == 0) {
105644 + if (local_read(&local->open_count) == 0) {
105645 ieee80211_stop_device(local);
105646
105647 /* no reconfiguring after stop! */
105648 @@ -1006,7 +1006,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
105649 ieee80211_configure_filter(local);
105650 ieee80211_hw_config(local, hw_reconf_flags);
105651
105652 - if (local->monitors == local->open_count)
105653 + if (local->monitors == local_read(&local->open_count))
105654 ieee80211_add_virtual_monitor(local);
105655 }
105656
105657 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
105658 index e0ab432..36b7b94 100644
105659 --- a/net/mac80211/main.c
105660 +++ b/net/mac80211/main.c
105661 @@ -174,7 +174,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
105662 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
105663 IEEE80211_CONF_CHANGE_POWER);
105664
105665 - if (changed && local->open_count) {
105666 + if (changed && local_read(&local->open_count)) {
105667 ret = drv_config(local, changed);
105668 /*
105669 * Goal:
105670 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
105671 index 4c5192e..04cc0d8 100644
105672 --- a/net/mac80211/pm.c
105673 +++ b/net/mac80211/pm.c
105674 @@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
105675 struct ieee80211_sub_if_data *sdata;
105676 struct sta_info *sta;
105677
105678 - if (!local->open_count)
105679 + if (!local_read(&local->open_count))
105680 goto suspend;
105681
105682 ieee80211_scan_cancel(local);
105683 @@ -59,7 +59,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
105684 cancel_work_sync(&local->dynamic_ps_enable_work);
105685 del_timer_sync(&local->dynamic_ps_timer);
105686
105687 - local->wowlan = wowlan && local->open_count;
105688 + local->wowlan = wowlan && local_read(&local->open_count);
105689 if (local->wowlan) {
105690 int err = drv_suspend(local, wowlan);
105691 if (err < 0) {
105692 @@ -125,7 +125,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
105693 WARN_ON(!list_empty(&local->chanctx_list));
105694
105695 /* stop hardware - this must stop RX */
105696 - if (local->open_count)
105697 + if (local_read(&local->open_count))
105698 ieee80211_stop_device(local);
105699
105700 suspend:
105701 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
105702 index 6081329..ab23834 100644
105703 --- a/net/mac80211/rate.c
105704 +++ b/net/mac80211/rate.c
105705 @@ -720,7 +720,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
105706
105707 ASSERT_RTNL();
105708
105709 - if (local->open_count)
105710 + if (local_read(&local->open_count))
105711 return -EBUSY;
105712
105713 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
105714 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
105715 index 725af7a..a21a20a 100644
105716 --- a/net/mac80211/util.c
105717 +++ b/net/mac80211/util.c
105718 @@ -1643,7 +1643,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
105719 }
105720 #endif
105721 /* everything else happens only if HW was up & running */
105722 - if (!local->open_count)
105723 + if (!local_read(&local->open_count))
105724 goto wake_up;
105725
105726 /*
105727 @@ -1869,7 +1869,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
105728 local->in_reconfig = false;
105729 barrier();
105730
105731 - if (local->monitors == local->open_count && local->monitors > 0)
105732 + if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
105733 ieee80211_add_virtual_monitor(local);
105734
105735 /*
105736 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
105737 index 6d77cce..36e2fc3 100644
105738 --- a/net/netfilter/Kconfig
105739 +++ b/net/netfilter/Kconfig
105740 @@ -1096,6 +1096,16 @@ config NETFILTER_XT_MATCH_ESP
105741
105742 To compile it as a module, choose M here. If unsure, say N.
105743
105744 +config NETFILTER_XT_MATCH_GRADM
105745 + tristate '"gradm" match support'
105746 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
105747 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
105748 + ---help---
105749 + The gradm match allows to match on grsecurity RBAC being enabled.
105750 + It is useful when iptables rules are applied early on bootup to
105751 + prevent connections to the machine (except from a trusted host)
105752 + while the RBAC system is disabled.
105753 +
105754 config NETFILTER_XT_MATCH_HASHLIMIT
105755 tristate '"hashlimit" match support'
105756 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
105757 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
105758 index fad5fdb..ba3672a 100644
105759 --- a/net/netfilter/Makefile
105760 +++ b/net/netfilter/Makefile
105761 @@ -136,6 +136,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
105762 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
105763 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
105764 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
105765 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
105766 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
105767 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
105768 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
105769 diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
105770 index 6582dce..a911da7 100644
105771 --- a/net/netfilter/ipset/ip_set_core.c
105772 +++ b/net/netfilter/ipset/ip_set_core.c
105773 @@ -1921,7 +1921,7 @@ done:
105774 return ret;
105775 }
105776
105777 -static struct nf_sockopt_ops so_set __read_mostly = {
105778 +static struct nf_sockopt_ops so_set = {
105779 .pf = PF_INET,
105780 .get_optmin = SO_IP_SET,
105781 .get_optmax = SO_IP_SET + 1,
105782 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
105783 index 610e19c..08d0c3f 100644
105784 --- a/net/netfilter/ipvs/ip_vs_conn.c
105785 +++ b/net/netfilter/ipvs/ip_vs_conn.c
105786 @@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
105787 /* Increase the refcnt counter of the dest */
105788 ip_vs_dest_hold(dest);
105789
105790 - conn_flags = atomic_read(&dest->conn_flags);
105791 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
105792 if (cp->protocol != IPPROTO_UDP)
105793 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
105794 flags = cp->flags;
105795 @@ -899,7 +899,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
105796
105797 cp->control = NULL;
105798 atomic_set(&cp->n_control, 0);
105799 - atomic_set(&cp->in_pkts, 0);
105800 + atomic_set_unchecked(&cp->in_pkts, 0);
105801
105802 cp->packet_xmit = NULL;
105803 cp->app = NULL;
105804 @@ -1187,7 +1187,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
105805
105806 /* Don't drop the entry if its number of incoming packets is not
105807 located in [0, 8] */
105808 - i = atomic_read(&cp->in_pkts);
105809 + i = atomic_read_unchecked(&cp->in_pkts);
105810 if (i > 8 || i < 0) return 0;
105811
105812 if (!todrop_rate[i]) return 0;
105813 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
105814 index 5c34e8d..0d8eb7f 100644
105815 --- a/net/netfilter/ipvs/ip_vs_core.c
105816 +++ b/net/netfilter/ipvs/ip_vs_core.c
105817 @@ -567,7 +567,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
105818 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
105819 /* do not touch skb anymore */
105820
105821 - atomic_inc(&cp->in_pkts);
105822 + atomic_inc_unchecked(&cp->in_pkts);
105823 ip_vs_conn_put(cp);
105824 return ret;
105825 }
105826 @@ -1711,7 +1711,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
105827 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
105828 pkts = sysctl_sync_threshold(ipvs);
105829 else
105830 - pkts = atomic_add_return(1, &cp->in_pkts);
105831 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
105832
105833 if (ipvs->sync_state & IP_VS_STATE_MASTER)
105834 ip_vs_sync_conn(net, cp, pkts);
105835 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
105836 index fd3f444..ab28fa24 100644
105837 --- a/net/netfilter/ipvs/ip_vs_ctl.c
105838 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
105839 @@ -794,7 +794,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
105840 */
105841 ip_vs_rs_hash(ipvs, dest);
105842 }
105843 - atomic_set(&dest->conn_flags, conn_flags);
105844 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
105845
105846 /* bind the service */
105847 old_svc = rcu_dereference_protected(dest->svc, 1);
105848 @@ -1654,7 +1654,7 @@ proc_do_sync_ports(struct ctl_table *table, int write,
105849 * align with netns init in ip_vs_control_net_init()
105850 */
105851
105852 -static struct ctl_table vs_vars[] = {
105853 +static ctl_table_no_const vs_vars[] __read_only = {
105854 {
105855 .procname = "amemthresh",
105856 .maxlen = sizeof(int),
105857 @@ -1989,7 +1989,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
105858 " %-7s %-6d %-10d %-10d\n",
105859 &dest->addr.in6,
105860 ntohs(dest->port),
105861 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
105862 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
105863 atomic_read(&dest->weight),
105864 atomic_read(&dest->activeconns),
105865 atomic_read(&dest->inactconns));
105866 @@ -2000,7 +2000,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
105867 "%-7s %-6d %-10d %-10d\n",
105868 ntohl(dest->addr.ip),
105869 ntohs(dest->port),
105870 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
105871 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
105872 atomic_read(&dest->weight),
105873 atomic_read(&dest->activeconns),
105874 atomic_read(&dest->inactconns));
105875 @@ -2471,7 +2471,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
105876
105877 entry.addr = dest->addr.ip;
105878 entry.port = dest->port;
105879 - entry.conn_flags = atomic_read(&dest->conn_flags);
105880 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
105881 entry.weight = atomic_read(&dest->weight);
105882 entry.u_threshold = dest->u_threshold;
105883 entry.l_threshold = dest->l_threshold;
105884 @@ -3010,7 +3010,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
105885 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
105886 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
105887 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
105888 - (atomic_read(&dest->conn_flags) &
105889 + (atomic_read_unchecked(&dest->conn_flags) &
105890 IP_VS_CONN_F_FWD_MASK)) ||
105891 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
105892 atomic_read(&dest->weight)) ||
105893 @@ -3600,7 +3600,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
105894 {
105895 int idx;
105896 struct netns_ipvs *ipvs = net_ipvs(net);
105897 - struct ctl_table *tbl;
105898 + ctl_table_no_const *tbl;
105899
105900 atomic_set(&ipvs->dropentry, 0);
105901 spin_lock_init(&ipvs->dropentry_lock);
105902 diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
105903 index 547ff33..c8c8117 100644
105904 --- a/net/netfilter/ipvs/ip_vs_lblc.c
105905 +++ b/net/netfilter/ipvs/ip_vs_lblc.c
105906 @@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
105907 * IPVS LBLC sysctl table
105908 */
105909 #ifdef CONFIG_SYSCTL
105910 -static struct ctl_table vs_vars_table[] = {
105911 +static ctl_table_no_const vs_vars_table[] __read_only = {
105912 {
105913 .procname = "lblc_expiration",
105914 .data = NULL,
105915 diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
105916 index 3f21a2f..a112e85 100644
105917 --- a/net/netfilter/ipvs/ip_vs_lblcr.c
105918 +++ b/net/netfilter/ipvs/ip_vs_lblcr.c
105919 @@ -289,7 +289,7 @@ struct ip_vs_lblcr_table {
105920 * IPVS LBLCR sysctl table
105921 */
105922
105923 -static struct ctl_table vs_vars_table[] = {
105924 +static ctl_table_no_const vs_vars_table[] __read_only = {
105925 {
105926 .procname = "lblcr_expiration",
105927 .data = NULL,
105928 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
105929 index eadffb2..c2feeae 100644
105930 --- a/net/netfilter/ipvs/ip_vs_sync.c
105931 +++ b/net/netfilter/ipvs/ip_vs_sync.c
105932 @@ -609,7 +609,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
105933 cp = cp->control;
105934 if (cp) {
105935 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
105936 - pkts = atomic_add_return(1, &cp->in_pkts);
105937 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
105938 else
105939 pkts = sysctl_sync_threshold(ipvs);
105940 ip_vs_sync_conn(net, cp->control, pkts);
105941 @@ -771,7 +771,7 @@ control:
105942 if (!cp)
105943 return;
105944 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
105945 - pkts = atomic_add_return(1, &cp->in_pkts);
105946 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
105947 else
105948 pkts = sysctl_sync_threshold(ipvs);
105949 goto sloop;
105950 @@ -894,7 +894,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
105951
105952 if (opt)
105953 memcpy(&cp->in_seq, opt, sizeof(*opt));
105954 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
105955 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
105956 cp->state = state;
105957 cp->old_state = cp->state;
105958 /*
105959 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
105960 index 56896a4..dfe3806 100644
105961 --- a/net/netfilter/ipvs/ip_vs_xmit.c
105962 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
105963 @@ -1114,7 +1114,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
105964 else
105965 rc = NF_ACCEPT;
105966 /* do not touch skb anymore */
105967 - atomic_inc(&cp->in_pkts);
105968 + atomic_inc_unchecked(&cp->in_pkts);
105969 goto out;
105970 }
105971
105972 @@ -1206,7 +1206,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
105973 else
105974 rc = NF_ACCEPT;
105975 /* do not touch skb anymore */
105976 - atomic_inc(&cp->in_pkts);
105977 + atomic_inc_unchecked(&cp->in_pkts);
105978 goto out;
105979 }
105980
105981 diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
105982 index a4b5e2a..13b1de3 100644
105983 --- a/net/netfilter/nf_conntrack_acct.c
105984 +++ b/net/netfilter/nf_conntrack_acct.c
105985 @@ -62,7 +62,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
105986 #ifdef CONFIG_SYSCTL
105987 static int nf_conntrack_acct_init_sysctl(struct net *net)
105988 {
105989 - struct ctl_table *table;
105990 + ctl_table_no_const *table;
105991
105992 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
105993 GFP_KERNEL);
105994 diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
105995 index de88c4a..ec84234 100644
105996 --- a/net/netfilter/nf_conntrack_core.c
105997 +++ b/net/netfilter/nf_conntrack_core.c
105998 @@ -1739,6 +1739,10 @@ void nf_conntrack_init_end(void)
105999 #define DYING_NULLS_VAL ((1<<30)+1)
106000 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
106001
106002 +#ifdef CONFIG_GRKERNSEC_HIDESYM
106003 +static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
106004 +#endif
106005 +
106006 int nf_conntrack_init_net(struct net *net)
106007 {
106008 int ret = -ENOMEM;
106009 @@ -1764,7 +1768,11 @@ int nf_conntrack_init_net(struct net *net)
106010 if (!net->ct.stat)
106011 goto err_pcpu_lists;
106012
106013 +#ifdef CONFIG_GRKERNSEC_HIDESYM
106014 + net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08x", atomic_inc_return_unchecked(&conntrack_cache_id));
106015 +#else
106016 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
106017 +#endif
106018 if (!net->ct.slabname)
106019 goto err_slabname;
106020
106021 diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
106022 index 4e78c57..ec8fb74 100644
106023 --- a/net/netfilter/nf_conntrack_ecache.c
106024 +++ b/net/netfilter/nf_conntrack_ecache.c
106025 @@ -264,7 +264,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
106026 #ifdef CONFIG_SYSCTL
106027 static int nf_conntrack_event_init_sysctl(struct net *net)
106028 {
106029 - struct ctl_table *table;
106030 + ctl_table_no_const *table;
106031
106032 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
106033 GFP_KERNEL);
106034 diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
106035 index 5b3eae7..dd4b8fe 100644
106036 --- a/net/netfilter/nf_conntrack_helper.c
106037 +++ b/net/netfilter/nf_conntrack_helper.c
106038 @@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
106039
106040 static int nf_conntrack_helper_init_sysctl(struct net *net)
106041 {
106042 - struct ctl_table *table;
106043 + ctl_table_no_const *table;
106044
106045 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
106046 GFP_KERNEL);
106047 diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
106048 index b65d586..beec902 100644
106049 --- a/net/netfilter/nf_conntrack_proto.c
106050 +++ b/net/netfilter/nf_conntrack_proto.c
106051 @@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
106052
106053 static void
106054 nf_ct_unregister_sysctl(struct ctl_table_header **header,
106055 - struct ctl_table **table,
106056 + ctl_table_no_const **table,
106057 unsigned int users)
106058 {
106059 if (users > 0)
106060 diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
106061 index f641751..d3c5b51 100644
106062 --- a/net/netfilter/nf_conntrack_standalone.c
106063 +++ b/net/netfilter/nf_conntrack_standalone.c
106064 @@ -471,7 +471,7 @@ static struct ctl_table nf_ct_netfilter_table[] = {
106065
106066 static int nf_conntrack_standalone_init_sysctl(struct net *net)
106067 {
106068 - struct ctl_table *table;
106069 + ctl_table_no_const *table;
106070
106071 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
106072 GFP_KERNEL);
106073 diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
106074 index 7a394df..bd91a8a 100644
106075 --- a/net/netfilter/nf_conntrack_timestamp.c
106076 +++ b/net/netfilter/nf_conntrack_timestamp.c
106077 @@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
106078 #ifdef CONFIG_SYSCTL
106079 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
106080 {
106081 - struct ctl_table *table;
106082 + ctl_table_no_const *table;
106083
106084 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
106085 GFP_KERNEL);
106086 diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
106087 index daad602..384be13 100644
106088 --- a/net/netfilter/nf_log.c
106089 +++ b/net/netfilter/nf_log.c
106090 @@ -353,7 +353,7 @@ static const struct file_operations nflog_file_ops = {
106091
106092 #ifdef CONFIG_SYSCTL
106093 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
106094 -static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
106095 +static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
106096
106097 static int nf_log_proc_dostring(struct ctl_table *table, int write,
106098 void __user *buffer, size_t *lenp, loff_t *ppos)
106099 @@ -384,14 +384,16 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
106100 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
106101 mutex_unlock(&nf_log_mutex);
106102 } else {
106103 + ctl_table_no_const nf_log_table = *table;
106104 +
106105 mutex_lock(&nf_log_mutex);
106106 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
106107 lockdep_is_held(&nf_log_mutex));
106108 if (!logger)
106109 - table->data = "NONE";
106110 + nf_log_table.data = "NONE";
106111 else
106112 - table->data = logger->name;
106113 - r = proc_dostring(table, write, buffer, lenp, ppos);
106114 + nf_log_table.data = logger->name;
106115 + r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
106116 mutex_unlock(&nf_log_mutex);
106117 }
106118
106119 diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
106120 index c68c1e5..8b5d670 100644
106121 --- a/net/netfilter/nf_sockopt.c
106122 +++ b/net/netfilter/nf_sockopt.c
106123 @@ -43,7 +43,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
106124 }
106125 }
106126
106127 - list_add(&reg->list, &nf_sockopts);
106128 + pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
106129 out:
106130 mutex_unlock(&nf_sockopt_mutex);
106131 return ret;
106132 @@ -53,7 +53,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
106133 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
106134 {
106135 mutex_lock(&nf_sockopt_mutex);
106136 - list_del(&reg->list);
106137 + pax_list_del((struct list_head *)&reg->list);
106138 mutex_unlock(&nf_sockopt_mutex);
106139 }
106140 EXPORT_SYMBOL(nf_unregister_sockopt);
106141 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
106142 index 3250735..1fac969 100644
106143 --- a/net/netfilter/nfnetlink_log.c
106144 +++ b/net/netfilter/nfnetlink_log.c
106145 @@ -80,7 +80,7 @@ static int nfnl_log_net_id __read_mostly;
106146 struct nfnl_log_net {
106147 spinlock_t instances_lock;
106148 struct hlist_head instance_table[INSTANCE_BUCKETS];
106149 - atomic_t global_seq;
106150 + atomic_unchecked_t global_seq;
106151 };
106152
106153 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
106154 @@ -563,7 +563,7 @@ __build_packet_message(struct nfnl_log_net *log,
106155 /* global sequence number */
106156 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
106157 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
106158 - htonl(atomic_inc_return(&log->global_seq))))
106159 + htonl(atomic_inc_return_unchecked(&log->global_seq))))
106160 goto nla_put_failure;
106161
106162 if (data_len) {
106163 diff --git a/net/netfilter/nfnetlink_queue_core.c b/net/netfilter/nfnetlink_queue_core.c
106164 index 108120f..5b169db 100644
106165 --- a/net/netfilter/nfnetlink_queue_core.c
106166 +++ b/net/netfilter/nfnetlink_queue_core.c
106167 @@ -665,7 +665,7 @@ nfqnl_enqueue_packet(struct nf_queue_entry *entry, unsigned int queuenum)
106168 * returned by nf_queue. For instance, callers rely on -ECANCELED to
106169 * mean 'ignore this hook'.
106170 */
106171 - if (IS_ERR(segs))
106172 + if (IS_ERR_OR_NULL(segs))
106173 goto out_err;
106174 queued = 0;
106175 err = 0;
106176 diff --git a/net/netfilter/nft_compat.c b/net/netfilter/nft_compat.c
106177 index 5b5ab9e..fc1015c 100644
106178 --- a/net/netfilter/nft_compat.c
106179 +++ b/net/netfilter/nft_compat.c
106180 @@ -225,7 +225,7 @@ target_dump_info(struct sk_buff *skb, const struct xt_target *t, const void *in)
106181 /* We want to reuse existing compat_to_user */
106182 old_fs = get_fs();
106183 set_fs(KERNEL_DS);
106184 - t->compat_to_user(out, in);
106185 + t->compat_to_user((void __force_user *)out, in);
106186 set_fs(old_fs);
106187 ret = nla_put(skb, NFTA_TARGET_INFO, XT_ALIGN(t->targetsize), out);
106188 kfree(out);
106189 @@ -421,7 +421,7 @@ match_dump_info(struct sk_buff *skb, const struct xt_match *m, const void *in)
106190 /* We want to reuse existing compat_to_user */
106191 old_fs = get_fs();
106192 set_fs(KERNEL_DS);
106193 - m->compat_to_user(out, in);
106194 + m->compat_to_user((void __force_user *)out, in);
106195 set_fs(old_fs);
106196 ret = nla_put(skb, NFTA_MATCH_INFO, XT_ALIGN(m->matchsize), out);
106197 kfree(out);
106198 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
106199 new file mode 100644
106200 index 0000000..c566332
106201 --- /dev/null
106202 +++ b/net/netfilter/xt_gradm.c
106203 @@ -0,0 +1,51 @@
106204 +/*
106205 + * gradm match for netfilter
106206 + * Copyright © Zbigniew Krzystolik, 2010
106207 + *
106208 + * This program is free software; you can redistribute it and/or modify
106209 + * it under the terms of the GNU General Public License; either version
106210 + * 2 or 3 as published by the Free Software Foundation.
106211 + */
106212 +#include <linux/module.h>
106213 +#include <linux/moduleparam.h>
106214 +#include <linux/skbuff.h>
106215 +#include <linux/netfilter/x_tables.h>
106216 +#include <linux/grsecurity.h>
106217 +#include <linux/netfilter/xt_gradm.h>
106218 +
106219 +static bool
106220 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
106221 +{
106222 + const struct xt_gradm_mtinfo *info = par->matchinfo;
106223 + bool retval = false;
106224 + if (gr_acl_is_enabled())
106225 + retval = true;
106226 + return retval ^ info->invflags;
106227 +}
106228 +
106229 +static struct xt_match gradm_mt_reg __read_mostly = {
106230 + .name = "gradm",
106231 + .revision = 0,
106232 + .family = NFPROTO_UNSPEC,
106233 + .match = gradm_mt,
106234 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
106235 + .me = THIS_MODULE,
106236 +};
106237 +
106238 +static int __init gradm_mt_init(void)
106239 +{
106240 + return xt_register_match(&gradm_mt_reg);
106241 +}
106242 +
106243 +static void __exit gradm_mt_exit(void)
106244 +{
106245 + xt_unregister_match(&gradm_mt_reg);
106246 +}
106247 +
106248 +module_init(gradm_mt_init);
106249 +module_exit(gradm_mt_exit);
106250 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
106251 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
106252 +MODULE_LICENSE("GPL");
106253 +MODULE_ALIAS("ipt_gradm");
106254 +MODULE_ALIAS("ip6t_gradm");
106255 diff --git a/net/netfilter/xt_hashlimit.c b/net/netfilter/xt_hashlimit.c
106256 index 47dc683..2e0d52c 100644
106257 --- a/net/netfilter/xt_hashlimit.c
106258 +++ b/net/netfilter/xt_hashlimit.c
106259 @@ -871,11 +871,11 @@ static int __net_init hashlimit_proc_net_init(struct net *net)
106260 {
106261 struct hashlimit_net *hashlimit_net = hashlimit_pernet(net);
106262
106263 - hashlimit_net->ipt_hashlimit = proc_mkdir("ipt_hashlimit", net->proc_net);
106264 + hashlimit_net->ipt_hashlimit = proc_mkdir_restrict("ipt_hashlimit", net->proc_net);
106265 if (!hashlimit_net->ipt_hashlimit)
106266 return -ENOMEM;
106267 #if IS_ENABLED(CONFIG_IP6_NF_IPTABLES)
106268 - hashlimit_net->ip6t_hashlimit = proc_mkdir("ip6t_hashlimit", net->proc_net);
106269 + hashlimit_net->ip6t_hashlimit = proc_mkdir_restrict("ip6t_hashlimit", net->proc_net);
106270 if (!hashlimit_net->ip6t_hashlimit) {
106271 remove_proc_entry("ipt_hashlimit", net->proc_net);
106272 return -ENOMEM;
106273 diff --git a/net/netfilter/xt_recent.c b/net/netfilter/xt_recent.c
106274 index a9faae8..1ea30e0 100644
106275 --- a/net/netfilter/xt_recent.c
106276 +++ b/net/netfilter/xt_recent.c
106277 @@ -615,7 +615,7 @@ static int __net_init recent_proc_net_init(struct net *net)
106278 {
106279 struct recent_net *recent_net = recent_pernet(net);
106280
106281 - recent_net->xt_recent = proc_mkdir("xt_recent", net->proc_net);
106282 + recent_net->xt_recent = proc_mkdir_restrict("xt_recent", net->proc_net);
106283 if (!recent_net->xt_recent)
106284 return -ENOMEM;
106285 return 0;
106286 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
106287 index 11de55e..f25e448 100644
106288 --- a/net/netfilter/xt_statistic.c
106289 +++ b/net/netfilter/xt_statistic.c
106290 @@ -19,7 +19,7 @@
106291 #include <linux/module.h>
106292
106293 struct xt_statistic_priv {
106294 - atomic_t count;
106295 + atomic_unchecked_t count;
106296 } ____cacheline_aligned_in_smp;
106297
106298 MODULE_LICENSE("GPL");
106299 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
106300 break;
106301 case XT_STATISTIC_MODE_NTH:
106302 do {
106303 - oval = atomic_read(&info->master->count);
106304 + oval = atomic_read_unchecked(&info->master->count);
106305 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
106306 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
106307 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
106308 if (nval == 0)
106309 ret = !ret;
106310 break;
106311 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
106312 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
106313 if (info->master == NULL)
106314 return -ENOMEM;
106315 - atomic_set(&info->master->count, info->u.nth.count);
106316 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
106317
106318 return 0;
106319 }
106320 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
106321 index b6bf8e8..7884ddf 100644
106322 --- a/net/netlink/af_netlink.c
106323 +++ b/net/netlink/af_netlink.c
106324 @@ -273,7 +273,7 @@ static void netlink_overrun(struct sock *sk)
106325 sk->sk_error_report(sk);
106326 }
106327 }
106328 - atomic_inc(&sk->sk_drops);
106329 + atomic_inc_unchecked(&sk->sk_drops);
106330 }
106331
106332 static void netlink_rcv_wake(struct sock *sk)
106333 @@ -3010,7 +3010,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
106334 sk_wmem_alloc_get(s),
106335 nlk->cb_running,
106336 atomic_read(&s->sk_refcnt),
106337 - atomic_read(&s->sk_drops),
106338 + atomic_read_unchecked(&s->sk_drops),
106339 sock_i_ino(s)
106340 );
106341
106342 diff --git a/net/openvswitch/datapath.c b/net/openvswitch/datapath.c
106343 index 64dc864..7a9e2a4 100644
106344 --- a/net/openvswitch/datapath.c
106345 +++ b/net/openvswitch/datapath.c
106346 @@ -332,6 +332,8 @@ static int queue_gso_packets(struct datapath *dp, struct sk_buff *skb,
106347 segs = __skb_gso_segment(skb, NETIF_F_SG, false);
106348 if (IS_ERR(segs))
106349 return PTR_ERR(segs);
106350 + if (segs == NULL)
106351 + return -EINVAL;
106352
106353 /* Queue all of the segments. */
106354 skb = segs;
106355 diff --git a/net/openvswitch/vport-internal_dev.c b/net/openvswitch/vport-internal_dev.c
106356 index 8451612..c8872bc 100644
106357 --- a/net/openvswitch/vport-internal_dev.c
106358 +++ b/net/openvswitch/vport-internal_dev.c
106359 @@ -122,7 +122,7 @@ static const struct net_device_ops internal_dev_netdev_ops = {
106360 .ndo_get_stats64 = internal_dev_get_stats,
106361 };
106362
106363 -static struct rtnl_link_ops internal_dev_link_ops __read_mostly = {
106364 +static struct rtnl_link_ops internal_dev_link_ops = {
106365 .kind = "openvswitch",
106366 };
106367
106368 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
106369 index 93896d2..b701c88 100644
106370 --- a/net/packet/af_packet.c
106371 +++ b/net/packet/af_packet.c
106372 @@ -275,7 +275,7 @@ static int packet_direct_xmit(struct sk_buff *skb)
106373
106374 return ret;
106375 drop:
106376 - atomic_long_inc(&dev->tx_dropped);
106377 + atomic_long_inc_unchecked(&dev->tx_dropped);
106378 kfree_skb(skb);
106379 return NET_XMIT_DROP;
106380 }
106381 @@ -1842,7 +1842,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
106382
106383 spin_lock(&sk->sk_receive_queue.lock);
106384 po->stats.stats1.tp_packets++;
106385 - skb->dropcount = atomic_read(&sk->sk_drops);
106386 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
106387 __skb_queue_tail(&sk->sk_receive_queue, skb);
106388 spin_unlock(&sk->sk_receive_queue.lock);
106389 sk->sk_data_ready(sk);
106390 @@ -1851,7 +1851,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
106391 drop_n_acct:
106392 spin_lock(&sk->sk_receive_queue.lock);
106393 po->stats.stats1.tp_drops++;
106394 - atomic_inc(&sk->sk_drops);
106395 + atomic_inc_unchecked(&sk->sk_drops);
106396 spin_unlock(&sk->sk_receive_queue.lock);
106397
106398 drop_n_restore:
106399 @@ -3466,7 +3466,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
106400 case PACKET_HDRLEN:
106401 if (len > sizeof(int))
106402 len = sizeof(int);
106403 - if (copy_from_user(&val, optval, len))
106404 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
106405 return -EFAULT;
106406 switch (val) {
106407 case TPACKET_V1:
106408 @@ -3512,7 +3512,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
106409 len = lv;
106410 if (put_user(len, optlen))
106411 return -EFAULT;
106412 - if (copy_to_user(optval, data, len))
106413 + if (len > sizeof(st) || copy_to_user(optval, data, len))
106414 return -EFAULT;
106415 return 0;
106416 }
106417 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
106418 index 70a547e..23477fe 100644
106419 --- a/net/phonet/pep.c
106420 +++ b/net/phonet/pep.c
106421 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
106422
106423 case PNS_PEP_CTRL_REQ:
106424 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
106425 - atomic_inc(&sk->sk_drops);
106426 + atomic_inc_unchecked(&sk->sk_drops);
106427 break;
106428 }
106429 __skb_pull(skb, 4);
106430 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
106431 }
106432
106433 if (pn->rx_credits == 0) {
106434 - atomic_inc(&sk->sk_drops);
106435 + atomic_inc_unchecked(&sk->sk_drops);
106436 err = -ENOBUFS;
106437 break;
106438 }
106439 @@ -579,7 +579,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
106440 }
106441
106442 if (pn->rx_credits == 0) {
106443 - atomic_inc(&sk->sk_drops);
106444 + atomic_inc_unchecked(&sk->sk_drops);
106445 err = NET_RX_DROP;
106446 break;
106447 }
106448 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
106449 index 008214a..bb68240 100644
106450 --- a/net/phonet/socket.c
106451 +++ b/net/phonet/socket.c
106452 @@ -611,7 +611,7 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
106453 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sk)),
106454 sock_i_ino(sk),
106455 atomic_read(&sk->sk_refcnt), sk,
106456 - atomic_read(&sk->sk_drops));
106457 + atomic_read_unchecked(&sk->sk_drops));
106458 }
106459 seq_pad(seq, '\n');
106460 return 0;
106461 diff --git a/net/phonet/sysctl.c b/net/phonet/sysctl.c
106462 index c02a8c4..3c5b600 100644
106463 --- a/net/phonet/sysctl.c
106464 +++ b/net/phonet/sysctl.c
106465 @@ -67,7 +67,7 @@ static int proc_local_port_range(struct ctl_table *table, int write,
106466 {
106467 int ret;
106468 int range[2] = {local_port_range[0], local_port_range[1]};
106469 - struct ctl_table tmp = {
106470 + ctl_table_no_const tmp = {
106471 .data = &range,
106472 .maxlen = sizeof(range),
106473 .mode = table->mode,
106474 diff --git a/net/rds/cong.c b/net/rds/cong.c
106475 index e5b65ac..f3b6fb7 100644
106476 --- a/net/rds/cong.c
106477 +++ b/net/rds/cong.c
106478 @@ -78,7 +78,7 @@
106479 * finds that the saved generation number is smaller than the global generation
106480 * number, it wakes up the process.
106481 */
106482 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
106483 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
106484
106485 /*
106486 * Congestion monitoring
106487 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
106488 rdsdebug("waking map %p for %pI4\n",
106489 map, &map->m_addr);
106490 rds_stats_inc(s_cong_update_received);
106491 - atomic_inc(&rds_cong_generation);
106492 + atomic_inc_unchecked(&rds_cong_generation);
106493 if (waitqueue_active(&map->m_waitq))
106494 wake_up(&map->m_waitq);
106495 if (waitqueue_active(&rds_poll_waitq))
106496 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
106497
106498 int rds_cong_updated_since(unsigned long *recent)
106499 {
106500 - unsigned long gen = atomic_read(&rds_cong_generation);
106501 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
106502
106503 if (likely(*recent == gen))
106504 return 0;
106505 diff --git a/net/rds/ib.h b/net/rds/ib.h
106506 index 7280ab8..e04f4ea 100644
106507 --- a/net/rds/ib.h
106508 +++ b/net/rds/ib.h
106509 @@ -128,7 +128,7 @@ struct rds_ib_connection {
106510 /* sending acks */
106511 unsigned long i_ack_flags;
106512 #ifdef KERNEL_HAS_ATOMIC64
106513 - atomic64_t i_ack_next; /* next ACK to send */
106514 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
106515 #else
106516 spinlock_t i_ack_lock; /* protect i_ack_next */
106517 u64 i_ack_next; /* next ACK to send */
106518 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
106519 index 31b74f5..dc1fbfa 100644
106520 --- a/net/rds/ib_cm.c
106521 +++ b/net/rds/ib_cm.c
106522 @@ -717,7 +717,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
106523 /* Clear the ACK state */
106524 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
106525 #ifdef KERNEL_HAS_ATOMIC64
106526 - atomic64_set(&ic->i_ack_next, 0);
106527 + atomic64_set_unchecked(&ic->i_ack_next, 0);
106528 #else
106529 ic->i_ack_next = 0;
106530 #endif
106531 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
106532 index d67de45..73dbf51 100644
106533 --- a/net/rds/ib_recv.c
106534 +++ b/net/rds/ib_recv.c
106535 @@ -596,7 +596,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
106536 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
106537 int ack_required)
106538 {
106539 - atomic64_set(&ic->i_ack_next, seq);
106540 + atomic64_set_unchecked(&ic->i_ack_next, seq);
106541 if (ack_required) {
106542 smp_mb__before_atomic();
106543 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
106544 @@ -608,7 +608,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
106545 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
106546 smp_mb__after_atomic();
106547
106548 - return atomic64_read(&ic->i_ack_next);
106549 + return atomic64_read_unchecked(&ic->i_ack_next);
106550 }
106551 #endif
106552
106553 diff --git a/net/rds/iw.h b/net/rds/iw.h
106554 index 04ce3b1..48119a6 100644
106555 --- a/net/rds/iw.h
106556 +++ b/net/rds/iw.h
106557 @@ -134,7 +134,7 @@ struct rds_iw_connection {
106558 /* sending acks */
106559 unsigned long i_ack_flags;
106560 #ifdef KERNEL_HAS_ATOMIC64
106561 - atomic64_t i_ack_next; /* next ACK to send */
106562 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
106563 #else
106564 spinlock_t i_ack_lock; /* protect i_ack_next */
106565 u64 i_ack_next; /* next ACK to send */
106566 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
106567 index a91e1db..cf3053f 100644
106568 --- a/net/rds/iw_cm.c
106569 +++ b/net/rds/iw_cm.c
106570 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
106571 /* Clear the ACK state */
106572 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
106573 #ifdef KERNEL_HAS_ATOMIC64
106574 - atomic64_set(&ic->i_ack_next, 0);
106575 + atomic64_set_unchecked(&ic->i_ack_next, 0);
106576 #else
106577 ic->i_ack_next = 0;
106578 #endif
106579 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
106580 index aa8bf67..b70133c 100644
106581 --- a/net/rds/iw_recv.c
106582 +++ b/net/rds/iw_recv.c
106583 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
106584 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
106585 int ack_required)
106586 {
106587 - atomic64_set(&ic->i_ack_next, seq);
106588 + atomic64_set_unchecked(&ic->i_ack_next, seq);
106589 if (ack_required) {
106590 smp_mb__before_atomic();
106591 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
106592 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
106593 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
106594 smp_mb__after_atomic();
106595
106596 - return atomic64_read(&ic->i_ack_next);
106597 + return atomic64_read_unchecked(&ic->i_ack_next);
106598 }
106599 #endif
106600
106601 diff --git a/net/rds/rdma.c b/net/rds/rdma.c
106602 index 4e37c1c..40084d8 100644
106603 --- a/net/rds/rdma.c
106604 +++ b/net/rds/rdma.c
106605 @@ -564,12 +564,12 @@ int rds_cmsg_rdma_args(struct rds_sock *rs, struct rds_message *rm,
106606
106607 if (rs->rs_bound_addr == 0) {
106608 ret = -ENOTCONN; /* XXX not a great errno */
106609 - goto out;
106610 + goto out_ret;
106611 }
106612
106613 if (args->nr_local > UIO_MAXIOV) {
106614 ret = -EMSGSIZE;
106615 - goto out;
106616 + goto out_ret;
106617 }
106618
106619 /* Check whether to allocate the iovec area */
106620 @@ -578,7 +578,7 @@ int rds_cmsg_rdma_args(struct rds_sock *rs, struct rds_message *rm,
106621 iovs = sock_kmalloc(rds_rs_to_sk(rs), iov_size, GFP_KERNEL);
106622 if (!iovs) {
106623 ret = -ENOMEM;
106624 - goto out;
106625 + goto out_ret;
106626 }
106627 }
106628
106629 @@ -696,6 +696,7 @@ out:
106630 if (iovs != iovstack)
106631 sock_kfree_s(rds_rs_to_sk(rs), iovs, iov_size);
106632 kfree(pages);
106633 +out_ret:
106634 if (ret)
106635 rds_rdma_free_op(op);
106636 else
106637 diff --git a/net/rds/rds.h b/net/rds/rds.h
106638 index 48f8ffc..0ef3eec 100644
106639 --- a/net/rds/rds.h
106640 +++ b/net/rds/rds.h
106641 @@ -449,7 +449,7 @@ struct rds_transport {
106642 void (*sync_mr)(void *trans_private, int direction);
106643 void (*free_mr)(void *trans_private, int invalidate);
106644 void (*flush_mrs)(void);
106645 -};
106646 +} __do_const;
106647
106648 struct rds_sock {
106649 struct sock rs_sk;
106650 diff --git a/net/rds/send.c b/net/rds/send.c
106651 index 2371816..0a64541 100644
106652 --- a/net/rds/send.c
106653 +++ b/net/rds/send.c
106654 @@ -593,8 +593,11 @@ static void rds_send_remove_from_sock(struct list_head *messages, int status)
106655 sock_put(rds_rs_to_sk(rs));
106656 }
106657 rs = rm->m_rs;
106658 - sock_hold(rds_rs_to_sk(rs));
106659 + if (rs)
106660 + sock_hold(rds_rs_to_sk(rs));
106661 }
106662 + if (!rs)
106663 + goto unlock_and_drop;
106664 spin_lock(&rs->rs_lock);
106665
106666 if (test_and_clear_bit(RDS_MSG_ON_SOCK, &rm->m_flags)) {
106667 @@ -638,9 +641,6 @@ unlock_and_drop:
106668 * queue. This means that in the TCP case, the message may not have been
106669 * assigned the m_ack_seq yet - but that's fine as long as tcp_is_acked
106670 * checks the RDS_MSG_HAS_ACK_SEQ bit.
106671 - *
106672 - * XXX It's not clear to me how this is safely serialized with socket
106673 - * destruction. Maybe it should bail if it sees SOCK_DEAD.
106674 */
106675 void rds_send_drop_acked(struct rds_connection *conn, u64 ack,
106676 is_acked_func is_acked)
106677 @@ -711,6 +711,9 @@ void rds_send_drop_to(struct rds_sock *rs, struct sockaddr_in *dest)
106678 */
106679 if (!test_and_clear_bit(RDS_MSG_ON_CONN, &rm->m_flags)) {
106680 spin_unlock_irqrestore(&conn->c_lock, flags);
106681 + spin_lock_irqsave(&rm->m_rs_lock, flags);
106682 + rm->m_rs = NULL;
106683 + spin_unlock_irqrestore(&rm->m_rs_lock, flags);
106684 continue;
106685 }
106686 list_del_init(&rm->m_conn_item);
106687 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
106688 index edac9ef..16bcb98 100644
106689 --- a/net/rds/tcp.c
106690 +++ b/net/rds/tcp.c
106691 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
106692 int val = 1;
106693
106694 set_fs(KERNEL_DS);
106695 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
106696 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
106697 sizeof(val));
106698 set_fs(oldfs);
106699 }
106700 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
106701 index 53b17ca..45463e7 100644
106702 --- a/net/rds/tcp_send.c
106703 +++ b/net/rds/tcp_send.c
106704 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
106705
106706 oldfs = get_fs();
106707 set_fs(KERNEL_DS);
106708 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
106709 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
106710 sizeof(val));
106711 set_fs(oldfs);
106712 }
106713 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
106714 index 7b16704..9628ec6 100644
106715 --- a/net/rxrpc/af_rxrpc.c
106716 +++ b/net/rxrpc/af_rxrpc.c
106717 @@ -40,7 +40,7 @@ static const struct proto_ops rxrpc_rpc_ops;
106718 __be32 rxrpc_epoch;
106719
106720 /* current debugging ID */
106721 -atomic_t rxrpc_debug_id;
106722 +atomic_unchecked_t rxrpc_debug_id;
106723
106724 /* count of skbs currently in use */
106725 atomic_t rxrpc_n_skbs;
106726 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
106727 index c6be17a..2a6200a 100644
106728 --- a/net/rxrpc/ar-ack.c
106729 +++ b/net/rxrpc/ar-ack.c
106730 @@ -223,7 +223,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
106731
106732 _enter("{%d,%d,%d,%d},",
106733 call->acks_hard, call->acks_unacked,
106734 - atomic_read(&call->sequence),
106735 + atomic_read_unchecked(&call->sequence),
106736 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
106737
106738 stop = 0;
106739 @@ -247,7 +247,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
106740
106741 /* each Tx packet has a new serial number */
106742 sp->hdr.serial =
106743 - htonl(atomic_inc_return(&call->conn->serial));
106744 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
106745
106746 hdr = (struct rxrpc_header *) txb->head;
106747 hdr->serial = sp->hdr.serial;
106748 @@ -451,7 +451,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
106749 */
106750 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
106751 {
106752 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
106753 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
106754 }
106755
106756 /*
106757 @@ -677,7 +677,7 @@ process_further:
106758
106759 latest = ntohl(sp->hdr.serial);
106760 hard = ntohl(ack.firstPacket);
106761 - tx = atomic_read(&call->sequence);
106762 + tx = atomic_read_unchecked(&call->sequence);
106763
106764 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
106765 latest,
106766 @@ -1209,7 +1209,7 @@ void rxrpc_process_call(struct work_struct *work)
106767 goto maybe_reschedule;
106768
106769 send_ACK_with_skew:
106770 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
106771 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
106772 ntohl(ack.serial));
106773 send_ACK:
106774 mtu = call->conn->trans->peer->if_mtu;
106775 @@ -1221,7 +1221,7 @@ send_ACK:
106776 ackinfo.rxMTU = htonl(rxrpc_rx_mtu);
106777 ackinfo.jumbo_max = htonl(rxrpc_rx_jumbo_max);
106778
106779 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
106780 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
106781 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
106782 ntohl(hdr.serial),
106783 ntohs(ack.maxSkew),
106784 @@ -1239,7 +1239,7 @@ send_ACK:
106785 send_message:
106786 _debug("send message");
106787
106788 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
106789 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
106790 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
106791 send_message_2:
106792
106793 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
106794 index a9e05db..194e793 100644
106795 --- a/net/rxrpc/ar-call.c
106796 +++ b/net/rxrpc/ar-call.c
106797 @@ -232,7 +232,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
106798 spin_lock_init(&call->lock);
106799 rwlock_init(&call->state_lock);
106800 atomic_set(&call->usage, 1);
106801 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
106802 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
106803 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
106804
106805 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
106806 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
106807 index 6631f4f..bfdf056 100644
106808 --- a/net/rxrpc/ar-connection.c
106809 +++ b/net/rxrpc/ar-connection.c
106810 @@ -210,7 +210,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
106811 rwlock_init(&conn->lock);
106812 spin_lock_init(&conn->state_lock);
106813 atomic_set(&conn->usage, 1);
106814 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
106815 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
106816 conn->avail_calls = RXRPC_MAXCALLS;
106817 conn->size_align = 4;
106818 conn->header_size = sizeof(struct rxrpc_header);
106819 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
106820 index e7ed43a..6afa140 100644
106821 --- a/net/rxrpc/ar-connevent.c
106822 +++ b/net/rxrpc/ar-connevent.c
106823 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
106824
106825 len = iov[0].iov_len + iov[1].iov_len;
106826
106827 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
106828 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
106829 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
106830
106831 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
106832 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
106833 index 63b21e5..330232e 100644
106834 --- a/net/rxrpc/ar-input.c
106835 +++ b/net/rxrpc/ar-input.c
106836 @@ -338,9 +338,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
106837 /* track the latest serial number on this connection for ACK packet
106838 * information */
106839 serial = ntohl(sp->hdr.serial);
106840 - hi_serial = atomic_read(&call->conn->hi_serial);
106841 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
106842 while (serial > hi_serial)
106843 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
106844 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
106845 serial);
106846
106847 /* request ACK generation for any ACK or DATA packet that requests
106848 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
106849 index ba9fd36..9bbfe01 100644
106850 --- a/net/rxrpc/ar-internal.h
106851 +++ b/net/rxrpc/ar-internal.h
106852 @@ -272,8 +272,8 @@ struct rxrpc_connection {
106853 int error; /* error code for local abort */
106854 int debug_id; /* debug ID for printks */
106855 unsigned int call_counter; /* call ID counter */
106856 - atomic_t serial; /* packet serial number counter */
106857 - atomic_t hi_serial; /* highest serial number received */
106858 + atomic_unchecked_t serial; /* packet serial number counter */
106859 + atomic_unchecked_t hi_serial; /* highest serial number received */
106860 u8 avail_calls; /* number of calls available */
106861 u8 size_align; /* data size alignment (for security) */
106862 u8 header_size; /* rxrpc + security header size */
106863 @@ -346,7 +346,7 @@ struct rxrpc_call {
106864 spinlock_t lock;
106865 rwlock_t state_lock; /* lock for state transition */
106866 atomic_t usage;
106867 - atomic_t sequence; /* Tx data packet sequence counter */
106868 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
106869 u32 abort_code; /* local/remote abort code */
106870 enum { /* current state of call */
106871 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
106872 @@ -431,7 +431,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
106873 */
106874 extern atomic_t rxrpc_n_skbs;
106875 extern __be32 rxrpc_epoch;
106876 -extern atomic_t rxrpc_debug_id;
106877 +extern atomic_unchecked_t rxrpc_debug_id;
106878 extern struct workqueue_struct *rxrpc_workqueue;
106879
106880 /*
106881 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
106882 index 87f7135..74d3703 100644
106883 --- a/net/rxrpc/ar-local.c
106884 +++ b/net/rxrpc/ar-local.c
106885 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
106886 spin_lock_init(&local->lock);
106887 rwlock_init(&local->services_lock);
106888 atomic_set(&local->usage, 1);
106889 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
106890 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
106891 memcpy(&local->srx, srx, sizeof(*srx));
106892 }
106893
106894 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
106895 index 0b4b9a7..966ffbb 100644
106896 --- a/net/rxrpc/ar-output.c
106897 +++ b/net/rxrpc/ar-output.c
106898 @@ -682,14 +682,14 @@ static int rxrpc_send_data(struct kiocb *iocb,
106899 memset(skb_put(skb, pad), 0, pad);
106900 }
106901
106902 - seq = atomic_inc_return(&call->sequence);
106903 + seq = atomic_inc_return_unchecked(&call->sequence);
106904
106905 sp->hdr.epoch = conn->epoch;
106906 sp->hdr.cid = call->cid;
106907 sp->hdr.callNumber = call->call_id;
106908 sp->hdr.seq = htonl(seq);
106909 sp->hdr.serial =
106910 - htonl(atomic_inc_return(&conn->serial));
106911 + htonl(atomic_inc_return_unchecked(&conn->serial));
106912 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
106913 sp->hdr.userStatus = 0;
106914 sp->hdr.securityIndex = conn->security_ix;
106915 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
106916 index bebaa43..2644591 100644
106917 --- a/net/rxrpc/ar-peer.c
106918 +++ b/net/rxrpc/ar-peer.c
106919 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
106920 INIT_LIST_HEAD(&peer->error_targets);
106921 spin_lock_init(&peer->lock);
106922 atomic_set(&peer->usage, 1);
106923 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
106924 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
106925 memcpy(&peer->srx, srx, sizeof(*srx));
106926
106927 rxrpc_assess_MTU_size(peer);
106928 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
106929 index 38047f7..9f48511 100644
106930 --- a/net/rxrpc/ar-proc.c
106931 +++ b/net/rxrpc/ar-proc.c
106932 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
106933 atomic_read(&conn->usage),
106934 rxrpc_conn_states[conn->state],
106935 key_serial(conn->key),
106936 - atomic_read(&conn->serial),
106937 - atomic_read(&conn->hi_serial));
106938 + atomic_read_unchecked(&conn->serial),
106939 + atomic_read_unchecked(&conn->hi_serial));
106940
106941 return 0;
106942 }
106943 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
106944 index 1976dec..aa70be5 100644
106945 --- a/net/rxrpc/ar-transport.c
106946 +++ b/net/rxrpc/ar-transport.c
106947 @@ -51,7 +51,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
106948 spin_lock_init(&trans->client_lock);
106949 rwlock_init(&trans->conn_lock);
106950 atomic_set(&trans->usage, 1);
106951 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
106952 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
106953
106954 if (peer->srx.transport.family == AF_INET) {
106955 switch (peer->srx.transport_type) {
106956 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
106957 index f226709..0e735a8 100644
106958 --- a/net/rxrpc/rxkad.c
106959 +++ b/net/rxrpc/rxkad.c
106960 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
106961
106962 len = iov[0].iov_len + iov[1].iov_len;
106963
106964 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
106965 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
106966 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
106967
106968 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
106969 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
106970
106971 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
106972
106973 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
106974 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
106975 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
106976
106977 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
106978 diff --git a/net/sched/sch_generic.c b/net/sched/sch_generic.c
106979 index fc04fe9..8167357 100644
106980 --- a/net/sched/sch_generic.c
106981 +++ b/net/sched/sch_generic.c
106982 @@ -310,7 +310,7 @@ void netif_carrier_on(struct net_device *dev)
106983 if (test_and_clear_bit(__LINK_STATE_NOCARRIER, &dev->state)) {
106984 if (dev->reg_state == NETREG_UNINITIALIZED)
106985 return;
106986 - atomic_inc(&dev->carrier_changes);
106987 + atomic_inc_unchecked(&dev->carrier_changes);
106988 linkwatch_fire_event(dev);
106989 if (netif_running(dev))
106990 __netdev_watchdog_up(dev);
106991 @@ -329,7 +329,7 @@ void netif_carrier_off(struct net_device *dev)
106992 if (!test_and_set_bit(__LINK_STATE_NOCARRIER, &dev->state)) {
106993 if (dev->reg_state == NETREG_UNINITIALIZED)
106994 return;
106995 - atomic_inc(&dev->carrier_changes);
106996 + atomic_inc_unchecked(&dev->carrier_changes);
106997 linkwatch_fire_event(dev);
106998 }
106999 }
107000 diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
107001 index 0e4198e..f94193e 100644
107002 --- a/net/sctp/ipv6.c
107003 +++ b/net/sctp/ipv6.c
107004 @@ -972,7 +972,7 @@ static const struct inet6_protocol sctpv6_protocol = {
107005 .flags = INET6_PROTO_NOPOLICY | INET6_PROTO_FINAL,
107006 };
107007
107008 -static struct sctp_af sctp_af_inet6 = {
107009 +static struct sctp_af sctp_af_inet6 __read_only = {
107010 .sa_family = AF_INET6,
107011 .sctp_xmit = sctp_v6_xmit,
107012 .setsockopt = ipv6_setsockopt,
107013 @@ -1002,7 +1002,7 @@ static struct sctp_af sctp_af_inet6 = {
107014 #endif
107015 };
107016
107017 -static struct sctp_pf sctp_pf_inet6 = {
107018 +static struct sctp_pf sctp_pf_inet6 __read_only = {
107019 .event_msgname = sctp_inet6_event_msgname,
107020 .skb_msgname = sctp_inet6_skb_msgname,
107021 .af_supported = sctp_inet6_af_supported,
107022 @@ -1029,7 +1029,7 @@ void sctp_v6_pf_init(void)
107023
107024 void sctp_v6_pf_exit(void)
107025 {
107026 - list_del(&sctp_af_inet6.list);
107027 + pax_list_del(&sctp_af_inet6.list);
107028 }
107029
107030 /* Initialize IPv6 support and register with socket layer. */
107031 diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
107032 index 6240834..cac4b52 100644
107033 --- a/net/sctp/protocol.c
107034 +++ b/net/sctp/protocol.c
107035 @@ -836,8 +836,10 @@ int sctp_register_af(struct sctp_af *af)
107036 return 0;
107037 }
107038
107039 + pax_open_kernel();
107040 INIT_LIST_HEAD(&af->list);
107041 - list_add_tail(&af->list, &sctp_address_families);
107042 + pax_close_kernel();
107043 + pax_list_add_tail(&af->list, &sctp_address_families);
107044 return 1;
107045 }
107046
107047 @@ -967,7 +969,7 @@ static inline int sctp_v4_xmit(struct sk_buff *skb,
107048
107049 static struct sctp_af sctp_af_inet;
107050
107051 -static struct sctp_pf sctp_pf_inet = {
107052 +static struct sctp_pf sctp_pf_inet __read_only = {
107053 .event_msgname = sctp_inet_event_msgname,
107054 .skb_msgname = sctp_inet_skb_msgname,
107055 .af_supported = sctp_inet_af_supported,
107056 @@ -1039,7 +1041,7 @@ static const struct net_protocol sctp_protocol = {
107057 };
107058
107059 /* IPv4 address related functions. */
107060 -static struct sctp_af sctp_af_inet = {
107061 +static struct sctp_af sctp_af_inet __read_only = {
107062 .sa_family = AF_INET,
107063 .sctp_xmit = sctp_v4_xmit,
107064 .setsockopt = ip_setsockopt,
107065 @@ -1123,7 +1125,7 @@ static void sctp_v4_pf_init(void)
107066
107067 static void sctp_v4_pf_exit(void)
107068 {
107069 - list_del(&sctp_af_inet.list);
107070 + pax_list_del(&sctp_af_inet.list);
107071 }
107072
107073 static int sctp_v4_protosw_init(void)
107074 diff --git a/net/sctp/sm_sideeffect.c b/net/sctp/sm_sideeffect.c
107075 index fef2acd..c705c4f 100644
107076 --- a/net/sctp/sm_sideeffect.c
107077 +++ b/net/sctp/sm_sideeffect.c
107078 @@ -439,7 +439,7 @@ static void sctp_generate_sack_event(unsigned long data)
107079 sctp_generate_timeout_event(asoc, SCTP_EVENT_TIMEOUT_SACK);
107080 }
107081
107082 -sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
107083 +sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
107084 NULL,
107085 sctp_generate_t1_cookie_event,
107086 sctp_generate_t1_init_event,
107087 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
107088 index 634a2ab..8e93929 100644
107089 --- a/net/sctp/socket.c
107090 +++ b/net/sctp/socket.c
107091 @@ -2199,11 +2199,13 @@ static int sctp_setsockopt_events(struct sock *sk, char __user *optval,
107092 {
107093 struct sctp_association *asoc;
107094 struct sctp_ulpevent *event;
107095 + struct sctp_event_subscribe subscribe;
107096
107097 if (optlen > sizeof(struct sctp_event_subscribe))
107098 return -EINVAL;
107099 - if (copy_from_user(&sctp_sk(sk)->subscribe, optval, optlen))
107100 + if (copy_from_user(&subscribe, optval, optlen))
107101 return -EFAULT;
107102 + sctp_sk(sk)->subscribe = subscribe;
107103
107104 if (sctp_sk(sk)->subscribe.sctp_data_io_event)
107105 pr_warn_ratelimited(DEPRECATED "%s (pid %d) "
107106 @@ -4372,13 +4374,16 @@ static int sctp_getsockopt_disable_fragments(struct sock *sk, int len,
107107 static int sctp_getsockopt_events(struct sock *sk, int len, char __user *optval,
107108 int __user *optlen)
107109 {
107110 + struct sctp_event_subscribe subscribe;
107111 +
107112 if (len <= 0)
107113 return -EINVAL;
107114 if (len > sizeof(struct sctp_event_subscribe))
107115 len = sizeof(struct sctp_event_subscribe);
107116 if (put_user(len, optlen))
107117 return -EFAULT;
107118 - if (copy_to_user(optval, &sctp_sk(sk)->subscribe, len))
107119 + subscribe = sctp_sk(sk)->subscribe;
107120 + if (copy_to_user(optval, &subscribe, len))
107121 return -EFAULT;
107122 return 0;
107123 }
107124 @@ -4396,6 +4401,8 @@ static int sctp_getsockopt_events(struct sock *sk, int len, char __user *optval,
107125 */
107126 static int sctp_getsockopt_autoclose(struct sock *sk, int len, char __user *optval, int __user *optlen)
107127 {
107128 + __u32 autoclose;
107129 +
107130 /* Applicable to UDP-style socket only */
107131 if (sctp_style(sk, TCP))
107132 return -EOPNOTSUPP;
107133 @@ -4404,7 +4411,8 @@ static int sctp_getsockopt_autoclose(struct sock *sk, int len, char __user *optv
107134 len = sizeof(int);
107135 if (put_user(len, optlen))
107136 return -EFAULT;
107137 - if (copy_to_user(optval, &sctp_sk(sk)->autoclose, sizeof(int)))
107138 + autoclose = sctp_sk(sk)->autoclose;
107139 + if (copy_to_user(optval, &autoclose, sizeof(int)))
107140 return -EFAULT;
107141 return 0;
107142 }
107143 @@ -4778,12 +4786,15 @@ static int sctp_getsockopt_delayed_ack(struct sock *sk, int len,
107144 */
107145 static int sctp_getsockopt_initmsg(struct sock *sk, int len, char __user *optval, int __user *optlen)
107146 {
107147 + struct sctp_initmsg initmsg;
107148 +
107149 if (len < sizeof(struct sctp_initmsg))
107150 return -EINVAL;
107151 len = sizeof(struct sctp_initmsg);
107152 if (put_user(len, optlen))
107153 return -EFAULT;
107154 - if (copy_to_user(optval, &sctp_sk(sk)->initmsg, len))
107155 + initmsg = sctp_sk(sk)->initmsg;
107156 + if (copy_to_user(optval, &initmsg, len))
107157 return -EFAULT;
107158 return 0;
107159 }
107160 @@ -4824,6 +4835,8 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
107161 ->addr_to_user(sp, &temp);
107162 if (space_left < addrlen)
107163 return -ENOMEM;
107164 + if (addrlen > sizeof(temp) || addrlen < 0)
107165 + return -EFAULT;
107166 if (copy_to_user(to, &temp, addrlen))
107167 return -EFAULT;
107168 to += addrlen;
107169 diff --git a/net/sctp/sysctl.c b/net/sctp/sysctl.c
107170 index 2e9ada1..40f425d 100644
107171 --- a/net/sctp/sysctl.c
107172 +++ b/net/sctp/sysctl.c
107173 @@ -321,7 +321,7 @@ static int proc_sctp_do_hmac_alg(struct ctl_table *ctl, int write,
107174 loff_t *ppos)
107175 {
107176 struct net *net = current->nsproxy->net_ns;
107177 - struct ctl_table tbl;
107178 + ctl_table_no_const tbl;
107179 bool changed = false;
107180 char *none = "none";
107181 char tmp[8];
107182 @@ -369,7 +369,7 @@ static int proc_sctp_do_rto_min(struct ctl_table *ctl, int write,
107183 struct net *net = current->nsproxy->net_ns;
107184 unsigned int min = *(unsigned int *) ctl->extra1;
107185 unsigned int max = *(unsigned int *) ctl->extra2;
107186 - struct ctl_table tbl;
107187 + ctl_table_no_const tbl;
107188 int ret, new_value;
107189
107190 memset(&tbl, 0, sizeof(struct ctl_table));
107191 @@ -398,7 +398,7 @@ static int proc_sctp_do_rto_max(struct ctl_table *ctl, int write,
107192 struct net *net = current->nsproxy->net_ns;
107193 unsigned int min = *(unsigned int *) ctl->extra1;
107194 unsigned int max = *(unsigned int *) ctl->extra2;
107195 - struct ctl_table tbl;
107196 + ctl_table_no_const tbl;
107197 int ret, new_value;
107198
107199 memset(&tbl, 0, sizeof(struct ctl_table));
107200 @@ -436,7 +436,7 @@ static int proc_sctp_do_auth(struct ctl_table *ctl, int write,
107201 loff_t *ppos)
107202 {
107203 struct net *net = current->nsproxy->net_ns;
107204 - struct ctl_table tbl;
107205 + ctl_table_no_const tbl;
107206 int new_value, ret;
107207
107208 memset(&tbl, 0, sizeof(struct ctl_table));
107209 @@ -463,7 +463,7 @@ static int proc_sctp_do_auth(struct ctl_table *ctl, int write,
107210
107211 int sctp_sysctl_net_register(struct net *net)
107212 {
107213 - struct ctl_table *table;
107214 + ctl_table_no_const *table;
107215 int i;
107216
107217 table = kmemdup(sctp_net_table, sizeof(sctp_net_table), GFP_KERNEL);
107218 diff --git a/net/socket.c b/net/socket.c
107219 index 4cdbc10..f075204 100644
107220 --- a/net/socket.c
107221 +++ b/net/socket.c
107222 @@ -89,6 +89,7 @@
107223 #include <linux/magic.h>
107224 #include <linux/slab.h>
107225 #include <linux/xattr.h>
107226 +#include <linux/in.h>
107227
107228 #include <asm/uaccess.h>
107229 #include <asm/unistd.h>
107230 @@ -113,6 +114,8 @@ unsigned int sysctl_net_busy_read __read_mostly;
107231 unsigned int sysctl_net_busy_poll __read_mostly;
107232 #endif
107233
107234 +#include <linux/grsock.h>
107235 +
107236 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
107237 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
107238 unsigned long nr_segs, loff_t pos);
107239 @@ -164,7 +167,7 @@ static const struct file_operations socket_file_ops = {
107240 */
107241
107242 static DEFINE_SPINLOCK(net_family_lock);
107243 -static const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
107244 +const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
107245
107246 /*
107247 * Statistics counters of the socket lists
107248 @@ -330,7 +333,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
107249 &sockfs_dentry_operations, SOCKFS_MAGIC);
107250 }
107251
107252 -static struct vfsmount *sock_mnt __read_mostly;
107253 +struct vfsmount *sock_mnt __read_mostly;
107254
107255 static struct file_system_type sock_fs_type = {
107256 .name = "sockfs",
107257 @@ -1265,6 +1268,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
107258 return -EAFNOSUPPORT;
107259 if (type < 0 || type >= SOCK_MAX)
107260 return -EINVAL;
107261 + if (protocol < 0)
107262 + return -EINVAL;
107263
107264 /* Compatibility.
107265
107266 @@ -1285,6 +1290,20 @@ int __sock_create(struct net *net, int family, int type, int protocol,
107267 if (err)
107268 return err;
107269
107270 + if(!kern && !gr_search_socket(family, type, protocol)) {
107271 + if (rcu_access_pointer(net_families[family]) == NULL)
107272 + return -EAFNOSUPPORT;
107273 + else
107274 + return -EACCES;
107275 + }
107276 +
107277 + if (!kern && gr_handle_sock_all(family, type, protocol)) {
107278 + if (rcu_access_pointer(net_families[family]) == NULL)
107279 + return -EAFNOSUPPORT;
107280 + else
107281 + return -EACCES;
107282 + }
107283 +
107284 /*
107285 * Allocate the socket and allow the family to set things up. if
107286 * the protocol is 0, the family is instructed to select an appropriate
107287 @@ -1536,6 +1555,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
107288 if (sock) {
107289 err = move_addr_to_kernel(umyaddr, addrlen, &address);
107290 if (err >= 0) {
107291 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
107292 + err = -EACCES;
107293 + goto error;
107294 + }
107295 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
107296 + if (err)
107297 + goto error;
107298 +
107299 err = security_socket_bind(sock,
107300 (struct sockaddr *)&address,
107301 addrlen);
107302 @@ -1544,6 +1571,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
107303 (struct sockaddr *)
107304 &address, addrlen);
107305 }
107306 +error:
107307 fput_light(sock->file, fput_needed);
107308 }
107309 return err;
107310 @@ -1567,10 +1595,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
107311 if ((unsigned int)backlog > somaxconn)
107312 backlog = somaxconn;
107313
107314 + if (gr_handle_sock_server_other(sock->sk)) {
107315 + err = -EPERM;
107316 + goto error;
107317 + }
107318 +
107319 + err = gr_search_listen(sock);
107320 + if (err)
107321 + goto error;
107322 +
107323 err = security_socket_listen(sock, backlog);
107324 if (!err)
107325 err = sock->ops->listen(sock, backlog);
107326
107327 +error:
107328 fput_light(sock->file, fput_needed);
107329 }
107330 return err;
107331 @@ -1614,6 +1652,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
107332 newsock->type = sock->type;
107333 newsock->ops = sock->ops;
107334
107335 + if (gr_handle_sock_server_other(sock->sk)) {
107336 + err = -EPERM;
107337 + sock_release(newsock);
107338 + goto out_put;
107339 + }
107340 +
107341 + err = gr_search_accept(sock);
107342 + if (err) {
107343 + sock_release(newsock);
107344 + goto out_put;
107345 + }
107346 +
107347 /*
107348 * We don't need try_module_get here, as the listening socket (sock)
107349 * has the protocol module (sock->ops->owner) held.
107350 @@ -1659,6 +1709,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
107351 fd_install(newfd, newfile);
107352 err = newfd;
107353
107354 + gr_attach_curr_ip(newsock->sk);
107355 +
107356 out_put:
107357 fput_light(sock->file, fput_needed);
107358 out:
107359 @@ -1691,6 +1743,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
107360 int, addrlen)
107361 {
107362 struct socket *sock;
107363 + struct sockaddr *sck;
107364 struct sockaddr_storage address;
107365 int err, fput_needed;
107366
107367 @@ -1701,6 +1754,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
107368 if (err < 0)
107369 goto out_put;
107370
107371 + sck = (struct sockaddr *)&address;
107372 +
107373 + if (gr_handle_sock_client(sck)) {
107374 + err = -EACCES;
107375 + goto out_put;
107376 + }
107377 +
107378 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
107379 + if (err)
107380 + goto out_put;
107381 +
107382 err =
107383 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
107384 if (err)
107385 @@ -1782,6 +1846,8 @@ SYSCALL_DEFINE3(getpeername, int, fd, struct sockaddr __user *, usockaddr,
107386 * the protocol.
107387 */
107388
107389 +asmlinkage long sys_sendto(int, void __user *, size_t, unsigned, struct sockaddr __user *, int);
107390 +
107391 SYSCALL_DEFINE6(sendto, int, fd, void __user *, buff, size_t, len,
107392 unsigned int, flags, struct sockaddr __user *, addr,
107393 int, addr_len)
107394 @@ -1848,7 +1914,7 @@ SYSCALL_DEFINE6(recvfrom, int, fd, void __user *, ubuf, size_t, size,
107395 struct socket *sock;
107396 struct iovec iov;
107397 struct msghdr msg;
107398 - struct sockaddr_storage address;
107399 + struct sockaddr_storage address = { };
107400 int err, err2;
107401 int fput_needed;
107402
107403 @@ -2077,7 +2143,7 @@ static int ___sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
107404 * checking falls down on this.
107405 */
107406 if (copy_from_user(ctl_buf,
107407 - (void __user __force *)msg_sys->msg_control,
107408 + (void __force_user *)msg_sys->msg_control,
107409 ctl_len))
107410 goto out_freectl;
107411 msg_sys->msg_control = ctl_buf;
107412 @@ -2228,7 +2294,7 @@ static int ___sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
107413 int err, total_len, len;
107414
107415 /* kernel mode address */
107416 - struct sockaddr_storage addr;
107417 + struct sockaddr_storage addr = { };
107418
107419 /* user mode address pointers */
107420 struct sockaddr __user *uaddr;
107421 @@ -2257,7 +2323,7 @@ static int ___sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
107422 /* Save the user-mode address (verify_iovec will change the
107423 * kernel msghdr to use the kernel address space)
107424 */
107425 - uaddr = (__force void __user *)msg_sys->msg_name;
107426 + uaddr = (void __force_user *)msg_sys->msg_name;
107427 uaddr_len = COMPAT_NAMELEN(msg);
107428 if (MSG_CMSG_COMPAT & flags)
107429 err = verify_compat_iovec(msg_sys, iov, &addr, VERIFY_WRITE);
107430 @@ -2898,7 +2964,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
107431 ifr = compat_alloc_user_space(buf_size);
107432 rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
107433
107434 - if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
107435 + if (copy_in_user(ifr->ifr_name, ifr32->ifr_name, IFNAMSIZ))
107436 return -EFAULT;
107437
107438 if (put_user(convert_in ? rxnfc : compat_ptr(data),
107439 @@ -3009,7 +3075,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
107440 old_fs = get_fs();
107441 set_fs(KERNEL_DS);
107442 err = dev_ioctl(net, cmd,
107443 - (struct ifreq __user __force *) &kifr);
107444 + (struct ifreq __force_user *) &kifr);
107445 set_fs(old_fs);
107446
107447 return err;
107448 @@ -3102,7 +3168,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
107449
107450 old_fs = get_fs();
107451 set_fs(KERNEL_DS);
107452 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
107453 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
107454 set_fs(old_fs);
107455
107456 if (cmd == SIOCGIFMAP && !err) {
107457 @@ -3186,7 +3252,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
107458 ret |= get_user(rtdev, &(ur4->rt_dev));
107459 if (rtdev) {
107460 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
107461 - r4.rt_dev = (char __user __force *)devname;
107462 + r4.rt_dev = (char __force_user *)devname;
107463 devname[15] = 0;
107464 } else
107465 r4.rt_dev = NULL;
107466 @@ -3413,8 +3479,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
107467 int __user *uoptlen;
107468 int err;
107469
107470 - uoptval = (char __user __force *) optval;
107471 - uoptlen = (int __user __force *) optlen;
107472 + uoptval = (char __force_user *) optval;
107473 + uoptlen = (int __force_user *) optlen;
107474
107475 set_fs(KERNEL_DS);
107476 if (level == SOL_SOCKET)
107477 @@ -3434,7 +3500,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
107478 char __user *uoptval;
107479 int err;
107480
107481 - uoptval = (char __user __force *) optval;
107482 + uoptval = (char __force_user *) optval;
107483
107484 set_fs(KERNEL_DS);
107485 if (level == SOL_SOCKET)
107486 diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c
107487 index c548ab2..4e1b68b 100644
107488 --- a/net/sunrpc/auth_gss/svcauth_gss.c
107489 +++ b/net/sunrpc/auth_gss/svcauth_gss.c
107490 @@ -1140,7 +1140,7 @@ static int gss_proxy_save_rsc(struct cache_detail *cd,
107491 uint64_t *handle)
107492 {
107493 struct rsc rsci, *rscp = NULL;
107494 - static atomic64_t ctxhctr;
107495 + static atomic64_unchecked_t ctxhctr = ATOMIC64_INIT(0);
107496 long long ctxh;
107497 struct gss_api_mech *gm = NULL;
107498 time_t expiry;
107499 @@ -1151,7 +1151,7 @@ static int gss_proxy_save_rsc(struct cache_detail *cd,
107500 status = -ENOMEM;
107501 /* the handle needs to be just a unique id,
107502 * use a static counter */
107503 - ctxh = atomic64_inc_return(&ctxhctr);
107504 + ctxh = atomic64_inc_return_unchecked(&ctxhctr);
107505
107506 /* make a copy for the caller */
107507 *handle = ctxh;
107508 diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c
107509 index 0663621..c4928d4 100644
107510 --- a/net/sunrpc/cache.c
107511 +++ b/net/sunrpc/cache.c
107512 @@ -1609,7 +1609,7 @@ static int create_cache_proc_entries(struct cache_detail *cd, struct net *net)
107513 struct sunrpc_net *sn;
107514
107515 sn = net_generic(net, sunrpc_net_id);
107516 - cd->u.procfs.proc_ent = proc_mkdir(cd->name, sn->proc_net_rpc);
107517 + cd->u.procfs.proc_ent = proc_mkdir_restrict(cd->name, sn->proc_net_rpc);
107518 if (cd->u.procfs.proc_ent == NULL)
107519 goto out_nomem;
107520 cd->u.procfs.channel_ent = NULL;
107521 diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
107522 index e0b94ce..6135813 100644
107523 --- a/net/sunrpc/clnt.c
107524 +++ b/net/sunrpc/clnt.c
107525 @@ -1428,7 +1428,9 @@ call_start(struct rpc_task *task)
107526 (RPC_IS_ASYNC(task) ? "async" : "sync"));
107527
107528 /* Increment call count */
107529 - task->tk_msg.rpc_proc->p_count++;
107530 + pax_open_kernel();
107531 + (*(unsigned int *)&task->tk_msg.rpc_proc->p_count)++;
107532 + pax_close_kernel();
107533 clnt->cl_stats->rpccnt++;
107534 task->tk_action = call_reserve;
107535 }
107536 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
107537 index 9358c79..22d0a5b 100644
107538 --- a/net/sunrpc/sched.c
107539 +++ b/net/sunrpc/sched.c
107540 @@ -261,9 +261,9 @@ static int rpc_wait_bit_killable(struct wait_bit_key *key)
107541 #if defined(RPC_DEBUG) || defined(RPC_TRACEPOINTS)
107542 static void rpc_task_set_debuginfo(struct rpc_task *task)
107543 {
107544 - static atomic_t rpc_pid;
107545 + static atomic_unchecked_t rpc_pid;
107546
107547 - task->tk_pid = atomic_inc_return(&rpc_pid);
107548 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
107549 }
107550 #else
107551 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
107552 diff --git a/net/sunrpc/stats.c b/net/sunrpc/stats.c
107553 index 5453049..465669a 100644
107554 --- a/net/sunrpc/stats.c
107555 +++ b/net/sunrpc/stats.c
107556 @@ -267,7 +267,7 @@ int rpc_proc_init(struct net *net)
107557
107558 dprintk("RPC: registering /proc/net/rpc\n");
107559 sn = net_generic(net, sunrpc_net_id);
107560 - sn->proc_net_rpc = proc_mkdir("rpc", net->proc_net);
107561 + sn->proc_net_rpc = proc_mkdir_restrict("rpc", net->proc_net);
107562 if (sn->proc_net_rpc == NULL)
107563 return -ENOMEM;
107564
107565 diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c
107566 index 1db5007..6e66296 100644
107567 --- a/net/sunrpc/svc.c
107568 +++ b/net/sunrpc/svc.c
107569 @@ -1167,7 +1167,9 @@ svc_process_common(struct svc_rqst *rqstp, struct kvec *argv, struct kvec *resv)
107570 svc_putnl(resv, RPC_SUCCESS);
107571
107572 /* Bump per-procedure stats counter */
107573 - procp->pc_count++;
107574 + pax_open_kernel();
107575 + (*(unsigned int *)&procp->pc_count)++;
107576 + pax_close_kernel();
107577
107578 /* Initialize storage for argp and resp */
107579 memset(rqstp->rq_argp, 0, procp->pc_argsize);
107580 diff --git a/net/sunrpc/svcauth_unix.c b/net/sunrpc/svcauth_unix.c
107581 index 621ca7b..59421dd 100644
107582 --- a/net/sunrpc/svcauth_unix.c
107583 +++ b/net/sunrpc/svcauth_unix.c
107584 @@ -414,7 +414,7 @@ struct unix_gid {
107585 struct group_info *gi;
107586 };
107587
107588 -static int unix_gid_hash(kuid_t uid)
107589 +static int __intentional_overflow(-1) unix_gid_hash(kuid_t uid)
107590 {
107591 return hash_long(from_kuid(&init_user_ns, uid), GID_HASHBITS);
107592 }
107593 @@ -470,7 +470,7 @@ static void unix_gid_request(struct cache_detail *cd,
107594 (*bpp)[-1] = '\n';
107595 }
107596
107597 -static struct unix_gid *unix_gid_lookup(struct cache_detail *cd, kuid_t uid);
107598 +static struct unix_gid * __intentional_overflow(-1) unix_gid_lookup(struct cache_detail *cd, kuid_t uid);
107599
107600 static int unix_gid_parse(struct cache_detail *cd,
107601 char *mesg, int mlen)
107602 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
107603 index c1b6270..05089c1 100644
107604 --- a/net/sunrpc/xprtrdma/svc_rdma.c
107605 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
107606 @@ -62,15 +62,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
107607 static unsigned int min_max_inline = 4096;
107608 static unsigned int max_max_inline = 65536;
107609
107610 -atomic_t rdma_stat_recv;
107611 -atomic_t rdma_stat_read;
107612 -atomic_t rdma_stat_write;
107613 -atomic_t rdma_stat_sq_starve;
107614 -atomic_t rdma_stat_rq_starve;
107615 -atomic_t rdma_stat_rq_poll;
107616 -atomic_t rdma_stat_rq_prod;
107617 -atomic_t rdma_stat_sq_poll;
107618 -atomic_t rdma_stat_sq_prod;
107619 +atomic_unchecked_t rdma_stat_recv;
107620 +atomic_unchecked_t rdma_stat_read;
107621 +atomic_unchecked_t rdma_stat_write;
107622 +atomic_unchecked_t rdma_stat_sq_starve;
107623 +atomic_unchecked_t rdma_stat_rq_starve;
107624 +atomic_unchecked_t rdma_stat_rq_poll;
107625 +atomic_unchecked_t rdma_stat_rq_prod;
107626 +atomic_unchecked_t rdma_stat_sq_poll;
107627 +atomic_unchecked_t rdma_stat_sq_prod;
107628
107629 /* Temporary NFS request map and context caches */
107630 struct kmem_cache *svc_rdma_map_cachep;
107631 @@ -110,7 +110,7 @@ static int read_reset_stat(struct ctl_table *table, int write,
107632 len -= *ppos;
107633 if (len > *lenp)
107634 len = *lenp;
107635 - if (len && copy_to_user(buffer, str_buf, len))
107636 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
107637 return -EFAULT;
107638 *lenp = len;
107639 *ppos += len;
107640 @@ -151,63 +151,63 @@ static struct ctl_table svcrdma_parm_table[] = {
107641 {
107642 .procname = "rdma_stat_read",
107643 .data = &rdma_stat_read,
107644 - .maxlen = sizeof(atomic_t),
107645 + .maxlen = sizeof(atomic_unchecked_t),
107646 .mode = 0644,
107647 .proc_handler = read_reset_stat,
107648 },
107649 {
107650 .procname = "rdma_stat_recv",
107651 .data = &rdma_stat_recv,
107652 - .maxlen = sizeof(atomic_t),
107653 + .maxlen = sizeof(atomic_unchecked_t),
107654 .mode = 0644,
107655 .proc_handler = read_reset_stat,
107656 },
107657 {
107658 .procname = "rdma_stat_write",
107659 .data = &rdma_stat_write,
107660 - .maxlen = sizeof(atomic_t),
107661 + .maxlen = sizeof(atomic_unchecked_t),
107662 .mode = 0644,
107663 .proc_handler = read_reset_stat,
107664 },
107665 {
107666 .procname = "rdma_stat_sq_starve",
107667 .data = &rdma_stat_sq_starve,
107668 - .maxlen = sizeof(atomic_t),
107669 + .maxlen = sizeof(atomic_unchecked_t),
107670 .mode = 0644,
107671 .proc_handler = read_reset_stat,
107672 },
107673 {
107674 .procname = "rdma_stat_rq_starve",
107675 .data = &rdma_stat_rq_starve,
107676 - .maxlen = sizeof(atomic_t),
107677 + .maxlen = sizeof(atomic_unchecked_t),
107678 .mode = 0644,
107679 .proc_handler = read_reset_stat,
107680 },
107681 {
107682 .procname = "rdma_stat_rq_poll",
107683 .data = &rdma_stat_rq_poll,
107684 - .maxlen = sizeof(atomic_t),
107685 + .maxlen = sizeof(atomic_unchecked_t),
107686 .mode = 0644,
107687 .proc_handler = read_reset_stat,
107688 },
107689 {
107690 .procname = "rdma_stat_rq_prod",
107691 .data = &rdma_stat_rq_prod,
107692 - .maxlen = sizeof(atomic_t),
107693 + .maxlen = sizeof(atomic_unchecked_t),
107694 .mode = 0644,
107695 .proc_handler = read_reset_stat,
107696 },
107697 {
107698 .procname = "rdma_stat_sq_poll",
107699 .data = &rdma_stat_sq_poll,
107700 - .maxlen = sizeof(atomic_t),
107701 + .maxlen = sizeof(atomic_unchecked_t),
107702 .mode = 0644,
107703 .proc_handler = read_reset_stat,
107704 },
107705 {
107706 .procname = "rdma_stat_sq_prod",
107707 .data = &rdma_stat_sq_prod,
107708 - .maxlen = sizeof(atomic_t),
107709 + .maxlen = sizeof(atomic_unchecked_t),
107710 .mode = 0644,
107711 .proc_handler = read_reset_stat,
107712 },
107713 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
107714 index e011027..9d3c4e1 100644
107715 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
107716 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
107717 @@ -220,7 +220,7 @@ static int rdma_read_chunk_lcl(struct svcxprt_rdma *xprt,
107718 *page_no = pg_no;
107719 *page_offset = pg_off;
107720 ret = read;
107721 - atomic_inc(&rdma_stat_read);
107722 + atomic_inc_unchecked(&rdma_stat_read);
107723 return ret;
107724 err:
107725 svc_rdma_unmap_dma(ctxt);
107726 @@ -356,7 +356,7 @@ static int rdma_read_chunk_frmr(struct svcxprt_rdma *xprt,
107727 *page_no = pg_no;
107728 *page_offset = pg_off;
107729 ret = read;
107730 - atomic_inc(&rdma_stat_read);
107731 + atomic_inc_unchecked(&rdma_stat_read);
107732 return ret;
107733 err:
107734 svc_rdma_unmap_dma(ctxt);
107735 @@ -540,7 +540,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
107736 dto_q);
107737 list_del_init(&ctxt->dto_q);
107738 } else {
107739 - atomic_inc(&rdma_stat_rq_starve);
107740 + atomic_inc_unchecked(&rdma_stat_rq_starve);
107741 clear_bit(XPT_DATA, &xprt->xpt_flags);
107742 ctxt = NULL;
107743 }
107744 @@ -559,7 +559,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
107745 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
107746 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
107747 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
107748 - atomic_inc(&rdma_stat_recv);
107749 + atomic_inc_unchecked(&rdma_stat_recv);
107750
107751 /* Build up the XDR from the receive buffers. */
107752 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
107753 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
107754 index 9f1b506..2e0b321 100644
107755 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
107756 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
107757 @@ -208,7 +208,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
107758 write_wr.wr.rdma.remote_addr = to;
107759
107760 /* Post It */
107761 - atomic_inc(&rdma_stat_write);
107762 + atomic_inc_unchecked(&rdma_stat_write);
107763 if (svc_rdma_send(xprt, &write_wr))
107764 goto err;
107765 return write_len - bc;
107766 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
107767 index 374feb4..46487d5 100644
107768 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
107769 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
107770 @@ -295,7 +295,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
107771 return;
107772
107773 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
107774 - atomic_inc(&rdma_stat_rq_poll);
107775 + atomic_inc_unchecked(&rdma_stat_rq_poll);
107776
107777 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
107778 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
107779 @@ -317,7 +317,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
107780 }
107781
107782 if (ctxt)
107783 - atomic_inc(&rdma_stat_rq_prod);
107784 + atomic_inc_unchecked(&rdma_stat_rq_prod);
107785
107786 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
107787 /*
107788 @@ -392,7 +392,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
107789 return;
107790
107791 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
107792 - atomic_inc(&rdma_stat_sq_poll);
107793 + atomic_inc_unchecked(&rdma_stat_sq_poll);
107794 while ((ret = ib_poll_cq(cq, ARRAY_SIZE(wc_a), wc_a)) > 0) {
107795 int i;
107796
107797 @@ -420,7 +420,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
107798 }
107799
107800 if (ctxt)
107801 - atomic_inc(&rdma_stat_sq_prod);
107802 + atomic_inc_unchecked(&rdma_stat_sq_prod);
107803 }
107804
107805 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
107806 @@ -1264,7 +1264,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
107807 spin_lock_bh(&xprt->sc_lock);
107808 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
107809 spin_unlock_bh(&xprt->sc_lock);
107810 - atomic_inc(&rdma_stat_sq_starve);
107811 + atomic_inc_unchecked(&rdma_stat_sq_starve);
107812
107813 /* See if we can opportunistically reap SQ WR to make room */
107814 sq_cq_reap(xprt);
107815 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
107816 index e7000be..e3b0ba7 100644
107817 --- a/net/sysctl_net.c
107818 +++ b/net/sysctl_net.c
107819 @@ -46,7 +46,7 @@ static int net_ctl_permissions(struct ctl_table_header *head,
107820 kgid_t root_gid = make_kgid(net->user_ns, 0);
107821
107822 /* Allow network administrator to have same access as root. */
107823 - if (ns_capable(net->user_ns, CAP_NET_ADMIN) ||
107824 + if (ns_capable_nolog(net->user_ns, CAP_NET_ADMIN) ||
107825 uid_eq(root_uid, current_euid())) {
107826 int mode = (table->mode >> 6) & 7;
107827 return (mode << 6) | (mode << 3) | mode;
107828 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
107829 index 6424372..afd36e9 100644
107830 --- a/net/tipc/subscr.c
107831 +++ b/net/tipc/subscr.c
107832 @@ -97,7 +97,7 @@ static void subscr_send_event(struct tipc_subscription *sub, u32 found_lower,
107833 struct tipc_subscriber *subscriber = sub->subscriber;
107834 struct kvec msg_sect;
107835
107836 - msg_sect.iov_base = (void *)&sub->evt;
107837 + msg_sect.iov_base = &sub->evt;
107838 msg_sect.iov_len = sizeof(struct tipc_event);
107839 sub->evt.event = htohl(event, sub->swap);
107840 sub->evt.found_lower = htohl(found_lower, sub->swap);
107841 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
107842 index e968843..bc95776 100644
107843 --- a/net/unix/af_unix.c
107844 +++ b/net/unix/af_unix.c
107845 @@ -791,6 +791,12 @@ static struct sock *unix_find_other(struct net *net,
107846 err = -ECONNREFUSED;
107847 if (!S_ISSOCK(inode->i_mode))
107848 goto put_fail;
107849 +
107850 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
107851 + err = -EACCES;
107852 + goto put_fail;
107853 + }
107854 +
107855 u = unix_find_socket_byinode(inode);
107856 if (!u)
107857 goto put_fail;
107858 @@ -811,6 +817,13 @@ static struct sock *unix_find_other(struct net *net,
107859 if (u) {
107860 struct dentry *dentry;
107861 dentry = unix_sk(u)->path.dentry;
107862 +
107863 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
107864 + err = -EPERM;
107865 + sock_put(u);
107866 + goto fail;
107867 + }
107868 +
107869 if (dentry)
107870 touch_atime(&unix_sk(u)->path);
107871 } else
107872 @@ -844,12 +857,18 @@ static int unix_mknod(const char *sun_path, umode_t mode, struct path *res)
107873 */
107874 err = security_path_mknod(&path, dentry, mode, 0);
107875 if (!err) {
107876 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
107877 + err = -EACCES;
107878 + goto out;
107879 + }
107880 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
107881 if (!err) {
107882 res->mnt = mntget(path.mnt);
107883 res->dentry = dget(dentry);
107884 + gr_handle_create(dentry, path.mnt);
107885 }
107886 }
107887 +out:
107888 done_path_create(&path, dentry);
107889 return err;
107890 }
107891 @@ -2350,9 +2369,13 @@ static int unix_seq_show(struct seq_file *seq, void *v)
107892 seq_puts(seq, "Num RefCount Protocol Flags Type St "
107893 "Inode Path\n");
107894 else {
107895 - struct sock *s = v;
107896 + struct sock *s = v, *peer;
107897 struct unix_sock *u = unix_sk(s);
107898 unix_state_lock(s);
107899 + peer = unix_peer(s);
107900 + unix_state_unlock(s);
107901 +
107902 + unix_state_double_lock(s, peer);
107903
107904 seq_printf(seq, "%pK: %08X %08X %08X %04X %02X %5lu",
107905 s,
107906 @@ -2379,8 +2402,10 @@ static int unix_seq_show(struct seq_file *seq, void *v)
107907 }
107908 for ( ; i < len; i++)
107909 seq_putc(seq, u->addr->name->sun_path[i]);
107910 - }
107911 - unix_state_unlock(s);
107912 + } else if (peer)
107913 + seq_printf(seq, " P%lu", sock_i_ino(peer));
107914 +
107915 + unix_state_double_unlock(s, peer);
107916 seq_putc(seq, '\n');
107917 }
107918
107919 diff --git a/net/unix/sysctl_net_unix.c b/net/unix/sysctl_net_unix.c
107920 index b3d5150..ff3a837 100644
107921 --- a/net/unix/sysctl_net_unix.c
107922 +++ b/net/unix/sysctl_net_unix.c
107923 @@ -28,7 +28,7 @@ static struct ctl_table unix_table[] = {
107924
107925 int __net_init unix_sysctl_register(struct net *net)
107926 {
107927 - struct ctl_table *table;
107928 + ctl_table_no_const *table;
107929
107930 table = kmemdup(unix_table, sizeof(unix_table), GFP_KERNEL);
107931 if (table == NULL)
107932 diff --git a/net/vmw_vsock/vmci_transport_notify.c b/net/vmw_vsock/vmci_transport_notify.c
107933 index 9b7f207..2596621 100644
107934 --- a/net/vmw_vsock/vmci_transport_notify.c
107935 +++ b/net/vmw_vsock/vmci_transport_notify.c
107936 @@ -662,19 +662,19 @@ static void vmci_transport_notify_pkt_process_negotiate(struct sock *sk)
107937
107938 /* Socket control packet based operations. */
107939 struct vmci_transport_notify_ops vmci_transport_notify_pkt_ops = {
107940 - vmci_transport_notify_pkt_socket_init,
107941 - vmci_transport_notify_pkt_socket_destruct,
107942 - vmci_transport_notify_pkt_poll_in,
107943 - vmci_transport_notify_pkt_poll_out,
107944 - vmci_transport_notify_pkt_handle_pkt,
107945 - vmci_transport_notify_pkt_recv_init,
107946 - vmci_transport_notify_pkt_recv_pre_block,
107947 - vmci_transport_notify_pkt_recv_pre_dequeue,
107948 - vmci_transport_notify_pkt_recv_post_dequeue,
107949 - vmci_transport_notify_pkt_send_init,
107950 - vmci_transport_notify_pkt_send_pre_block,
107951 - vmci_transport_notify_pkt_send_pre_enqueue,
107952 - vmci_transport_notify_pkt_send_post_enqueue,
107953 - vmci_transport_notify_pkt_process_request,
107954 - vmci_transport_notify_pkt_process_negotiate,
107955 + .socket_init = vmci_transport_notify_pkt_socket_init,
107956 + .socket_destruct = vmci_transport_notify_pkt_socket_destruct,
107957 + .poll_in = vmci_transport_notify_pkt_poll_in,
107958 + .poll_out = vmci_transport_notify_pkt_poll_out,
107959 + .handle_notify_pkt = vmci_transport_notify_pkt_handle_pkt,
107960 + .recv_init = vmci_transport_notify_pkt_recv_init,
107961 + .recv_pre_block = vmci_transport_notify_pkt_recv_pre_block,
107962 + .recv_pre_dequeue = vmci_transport_notify_pkt_recv_pre_dequeue,
107963 + .recv_post_dequeue = vmci_transport_notify_pkt_recv_post_dequeue,
107964 + .send_init = vmci_transport_notify_pkt_send_init,
107965 + .send_pre_block = vmci_transport_notify_pkt_send_pre_block,
107966 + .send_pre_enqueue = vmci_transport_notify_pkt_send_pre_enqueue,
107967 + .send_post_enqueue = vmci_transport_notify_pkt_send_post_enqueue,
107968 + .process_request = vmci_transport_notify_pkt_process_request,
107969 + .process_negotiate = vmci_transport_notify_pkt_process_negotiate,
107970 };
107971 diff --git a/net/vmw_vsock/vmci_transport_notify_qstate.c b/net/vmw_vsock/vmci_transport_notify_qstate.c
107972 index dc9c792..3089de0 100644
107973 --- a/net/vmw_vsock/vmci_transport_notify_qstate.c
107974 +++ b/net/vmw_vsock/vmci_transport_notify_qstate.c
107975 @@ -420,19 +420,19 @@ vmci_transport_notify_pkt_send_pre_enqueue(
107976
107977 /* Socket always on control packet based operations. */
107978 struct vmci_transport_notify_ops vmci_transport_notify_pkt_q_state_ops = {
107979 - vmci_transport_notify_pkt_socket_init,
107980 - vmci_transport_notify_pkt_socket_destruct,
107981 - vmci_transport_notify_pkt_poll_in,
107982 - vmci_transport_notify_pkt_poll_out,
107983 - vmci_transport_notify_pkt_handle_pkt,
107984 - vmci_transport_notify_pkt_recv_init,
107985 - vmci_transport_notify_pkt_recv_pre_block,
107986 - vmci_transport_notify_pkt_recv_pre_dequeue,
107987 - vmci_transport_notify_pkt_recv_post_dequeue,
107988 - vmci_transport_notify_pkt_send_init,
107989 - vmci_transport_notify_pkt_send_pre_block,
107990 - vmci_transport_notify_pkt_send_pre_enqueue,
107991 - vmci_transport_notify_pkt_send_post_enqueue,
107992 - vmci_transport_notify_pkt_process_request,
107993 - vmci_transport_notify_pkt_process_negotiate,
107994 + .socket_init = vmci_transport_notify_pkt_socket_init,
107995 + .socket_destruct = vmci_transport_notify_pkt_socket_destruct,
107996 + .poll_in = vmci_transport_notify_pkt_poll_in,
107997 + .poll_out = vmci_transport_notify_pkt_poll_out,
107998 + .handle_notify_pkt = vmci_transport_notify_pkt_handle_pkt,
107999 + .recv_init = vmci_transport_notify_pkt_recv_init,
108000 + .recv_pre_block = vmci_transport_notify_pkt_recv_pre_block,
108001 + .recv_pre_dequeue = vmci_transport_notify_pkt_recv_pre_dequeue,
108002 + .recv_post_dequeue = vmci_transport_notify_pkt_recv_post_dequeue,
108003 + .send_init = vmci_transport_notify_pkt_send_init,
108004 + .send_pre_block = vmci_transport_notify_pkt_send_pre_block,
108005 + .send_pre_enqueue = vmci_transport_notify_pkt_send_pre_enqueue,
108006 + .send_post_enqueue = vmci_transport_notify_pkt_send_post_enqueue,
108007 + .process_request = vmci_transport_notify_pkt_process_request,
108008 + .process_negotiate = vmci_transport_notify_pkt_process_negotiate,
108009 };
108010 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
108011 index c8717c1..08539f5 100644
108012 --- a/net/wireless/wext-core.c
108013 +++ b/net/wireless/wext-core.c
108014 @@ -748,8 +748,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
108015 */
108016
108017 /* Support for very large requests */
108018 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
108019 - (user_length > descr->max_tokens)) {
108020 + if (user_length > descr->max_tokens) {
108021 /* Allow userspace to GET more than max so
108022 * we can support any size GET requests.
108023 * There is still a limit : -ENOMEM.
108024 @@ -788,22 +787,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
108025 }
108026 }
108027
108028 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
108029 - /*
108030 - * If this is a GET, but not NOMAX, it means that the extra
108031 - * data is not bounded by userspace, but by max_tokens. Thus
108032 - * set the length to max_tokens. This matches the extra data
108033 - * allocation.
108034 - * The driver should fill it with the number of tokens it
108035 - * provided, and it may check iwp->length rather than having
108036 - * knowledge of max_tokens. If the driver doesn't change the
108037 - * iwp->length, this ioctl just copies back max_token tokens
108038 - * filled with zeroes. Hopefully the driver isn't claiming
108039 - * them to be valid data.
108040 - */
108041 - iwp->length = descr->max_tokens;
108042 - }
108043 -
108044 err = handler(dev, info, (union iwreq_data *) iwp, extra);
108045
108046 iwp->length += essid_compat;
108047 diff --git a/net/x25/sysctl_net_x25.c b/net/x25/sysctl_net_x25.c
108048 index 4323952..a06dfe1 100644
108049 --- a/net/x25/sysctl_net_x25.c
108050 +++ b/net/x25/sysctl_net_x25.c
108051 @@ -70,7 +70,7 @@ static struct ctl_table x25_table[] = {
108052 .mode = 0644,
108053 .proc_handler = proc_dointvec,
108054 },
108055 - { 0, },
108056 + { },
108057 };
108058
108059 void __init x25_register_sysctl(void)
108060 diff --git a/net/x25/x25_proc.c b/net/x25/x25_proc.c
108061 index 0917f04..f4e3d8c 100644
108062 --- a/net/x25/x25_proc.c
108063 +++ b/net/x25/x25_proc.c
108064 @@ -209,7 +209,7 @@ static const struct file_operations x25_seq_forward_fops = {
108065
108066 int __init x25_proc_init(void)
108067 {
108068 - if (!proc_mkdir("x25", init_net.proc_net))
108069 + if (!proc_mkdir_restrict("x25", init_net.proc_net))
108070 return -ENOMEM;
108071
108072 if (!proc_create("x25/route", S_IRUGO, init_net.proc_net,
108073 diff --git a/net/xfrm/xfrm_output.c b/net/xfrm/xfrm_output.c
108074 index c51e8f7b..e44f360 100644
108075 --- a/net/xfrm/xfrm_output.c
108076 +++ b/net/xfrm/xfrm_output.c
108077 @@ -157,6 +157,8 @@ static int xfrm_output_gso(struct sk_buff *skb)
108078 kfree_skb(skb);
108079 if (IS_ERR(segs))
108080 return PTR_ERR(segs);
108081 + if (segs == NULL)
108082 + return -EINVAL;
108083
108084 do {
108085 struct sk_buff *nskb = segs->next;
108086 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
108087 index fdde51f..4839450 100644
108088 --- a/net/xfrm/xfrm_policy.c
108089 +++ b/net/xfrm/xfrm_policy.c
108090 @@ -330,7 +330,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
108091 {
108092 policy->walk.dead = 1;
108093
108094 - atomic_inc(&policy->genid);
108095 + atomic_inc_unchecked(&policy->genid);
108096
108097 if (del_timer(&policy->polq.hold_timer))
108098 xfrm_pol_put(policy);
108099 @@ -664,7 +664,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
108100 hlist_add_head(&policy->bydst, chain);
108101 xfrm_pol_hold(policy);
108102 net->xfrm.policy_count[dir]++;
108103 - atomic_inc(&net->xfrm.flow_cache_genid);
108104 + atomic_inc_unchecked(&net->xfrm.flow_cache_genid);
108105
108106 /* After previous checking, family can either be AF_INET or AF_INET6 */
108107 if (policy->family == AF_INET)
108108 @@ -1754,7 +1754,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
108109
108110 xdst->num_pols = num_pols;
108111 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy *) * num_pols);
108112 - xdst->policy_genid = atomic_read(&pols[0]->genid);
108113 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
108114
108115 return xdst;
108116 }
108117 @@ -2570,10 +2570,11 @@ void xfrm_garbage_collect(struct net *net)
108118 }
108119 EXPORT_SYMBOL(xfrm_garbage_collect);
108120
108121 -static void xfrm_garbage_collect_deferred(struct net *net)
108122 +void xfrm_garbage_collect_deferred(struct net *net)
108123 {
108124 flow_cache_flush_deferred(net);
108125 }
108126 +EXPORT_SYMBOL(xfrm_garbage_collect_deferred);
108127
108128 static void xfrm_init_pmtu(struct dst_entry *dst)
108129 {
108130 @@ -2623,7 +2624,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
108131 if (xdst->xfrm_genid != dst->xfrm->genid)
108132 return 0;
108133 if (xdst->num_pols > 0 &&
108134 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
108135 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
108136 return 0;
108137
108138 mtu = dst_mtu(dst->child);
108139 @@ -2711,8 +2712,6 @@ int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo)
108140 dst_ops->link_failure = xfrm_link_failure;
108141 if (likely(dst_ops->neigh_lookup == NULL))
108142 dst_ops->neigh_lookup = xfrm_neigh_lookup;
108143 - if (likely(afinfo->garbage_collect == NULL))
108144 - afinfo->garbage_collect = xfrm_garbage_collect_deferred;
108145 rcu_assign_pointer(xfrm_policy_afinfo[afinfo->family], afinfo);
108146 }
108147 spin_unlock(&xfrm_policy_afinfo_lock);
108148 @@ -2766,7 +2765,6 @@ int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo)
108149 dst_ops->check = NULL;
108150 dst_ops->negative_advice = NULL;
108151 dst_ops->link_failure = NULL;
108152 - afinfo->garbage_collect = NULL;
108153 }
108154 return err;
108155 }
108156 @@ -3151,7 +3149,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
108157 sizeof(pol->xfrm_vec[i].saddr));
108158 pol->xfrm_vec[i].encap_family = mp->new_family;
108159 /* flush bundles */
108160 - atomic_inc(&pol->genid);
108161 + atomic_inc_unchecked(&pol->genid);
108162 }
108163 }
108164
108165 diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
108166 index 0ab5413..73dd2cf 100644
108167 --- a/net/xfrm/xfrm_state.c
108168 +++ b/net/xfrm/xfrm_state.c
108169 @@ -173,12 +173,14 @@ int xfrm_register_type(const struct xfrm_type *type, unsigned short family)
108170
108171 if (unlikely(afinfo == NULL))
108172 return -EAFNOSUPPORT;
108173 - typemap = afinfo->type_map;
108174 + typemap = (const struct xfrm_type **)afinfo->type_map;
108175 spin_lock_bh(&xfrm_type_lock);
108176
108177 - if (likely(typemap[type->proto] == NULL))
108178 + if (likely(typemap[type->proto] == NULL)) {
108179 + pax_open_kernel();
108180 typemap[type->proto] = type;
108181 - else
108182 + pax_close_kernel();
108183 + } else
108184 err = -EEXIST;
108185 spin_unlock_bh(&xfrm_type_lock);
108186 xfrm_state_put_afinfo(afinfo);
108187 @@ -194,13 +196,16 @@ int xfrm_unregister_type(const struct xfrm_type *type, unsigned short family)
108188
108189 if (unlikely(afinfo == NULL))
108190 return -EAFNOSUPPORT;
108191 - typemap = afinfo->type_map;
108192 + typemap = (const struct xfrm_type **)afinfo->type_map;
108193 spin_lock_bh(&xfrm_type_lock);
108194
108195 if (unlikely(typemap[type->proto] != type))
108196 err = -ENOENT;
108197 - else
108198 + else {
108199 + pax_open_kernel();
108200 typemap[type->proto] = NULL;
108201 + pax_close_kernel();
108202 + }
108203 spin_unlock_bh(&xfrm_type_lock);
108204 xfrm_state_put_afinfo(afinfo);
108205 return err;
108206 @@ -210,7 +215,6 @@ EXPORT_SYMBOL(xfrm_unregister_type);
108207 static const struct xfrm_type *xfrm_get_type(u8 proto, unsigned short family)
108208 {
108209 struct xfrm_state_afinfo *afinfo;
108210 - const struct xfrm_type **typemap;
108211 const struct xfrm_type *type;
108212 int modload_attempted = 0;
108213
108214 @@ -218,9 +222,8 @@ retry:
108215 afinfo = xfrm_state_get_afinfo(family);
108216 if (unlikely(afinfo == NULL))
108217 return NULL;
108218 - typemap = afinfo->type_map;
108219
108220 - type = typemap[proto];
108221 + type = afinfo->type_map[proto];
108222 if (unlikely(type && !try_module_get(type->owner)))
108223 type = NULL;
108224 if (!type && !modload_attempted) {
108225 @@ -254,7 +257,7 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
108226 return -EAFNOSUPPORT;
108227
108228 err = -EEXIST;
108229 - modemap = afinfo->mode_map;
108230 + modemap = (struct xfrm_mode **)afinfo->mode_map;
108231 spin_lock_bh(&xfrm_mode_lock);
108232 if (modemap[mode->encap])
108233 goto out;
108234 @@ -263,8 +266,10 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
108235 if (!try_module_get(afinfo->owner))
108236 goto out;
108237
108238 - mode->afinfo = afinfo;
108239 + pax_open_kernel();
108240 + *(const void **)&mode->afinfo = afinfo;
108241 modemap[mode->encap] = mode;
108242 + pax_close_kernel();
108243 err = 0;
108244
108245 out:
108246 @@ -288,10 +293,12 @@ int xfrm_unregister_mode(struct xfrm_mode *mode, int family)
108247 return -EAFNOSUPPORT;
108248
108249 err = -ENOENT;
108250 - modemap = afinfo->mode_map;
108251 + modemap = (struct xfrm_mode **)afinfo->mode_map;
108252 spin_lock_bh(&xfrm_mode_lock);
108253 if (likely(modemap[mode->encap] == mode)) {
108254 + pax_open_kernel();
108255 modemap[mode->encap] = NULL;
108256 + pax_close_kernel();
108257 module_put(mode->afinfo->owner);
108258 err = 0;
108259 }
108260 @@ -1512,10 +1519,10 @@ EXPORT_SYMBOL(xfrm_find_acq_byseq);
108261 u32 xfrm_get_acqseq(void)
108262 {
108263 u32 res;
108264 - static atomic_t acqseq;
108265 + static atomic_unchecked_t acqseq;
108266
108267 do {
108268 - res = atomic_inc_return(&acqseq);
108269 + res = atomic_inc_return_unchecked(&acqseq);
108270 } while (!res);
108271
108272 return res;
108273 diff --git a/net/xfrm/xfrm_sysctl.c b/net/xfrm/xfrm_sysctl.c
108274 index 05a6e3d..6716ec9 100644
108275 --- a/net/xfrm/xfrm_sysctl.c
108276 +++ b/net/xfrm/xfrm_sysctl.c
108277 @@ -42,7 +42,7 @@ static struct ctl_table xfrm_table[] = {
108278
108279 int __net_init xfrm_sysctl_init(struct net *net)
108280 {
108281 - struct ctl_table *table;
108282 + ctl_table_no_const *table;
108283
108284 __xfrm_sysctl_init(net);
108285
108286 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
108287 index bf3e677..c7d426e 100644
108288 --- a/scripts/Makefile.build
108289 +++ b/scripts/Makefile.build
108290 @@ -60,7 +60,7 @@ endif
108291 endif
108292
108293 # Do not include host rules unless needed
108294 -ifneq ($(hostprogs-y)$(hostprogs-m),)
108295 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
108296 include scripts/Makefile.host
108297 endif
108298
108299 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
108300 index a651cee..6b3b9a3 100644
108301 --- a/scripts/Makefile.clean
108302 +++ b/scripts/Makefile.clean
108303 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
108304 __clean-files := $(extra-y) $(extra-m) $(extra-) \
108305 $(always) $(targets) $(clean-files) \
108306 $(host-progs) \
108307 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
108308 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
108309 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
108310
108311 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
108312
108313 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
108314 index ab5980f..85fd3e1 100644
108315 --- a/scripts/Makefile.host
108316 +++ b/scripts/Makefile.host
108317 @@ -20,7 +20,19 @@
108318 # Will compile qconf as a C++ program, and menu as a C program.
108319 # They are linked as C++ code to the executable qconf
108320
108321 +# hostprogs-y := conf
108322 +# conf-objs := conf.o libkconfig.so
108323 +# libkconfig-objs := expr.o type.o
108324 +# Will create a shared library named libkconfig.so that consists of
108325 +# expr.o and type.o (they are both compiled as C code and the object files
108326 +# are made as position independent code).
108327 +# conf.c is compiled as a C program, and conf.o is linked together with
108328 +# libkconfig.so as the executable conf.
108329 +# Note: Shared libraries consisting of C++ files are not supported
108330 +
108331 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
108332 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
108333 +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
108334
108335 # C code
108336 # Executables compiled from a single .c file
108337 @@ -42,6 +54,19 @@ host-cxxmulti := $(foreach m,$(__hostprogs),$(if $($(m)-cxxobjs),$(m)))
108338 # C++ Object (.o) files compiled from .cc files
108339 host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
108340
108341 +# Shared libaries (only .c supported)
108342 +# Shared libraries (.so) - all .so files referenced in "xxx-objs"
108343 +host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
108344 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
108345 +host-cxxshlib := $(sort $(filter %.so, $(__hostcxxlibs)))
108346 +# Remove .so files from "xxx-objs"
108347 +host-cobjs := $(filter-out %.so,$(host-cobjs))
108348 +host-cxxobjs := $(filter-out %.so,$(host-cxxobjs))
108349 +
108350 +# Object (.o) files used by the shared libaries
108351 +host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
108352 +host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
108353 +
108354 # output directory for programs/.o files
108355 # hostprogs-y := tools/build may have been specified.
108356 # Retrieve also directory of .o files from prog-objs or prog-cxxobjs notation
108357 @@ -56,6 +81,10 @@ host-cmulti := $(addprefix $(obj)/,$(host-cmulti))
108358 host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
108359 host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
108360 host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
108361 +host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
108362 +host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
108363 +host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
108364 +host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
108365 host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
108366
108367 obj-dirs += $(host-objdirs)
108368 @@ -96,7 +125,7 @@ quiet_cmd_host-cmulti = HOSTLD $@
108369 cmd_host-cmulti = $(HOSTCC) $(HOSTLDFLAGS) -o $@ \
108370 $(addprefix $(obj)/,$($(@F)-objs)) \
108371 $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
108372 -$(host-cmulti): $(obj)/%: $(host-cobjs) FORCE
108373 +$(host-cmulti): $(obj)/%: $(host-cobjs) $(host-cshlib) FORCE
108374 $(call if_changed,host-cmulti)
108375
108376 # Create .o file from a single .c file
108377 @@ -113,7 +142,7 @@ quiet_cmd_host-cxxmulti = HOSTLD $@
108378 $(foreach o,objs cxxobjs,\
108379 $(addprefix $(obj)/,$($(@F)-$(o)))) \
108380 $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
108381 -$(host-cxxmulti): $(obj)/%: $(host-cobjs) $(host-cxxobjs) FORCE
108382 +$(host-cxxmulti): $(obj)/%: $(host-cobjs) $(host-cxxobjs) $(host-cshlib) FORCE
108383 $(call if_changed,host-cxxmulti)
108384
108385 # Create .o file from a single .cc (C++) file
108386 @@ -122,5 +151,37 @@ quiet_cmd_host-cxxobjs = HOSTCXX $@
108387 $(host-cxxobjs): $(obj)/%.o: $(src)/%.cc FORCE
108388 $(call if_changed_dep,host-cxxobjs)
108389
108390 +# Compile .c file, create position independent .o file
108391 +# host-cshobjs -> .o
108392 +quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
108393 + cmd_host-cshobjs = $(HOSTCC) $(hostc_flags) -fPIC -c -o $@ $<
108394 +$(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
108395 + $(call if_changed_dep,host-cshobjs)
108396 +
108397 +# Compile .c file, create position independent .o file
108398 +# host-cxxshobjs -> .o
108399 +quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
108400 + cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
108401 +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
108402 + $(call if_changed_dep,host-cxxshobjs)
108403 +
108404 +# Link a shared library, based on position independent .o files
108405 +# *.o -> .so shared library (host-cshlib)
108406 +quiet_cmd_host-cshlib = HOSTLLD -shared $@
108407 + cmd_host-cshlib = $(HOSTCC) $(HOSTLDFLAGS) -shared -o $@ \
108408 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
108409 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
108410 +$(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
108411 + $(call if_changed,host-cshlib)
108412 +
108413 +# Link a shared library, based on position independent .o files
108414 +# *.o -> .so shared library (host-cxxshlib)
108415 +quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
108416 + cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
108417 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
108418 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
108419 +$(host-cxxshlib): $(obj)/%: $(host-cxxshobjs) FORCE
108420 + $(call if_changed,host-cxxshlib)
108421 +
108422 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
108423 - $(host-cxxmulti) $(host-cxxobjs)
108424 + $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
108425 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
108426 index b304068..462d24e 100644
108427 --- a/scripts/basic/fixdep.c
108428 +++ b/scripts/basic/fixdep.c
108429 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
108430 /*
108431 * Lookup a value in the configuration string.
108432 */
108433 -static int is_defined_config(const char *name, int len, unsigned int hash)
108434 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
108435 {
108436 struct item *aux;
108437
108438 @@ -211,10 +211,10 @@ static void clear_config(void)
108439 /*
108440 * Record the use of a CONFIG_* word.
108441 */
108442 -static void use_config(const char *m, int slen)
108443 +static void use_config(const char *m, unsigned int slen)
108444 {
108445 unsigned int hash = strhash(m, slen);
108446 - int c, i;
108447 + unsigned int c, i;
108448
108449 if (is_defined_config(m, slen, hash))
108450 return;
108451 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
108452
108453 static void parse_config_file(const char *map, size_t len)
108454 {
108455 - const int *end = (const int *) (map + len);
108456 + const unsigned int *end = (const unsigned int *) (map + len);
108457 /* start at +1, so that p can never be < map */
108458 - const int *m = (const int *) map + 1;
108459 + const unsigned int *m = (const unsigned int *) map + 1;
108460 const char *p, *q;
108461
108462 for (; m < end; m++) {
108463 @@ -435,7 +435,7 @@ static void print_deps(void)
108464 static void traps(void)
108465 {
108466 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
108467 - int *p = (int *)test;
108468 + unsigned int *p = (unsigned int *)test;
108469
108470 if (*p != INT_CONF) {
108471 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianness? %#x\n",
108472 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
108473 new file mode 100644
108474 index 0000000..42018ed
108475 --- /dev/null
108476 +++ b/scripts/gcc-plugin.sh
108477 @@ -0,0 +1,51 @@
108478 +#!/bin/sh
108479 +srctree=$(dirname "$0")
108480 +gccplugins_dir=$($3 -print-file-name=plugin)
108481 +plugincc=$($1 -E - -o /dev/null -I${srctree}/../tools/gcc -I${gccplugins_dir}/include 2>&1 <<EOF
108482 +#include "gcc-common.h"
108483 +#if BUILDING_GCC_VERSION >= 4008 || defined(ENABLE_BUILD_WITH_CXX)
108484 +#warning $2 CXX
108485 +#else
108486 +#warning $1 CC
108487 +#endif
108488 +EOF
108489 +)
108490 +
108491 +if [ $? -ne 0 ]
108492 +then
108493 + exit 1
108494 +fi
108495 +
108496 +case "$plugincc" in
108497 + *"$1 CC"*)
108498 + echo "$1"
108499 + exit 0
108500 + ;;
108501 +
108502 + *"$2 CXX"*)
108503 + # the c++ compiler needs another test, see below
108504 + ;;
108505 +
108506 + *)
108507 + exit 1
108508 + ;;
108509 +esac
108510 +
108511 +# we need a c++ compiler that supports the designated initializer GNU extension
108512 +plugincc=$($2 -c -x c++ -std=gnu++98 - -fsyntax-only -I${srctree}/../tools/gcc -I${gccplugins_dir}/include 2>&1 <<EOF
108513 +#include "gcc-common.h"
108514 +class test {
108515 +public:
108516 + int test;
108517 +} test = {
108518 + .test = 1
108519 +};
108520 +EOF
108521 +)
108522 +
108523 +if [ $? -eq 0 ]
108524 +then
108525 + echo "$2"
108526 + exit 0
108527 +fi
108528 +exit 1
108529 diff --git a/scripts/headers_install.sh b/scripts/headers_install.sh
108530 index 5de5660..d3deb89 100644
108531 --- a/scripts/headers_install.sh
108532 +++ b/scripts/headers_install.sh
108533 @@ -32,6 +32,7 @@ do
108534 FILE="$(basename "$i")"
108535 sed -r \
108536 -e 's/([ \t(])(__user|__force|__iomem)[ \t]/\1/g' \
108537 + -e 's/__intentional_overflow\([- \t,0-9]*\)//g' \
108538 -e 's/__attribute_const__([ \t]|$)/\1/g' \
108539 -e 's@^#include <linux/compiler.h>@@' \
108540 -e 's/(^|[^a-zA-Z0-9])__packed([^a-zA-Z0-9_]|$)/\1__attribute__((packed))\2/g' \
108541 diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
108542 index 86a4fe7..99e91f9 100644
108543 --- a/scripts/link-vmlinux.sh
108544 +++ b/scripts/link-vmlinux.sh
108545 @@ -166,7 +166,7 @@ else
108546 fi;
108547
108548 # final build of init/
108549 -${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init
108550 +${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init GCC_PLUGINS_CFLAGS="${GCC_PLUGINS_CFLAGS}" GCC_PLUGINS_AFLAGS="${GCC_PLUGINS_AFLAGS}"
108551
108552 kallsymso=""
108553 kallsyms_vmlinux=""
108554 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
108555 index e614ef6..d9d2b01 100644
108556 --- a/scripts/mod/file2alias.c
108557 +++ b/scripts/mod/file2alias.c
108558 @@ -142,7 +142,7 @@ static void device_id_check(const char *modname, const char *device_id,
108559 unsigned long size, unsigned long id_size,
108560 void *symval)
108561 {
108562 - int i;
108563 + unsigned int i;
108564
108565 if (size % id_size || size < id_size) {
108566 fatal("%s: sizeof(struct %s_device_id)=%lu is not a modulo "
108567 @@ -171,7 +171,7 @@ static void device_id_check(const char *modname, const char *device_id,
108568 /* USB is special because the bcdDevice can be matched against a numeric range */
108569 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipNinN" */
108570 static void do_usb_entry(void *symval,
108571 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
108572 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
108573 unsigned char range_lo, unsigned char range_hi,
108574 unsigned char max, struct module *mod)
108575 {
108576 @@ -281,7 +281,7 @@ static void do_usb_entry_multi(void *symval, struct module *mod)
108577 {
108578 unsigned int devlo, devhi;
108579 unsigned char chi, clo, max;
108580 - int ndigits;
108581 + unsigned int ndigits;
108582
108583 DEF_FIELD(symval, usb_device_id, match_flags);
108584 DEF_FIELD(symval, usb_device_id, idVendor);
108585 @@ -534,7 +534,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
108586 for (i = 0; i < count; i++) {
108587 DEF_FIELD_ADDR(symval + i*id_size, pnp_device_id, id);
108588 char acpi_id[sizeof(*id)];
108589 - int j;
108590 + unsigned int j;
108591
108592 buf_printf(&mod->dev_table_buf,
108593 "MODULE_ALIAS(\"pnp:d%s*\");\n", *id);
108594 @@ -563,7 +563,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
108595
108596 for (j = 0; j < PNP_MAX_DEVICES; j++) {
108597 const char *id = (char *)(*devs)[j].id;
108598 - int i2, j2;
108599 + unsigned int i2, j2;
108600 int dup = 0;
108601
108602 if (!id[0])
108603 @@ -589,7 +589,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
108604 /* add an individual alias for every device entry */
108605 if (!dup) {
108606 char acpi_id[PNP_ID_LEN];
108607 - int k;
108608 + unsigned int k;
108609
108610 buf_printf(&mod->dev_table_buf,
108611 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
108612 @@ -939,7 +939,7 @@ static void dmi_ascii_filter(char *d, const char *s)
108613 static int do_dmi_entry(const char *filename, void *symval,
108614 char *alias)
108615 {
108616 - int i, j;
108617 + unsigned int i, j;
108618 DEF_FIELD_ADDR(symval, dmi_system_id, matches);
108619 sprintf(alias, "dmi*");
108620
108621 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
108622 index 091d905..77b88c7 100644
108623 --- a/scripts/mod/modpost.c
108624 +++ b/scripts/mod/modpost.c
108625 @@ -920,6 +920,7 @@ enum mismatch {
108626 ANY_INIT_TO_ANY_EXIT,
108627 ANY_EXIT_TO_ANY_INIT,
108628 EXPORT_TO_INIT_EXIT,
108629 + DATA_TO_TEXT
108630 };
108631
108632 struct sectioncheck {
108633 @@ -1006,6 +1007,12 @@ const struct sectioncheck sectioncheck[] = {
108634 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
108635 .mismatch = EXPORT_TO_INIT_EXIT,
108636 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
108637 +},
108638 +/* Do not reference code from writable data */
108639 +{
108640 + .fromsec = { DATA_SECTIONS, NULL },
108641 + .tosec = { TEXT_SECTIONS, NULL },
108642 + .mismatch = DATA_TO_TEXT
108643 }
108644 };
108645
108646 @@ -1126,10 +1133,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
108647 continue;
108648 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
108649 continue;
108650 - if (sym->st_value == addr)
108651 - return sym;
108652 /* Find a symbol nearby - addr are maybe negative */
108653 d = sym->st_value - addr;
108654 + if (d == 0)
108655 + return sym;
108656 if (d < 0)
108657 d = addr - sym->st_value;
108658 if (d < distance) {
108659 @@ -1407,6 +1414,14 @@ static void report_sec_mismatch(const char *modname,
108660 tosym, prl_to, prl_to, tosym);
108661 free(prl_to);
108662 break;
108663 + case DATA_TO_TEXT:
108664 +#if 0
108665 + fprintf(stderr,
108666 + "The %s %s:%s references\n"
108667 + "the %s %s:%s%s\n",
108668 + from, fromsec, fromsym, to, tosec, tosym, to_p);
108669 +#endif
108670 + break;
108671 }
108672 fprintf(stderr, "\n");
108673 }
108674 @@ -1658,7 +1673,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
108675 static void check_sec_ref(struct module *mod, const char *modname,
108676 struct elf_info *elf)
108677 {
108678 - int i;
108679 + unsigned int i;
108680 Elf_Shdr *sechdrs = elf->sechdrs;
108681
108682 /* Walk through all sections */
108683 @@ -1789,7 +1804,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
108684 va_end(ap);
108685 }
108686
108687 -void buf_write(struct buffer *buf, const char *s, int len)
108688 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
108689 {
108690 if (buf->size - buf->pos < len) {
108691 buf->size += len + SZ;
108692 @@ -2008,7 +2023,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
108693 if (fstat(fileno(file), &st) < 0)
108694 goto close_write;
108695
108696 - if (st.st_size != b->pos)
108697 + if (st.st_size != (off_t)b->pos)
108698 goto close_write;
108699
108700 tmp = NOFAIL(malloc(b->pos));
108701 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
108702 index 168b43d..77914bf 100644
108703 --- a/scripts/mod/modpost.h
108704 +++ b/scripts/mod/modpost.h
108705 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
108706
108707 struct buffer {
108708 char *p;
108709 - int pos;
108710 - int size;
108711 + unsigned int pos;
108712 + unsigned int size;
108713 };
108714
108715 void __attribute__((format(printf, 2, 3)))
108716 buf_printf(struct buffer *buf, const char *fmt, ...);
108717
108718 void
108719 -buf_write(struct buffer *buf, const char *s, int len);
108720 +buf_write(struct buffer *buf, const char *s, unsigned int len);
108721
108722 struct module {
108723 struct module *next;
108724 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
108725 index 944418d..15291e4 100644
108726 --- a/scripts/mod/sumversion.c
108727 +++ b/scripts/mod/sumversion.c
108728 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
108729 goto out;
108730 }
108731
108732 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
108733 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
108734 warn("writing sum in %s failed: %s\n",
108735 filename, strerror(errno));
108736 goto out;
108737 diff --git a/scripts/module-common.lds b/scripts/module-common.lds
108738 index 0865b3e..7235dd4 100644
108739 --- a/scripts/module-common.lds
108740 +++ b/scripts/module-common.lds
108741 @@ -6,6 +6,10 @@
108742 SECTIONS {
108743 /DISCARD/ : { *(.discard) }
108744
108745 + .rodata : {
108746 + *(.rodata) *(.rodata.*)
108747 + *(.data..read_only)
108748 + }
108749 __ksymtab : { *(SORT(___ksymtab+*)) }
108750 __ksymtab_gpl : { *(SORT(___ksymtab_gpl+*)) }
108751 __ksymtab_unused : { *(SORT(___ksymtab_unused+*)) }
108752 diff --git a/scripts/package/Makefile b/scripts/package/Makefile
108753 index 99ca6e7..3a1a1a1 100644
108754 --- a/scripts/package/Makefile
108755 +++ b/scripts/package/Makefile
108756 @@ -46,7 +46,7 @@ rpm-pkg rpm: FORCE
108757 ln -sf $(srctree) $(KERNELPATH)
108758 $(CONFIG_SHELL) $(MKSPEC) >$(objtree)/kernel.spec
108759 $(CONFIG_SHELL) $(srctree)/scripts/setlocalversion --save-scmversion
108760 - tar -cz $(RCS_TAR_IGNORE) -f $(KERNELPATH).tar.gz $(TAR_CONTENT)
108761 + tar --owner=root --group=root -cz $(RCS_TAR_IGNORE) -f $(KERNELPATH).tar.gz $(TAR_CONTENT)
108762 rm $(KERNELPATH)
108763 rm -f $(objtree)/.scmversion
108764 $(CONFIG_SHELL) $(srctree)/scripts/mkversion > $(objtree)/.tmp_version
108765 diff --git a/scripts/package/builddeb b/scripts/package/builddeb
108766 index 7c0e6e4..bf2c90e 100644
108767 --- a/scripts/package/builddeb
108768 +++ b/scripts/package/builddeb
108769 @@ -293,6 +293,7 @@ fi
108770 (cd $srctree; find arch/$SRCARCH -name module.lds -o -name Kbuild.platforms -o -name Platform) >> "$objtree/debian/hdrsrcfiles"
108771 (cd $srctree; find $(find arch/$SRCARCH -name include -o -name scripts -type d) -type f) >> "$objtree/debian/hdrsrcfiles"
108772 (cd $objtree; find arch/$SRCARCH/include Module.symvers include scripts -type f) >> "$objtree/debian/hdrobjfiles"
108773 +(cd $objtree; find tools/gcc -name \*.so >> "$objtree/debian/hdrobjfiles")
108774 destdir=$kernel_headers_dir/usr/src/linux-headers-$version
108775 mkdir -p "$destdir"
108776 (cd $srctree; tar -c -f - -T -) < "$objtree/debian/hdrsrcfiles" | (cd $destdir; tar -xf -)
108777 diff --git a/scripts/package/mkspec b/scripts/package/mkspec
108778 index 1395760..6ceef68 100755
108779 --- a/scripts/package/mkspec
108780 +++ b/scripts/package/mkspec
108781 @@ -121,14 +121,27 @@ echo 'rm -f $RPM_BUILD_ROOT'"/lib/modules/$KERNELRELEASE/{build,source}"
108782 echo "mkdir -p "'$RPM_BUILD_ROOT'"/usr/src/kernels/$KERNELRELEASE"
108783 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\""
108784 echo "tar "'$EXCLUDES'" -cf- . | (cd "'$RPM_BUILD_ROOT'"/usr/src/kernels/$KERNELRELEASE;tar xvf -)"
108785 -echo 'cd $RPM_BUILD_ROOT'"/lib/modules/$KERNELRELEASE"
108786 -echo "ln -sf /usr/src/kernels/$KERNELRELEASE build"
108787 -echo "ln -sf /usr/src/kernels/$KERNELRELEASE source"
108788
108789 echo ""
108790 echo "%clean"
108791 echo 'rm -rf $RPM_BUILD_ROOT'
108792 echo ""
108793 +echo "%pre"
108794 +echo 'chmod -f 0500 /boot'
108795 +echo 'if [ -d /lib/modules ]; then'
108796 +echo 'chmod -f 0500 /lib/modules'
108797 +echo 'fi'
108798 +echo 'if [ -d /lib32/modules ]; then'
108799 +echo 'chmod -f 0500 /lib32/modules'
108800 +echo 'fi'
108801 +echo 'if [ -d /lib64/modules ]; then'
108802 +echo 'chmod -f 0500 /lib64/modules'
108803 +echo 'fi'
108804 +echo ""
108805 +echo "%post devel"
108806 +echo "ln -sf /usr/src/kernels/$KERNELRELEASE /lib/modules/$KERNELRELEASE/build"
108807 +echo "ln -sf /usr/src/kernels/$KERNELRELEASE /lib/modules/$KERNELRELEASE/source"
108808 +echo ""
108809 echo "%post"
108810 echo "if [ -x /sbin/installkernel -a -r /boot/vmlinuz-$KERNELRELEASE -a -r /boot/System.map-$KERNELRELEASE ]; then"
108811 echo "cp /boot/vmlinuz-$KERNELRELEASE /boot/vmlinuz-$KERNELRELEASE-rpm"
108812 @@ -139,11 +152,11 @@ echo "rm -f /boot/vmlinuz-$KERNELRELEASE-rpm /boot/System.map-$KERNELRELEASE-rpm
108813 echo "fi"
108814 echo ""
108815 echo "%files"
108816 -echo '%defattr (-, root, root)'
108817 +echo '%defattr (400, root, root, 500)'
108818 echo "%dir /lib/modules"
108819 -echo "/lib/modules/$KERNELRELEASE"
108820 echo "%exclude /lib/modules/$KERNELRELEASE/build"
108821 echo "%exclude /lib/modules/$KERNELRELEASE/source"
108822 +echo "/lib/modules/$KERNELRELEASE"
108823 echo "/lib/firmware/$KERNELRELEASE"
108824 echo "/boot/*"
108825 echo ""
108826 @@ -152,8 +165,7 @@ echo '%defattr (-, root, root)'
108827 echo "/usr/include"
108828 echo ""
108829 echo "%files devel"
108830 -echo '%defattr (-, root, root)'
108831 +echo '%defattr (400, root, root, 500)'
108832 +echo "%dir /lib/modules/$KERNELRELEASE"
108833 echo "/usr/src/kernels/$KERNELRELEASE"
108834 -echo "/lib/modules/$KERNELRELEASE/build"
108835 -echo "/lib/modules/$KERNELRELEASE/source"
108836 echo ""
108837 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
108838 index 4718d78..9220d58 100644
108839 --- a/scripts/pnmtologo.c
108840 +++ b/scripts/pnmtologo.c
108841 @@ -244,14 +244,14 @@ static void write_header(void)
108842 fprintf(out, " * Linux logo %s\n", logoname);
108843 fputs(" */\n\n", out);
108844 fputs("#include <linux/linux_logo.h>\n\n", out);
108845 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
108846 + fprintf(out, "static unsigned char %s_data[] = {\n",
108847 logoname);
108848 }
108849
108850 static void write_footer(void)
108851 {
108852 fputs("\n};\n\n", out);
108853 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
108854 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
108855 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
108856 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
108857 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
108858 @@ -381,7 +381,7 @@ static void write_logo_clut224(void)
108859 fputs("\n};\n\n", out);
108860
108861 /* write logo clut */
108862 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
108863 + fprintf(out, "static unsigned char %s_clut[] = {\n",
108864 logoname);
108865 write_hex_cnt = 0;
108866 for (i = 0; i < logo_clutsize; i++) {
108867 diff --git a/scripts/sortextable.h b/scripts/sortextable.h
108868 index 8fac3fd..32ff38d 100644
108869 --- a/scripts/sortextable.h
108870 +++ b/scripts/sortextable.h
108871 @@ -108,9 +108,9 @@ do_func(Elf_Ehdr *ehdr, char const *const fname, table_sort_t custom_sort)
108872 const char *secstrtab;
108873 const char *strtab;
108874 char *extab_image;
108875 - int extab_index = 0;
108876 - int i;
108877 - int idx;
108878 + unsigned int extab_index = 0;
108879 + unsigned int i;
108880 + unsigned int idx;
108881 unsigned int num_sections;
108882 unsigned int secindex_strings;
108883
108884 diff --git a/scripts/tags.sh b/scripts/tags.sh
108885 index 293828b..9fbe696 100755
108886 --- a/scripts/tags.sh
108887 +++ b/scripts/tags.sh
108888 @@ -26,7 +26,7 @@ else
108889 fi
108890
108891 # ignore userspace tools
108892 -ignore="$ignore ( -path ${tree}tools ) -prune -o"
108893 +ignore="$ignore ( -path \"${tree}tools/[^g]*\" ) -prune -o"
108894
108895 # Find all available archs
108896 find_all_archs()
108897 diff --git a/security/Kconfig b/security/Kconfig
108898 index beb86b5..1a953b1 100644
108899 --- a/security/Kconfig
108900 +++ b/security/Kconfig
108901 @@ -4,6 +4,974 @@
108902
108903 menu "Security options"
108904
108905 +menu "Grsecurity"
108906 +
108907 + config ARCH_TRACK_EXEC_LIMIT
108908 + bool
108909 +
108910 + config PAX_KERNEXEC_PLUGIN
108911 + bool
108912 +
108913 + config PAX_PER_CPU_PGD
108914 + bool
108915 +
108916 + config TASK_SIZE_MAX_SHIFT
108917 + int
108918 + depends on X86_64
108919 + default 47 if !PAX_PER_CPU_PGD
108920 + default 42 if PAX_PER_CPU_PGD
108921 +
108922 + config PAX_ENABLE_PAE
108923 + bool
108924 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
108925 +
108926 + config PAX_USERCOPY_SLABS
108927 + bool
108928 +
108929 +config GRKERNSEC
108930 + bool "Grsecurity"
108931 + select CRYPTO
108932 + select CRYPTO_SHA256
108933 + select PROC_FS
108934 + select STOP_MACHINE
108935 + select TTY
108936 + select DEBUG_KERNEL
108937 + select DEBUG_LIST
108938 + help
108939 + If you say Y here, you will be able to configure many features
108940 + that will enhance the security of your system. It is highly
108941 + recommended that you say Y here and read through the help
108942 + for each option so that you fully understand the features and
108943 + can evaluate their usefulness for your machine.
108944 +
108945 +choice
108946 + prompt "Configuration Method"
108947 + depends on GRKERNSEC
108948 + default GRKERNSEC_CONFIG_CUSTOM
108949 + help
108950 +
108951 +config GRKERNSEC_CONFIG_AUTO
108952 + bool "Automatic"
108953 + help
108954 + If you choose this configuration method, you'll be able to answer a small
108955 + number of simple questions about how you plan to use this kernel.
108956 + The settings of grsecurity and PaX will be automatically configured for
108957 + the highest commonly-used settings within the provided constraints.
108958 +
108959 + If you require additional configuration, custom changes can still be made
108960 + from the "custom configuration" menu.
108961 +
108962 +config GRKERNSEC_CONFIG_CUSTOM
108963 + bool "Custom"
108964 + help
108965 + If you choose this configuration method, you'll be able to configure all
108966 + grsecurity and PaX settings manually. Via this method, no options are
108967 + automatically enabled.
108968 +
108969 +endchoice
108970 +
108971 +choice
108972 + prompt "Usage Type"
108973 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
108974 + default GRKERNSEC_CONFIG_SERVER
108975 + help
108976 +
108977 +config GRKERNSEC_CONFIG_SERVER
108978 + bool "Server"
108979 + help
108980 + Choose this option if you plan to use this kernel on a server.
108981 +
108982 +config GRKERNSEC_CONFIG_DESKTOP
108983 + bool "Desktop"
108984 + help
108985 + Choose this option if you plan to use this kernel on a desktop.
108986 +
108987 +endchoice
108988 +
108989 +choice
108990 + prompt "Virtualization Type"
108991 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO)
108992 + default GRKERNSEC_CONFIG_VIRT_NONE
108993 + help
108994 +
108995 +config GRKERNSEC_CONFIG_VIRT_NONE
108996 + bool "None"
108997 + help
108998 + Choose this option if this kernel will be run on bare metal.
108999 +
109000 +config GRKERNSEC_CONFIG_VIRT_GUEST
109001 + bool "Guest"
109002 + help
109003 + Choose this option if this kernel will be run as a VM guest.
109004 +
109005 +config GRKERNSEC_CONFIG_VIRT_HOST
109006 + bool "Host"
109007 + help
109008 + Choose this option if this kernel will be run as a VM host.
109009 +
109010 +endchoice
109011 +
109012 +choice
109013 + prompt "Virtualization Hardware"
109014 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
109015 + help
109016 +
109017 +config GRKERNSEC_CONFIG_VIRT_EPT
109018 + bool "EPT/RVI Processor Support"
109019 + depends on X86
109020 + help
109021 + Choose this option if your CPU supports the EPT or RVI features of 2nd-gen
109022 + hardware virtualization. This allows for additional kernel hardening protections
109023 + to operate without additional performance impact.
109024 +
109025 + To see if your Intel processor supports EPT, see:
109026 + http://ark.intel.com/Products/VirtualizationTechnology
109027 + (Most Core i3/5/7 support EPT)
109028 +
109029 + To see if your AMD processor supports RVI, see:
109030 + http://support.amd.com/us/kbarticles/Pages/GPU120AMDRVICPUsHyperVWin8.aspx
109031 +
109032 +config GRKERNSEC_CONFIG_VIRT_SOFT
109033 + bool "First-gen/No Hardware Virtualization"
109034 + help
109035 + Choose this option if you use an Atom/Pentium/Core 2 processor that either doesn't
109036 + support hardware virtualization or doesn't support the EPT/RVI extensions.
109037 +
109038 +endchoice
109039 +
109040 +choice
109041 + prompt "Virtualization Software"
109042 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
109043 + help
109044 +
109045 +config GRKERNSEC_CONFIG_VIRT_XEN
109046 + bool "Xen"
109047 + help
109048 + Choose this option if this kernel is running as a Xen guest or host.
109049 +
109050 +config GRKERNSEC_CONFIG_VIRT_VMWARE
109051 + bool "VMWare"
109052 + help
109053 + Choose this option if this kernel is running as a VMWare guest or host.
109054 +
109055 +config GRKERNSEC_CONFIG_VIRT_KVM
109056 + bool "KVM"
109057 + help
109058 + Choose this option if this kernel is running as a KVM guest or host.
109059 +
109060 +config GRKERNSEC_CONFIG_VIRT_VIRTUALBOX
109061 + bool "VirtualBox"
109062 + help
109063 + Choose this option if this kernel is running as a VirtualBox guest or host.
109064 +
109065 +config GRKERNSEC_CONFIG_VIRT_HYPERV
109066 + bool "Hyper-V"
109067 + help
109068 + Choose this option if this kernel is running as a Hyper-V guest.
109069 +
109070 +endchoice
109071 +
109072 +choice
109073 + prompt "Required Priorities"
109074 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
109075 + default GRKERNSEC_CONFIG_PRIORITY_PERF
109076 + help
109077 +
109078 +config GRKERNSEC_CONFIG_PRIORITY_PERF
109079 + bool "Performance"
109080 + help
109081 + Choose this option if performance is of highest priority for this deployment
109082 + of grsecurity. Features like UDEREF on a 64bit kernel, kernel stack clearing,
109083 + clearing of structures intended for userland, and freed memory sanitizing will
109084 + be disabled.
109085 +
109086 +config GRKERNSEC_CONFIG_PRIORITY_SECURITY
109087 + bool "Security"
109088 + help
109089 + Choose this option if security is of highest priority for this deployment of
109090 + grsecurity. UDEREF, kernel stack clearing, clearing of structures intended
109091 + for userland, and freed memory sanitizing will be enabled for this kernel.
109092 + In a worst-case scenario, these features can introduce a 20% performance hit
109093 + (UDEREF on x64 contributing half of this hit).
109094 +
109095 +endchoice
109096 +
109097 +menu "Default Special Groups"
109098 +depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
109099 +
109100 +config GRKERNSEC_PROC_GID
109101 + int "GID exempted from /proc restrictions"
109102 + default 1001
109103 + help
109104 + Setting this GID determines which group will be exempted from
109105 + grsecurity's /proc restrictions, allowing users of the specified
109106 + group to view network statistics and the existence of other users'
109107 + processes on the system. This GID may also be chosen at boot time
109108 + via "grsec_proc_gid=" on the kernel commandline.
109109 +
109110 +config GRKERNSEC_TPE_UNTRUSTED_GID
109111 + int "GID for TPE-untrusted users"
109112 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
109113 + default 1005
109114 + help
109115 + Setting this GID determines which group untrusted users should
109116 + be added to. These users will be placed under grsecurity's Trusted Path
109117 + Execution mechanism, preventing them from executing their own binaries.
109118 + The users will only be able to execute binaries in directories owned and
109119 + writable only by the root user. If the sysctl option is enabled, a sysctl
109120 + option with name "tpe_gid" is created.
109121 +
109122 +config GRKERNSEC_TPE_TRUSTED_GID
109123 + int "GID for TPE-trusted users"
109124 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
109125 + default 1005
109126 + help
109127 + Setting this GID determines what group TPE restrictions will be
109128 + *disabled* for. If the sysctl option is enabled, a sysctl option
109129 + with name "tpe_gid" is created.
109130 +
109131 +config GRKERNSEC_SYMLINKOWN_GID
109132 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
109133 + depends on GRKERNSEC_CONFIG_SERVER
109134 + default 1006
109135 + help
109136 + Setting this GID determines what group kernel-enforced
109137 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
109138 + is enabled, a sysctl option with name "symlinkown_gid" is created.
109139 +
109140 +
109141 +endmenu
109142 +
109143 +menu "Customize Configuration"
109144 +depends on GRKERNSEC
109145 +
109146 +menu "PaX"
109147 +
109148 +config PAX
109149 + bool "Enable various PaX features"
109150 + default y if GRKERNSEC_CONFIG_AUTO
109151 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
109152 + help
109153 + This allows you to enable various PaX features. PaX adds
109154 + intrusion prevention mechanisms to the kernel that reduce
109155 + the risks posed by exploitable memory corruption bugs.
109156 +
109157 +menu "PaX Control"
109158 + depends on PAX
109159 +
109160 +config PAX_SOFTMODE
109161 + bool 'Support soft mode'
109162 + help
109163 + Enabling this option will allow you to run PaX in soft mode, that
109164 + is, PaX features will not be enforced by default, only on executables
109165 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
109166 + support as they are the only way to mark executables for soft mode use.
109167 +
109168 + Soft mode can be activated by using the "pax_softmode=1" kernel command
109169 + line option on boot. Furthermore you can control various PaX features
109170 + at runtime via the entries in /proc/sys/kernel/pax.
109171 +
109172 +config PAX_EI_PAX
109173 + bool 'Use legacy ELF header marking'
109174 + default y if GRKERNSEC_CONFIG_AUTO
109175 + help
109176 + Enabling this option will allow you to control PaX features on
109177 + a per executable basis via the 'chpax' utility available at
109178 + http://pax.grsecurity.net/. The control flags will be read from
109179 + an otherwise reserved part of the ELF header. This marking has
109180 + numerous drawbacks (no support for soft-mode, toolchain does not
109181 + know about the non-standard use of the ELF header) therefore it
109182 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
109183 + support.
109184 +
109185 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
109186 + support as well, they will override the legacy EI_PAX marks.
109187 +
109188 + If you enable none of the marking options then all applications
109189 + will run with PaX enabled on them by default.
109190 +
109191 +config PAX_PT_PAX_FLAGS
109192 + bool 'Use ELF program header marking'
109193 + default y if GRKERNSEC_CONFIG_AUTO
109194 + help
109195 + Enabling this option will allow you to control PaX features on
109196 + a per executable basis via the 'paxctl' utility available at
109197 + http://pax.grsecurity.net/. The control flags will be read from
109198 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
109199 + has the benefits of supporting both soft mode and being fully
109200 + integrated into the toolchain (the binutils patch is available
109201 + from http://pax.grsecurity.net).
109202 +
109203 + Note that if you enable the legacy EI_PAX marking support as well,
109204 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
109205 +
109206 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
109207 + must make sure that the marks are the same if a binary has both marks.
109208 +
109209 + If you enable none of the marking options then all applications
109210 + will run with PaX enabled on them by default.
109211 +
109212 +config PAX_XATTR_PAX_FLAGS
109213 + bool 'Use filesystem extended attributes marking'
109214 + default y if GRKERNSEC_CONFIG_AUTO
109215 + select CIFS_XATTR if CIFS
109216 + select F2FS_FS_XATTR if F2FS_FS
109217 + select EXT2_FS_XATTR if EXT2_FS
109218 + select EXT3_FS_XATTR if EXT3_FS
109219 + select JFFS2_FS_XATTR if JFFS2_FS
109220 + select REISERFS_FS_XATTR if REISERFS_FS
109221 + select SQUASHFS_XATTR if SQUASHFS
109222 + select TMPFS_XATTR if TMPFS
109223 + help
109224 + Enabling this option will allow you to control PaX features on
109225 + a per executable basis via the 'setfattr' utility. The control
109226 + flags will be read from the user.pax.flags extended attribute of
109227 + the file. This marking has the benefit of supporting binary-only
109228 + applications that self-check themselves (e.g., skype) and would
109229 + not tolerate chpax/paxctl changes. The main drawback is that
109230 + extended attributes are not supported by some filesystems (e.g.,
109231 + isofs, udf, vfat) so copying files through such filesystems will
109232 + lose the extended attributes and these PaX markings.
109233 +
109234 + Note that if you enable the legacy EI_PAX marking support as well,
109235 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
109236 +
109237 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
109238 + must make sure that the marks are the same if a binary has both marks.
109239 +
109240 + If you enable none of the marking options then all applications
109241 + will run with PaX enabled on them by default.
109242 +
109243 +choice
109244 + prompt 'MAC system integration'
109245 + default PAX_HAVE_ACL_FLAGS
109246 + help
109247 + Mandatory Access Control systems have the option of controlling
109248 + PaX flags on a per executable basis, choose the method supported
109249 + by your particular system.
109250 +
109251 + - "none": if your MAC system does not interact with PaX,
109252 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
109253 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
109254 +
109255 + NOTE: this option is for developers/integrators only.
109256 +
109257 + config PAX_NO_ACL_FLAGS
109258 + bool 'none'
109259 +
109260 + config PAX_HAVE_ACL_FLAGS
109261 + bool 'direct'
109262 +
109263 + config PAX_HOOK_ACL_FLAGS
109264 + bool 'hook'
109265 +endchoice
109266 +
109267 +endmenu
109268 +
109269 +menu "Non-executable pages"
109270 + depends on PAX
109271 +
109272 +config PAX_NOEXEC
109273 + bool "Enforce non-executable pages"
109274 + default y if GRKERNSEC_CONFIG_AUTO
109275 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V6K || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
109276 + help
109277 + By design some architectures do not allow for protecting memory
109278 + pages against execution or even if they do, Linux does not make
109279 + use of this feature. In practice this means that if a page is
109280 + readable (such as the stack or heap) it is also executable.
109281 +
109282 + There is a well known exploit technique that makes use of this
109283 + fact and a common programming mistake where an attacker can
109284 + introduce code of his choice somewhere in the attacked program's
109285 + memory (typically the stack or the heap) and then execute it.
109286 +
109287 + If the attacked program was running with different (typically
109288 + higher) privileges than that of the attacker, then he can elevate
109289 + his own privilege level (e.g. get a root shell, write to files for
109290 + which he does not have write access to, etc).
109291 +
109292 + Enabling this option will let you choose from various features
109293 + that prevent the injection and execution of 'foreign' code in
109294 + a program.
109295 +
109296 + This will also break programs that rely on the old behaviour and
109297 + expect that dynamically allocated memory via the malloc() family
109298 + of functions is executable (which it is not). Notable examples
109299 + are the XFree86 4.x server, the java runtime and wine.
109300 +
109301 +config PAX_PAGEEXEC
109302 + bool "Paging based non-executable pages"
109303 + default y if GRKERNSEC_CONFIG_AUTO
109304 + 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)
109305 + select ARCH_TRACK_EXEC_LIMIT if X86_32
109306 + help
109307 + This implementation is based on the paging feature of the CPU.
109308 + On i386 without hardware non-executable bit support there is a
109309 + variable but usually low performance impact, however on Intel's
109310 + P4 core based CPUs it is very high so you should not enable this
109311 + for kernels meant to be used on such CPUs.
109312 +
109313 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
109314 + with hardware non-executable bit support there is no performance
109315 + impact, on ppc the impact is negligible.
109316 +
109317 + Note that several architectures require various emulations due to
109318 + badly designed userland ABIs, this will cause a performance impact
109319 + but will disappear as soon as userland is fixed. For example, ppc
109320 + userland MUST have been built with secure-plt by a recent toolchain.
109321 +
109322 +config PAX_SEGMEXEC
109323 + bool "Segmentation based non-executable pages"
109324 + default y if GRKERNSEC_CONFIG_AUTO
109325 + depends on PAX_NOEXEC && X86_32
109326 + help
109327 + This implementation is based on the segmentation feature of the
109328 + CPU and has a very small performance impact, however applications
109329 + will be limited to a 1.5 GB address space instead of the normal
109330 + 3 GB.
109331 +
109332 +config PAX_EMUTRAMP
109333 + bool "Emulate trampolines"
109334 + default y if PARISC || GRKERNSEC_CONFIG_AUTO
109335 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
109336 + help
109337 + There are some programs and libraries that for one reason or
109338 + another attempt to execute special small code snippets from
109339 + non-executable memory pages. Most notable examples are the
109340 + signal handler return code generated by the kernel itself and
109341 + the GCC trampolines.
109342 +
109343 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
109344 + such programs will no longer work under your kernel.
109345 +
109346 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
109347 + utilities to enable trampoline emulation for the affected programs
109348 + yet still have the protection provided by the non-executable pages.
109349 +
109350 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
109351 + your system will not even boot.
109352 +
109353 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
109354 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
109355 + for the affected files.
109356 +
109357 + NOTE: enabling this feature *may* open up a loophole in the
109358 + protection provided by non-executable pages that an attacker
109359 + could abuse. Therefore the best solution is to not have any
109360 + files on your system that would require this option. This can
109361 + be achieved by not using libc5 (which relies on the kernel
109362 + signal handler return code) and not using or rewriting programs
109363 + that make use of the nested function implementation of GCC.
109364 + Skilled users can just fix GCC itself so that it implements
109365 + nested function calls in a way that does not interfere with PaX.
109366 +
109367 +config PAX_EMUSIGRT
109368 + bool "Automatically emulate sigreturn trampolines"
109369 + depends on PAX_EMUTRAMP && PARISC
109370 + default y
109371 + help
109372 + Enabling this option will have the kernel automatically detect
109373 + and emulate signal return trampolines executing on the stack
109374 + that would otherwise lead to task termination.
109375 +
109376 + This solution is intended as a temporary one for users with
109377 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
109378 + Modula-3 runtime, etc) or executables linked to such, basically
109379 + everything that does not specify its own SA_RESTORER function in
109380 + normal executable memory like glibc 2.1+ does.
109381 +
109382 + On parisc you MUST enable this option, otherwise your system will
109383 + not even boot.
109384 +
109385 + NOTE: this feature cannot be disabled on a per executable basis
109386 + and since it *does* open up a loophole in the protection provided
109387 + by non-executable pages, the best solution is to not have any
109388 + files on your system that would require this option.
109389 +
109390 +config PAX_MPROTECT
109391 + bool "Restrict mprotect()"
109392 + default y if GRKERNSEC_CONFIG_AUTO
109393 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
109394 + help
109395 + Enabling this option will prevent programs from
109396 + - changing the executable status of memory pages that were
109397 + not originally created as executable,
109398 + - making read-only executable pages writable again,
109399 + - creating executable pages from anonymous memory,
109400 + - making read-only-after-relocations (RELRO) data pages writable again.
109401 +
109402 + You should say Y here to complete the protection provided by
109403 + the enforcement of non-executable pages.
109404 +
109405 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
109406 + this feature on a per file basis.
109407 +
109408 +config PAX_MPROTECT_COMPAT
109409 + bool "Use legacy/compat protection demoting (read help)"
109410 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
109411 + depends on PAX_MPROTECT
109412 + help
109413 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
109414 + by sending the proper error code to the application. For some broken
109415 + userland, this can cause problems with Python or other applications. The
109416 + current implementation however allows for applications like clamav to
109417 + detect if JIT compilation/execution is allowed and to fall back gracefully
109418 + to an interpreter-based mode if it does not. While we encourage everyone
109419 + to use the current implementation as-is and push upstream to fix broken
109420 + userland (note that the RWX logging option can assist with this), in some
109421 + environments this may not be possible. Having to disable MPROTECT
109422 + completely on certain binaries reduces the security benefit of PaX,
109423 + so this option is provided for those environments to revert to the old
109424 + behavior.
109425 +
109426 +config PAX_ELFRELOCS
109427 + bool "Allow ELF text relocations (read help)"
109428 + depends on PAX_MPROTECT
109429 + default n
109430 + help
109431 + Non-executable pages and mprotect() restrictions are effective
109432 + in preventing the introduction of new executable code into an
109433 + attacked task's address space. There remain only two venues
109434 + for this kind of attack: if the attacker can execute already
109435 + existing code in the attacked task then he can either have it
109436 + create and mmap() a file containing his code or have it mmap()
109437 + an already existing ELF library that does not have position
109438 + independent code in it and use mprotect() on it to make it
109439 + writable and copy his code there. While protecting against
109440 + the former approach is beyond PaX, the latter can be prevented
109441 + by having only PIC ELF libraries on one's system (which do not
109442 + need to relocate their code). If you are sure this is your case,
109443 + as is the case with all modern Linux distributions, then leave
109444 + this option disabled. You should say 'n' here.
109445 +
109446 +config PAX_ETEXECRELOCS
109447 + bool "Allow ELF ET_EXEC text relocations"
109448 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
109449 + select PAX_ELFRELOCS
109450 + default y
109451 + help
109452 + On some architectures there are incorrectly created applications
109453 + that require text relocations and would not work without enabling
109454 + this option. If you are an alpha, ia64 or parisc user, you should
109455 + enable this option and disable it once you have made sure that
109456 + none of your applications need it.
109457 +
109458 +config PAX_EMUPLT
109459 + bool "Automatically emulate ELF PLT"
109460 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
109461 + default y
109462 + help
109463 + Enabling this option will have the kernel automatically detect
109464 + and emulate the Procedure Linkage Table entries in ELF files.
109465 + On some architectures such entries are in writable memory, and
109466 + become non-executable leading to task termination. Therefore
109467 + it is mandatory that you enable this option on alpha, parisc,
109468 + sparc and sparc64, otherwise your system would not even boot.
109469 +
109470 + NOTE: this feature *does* open up a loophole in the protection
109471 + provided by the non-executable pages, therefore the proper
109472 + solution is to modify the toolchain to produce a PLT that does
109473 + not need to be writable.
109474 +
109475 +config PAX_DLRESOLVE
109476 + bool 'Emulate old glibc resolver stub'
109477 + depends on PAX_EMUPLT && SPARC
109478 + default n
109479 + help
109480 + This option is needed if userland has an old glibc (before 2.4)
109481 + that puts a 'save' instruction into the runtime generated resolver
109482 + stub that needs special emulation.
109483 +
109484 +config PAX_KERNEXEC
109485 + bool "Enforce non-executable kernel pages"
109486 + 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))
109487 + depends on (X86 || (ARM && (CPU_V6 || CPU_V6K || CPU_V7) && !(ARM_LPAE && MODULES))) && !XEN
109488 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
109489 + select PAX_KERNEXEC_PLUGIN if X86_64
109490 + help
109491 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
109492 + that is, enabling this option will make it harder to inject
109493 + and execute 'foreign' code in kernel memory itself.
109494 +
109495 + Note that on amd64, CONFIG_EFI enabled with "efi=old_map" on
109496 + the kernel command-line will result in an RWX physical map.
109497 +
109498 + Likewise, the EFI runtime services are necessarily mapped as
109499 + RWX. If CONFIG_EFI is enabled on an EFI-capable system, it
109500 + is recommended that you boot with "noefi" on the kernel
109501 + command-line if possible to eliminate the mapping.
109502 +
109503 +choice
109504 + prompt "Return Address Instrumentation Method"
109505 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
109506 + depends on PAX_KERNEXEC_PLUGIN
109507 + help
109508 + Select the method used to instrument function pointer dereferences.
109509 + Note that binary modules cannot be instrumented by this approach.
109510 +
109511 + Note that the implementation requires a gcc with plugin support,
109512 + i.e., gcc 4.5 or newer. You may need to install the supporting
109513 + headers explicitly in addition to the normal gcc package.
109514 +
109515 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
109516 + bool "bts"
109517 + help
109518 + This method is compatible with binary only modules but has
109519 + a higher runtime overhead.
109520 +
109521 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
109522 + bool "or"
109523 + depends on !PARAVIRT
109524 + help
109525 + This method is incompatible with binary only modules but has
109526 + a lower runtime overhead.
109527 +endchoice
109528 +
109529 +config PAX_KERNEXEC_PLUGIN_METHOD
109530 + string
109531 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
109532 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
109533 + default ""
109534 +
109535 +config PAX_KERNEXEC_MODULE_TEXT
109536 + int "Minimum amount of memory reserved for module code"
109537 + default "8" if (!GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_SERVER)
109538 + default "12" if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
109539 + depends on PAX_KERNEXEC && X86_32
109540 + help
109541 + Due to implementation details the kernel must reserve a fixed
109542 + amount of memory for runtime allocated code (such as modules)
109543 + at compile time that cannot be changed at runtime. Here you
109544 + can specify the minimum amount in MB that will be reserved.
109545 + Due to the same implementation details this size will always
109546 + be rounded up to the next 2/4 MB boundary (depends on PAE) so
109547 + the actually available memory for runtime allocated code will
109548 + usually be more than this minimum.
109549 +
109550 + The default 4 MB should be enough for most users but if you have
109551 + an excessive number of modules (e.g., most distribution configs
109552 + compile many drivers as modules) or use huge modules such as
109553 + nvidia's kernel driver, you will need to adjust this amount.
109554 + A good rule of thumb is to look at your currently loaded kernel
109555 + modules and add up their sizes.
109556 +
109557 +endmenu
109558 +
109559 +menu "Address Space Layout Randomization"
109560 + depends on PAX
109561 +
109562 +config PAX_ASLR
109563 + bool "Address Space Layout Randomization"
109564 + default y if GRKERNSEC_CONFIG_AUTO
109565 + help
109566 + Many if not most exploit techniques rely on the knowledge of
109567 + certain addresses in the attacked program. The following options
109568 + will allow the kernel to apply a certain amount of randomization
109569 + to specific parts of the program thereby forcing an attacker to
109570 + guess them in most cases. Any failed guess will most likely crash
109571 + the attacked program which allows the kernel to detect such attempts
109572 + and react on them. PaX itself provides no reaction mechanisms,
109573 + instead it is strongly encouraged that you make use of grsecurity's
109574 + (http://www.grsecurity.net/) built-in crash detection features or
109575 + develop one yourself.
109576 +
109577 + By saying Y here you can choose to randomize the following areas:
109578 + - top of the task's kernel stack
109579 + - top of the task's userland stack
109580 + - base address for mmap() requests that do not specify one
109581 + (this includes all libraries)
109582 + - base address of the main executable
109583 +
109584 + It is strongly recommended to say Y here as address space layout
109585 + randomization has negligible impact on performance yet it provides
109586 + a very effective protection.
109587 +
109588 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
109589 + this feature on a per file basis.
109590 +
109591 +config PAX_RANDKSTACK
109592 + bool "Randomize kernel stack base"
109593 + default y if GRKERNSEC_CONFIG_AUTO && !(GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_VIRTUALBOX)
109594 + depends on X86_TSC && X86
109595 + help
109596 + By saying Y here the kernel will randomize every task's kernel
109597 + stack on every system call. This will not only force an attacker
109598 + to guess it but also prevent him from making use of possible
109599 + leaked information about it.
109600 +
109601 + Since the kernel stack is a rather scarce resource, randomization
109602 + may cause unexpected stack overflows, therefore you should very
109603 + carefully test your system. Note that once enabled in the kernel
109604 + configuration, this feature cannot be disabled on a per file basis.
109605 +
109606 +config PAX_RANDUSTACK
109607 + bool
109608 +
109609 +config PAX_RANDMMAP
109610 + bool "Randomize user stack and mmap() bases"
109611 + default y if GRKERNSEC_CONFIG_AUTO
109612 + depends on PAX_ASLR
109613 + select PAX_RANDUSTACK
109614 + help
109615 + By saying Y here the kernel will randomize every task's userland
109616 + stack and use a randomized base address for mmap() requests that
109617 + do not specify one themselves.
109618 +
109619 + The stack randomization is done in two steps where the second
109620 + one may apply a big amount of shift to the top of the stack and
109621 + cause problems for programs that want to use lots of memory (more
109622 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
109623 +
109624 + As a result of mmap randomization all dynamically loaded libraries
109625 + will appear at random addresses and therefore be harder to exploit
109626 + by a technique where an attacker attempts to execute library code
109627 + for his purposes (e.g. spawn a shell from an exploited program that
109628 + is running at an elevated privilege level).
109629 +
109630 + Furthermore, if a program is relinked as a dynamic ELF file, its
109631 + base address will be randomized as well, completing the full
109632 + randomization of the address space layout. Attacking such programs
109633 + becomes a guess game. You can find an example of doing this at
109634 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
109635 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
109636 +
109637 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
109638 + feature on a per file basis.
109639 +
109640 +endmenu
109641 +
109642 +menu "Miscellaneous hardening features"
109643 +
109644 +config PAX_MEMORY_SANITIZE
109645 + bool "Sanitize all freed memory"
109646 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
109647 + help
109648 + By saying Y here the kernel will erase memory pages and slab objects
109649 + as soon as they are freed. This in turn reduces the lifetime of data
109650 + stored in them, making it less likely that sensitive information such
109651 + as passwords, cryptographic secrets, etc stay in memory for too long.
109652 +
109653 + This is especially useful for programs whose runtime is short, long
109654 + lived processes and the kernel itself benefit from this as long as
109655 + they ensure timely freeing of memory that may hold sensitive
109656 + information.
109657 +
109658 + A nice side effect of the sanitization of slab objects is the
109659 + reduction of possible info leaks caused by padding bytes within the
109660 + leaky structures. Use-after-free bugs for structures containing
109661 + pointers can also be detected as dereferencing the sanitized pointer
109662 + will generate an access violation.
109663 +
109664 + The tradeoff is performance impact, on a single CPU system kernel
109665 + compilation sees a 3% slowdown, other systems and workloads may vary
109666 + and you are advised to test this feature on your expected workload
109667 + before deploying it.
109668 +
109669 + The slab sanitization feature excludes a few slab caches per default
109670 + for performance reasons. To extend the feature to cover those as
109671 + well, pass "pax_sanitize_slab=full" as kernel command line parameter.
109672 +
109673 + To reduce the performance penalty by sanitizing pages only, albeit
109674 + limiting the effectiveness of this feature at the same time, slab
109675 + sanitization can be disabled with the kernel command line parameter
109676 + "pax_sanitize_slab=off".
109677 +
109678 + Note that this feature does not protect data stored in live pages,
109679 + e.g., process memory swapped to disk may stay there for a long time.
109680 +
109681 +config PAX_MEMORY_STACKLEAK
109682 + bool "Sanitize kernel stack"
109683 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
109684 + depends on X86
109685 + help
109686 + By saying Y here the kernel will erase the kernel stack before it
109687 + returns from a system call. This in turn reduces the information
109688 + that a kernel stack leak bug can reveal.
109689 +
109690 + Note that such a bug can still leak information that was put on
109691 + the stack by the current system call (the one eventually triggering
109692 + the bug) but traces of earlier system calls on the kernel stack
109693 + cannot leak anymore.
109694 +
109695 + The tradeoff is performance impact: on a single CPU system kernel
109696 + compilation sees a 1% slowdown, other systems and workloads may vary
109697 + and you are advised to test this feature on your expected workload
109698 + before deploying it.
109699 +
109700 + Note that the full feature requires a gcc with plugin support,
109701 + i.e., gcc 4.5 or newer. You may need to install the supporting
109702 + headers explicitly in addition to the normal gcc package. Using
109703 + older gcc versions means that functions with large enough stack
109704 + frames may leave uninitialized memory behind that may be exposed
109705 + to a later syscall leaking the stack.
109706 +
109707 +config PAX_MEMORY_STRUCTLEAK
109708 + bool "Forcibly initialize local variables copied to userland"
109709 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
109710 + help
109711 + By saying Y here the kernel will zero initialize some local
109712 + variables that are going to be copied to userland. This in
109713 + turn prevents unintended information leakage from the kernel
109714 + stack should later code forget to explicitly set all parts of
109715 + the copied variable.
109716 +
109717 + The tradeoff is less performance impact than PAX_MEMORY_STACKLEAK
109718 + at a much smaller coverage.
109719 +
109720 + Note that the implementation requires a gcc with plugin support,
109721 + i.e., gcc 4.5 or newer. You may need to install the supporting
109722 + headers explicitly in addition to the normal gcc package.
109723 +
109724 +config PAX_MEMORY_UDEREF
109725 + bool "Prevent invalid userland pointer dereference"
109726 + default y if GRKERNSEC_CONFIG_AUTO && !(X86_64 && GRKERNSEC_CONFIG_PRIORITY_PERF) && (!X86 || GRKERNSEC_CONFIG_VIRT_NONE || GRKERNSEC_CONFIG_VIRT_EPT)
109727 + depends on (X86 || (ARM && (CPU_V6 || CPU_V6K || CPU_V7) && !ARM_LPAE)) && !UML_X86 && !XEN
109728 + select PAX_PER_CPU_PGD if X86_64
109729 + help
109730 + By saying Y here the kernel will be prevented from dereferencing
109731 + userland pointers in contexts where the kernel expects only kernel
109732 + pointers. This is both a useful runtime debugging feature and a
109733 + security measure that prevents exploiting a class of kernel bugs.
109734 +
109735 + The tradeoff is that some virtualization solutions may experience
109736 + a huge slowdown and therefore you should not enable this feature
109737 + for kernels meant to run in such environments. Whether a given VM
109738 + solution is affected or not is best determined by simply trying it
109739 + out, the performance impact will be obvious right on boot as this
109740 + mechanism engages from very early on. A good rule of thumb is that
109741 + VMs running on CPUs without hardware virtualization support (i.e.,
109742 + the majority of IA-32 CPUs) will likely experience the slowdown.
109743 +
109744 + On X86_64 the kernel will make use of PCID support when available
109745 + (Intel's Westmere, Sandy Bridge, etc) for better security (default)
109746 + or performance impact. Pass pax_weakuderef on the kernel command
109747 + line to choose the latter.
109748 +
109749 +config PAX_REFCOUNT
109750 + bool "Prevent various kernel object reference counter overflows"
109751 + default y if GRKERNSEC_CONFIG_AUTO
109752 + depends on GRKERNSEC && ((ARM && (CPU_V6 || CPU_V6K || CPU_V7)) || MIPS || PPC || SPARC64 || X86)
109753 + help
109754 + By saying Y here the kernel will detect and prevent overflowing
109755 + various (but not all) kinds of object reference counters. Such
109756 + overflows can normally occur due to bugs only and are often, if
109757 + not always, exploitable.
109758 +
109759 + The tradeoff is that data structures protected by an overflowed
109760 + refcount will never be freed and therefore will leak memory. Note
109761 + that this leak also happens even without this protection but in
109762 + that case the overflow can eventually trigger the freeing of the
109763 + data structure while it is still being used elsewhere, resulting
109764 + in the exploitable situation that this feature prevents.
109765 +
109766 + Since this has a negligible performance impact, you should enable
109767 + this feature.
109768 +
109769 +config PAX_CONSTIFY_PLUGIN
109770 + bool "Automatically constify eligible structures"
109771 + default y
109772 + depends on !UML && PAX_KERNEXEC
109773 + help
109774 + By saying Y here the compiler will automatically constify a class
109775 + of types that contain only function pointers. This reduces the
109776 + kernel's attack surface and also produces a better memory layout.
109777 +
109778 + Note that the implementation requires a gcc with plugin support,
109779 + i.e., gcc 4.5 or newer. You may need to install the supporting
109780 + headers explicitly in addition to the normal gcc package.
109781 +
109782 + Note that if some code really has to modify constified variables
109783 + then the source code will have to be patched to allow it. Examples
109784 + can be found in PaX itself (the no_const attribute) and for some
109785 + out-of-tree modules at http://www.grsecurity.net/~paxguy1/ .
109786 +
109787 +config PAX_USERCOPY
109788 + bool "Harden heap object copies between kernel and userland"
109789 + default y if GRKERNSEC_CONFIG_AUTO
109790 + depends on ARM || IA64 || PPC || SPARC || X86
109791 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
109792 + select PAX_USERCOPY_SLABS
109793 + help
109794 + By saying Y here the kernel will enforce the size of heap objects
109795 + when they are copied in either direction between the kernel and
109796 + userland, even if only a part of the heap object is copied.
109797 +
109798 + Specifically, this checking prevents information leaking from the
109799 + kernel heap during kernel to userland copies (if the kernel heap
109800 + object is otherwise fully initialized) and prevents kernel heap
109801 + overflows during userland to kernel copies.
109802 +
109803 + Note that the current implementation provides the strictest bounds
109804 + checks for the SLUB allocator.
109805 +
109806 + Enabling this option also enables per-slab cache protection against
109807 + data in a given cache being copied into/out of via userland
109808 + accessors. Though the whitelist of regions will be reduced over
109809 + time, it notably protects important data structures like task structs.
109810 +
109811 + If frame pointers are enabled on x86, this option will also restrict
109812 + copies into and out of the kernel stack to local variables within a
109813 + single frame.
109814 +
109815 + Since this has a negligible performance impact, you should enable
109816 + this feature.
109817 +
109818 +config PAX_USERCOPY_DEBUG
109819 + bool
109820 + depends on X86 && PAX_USERCOPY
109821 + default n
109822 +
109823 +config PAX_SIZE_OVERFLOW
109824 + bool "Prevent various integer overflows in function size parameters"
109825 + default y if GRKERNSEC_CONFIG_AUTO
109826 + depends on X86
109827 + help
109828 + By saying Y here the kernel recomputes expressions of function
109829 + arguments marked by a size_overflow attribute with double integer
109830 + precision (DImode/TImode for 32/64 bit integer types).
109831 +
109832 + The recomputed argument is checked against TYPE_MAX and an event
109833 + is logged on overflow and the triggering process is killed.
109834 +
109835 + Homepage: http://www.grsecurity.net/~ephox/overflow_plugin/
109836 +
109837 + Note that the implementation requires a gcc with plugin support,
109838 + i.e., gcc 4.5 or newer. You may need to install the supporting
109839 + headers explicitly in addition to the normal gcc package.
109840 +
109841 +config PAX_LATENT_ENTROPY
109842 + bool "Generate some entropy during boot and runtime"
109843 + default y if GRKERNSEC_CONFIG_AUTO
109844 + help
109845 + By saying Y here the kernel will instrument some kernel code to
109846 + extract some entropy from both original and artificially created
109847 + program state. This will help especially embedded systems where
109848 + there is little 'natural' source of entropy normally. The cost
109849 + is some slowdown of the boot process and fork and irq processing.
109850 +
109851 + When pax_extra_latent_entropy is passed on the kernel command line,
109852 + entropy will be extracted from up to the first 4GB of RAM while the
109853 + runtime memory allocator is being initialized. This costs even more
109854 + slowdown of the boot process.
109855 +
109856 + Note that the implementation requires a gcc with plugin support,
109857 + i.e., gcc 4.5 or newer. You may need to install the supporting
109858 + headers explicitly in addition to the normal gcc package.
109859 +
109860 + Note that entropy extracted this way is not cryptographically
109861 + secure!
109862 +
109863 +endmenu
109864 +
109865 +endmenu
109866 +
109867 +source grsecurity/Kconfig
109868 +
109869 +endmenu
109870 +
109871 +endmenu
109872 +
109873 source security/keys/Kconfig
109874
109875 config SECURITY_DMESG_RESTRICT
109876 @@ -103,7 +1071,7 @@ config INTEL_TXT
109877 config LSM_MMAP_MIN_ADDR
109878 int "Low address space for LSM to protect from user allocation"
109879 depends on SECURITY && SECURITY_SELINUX
109880 - default 32768 if ARM || (ARM64 && COMPAT)
109881 + default 32768 if ALPHA || ARM || (ARM64 && COMPAT) || PARISC || SPARC32
109882 default 65536
109883 help
109884 This is the portion of low virtual memory which should be protected
109885 diff --git a/security/apparmor/file.c b/security/apparmor/file.c
109886 index fdaa50c..2761dcb 100644
109887 --- a/security/apparmor/file.c
109888 +++ b/security/apparmor/file.c
109889 @@ -348,8 +348,8 @@ static inline bool xindex_is_subset(u32 link, u32 target)
109890 int aa_path_link(struct aa_profile *profile, struct dentry *old_dentry,
109891 struct path *new_dir, struct dentry *new_dentry)
109892 {
109893 - struct path link = { new_dir->mnt, new_dentry };
109894 - struct path target = { new_dir->mnt, old_dentry };
109895 + struct path link = { .mnt = new_dir->mnt, .dentry = new_dentry };
109896 + struct path target = { .mnt = new_dir->mnt, .dentry = old_dentry };
109897 struct path_cond cond = {
109898 old_dentry->d_inode->i_uid,
109899 old_dentry->d_inode->i_mode
109900 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
109901 index 9981000..eb21356 100644
109902 --- a/security/apparmor/lsm.c
109903 +++ b/security/apparmor/lsm.c
109904 @@ -186,7 +186,7 @@ static int common_perm_dir_dentry(int op, struct path *dir,
109905 struct dentry *dentry, u32 mask,
109906 struct path_cond *cond)
109907 {
109908 - struct path path = { dir->mnt, dentry };
109909 + struct path path = { .mnt = dir->mnt, .dentry = dentry };
109910
109911 return common_perm(op, &path, mask, cond);
109912 }
109913 @@ -203,7 +203,7 @@ static int common_perm_dir_dentry(int op, struct path *dir,
109914 static int common_perm_mnt_dentry(int op, struct vfsmount *mnt,
109915 struct dentry *dentry, u32 mask)
109916 {
109917 - struct path path = { mnt, dentry };
109918 + struct path path = { .mnt = mnt, .dentry = dentry };
109919 struct path_cond cond = { dentry->d_inode->i_uid,
109920 dentry->d_inode->i_mode
109921 };
109922 @@ -325,8 +325,8 @@ static int apparmor_path_rename(struct path *old_dir, struct dentry *old_dentry,
109923
109924 profile = aa_current_profile();
109925 if (!unconfined(profile)) {
109926 - struct path old_path = { old_dir->mnt, old_dentry };
109927 - struct path new_path = { new_dir->mnt, new_dentry };
109928 + struct path old_path = { .mnt = old_dir->mnt, .dentry = old_dentry };
109929 + struct path new_path = { .mnt = new_dir->mnt, .dentry = new_dentry };
109930 struct path_cond cond = { old_dentry->d_inode->i_uid,
109931 old_dentry->d_inode->i_mode
109932 };
109933 @@ -615,7 +615,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
109934 return error;
109935 }
109936
109937 -static struct security_operations apparmor_ops = {
109938 +static struct security_operations apparmor_ops __read_only = {
109939 .name = "apparmor",
109940
109941 .ptrace_access_check = apparmor_ptrace_access_check,
109942 diff --git a/security/commoncap.c b/security/commoncap.c
109943 index bab0611..f9a0ff5 100644
109944 --- a/security/commoncap.c
109945 +++ b/security/commoncap.c
109946 @@ -427,6 +427,32 @@ int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data
109947 return 0;
109948 }
109949
109950 +/* returns:
109951 + 1 for suid privilege
109952 + 2 for sgid privilege
109953 + 3 for fscap privilege
109954 +*/
109955 +int is_privileged_binary(const struct dentry *dentry)
109956 +{
109957 + struct cpu_vfs_cap_data capdata;
109958 + struct inode *inode = dentry->d_inode;
109959 +
109960 + if (!inode || S_ISDIR(inode->i_mode))
109961 + return 0;
109962 +
109963 + if (inode->i_mode & S_ISUID)
109964 + return 1;
109965 + if ((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
109966 + return 2;
109967 +
109968 + if (!get_vfs_caps_from_disk(dentry, &capdata)) {
109969 + if (!cap_isclear(capdata.inheritable) || !cap_isclear(capdata.permitted))
109970 + return 3;
109971 + }
109972 +
109973 + return 0;
109974 +}
109975 +
109976 /*
109977 * Attempt to get the on-exec apply capability sets for an executable file from
109978 * its xattrs and, if present, apply them to the proposed credentials being
109979 @@ -595,6 +621,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
109980 const struct cred *cred = current_cred();
109981 kuid_t root_uid = make_kuid(cred->user_ns, 0);
109982
109983 + if (gr_acl_enable_at_secure())
109984 + return 1;
109985 +
109986 if (!uid_eq(cred->uid, root_uid)) {
109987 if (bprm->cap_effective)
109988 return 1;
109989 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
109990 index 0fb456c..83711f9 100644
109991 --- a/security/integrity/ima/ima.h
109992 +++ b/security/integrity/ima/ima.h
109993 @@ -118,8 +118,8 @@ int ima_init_template(void);
109994 extern spinlock_t ima_queue_lock;
109995
109996 struct ima_h_table {
109997 - atomic_long_t len; /* number of stored measurements in the list */
109998 - atomic_long_t violations;
109999 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
110000 + atomic_long_unchecked_t violations;
110001 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
110002 };
110003 extern struct ima_h_table ima_htable;
110004 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
110005 index d9cd5ce..c5c29ac 100644
110006 --- a/security/integrity/ima/ima_api.c
110007 +++ b/security/integrity/ima/ima_api.c
110008 @@ -137,7 +137,7 @@ void ima_add_violation(struct file *file, const unsigned char *filename,
110009 int result;
110010
110011 /* can overflow, only indicator */
110012 - atomic_long_inc(&ima_htable.violations);
110013 + atomic_long_inc_unchecked(&ima_htable.violations);
110014
110015 result = ima_alloc_init_template(NULL, file, filename,
110016 NULL, 0, &entry);
110017 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
110018 index da92fcc..8a5d390 100644
110019 --- a/security/integrity/ima/ima_fs.c
110020 +++ b/security/integrity/ima/ima_fs.c
110021 @@ -28,12 +28,12 @@
110022 static int valid_policy = 1;
110023 #define TMPBUFLEN 12
110024 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
110025 - loff_t *ppos, atomic_long_t *val)
110026 + loff_t *ppos, atomic_long_unchecked_t *val)
110027 {
110028 char tmpbuf[TMPBUFLEN];
110029 ssize_t len;
110030
110031 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
110032 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
110033 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
110034 }
110035
110036 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
110037 index 552705d..9920f4fb 100644
110038 --- a/security/integrity/ima/ima_queue.c
110039 +++ b/security/integrity/ima/ima_queue.c
110040 @@ -83,7 +83,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
110041 INIT_LIST_HEAD(&qe->later);
110042 list_add_tail_rcu(&qe->later, &ima_measurements);
110043
110044 - atomic_long_inc(&ima_htable.len);
110045 + atomic_long_inc_unchecked(&ima_htable.len);
110046 key = ima_hash_key(entry->digest);
110047 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
110048 return 0;
110049 diff --git a/security/keys/compat.c b/security/keys/compat.c
110050 index 3478965..ec7bb9e 100644
110051 --- a/security/keys/compat.c
110052 +++ b/security/keys/compat.c
110053 @@ -44,7 +44,7 @@ static long compat_keyctl_instantiate_key_iov(
110054 if (ret == 0)
110055 goto no_payload_free;
110056
110057 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
110058 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
110059 err:
110060 if (iov != iovstack)
110061 kfree(iov);
110062 diff --git a/security/keys/internal.h b/security/keys/internal.h
110063 index 5f20da0..444ccf1 100644
110064 --- a/security/keys/internal.h
110065 +++ b/security/keys/internal.h
110066 @@ -244,7 +244,7 @@ extern long keyctl_instantiate_key_iov(key_serial_t,
110067 extern long keyctl_invalidate_key(key_serial_t);
110068
110069 extern long keyctl_instantiate_key_common(key_serial_t,
110070 - const struct iovec *,
110071 + const struct iovec __user *,
110072 unsigned, size_t, key_serial_t);
110073 #ifdef CONFIG_PERSISTENT_KEYRINGS
110074 extern long keyctl_get_persistent(uid_t, key_serial_t);
110075 diff --git a/security/keys/key.c b/security/keys/key.c
110076 index 6d0cad1..8f957df 100644
110077 --- a/security/keys/key.c
110078 +++ b/security/keys/key.c
110079 @@ -285,7 +285,7 @@ struct key *key_alloc(struct key_type *type, const char *desc,
110080
110081 atomic_set(&key->usage, 1);
110082 init_rwsem(&key->sem);
110083 - lockdep_set_class(&key->sem, &type->lock_class);
110084 + lockdep_set_class(&key->sem, (struct lock_class_key *)&type->lock_class);
110085 key->index_key.type = type;
110086 key->user = user;
110087 key->quotalen = quotalen;
110088 @@ -1075,7 +1075,9 @@ int register_key_type(struct key_type *ktype)
110089 struct key_type *p;
110090 int ret;
110091
110092 - memset(&ktype->lock_class, 0, sizeof(ktype->lock_class));
110093 + pax_open_kernel();
110094 + memset((void *)&ktype->lock_class, 0, sizeof(ktype->lock_class));
110095 + pax_close_kernel();
110096
110097 ret = -EEXIST;
110098 down_write(&key_types_sem);
110099 @@ -1087,7 +1089,7 @@ int register_key_type(struct key_type *ktype)
110100 }
110101
110102 /* store the type */
110103 - list_add(&ktype->link, &key_types_list);
110104 + pax_list_add((struct list_head *)&ktype->link, &key_types_list);
110105
110106 pr_notice("Key type %s registered\n", ktype->name);
110107 ret = 0;
110108 @@ -1109,7 +1111,7 @@ EXPORT_SYMBOL(register_key_type);
110109 void unregister_key_type(struct key_type *ktype)
110110 {
110111 down_write(&key_types_sem);
110112 - list_del_init(&ktype->link);
110113 + pax_list_del_init((struct list_head *)&ktype->link);
110114 downgrade_write(&key_types_sem);
110115 key_gc_keytype(ktype);
110116 pr_notice("Key type %s unregistered\n", ktype->name);
110117 @@ -1127,10 +1129,10 @@ void __init key_init(void)
110118 0, SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
110119
110120 /* add the special key types */
110121 - list_add_tail(&key_type_keyring.link, &key_types_list);
110122 - list_add_tail(&key_type_dead.link, &key_types_list);
110123 - list_add_tail(&key_type_user.link, &key_types_list);
110124 - list_add_tail(&key_type_logon.link, &key_types_list);
110125 + pax_list_add_tail((struct list_head *)&key_type_keyring.link, &key_types_list);
110126 + pax_list_add_tail((struct list_head *)&key_type_dead.link, &key_types_list);
110127 + pax_list_add_tail((struct list_head *)&key_type_user.link, &key_types_list);
110128 + pax_list_add_tail((struct list_head *)&key_type_logon.link, &key_types_list);
110129
110130 /* record the root user tracking */
110131 rb_link_node(&root_key_user.node,
110132 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
110133 index eff88a5..51d35ef 100644
110134 --- a/security/keys/keyctl.c
110135 +++ b/security/keys/keyctl.c
110136 @@ -1004,7 +1004,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
110137 /*
110138 * Copy the iovec data from userspace
110139 */
110140 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
110141 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
110142 unsigned ioc)
110143 {
110144 for (; ioc > 0; ioc--) {
110145 @@ -1026,7 +1026,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
110146 * If successful, 0 will be returned.
110147 */
110148 long keyctl_instantiate_key_common(key_serial_t id,
110149 - const struct iovec *payload_iov,
110150 + const struct iovec __user *payload_iov,
110151 unsigned ioc,
110152 size_t plen,
110153 key_serial_t ringid)
110154 @@ -1121,7 +1121,7 @@ long keyctl_instantiate_key(key_serial_t id,
110155 [0].iov_len = plen
110156 };
110157
110158 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
110159 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
110160 }
110161
110162 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
110163 @@ -1154,7 +1154,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
110164 if (ret == 0)
110165 goto no_payload_free;
110166
110167 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
110168 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
110169 err:
110170 if (iov != iovstack)
110171 kfree(iov);
110172 diff --git a/security/min_addr.c b/security/min_addr.c
110173 index f728728..6457a0c 100644
110174 --- a/security/min_addr.c
110175 +++ b/security/min_addr.c
110176 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
110177 */
110178 static void update_mmap_min_addr(void)
110179 {
110180 +#ifndef SPARC
110181 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
110182 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
110183 mmap_min_addr = dac_mmap_min_addr;
110184 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
110185 #else
110186 mmap_min_addr = dac_mmap_min_addr;
110187 #endif
110188 +#endif
110189 }
110190
110191 /*
110192 diff --git a/security/security.c b/security/security.c
110193 index e41b1a8..b66a558 100644
110194 --- a/security/security.c
110195 +++ b/security/security.c
110196 @@ -33,8 +33,8 @@
110197 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
110198 CONFIG_DEFAULT_SECURITY;
110199
110200 -static struct security_operations *security_ops;
110201 -static struct security_operations default_security_ops = {
110202 +struct security_operations *security_ops __read_only;
110203 +struct security_operations default_security_ops __read_only = {
110204 .name = "default",
110205 };
110206
110207 @@ -73,11 +73,6 @@ int __init security_init(void)
110208 return 0;
110209 }
110210
110211 -void reset_security_ops(void)
110212 -{
110213 - security_ops = &default_security_ops;
110214 -}
110215 -
110216 /* Save user chosen LSM */
110217 static int __init choose_lsm(char *str)
110218 {
110219 diff --git a/security/selinux/avc.c b/security/selinux/avc.c
110220 index a18f1fa..c9b9fc4 100644
110221 --- a/security/selinux/avc.c
110222 +++ b/security/selinux/avc.c
110223 @@ -59,7 +59,7 @@ struct avc_node {
110224 struct avc_cache {
110225 struct hlist_head slots[AVC_CACHE_SLOTS]; /* head for avc_node->list */
110226 spinlock_t slots_lock[AVC_CACHE_SLOTS]; /* lock for writes */
110227 - atomic_t lru_hint; /* LRU hint for reclaim scan */
110228 + atomic_unchecked_t lru_hint; /* LRU hint for reclaim scan */
110229 atomic_t active_nodes;
110230 u32 latest_notif; /* latest revocation notification */
110231 };
110232 @@ -167,7 +167,7 @@ void __init avc_init(void)
110233 spin_lock_init(&avc_cache.slots_lock[i]);
110234 }
110235 atomic_set(&avc_cache.active_nodes, 0);
110236 - atomic_set(&avc_cache.lru_hint, 0);
110237 + atomic_set_unchecked(&avc_cache.lru_hint, 0);
110238
110239 avc_node_cachep = kmem_cache_create("avc_node", sizeof(struct avc_node),
110240 0, SLAB_PANIC, NULL);
110241 @@ -242,7 +242,7 @@ static inline int avc_reclaim_node(void)
110242 spinlock_t *lock;
110243
110244 for (try = 0, ecx = 0; try < AVC_CACHE_SLOTS; try++) {
110245 - hvalue = atomic_inc_return(&avc_cache.lru_hint) & (AVC_CACHE_SLOTS - 1);
110246 + hvalue = atomic_inc_return_unchecked(&avc_cache.lru_hint) & (AVC_CACHE_SLOTS - 1);
110247 head = &avc_cache.slots[hvalue];
110248 lock = &avc_cache.slots_lock[hvalue];
110249
110250 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
110251 index e03bad5..b15da09 100644
110252 --- a/security/selinux/hooks.c
110253 +++ b/security/selinux/hooks.c
110254 @@ -95,8 +95,6 @@
110255 #include "audit.h"
110256 #include "avc_ss.h"
110257
110258 -extern struct security_operations *security_ops;
110259 -
110260 /* SECMARK reference count */
110261 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
110262
110263 @@ -5772,7 +5770,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
110264
110265 #endif
110266
110267 -static struct security_operations selinux_ops = {
110268 +static struct security_operations selinux_ops __read_only = {
110269 .name = "selinux",
110270
110271 .ptrace_access_check = selinux_ptrace_access_check,
110272 @@ -6128,6 +6126,9 @@ static void selinux_nf_ip_exit(void)
110273 #ifdef CONFIG_SECURITY_SELINUX_DISABLE
110274 static int selinux_disabled;
110275
110276 +extern struct security_operations *security_ops;
110277 +extern struct security_operations default_security_ops;
110278 +
110279 int selinux_disable(void)
110280 {
110281 if (ss_initialized) {
110282 @@ -6145,7 +6146,9 @@ int selinux_disable(void)
110283 selinux_disabled = 1;
110284 selinux_enabled = 0;
110285
110286 - reset_security_ops();
110287 + pax_open_kernel();
110288 + security_ops = &default_security_ops;
110289 + pax_close_kernel();
110290
110291 /* Try to destroy the avc node cache */
110292 avc_disable();
110293 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
110294 index 1450f85..a91e0bc 100644
110295 --- a/security/selinux/include/xfrm.h
110296 +++ b/security/selinux/include/xfrm.h
110297 @@ -48,7 +48,7 @@ static inline void selinux_xfrm_notify_policyload(void)
110298
110299 rtnl_lock();
110300 for_each_net(net) {
110301 - atomic_inc(&net->xfrm.flow_cache_genid);
110302 + atomic_inc_unchecked(&net->xfrm.flow_cache_genid);
110303 rt_genid_bump_all(net);
110304 }
110305 rtnl_unlock();
110306 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
110307 index e6ab307..2008c98 100644
110308 --- a/security/smack/smack_lsm.c
110309 +++ b/security/smack/smack_lsm.c
110310 @@ -3849,7 +3849,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
110311 return 0;
110312 }
110313
110314 -struct security_operations smack_ops = {
110315 +struct security_operations smack_ops __read_only = {
110316 .name = "smack",
110317
110318 .ptrace_access_check = smack_ptrace_access_check,
110319 diff --git a/security/tomoyo/file.c b/security/tomoyo/file.c
110320 index 4003907..13a2b55 100644
110321 --- a/security/tomoyo/file.c
110322 +++ b/security/tomoyo/file.c
110323 @@ -692,7 +692,7 @@ int tomoyo_path_number_perm(const u8 type, struct path *path,
110324 {
110325 struct tomoyo_request_info r;
110326 struct tomoyo_obj_info obj = {
110327 - .path1 = *path,
110328 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
110329 };
110330 int error = -ENOMEM;
110331 struct tomoyo_path_info buf;
110332 @@ -740,7 +740,7 @@ int tomoyo_check_open_permission(struct tomoyo_domain_info *domain,
110333 struct tomoyo_path_info buf;
110334 struct tomoyo_request_info r;
110335 struct tomoyo_obj_info obj = {
110336 - .path1 = *path,
110337 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
110338 };
110339 int idx;
110340
110341 @@ -786,7 +786,7 @@ int tomoyo_path_perm(const u8 operation, struct path *path, const char *target)
110342 {
110343 struct tomoyo_request_info r;
110344 struct tomoyo_obj_info obj = {
110345 - .path1 = *path,
110346 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
110347 };
110348 int error;
110349 struct tomoyo_path_info buf;
110350 @@ -843,7 +843,7 @@ int tomoyo_mkdev_perm(const u8 operation, struct path *path,
110351 {
110352 struct tomoyo_request_info r;
110353 struct tomoyo_obj_info obj = {
110354 - .path1 = *path,
110355 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
110356 };
110357 int error = -ENOMEM;
110358 struct tomoyo_path_info buf;
110359 @@ -890,8 +890,8 @@ int tomoyo_path2_perm(const u8 operation, struct path *path1,
110360 struct tomoyo_path_info buf2;
110361 struct tomoyo_request_info r;
110362 struct tomoyo_obj_info obj = {
110363 - .path1 = *path1,
110364 - .path2 = *path2,
110365 + .path1 = { .mnt = path1->mnt, .dentry = path1->dentry },
110366 + .path2 = { .mnt = path2->mnt, .dentry = path2->dentry }
110367 };
110368 int idx;
110369
110370 diff --git a/security/tomoyo/mount.c b/security/tomoyo/mount.c
110371 index 390c646..f2f8db3 100644
110372 --- a/security/tomoyo/mount.c
110373 +++ b/security/tomoyo/mount.c
110374 @@ -118,6 +118,10 @@ static int tomoyo_mount_acl(struct tomoyo_request_info *r,
110375 type == tomoyo_mounts[TOMOYO_MOUNT_MOVE]) {
110376 need_dev = -1; /* dev_name is a directory */
110377 } else {
110378 + if (!capable(CAP_SYS_ADMIN)) {
110379 + error = -EPERM;
110380 + goto out;
110381 + }
110382 fstype = get_fs_type(type);
110383 if (!fstype) {
110384 error = -ENODEV;
110385 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
110386 index f0b756e..8aa497b 100644
110387 --- a/security/tomoyo/tomoyo.c
110388 +++ b/security/tomoyo/tomoyo.c
110389 @@ -146,7 +146,7 @@ static int tomoyo_bprm_check_security(struct linux_binprm *bprm)
110390 */
110391 static int tomoyo_inode_getattr(struct vfsmount *mnt, struct dentry *dentry)
110392 {
110393 - struct path path = { mnt, dentry };
110394 + struct path path = { .mnt = mnt, .dentry = dentry };
110395 return tomoyo_path_perm(TOMOYO_TYPE_GETATTR, &path, NULL);
110396 }
110397
110398 @@ -172,7 +172,7 @@ static int tomoyo_path_truncate(struct path *path)
110399 */
110400 static int tomoyo_path_unlink(struct path *parent, struct dentry *dentry)
110401 {
110402 - struct path path = { parent->mnt, dentry };
110403 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
110404 return tomoyo_path_perm(TOMOYO_TYPE_UNLINK, &path, NULL);
110405 }
110406
110407 @@ -188,7 +188,7 @@ static int tomoyo_path_unlink(struct path *parent, struct dentry *dentry)
110408 static int tomoyo_path_mkdir(struct path *parent, struct dentry *dentry,
110409 umode_t mode)
110410 {
110411 - struct path path = { parent->mnt, dentry };
110412 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
110413 return tomoyo_path_number_perm(TOMOYO_TYPE_MKDIR, &path,
110414 mode & S_IALLUGO);
110415 }
110416 @@ -203,7 +203,7 @@ static int tomoyo_path_mkdir(struct path *parent, struct dentry *dentry,
110417 */
110418 static int tomoyo_path_rmdir(struct path *parent, struct dentry *dentry)
110419 {
110420 - struct path path = { parent->mnt, dentry };
110421 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
110422 return tomoyo_path_perm(TOMOYO_TYPE_RMDIR, &path, NULL);
110423 }
110424
110425 @@ -219,7 +219,7 @@ static int tomoyo_path_rmdir(struct path *parent, struct dentry *dentry)
110426 static int tomoyo_path_symlink(struct path *parent, struct dentry *dentry,
110427 const char *old_name)
110428 {
110429 - struct path path = { parent->mnt, dentry };
110430 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
110431 return tomoyo_path_perm(TOMOYO_TYPE_SYMLINK, &path, old_name);
110432 }
110433
110434 @@ -236,7 +236,7 @@ static int tomoyo_path_symlink(struct path *parent, struct dentry *dentry,
110435 static int tomoyo_path_mknod(struct path *parent, struct dentry *dentry,
110436 umode_t mode, unsigned int dev)
110437 {
110438 - struct path path = { parent->mnt, dentry };
110439 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
110440 int type = TOMOYO_TYPE_CREATE;
110441 const unsigned int perm = mode & S_IALLUGO;
110442
110443 @@ -275,8 +275,8 @@ static int tomoyo_path_mknod(struct path *parent, struct dentry *dentry,
110444 static int tomoyo_path_link(struct dentry *old_dentry, struct path *new_dir,
110445 struct dentry *new_dentry)
110446 {
110447 - struct path path1 = { new_dir->mnt, old_dentry };
110448 - struct path path2 = { new_dir->mnt, new_dentry };
110449 + struct path path1 = { .mnt = new_dir->mnt, .dentry = old_dentry };
110450 + struct path path2 = { .mnt = new_dir->mnt, .dentry = new_dentry };
110451 return tomoyo_path2_perm(TOMOYO_TYPE_LINK, &path1, &path2);
110452 }
110453
110454 @@ -295,8 +295,8 @@ static int tomoyo_path_rename(struct path *old_parent,
110455 struct path *new_parent,
110456 struct dentry *new_dentry)
110457 {
110458 - struct path path1 = { old_parent->mnt, old_dentry };
110459 - struct path path2 = { new_parent->mnt, new_dentry };
110460 + struct path path1 = { .mnt = old_parent->mnt, .dentry = old_dentry };
110461 + struct path path2 = { .mnt = new_parent->mnt, .dentry = new_dentry };
110462 return tomoyo_path2_perm(TOMOYO_TYPE_RENAME, &path1, &path2);
110463 }
110464
110465 @@ -424,7 +424,7 @@ static int tomoyo_sb_mount(const char *dev_name, struct path *path,
110466 */
110467 static int tomoyo_sb_umount(struct vfsmount *mnt, int flags)
110468 {
110469 - struct path path = { mnt, mnt->mnt_root };
110470 + struct path path = { .mnt = mnt, .dentry = mnt->mnt_root };
110471 return tomoyo_path_perm(TOMOYO_TYPE_UMOUNT, &path, NULL);
110472 }
110473
110474 @@ -503,7 +503,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
110475 * tomoyo_security_ops is a "struct security_operations" which is used for
110476 * registering TOMOYO.
110477 */
110478 -static struct security_operations tomoyo_security_ops = {
110479 +static struct security_operations tomoyo_security_ops __read_only = {
110480 .name = "tomoyo",
110481 .cred_alloc_blank = tomoyo_cred_alloc_blank,
110482 .cred_prepare = tomoyo_cred_prepare,
110483 diff --git a/security/yama/Kconfig b/security/yama/Kconfig
110484 index 20ef514..4182bed 100644
110485 --- a/security/yama/Kconfig
110486 +++ b/security/yama/Kconfig
110487 @@ -1,6 +1,6 @@
110488 config SECURITY_YAMA
110489 bool "Yama support"
110490 - depends on SECURITY
110491 + depends on SECURITY && !GRKERNSEC
110492 select SECURITYFS
110493 select SECURITY_PATH
110494 default n
110495 diff --git a/security/yama/yama_lsm.c b/security/yama/yama_lsm.c
110496 index 13c88fbc..f8c115e 100644
110497 --- a/security/yama/yama_lsm.c
110498 +++ b/security/yama/yama_lsm.c
110499 @@ -365,7 +365,7 @@ int yama_ptrace_traceme(struct task_struct *parent)
110500 }
110501
110502 #ifndef CONFIG_SECURITY_YAMA_STACKED
110503 -static struct security_operations yama_ops = {
110504 +static struct security_operations yama_ops __read_only = {
110505 .name = "yama",
110506
110507 .ptrace_access_check = yama_ptrace_access_check,
110508 @@ -376,28 +376,24 @@ static struct security_operations yama_ops = {
110509 #endif
110510
110511 #ifdef CONFIG_SYSCTL
110512 +static int zero __read_only;
110513 +static int max_scope __read_only = YAMA_SCOPE_NO_ATTACH;
110514 +
110515 static int yama_dointvec_minmax(struct ctl_table *table, int write,
110516 void __user *buffer, size_t *lenp, loff_t *ppos)
110517 {
110518 - int rc;
110519 + ctl_table_no_const yama_table;
110520
110521 if (write && !capable(CAP_SYS_PTRACE))
110522 return -EPERM;
110523
110524 - rc = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
110525 - if (rc)
110526 - return rc;
110527 -
110528 + yama_table = *table;
110529 /* Lock the max value if it ever gets set. */
110530 - if (write && *(int *)table->data == *(int *)table->extra2)
110531 - table->extra1 = table->extra2;
110532 -
110533 - return rc;
110534 + if (ptrace_scope == max_scope)
110535 + yama_table.extra1 = &max_scope;
110536 + return proc_dointvec_minmax(&yama_table, write, buffer, lenp, ppos);
110537 }
110538
110539 -static int zero;
110540 -static int max_scope = YAMA_SCOPE_NO_ATTACH;
110541 -
110542 struct ctl_path yama_sysctl_path[] = {
110543 { .procname = "kernel", },
110544 { .procname = "yama", },
110545 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
110546 index 401107b..b9c47c6 100644
110547 --- a/sound/aoa/codecs/onyx.c
110548 +++ b/sound/aoa/codecs/onyx.c
110549 @@ -54,7 +54,7 @@ struct onyx {
110550 spdif_locked:1,
110551 analog_locked:1,
110552 original_mute:2;
110553 - int open_count;
110554 + local_t open_count;
110555 struct codec_info *codec_info;
110556
110557 /* mutex serializes concurrent access to the device
110558 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
110559 struct onyx *onyx = cii->codec_data;
110560
110561 mutex_lock(&onyx->mutex);
110562 - onyx->open_count++;
110563 + local_inc(&onyx->open_count);
110564 mutex_unlock(&onyx->mutex);
110565
110566 return 0;
110567 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
110568 struct onyx *onyx = cii->codec_data;
110569
110570 mutex_lock(&onyx->mutex);
110571 - onyx->open_count--;
110572 - if (!onyx->open_count)
110573 + if (local_dec_and_test(&onyx->open_count))
110574 onyx->spdif_locked = onyx->analog_locked = 0;
110575 mutex_unlock(&onyx->mutex);
110576
110577 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
110578 index ffd2025..df062c9 100644
110579 --- a/sound/aoa/codecs/onyx.h
110580 +++ b/sound/aoa/codecs/onyx.h
110581 @@ -11,6 +11,7 @@
110582 #include <linux/i2c.h>
110583 #include <asm/pmac_low_i2c.h>
110584 #include <asm/prom.h>
110585 +#include <asm/local.h>
110586
110587 /* PCM3052 register definitions */
110588
110589 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
110590 index ada69d7..5f65386 100644
110591 --- a/sound/core/oss/pcm_oss.c
110592 +++ b/sound/core/oss/pcm_oss.c
110593 @@ -1190,10 +1190,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
110594 if (in_kernel) {
110595 mm_segment_t fs;
110596 fs = snd_enter_user();
110597 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
110598 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
110599 snd_leave_user(fs);
110600 } else {
110601 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
110602 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
110603 }
110604 if (ret != -EPIPE && ret != -ESTRPIPE)
110605 break;
110606 @@ -1233,10 +1233,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
110607 if (in_kernel) {
110608 mm_segment_t fs;
110609 fs = snd_enter_user();
110610 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
110611 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
110612 snd_leave_user(fs);
110613 } else {
110614 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
110615 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
110616 }
110617 if (ret == -EPIPE) {
110618 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
110619 @@ -1332,7 +1332,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
110620 struct snd_pcm_plugin_channel *channels;
110621 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
110622 if (!in_kernel) {
110623 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
110624 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
110625 return -EFAULT;
110626 buf = runtime->oss.buffer;
110627 }
110628 @@ -1402,7 +1402,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
110629 }
110630 } else {
110631 tmp = snd_pcm_oss_write2(substream,
110632 - (const char __force *)buf,
110633 + (const char __force_kernel *)buf,
110634 runtime->oss.period_bytes, 0);
110635 if (tmp <= 0)
110636 goto err;
110637 @@ -1428,7 +1428,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
110638 struct snd_pcm_runtime *runtime = substream->runtime;
110639 snd_pcm_sframes_t frames, frames1;
110640 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
110641 - char __user *final_dst = (char __force __user *)buf;
110642 + char __user *final_dst = (char __force_user *)buf;
110643 if (runtime->oss.plugin_first) {
110644 struct snd_pcm_plugin_channel *channels;
110645 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
110646 @@ -1490,7 +1490,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
110647 xfer += tmp;
110648 runtime->oss.buffer_used -= tmp;
110649 } else {
110650 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
110651 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
110652 runtime->oss.period_bytes, 0);
110653 if (tmp <= 0)
110654 goto err;
110655 @@ -1659,7 +1659,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
110656 size1);
110657 size1 /= runtime->channels; /* frames */
110658 fs = snd_enter_user();
110659 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
110660 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
110661 snd_leave_user(fs);
110662 }
110663 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
110664 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
110665 index 2d957ba..fda022c 100644
110666 --- a/sound/core/pcm_compat.c
110667 +++ b/sound/core/pcm_compat.c
110668 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
110669 int err;
110670
110671 fs = snd_enter_user();
110672 - err = snd_pcm_delay(substream, &delay);
110673 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
110674 snd_leave_user(fs);
110675 if (err < 0)
110676 return err;
110677 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
110678 index a95356f..0f5eabf 100644
110679 --- a/sound/core/pcm_native.c
110680 +++ b/sound/core/pcm_native.c
110681 @@ -2815,11 +2815,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
110682 switch (substream->stream) {
110683 case SNDRV_PCM_STREAM_PLAYBACK:
110684 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
110685 - (void __user *)arg);
110686 + (void __force_user *)arg);
110687 break;
110688 case SNDRV_PCM_STREAM_CAPTURE:
110689 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
110690 - (void __user *)arg);
110691 + (void __force_user *)arg);
110692 break;
110693 default:
110694 result = -EINVAL;
110695 diff --git a/sound/core/seq/oss/seq_oss.c b/sound/core/seq/oss/seq_oss.c
110696 index 16d4267..fe8b49b 100644
110697 --- a/sound/core/seq/oss/seq_oss.c
110698 +++ b/sound/core/seq/oss/seq_oss.c
110699 @@ -69,8 +69,8 @@ static int __init alsa_seq_oss_init(void)
110700 {
110701 int rc;
110702 static struct snd_seq_dev_ops ops = {
110703 - snd_seq_oss_synth_register,
110704 - snd_seq_oss_synth_unregister,
110705 + .init_device = snd_seq_oss_synth_register,
110706 + .free_device = snd_seq_oss_synth_unregister,
110707 };
110708
110709 snd_seq_autoload_lock();
110710 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
110711 index 91a786a..4c07ed4 100644
110712 --- a/sound/core/seq/seq_device.c
110713 +++ b/sound/core/seq/seq_device.c
110714 @@ -64,7 +64,7 @@ struct ops_list {
110715 int argsize; /* argument size */
110716
110717 /* operators */
110718 - struct snd_seq_dev_ops ops;
110719 + struct snd_seq_dev_ops *ops;
110720
110721 /* registered devices */
110722 struct list_head dev_list; /* list of devices */
110723 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
110724
110725 mutex_lock(&ops->reg_mutex);
110726 /* copy driver operators */
110727 - ops->ops = *entry;
110728 + ops->ops = entry;
110729 ops->driver |= DRIVER_LOADED;
110730 ops->argsize = argsize;
110731
110732 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
110733 dev->name, ops->id, ops->argsize, dev->argsize);
110734 return -EINVAL;
110735 }
110736 - if (ops->ops.init_device(dev) >= 0) {
110737 + if (ops->ops->init_device(dev) >= 0) {
110738 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
110739 ops->num_init_devices++;
110740 } else {
110741 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
110742 dev->name, ops->id, ops->argsize, dev->argsize);
110743 return -EINVAL;
110744 }
110745 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
110746 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
110747 dev->status = SNDRV_SEQ_DEVICE_FREE;
110748 dev->driver_data = NULL;
110749 ops->num_init_devices--;
110750 diff --git a/sound/core/seq/seq_midi.c b/sound/core/seq/seq_midi.c
110751 index a1fd77a..69cd659 100644
110752 --- a/sound/core/seq/seq_midi.c
110753 +++ b/sound/core/seq/seq_midi.c
110754 @@ -462,8 +462,8 @@ snd_seq_midisynth_unregister_port(struct snd_seq_device *dev)
110755 static int __init alsa_seq_midi_init(void)
110756 {
110757 static struct snd_seq_dev_ops ops = {
110758 - snd_seq_midisynth_register_port,
110759 - snd_seq_midisynth_unregister_port,
110760 + .init_device = snd_seq_midisynth_register_port,
110761 + .free_device = snd_seq_midisynth_unregister_port,
110762 };
110763 memset(&synths, 0, sizeof(synths));
110764 snd_seq_autoload_lock();
110765 diff --git a/sound/core/sound.c b/sound/core/sound.c
110766 index 38ad1a0..5010a40 100644
110767 --- a/sound/core/sound.c
110768 +++ b/sound/core/sound.c
110769 @@ -86,7 +86,7 @@ static void snd_request_other(int minor)
110770 case SNDRV_MINOR_TIMER: str = "snd-timer"; break;
110771 default: return;
110772 }
110773 - request_module(str);
110774 + request_module("%s", str);
110775 }
110776
110777 #endif /* modular kernel */
110778 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
110779 index f5fd448..6ae276da 100644
110780 --- a/sound/drivers/mts64.c
110781 +++ b/sound/drivers/mts64.c
110782 @@ -29,6 +29,7 @@
110783 #include <sound/initval.h>
110784 #include <sound/rawmidi.h>
110785 #include <sound/control.h>
110786 +#include <asm/local.h>
110787
110788 #define CARD_NAME "Miditerminal 4140"
110789 #define DRIVER_NAME "MTS64"
110790 @@ -67,7 +68,7 @@ struct mts64 {
110791 struct pardevice *pardev;
110792 int pardev_claimed;
110793
110794 - int open_count;
110795 + local_t open_count;
110796 int current_midi_output_port;
110797 int current_midi_input_port;
110798 u8 mode[MTS64_NUM_INPUT_PORTS];
110799 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
110800 {
110801 struct mts64 *mts = substream->rmidi->private_data;
110802
110803 - if (mts->open_count == 0) {
110804 + if (local_read(&mts->open_count) == 0) {
110805 /* We don't need a spinlock here, because this is just called
110806 if the device has not been opened before.
110807 So there aren't any IRQs from the device */
110808 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
110809
110810 msleep(50);
110811 }
110812 - ++(mts->open_count);
110813 + local_inc(&mts->open_count);
110814
110815 return 0;
110816 }
110817 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
110818 struct mts64 *mts = substream->rmidi->private_data;
110819 unsigned long flags;
110820
110821 - --(mts->open_count);
110822 - if (mts->open_count == 0) {
110823 + if (local_dec_return(&mts->open_count) == 0) {
110824 /* We need the spinlock_irqsave here because we can still
110825 have IRQs at this point */
110826 spin_lock_irqsave(&mts->lock, flags);
110827 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
110828
110829 msleep(500);
110830
110831 - } else if (mts->open_count < 0)
110832 - mts->open_count = 0;
110833 + } else if (local_read(&mts->open_count) < 0)
110834 + local_set(&mts->open_count, 0);
110835
110836 return 0;
110837 }
110838 diff --git a/sound/drivers/opl3/opl3_seq.c b/sound/drivers/opl3/opl3_seq.c
110839 index 6839953..7a0f4b9 100644
110840 --- a/sound/drivers/opl3/opl3_seq.c
110841 +++ b/sound/drivers/opl3/opl3_seq.c
110842 @@ -281,8 +281,8 @@ static int __init alsa_opl3_seq_init(void)
110843 {
110844 static struct snd_seq_dev_ops ops =
110845 {
110846 - snd_opl3_seq_new_device,
110847 - snd_opl3_seq_delete_device
110848 + .init_device = snd_opl3_seq_new_device,
110849 + .free_device = snd_opl3_seq_delete_device
110850 };
110851
110852 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OPL3, &ops,
110853 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
110854 index b953fb4..1999c01 100644
110855 --- a/sound/drivers/opl4/opl4_lib.c
110856 +++ b/sound/drivers/opl4/opl4_lib.c
110857 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
110858 MODULE_DESCRIPTION("OPL4 driver");
110859 MODULE_LICENSE("GPL");
110860
110861 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
110862 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
110863 {
110864 int timeout = 10;
110865 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
110866 diff --git a/sound/drivers/opl4/opl4_seq.c b/sound/drivers/opl4/opl4_seq.c
110867 index 9919769..d7de36c 100644
110868 --- a/sound/drivers/opl4/opl4_seq.c
110869 +++ b/sound/drivers/opl4/opl4_seq.c
110870 @@ -198,8 +198,8 @@ static int snd_opl4_seq_delete_device(struct snd_seq_device *dev)
110871 static int __init alsa_opl4_synth_init(void)
110872 {
110873 static struct snd_seq_dev_ops ops = {
110874 - snd_opl4_seq_new_device,
110875 - snd_opl4_seq_delete_device
110876 + .init_device = snd_opl4_seq_new_device,
110877 + .free_device = snd_opl4_seq_delete_device
110878 };
110879
110880 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OPL4, &ops,
110881 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
110882 index 78ccfa4..7a0857b 100644
110883 --- a/sound/drivers/portman2x4.c
110884 +++ b/sound/drivers/portman2x4.c
110885 @@ -48,6 +48,7 @@
110886 #include <sound/initval.h>
110887 #include <sound/rawmidi.h>
110888 #include <sound/control.h>
110889 +#include <asm/local.h>
110890
110891 #define CARD_NAME "Portman 2x4"
110892 #define DRIVER_NAME "portman"
110893 @@ -85,7 +86,7 @@ struct portman {
110894 struct pardevice *pardev;
110895 int pardev_claimed;
110896
110897 - int open_count;
110898 + local_t open_count;
110899 int mode[PORTMAN_NUM_INPUT_PORTS];
110900 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
110901 };
110902 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
110903 index 95fc2eaf..ea5d6a7 100644
110904 --- a/sound/firewire/amdtp.c
110905 +++ b/sound/firewire/amdtp.c
110906 @@ -521,7 +521,7 @@ static void update_pcm_pointers(struct amdtp_stream *s,
110907 ptr = s->pcm_buffer_pointer + frames;
110908 if (ptr >= pcm->runtime->buffer_size)
110909 ptr -= pcm->runtime->buffer_size;
110910 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
110911 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
110912
110913 s->pcm_period_pointer += frames;
110914 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
110915 @@ -961,7 +961,7 @@ EXPORT_SYMBOL(amdtp_stream_pcm_pointer);
110916 */
110917 void amdtp_stream_update(struct amdtp_stream *s)
110918 {
110919 - ACCESS_ONCE(s->source_node_id_field) =
110920 + ACCESS_ONCE_RW(s->source_node_id_field) =
110921 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
110922 }
110923 EXPORT_SYMBOL(amdtp_stream_update);
110924 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
110925 index 4823c08..47a5f7c 100644
110926 --- a/sound/firewire/amdtp.h
110927 +++ b/sound/firewire/amdtp.h
110928 @@ -212,7 +212,7 @@ static inline bool amdtp_stream_pcm_running(struct amdtp_stream *s)
110929 static inline void amdtp_stream_pcm_trigger(struct amdtp_stream *s,
110930 struct snd_pcm_substream *pcm)
110931 {
110932 - ACCESS_ONCE(s->pcm) = pcm;
110933 + ACCESS_ONCE_RW(s->pcm) = pcm;
110934 }
110935
110936 /**
110937 @@ -230,7 +230,7 @@ static inline void amdtp_stream_midi_trigger(struct amdtp_stream *s,
110938 struct snd_rawmidi_substream *midi)
110939 {
110940 if (port < s->midi_ports)
110941 - ACCESS_ONCE(s->midi[port]) = midi;
110942 + ACCESS_ONCE_RW(s->midi[port]) = midi;
110943 }
110944
110945 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
110946 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
110947 index 7ac9443..0ec6274 100644
110948 --- a/sound/firewire/isight.c
110949 +++ b/sound/firewire/isight.c
110950 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
110951 ptr += count;
110952 if (ptr >= runtime->buffer_size)
110953 ptr -= runtime->buffer_size;
110954 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
110955 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
110956
110957 isight->period_counter += count;
110958 if (isight->period_counter >= runtime->period_size) {
110959 @@ -299,7 +299,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
110960 if (err < 0)
110961 return err;
110962
110963 - ACCESS_ONCE(isight->pcm_active) = true;
110964 + ACCESS_ONCE_RW(isight->pcm_active) = true;
110965
110966 return 0;
110967 }
110968 @@ -337,7 +337,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
110969 {
110970 struct isight *isight = substream->private_data;
110971
110972 - ACCESS_ONCE(isight->pcm_active) = false;
110973 + ACCESS_ONCE_RW(isight->pcm_active) = false;
110974
110975 mutex_lock(&isight->mutex);
110976 isight_stop_streaming(isight);
110977 @@ -430,10 +430,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
110978
110979 switch (cmd) {
110980 case SNDRV_PCM_TRIGGER_START:
110981 - ACCESS_ONCE(isight->pcm_running) = true;
110982 + ACCESS_ONCE_RW(isight->pcm_running) = true;
110983 break;
110984 case SNDRV_PCM_TRIGGER_STOP:
110985 - ACCESS_ONCE(isight->pcm_running) = false;
110986 + ACCESS_ONCE_RW(isight->pcm_running) = false;
110987 break;
110988 default:
110989 return -EINVAL;
110990 diff --git a/sound/firewire/scs1x.c b/sound/firewire/scs1x.c
110991 index 2dba848..c682aef 100644
110992 --- a/sound/firewire/scs1x.c
110993 +++ b/sound/firewire/scs1x.c
110994 @@ -74,7 +74,7 @@ static void scs_output_trigger(struct snd_rawmidi_substream *stream, int up)
110995 {
110996 struct scs *scs = stream->rmidi->private_data;
110997
110998 - ACCESS_ONCE(scs->output) = up ? stream : NULL;
110999 + ACCESS_ONCE_RW(scs->output) = up ? stream : NULL;
111000 if (up) {
111001 scs->output_idle = false;
111002 tasklet_schedule(&scs->tasklet);
111003 @@ -257,7 +257,7 @@ static void scs_input_trigger(struct snd_rawmidi_substream *stream, int up)
111004 {
111005 struct scs *scs = stream->rmidi->private_data;
111006
111007 - ACCESS_ONCE(scs->input) = up ? stream : NULL;
111008 + ACCESS_ONCE_RW(scs->input) = up ? stream : NULL;
111009 }
111010
111011 static void scs_input_escaped_byte(struct snd_rawmidi_substream *stream,
111012 @@ -473,8 +473,8 @@ static void scs_remove(struct fw_unit *unit)
111013
111014 snd_card_disconnect(scs->card);
111015
111016 - ACCESS_ONCE(scs->output) = NULL;
111017 - ACCESS_ONCE(scs->input) = NULL;
111018 + ACCESS_ONCE_RW(scs->output) = NULL;
111019 + ACCESS_ONCE_RW(scs->input) = NULL;
111020
111021 wait_event(scs->idle_wait, scs->output_idle);
111022
111023 diff --git a/sound/isa/sb/emu8000_synth.c b/sound/isa/sb/emu8000_synth.c
111024 index 4e3fcfb..ab45a9d 100644
111025 --- a/sound/isa/sb/emu8000_synth.c
111026 +++ b/sound/isa/sb/emu8000_synth.c
111027 @@ -120,8 +120,8 @@ static int __init alsa_emu8000_init(void)
111028 {
111029
111030 static struct snd_seq_dev_ops ops = {
111031 - snd_emu8000_new_device,
111032 - snd_emu8000_delete_device,
111033 + .init_device = snd_emu8000_new_device,
111034 + .free_device = snd_emu8000_delete_device,
111035 };
111036 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU8000, &ops,
111037 sizeof(struct snd_emu8000*));
111038 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
111039 index 048439a..3be9f6f 100644
111040 --- a/sound/oss/sb_audio.c
111041 +++ b/sound/oss/sb_audio.c
111042 @@ -904,7 +904,7 @@ sb16_copy_from_user(int dev,
111043 buf16 = (signed short *)(localbuf + localoffs);
111044 while (c)
111045 {
111046 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
111047 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
111048 if (copy_from_user(lbuf8,
111049 userbuf+useroffs + p,
111050 locallen))
111051 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
111052 index a33e8ce..2262303 100644
111053 --- a/sound/oss/swarm_cs4297a.c
111054 +++ b/sound/oss/swarm_cs4297a.c
111055 @@ -2623,7 +2623,6 @@ static int __init cs4297a_init(void)
111056 {
111057 struct cs4297a_state *s;
111058 u32 pwr, id;
111059 - mm_segment_t fs;
111060 int rval;
111061 u64 cfg;
111062 int mdio_val;
111063 @@ -2709,22 +2708,23 @@ static int __init cs4297a_init(void)
111064 if (!rval) {
111065 char *sb1250_duart_present;
111066
111067 +#if 0
111068 + mm_segment_t fs;
111069 fs = get_fs();
111070 set_fs(KERNEL_DS);
111071 -#if 0
111072 val = SOUND_MASK_LINE;
111073 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
111074 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
111075 val = initvol[i].vol;
111076 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
111077 }
111078 + set_fs(fs);
111079 // cs4297a_write_ac97(s, 0x18, 0x0808);
111080 #else
111081 // cs4297a_write_ac97(s, 0x5e, 0x180);
111082 cs4297a_write_ac97(s, 0x02, 0x0808);
111083 cs4297a_write_ac97(s, 0x18, 0x0808);
111084 #endif
111085 - set_fs(fs);
111086
111087 list_add(&s->list, &cs4297a_devs);
111088
111089 diff --git a/sound/pci/emu10k1/emu10k1_synth.c b/sound/pci/emu10k1/emu10k1_synth.c
111090 index 4c41c90..37f3631 100644
111091 --- a/sound/pci/emu10k1/emu10k1_synth.c
111092 +++ b/sound/pci/emu10k1/emu10k1_synth.c
111093 @@ -108,8 +108,8 @@ static int __init alsa_emu10k1_synth_init(void)
111094 {
111095
111096 static struct snd_seq_dev_ops ops = {
111097 - snd_emu10k1_synth_new_device,
111098 - snd_emu10k1_synth_delete_device,
111099 + .init_device = snd_emu10k1_synth_new_device,
111100 + .free_device = snd_emu10k1_synth_delete_device,
111101 };
111102 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU10K1_SYNTH, &ops,
111103 sizeof(struct snd_emu10k1_synth_arg));
111104 diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
111105 index ec6a7d0..4e578f7 100644
111106 --- a/sound/pci/hda/hda_codec.c
111107 +++ b/sound/pci/hda/hda_codec.c
111108 @@ -966,14 +966,10 @@ find_codec_preset(struct hda_codec *codec)
111109 mutex_unlock(&preset_mutex);
111110
111111 if (mod_requested < HDA_MODREQ_MAX_COUNT) {
111112 - char name[32];
111113 if (!mod_requested)
111114 - snprintf(name, sizeof(name), "snd-hda-codec-id:%08x",
111115 - codec->vendor_id);
111116 + request_module("snd-hda-codec-id:%08x", codec->vendor_id);
111117 else
111118 - snprintf(name, sizeof(name), "snd-hda-codec-id:%04x*",
111119 - (codec->vendor_id >> 16) & 0xffff);
111120 - request_module(name);
111121 + request_module("snd-hda-codec-id:%04x*", (codec->vendor_id >> 16) & 0xffff);
111122 mod_requested++;
111123 goto again;
111124 }
111125 @@ -2780,7 +2776,7 @@ static int get_kctl_0dB_offset(struct hda_codec *codec,
111126 /* FIXME: set_fs() hack for obtaining user-space TLV data */
111127 mm_segment_t fs = get_fs();
111128 set_fs(get_ds());
111129 - if (!kctl->tlv.c(kctl, 0, sizeof(_tlv), _tlv))
111130 + if (!kctl->tlv.c(kctl, 0, sizeof(_tlv), (unsigned int __force_user *)_tlv))
111131 tlv = _tlv;
111132 set_fs(fs);
111133 } else if (kctl->vd[0].access & SNDRV_CTL_ELEM_ACCESS_TLV_READ)
111134 diff --git a/sound/pci/ymfpci/ymfpci.h b/sound/pci/ymfpci/ymfpci.h
111135 index 4631a23..001ae57 100644
111136 --- a/sound/pci/ymfpci/ymfpci.h
111137 +++ b/sound/pci/ymfpci/ymfpci.h
111138 @@ -358,7 +358,7 @@ struct snd_ymfpci {
111139 spinlock_t reg_lock;
111140 spinlock_t voice_lock;
111141 wait_queue_head_t interrupt_sleep;
111142 - atomic_t interrupt_sleep_count;
111143 + atomic_unchecked_t interrupt_sleep_count;
111144 struct snd_info_entry *proc_entry;
111145 const struct firmware *dsp_microcode;
111146 const struct firmware *controller_microcode;
111147 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
111148 index 81c916a..516f0bf 100644
111149 --- a/sound/pci/ymfpci/ymfpci_main.c
111150 +++ b/sound/pci/ymfpci/ymfpci_main.c
111151 @@ -204,8 +204,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
111152 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
111153 break;
111154 }
111155 - if (atomic_read(&chip->interrupt_sleep_count)) {
111156 - atomic_set(&chip->interrupt_sleep_count, 0);
111157 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
111158 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
111159 wake_up(&chip->interrupt_sleep);
111160 }
111161 __end:
111162 @@ -789,7 +789,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
111163 continue;
111164 init_waitqueue_entry(&wait, current);
111165 add_wait_queue(&chip->interrupt_sleep, &wait);
111166 - atomic_inc(&chip->interrupt_sleep_count);
111167 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
111168 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
111169 remove_wait_queue(&chip->interrupt_sleep, &wait);
111170 }
111171 @@ -827,8 +827,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
111172 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
111173 spin_unlock(&chip->reg_lock);
111174
111175 - if (atomic_read(&chip->interrupt_sleep_count)) {
111176 - atomic_set(&chip->interrupt_sleep_count, 0);
111177 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
111178 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
111179 wake_up(&chip->interrupt_sleep);
111180 }
111181 }
111182 @@ -2423,7 +2423,7 @@ int snd_ymfpci_create(struct snd_card *card,
111183 spin_lock_init(&chip->reg_lock);
111184 spin_lock_init(&chip->voice_lock);
111185 init_waitqueue_head(&chip->interrupt_sleep);
111186 - atomic_set(&chip->interrupt_sleep_count, 0);
111187 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
111188 chip->card = card;
111189 chip->pci = pci;
111190 chip->irq = -1;
111191 diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
111192 index a3e0a0d..ab98399 100644
111193 --- a/sound/soc/soc-core.c
111194 +++ b/sound/soc/soc-core.c
111195 @@ -2286,8 +2286,10 @@ int snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops *ops,
111196 if (ret)
111197 return ret;
111198
111199 - ops->warm_reset = snd_soc_ac97_warm_reset;
111200 - ops->reset = snd_soc_ac97_reset;
111201 + pax_open_kernel();
111202 + *(void **)&ops->warm_reset = snd_soc_ac97_warm_reset;
111203 + *(void **)&ops->reset = snd_soc_ac97_reset;
111204 + pax_close_kernel();
111205
111206 snd_ac97_rst_cfg = cfg;
111207 return 0;
111208 diff --git a/sound/synth/emux/emux_seq.c b/sound/synth/emux/emux_seq.c
111209 index 7778b8e..3d619fc 100644
111210 --- a/sound/synth/emux/emux_seq.c
111211 +++ b/sound/synth/emux/emux_seq.c
111212 @@ -33,13 +33,13 @@ static int snd_emux_unuse(void *private_data, struct snd_seq_port_subscribe *inf
111213 * MIDI emulation operators
111214 */
111215 static struct snd_midi_op emux_ops = {
111216 - snd_emux_note_on,
111217 - snd_emux_note_off,
111218 - snd_emux_key_press,
111219 - snd_emux_terminate_note,
111220 - snd_emux_control,
111221 - snd_emux_nrpn,
111222 - snd_emux_sysex,
111223 + .note_on = snd_emux_note_on,
111224 + .note_off = snd_emux_note_off,
111225 + .key_press = snd_emux_key_press,
111226 + .note_terminate = snd_emux_terminate_note,
111227 + .control = snd_emux_control,
111228 + .nrpn = snd_emux_nrpn,
111229 + .sysex = snd_emux_sysex,
111230 };
111231
111232
111233 diff --git a/tools/gcc/.gitignore b/tools/gcc/.gitignore
111234 new file mode 100644
111235 index 0000000..de92ed9
111236 --- /dev/null
111237 +++ b/tools/gcc/.gitignore
111238 @@ -0,0 +1 @@
111239 +randomize_layout_seed.h
111240 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
111241 new file mode 100644
111242 index 0000000..7b8921f
111243 --- /dev/null
111244 +++ b/tools/gcc/Makefile
111245 @@ -0,0 +1,52 @@
111246 +#CC := gcc
111247 +#PLUGIN_SOURCE_FILES := pax_plugin.c
111248 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
111249 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
111250 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
111251 +
111252 +ifeq ($(PLUGINCC),$(HOSTCC))
111253 +HOSTLIBS := hostlibs
111254 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(src) -std=gnu99 -ggdb
111255 +export HOST_EXTRACFLAGS
111256 +else
111257 +HOSTLIBS := hostcxxlibs
111258 +HOST_EXTRACXXFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(src) -std=gnu++98 -fno-rtti -ggdb -Wno-unused-parameter -Wno-narrowing -Wno-unused-variable
111259 +export HOST_EXTRACXXFLAGS
111260 +endif
111261 +
111262 +export GCCPLUGINS_DIR HOSTLIBS
111263 +
111264 +$(HOSTLIBS)-$(CONFIG_PAX_CONSTIFY_PLUGIN) := constify_plugin.so
111265 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
111266 +$(HOSTLIBS)-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
111267 +$(HOSTLIBS)-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
111268 +$(HOSTLIBS)-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
111269 +$(HOSTLIBS)-y += colorize_plugin.so
111270 +$(HOSTLIBS)-$(CONFIG_PAX_LATENT_ENTROPY) += latent_entropy_plugin.so
111271 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STRUCTLEAK) += structleak_plugin.so
111272 +$(HOSTLIBS)-$(CONFIG_GRKERNSEC_RANDSTRUCT) += randomize_layout_plugin.so
111273 +
111274 +subdir-$(CONFIG_PAX_SIZE_OVERFLOW) := size_overflow_plugin
111275 +subdir- += size_overflow_plugin
111276 +
111277 +always := $($(HOSTLIBS)-y)
111278 +
111279 +constify_plugin-objs := constify_plugin.o
111280 +stackleak_plugin-objs := stackleak_plugin.o
111281 +kallocstat_plugin-objs := kallocstat_plugin.o
111282 +kernexec_plugin-objs := kernexec_plugin.o
111283 +checker_plugin-objs := checker_plugin.o
111284 +colorize_plugin-objs := colorize_plugin.o
111285 +latent_entropy_plugin-objs := latent_entropy_plugin.o
111286 +structleak_plugin-objs := structleak_plugin.o
111287 +randomize_layout_plugin-objs := randomize_layout_plugin.o
111288 +
111289 +$(obj)/randomize_layout_plugin.o: $(objtree)/$(obj)/randomize_layout_seed.h
111290 +
111291 +quiet_cmd_create_randomize_layout_seed = GENSEED $@
111292 + cmd_create_randomize_layout_seed = \
111293 + $(CONFIG_SHELL) $(srctree)/$(src)/gen-random-seed.sh $@ $(objtree)/include/generated/randomize_layout_hash.h
111294 +$(objtree)/$(obj)/randomize_layout_seed.h: FORCE
111295 + $(call if_changed,create_randomize_layout_seed)
111296 +
111297 +targets += randomize_layout_seed.h randomize_layout_hash.h
111298 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
111299 new file mode 100644
111300 index 0000000..5452feea
111301 --- /dev/null
111302 +++ b/tools/gcc/checker_plugin.c
111303 @@ -0,0 +1,150 @@
111304 +/*
111305 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
111306 + * Licensed under the GPL v2
111307 + *
111308 + * Note: the choice of the license means that the compilation process is
111309 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
111310 + * but for the kernel it doesn't matter since it doesn't link against
111311 + * any of the gcc libraries
111312 + *
111313 + * gcc plugin to implement various sparse (source code checker) features
111314 + *
111315 + * TODO:
111316 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
111317 + *
111318 + * BUGS:
111319 + * - none known
111320 + */
111321 +
111322 +#include "gcc-common.h"
111323 +
111324 +extern void c_register_addr_space (const char *str, addr_space_t as);
111325 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
111326 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
111327 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
111328 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
111329 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
111330 +
111331 +int plugin_is_GPL_compatible;
111332 +
111333 +static struct plugin_info checker_plugin_info = {
111334 + .version = "201304082245",
111335 + .help = NULL,
111336 +};
111337 +
111338 +#define ADDR_SPACE_KERNEL 0
111339 +#define ADDR_SPACE_FORCE_KERNEL 1
111340 +#define ADDR_SPACE_USER 2
111341 +#define ADDR_SPACE_FORCE_USER 3
111342 +#define ADDR_SPACE_IOMEM 0
111343 +#define ADDR_SPACE_FORCE_IOMEM 0
111344 +#define ADDR_SPACE_PERCPU 0
111345 +#define ADDR_SPACE_FORCE_PERCPU 0
111346 +#define ADDR_SPACE_RCU 0
111347 +#define ADDR_SPACE_FORCE_RCU 0
111348 +
111349 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
111350 +{
111351 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
111352 +}
111353 +
111354 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
111355 +{
111356 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
111357 +}
111358 +
111359 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
111360 +{
111361 + return default_addr_space_valid_pointer_mode(mode, as);
111362 +}
111363 +
111364 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
111365 +{
111366 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
111367 +}
111368 +
111369 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
111370 +{
111371 + return default_addr_space_legitimize_address(x, oldx, mode, as);
111372 +}
111373 +
111374 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
111375 +{
111376 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
111377 + return true;
111378 +
111379 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
111380 + return true;
111381 +
111382 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
111383 + return true;
111384 +
111385 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
111386 + return true;
111387 +
111388 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
111389 + return true;
111390 +
111391 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
111392 + return true;
111393 +
111394 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
111395 + return true;
111396 +
111397 + return subset == superset;
111398 +}
111399 +
111400 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
111401 +{
111402 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
111403 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
111404 +
111405 + return op;
111406 +}
111407 +
111408 +static void register_checker_address_spaces(void *event_data, void *data)
111409 +{
111410 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
111411 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
111412 + c_register_addr_space("__user", ADDR_SPACE_USER);
111413 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
111414 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
111415 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
111416 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
111417 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
111418 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
111419 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
111420 +
111421 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
111422 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
111423 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
111424 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
111425 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
111426 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
111427 + targetm.addr_space.convert = checker_addr_space_convert;
111428 +}
111429 +
111430 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
111431 +{
111432 + const char * const plugin_name = plugin_info->base_name;
111433 + const int argc = plugin_info->argc;
111434 + const struct plugin_argument * const argv = plugin_info->argv;
111435 + int i;
111436 +
111437 + if (!plugin_default_version_check(version, &gcc_version)) {
111438 + error(G_("incompatible gcc/plugin versions"));
111439 + return 1;
111440 + }
111441 +
111442 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
111443 +
111444 + for (i = 0; i < argc; ++i)
111445 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
111446 +
111447 + if (TARGET_64BIT == 0)
111448 + return 0;
111449 +
111450 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
111451 +
111452 + return 0;
111453 +}
111454 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
111455 new file mode 100644
111456 index 0000000..54461af
111457 --- /dev/null
111458 +++ b/tools/gcc/colorize_plugin.c
111459 @@ -0,0 +1,210 @@
111460 +/*
111461 + * Copyright 2012-2014 by PaX Team <pageexec@freemail.hu>
111462 + * Licensed under the GPL v2
111463 + *
111464 + * Note: the choice of the license means that the compilation process is
111465 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
111466 + * but for the kernel it doesn't matter since it doesn't link against
111467 + * any of the gcc libraries
111468 + *
111469 + * gcc plugin to colorize diagnostic output
111470 + *
111471 + */
111472 +
111473 +#include "gcc-common.h"
111474 +
111475 +int plugin_is_GPL_compatible;
111476 +
111477 +static struct plugin_info colorize_plugin_info = {
111478 + .version = "201404202350",
111479 + .help = "color=[never|always|auto]\tdetermine when to colorize\n",
111480 +};
111481 +
111482 +#define GREEN "\033[32m\033[K"
111483 +#define LIGHTGREEN "\033[1;32m\033[K"
111484 +#define YELLOW "\033[33m\033[K"
111485 +#define LIGHTYELLOW "\033[1;33m\033[K"
111486 +#define RED "\033[31m\033[K"
111487 +#define LIGHTRED "\033[1;31m\033[K"
111488 +#define BLUE "\033[34m\033[K"
111489 +#define LIGHTBLUE "\033[1;34m\033[K"
111490 +#define BRIGHT "\033[1;m\033[K"
111491 +#define NORMAL "\033[m\033[K"
111492 +
111493 +static diagnostic_starter_fn old_starter;
111494 +static diagnostic_finalizer_fn old_finalizer;
111495 +
111496 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
111497 +{
111498 + const char *color;
111499 + char *newprefix;
111500 +
111501 + switch (diagnostic->kind) {
111502 + case DK_NOTE:
111503 + color = LIGHTBLUE;
111504 + break;
111505 +
111506 + case DK_PEDWARN:
111507 + case DK_WARNING:
111508 + color = LIGHTYELLOW;
111509 + break;
111510 +
111511 + case DK_ERROR:
111512 + case DK_FATAL:
111513 + case DK_ICE:
111514 + case DK_PERMERROR:
111515 + case DK_SORRY:
111516 + color = LIGHTRED;
111517 + break;
111518 +
111519 + default:
111520 + color = NORMAL;
111521 + }
111522 +
111523 + old_starter(context, diagnostic);
111524 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
111525 + return;
111526 + pp_destroy_prefix(context->printer);
111527 + pp_set_prefix(context->printer, newprefix);
111528 +}
111529 +
111530 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
111531 +{
111532 + old_finalizer(context, diagnostic);
111533 +}
111534 +
111535 +static void colorize_arm(void)
111536 +{
111537 + old_starter = diagnostic_starter(global_dc);
111538 + old_finalizer = diagnostic_finalizer(global_dc);
111539 +
111540 + diagnostic_starter(global_dc) = start_colorize;
111541 + diagnostic_finalizer(global_dc) = finalize_colorize;
111542 +}
111543 +
111544 +static unsigned int execute_colorize_rearm(void)
111545 +{
111546 + if (diagnostic_starter(global_dc) == start_colorize)
111547 + return 0;
111548 +
111549 + colorize_arm();
111550 + return 0;
111551 +}
111552 +
111553 +#if BUILDING_GCC_VERSION >= 4009
111554 +static const struct pass_data colorize_rearm_pass_data = {
111555 +#else
111556 +struct simple_ipa_opt_pass colorize_rearm_pass = {
111557 + .pass = {
111558 +#endif
111559 + .type = SIMPLE_IPA_PASS,
111560 + .name = "colorize_rearm",
111561 +#if BUILDING_GCC_VERSION >= 4008
111562 + .optinfo_flags = OPTGROUP_NONE,
111563 +#endif
111564 +#if BUILDING_GCC_VERSION >= 4009
111565 + .has_gate = false,
111566 + .has_execute = true,
111567 +#else
111568 + .gate = NULL,
111569 + .execute = execute_colorize_rearm,
111570 + .sub = NULL,
111571 + .next = NULL,
111572 + .static_pass_number = 0,
111573 +#endif
111574 + .tv_id = TV_NONE,
111575 + .properties_required = 0,
111576 + .properties_provided = 0,
111577 + .properties_destroyed = 0,
111578 + .todo_flags_start = 0,
111579 + .todo_flags_finish = 0
111580 +#if BUILDING_GCC_VERSION < 4009
111581 + }
111582 +#endif
111583 +};
111584 +
111585 +#if BUILDING_GCC_VERSION >= 4009
111586 +namespace {
111587 +class colorize_rearm_pass : public simple_ipa_opt_pass {
111588 +public:
111589 + colorize_rearm_pass() : simple_ipa_opt_pass(colorize_rearm_pass_data, g) {}
111590 + unsigned int execute() { return execute_colorize_rearm(); }
111591 +};
111592 +}
111593 +
111594 +static opt_pass *make_colorize_rearm_pass(void)
111595 +{
111596 + return new colorize_rearm_pass();
111597 +}
111598 +#else
111599 +static struct opt_pass *make_colorize_rearm_pass(void)
111600 +{
111601 + return &colorize_rearm_pass.pass;
111602 +}
111603 +#endif
111604 +
111605 +static void colorize_start_unit(void *gcc_data, void *user_data)
111606 +{
111607 + colorize_arm();
111608 +}
111609 +
111610 +static bool should_colorize(void)
111611 +{
111612 +#if BUILDING_GCC_VERSION >= 4009
111613 + return false;
111614 +#else
111615 + char const *t = getenv("TERM");
111616 +
111617 + return t && strcmp(t, "dumb") && isatty(STDERR_FILENO);
111618 +#endif
111619 +}
111620 +
111621 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
111622 +{
111623 + const char * const plugin_name = plugin_info->base_name;
111624 + const int argc = plugin_info->argc;
111625 + const struct plugin_argument * const argv = plugin_info->argv;
111626 + int i;
111627 + struct register_pass_info colorize_rearm_pass_info;
111628 + bool colorize;
111629 +
111630 + colorize_rearm_pass_info.pass = make_colorize_rearm_pass();
111631 + colorize_rearm_pass_info.reference_pass_name = "*free_lang_data";
111632 + colorize_rearm_pass_info.ref_pass_instance_number = 1;
111633 + colorize_rearm_pass_info.pos_op = PASS_POS_INSERT_AFTER;
111634 +
111635 + if (!plugin_default_version_check(version, &gcc_version)) {
111636 + error(G_("incompatible gcc/plugin versions"));
111637 + return 1;
111638 + }
111639 +
111640 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
111641 +
111642 + colorize = getenv("GCC_COLORS") ? should_colorize() : false;
111643 +
111644 + for (i = 0; i < argc; ++i) {
111645 + if (!strcmp(argv[i].key, "color")) {
111646 + if (!argv[i].value) {
111647 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
111648 + continue;
111649 + }
111650 + if (!strcmp(argv[i].value, "always"))
111651 + colorize = true;
111652 + else if (!strcmp(argv[i].value, "never"))
111653 + colorize = false;
111654 + else if (!strcmp(argv[i].value, "auto"))
111655 + colorize = should_colorize();
111656 + else
111657 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
111658 + continue;
111659 + }
111660 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
111661 + }
111662 +
111663 + if (colorize) {
111664 + // TODO: parse GCC_COLORS as used by gcc 4.9+
111665 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
111666 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
111667 + }
111668 + return 0;
111669 +}
111670 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
111671 new file mode 100644
111672 index 0000000..82bc5a8
111673 --- /dev/null
111674 +++ b/tools/gcc/constify_plugin.c
111675 @@ -0,0 +1,557 @@
111676 +/*
111677 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
111678 + * Copyright 2011-2014 by PaX Team <pageexec@freemail.hu>
111679 + * Licensed under the GPL v2, or (at your option) v3
111680 + *
111681 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
111682 + *
111683 + * Homepage:
111684 + * http://www.grsecurity.net/~ephox/const_plugin/
111685 + *
111686 + * Usage:
111687 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
111688 + * $ gcc -fplugin=constify_plugin.so test.c -O2
111689 + */
111690 +
111691 +#include "gcc-common.h"
111692 +
111693 +// unused C type flag in all versions 4.5-4.9
111694 +#define TYPE_CONSTIFY_VISITED(TYPE) TYPE_LANG_FLAG_4(TYPE)
111695 +
111696 +int plugin_is_GPL_compatible;
111697 +
111698 +static struct plugin_info const_plugin_info = {
111699 + .version = "201401270210",
111700 + .help = "no-constify\tturn off constification\n",
111701 +};
111702 +
111703 +typedef struct {
111704 + bool has_fptr_field;
111705 + bool has_writable_field;
111706 + bool has_do_const_field;
111707 + bool has_no_const_field;
111708 +} constify_info;
111709 +
111710 +static const_tree get_field_type(const_tree field)
111711 +{
111712 + return strip_array_types(TREE_TYPE(field));
111713 +}
111714 +
111715 +static bool is_fptr(const_tree field)
111716 +{
111717 + const_tree ptr = get_field_type(field);
111718 +
111719 + if (TREE_CODE(ptr) != POINTER_TYPE)
111720 + return false;
111721 +
111722 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
111723 +}
111724 +
111725 +/*
111726 + * determine whether the given structure type meets the requirements for automatic constification,
111727 + * including the constification attributes on nested structure types
111728 + */
111729 +static void constifiable(const_tree node, constify_info *cinfo)
111730 +{
111731 + const_tree field;
111732 +
111733 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
111734 +
111735 + // e.g., pointer to structure fields while still constructing the structure type
111736 + if (TYPE_FIELDS(node) == NULL_TREE)
111737 + return;
111738 +
111739 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
111740 + const_tree type = get_field_type(field);
111741 + enum tree_code code = TREE_CODE(type);
111742 +
111743 + if (node == type)
111744 + continue;
111745 +
111746 + if (is_fptr(field))
111747 + cinfo->has_fptr_field = true;
111748 + else if (!TREE_READONLY(field))
111749 + cinfo->has_writable_field = true;
111750 +
111751 + if (code == RECORD_TYPE || code == UNION_TYPE) {
111752 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
111753 + cinfo->has_do_const_field = true;
111754 + else if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
111755 + cinfo->has_no_const_field = true;
111756 + else
111757 + constifiable(type, cinfo);
111758 + }
111759 + }
111760 +}
111761 +
111762 +static bool constified(const_tree node)
111763 +{
111764 + constify_info cinfo = {
111765 + .has_fptr_field = false,
111766 + .has_writable_field = false,
111767 + .has_do_const_field = false,
111768 + .has_no_const_field = false
111769 + };
111770 +
111771 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
111772 +
111773 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node))) {
111774 +// gcc_assert(!TYPE_READONLY(node));
111775 + return false;
111776 + }
111777 +
111778 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(node))) {
111779 + gcc_assert(TYPE_READONLY(node));
111780 + return true;
111781 + }
111782 +
111783 + constifiable(node, &cinfo);
111784 + if ((!cinfo.has_fptr_field || cinfo.has_writable_field) && !cinfo.has_do_const_field)
111785 + return false;
111786 +
111787 + return TYPE_READONLY(node);
111788 +}
111789 +
111790 +static void deconstify_tree(tree node);
111791 +
111792 +static void deconstify_type(tree type)
111793 +{
111794 + tree field;
111795 +
111796 + gcc_assert(TREE_CODE(type) == RECORD_TYPE || TREE_CODE(type) == UNION_TYPE);
111797 +
111798 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
111799 + const_tree fieldtype = get_field_type(field);
111800 +
111801 + // special case handling of simple ptr-to-same-array-type members
111802 + if (TREE_CODE(TREE_TYPE(field)) == POINTER_TYPE) {
111803 + tree ptrtype = TREE_TYPE(TREE_TYPE(field));
111804 +
111805 + if (TREE_TYPE(TREE_TYPE(field)) == type)
111806 + continue;
111807 + if (TREE_CODE(ptrtype) != RECORD_TYPE && TREE_CODE(ptrtype) != UNION_TYPE)
111808 + continue;
111809 + if (!constified(ptrtype))
111810 + continue;
111811 + if (TYPE_MAIN_VARIANT(ptrtype) == TYPE_MAIN_VARIANT(type)) {
111812 + TREE_TYPE(field) = copy_node(TREE_TYPE(field));
111813 + TREE_TYPE(TREE_TYPE(field)) = build_qualified_type(type, TYPE_QUALS(ptrtype) & ~TYPE_QUAL_CONST);
111814 + }
111815 + continue;
111816 + }
111817 + if (TREE_CODE(fieldtype) != RECORD_TYPE && TREE_CODE(fieldtype) != UNION_TYPE)
111818 + continue;
111819 + if (!constified(fieldtype))
111820 + continue;
111821 +
111822 + deconstify_tree(field);
111823 + TREE_READONLY(field) = 0;
111824 + }
111825 + TYPE_READONLY(type) = 0;
111826 + C_TYPE_FIELDS_READONLY(type) = 0;
111827 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
111828 + TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
111829 + TYPE_ATTRIBUTES(type) = remove_attribute("do_const", TYPE_ATTRIBUTES(type));
111830 + }
111831 +}
111832 +
111833 +static void deconstify_tree(tree node)
111834 +{
111835 + tree old_type, new_type, field;
111836 +
111837 + old_type = TREE_TYPE(node);
111838 + while (TREE_CODE(old_type) == ARRAY_TYPE && TREE_CODE(TREE_TYPE(old_type)) != ARRAY_TYPE) {
111839 + node = TREE_TYPE(node) = copy_node(old_type);
111840 + old_type = TREE_TYPE(old_type);
111841 + }
111842 +
111843 + gcc_assert(TREE_CODE(old_type) == RECORD_TYPE || TREE_CODE(old_type) == UNION_TYPE);
111844 + gcc_assert(TYPE_READONLY(old_type) && (TYPE_QUALS(old_type) & TYPE_QUAL_CONST));
111845 +
111846 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
111847 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
111848 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
111849 + DECL_FIELD_CONTEXT(field) = new_type;
111850 +
111851 + deconstify_type(new_type);
111852 +
111853 + TREE_TYPE(node) = new_type;
111854 +}
111855 +
111856 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
111857 +{
111858 + tree type;
111859 + constify_info cinfo = {
111860 + .has_fptr_field = false,
111861 + .has_writable_field = false,
111862 + .has_do_const_field = false,
111863 + .has_no_const_field = false
111864 + };
111865 +
111866 + *no_add_attrs = true;
111867 + if (TREE_CODE(*node) == FUNCTION_DECL) {
111868 + error("%qE attribute does not apply to functions (%qF)", name, *node);
111869 + return NULL_TREE;
111870 + }
111871 +
111872 + if (TREE_CODE(*node) == PARM_DECL) {
111873 + error("%qE attribute does not apply to function parameters (%qD)", name, *node);
111874 + return NULL_TREE;
111875 + }
111876 +
111877 + if (TREE_CODE(*node) == VAR_DECL) {
111878 + error("%qE attribute does not apply to variables (%qD)", name, *node);
111879 + return NULL_TREE;
111880 + }
111881 +
111882 + if (TYPE_P(*node)) {
111883 + type = *node;
111884 + } else {
111885 + gcc_assert(TREE_CODE(*node) == TYPE_DECL);
111886 + type = TREE_TYPE(*node);
111887 + }
111888 +
111889 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
111890 + error("%qE attribute used on %qT applies to struct and union types only", name, type);
111891 + return NULL_TREE;
111892 + }
111893 +
111894 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
111895 + error("%qE attribute is already applied to the type %qT", name, type);
111896 + return NULL_TREE;
111897 + }
111898 +
111899 + if (TYPE_P(*node)) {
111900 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
111901 + error("%qE attribute used on type %qT is incompatible with 'do_const'", name, type);
111902 + else
111903 + *no_add_attrs = false;
111904 + return NULL_TREE;
111905 + }
111906 +
111907 + constifiable(type, &cinfo);
111908 + if ((cinfo.has_fptr_field && !cinfo.has_writable_field) || lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
111909 + deconstify_tree(*node);
111910 + TYPE_CONSTIFY_VISITED(TREE_TYPE(*node)) = 1;
111911 + return NULL_TREE;
111912 + }
111913 +
111914 + error("%qE attribute used on type %qT that is not constified", name, type);
111915 + return NULL_TREE;
111916 +}
111917 +
111918 +static void constify_type(tree type)
111919 +{
111920 + TYPE_READONLY(type) = 1;
111921 + C_TYPE_FIELDS_READONLY(type) = 1;
111922 + TYPE_CONSTIFY_VISITED(type) = 1;
111923 +// TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
111924 +// TYPE_ATTRIBUTES(type) = tree_cons(get_identifier("do_const"), NULL_TREE, TYPE_ATTRIBUTES(type));
111925 +}
111926 +
111927 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
111928 +{
111929 + *no_add_attrs = true;
111930 + if (!TYPE_P(*node)) {
111931 + error("%qE attribute applies to types only (%qD)", name, *node);
111932 + return NULL_TREE;
111933 + }
111934 +
111935 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
111936 + error("%qE attribute used on %qT applies to struct and union types only", name, *node);
111937 + return NULL_TREE;
111938 + }
111939 +
111940 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(*node))) {
111941 + error("%qE attribute used on %qT is already applied to the type", name, *node);
111942 + return NULL_TREE;
111943 + }
111944 +
111945 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(*node))) {
111946 + error("%qE attribute used on %qT is incompatible with 'no_const'", name, *node);
111947 + return NULL_TREE;
111948 + }
111949 +
111950 + *no_add_attrs = false;
111951 + return NULL_TREE;
111952 +}
111953 +
111954 +static struct attribute_spec no_const_attr = {
111955 + .name = "no_const",
111956 + .min_length = 0,
111957 + .max_length = 0,
111958 + .decl_required = false,
111959 + .type_required = false,
111960 + .function_type_required = false,
111961 + .handler = handle_no_const_attribute,
111962 +#if BUILDING_GCC_VERSION >= 4007
111963 + .affects_type_identity = true
111964 +#endif
111965 +};
111966 +
111967 +static struct attribute_spec do_const_attr = {
111968 + .name = "do_const",
111969 + .min_length = 0,
111970 + .max_length = 0,
111971 + .decl_required = false,
111972 + .type_required = false,
111973 + .function_type_required = false,
111974 + .handler = handle_do_const_attribute,
111975 +#if BUILDING_GCC_VERSION >= 4007
111976 + .affects_type_identity = true
111977 +#endif
111978 +};
111979 +
111980 +static void register_attributes(void *event_data, void *data)
111981 +{
111982 + register_attribute(&no_const_attr);
111983 + register_attribute(&do_const_attr);
111984 +}
111985 +
111986 +static void finish_type(void *event_data, void *data)
111987 +{
111988 + tree type = (tree)event_data;
111989 + constify_info cinfo = {
111990 + .has_fptr_field = false,
111991 + .has_writable_field = false,
111992 + .has_do_const_field = false,
111993 + .has_no_const_field = false
111994 + };
111995 +
111996 + if (type == NULL_TREE || type == error_mark_node)
111997 + return;
111998 +
111999 + if (TYPE_FIELDS(type) == NULL_TREE || TYPE_CONSTIFY_VISITED(type))
112000 + return;
112001 +
112002 + constifiable(type, &cinfo);
112003 +
112004 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type))) {
112005 + if ((cinfo.has_fptr_field && !cinfo.has_writable_field) || cinfo.has_do_const_field) {
112006 + deconstify_type(type);
112007 + TYPE_CONSTIFY_VISITED(type) = 1;
112008 + } else
112009 + error("'no_const' attribute used on type %qT that is not constified", type);
112010 + return;
112011 + }
112012 +
112013 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
112014 + if (!cinfo.has_writable_field) {
112015 + error("'do_const' attribute used on type %qT that is%sconstified", type, cinfo.has_fptr_field ? " " : " not ");
112016 + return;
112017 + }
112018 + constify_type(type);
112019 + return;
112020 + }
112021 +
112022 + if (cinfo.has_fptr_field && !cinfo.has_writable_field) {
112023 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
112024 + error("'do_const' attribute used on type %qT that is constified", type);
112025 + return;
112026 + }
112027 + constify_type(type);
112028 + return;
112029 + }
112030 +
112031 + deconstify_type(type);
112032 + TYPE_CONSTIFY_VISITED(type) = 1;
112033 +}
112034 +
112035 +static void check_global_variables(void *event_data, void *data)
112036 +{
112037 +#if BUILDING_GCC_VERSION >= 4009
112038 + varpool_node *node;
112039 +#else
112040 + struct varpool_node *node;
112041 +#endif
112042 +
112043 + FOR_EACH_VARIABLE(node) {
112044 + tree var = NODE_DECL(node);
112045 + tree type = TREE_TYPE(var);
112046 +
112047 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
112048 + continue;
112049 +
112050 + if (!TYPE_READONLY(type) || !C_TYPE_FIELDS_READONLY(type))
112051 + continue;
112052 +
112053 + if (!TYPE_CONSTIFY_VISITED(type))
112054 + continue;
112055 +
112056 + if (DECL_EXTERNAL(var))
112057 + continue;
112058 +
112059 + if (DECL_INITIAL(var))
112060 + continue;
112061 +
112062 + // this works around a gcc bug/feature where uninitialized globals
112063 + // are moved into the .bss section regardless of any constification
112064 + DECL_INITIAL(var) = build_constructor(type, NULL);
112065 +// inform(DECL_SOURCE_LOCATION(var), "constified variable %qE moved into .rodata", var);
112066 + }
112067 +}
112068 +
112069 +static unsigned int check_local_variables(void)
112070 +{
112071 + unsigned int ret = 0;
112072 + tree var;
112073 +
112074 + unsigned int i;
112075 +
112076 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
112077 + tree type = TREE_TYPE(var);
112078 +
112079 + gcc_assert(DECL_P(var));
112080 + if (is_global_var(var))
112081 + continue;
112082 +
112083 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
112084 + continue;
112085 +
112086 + if (!TYPE_READONLY(type) || !C_TYPE_FIELDS_READONLY(type))
112087 + continue;
112088 +
112089 + if (!TYPE_CONSTIFY_VISITED(type))
112090 + continue;
112091 +
112092 + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
112093 + ret = 1;
112094 + }
112095 + return ret;
112096 +}
112097 +
112098 +#if BUILDING_GCC_VERSION >= 4009
112099 +static const struct pass_data check_local_variables_pass_data = {
112100 +#else
112101 +static struct gimple_opt_pass check_local_variables_pass = {
112102 + .pass = {
112103 +#endif
112104 + .type = GIMPLE_PASS,
112105 + .name = "check_local_variables",
112106 +#if BUILDING_GCC_VERSION >= 4008
112107 + .optinfo_flags = OPTGROUP_NONE,
112108 +#endif
112109 +#if BUILDING_GCC_VERSION >= 4009
112110 + .has_gate = false,
112111 + .has_execute = true,
112112 +#else
112113 + .gate = NULL,
112114 + .execute = check_local_variables,
112115 + .sub = NULL,
112116 + .next = NULL,
112117 + .static_pass_number = 0,
112118 +#endif
112119 + .tv_id = TV_NONE,
112120 + .properties_required = 0,
112121 + .properties_provided = 0,
112122 + .properties_destroyed = 0,
112123 + .todo_flags_start = 0,
112124 + .todo_flags_finish = 0
112125 +#if BUILDING_GCC_VERSION < 4009
112126 + }
112127 +#endif
112128 +};
112129 +
112130 +#if BUILDING_GCC_VERSION >= 4009
112131 +namespace {
112132 +class check_local_variables_pass : public gimple_opt_pass {
112133 +public:
112134 + check_local_variables_pass() : gimple_opt_pass(check_local_variables_pass_data, g) {}
112135 + unsigned int execute() { return check_local_variables(); }
112136 +};
112137 +}
112138 +
112139 +static opt_pass *make_check_local_variables_pass(void)
112140 +{
112141 + return new check_local_variables_pass();
112142 +}
112143 +#else
112144 +static struct opt_pass *make_check_local_variables_pass(void)
112145 +{
112146 + return &check_local_variables_pass.pass;
112147 +}
112148 +#endif
112149 +
112150 +static struct {
112151 + const char *name;
112152 + const char *asm_op;
112153 +} sections[] = {
112154 + {".init.rodata", "\t.section\t.init.rodata,\"a\""},
112155 + {".ref.rodata", "\t.section\t.ref.rodata,\"a\""},
112156 + {".devinit.rodata", "\t.section\t.devinit.rodata,\"a\""},
112157 + {".devexit.rodata", "\t.section\t.devexit.rodata,\"a\""},
112158 + {".cpuinit.rodata", "\t.section\t.cpuinit.rodata,\"a\""},
112159 + {".cpuexit.rodata", "\t.section\t.cpuexit.rodata,\"a\""},
112160 + {".meminit.rodata", "\t.section\t.meminit.rodata,\"a\""},
112161 + {".memexit.rodata", "\t.section\t.memexit.rodata,\"a\""},
112162 + {".data..read_only", "\t.section\t.data..read_only,\"a\""},
112163 +};
112164 +
112165 +static unsigned int (*old_section_type_flags)(tree decl, const char *name, int reloc);
112166 +
112167 +static unsigned int constify_section_type_flags(tree decl, const char *name, int reloc)
112168 +{
112169 + size_t i;
112170 +
112171 + for (i = 0; i < ARRAY_SIZE(sections); i++)
112172 + if (!strcmp(sections[i].name, name))
112173 + return 0;
112174 + return old_section_type_flags(decl, name, reloc);
112175 +}
112176 +
112177 +static void constify_start_unit(void *gcc_data, void *user_data)
112178 +{
112179 +// size_t i;
112180 +
112181 +// for (i = 0; i < ARRAY_SIZE(sections); i++)
112182 +// sections[i].section = get_unnamed_section(0, output_section_asm_op, sections[i].asm_op);
112183 +// sections[i].section = get_section(sections[i].name, 0, NULL);
112184 +
112185 + old_section_type_flags = targetm.section_type_flags;
112186 + targetm.section_type_flags = constify_section_type_flags;
112187 +}
112188 +
112189 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
112190 +{
112191 + const char * const plugin_name = plugin_info->base_name;
112192 + const int argc = plugin_info->argc;
112193 + const struct plugin_argument * const argv = plugin_info->argv;
112194 + int i;
112195 + bool constify = true;
112196 +
112197 + struct register_pass_info check_local_variables_pass_info;
112198 +
112199 + check_local_variables_pass_info.pass = make_check_local_variables_pass();
112200 + check_local_variables_pass_info.reference_pass_name = "ssa";
112201 + check_local_variables_pass_info.ref_pass_instance_number = 1;
112202 + check_local_variables_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
112203 +
112204 + if (!plugin_default_version_check(version, &gcc_version)) {
112205 + error(G_("incompatible gcc/plugin versions"));
112206 + return 1;
112207 + }
112208 +
112209 + for (i = 0; i < argc; ++i) {
112210 + if (!(strcmp(argv[i].key, "no-constify"))) {
112211 + constify = false;
112212 + continue;
112213 + }
112214 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
112215 + }
112216 +
112217 + if (strcmp(lang_hooks.name, "GNU C")) {
112218 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
112219 + constify = false;
112220 + }
112221 +
112222 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
112223 + if (constify) {
112224 + register_callback(plugin_name, PLUGIN_ALL_IPA_PASSES_START, check_global_variables, NULL);
112225 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
112226 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &check_local_variables_pass_info);
112227 + register_callback(plugin_name, PLUGIN_START_UNIT, constify_start_unit, NULL);
112228 + }
112229 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
112230 +
112231 + return 0;
112232 +}
112233 diff --git a/tools/gcc/gcc-common.h b/tools/gcc/gcc-common.h
112234 new file mode 100644
112235 index 0000000..e90c205
112236 --- /dev/null
112237 +++ b/tools/gcc/gcc-common.h
112238 @@ -0,0 +1,295 @@
112239 +#ifndef GCC_COMMON_H_INCLUDED
112240 +#define GCC_COMMON_H_INCLUDED
112241 +
112242 +#include "plugin.h"
112243 +#include "bversion.h"
112244 +#include "plugin-version.h"
112245 +#include "config.h"
112246 +#include "system.h"
112247 +#include "coretypes.h"
112248 +#include "tm.h"
112249 +#include "line-map.h"
112250 +#include "input.h"
112251 +#include "tree.h"
112252 +
112253 +#include "tree-inline.h"
112254 +#include "version.h"
112255 +#include "rtl.h"
112256 +#include "tm_p.h"
112257 +#include "flags.h"
112258 +//#include "insn-attr.h"
112259 +//#include "insn-config.h"
112260 +//#include "insn-flags.h"
112261 +#include "hard-reg-set.h"
112262 +//#include "recog.h"
112263 +#include "output.h"
112264 +#include "except.h"
112265 +#include "function.h"
112266 +#include "toplev.h"
112267 +//#include "expr.h"
112268 +#include "basic-block.h"
112269 +#include "intl.h"
112270 +#include "ggc.h"
112271 +//#include "regs.h"
112272 +#include "timevar.h"
112273 +
112274 +#include "params.h"
112275 +#include "pointer-set.h"
112276 +#include "emit-rtl.h"
112277 +//#include "reload.h"
112278 +//#include "ira.h"
112279 +//#include "dwarf2asm.h"
112280 +#include "debug.h"
112281 +#include "target.h"
112282 +#include "langhooks.h"
112283 +#include "cfgloop.h"
112284 +//#include "hosthooks.h"
112285 +#include "cgraph.h"
112286 +#include "opts.h"
112287 +//#include "coverage.h"
112288 +//#include "value-prof.h"
112289 +
112290 +#if BUILDING_GCC_VERSION >= 4007
112291 +#include "tree-pretty-print.h"
112292 +#include "gimple-pretty-print.h"
112293 +#include "c-tree.h"
112294 +//#include "alloc-pool.h"
112295 +#endif
112296 +
112297 +#if BUILDING_GCC_VERSION <= 4008
112298 +#include "tree-flow.h"
112299 +#else
112300 +#include "tree-cfgcleanup.h"
112301 +#endif
112302 +
112303 +#include "diagnostic.h"
112304 +//#include "tree-diagnostic.h"
112305 +#include "tree-dump.h"
112306 +#include "tree-pass.h"
112307 +//#include "df.h"
112308 +#include "predict.h"
112309 +#include "ipa-utils.h"
112310 +
112311 +#if BUILDING_GCC_VERSION >= 4009
112312 +#include "varasm.h"
112313 +#include "stor-layout.h"
112314 +#include "internal-fn.h"
112315 +#include "gimple-expr.h"
112316 +//#include "diagnostic-color.h"
112317 +#include "context.h"
112318 +#include "tree-ssa-alias.h"
112319 +#include "stringpool.h"
112320 +#include "tree-ssanames.h"
112321 +#include "print-tree.h"
112322 +#include "tree-eh.h"
112323 +#include "stmt.h"
112324 +#endif
112325 +
112326 +#include "gimple.h"
112327 +
112328 +#if BUILDING_GCC_VERSION >= 4009
112329 +#include "tree-ssa-operands.h"
112330 +#include "tree-phinodes.h"
112331 +#include "tree-cfg.h"
112332 +#include "gimple-iterator.h"
112333 +#include "gimple-ssa.h"
112334 +#include "ssa-iterators.h"
112335 +#endif
112336 +
112337 +//#include "lto/lto.h"
112338 +//#include "data-streamer.h"
112339 +//#include "lto-compress.h"
112340 +
112341 +//#include "expr.h" where are you...
112342 +extern rtx emit_move_insn(rtx x, rtx y);
112343 +
112344 +// missing from basic_block.h...
112345 +extern void debug_dominance_info(enum cdi_direction dir);
112346 +extern void debug_dominance_tree(enum cdi_direction dir, basic_block root);
112347 +
112348 +#define __unused __attribute__((__unused__))
112349 +
112350 +#define DECL_NAME_POINTER(node) IDENTIFIER_POINTER(DECL_NAME(node))
112351 +#define DECL_NAME_LENGTH(node) IDENTIFIER_LENGTH(DECL_NAME(node))
112352 +#define TYPE_NAME_POINTER(node) IDENTIFIER_POINTER(TYPE_NAME(node))
112353 +#define TYPE_NAME_LENGTH(node) IDENTIFIER_LENGTH(TYPE_NAME(node))
112354 +
112355 +#if BUILDING_GCC_VERSION == 4005
112356 +#define FOR_EACH_LOCAL_DECL(FUN, I, D) for (tree vars = (FUN)->local_decls; vars && (D = TREE_VALUE(vars)); vars = TREE_CHAIN(vars), I)
112357 +#define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
112358 +#define FOR_EACH_VEC_ELT(T, V, I, P) for (I = 0; VEC_iterate(T, (V), (I), (P)); ++(I))
112359 +#define TODO_rebuild_cgraph_edges 0
112360 +
112361 +static inline bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
112362 +{
112363 + tree fndecl;
112364 +
112365 + if (!is_gimple_call(stmt))
112366 + return false;
112367 + fndecl = gimple_call_fndecl(stmt);
112368 + if (!fndecl || DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
112369 + return false;
112370 +// print_node(stderr, "pax", fndecl, 4);
112371 + return DECL_FUNCTION_CODE(fndecl) == code;
112372 +}
112373 +
112374 +static inline bool is_simple_builtin(tree decl)
112375 +{
112376 + if (decl && DECL_BUILT_IN_CLASS(decl) != BUILT_IN_NORMAL)
112377 + return false;
112378 +
112379 + switch (DECL_FUNCTION_CODE(decl)) {
112380 + /* Builtins that expand to constants. */
112381 + case BUILT_IN_CONSTANT_P:
112382 + case BUILT_IN_EXPECT:
112383 + case BUILT_IN_OBJECT_SIZE:
112384 + case BUILT_IN_UNREACHABLE:
112385 + /* Simple register moves or loads from stack. */
112386 + case BUILT_IN_RETURN_ADDRESS:
112387 + case BUILT_IN_EXTRACT_RETURN_ADDR:
112388 + case BUILT_IN_FROB_RETURN_ADDR:
112389 + case BUILT_IN_RETURN:
112390 + case BUILT_IN_AGGREGATE_INCOMING_ADDRESS:
112391 + case BUILT_IN_FRAME_ADDRESS:
112392 + case BUILT_IN_VA_END:
112393 + case BUILT_IN_STACK_SAVE:
112394 + case BUILT_IN_STACK_RESTORE:
112395 + /* Exception state returns or moves registers around. */
112396 + case BUILT_IN_EH_FILTER:
112397 + case BUILT_IN_EH_POINTER:
112398 + case BUILT_IN_EH_COPY_VALUES:
112399 + return true;
112400 +
112401 + default:
112402 + return false;
112403 + }
112404 +}
112405 +#endif
112406 +
112407 +#if BUILDING_GCC_VERSION <= 4006
112408 +#define ANY_RETURN_P(rtx) (GET_CODE(rtx) == RETURN)
112409 +#define C_DECL_REGISTER(EXP) DECL_LANG_FLAG_4(EXP)
112410 +
112411 +// should come from c-tree.h if only it were installed for gcc 4.5...
112412 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
112413 +
112414 +#define get_random_seed(noinit) ({ \
112415 + unsigned HOST_WIDE_INT seed; \
112416 + sscanf(get_random_seed(noinit), "%" HOST_WIDE_INT_PRINT "x", &seed); \
112417 + seed * seed; })
112418 +
112419 +static inline bool gimple_clobber_p(gimple s)
112420 +{
112421 + return false;
112422 +}
112423 +
112424 +static inline tree builtin_decl_implicit(enum built_in_function fncode)
112425 +{
112426 + return implicit_built_in_decls[fncode];
112427 +}
112428 +
112429 +static inline struct cgraph_node *cgraph_get_create_node(tree decl)
112430 +{
112431 + struct cgraph_node *node = cgraph_get_node(decl);
112432 +
112433 + return node ? node : cgraph_node(decl);
112434 +}
112435 +
112436 +static inline bool cgraph_function_with_gimple_body_p(struct cgraph_node *node)
112437 +{
112438 + return node->analyzed && !node->thunk.thunk_p && !node->alias;
112439 +}
112440 +
112441 +static inline struct cgraph_node *cgraph_first_function_with_gimple_body(void)
112442 +{
112443 + struct cgraph_node *node;
112444 +
112445 + for (node = cgraph_nodes; node; node = node->next)
112446 + if (cgraph_function_with_gimple_body_p(node))
112447 + return node;
112448 + return NULL;
112449 +}
112450 +
112451 +static inline struct cgraph_node *cgraph_next_function_with_gimple_body(struct cgraph_node *node)
112452 +{
112453 + for (node = node->next; node; node = node->next)
112454 + if (cgraph_function_with_gimple_body_p(node))
112455 + return node;
112456 + return NULL;
112457 +}
112458 +
112459 +#define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
112460 + for ((node) = cgraph_first_function_with_gimple_body(); (node); \
112461 + (node) = cgraph_next_function_with_gimple_body(node))
112462 +#endif
112463 +
112464 +#if BUILDING_GCC_VERSION == 4006
112465 +extern void debug_gimple_stmt(gimple);
112466 +extern void debug_gimple_seq(gimple_seq);
112467 +extern void print_gimple_seq(FILE *, gimple_seq, int, int);
112468 +extern void print_gimple_stmt(FILE *, gimple, int, int);
112469 +extern void print_gimple_expr(FILE *, gimple, int, int);
112470 +extern void dump_gimple_stmt(pretty_printer *, gimple, int, int);
112471 +#endif
112472 +
112473 +#if BUILDING_GCC_VERSION <= 4007
112474 +#define FOR_EACH_VARIABLE(node) for (node = varpool_nodes; node; node = node->next)
112475 +#define PROP_loops 0
112476 +
112477 +static inline int bb_loop_depth(const_basic_block bb)
112478 +{
112479 + return bb->loop_father ? loop_depth(bb->loop_father) : 0;
112480 +}
112481 +
112482 +static inline bool gimple_store_p(gimple gs)
112483 +{
112484 + tree lhs = gimple_get_lhs(gs);
112485 + return lhs && !is_gimple_reg(lhs);
112486 +}
112487 +#endif
112488 +
112489 +#if BUILDING_GCC_VERSION >= 4007
112490 +#define cgraph_create_edge(caller, callee, call_stmt, count, freq, nest) \
112491 + cgraph_create_edge((caller), (callee), (call_stmt), (count), (freq))
112492 +#define cgraph_create_edge_including_clones(caller, callee, old_call_stmt, call_stmt, count, freq, nest, reason) \
112493 + cgraph_create_edge_including_clones((caller), (callee), (old_call_stmt), (call_stmt), (count), (freq), (reason))
112494 +#endif
112495 +
112496 +#if BUILDING_GCC_VERSION <= 4008
112497 +#define ENTRY_BLOCK_PTR_FOR_FN(FN) ENTRY_BLOCK_PTR_FOR_FUNCTION(FN)
112498 +#define EXIT_BLOCK_PTR_FOR_FN(FN) EXIT_BLOCK_PTR_FOR_FUNCTION(FN)
112499 +#define basic_block_info_for_fn(FN) ((FN)->cfg->x_basic_block_info)
112500 +#define n_basic_blocks_for_fn(FN) ((FN)->cfg->x_n_basic_blocks)
112501 +#define n_edges_for_fn(FN) ((FN)->cfg->x_n_edges)
112502 +#define last_basic_block_for_fn(FN) ((FN)->cfg->x_last_basic_block)
112503 +#define label_to_block_map_for_fn(FN) ((FN)->cfg->x_label_to_block_map)
112504 +#define profile_status_for_fn(FN) ((FN)->cfg->x_profile_status)
112505 +
112506 +static inline const char *get_tree_code_name(enum tree_code code)
112507 +{
112508 + gcc_assert(code < MAX_TREE_CODES);
112509 + return tree_code_name[code];
112510 +}
112511 +
112512 +#define ipa_remove_stmt_references(cnode, stmt)
112513 +#endif
112514 +
112515 +#if BUILDING_GCC_VERSION == 4008
112516 +#define NODE_DECL(node) node->symbol.decl
112517 +#else
112518 +#define NODE_DECL(node) node->decl
112519 +#endif
112520 +
112521 +#if BUILDING_GCC_VERSION >= 4008
112522 +#define add_referenced_var(var)
112523 +#define mark_sym_for_renaming(var)
112524 +#define varpool_mark_needed_node(node)
112525 +#define TODO_dump_func 0
112526 +#define TODO_dump_cgraph 0
112527 +#endif
112528 +
112529 +#if BUILDING_GCC_VERSION >= 4009
112530 +#define TODO_ggc_collect 0
112531 +#endif
112532 +
112533 +#endif
112534 diff --git a/tools/gcc/gen-random-seed.sh b/tools/gcc/gen-random-seed.sh
112535 new file mode 100644
112536 index 0000000..7514850
112537 --- /dev/null
112538 +++ b/tools/gcc/gen-random-seed.sh
112539 @@ -0,0 +1,8 @@
112540 +#!/bin/sh
112541 +
112542 +if [ ! -f "$1" ]; then
112543 + SEED=`od -A n -t x8 -N 32 /dev/urandom | tr -d ' \n'`
112544 + echo "const char *randstruct_seed = \"$SEED\";" > "$1"
112545 + HASH=`echo -n "$SEED" | sha256sum | cut -d" " -f1 | tr -d ' \n'`
112546 + echo "#define RANDSTRUCT_HASHED_SEED \"$HASH\"" > "$2"
112547 +fi
112548 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
112549 new file mode 100644
112550 index 0000000..d81c094
112551 --- /dev/null
112552 +++ b/tools/gcc/kallocstat_plugin.c
112553 @@ -0,0 +1,183 @@
112554 +/*
112555 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
112556 + * Licensed under the GPL v2
112557 + *
112558 + * Note: the choice of the license means that the compilation process is
112559 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
112560 + * but for the kernel it doesn't matter since it doesn't link against
112561 + * any of the gcc libraries
112562 + *
112563 + * gcc plugin to find the distribution of k*alloc sizes
112564 + *
112565 + * TODO:
112566 + *
112567 + * BUGS:
112568 + * - none known
112569 + */
112570 +
112571 +#include "gcc-common.h"
112572 +
112573 +int plugin_is_GPL_compatible;
112574 +
112575 +static struct plugin_info kallocstat_plugin_info = {
112576 + .version = "201401260140",
112577 + .help = NULL
112578 +};
112579 +
112580 +static const char * const kalloc_functions[] = {
112581 + "__kmalloc",
112582 + "kmalloc",
112583 + "kmalloc_large",
112584 + "kmalloc_node",
112585 + "kmalloc_order",
112586 + "kmalloc_order_trace",
112587 + "kmalloc_slab",
112588 + "kzalloc",
112589 + "kzalloc_node",
112590 +};
112591 +
112592 +static bool is_kalloc(const char *fnname)
112593 +{
112594 + size_t i;
112595 +
112596 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
112597 + if (!strcmp(fnname, kalloc_functions[i]))
112598 + return true;
112599 + return false;
112600 +}
112601 +
112602 +static unsigned int execute_kallocstat(void)
112603 +{
112604 + basic_block bb;
112605 +
112606 + // 1. loop through BBs and GIMPLE statements
112607 + FOR_EACH_BB_FN(bb, cfun) {
112608 + gimple_stmt_iterator gsi;
112609 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
112610 + // gimple match:
112611 + tree fndecl, size;
112612 + gimple stmt;
112613 + const char *fnname;
112614 +
112615 + // is it a call
112616 + stmt = gsi_stmt(gsi);
112617 + if (!is_gimple_call(stmt))
112618 + continue;
112619 + fndecl = gimple_call_fndecl(stmt);
112620 + if (fndecl == NULL_TREE)
112621 + continue;
112622 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
112623 + continue;
112624 +
112625 + // is it a call to k*alloc
112626 + fnname = DECL_NAME_POINTER(fndecl);
112627 + if (!is_kalloc(fnname))
112628 + continue;
112629 +
112630 + // is the size arg const or the result of a simple const assignment
112631 + size = gimple_call_arg(stmt, 0);
112632 + while (true) {
112633 + expanded_location xloc;
112634 + size_t size_val;
112635 +
112636 + if (TREE_CONSTANT(size)) {
112637 + xloc = expand_location(gimple_location(stmt));
112638 + if (!xloc.file)
112639 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
112640 + size_val = TREE_INT_CST_LOW(size);
112641 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
112642 + break;
112643 + }
112644 +
112645 + if (TREE_CODE(size) != SSA_NAME)
112646 + break;
112647 + stmt = SSA_NAME_DEF_STMT(size);
112648 +//debug_gimple_stmt(stmt);
112649 +//debug_tree(size);
112650 + if (!stmt || !is_gimple_assign(stmt))
112651 + break;
112652 + if (gimple_num_ops(stmt) != 2)
112653 + break;
112654 + size = gimple_assign_rhs1(stmt);
112655 + }
112656 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
112657 +//debug_tree(gimple_call_fn(call_stmt));
112658 +//print_node(stderr, "pax", fndecl, 4);
112659 + }
112660 + }
112661 +
112662 + return 0;
112663 +}
112664 +
112665 +#if BUILDING_GCC_VERSION >= 4009
112666 +static const struct pass_data kallocstat_pass_data = {
112667 +#else
112668 +static struct gimple_opt_pass kallocstat_pass = {
112669 + .pass = {
112670 +#endif
112671 + .type = GIMPLE_PASS,
112672 + .name = "kallocstat",
112673 +#if BUILDING_GCC_VERSION >= 4008
112674 + .optinfo_flags = OPTGROUP_NONE,
112675 +#endif
112676 +#if BUILDING_GCC_VERSION >= 4009
112677 + .has_gate = false,
112678 + .has_execute = true,
112679 +#else
112680 + .gate = NULL,
112681 + .execute = execute_kallocstat,
112682 + .sub = NULL,
112683 + .next = NULL,
112684 + .static_pass_number = 0,
112685 +#endif
112686 + .tv_id = TV_NONE,
112687 + .properties_required = 0,
112688 + .properties_provided = 0,
112689 + .properties_destroyed = 0,
112690 + .todo_flags_start = 0,
112691 + .todo_flags_finish = 0
112692 +#if BUILDING_GCC_VERSION < 4009
112693 + }
112694 +#endif
112695 +};
112696 +
112697 +#if BUILDING_GCC_VERSION >= 4009
112698 +namespace {
112699 +class kallocstat_pass : public gimple_opt_pass {
112700 +public:
112701 + kallocstat_pass() : gimple_opt_pass(kallocstat_pass_data, g) {}
112702 + unsigned int execute() { return execute_kallocstat(); }
112703 +};
112704 +}
112705 +
112706 +static opt_pass *make_kallocstat_pass(void)
112707 +{
112708 + return new kallocstat_pass();
112709 +}
112710 +#else
112711 +static struct opt_pass *make_kallocstat_pass(void)
112712 +{
112713 + return &kallocstat_pass.pass;
112714 +}
112715 +#endif
112716 +
112717 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
112718 +{
112719 + const char * const plugin_name = plugin_info->base_name;
112720 + struct register_pass_info kallocstat_pass_info;
112721 +
112722 + kallocstat_pass_info.pass = make_kallocstat_pass();
112723 + kallocstat_pass_info.reference_pass_name = "ssa";
112724 + kallocstat_pass_info.ref_pass_instance_number = 1;
112725 + kallocstat_pass_info.pos_op = PASS_POS_INSERT_AFTER;
112726 +
112727 + if (!plugin_default_version_check(version, &gcc_version)) {
112728 + error(G_("incompatible gcc/plugin versions"));
112729 + return 1;
112730 + }
112731 +
112732 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
112733 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
112734 +
112735 + return 0;
112736 +}
112737 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
112738 new file mode 100644
112739 index 0000000..89f256d
112740 --- /dev/null
112741 +++ b/tools/gcc/kernexec_plugin.c
112742 @@ -0,0 +1,522 @@
112743 +/*
112744 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
112745 + * Licensed under the GPL v2
112746 + *
112747 + * Note: the choice of the license means that the compilation process is
112748 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
112749 + * but for the kernel it doesn't matter since it doesn't link against
112750 + * any of the gcc libraries
112751 + *
112752 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
112753 + *
112754 + * TODO:
112755 + *
112756 + * BUGS:
112757 + * - none known
112758 + */
112759 +
112760 +#include "gcc-common.h"
112761 +
112762 +int plugin_is_GPL_compatible;
112763 +
112764 +static struct plugin_info kernexec_plugin_info = {
112765 + .version = "201401260140",
112766 + .help = "method=[bts|or]\tinstrumentation method\n"
112767 +};
112768 +
112769 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
112770 +static void (*kernexec_instrument_retaddr)(rtx);
112771 +
112772 +/*
112773 + * add special KERNEXEC instrumentation: reload %r12 after it has been clobbered
112774 + */
112775 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
112776 +{
112777 + gimple asm_movabs_stmt;
112778 +
112779 + // build asm volatile("movabs $0x8000000000000000, %%r12\n\t" : : : );
112780 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r12\n\t", NULL, NULL, NULL, NULL);
112781 + gimple_asm_set_volatile(asm_movabs_stmt, true);
112782 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
112783 + update_stmt(asm_movabs_stmt);
112784 +}
112785 +
112786 +/*
112787 + * find all asm() stmts that clobber r12 and add a reload of r12
112788 + */
112789 +static unsigned int execute_kernexec_reload(void)
112790 +{
112791 + basic_block bb;
112792 +
112793 + // 1. loop through BBs and GIMPLE statements
112794 + FOR_EACH_BB_FN(bb, cfun) {
112795 + gimple_stmt_iterator gsi;
112796 +
112797 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
112798 + // gimple match: __asm__ ("" : : : "r12");
112799 + gimple asm_stmt;
112800 + size_t nclobbers;
112801 +
112802 + // is it an asm ...
112803 + asm_stmt = gsi_stmt(gsi);
112804 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
112805 + continue;
112806 +
112807 + // ... clobbering r12
112808 + nclobbers = gimple_asm_nclobbers(asm_stmt);
112809 + while (nclobbers--) {
112810 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
112811 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r12"))
112812 + continue;
112813 + kernexec_reload_fptr_mask(&gsi);
112814 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
112815 + break;
112816 + }
112817 + }
112818 + }
112819 +
112820 + return 0;
112821 +}
112822 +
112823 +/*
112824 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
112825 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
112826 + */
112827 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
112828 +{
112829 + gimple assign_intptr, assign_new_fptr, call_stmt;
112830 + tree intptr, orptr, old_fptr, new_fptr, kernexec_mask;
112831 +
112832 + call_stmt = gsi_stmt(*gsi);
112833 + old_fptr = gimple_call_fn(call_stmt);
112834 +
112835 + // create temporary unsigned long variable used for bitops and cast fptr to it
112836 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
112837 + add_referenced_var(intptr);
112838 + intptr = make_ssa_name(intptr, NULL);
112839 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
112840 + SSA_NAME_DEF_STMT(intptr) = assign_intptr;
112841 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
112842 + update_stmt(assign_intptr);
112843 +
112844 + // apply logical or to temporary unsigned long and bitmask
112845 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
112846 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
112847 + orptr = fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask);
112848 + intptr = make_ssa_name(SSA_NAME_VAR(intptr), NULL);
112849 + assign_intptr = gimple_build_assign(intptr, orptr);
112850 + SSA_NAME_DEF_STMT(intptr) = assign_intptr;
112851 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
112852 + update_stmt(assign_intptr);
112853 +
112854 + // cast temporary unsigned long back to a temporary fptr variable
112855 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
112856 + add_referenced_var(new_fptr);
112857 + new_fptr = make_ssa_name(new_fptr, NULL);
112858 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
112859 + SSA_NAME_DEF_STMT(new_fptr) = assign_new_fptr;
112860 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
112861 + update_stmt(assign_new_fptr);
112862 +
112863 + // replace call stmt fn with the new fptr
112864 + gimple_call_set_fn(call_stmt, new_fptr);
112865 + update_stmt(call_stmt);
112866 +}
112867 +
112868 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
112869 +{
112870 + gimple asm_or_stmt, call_stmt;
112871 + tree old_fptr, new_fptr, input, output;
112872 +#if BUILDING_GCC_VERSION <= 4007
112873 + VEC(tree, gc) *inputs = NULL;
112874 + VEC(tree, gc) *outputs = NULL;
112875 +#else
112876 + vec<tree, va_gc> *inputs = NULL;
112877 + vec<tree, va_gc> *outputs = NULL;
112878 +#endif
112879 +
112880 + call_stmt = gsi_stmt(*gsi);
112881 + old_fptr = gimple_call_fn(call_stmt);
112882 +
112883 + // create temporary fptr variable
112884 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
112885 + add_referenced_var(new_fptr);
112886 + new_fptr = make_ssa_name(new_fptr, NULL);
112887 +
112888 + // build asm volatile("orq %%r12, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
112889 + input = build_tree_list(NULL_TREE, build_string(1, "0"));
112890 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
112891 + output = build_tree_list(NULL_TREE, build_string(2, "=r"));
112892 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
112893 +#if BUILDING_GCC_VERSION <= 4007
112894 + VEC_safe_push(tree, gc, inputs, input);
112895 + VEC_safe_push(tree, gc, outputs, output);
112896 +#else
112897 + vec_safe_push(inputs, input);
112898 + vec_safe_push(outputs, output);
112899 +#endif
112900 + asm_or_stmt = gimple_build_asm_vec("orq %%r12, %0\n\t", inputs, outputs, NULL, NULL);
112901 + SSA_NAME_DEF_STMT(new_fptr) = asm_or_stmt;
112902 + gimple_asm_set_volatile(asm_or_stmt, true);
112903 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
112904 + update_stmt(asm_or_stmt);
112905 +
112906 + // replace call stmt fn with the new fptr
112907 + gimple_call_set_fn(call_stmt, new_fptr);
112908 + update_stmt(call_stmt);
112909 +}
112910 +
112911 +/*
112912 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
112913 + */
112914 +static unsigned int execute_kernexec_fptr(void)
112915 +{
112916 + basic_block bb;
112917 +
112918 + // 1. loop through BBs and GIMPLE statements
112919 + FOR_EACH_BB_FN(bb, cfun) {
112920 + gimple_stmt_iterator gsi;
112921 +
112922 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
112923 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
112924 + tree fn;
112925 + gimple call_stmt;
112926 +
112927 + // is it a call ...
112928 + call_stmt = gsi_stmt(gsi);
112929 + if (!is_gimple_call(call_stmt))
112930 + continue;
112931 + fn = gimple_call_fn(call_stmt);
112932 + if (TREE_CODE(fn) == ADDR_EXPR)
112933 + continue;
112934 + if (TREE_CODE(fn) != SSA_NAME)
112935 + gcc_unreachable();
112936 +
112937 + // ... through a function pointer
112938 + if (SSA_NAME_VAR(fn) != NULL_TREE) {
112939 + fn = SSA_NAME_VAR(fn);
112940 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL) {
112941 + debug_tree(fn);
112942 + gcc_unreachable();
112943 + }
112944 + }
112945 + fn = TREE_TYPE(fn);
112946 + if (TREE_CODE(fn) != POINTER_TYPE)
112947 + continue;
112948 + fn = TREE_TYPE(fn);
112949 + if (TREE_CODE(fn) != FUNCTION_TYPE)
112950 + continue;
112951 +
112952 + kernexec_instrument_fptr(&gsi);
112953 +
112954 +//debug_tree(gimple_call_fn(call_stmt));
112955 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
112956 + }
112957 + }
112958 +
112959 + return 0;
112960 +}
112961 +
112962 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
112963 +static void kernexec_instrument_retaddr_bts(rtx insn)
112964 +{
112965 + rtx btsq;
112966 + rtvec argvec, constraintvec, labelvec;
112967 + int line;
112968 +
112969 + // create asm volatile("btsq $63,(%%rsp)":::)
112970 + argvec = rtvec_alloc(0);
112971 + constraintvec = rtvec_alloc(0);
112972 + labelvec = rtvec_alloc(0);
112973 + line = expand_location(RTL_LOCATION(insn)).line;
112974 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
112975 + MEM_VOLATILE_P(btsq) = 1;
112976 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
112977 + emit_insn_before(btsq, insn);
112978 +}
112979 +
112980 +// add special KERNEXEC instrumentation: orq %r12,(%rsp) just before retn
112981 +static void kernexec_instrument_retaddr_or(rtx insn)
112982 +{
112983 + rtx orq;
112984 + rtvec argvec, constraintvec, labelvec;
112985 + int line;
112986 +
112987 + // create asm volatile("orq %%r12,(%%rsp)":::)
112988 + argvec = rtvec_alloc(0);
112989 + constraintvec = rtvec_alloc(0);
112990 + labelvec = rtvec_alloc(0);
112991 + line = expand_location(RTL_LOCATION(insn)).line;
112992 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r12,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
112993 + MEM_VOLATILE_P(orq) = 1;
112994 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
112995 + emit_insn_before(orq, insn);
112996 +}
112997 +
112998 +/*
112999 + * find all asm level function returns and forcibly set the highest bit of the return address
113000 + */
113001 +static unsigned int execute_kernexec_retaddr(void)
113002 +{
113003 + rtx insn;
113004 +
113005 +// if (stack_realign_drap)
113006 +// inform(DECL_SOURCE_LOCATION(current_function_decl), "drap detected in %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
113007 +
113008 + // 1. find function returns
113009 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
113010 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
113011 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
113012 + // (jump_insn 97 96 98 6 (simple_return) fptr.c:50 -1 (nil) -> simple_return)
113013 + rtx body;
113014 +
113015 + // is it a retn
113016 + if (!JUMP_P(insn))
113017 + continue;
113018 + body = PATTERN(insn);
113019 + if (GET_CODE(body) == PARALLEL)
113020 + body = XVECEXP(body, 0, 0);
113021 + if (!ANY_RETURN_P(body))
113022 + continue;
113023 + kernexec_instrument_retaddr(insn);
113024 + }
113025 +
113026 +// print_simple_rtl(stderr, get_insns());
113027 +// print_rtl(stderr, get_insns());
113028 +
113029 + return 0;
113030 +}
113031 +
113032 +static bool kernexec_cmodel_check(void)
113033 +{
113034 + tree section;
113035 +
113036 + if (ix86_cmodel != CM_KERNEL)
113037 + return false;
113038 +
113039 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
113040 + if (!section || !TREE_VALUE(section))
113041 + return true;
113042 +
113043 + section = TREE_VALUE(TREE_VALUE(section));
113044 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
113045 + return true;
113046 +
113047 + return false;
113048 +}
113049 +
113050 +#if BUILDING_GCC_VERSION >= 4009
113051 +static const struct pass_data kernexec_reload_pass_data = {
113052 +#else
113053 +static struct gimple_opt_pass kernexec_reload_pass = {
113054 + .pass = {
113055 +#endif
113056 + .type = GIMPLE_PASS,
113057 + .name = "kernexec_reload",
113058 +#if BUILDING_GCC_VERSION >= 4008
113059 + .optinfo_flags = OPTGROUP_NONE,
113060 +#endif
113061 +#if BUILDING_GCC_VERSION >= 4009
113062 + .has_gate = true,
113063 + .has_execute = true,
113064 +#else
113065 + .gate = kernexec_cmodel_check,
113066 + .execute = execute_kernexec_reload,
113067 + .sub = NULL,
113068 + .next = NULL,
113069 + .static_pass_number = 0,
113070 +#endif
113071 + .tv_id = TV_NONE,
113072 + .properties_required = 0,
113073 + .properties_provided = 0,
113074 + .properties_destroyed = 0,
113075 + .todo_flags_start = 0,
113076 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
113077 +#if BUILDING_GCC_VERSION < 4009
113078 + }
113079 +#endif
113080 +};
113081 +
113082 +#if BUILDING_GCC_VERSION >= 4009
113083 +static const struct pass_data kernexec_fptr_pass_data = {
113084 +#else
113085 +static struct gimple_opt_pass kernexec_fptr_pass = {
113086 + .pass = {
113087 +#endif
113088 + .type = GIMPLE_PASS,
113089 + .name = "kernexec_fptr",
113090 +#if BUILDING_GCC_VERSION >= 4008
113091 + .optinfo_flags = OPTGROUP_NONE,
113092 +#endif
113093 +#if BUILDING_GCC_VERSION >= 4009
113094 + .has_gate = true,
113095 + .has_execute = true,
113096 +#else
113097 + .gate = kernexec_cmodel_check,
113098 + .execute = execute_kernexec_fptr,
113099 + .sub = NULL,
113100 + .next = NULL,
113101 + .static_pass_number = 0,
113102 +#endif
113103 + .tv_id = TV_NONE,
113104 + .properties_required = 0,
113105 + .properties_provided = 0,
113106 + .properties_destroyed = 0,
113107 + .todo_flags_start = 0,
113108 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
113109 +#if BUILDING_GCC_VERSION < 4009
113110 + }
113111 +#endif
113112 +};
113113 +
113114 +#if BUILDING_GCC_VERSION >= 4009
113115 +static const struct pass_data kernexec_retaddr_pass_data = {
113116 +#else
113117 +static struct rtl_opt_pass kernexec_retaddr_pass = {
113118 + .pass = {
113119 +#endif
113120 + .type = RTL_PASS,
113121 + .name = "kernexec_retaddr",
113122 +#if BUILDING_GCC_VERSION >= 4008
113123 + .optinfo_flags = OPTGROUP_NONE,
113124 +#endif
113125 +#if BUILDING_GCC_VERSION >= 4009
113126 + .has_gate = true,
113127 + .has_execute = true,
113128 +#else
113129 + .gate = kernexec_cmodel_check,
113130 + .execute = execute_kernexec_retaddr,
113131 + .sub = NULL,
113132 + .next = NULL,
113133 + .static_pass_number = 0,
113134 +#endif
113135 + .tv_id = TV_NONE,
113136 + .properties_required = 0,
113137 + .properties_provided = 0,
113138 + .properties_destroyed = 0,
113139 + .todo_flags_start = 0,
113140 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
113141 +#if BUILDING_GCC_VERSION < 4009
113142 + }
113143 +#endif
113144 +};
113145 +
113146 +#if BUILDING_GCC_VERSION >= 4009
113147 +namespace {
113148 +class kernexec_reload_pass : public gimple_opt_pass {
113149 +public:
113150 + kernexec_reload_pass() : gimple_opt_pass(kernexec_reload_pass_data, g) {}
113151 + bool gate() { return kernexec_cmodel_check(); }
113152 + unsigned int execute() { return execute_kernexec_reload(); }
113153 +};
113154 +
113155 +class kernexec_fptr_pass : public gimple_opt_pass {
113156 +public:
113157 + kernexec_fptr_pass() : gimple_opt_pass(kernexec_fptr_pass_data, g) {}
113158 + bool gate() { return kernexec_cmodel_check(); }
113159 + unsigned int execute() { return execute_kernexec_fptr(); }
113160 +};
113161 +
113162 +class kernexec_retaddr_pass : public rtl_opt_pass {
113163 +public:
113164 + kernexec_retaddr_pass() : rtl_opt_pass(kernexec_retaddr_pass_data, g) {}
113165 + bool gate() { return kernexec_cmodel_check(); }
113166 + unsigned int execute() { return execute_kernexec_retaddr(); }
113167 +};
113168 +}
113169 +
113170 +static opt_pass *make_kernexec_reload_pass(void)
113171 +{
113172 + return new kernexec_reload_pass();
113173 +}
113174 +
113175 +static opt_pass *make_kernexec_fptr_pass(void)
113176 +{
113177 + return new kernexec_fptr_pass();
113178 +}
113179 +
113180 +static opt_pass *make_kernexec_retaddr_pass(void)
113181 +{
113182 + return new kernexec_retaddr_pass();
113183 +}
113184 +#else
113185 +static struct opt_pass *make_kernexec_reload_pass(void)
113186 +{
113187 + return &kernexec_reload_pass.pass;
113188 +}
113189 +
113190 +static struct opt_pass *make_kernexec_fptr_pass(void)
113191 +{
113192 + return &kernexec_fptr_pass.pass;
113193 +}
113194 +
113195 +static struct opt_pass *make_kernexec_retaddr_pass(void)
113196 +{
113197 + return &kernexec_retaddr_pass.pass;
113198 +}
113199 +#endif
113200 +
113201 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
113202 +{
113203 + const char * const plugin_name = plugin_info->base_name;
113204 + const int argc = plugin_info->argc;
113205 + const struct plugin_argument * const argv = plugin_info->argv;
113206 + int i;
113207 + struct register_pass_info kernexec_reload_pass_info;
113208 + struct register_pass_info kernexec_fptr_pass_info;
113209 + struct register_pass_info kernexec_retaddr_pass_info;
113210 +
113211 + kernexec_reload_pass_info.pass = make_kernexec_reload_pass();
113212 + kernexec_reload_pass_info.reference_pass_name = "ssa";
113213 + kernexec_reload_pass_info.ref_pass_instance_number = 1;
113214 + kernexec_reload_pass_info.pos_op = PASS_POS_INSERT_AFTER;
113215 +
113216 + kernexec_fptr_pass_info.pass = make_kernexec_fptr_pass();
113217 + kernexec_fptr_pass_info.reference_pass_name = "ssa";
113218 + kernexec_fptr_pass_info.ref_pass_instance_number = 1;
113219 + kernexec_fptr_pass_info.pos_op = PASS_POS_INSERT_AFTER;
113220 +
113221 + kernexec_retaddr_pass_info.pass = make_kernexec_retaddr_pass();
113222 + kernexec_retaddr_pass_info.reference_pass_name = "pro_and_epilogue";
113223 + kernexec_retaddr_pass_info.ref_pass_instance_number = 1;
113224 + kernexec_retaddr_pass_info.pos_op = PASS_POS_INSERT_AFTER;
113225 +
113226 + if (!plugin_default_version_check(version, &gcc_version)) {
113227 + error(G_("incompatible gcc/plugin versions"));
113228 + return 1;
113229 + }
113230 +
113231 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
113232 +
113233 + if (TARGET_64BIT == 0)
113234 + return 0;
113235 +
113236 + for (i = 0; i < argc; ++i) {
113237 + if (!strcmp(argv[i].key, "method")) {
113238 + if (!argv[i].value) {
113239 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
113240 + continue;
113241 + }
113242 + if (!strcmp(argv[i].value, "bts")) {
113243 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
113244 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
113245 + } else if (!strcmp(argv[i].value, "or")) {
113246 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
113247 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
113248 + fix_register("r12", 1, 1);
113249 + } else
113250 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
113251 + continue;
113252 + }
113253 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
113254 + }
113255 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
113256 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
113257 +
113258 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
113259 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
113260 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
113261 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
113262 +
113263 + return 0;
113264 +}
113265 diff --git a/tools/gcc/latent_entropy_plugin.c b/tools/gcc/latent_entropy_plugin.c
113266 new file mode 100644
113267 index 0000000..e48b323
113268 --- /dev/null
113269 +++ b/tools/gcc/latent_entropy_plugin.c
113270 @@ -0,0 +1,466 @@
113271 +/*
113272 + * Copyright 2012-2014 by the PaX Team <pageexec@freemail.hu>
113273 + * Licensed under the GPL v2
113274 + *
113275 + * Note: the choice of the license means that the compilation process is
113276 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
113277 + * but for the kernel it doesn't matter since it doesn't link against
113278 + * any of the gcc libraries
113279 + *
113280 + * gcc plugin to help generate a little bit of entropy from program state,
113281 + * used throughout the uptime of the kernel
113282 + *
113283 + * TODO:
113284 + * - add ipa pass to identify not explicitly marked candidate functions
113285 + * - mix in more program state (function arguments/return values, loop variables, etc)
113286 + * - more instrumentation control via attribute parameters
113287 + *
113288 + * BUGS:
113289 + * - LTO needs -flto-partition=none for now
113290 + */
113291 +
113292 +#include "gcc-common.h"
113293 +
113294 +int plugin_is_GPL_compatible;
113295 +
113296 +static tree latent_entropy_decl;
113297 +
113298 +static struct plugin_info latent_entropy_plugin_info = {
113299 + .version = "201409101820",
113300 + .help = NULL
113301 +};
113302 +
113303 +static unsigned HOST_WIDE_INT seed;
113304 +static unsigned HOST_WIDE_INT get_random_const(void)
113305 +{
113306 + unsigned int i;
113307 + unsigned HOST_WIDE_INT ret = 0;
113308 +
113309 + for (i = 0; i < 8 * sizeof ret; i++) {
113310 + ret = (ret << 1) | (seed & 1);
113311 + seed >>= 1;
113312 + if (ret & 1)
113313 + seed ^= 0xD800000000000000ULL;
113314 + }
113315 +
113316 + return ret;
113317 +}
113318 +
113319 +static tree handle_latent_entropy_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
113320 +{
113321 + tree type;
113322 + unsigned long long mask;
113323 +#if BUILDING_GCC_VERSION <= 4007
113324 + VEC(constructor_elt, gc) *vals;
113325 +#else
113326 + vec<constructor_elt, va_gc> *vals;
113327 +#endif
113328 +
113329 + switch (TREE_CODE(*node)) {
113330 + default:
113331 + *no_add_attrs = true;
113332 + error("%qE attribute only applies to functions and variables", name);
113333 + break;
113334 +
113335 + case VAR_DECL:
113336 + if (DECL_INITIAL(*node)) {
113337 + *no_add_attrs = true;
113338 + error("variable %qD with %qE attribute must not be initialized", *node, name);
113339 + break;
113340 + }
113341 +
113342 + if (!TREE_STATIC(*node)) {
113343 + *no_add_attrs = true;
113344 + error("variable %qD with %qE attribute must not be local", *node, name);
113345 + break;
113346 + }
113347 +
113348 + type = TREE_TYPE(*node);
113349 + switch (TREE_CODE(type)) {
113350 + default:
113351 + *no_add_attrs = true;
113352 + 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);
113353 + break;
113354 +
113355 + case RECORD_TYPE: {
113356 + tree field;
113357 + unsigned int nelt = 0;
113358 +
113359 + for (field = TYPE_FIELDS(type); field; nelt++, field = TREE_CHAIN(field)) {
113360 + tree fieldtype;
113361 +
113362 + fieldtype = TREE_TYPE(field);
113363 + if (TREE_CODE(fieldtype) != INTEGER_TYPE) {
113364 + *no_add_attrs = true;
113365 + error("structure variable %qD with %qE attribute has a non-integer field %qE", *node, name, field);
113366 + break;
113367 + }
113368 + }
113369 +
113370 + if (field)
113371 + break;
113372 +
113373 +#if BUILDING_GCC_VERSION <= 4007
113374 + vals = VEC_alloc(constructor_elt, gc, nelt);
113375 +#else
113376 + vec_alloc(vals, nelt);
113377 +#endif
113378 +
113379 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
113380 + tree fieldtype;
113381 +
113382 + fieldtype = TREE_TYPE(field);
113383 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(fieldtype)) - 1);
113384 + mask = 2 * (mask - 1) + 1;
113385 +
113386 + if (TYPE_UNSIGNED(fieldtype))
113387 + CONSTRUCTOR_APPEND_ELT(vals, field, build_int_cstu(fieldtype, mask & get_random_const()));
113388 + else
113389 + CONSTRUCTOR_APPEND_ELT(vals, field, build_int_cst(fieldtype, mask & get_random_const()));
113390 + }
113391 +
113392 + DECL_INITIAL(*node) = build_constructor(type, vals);
113393 +//debug_tree(DECL_INITIAL(*node));
113394 + break;
113395 + }
113396 +
113397 + case INTEGER_TYPE:
113398 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(type)) - 1);
113399 + mask = 2 * (mask - 1) + 1;
113400 +
113401 + if (TYPE_UNSIGNED(type))
113402 + DECL_INITIAL(*node) = build_int_cstu(type, mask & get_random_const());
113403 + else
113404 + DECL_INITIAL(*node) = build_int_cst(type, mask & get_random_const());
113405 + break;
113406 +
113407 + case ARRAY_TYPE: {
113408 + tree elt_type, array_size, elt_size;
113409 + unsigned int i, nelt;
113410 +
113411 + elt_type = TREE_TYPE(type);
113412 + elt_size = TYPE_SIZE_UNIT(TREE_TYPE(type));
113413 + array_size = TYPE_SIZE_UNIT(type);
113414 +
113415 + if (TREE_CODE(elt_type) != INTEGER_TYPE || !array_size || TREE_CODE(array_size) != INTEGER_CST) {
113416 + *no_add_attrs = true;
113417 + error("array variable %qD with %qE attribute must be a fixed length integer array type", *node, name);
113418 + break;
113419 + }
113420 +
113421 + nelt = TREE_INT_CST_LOW(array_size) / TREE_INT_CST_LOW(elt_size);
113422 +#if BUILDING_GCC_VERSION <= 4007
113423 + vals = VEC_alloc(constructor_elt, gc, nelt);
113424 +#else
113425 + vec_alloc(vals, nelt);
113426 +#endif
113427 +
113428 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(elt_type)) - 1);
113429 + mask = 2 * (mask - 1) + 1;
113430 +
113431 + for (i = 0; i < nelt; i++)
113432 + if (TYPE_UNSIGNED(elt_type))
113433 + CONSTRUCTOR_APPEND_ELT(vals, size_int(i), build_int_cstu(elt_type, mask & get_random_const()));
113434 + else
113435 + CONSTRUCTOR_APPEND_ELT(vals, size_int(i), build_int_cst(elt_type, mask & get_random_const()));
113436 +
113437 + DECL_INITIAL(*node) = build_constructor(type, vals);
113438 +//debug_tree(DECL_INITIAL(*node));
113439 + break;
113440 + }
113441 + }
113442 + break;
113443 +
113444 + case FUNCTION_DECL:
113445 + break;
113446 + }
113447 +
113448 + return NULL_TREE;
113449 +}
113450 +
113451 +static struct attribute_spec latent_entropy_attr = {
113452 + .name = "latent_entropy",
113453 + .min_length = 0,
113454 + .max_length = 0,
113455 + .decl_required = true,
113456 + .type_required = false,
113457 + .function_type_required = false,
113458 + .handler = handle_latent_entropy_attribute,
113459 +#if BUILDING_GCC_VERSION >= 4007
113460 + .affects_type_identity = false
113461 +#endif
113462 +};
113463 +
113464 +static void register_attributes(void *event_data, void *data)
113465 +{
113466 + register_attribute(&latent_entropy_attr);
113467 +}
113468 +
113469 +static bool gate_latent_entropy(void)
113470 +{
113471 + // don't bother with noreturn functions for now
113472 + if (TREE_THIS_VOLATILE(current_function_decl))
113473 + return false;
113474 +
113475 + // gcc-4.5 doesn't discover some trivial noreturn functions
113476 + if (EDGE_COUNT(EXIT_BLOCK_PTR_FOR_FN(cfun)->preds) == 0)
113477 + return false;
113478 +
113479 + return lookup_attribute("latent_entropy", DECL_ATTRIBUTES(current_function_decl)) != NULL_TREE;
113480 +}
113481 +
113482 +static enum tree_code get_op(tree *rhs)
113483 +{
113484 + static enum tree_code op;
113485 + unsigned HOST_WIDE_INT random_const;
113486 +
113487 + random_const = get_random_const();
113488 +
113489 + switch (op) {
113490 + case BIT_XOR_EXPR:
113491 + op = PLUS_EXPR;
113492 + break;
113493 +
113494 + case PLUS_EXPR:
113495 + if (rhs) {
113496 + op = LROTATE_EXPR;
113497 + random_const &= HOST_BITS_PER_WIDE_INT - 1;
113498 + break;
113499 + }
113500 +
113501 + case LROTATE_EXPR:
113502 + default:
113503 + op = BIT_XOR_EXPR;
113504 + break;
113505 + }
113506 + if (rhs)
113507 + *rhs = build_int_cstu(unsigned_intDI_type_node, random_const);
113508 + return op;
113509 +}
113510 +
113511 +static void perturb_local_entropy(basic_block bb, tree local_entropy)
113512 +{
113513 + gimple_stmt_iterator gsi;
113514 + gimple assign;
113515 + tree addxorrol, rhs;
113516 + enum tree_code op;
113517 +
113518 + op = get_op(&rhs);
113519 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, op, unsigned_intDI_type_node, local_entropy, rhs);
113520 + assign = gimple_build_assign(local_entropy, addxorrol);
113521 + gsi = gsi_after_labels(bb);
113522 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
113523 + update_stmt(assign);
113524 +//debug_bb(bb);
113525 +}
113526 +
113527 +static void perturb_latent_entropy(basic_block bb, tree rhs)
113528 +{
113529 + gimple_stmt_iterator gsi;
113530 + gimple assign;
113531 + tree addxorrol, temp;
113532 +
113533 + // 1. create temporary copy of latent_entropy
113534 + temp = create_tmp_var(unsigned_intDI_type_node, "temp_latent_entropy");
113535 + add_referenced_var(temp);
113536 +
113537 + // 2. read...
113538 + temp = make_ssa_name(temp, NULL);
113539 + assign = gimple_build_assign(temp, latent_entropy_decl);
113540 + SSA_NAME_DEF_STMT(temp) = assign;
113541 + add_referenced_var(latent_entropy_decl);
113542 + gsi = gsi_after_labels(bb);
113543 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
113544 + update_stmt(assign);
113545 +
113546 + // 3. ...modify...
113547 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, get_op(NULL), unsigned_intDI_type_node, temp, rhs);
113548 + temp = make_ssa_name(SSA_NAME_VAR(temp), NULL);
113549 + assign = gimple_build_assign(temp, addxorrol);
113550 + SSA_NAME_DEF_STMT(temp) = assign;
113551 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
113552 + update_stmt(assign);
113553 +
113554 + // 4. ...write latent_entropy
113555 + assign = gimple_build_assign(latent_entropy_decl, temp);
113556 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
113557 + update_stmt(assign);
113558 +}
113559 +
113560 +static unsigned int execute_latent_entropy(void)
113561 +{
113562 + basic_block bb;
113563 + gimple assign;
113564 + gimple_stmt_iterator gsi;
113565 + tree local_entropy;
113566 +
113567 + if (!latent_entropy_decl) {
113568 +#if BUILDING_GCC_VERSION >= 4009
113569 + varpool_node *node;
113570 +#else
113571 + struct varpool_node *node;
113572 +#endif
113573 +
113574 + FOR_EACH_VARIABLE(node) {
113575 + tree var = NODE_DECL(node);
113576 +
113577 + if (strcmp(IDENTIFIER_POINTER(DECL_NAME(var)), "latent_entropy"))
113578 + continue;
113579 + latent_entropy_decl = var;
113580 +// debug_tree(var);
113581 + break;
113582 + }
113583 + if (!latent_entropy_decl) {
113584 +// debug_tree(current_function_decl);
113585 + return 0;
113586 + }
113587 + }
113588 +
113589 +//fprintf(stderr, "latent_entropy: %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
113590 +
113591 + // 1. create local entropy variable
113592 + local_entropy = create_tmp_var(unsigned_intDI_type_node, "local_entropy");
113593 + add_referenced_var(local_entropy);
113594 + mark_sym_for_renaming(local_entropy);
113595 +
113596 + // 2. initialize local entropy variable
113597 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
113598 + if (dom_info_available_p(CDI_DOMINATORS))
113599 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
113600 + gsi = gsi_start_bb(bb);
113601 +
113602 + assign = gimple_build_assign(local_entropy, build_int_cstu(unsigned_intDI_type_node, get_random_const()));
113603 +// gimple_set_location(assign, loc);
113604 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
113605 + update_stmt(assign);
113606 +//debug_bb(bb);
113607 + gcc_assert(single_succ_p(bb));
113608 + bb = single_succ(bb);
113609 +
113610 + // 3. instrument each BB with an operation on the local entropy variable
113611 + while (bb != EXIT_BLOCK_PTR_FOR_FN(cfun)) {
113612 + perturb_local_entropy(bb, local_entropy);
113613 +//debug_bb(bb);
113614 + bb = bb->next_bb;
113615 + };
113616 +
113617 + // 4. mix local entropy into the global entropy variable
113618 + gcc_assert(single_pred_p(EXIT_BLOCK_PTR_FOR_FN(cfun)));
113619 + perturb_latent_entropy(single_pred(EXIT_BLOCK_PTR_FOR_FN(cfun)), local_entropy);
113620 +//debug_bb(single_pred(EXIT_BLOCK_PTR_FOR_FN(cfun)));
113621 + return 0;
113622 +}
113623 +
113624 +static void latent_entropy_start_unit(void *gcc_data, void *user_data)
113625 +{
113626 + tree latent_entropy_type;
113627 +
113628 + seed = get_random_seed(false);
113629 +
113630 + if (in_lto_p)
113631 + return;
113632 +
113633 + // extern volatile u64 latent_entropy
113634 + gcc_assert(TYPE_PRECISION(long_long_unsigned_type_node) == 64);
113635 + latent_entropy_type = build_qualified_type(long_long_unsigned_type_node, TYPE_QUALS(long_long_unsigned_type_node) | TYPE_QUAL_VOLATILE);
113636 + latent_entropy_decl = build_decl(UNKNOWN_LOCATION, VAR_DECL, get_identifier("latent_entropy"), latent_entropy_type);
113637 +
113638 + TREE_STATIC(latent_entropy_decl) = 1;
113639 + TREE_PUBLIC(latent_entropy_decl) = 1;
113640 + TREE_USED(latent_entropy_decl) = 1;
113641 + TREE_THIS_VOLATILE(latent_entropy_decl) = 1;
113642 + DECL_EXTERNAL(latent_entropy_decl) = 1;
113643 + DECL_ARTIFICIAL(latent_entropy_decl) = 1;
113644 + lang_hooks.decls.pushdecl(latent_entropy_decl);
113645 +// DECL_ASSEMBLER_NAME(latent_entropy_decl);
113646 +// varpool_finalize_decl(latent_entropy_decl);
113647 +// varpool_mark_needed_node(latent_entropy_decl);
113648 +}
113649 +
113650 +#if BUILDING_GCC_VERSION >= 4009
113651 +static const struct pass_data latent_entropy_pass_data = {
113652 +#else
113653 +static struct gimple_opt_pass latent_entropy_pass = {
113654 + .pass = {
113655 +#endif
113656 + .type = GIMPLE_PASS,
113657 + .name = "latent_entropy",
113658 +#if BUILDING_GCC_VERSION >= 4008
113659 + .optinfo_flags = OPTGROUP_NONE,
113660 +#endif
113661 +#if BUILDING_GCC_VERSION >= 4009
113662 + .has_gate = true,
113663 + .has_execute = true,
113664 +#else
113665 + .gate = gate_latent_entropy,
113666 + .execute = execute_latent_entropy,
113667 + .sub = NULL,
113668 + .next = NULL,
113669 + .static_pass_number = 0,
113670 +#endif
113671 + .tv_id = TV_NONE,
113672 + .properties_required = PROP_gimple_leh | PROP_cfg,
113673 + .properties_provided = 0,
113674 + .properties_destroyed = 0,
113675 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
113676 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
113677 +#if BUILDING_GCC_VERSION < 4009
113678 + }
113679 +#endif
113680 +};
113681 +
113682 +#if BUILDING_GCC_VERSION >= 4009
113683 +namespace {
113684 +class latent_entropy_pass : public gimple_opt_pass {
113685 +public:
113686 + latent_entropy_pass() : gimple_opt_pass(latent_entropy_pass_data, g) {}
113687 + bool gate() { return gate_latent_entropy(); }
113688 + unsigned int execute() { return execute_latent_entropy(); }
113689 +};
113690 +}
113691 +
113692 +static opt_pass *make_latent_entropy_pass(void)
113693 +{
113694 + return new latent_entropy_pass();
113695 +}
113696 +#else
113697 +static struct opt_pass *make_latent_entropy_pass(void)
113698 +{
113699 + return &latent_entropy_pass.pass;
113700 +}
113701 +#endif
113702 +
113703 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
113704 +{
113705 + const char * const plugin_name = plugin_info->base_name;
113706 + struct register_pass_info latent_entropy_pass_info;
113707 +
113708 + latent_entropy_pass_info.pass = make_latent_entropy_pass();
113709 + latent_entropy_pass_info.reference_pass_name = "optimized";
113710 + latent_entropy_pass_info.ref_pass_instance_number = 1;
113711 + latent_entropy_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
113712 + static const struct ggc_root_tab gt_ggc_r_gt_latent_entropy[] = {
113713 + {
113714 + .base = &latent_entropy_decl,
113715 + .nelt = 1,
113716 + .stride = sizeof(latent_entropy_decl),
113717 + .cb = &gt_ggc_mx_tree_node,
113718 + .pchw = &gt_pch_nx_tree_node
113719 + },
113720 + LAST_GGC_ROOT_TAB
113721 + };
113722 +
113723 + if (!plugin_default_version_check(version, &gcc_version)) {
113724 + error(G_("incompatible gcc/plugin versions"));
113725 + return 1;
113726 + }
113727 +
113728 + register_callback(plugin_name, PLUGIN_INFO, NULL, &latent_entropy_plugin_info);
113729 + register_callback(plugin_name, PLUGIN_START_UNIT, &latent_entropy_start_unit, NULL);
113730 + if (!in_lto_p)
113731 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_latent_entropy);
113732 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &latent_entropy_pass_info);
113733 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
113734 +
113735 + return 0;
113736 +}
113737 diff --git a/tools/gcc/randomize_layout_plugin.c b/tools/gcc/randomize_layout_plugin.c
113738 new file mode 100644
113739 index 0000000..a5cb46b
113740 --- /dev/null
113741 +++ b/tools/gcc/randomize_layout_plugin.c
113742 @@ -0,0 +1,915 @@
113743 +/*
113744 + * Copyright 2014 by Open Source Security, Inc., Brad Spengler <spender@grsecurity.net>
113745 + * and PaX Team <pageexec@freemail.hu>
113746 + * Licensed under the GPL v2
113747 + *
113748 + * Usage:
113749 + * $ # for 4.5/4.6/C based 4.7
113750 + * $ 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
113751 + * $ # for C++ based 4.7/4.8+
113752 + * $ 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
113753 + * $ gcc -fplugin=./randomize_layout_plugin.so test.c -O2
113754 + */
113755 +
113756 +#include "gcc-common.h"
113757 +#include "randomize_layout_seed.h"
113758 +
113759 +#if BUILDING_GCC_MAJOR < 4 || BUILDING_GCC_MINOR < 6 || (BUILDING_GCC_MINOR == 6 && BUILDING_GCC_PATCHLEVEL < 4)
113760 +#error "The RANDSTRUCT plugin requires GCC 4.6.4 or newer."
113761 +#endif
113762 +
113763 +#define ORIG_TYPE_NAME(node) \
113764 + (TYPE_NAME(TYPE_MAIN_VARIANT(node)) != NULL_TREE ? ((const unsigned char *)IDENTIFIER_POINTER(TYPE_NAME(TYPE_MAIN_VARIANT(node)))) : (const unsigned char *)"anonymous")
113765 +
113766 +int plugin_is_GPL_compatible;
113767 +
113768 +static int performance_mode;
113769 +
113770 +static struct plugin_info randomize_layout_plugin_info = {
113771 + .version = "201402201816",
113772 + .help = "disable\t\t\tdo not activate plugin\n"
113773 + "performance-mode\tenable cacheline-aware layout randomization\n"
113774 +};
113775 +
113776 +/* from old Linux dcache.h */
113777 +static inline unsigned long
113778 +partial_name_hash(unsigned long c, unsigned long prevhash)
113779 +{
113780 + return (prevhash + (c << 4) + (c >> 4)) * 11;
113781 +}
113782 +static inline unsigned int
113783 +name_hash(const unsigned char *name)
113784 +{
113785 + unsigned long hash = 0;
113786 + unsigned int len = strlen((const char *)name);
113787 + while (len--)
113788 + hash = partial_name_hash(*name++, hash);
113789 + return (unsigned int)hash;
113790 +}
113791 +
113792 +static tree handle_randomize_layout_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
113793 +{
113794 + tree type;
113795 +
113796 + *no_add_attrs = true;
113797 + if (TREE_CODE(*node) == FUNCTION_DECL) {
113798 + error("%qE attribute does not apply to functions (%qF)", name, *node);
113799 + return NULL_TREE;
113800 + }
113801 +
113802 + if (TREE_CODE(*node) == PARM_DECL) {
113803 + error("%qE attribute does not apply to function parameters (%qD)", name, *node);
113804 + return NULL_TREE;
113805 + }
113806 +
113807 + if (TREE_CODE(*node) == VAR_DECL) {
113808 + error("%qE attribute does not apply to variables (%qD)", name, *node);
113809 + return NULL_TREE;
113810 + }
113811 +
113812 + if (TYPE_P(*node)) {
113813 + type = *node;
113814 + } else {
113815 + gcc_assert(TREE_CODE(*node) == TYPE_DECL);
113816 + type = TREE_TYPE(*node);
113817 + }
113818 +
113819 + if (TREE_CODE(type) != RECORD_TYPE) {
113820 + error("%qE attribute used on %qT applies to struct types only", name, type);
113821 + return NULL_TREE;
113822 + }
113823 +
113824 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
113825 + error("%qE attribute is already applied to the type %qT", name, type);
113826 + return NULL_TREE;
113827 + }
113828 +
113829 + *no_add_attrs = false;
113830 +
113831 + return NULL_TREE;
113832 +}
113833 +
113834 +/* set on complete types that we don't need to inspect further at all */
113835 +static tree handle_randomize_considered_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
113836 +{
113837 + *no_add_attrs = false;
113838 + return NULL_TREE;
113839 +}
113840 +
113841 +/*
113842 + * set on types that we've performed a shuffle on, to prevent re-shuffling
113843 + * this does not preclude us from inspecting its fields for potential shuffles
113844 + */
113845 +static tree handle_randomize_performed_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
113846 +{
113847 + *no_add_attrs = false;
113848 + return NULL_TREE;
113849 +}
113850 +
113851 +/*
113852 + * 64bit variant of Bob Jenkins' public domain PRNG
113853 + * 256 bits of internal state
113854 + */
113855 +
113856 +typedef unsigned long long u64;
113857 +
113858 +typedef struct ranctx { u64 a; u64 b; u64 c; u64 d; } ranctx;
113859 +
113860 +#define rot(x,k) (((x)<<(k))|((x)>>(64-(k))))
113861 +static u64 ranval(ranctx *x) {
113862 + u64 e = x->a - rot(x->b, 7);
113863 + x->a = x->b ^ rot(x->c, 13);
113864 + x->b = x->c + rot(x->d, 37);
113865 + x->c = x->d + e;
113866 + x->d = e + x->a;
113867 + return x->d;
113868 +}
113869 +
113870 +static void raninit(ranctx *x, u64 *seed) {
113871 + int i;
113872 +
113873 + x->a = seed[0];
113874 + x->b = seed[1];
113875 + x->c = seed[2];
113876 + x->d = seed[3];
113877 +
113878 + for (i=0; i < 30; ++i)
113879 + (void)ranval(x);
113880 +}
113881 +
113882 +static u64 shuffle_seed[4];
113883 +
113884 +struct partition_group {
113885 + tree tree_start;
113886 + unsigned long start;
113887 + unsigned long length;
113888 +};
113889 +
113890 +static void partition_struct(tree *fields, unsigned long length, struct partition_group *size_groups, unsigned long *num_groups)
113891 +{
113892 + unsigned long i;
113893 + unsigned long accum_size = 0;
113894 + unsigned long accum_length = 0;
113895 + unsigned long group_idx = 0;
113896 +
113897 + gcc_assert(length < INT_MAX);
113898 +
113899 + memset(size_groups, 0, sizeof(struct partition_group) * length);
113900 +
113901 + for (i = 0; i < length; i++) {
113902 + if (size_groups[group_idx].tree_start == NULL_TREE) {
113903 + size_groups[group_idx].tree_start = fields[i];
113904 + size_groups[group_idx].start = i;
113905 + accum_length = 0;
113906 + accum_size = 0;
113907 + }
113908 + accum_size += (unsigned long)int_size_in_bytes(TREE_TYPE(fields[i]));
113909 + accum_length++;
113910 + if (accum_size >= 64) {
113911 + size_groups[group_idx].length = accum_length;
113912 + accum_length = 0;
113913 + group_idx++;
113914 + }
113915 + }
113916 +
113917 + if (size_groups[group_idx].tree_start != NULL_TREE &&
113918 + !size_groups[group_idx].length) {
113919 + size_groups[group_idx].length = accum_length;
113920 + group_idx++;
113921 + }
113922 +
113923 + *num_groups = group_idx;
113924 +}
113925 +
113926 +static void performance_shuffle(tree *newtree, unsigned long length, ranctx *prng_state)
113927 +{
113928 + unsigned long i, x;
113929 + struct partition_group size_group[length];
113930 + unsigned long num_groups = 0;
113931 + unsigned long randnum;
113932 +
113933 + partition_struct(newtree, length, (struct partition_group *)&size_group, &num_groups);
113934 + for (i = num_groups - 1; i > 0; i--) {
113935 + struct partition_group tmp;
113936 + randnum = ranval(prng_state) % (i + 1);
113937 + tmp = size_group[i];
113938 + size_group[i] = size_group[randnum];
113939 + size_group[randnum] = tmp;
113940 + }
113941 +
113942 + for (x = 0; x < num_groups; x++) {
113943 + for (i = size_group[x].start + size_group[x].length - 1; i > size_group[x].start; i--) {
113944 + tree tmp;
113945 + if (DECL_BIT_FIELD_TYPE(newtree[i]))
113946 + continue;
113947 + randnum = ranval(prng_state) % (i + 1);
113948 + // we could handle this case differently if desired
113949 + if (DECL_BIT_FIELD_TYPE(newtree[randnum]))
113950 + continue;
113951 + tmp = newtree[i];
113952 + newtree[i] = newtree[randnum];
113953 + newtree[randnum] = tmp;
113954 + }
113955 + }
113956 +}
113957 +
113958 +static void full_shuffle(tree *newtree, unsigned long length, ranctx *prng_state)
113959 +{
113960 + unsigned long i, randnum;
113961 +
113962 + for (i = length - 1; i > 0; i--) {
113963 + tree tmp;
113964 + randnum = ranval(prng_state) % (i + 1);
113965 + tmp = newtree[i];
113966 + newtree[i] = newtree[randnum];
113967 + newtree[randnum] = tmp;
113968 + }
113969 +}
113970 +
113971 +/* modern in-place Fisher-Yates shuffle */
113972 +static void shuffle(const_tree type, tree *newtree, unsigned long length)
113973 +{
113974 + unsigned long i;
113975 + u64 seed[4];
113976 + ranctx prng_state;
113977 + const unsigned char *structname;
113978 +
113979 + if (length == 0)
113980 + return;
113981 +
113982 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
113983 +
113984 + structname = ORIG_TYPE_NAME(type);
113985 +
113986 +#ifdef __DEBUG_PLUGIN
113987 + fprintf(stderr, "Shuffling struct %s %p\n", (const char *)structname, type);
113988 +#ifdef __DEBUG_VERBOSE
113989 + debug_tree((tree)type);
113990 +#endif
113991 +#endif
113992 +
113993 + for (i = 0; i < 4; i++) {
113994 + seed[i] = shuffle_seed[i];
113995 + seed[i] ^= name_hash(structname);
113996 + }
113997 +
113998 + raninit(&prng_state, (u64 *)&seed);
113999 +
114000 + if (performance_mode)
114001 + performance_shuffle(newtree, length, &prng_state);
114002 + else
114003 + full_shuffle(newtree, length, &prng_state);
114004 +}
114005 +
114006 +static bool is_flexible_array(const_tree field)
114007 +{
114008 + const_tree fieldtype;
114009 + const_tree typesize;
114010 + const_tree elemtype;
114011 + const_tree elemsize;
114012 +
114013 + fieldtype = TREE_TYPE(field);
114014 + typesize = TYPE_SIZE(fieldtype);
114015 +
114016 + if (TREE_CODE(fieldtype) != ARRAY_TYPE)
114017 + return false;
114018 +
114019 + elemtype = TREE_TYPE(fieldtype);
114020 + elemsize = TYPE_SIZE(elemtype);
114021 +
114022 + /* size of type is represented in bits */
114023 +
114024 + if (typesize == NULL_TREE && TYPE_DOMAIN(fieldtype) != NULL_TREE &&
114025 + TYPE_MAX_VALUE(TYPE_DOMAIN(fieldtype)) == NULL_TREE)
114026 + return true;
114027 +
114028 + if (typesize != NULL_TREE &&
114029 + (TREE_CONSTANT(typesize) && (!TREE_INT_CST_LOW(typesize) ||
114030 + TREE_INT_CST_LOW(typesize) == TREE_INT_CST_LOW(elemsize))))
114031 + return true;
114032 +
114033 + return false;
114034 +}
114035 +
114036 +static int relayout_struct(tree type)
114037 +{
114038 + unsigned long num_fields = (unsigned long)list_length(TYPE_FIELDS(type));
114039 + unsigned long shuffle_length = num_fields;
114040 + tree field;
114041 + tree newtree[num_fields];
114042 + unsigned long i;
114043 + tree list;
114044 + tree variant;
114045 + expanded_location xloc;
114046 +
114047 + if (TYPE_FIELDS(type) == NULL_TREE)
114048 + return 0;
114049 +
114050 + if (num_fields < 2)
114051 + return 0;
114052 +
114053 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
114054 +
114055 + gcc_assert(num_fields < INT_MAX);
114056 +
114057 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(type)) ||
114058 + lookup_attribute("no_randomize_layout", TYPE_ATTRIBUTES(TYPE_MAIN_VARIANT(type))))
114059 + return 0;
114060 +
114061 + /* Workaround for 3rd-party VirtualBox source that we can't modify ourselves */
114062 + if (!strcmp((const char *)ORIG_TYPE_NAME(type), "INTNETTRUNKFACTORY") ||
114063 + !strcmp((const char *)ORIG_TYPE_NAME(type), "RAWPCIFACTORY"))
114064 + return 0;
114065 +
114066 + /* throw out any structs in uapi */
114067 + xloc = expand_location(DECL_SOURCE_LOCATION(TYPE_FIELDS(type)));
114068 +
114069 + if (strstr(xloc.file, "/uapi/"))
114070 + error(G_("attempted to randomize userland API struct %s"), ORIG_TYPE_NAME(type));
114071 +
114072 + for (field = TYPE_FIELDS(type), i = 0; field; field = TREE_CHAIN(field), i++) {
114073 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
114074 + newtree[i] = field;
114075 + }
114076 +
114077 + /*
114078 + * enforce that we don't randomize the layout of the last
114079 + * element of a struct if it's a 0 or 1-length array
114080 + * or a proper flexible array
114081 + */
114082 + if (is_flexible_array(newtree[num_fields - 1]))
114083 + shuffle_length--;
114084 +
114085 + shuffle(type, (tree *)newtree, shuffle_length);
114086 +
114087 + /*
114088 + * set up a bogus anonymous struct field designed to error out on unnamed struct initializers
114089 + * as gcc provides no other way to detect such code
114090 + */
114091 + list = make_node(FIELD_DECL);
114092 + TREE_CHAIN(list) = newtree[0];
114093 + TREE_TYPE(list) = void_type_node;
114094 + DECL_SIZE(list) = bitsize_zero_node;
114095 + DECL_NONADDRESSABLE_P(list) = 1;
114096 + DECL_FIELD_BIT_OFFSET(list) = bitsize_zero_node;
114097 + DECL_SIZE_UNIT(list) = size_zero_node;
114098 + DECL_FIELD_OFFSET(list) = size_zero_node;
114099 + // to satisfy the constify plugin
114100 + TREE_READONLY(list) = 1;
114101 +
114102 + for (i = 0; i < num_fields - 1; i++)
114103 + TREE_CHAIN(newtree[i]) = newtree[i+1];
114104 + TREE_CHAIN(newtree[num_fields - 1]) = NULL_TREE;
114105 +
114106 + for (variant = TYPE_MAIN_VARIANT(type); variant; variant = TYPE_NEXT_VARIANT(variant)) {
114107 + TYPE_FIELDS(variant) = list;
114108 + TYPE_ATTRIBUTES(variant) = copy_list(TYPE_ATTRIBUTES(variant));
114109 + TYPE_ATTRIBUTES(variant) = tree_cons(get_identifier("randomize_performed"), NULL_TREE, TYPE_ATTRIBUTES(variant));
114110 + // force a re-layout
114111 + TYPE_SIZE(variant) = NULL_TREE;
114112 + layout_type(variant);
114113 + }
114114 +
114115 + return 1;
114116 +}
114117 +
114118 +/* from constify plugin */
114119 +static const_tree get_field_type(const_tree field)
114120 +{
114121 + return strip_array_types(TREE_TYPE(field));
114122 +}
114123 +
114124 +/* from constify plugin */
114125 +static bool is_fptr(const_tree fieldtype)
114126 +{
114127 + if (TREE_CODE(fieldtype) != POINTER_TYPE)
114128 + return false;
114129 +
114130 + return TREE_CODE(TREE_TYPE(fieldtype)) == FUNCTION_TYPE;
114131 +}
114132 +
114133 +/* derived from constify plugin */
114134 +static int is_pure_ops_struct(const_tree node)
114135 +{
114136 + const_tree field;
114137 +
114138 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
114139 +
114140 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
114141 + const_tree fieldtype = get_field_type(field);
114142 + enum tree_code code = TREE_CODE(fieldtype);
114143 +
114144 + if (node == fieldtype)
114145 + continue;
114146 +
114147 + if (!is_fptr(fieldtype))
114148 + return 0;
114149 +
114150 + if (code != RECORD_TYPE && code != UNION_TYPE)
114151 + continue;
114152 +
114153 + if (!is_pure_ops_struct(fieldtype))
114154 + return 0;
114155 + }
114156 +
114157 + return 1;
114158 +}
114159 +
114160 +static void randomize_type(tree type)
114161 +{
114162 + tree variant;
114163 +
114164 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
114165 +
114166 + if (lookup_attribute("randomize_considered", TYPE_ATTRIBUTES(type)))
114167 + return;
114168 +
114169 + if (lookup_attribute("randomize_layout", TYPE_ATTRIBUTES(TYPE_MAIN_VARIANT(type))) || is_pure_ops_struct(type))
114170 + relayout_struct(type);
114171 +
114172 + for (variant = TYPE_MAIN_VARIANT(type); variant; variant = TYPE_NEXT_VARIANT(variant)) {
114173 + TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
114174 + TYPE_ATTRIBUTES(type) = tree_cons(get_identifier("randomize_considered"), NULL_TREE, TYPE_ATTRIBUTES(type));
114175 + }
114176 +#ifdef __DEBUG_PLUGIN
114177 + fprintf(stderr, "Marking randomize_considered on struct %s\n", ORIG_TYPE_NAME(type));
114178 +#ifdef __DEBUG_VERBOSE
114179 + debug_tree(type);
114180 +#endif
114181 +#endif
114182 +}
114183 +
114184 +static void randomize_layout_finish_decl(void *event_data, void *data)
114185 +{
114186 + tree decl = (tree)event_data;
114187 + tree type;
114188 +
114189 + if (decl == NULL_TREE || decl == error_mark_node)
114190 + return;
114191 +
114192 + type = TREE_TYPE(decl);
114193 +
114194 + if (TREE_CODE(decl) != VAR_DECL)
114195 + return;
114196 +
114197 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
114198 + return;
114199 +
114200 + if (!lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(type)))
114201 + return;
114202 +
114203 + relayout_decl(decl);
114204 +}
114205 +
114206 +static void finish_type(void *event_data, void *data)
114207 +{
114208 + tree type = (tree)event_data;
114209 +
114210 + if (type == NULL_TREE || type == error_mark_node)
114211 + return;
114212 +
114213 + if (TREE_CODE(type) != RECORD_TYPE)
114214 + return;
114215 +
114216 + if (TYPE_FIELDS(type) == NULL_TREE)
114217 + return;
114218 +
114219 + if (lookup_attribute("randomize_considered", TYPE_ATTRIBUTES(type)))
114220 + return;
114221 +
114222 +#ifdef __DEBUG_PLUGIN
114223 + fprintf(stderr, "Calling randomize_type on %s\n", ORIG_TYPE_NAME(type));
114224 +#endif
114225 +#ifdef __DEBUG_VERBOSE
114226 + debug_tree(type);
114227 +#endif
114228 + randomize_type(type);
114229 +
114230 + return;
114231 +}
114232 +
114233 +static struct attribute_spec randomize_layout_attr = {
114234 + .name = "randomize_layout",
114235 + // related to args
114236 + .min_length = 0,
114237 + .max_length = 0,
114238 + .decl_required = false,
114239 + // need type declaration
114240 + .type_required = true,
114241 + .function_type_required = false,
114242 + .handler = handle_randomize_layout_attr,
114243 +#if BUILDING_GCC_VERSION >= 4007
114244 + .affects_type_identity = true
114245 +#endif
114246 +};
114247 +
114248 +static struct attribute_spec no_randomize_layout_attr = {
114249 + .name = "no_randomize_layout",
114250 + // related to args
114251 + .min_length = 0,
114252 + .max_length = 0,
114253 + .decl_required = false,
114254 + // need type declaration
114255 + .type_required = true,
114256 + .function_type_required = false,
114257 + .handler = handle_randomize_layout_attr,
114258 +#if BUILDING_GCC_VERSION >= 4007
114259 + .affects_type_identity = true
114260 +#endif
114261 +};
114262 +
114263 +static struct attribute_spec randomize_considered_attr = {
114264 + .name = "randomize_considered",
114265 + // related to args
114266 + .min_length = 0,
114267 + .max_length = 0,
114268 + .decl_required = false,
114269 + // need type declaration
114270 + .type_required = true,
114271 + .function_type_required = false,
114272 + .handler = handle_randomize_considered_attr,
114273 +#if BUILDING_GCC_VERSION >= 4007
114274 + .affects_type_identity = false
114275 +#endif
114276 +};
114277 +
114278 +static struct attribute_spec randomize_performed_attr = {
114279 + .name = "randomize_performed",
114280 + // related to args
114281 + .min_length = 0,
114282 + .max_length = 0,
114283 + .decl_required = false,
114284 + // need type declaration
114285 + .type_required = true,
114286 + .function_type_required = false,
114287 + .handler = handle_randomize_performed_attr,
114288 +#if BUILDING_GCC_VERSION >= 4007
114289 + .affects_type_identity = false
114290 +#endif
114291 +};
114292 +
114293 +static void register_attributes(void *event_data, void *data)
114294 +{
114295 + register_attribute(&randomize_layout_attr);
114296 + register_attribute(&no_randomize_layout_attr);
114297 + register_attribute(&randomize_considered_attr);
114298 + register_attribute(&randomize_performed_attr);
114299 +}
114300 +
114301 +static void check_bad_casts_in_constructor(tree var, tree init)
114302 +{
114303 + unsigned HOST_WIDE_INT idx;
114304 + tree field, val;
114305 + tree field_type, val_type;
114306 +
114307 + FOR_EACH_CONSTRUCTOR_ELT(CONSTRUCTOR_ELTS(init), idx, field, val) {
114308 + if (TREE_CODE(val) == CONSTRUCTOR) {
114309 + check_bad_casts_in_constructor(var, val);
114310 + continue;
114311 + }
114312 +
114313 + /* pipacs' plugin creates franken-arrays that differ from those produced by
114314 + normal code which all have valid 'field' trees. work around this */
114315 + if (field == NULL_TREE)
114316 + continue;
114317 + field_type = TREE_TYPE(field);
114318 + val_type = TREE_TYPE(val);
114319 +
114320 + if (TREE_CODE(field_type) != POINTER_TYPE || TREE_CODE(val_type) != POINTER_TYPE)
114321 + continue;
114322 +
114323 + if (field_type == val_type)
114324 + continue;
114325 +
114326 + field_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(field_type))));
114327 + val_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(val_type))));
114328 +
114329 + if (field_type == void_type_node)
114330 + continue;
114331 + if (field_type == val_type)
114332 + continue;
114333 + if (TREE_CODE(val_type) != RECORD_TYPE)
114334 + continue;
114335 +
114336 + if (!lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(val_type)))
114337 + continue;
114338 + inform(DECL_SOURCE_LOCATION(var), "found mismatched struct pointer types: %qT and %qT\n", TYPE_MAIN_VARIANT(field_type), TYPE_MAIN_VARIANT(val_type));
114339 + }
114340 +}
114341 +
114342 +/* derived from the constify plugin */
114343 +static void check_global_variables(void *event_data, void *data)
114344 +{
114345 + struct varpool_node *node;
114346 + tree init;
114347 +
114348 + FOR_EACH_VARIABLE(node) {
114349 + tree var = NODE_DECL(node);
114350 + init = DECL_INITIAL(var);
114351 + if (init == NULL_TREE)
114352 + continue;
114353 +
114354 + if (TREE_CODE(init) != CONSTRUCTOR)
114355 + continue;
114356 +
114357 + check_bad_casts_in_constructor(var, init);
114358 + }
114359 +}
114360 +
114361 +static bool dominated_by_is_err(const_tree rhs, basic_block bb)
114362 +{
114363 + basic_block dom;
114364 + gimple dom_stmt;
114365 + gimple call_stmt;
114366 + const_tree dom_lhs;
114367 + const_tree poss_is_err_cond;
114368 + const_tree poss_is_err_func;
114369 + const_tree is_err_arg;
114370 +
114371 + dom = get_immediate_dominator(CDI_DOMINATORS, bb);
114372 + if (!dom)
114373 + return false;
114374 +
114375 + dom_stmt = last_stmt(dom);
114376 + if (!dom_stmt)
114377 + return false;
114378 +
114379 + if (gimple_code(dom_stmt) != GIMPLE_COND)
114380 + return false;
114381 +
114382 + if (gimple_cond_code(dom_stmt) != NE_EXPR)
114383 + return false;
114384 +
114385 + if (!integer_zerop(gimple_cond_rhs(dom_stmt)))
114386 + return false;
114387 +
114388 + poss_is_err_cond = gimple_cond_lhs(dom_stmt);
114389 +
114390 + if (TREE_CODE(poss_is_err_cond) != SSA_NAME)
114391 + return false;
114392 +
114393 + call_stmt = SSA_NAME_DEF_STMT(poss_is_err_cond);
114394 +
114395 + if (gimple_code(call_stmt) != GIMPLE_CALL)
114396 + return false;
114397 +
114398 + dom_lhs = gimple_get_lhs(call_stmt);
114399 + poss_is_err_func = gimple_call_fndecl(call_stmt);
114400 + if (!poss_is_err_func)
114401 + return false;
114402 + if (dom_lhs != poss_is_err_cond)
114403 + return false;
114404 + if (strcmp(DECL_NAME_POINTER(poss_is_err_func), "IS_ERR"))
114405 + return false;
114406 +
114407 + is_err_arg = gimple_call_arg(call_stmt, 0);
114408 + if (!is_err_arg)
114409 + return false;
114410 +
114411 + if (is_err_arg != rhs)
114412 + return false;
114413 +
114414 + return true;
114415 +}
114416 +
114417 +static void handle_local_var_initializers(void)
114418 +{
114419 + tree var;
114420 + unsigned int i;
114421 +
114422 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
114423 + tree init = DECL_INITIAL(var);
114424 + if (!init)
114425 + continue;
114426 + if (TREE_CODE(init) != CONSTRUCTOR)
114427 + continue;
114428 + check_bad_casts_in_constructor(var, init);
114429 + }
114430 +}
114431 +
114432 +/*
114433 + * iterate over all statements to find "bad" casts:
114434 + * those where the address of the start of a structure is cast
114435 + * to a pointer of a structure of a different type, or a
114436 + * structure pointer type is cast to a different structure pointer type
114437 + */
114438 +static unsigned int find_bad_casts(void)
114439 +{
114440 + basic_block bb;
114441 +
114442 + handle_local_var_initializers();
114443 +
114444 + FOR_ALL_BB_FN(bb, cfun) {
114445 + gimple_stmt_iterator gsi;
114446 +
114447 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
114448 + gimple stmt;
114449 + const_tree lhs;
114450 + const_tree lhs_type;
114451 + const_tree rhs1;
114452 + const_tree rhs_type;
114453 + const_tree ptr_lhs_type;
114454 + const_tree ptr_rhs_type;
114455 + const_tree op0;
114456 + const_tree op0_type;
114457 + enum tree_code rhs_code;
114458 +
114459 + stmt = gsi_stmt(gsi);
114460 +
114461 +#ifdef __DEBUG_PLUGIN
114462 +#ifdef __DEBUG_VERBOSE
114463 + debug_gimple_stmt(stmt);
114464 + debug_tree(gimple_get_lhs(stmt));
114465 +#endif
114466 +#endif
114467 +
114468 + if (gimple_code(stmt) != GIMPLE_ASSIGN)
114469 + continue;
114470 +
114471 +#ifdef __DEBUG_PLUGIN
114472 +#ifdef __DEBUG_VERBOSE
114473 + debug_tree(gimple_assign_rhs1(stmt));
114474 +#endif
114475 +#endif
114476 +
114477 + rhs_code = gimple_assign_rhs_code(stmt);
114478 +
114479 + if (rhs_code != ADDR_EXPR && rhs_code != SSA_NAME)
114480 + continue;
114481 +
114482 + lhs = gimple_get_lhs(stmt);
114483 + lhs_type = TREE_TYPE(lhs);
114484 + rhs1 = gimple_assign_rhs1(stmt);
114485 + rhs_type = TREE_TYPE(rhs1);
114486 +
114487 + if (TREE_CODE(rhs_type) != POINTER_TYPE ||
114488 + TREE_CODE(lhs_type) != POINTER_TYPE)
114489 + continue;
114490 +
114491 + ptr_lhs_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(lhs_type))));
114492 + ptr_rhs_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(rhs_type))));
114493 +
114494 + if (ptr_rhs_type == void_type_node)
114495 + continue;
114496 +
114497 + if (ptr_lhs_type == void_type_node)
114498 + continue;
114499 +
114500 + if (dominated_by_is_err(rhs1, bb))
114501 + continue;
114502 +
114503 + if (TREE_CODE(ptr_rhs_type) != RECORD_TYPE) {
114504 +#ifndef __DEBUG_PLUGIN
114505 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(ptr_lhs_type)))
114506 +#endif
114507 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, ptr_rhs_type);
114508 + continue;
114509 + }
114510 +
114511 + if (rhs_code == SSA_NAME && ptr_lhs_type == ptr_rhs_type)
114512 + continue;
114513 +
114514 + if (rhs_code == ADDR_EXPR) {
114515 + op0 = TREE_OPERAND(rhs1, 0);
114516 +
114517 + if (op0 == NULL_TREE)
114518 + continue;
114519 +
114520 + if (TREE_CODE(op0) != VAR_DECL)
114521 + continue;
114522 +
114523 + op0_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(op0))));
114524 + if (op0_type == ptr_lhs_type)
114525 + continue;
114526 +
114527 +#ifndef __DEBUG_PLUGIN
114528 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(op0_type)))
114529 +#endif
114530 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, op0_type);
114531 + } else {
114532 + const_tree ssa_name_var = SSA_NAME_VAR(rhs1);
114533 + /* skip bogus type casts introduced by container_of */
114534 + if (ssa_name_var != NULL_TREE && DECL_NAME(ssa_name_var) &&
114535 + !strcmp((const char *)DECL_NAME_POINTER(ssa_name_var), "__mptr"))
114536 + continue;
114537 +#ifndef __DEBUG_PLUGIN
114538 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(ptr_rhs_type)))
114539 +#endif
114540 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, ptr_rhs_type);
114541 + }
114542 +
114543 + }
114544 + }
114545 + return 0;
114546 +}
114547 +
114548 +#if BUILDING_GCC_VERSION >= 4009
114549 +static const struct pass_data randomize_layout_bad_cast_data = {
114550 +#else
114551 +static struct gimple_opt_pass randomize_layout_bad_cast = {
114552 + .pass = {
114553 +#endif
114554 + .type = GIMPLE_PASS,
114555 + .name = "randomize_layout_bad_cast",
114556 +#if BUILDING_GCC_VERSION >= 4008
114557 + .optinfo_flags = OPTGROUP_NONE,
114558 +#endif
114559 +#if BUILDING_GCC_VERSION >= 4009
114560 + .has_gate = false,
114561 + .has_execute = true,
114562 +#else
114563 + .gate = NULL,
114564 + .execute = find_bad_casts,
114565 + .sub = NULL,
114566 + .next = NULL,
114567 + .static_pass_number = 0,
114568 +#endif
114569 + .tv_id = TV_NONE,
114570 + .properties_required = PROP_cfg,
114571 + .properties_provided = 0,
114572 + .properties_destroyed = 0,
114573 + .todo_flags_start = 0,
114574 + .todo_flags_finish = TODO_dump_func
114575 +#if BUILDING_GCC_VERSION < 4009
114576 + }
114577 +#endif
114578 +};
114579 +
114580 +#if BUILDING_GCC_VERSION >= 4009
114581 +namespace {
114582 +class randomize_layout_bad_cast : public gimple_opt_pass {
114583 +public:
114584 + randomize_layout_bad_cast() : gimple_opt_pass(randomize_layout_bad_cast_data, g) {}
114585 + unsigned int execute() { return find_bad_casts(); }
114586 +};
114587 +}
114588 +#endif
114589 +
114590 +static struct opt_pass *make_randomize_layout_bad_cast(void)
114591 +{
114592 +#if BUILDING_GCC_VERSION >= 4009
114593 + return new randomize_layout_bad_cast();
114594 +#else
114595 + return &randomize_layout_bad_cast.pass;
114596 +#endif
114597 +}
114598 +
114599 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
114600 +{
114601 + int i;
114602 + const char * const plugin_name = plugin_info->base_name;
114603 + const int argc = plugin_info->argc;
114604 + const struct plugin_argument * const argv = plugin_info->argv;
114605 + bool enable = true;
114606 + int obtained_seed = 0;
114607 + struct register_pass_info randomize_layout_bad_cast_info;
114608 +
114609 + randomize_layout_bad_cast_info.pass = make_randomize_layout_bad_cast();
114610 + randomize_layout_bad_cast_info.reference_pass_name = "ssa";
114611 + randomize_layout_bad_cast_info.ref_pass_instance_number = 1;
114612 + randomize_layout_bad_cast_info.pos_op = PASS_POS_INSERT_AFTER;
114613 +
114614 + if (!plugin_default_version_check(version, &gcc_version)) {
114615 + error(G_("incompatible gcc/plugin versions"));
114616 + return 1;
114617 + }
114618 +
114619 + if (strcmp(lang_hooks.name, "GNU C")) {
114620 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
114621 + enable = false;
114622 + }
114623 +
114624 + for (i = 0; i < argc; ++i) {
114625 + if (!strcmp(argv[i].key, "disable")) {
114626 + enable = false;
114627 + continue;
114628 + }
114629 + if (!strcmp(argv[i].key, "performance-mode")) {
114630 + performance_mode = 1;
114631 + continue;
114632 + }
114633 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
114634 + }
114635 +
114636 + if (strlen(randstruct_seed) != 64) {
114637 + error(G_("invalid seed value supplied for %s plugin"), plugin_name);
114638 + return 1;
114639 + }
114640 + obtained_seed = sscanf(randstruct_seed, "%016llx%016llx%016llx%016llx",
114641 + &shuffle_seed[0], &shuffle_seed[1], &shuffle_seed[2], &shuffle_seed[3]);
114642 + if (obtained_seed != 4) {
114643 + error(G_("Invalid seed supplied for %s plugin"), plugin_name);
114644 + return 1;
114645 + }
114646 +
114647 + register_callback(plugin_name, PLUGIN_INFO, NULL, &randomize_layout_plugin_info);
114648 + if (enable) {
114649 + register_callback(plugin_name, PLUGIN_ALL_IPA_PASSES_START, check_global_variables, NULL);
114650 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &randomize_layout_bad_cast_info);
114651 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
114652 + register_callback(plugin_name, PLUGIN_FINISH_DECL, randomize_layout_finish_decl, NULL);
114653 + }
114654 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
114655 +
114656 + return 0;
114657 +}
114658 diff --git a/tools/gcc/size_overflow_plugin/.gitignore b/tools/gcc/size_overflow_plugin/.gitignore
114659 new file mode 100644
114660 index 0000000..1f0214f
114661 --- /dev/null
114662 +++ b/tools/gcc/size_overflow_plugin/.gitignore
114663 @@ -0,0 +1,3 @@
114664 +randomize_layout_seed.h
114665 +size_overflow_hash.h
114666 +size_overflow_hash_aux.h
114667 diff --git a/tools/gcc/size_overflow_plugin/Makefile b/tools/gcc/size_overflow_plugin/Makefile
114668 new file mode 100644
114669 index 0000000..1ae2ed5
114670 --- /dev/null
114671 +++ b/tools/gcc/size_overflow_plugin/Makefile
114672 @@ -0,0 +1,20 @@
114673 +$(HOSTLIBS)-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
114674 +always := $($(HOSTLIBS)-y)
114675 +
114676 +size_overflow_plugin-objs := $(patsubst $(srctree)/$(src)/%.c,%.o,$(wildcard $(srctree)/$(src)/*.c))
114677 +
114678 +$(patsubst $(srctree)/$(src)/%.c,$(obj)/%.o,$(wildcard $(srctree)/$(src)/*.c)): $(objtree)/$(obj)/size_overflow_hash.h $(objtree)/$(obj)/size_overflow_hash_aux.h
114679 +
114680 +quiet_cmd_build_size_overflow_hash = GENHASH $@
114681 + cmd_build_size_overflow_hash = \
114682 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -s size_overflow_hash -d $< -o $@
114683 +$(objtree)/$(obj)/size_overflow_hash.h: $(src)/size_overflow_hash.data FORCE
114684 + $(call if_changed,build_size_overflow_hash)
114685 +
114686 +quiet_cmd_build_size_overflow_hash_aux = GENHASH $@
114687 + cmd_build_size_overflow_hash_aux = \
114688 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -s size_overflow_hash_aux -d $< -o $@
114689 +$(objtree)/$(obj)/size_overflow_hash_aux.h: $(src)/size_overflow_hash_aux.data FORCE
114690 + $(call if_changed,build_size_overflow_hash_aux)
114691 +
114692 +targets += size_overflow_hash.h size_overflow_hash_aux.h
114693 diff --git a/tools/gcc/size_overflow_plugin/generate_size_overflow_hash.sh b/tools/gcc/size_overflow_plugin/generate_size_overflow_hash.sh
114694 new file mode 100644
114695 index 0000000..12b1e3b
114696 --- /dev/null
114697 +++ b/tools/gcc/size_overflow_plugin/generate_size_overflow_hash.sh
114698 @@ -0,0 +1,102 @@
114699 +#!/bin/bash
114700 +
114701 +# This script generates the hash table (size_overflow_hash.h) for the size_overflow gcc plugin (size_overflow_plugin.c).
114702 +
114703 +header1="size_overflow_hash.h"
114704 +database="size_overflow_hash.data"
114705 +n=65536
114706 +hashtable_name="size_overflow_hash"
114707 +
114708 +usage() {
114709 +cat <<EOF
114710 +usage: $0 options
114711 +OPTIONS:
114712 + -h|--help help
114713 + -o header file
114714 + -d database file
114715 + -n hash array size
114716 + -s name of the hash table
114717 +EOF
114718 + return 0
114719 +}
114720 +
114721 +while true
114722 +do
114723 + case "$1" in
114724 + -h|--help) usage && exit 0;;
114725 + -n) n=$2; shift 2;;
114726 + -o) header1="$2"; shift 2;;
114727 + -d) database="$2"; shift 2;;
114728 + -s) hashtable_name="$2"; shift 2;;
114729 + --) shift 1; break ;;
114730 + *) break ;;
114731 + esac
114732 +done
114733 +
114734 +create_defines() {
114735 + for i in `seq 0 31`
114736 + do
114737 + echo -e "#define PARAM"$i" (1U << "$i")" >> "$header1"
114738 + done
114739 + echo >> "$header1"
114740 +}
114741 +
114742 +create_structs() {
114743 + rm -f "$header1"
114744 +
114745 + create_defines
114746 +
114747 + cat "$database" | while read data
114748 + do
114749 + data_array=($data)
114750 + struct_hash_name="${data_array[0]}"
114751 + funcn="${data_array[1]}"
114752 + params="${data_array[2]}"
114753 + next="${data_array[4]}"
114754 +
114755 + echo "const struct size_overflow_hash $struct_hash_name = {" >> "$header1"
114756 +
114757 + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
114758 + echo -en "\t.param\t= " >> "$header1"
114759 + line=
114760 + for param_num in ${params//-/ };
114761 + do
114762 + line="${line}PARAM"$param_num"|"
114763 + done
114764 +
114765 + echo -e "${line%?},\n};\n" >> "$header1"
114766 + done
114767 +}
114768 +
114769 +create_headers() {
114770 + echo "const struct size_overflow_hash * const $hashtable_name[$n] = {" >> "$header1"
114771 +}
114772 +
114773 +create_array_elements() {
114774 + index=0
114775 + grep -v "nohasharray" $database | sort -n -k 4 | while read data
114776 + do
114777 + data_array=($data)
114778 + i="${data_array[3]}"
114779 + hash="${data_array[0]}"
114780 + while [[ $index -lt $i ]]
114781 + do
114782 + echo -e "\t["$index"]\t= NULL," >> "$header1"
114783 + index=$(($index + 1))
114784 + done
114785 + index=$(($index + 1))
114786 + echo -e "\t["$i"]\t= &"$hash"," >> "$header1"
114787 + done
114788 + echo '};' >> $header1
114789 +}
114790 +
114791 +size_overflow_plugin_dir=`dirname $header1`
114792 +if [ "$size_overflow_plugin_dir" != '.' ]; then
114793 + mkdir -p "$size_overflow_plugin_dir" 2> /dev/null
114794 +fi
114795 +
114796 +create_structs
114797 +create_headers
114798 +create_array_elements
114799 +
114800 +exit 0
114801 diff --git a/tools/gcc/size_overflow_plugin/insert_size_overflow_asm.c b/tools/gcc/size_overflow_plugin/insert_size_overflow_asm.c
114802 new file mode 100644
114803 index 0000000..c43901f
114804 --- /dev/null
114805 +++ b/tools/gcc/size_overflow_plugin/insert_size_overflow_asm.c
114806 @@ -0,0 +1,748 @@
114807 +/*
114808 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
114809 + * Licensed under the GPL v2, or (at your option) v3
114810 + *
114811 + * Homepage:
114812 + * http://www.grsecurity.net/~ephox/overflow_plugin/
114813 + *
114814 + * Documentation:
114815 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
114816 + *
114817 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
114818 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
114819 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
114820 + *
114821 + * Usage:
114822 + * $ make
114823 + * $ make run
114824 + */
114825 +
114826 +#include "gcc-common.h"
114827 +#include "size_overflow.h"
114828 +
114829 +static void search_size_overflow_attribute(struct pointer_set_t *visited, tree lhs);
114830 +static enum mark search_intentional(struct pointer_set_t *visited, const_tree lhs);
114831 +
114832 +// data for the size_overflow asm stmt
114833 +struct asm_data {
114834 + gimple def_stmt;
114835 + tree input;
114836 + tree output;
114837 +};
114838 +
114839 +#if BUILDING_GCC_VERSION <= 4007
114840 +static VEC(tree, gc) *create_asm_io_list(tree string, tree io)
114841 +#else
114842 +static vec<tree, va_gc> *create_asm_io_list(tree string, tree io)
114843 +#endif
114844 +{
114845 + tree list;
114846 +#if BUILDING_GCC_VERSION <= 4007
114847 + VEC(tree, gc) *vec_list = NULL;
114848 +#else
114849 + vec<tree, va_gc> *vec_list = NULL;
114850 +#endif
114851 +
114852 + list = build_tree_list(NULL_TREE, string);
114853 + list = chainon(NULL_TREE, build_tree_list(list, io));
114854 +#if BUILDING_GCC_VERSION <= 4007
114855 + VEC_safe_push(tree, gc, vec_list, list);
114856 +#else
114857 + vec_safe_push(vec_list, list);
114858 +#endif
114859 + return vec_list;
114860 +}
114861 +
114862 +static void create_asm_stmt(const char *str, tree str_input, tree str_output, struct asm_data *asm_data)
114863 +{
114864 + gimple asm_stmt;
114865 + gimple_stmt_iterator gsi;
114866 +#if BUILDING_GCC_VERSION <= 4007
114867 + VEC(tree, gc) *input, *output = NULL;
114868 +#else
114869 + vec<tree, va_gc> *input, *output = NULL;
114870 +#endif
114871 +
114872 + input = create_asm_io_list(str_input, asm_data->input);
114873 +
114874 + if (asm_data->output)
114875 + output = create_asm_io_list(str_output, asm_data->output);
114876 +
114877 + asm_stmt = gimple_build_asm_vec(str, input, output, NULL, NULL);
114878 + gsi = gsi_for_stmt(asm_data->def_stmt);
114879 + gsi_insert_after(&gsi, asm_stmt, GSI_NEW_STMT);
114880 +
114881 + if (asm_data->output)
114882 + SSA_NAME_DEF_STMT(asm_data->output) = asm_stmt;
114883 +}
114884 +
114885 +static void replace_call_lhs(const struct asm_data *asm_data)
114886 +{
114887 + gimple_set_lhs(asm_data->def_stmt, asm_data->input);
114888 + update_stmt(asm_data->def_stmt);
114889 + SSA_NAME_DEF_STMT(asm_data->input) = asm_data->def_stmt;
114890 +}
114891 +
114892 +static enum mark search_intentional_phi(struct pointer_set_t *visited, const_tree result)
114893 +{
114894 + enum mark cur_fndecl_attr;
114895 + gimple phi = get_def_stmt(result);
114896 + unsigned int i, n = gimple_phi_num_args(phi);
114897 +
114898 + pointer_set_insert(visited, phi);
114899 + for (i = 0; i < n; i++) {
114900 + tree arg = gimple_phi_arg_def(phi, i);
114901 +
114902 + cur_fndecl_attr = search_intentional(visited, arg);
114903 + if (cur_fndecl_attr != MARK_NO)
114904 + return cur_fndecl_attr;
114905 + }
114906 + return MARK_NO;
114907 +}
114908 +
114909 +static enum mark search_intentional_binary(struct pointer_set_t *visited, const_tree lhs)
114910 +{
114911 + enum mark cur_fndecl_attr;
114912 + const_tree rhs1, rhs2;
114913 + gimple def_stmt = get_def_stmt(lhs);
114914 +
114915 + rhs1 = gimple_assign_rhs1(def_stmt);
114916 + rhs2 = gimple_assign_rhs2(def_stmt);
114917 +
114918 + cur_fndecl_attr = search_intentional(visited, rhs1);
114919 + if (cur_fndecl_attr != MARK_NO)
114920 + return cur_fndecl_attr;
114921 + return search_intentional(visited, rhs2);
114922 +}
114923 +
114924 +// Look up the intentional_overflow attribute on the caller and the callee functions.
114925 +static enum mark search_intentional(struct pointer_set_t *visited, const_tree lhs)
114926 +{
114927 + const_gimple def_stmt;
114928 +
114929 + if (TREE_CODE(lhs) != SSA_NAME)
114930 + return get_intentional_attr_type(lhs);
114931 +
114932 + def_stmt = get_def_stmt(lhs);
114933 + if (!def_stmt)
114934 + return MARK_NO;
114935 +
114936 + if (pointer_set_contains(visited, def_stmt))
114937 + return MARK_NO;
114938 +
114939 + switch (gimple_code(def_stmt)) {
114940 + case GIMPLE_NOP:
114941 + return search_intentional(visited, SSA_NAME_VAR(lhs));
114942 + case GIMPLE_ASM:
114943 + if (is_size_overflow_intentional_asm_turn_off(def_stmt))
114944 + return MARK_TURN_OFF;
114945 + return MARK_NO;
114946 + case GIMPLE_CALL:
114947 + return MARK_NO;
114948 + case GIMPLE_PHI:
114949 + return search_intentional_phi(visited, lhs);
114950 + case GIMPLE_ASSIGN:
114951 + switch (gimple_num_ops(def_stmt)) {
114952 + case 2:
114953 + return search_intentional(visited, gimple_assign_rhs1(def_stmt));
114954 + case 3:
114955 + return search_intentional_binary(visited, lhs);
114956 + }
114957 + case GIMPLE_RETURN:
114958 + return MARK_NO;
114959 + default:
114960 + debug_gimple_stmt((gimple)def_stmt);
114961 + error("%s: unknown gimple code", __func__);
114962 + gcc_unreachable();
114963 + }
114964 +}
114965 +
114966 +// Check the intentional_overflow attribute and create the asm comment string for the size_overflow asm stmt.
114967 +static enum mark check_intentional_attribute_gimple(const_tree arg, const_gimple stmt, unsigned int argnum)
114968 +{
114969 + const_tree fndecl;
114970 + struct pointer_set_t *visited;
114971 + enum mark cur_fndecl_attr, decl_attr = MARK_NO;
114972 +
114973 + fndecl = get_interesting_orig_fndecl(stmt, argnum);
114974 + if (is_end_intentional_intentional_attr(fndecl, argnum))
114975 + decl_attr = MARK_NOT_INTENTIONAL;
114976 + else if (is_yes_intentional_attr(fndecl, argnum))
114977 + decl_attr = MARK_YES;
114978 + else if (is_turn_off_intentional_attr(fndecl) || is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl))) {
114979 + return MARK_TURN_OFF;
114980 + }
114981 +
114982 + visited = pointer_set_create();
114983 + cur_fndecl_attr = search_intentional(visited, arg);
114984 + pointer_set_destroy(visited);
114985 +
114986 + switch (cur_fndecl_attr) {
114987 + case MARK_NO:
114988 + case MARK_TURN_OFF:
114989 + return cur_fndecl_attr;
114990 + default:
114991 + print_missing_intentional(decl_attr, cur_fndecl_attr, fndecl, argnum);
114992 + return MARK_YES;
114993 + }
114994 +}
114995 +
114996 +static void check_missing_size_overflow_attribute(tree var)
114997 +{
114998 + tree orig_fndecl;
114999 + unsigned int num;
115000 +
115001 + if (is_a_return_check(var))
115002 + orig_fndecl = DECL_ORIGIN(var);
115003 + else
115004 + orig_fndecl = DECL_ORIGIN(current_function_decl);
115005 +
115006 + num = get_function_num(var, orig_fndecl);
115007 + if (num == CANNOT_FIND_ARG)
115008 + return;
115009 +
115010 + is_missing_function(orig_fndecl, num);
115011 +}
115012 +
115013 +static void search_size_overflow_attribute_phi(struct pointer_set_t *visited, const_tree result)
115014 +{
115015 + gimple phi = get_def_stmt(result);
115016 + unsigned int i, n = gimple_phi_num_args(phi);
115017 +
115018 + pointer_set_insert(visited, phi);
115019 + for (i = 0; i < n; i++) {
115020 + tree arg = gimple_phi_arg_def(phi, i);
115021 +
115022 + search_size_overflow_attribute(visited, arg);
115023 + }
115024 +}
115025 +
115026 +static void search_size_overflow_attribute_binary(struct pointer_set_t *visited, const_tree lhs)
115027 +{
115028 + const_gimple def_stmt = get_def_stmt(lhs);
115029 + tree rhs1, rhs2;
115030 +
115031 + rhs1 = gimple_assign_rhs1(def_stmt);
115032 + rhs2 = gimple_assign_rhs2(def_stmt);
115033 +
115034 + search_size_overflow_attribute(visited, rhs1);
115035 + search_size_overflow_attribute(visited, rhs2);
115036 +}
115037 +
115038 +static void search_size_overflow_attribute(struct pointer_set_t *visited, tree lhs)
115039 +{
115040 + const_gimple def_stmt;
115041 +
115042 + if (TREE_CODE(lhs) == PARM_DECL) {
115043 + check_missing_size_overflow_attribute(lhs);
115044 + return;
115045 + }
115046 +
115047 + def_stmt = get_def_stmt(lhs);
115048 + if (!def_stmt)
115049 + return;
115050 +
115051 + if (pointer_set_insert(visited, def_stmt))
115052 + return;
115053 +
115054 + switch (gimple_code(def_stmt)) {
115055 + case GIMPLE_NOP:
115056 + return search_size_overflow_attribute(visited, SSA_NAME_VAR(lhs));
115057 + case GIMPLE_ASM:
115058 + return;
115059 + case GIMPLE_CALL: {
115060 + tree fndecl = gimple_call_fndecl(def_stmt);
115061 +
115062 + if (fndecl == NULL_TREE)
115063 + return;
115064 + check_missing_size_overflow_attribute(fndecl);
115065 + return;
115066 + }
115067 + case GIMPLE_PHI:
115068 + return search_size_overflow_attribute_phi(visited, lhs);
115069 + case GIMPLE_ASSIGN:
115070 + switch (gimple_num_ops(def_stmt)) {
115071 + case 2:
115072 + return search_size_overflow_attribute(visited, gimple_assign_rhs1(def_stmt));
115073 + case 3:
115074 + return search_size_overflow_attribute_binary(visited, lhs);
115075 + }
115076 + default:
115077 + debug_gimple_stmt((gimple)def_stmt);
115078 + error("%s: unknown gimple code", __func__);
115079 + gcc_unreachable();
115080 + }
115081 +}
115082 +
115083 +// Search missing entries in the hash table (invoked from the gimple pass)
115084 +static void search_missing_size_overflow_attribute_gimple(const_gimple stmt, unsigned int num)
115085 +{
115086 + tree fndecl = NULL_TREE;
115087 + tree lhs;
115088 + struct pointer_set_t *visited;
115089 +
115090 + if (is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl)))
115091 + return;
115092 +
115093 + if (num == 0) {
115094 + gcc_assert(gimple_code(stmt) == GIMPLE_RETURN);
115095 + lhs = gimple_return_retval(stmt);
115096 + } else {
115097 + gcc_assert(is_gimple_call(stmt));
115098 + lhs = gimple_call_arg(stmt, num - 1);
115099 + fndecl = gimple_call_fndecl(stmt);
115100 + }
115101 +
115102 + if (fndecl != NULL_TREE && is_turn_off_intentional_attr(DECL_ORIGIN(fndecl)))
115103 + return;
115104 +
115105 + visited = pointer_set_create();
115106 + search_size_overflow_attribute(visited, lhs);
115107 + pointer_set_destroy(visited);
115108 +}
115109 +
115110 +static void create_output_from_phi(gimple stmt, unsigned int argnum, struct asm_data *asm_data)
115111 +{
115112 + gimple_stmt_iterator gsi;
115113 + gimple assign;
115114 +
115115 + assign = gimple_build_assign(asm_data->input, asm_data->output);
115116 + gsi = gsi_for_stmt(stmt);
115117 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
115118 + asm_data->def_stmt = assign;
115119 +
115120 + asm_data->output = create_new_var(TREE_TYPE(asm_data->output));
115121 + asm_data->output = make_ssa_name(asm_data->output, stmt);
115122 + if (gimple_code(stmt) == GIMPLE_RETURN)
115123 + gimple_return_set_retval(stmt, asm_data->output);
115124 + else
115125 + gimple_call_set_arg(stmt, argnum - 1, asm_data->output);
115126 + update_stmt(stmt);
115127 +}
115128 +
115129 +static char *create_asm_comment(unsigned int argnum, const_gimple stmt , const char *mark_str)
115130 +{
115131 + const char *fn_name;
115132 + char *asm_comment;
115133 + unsigned int len;
115134 +
115135 + if (argnum == 0)
115136 + fn_name = DECL_NAME_POINTER(current_function_decl);
115137 + else
115138 + fn_name = DECL_NAME_POINTER(gimple_call_fndecl(stmt));
115139 +
115140 + len = asprintf(&asm_comment, "%s %s %u", mark_str, fn_name, argnum);
115141 + gcc_assert(len > 0);
115142 +
115143 + return asm_comment;
115144 +}
115145 +
115146 +static const char *convert_mark_to_str(enum mark mark)
115147 +{
115148 + switch (mark) {
115149 + case MARK_NO:
115150 + return OK_ASM_STR;
115151 + case MARK_YES:
115152 + case MARK_NOT_INTENTIONAL:
115153 + return YES_ASM_STR;
115154 + case MARK_TURN_OFF:
115155 + return TURN_OFF_ASM_STR;
115156 + }
115157 +
115158 + gcc_unreachable();
115159 +}
115160 +
115161 +/* Create the input of the size_overflow asm stmt.
115162 + * When the arg of the callee function is a parm_decl it creates this kind of size_overflow asm stmt:
115163 + * __asm__("# size_overflow MARK_YES" : : "rm" size_1(D));
115164 + * The input field in asm_data will be empty if there is no need for further size_overflow asm stmt insertion.
115165 + * otherwise create the input (for a phi stmt the output too) of the asm stmt.
115166 + */
115167 +static void create_asm_input(gimple stmt, unsigned int argnum, struct asm_data *asm_data)
115168 +{
115169 + if (!asm_data->def_stmt) {
115170 + asm_data->input = NULL_TREE;
115171 + return;
115172 + }
115173 +
115174 + asm_data->input = create_new_var(TREE_TYPE(asm_data->output));
115175 + asm_data->input = make_ssa_name(asm_data->input, asm_data->def_stmt);
115176 +
115177 + switch (gimple_code(asm_data->def_stmt)) {
115178 + case GIMPLE_ASSIGN:
115179 + case GIMPLE_CALL:
115180 + replace_call_lhs(asm_data);
115181 + break;
115182 + case GIMPLE_PHI:
115183 + create_output_from_phi(stmt, argnum, asm_data);
115184 + break;
115185 + case GIMPLE_NOP: {
115186 + enum mark mark;
115187 + const char *mark_str;
115188 + char *asm_comment;
115189 +
115190 + mark = check_intentional_attribute_gimple(asm_data->output, stmt, argnum);
115191 +
115192 + asm_data->input = asm_data->output;
115193 + asm_data->output = NULL;
115194 + asm_data->def_stmt = stmt;
115195 +
115196 + mark_str = convert_mark_to_str(mark);
115197 + asm_comment = create_asm_comment(argnum, stmt, mark_str);
115198 +
115199 + create_asm_stmt(asm_comment, build_string(3, "rm"), NULL, asm_data);
115200 + free(asm_comment);
115201 + asm_data->input = NULL_TREE;
115202 + break;
115203 + }
115204 + case GIMPLE_ASM:
115205 + if (is_size_overflow_asm(asm_data->def_stmt)) {
115206 + asm_data->input = NULL_TREE;
115207 + break;
115208 + }
115209 + default:
115210 + debug_gimple_stmt(asm_data->def_stmt);
115211 + gcc_unreachable();
115212 + }
115213 +}
115214 +
115215 +/* This is the gimple part of searching for a missing size_overflow attribute. If the intentional_overflow attribute type
115216 + * is of the right kind create the appropriate size_overflow asm stmts:
115217 + * __asm__("# size_overflow" : =rm" D.3344_8 : "0" cicus.4_16);
115218 + * __asm__("# size_overflow MARK_YES" : : "rm" size_1(D));
115219 + */
115220 +static void create_size_overflow_asm(gimple stmt, tree output_node, unsigned int argnum)
115221 +{
115222 + struct asm_data asm_data;
115223 + const char *mark_str;
115224 + char *asm_comment;
115225 + enum mark mark;
115226 +
115227 + if (is_gimple_constant(output_node))
115228 + return;
115229 +
115230 + asm_data.output = output_node;
115231 + mark = check_intentional_attribute_gimple(asm_data.output, stmt, argnum);
115232 + if (mark != MARK_TURN_OFF)
115233 + search_missing_size_overflow_attribute_gimple(stmt, argnum);
115234 +
115235 + asm_data.def_stmt = get_def_stmt(asm_data.output);
115236 + if (is_size_overflow_intentional_asm_turn_off(asm_data.def_stmt))
115237 + return;
115238 +
115239 + create_asm_input(stmt, argnum, &asm_data);
115240 + if (asm_data.input == NULL_TREE)
115241 + return;
115242 +
115243 + mark_str = convert_mark_to_str(mark);
115244 + asm_comment = create_asm_comment(argnum, stmt, mark_str);
115245 + create_asm_stmt(asm_comment, build_string(2, "0"), build_string(4, "=rm"), &asm_data);
115246 + free(asm_comment);
115247 +}
115248 +
115249 +// Insert an asm stmt with "MARK_TURN_OFF", "MARK_YES" or "MARK_NOT_INTENTIONAL".
115250 +static bool create_mark_asm(gimple stmt, enum mark mark)
115251 +{
115252 + struct asm_data asm_data;
115253 + const char *asm_str;
115254 +
115255 + switch (mark) {
115256 + case MARK_TURN_OFF:
115257 + asm_str = TURN_OFF_ASM_STR;
115258 + break;
115259 + case MARK_NOT_INTENTIONAL:
115260 + case MARK_YES:
115261 + asm_str = YES_ASM_STR;
115262 + break;
115263 + default:
115264 + gcc_unreachable();
115265 + }
115266 +
115267 + asm_data.def_stmt = stmt;
115268 + asm_data.output = gimple_call_lhs(stmt);
115269 +
115270 + if (asm_data.output == NULL_TREE) {
115271 + asm_data.input = gimple_call_arg(stmt, 0);
115272 + if (is_gimple_constant(asm_data.input))
115273 + return false;
115274 + asm_data.output = NULL;
115275 + create_asm_stmt(asm_str, build_string(3, "rm"), NULL, &asm_data);
115276 + return true;
115277 + }
115278 +
115279 + create_asm_input(stmt, 0, &asm_data);
115280 + gcc_assert(asm_data.input != NULL_TREE);
115281 +
115282 + create_asm_stmt(asm_str, build_string(2, "0"), build_string(4, "=rm"), &asm_data);
115283 + return true;
115284 +}
115285 +
115286 +static void walk_use_def_ptr(struct pointer_set_t *visited, const_tree lhs)
115287 +{
115288 + gimple def_stmt;
115289 +
115290 + def_stmt = get_def_stmt(lhs);
115291 + if (!def_stmt)
115292 + return;
115293 +
115294 + if (pointer_set_insert(visited, def_stmt))
115295 + return;
115296 +
115297 + switch (gimple_code(def_stmt)) {
115298 + case GIMPLE_NOP:
115299 + case GIMPLE_ASM:
115300 + case GIMPLE_CALL:
115301 + break;
115302 + case GIMPLE_PHI: {
115303 + unsigned int i, n = gimple_phi_num_args(def_stmt);
115304 +
115305 + pointer_set_insert(visited, def_stmt);
115306 +
115307 + for (i = 0; i < n; i++) {
115308 + tree arg = gimple_phi_arg_def(def_stmt, i);
115309 +
115310 + walk_use_def_ptr(visited, arg);
115311 + }
115312 + }
115313 + case GIMPLE_ASSIGN:
115314 + switch (gimple_num_ops(def_stmt)) {
115315 + case 2:
115316 + walk_use_def_ptr(visited, gimple_assign_rhs1(def_stmt));
115317 + return;
115318 + case 3:
115319 + walk_use_def_ptr(visited, gimple_assign_rhs1(def_stmt));
115320 + walk_use_def_ptr(visited, gimple_assign_rhs2(def_stmt));
115321 + return;
115322 + default:
115323 + return;
115324 + }
115325 + default:
115326 + debug_gimple_stmt((gimple)def_stmt);
115327 + error("%s: unknown gimple code", __func__);
115328 + gcc_unreachable();
115329 + }
115330 +}
115331 +
115332 +// Look for a ptr - ptr expression (e.g., cpuset_common_file_read() s - page)
115333 +static void insert_mark_not_intentional_asm_at_ptr(const_tree arg)
115334 +{
115335 + struct pointer_set_t *visited;
115336 +
115337 + visited = pointer_set_create();
115338 + walk_use_def_ptr(visited, arg);
115339 + pointer_set_destroy(visited);
115340 +}
115341 +
115342 +// Determine the return value and insert the asm stmt to mark the return stmt.
115343 +static void insert_asm_ret(gimple stmt)
115344 +{
115345 + tree ret;
115346 +
115347 + ret = gimple_return_retval(stmt);
115348 + create_size_overflow_asm(stmt, ret, 0);
115349 +}
115350 +
115351 +// Determine the correct arg index and arg and insert the asm stmt to mark the stmt.
115352 +static void insert_asm_arg(gimple stmt, unsigned int orig_argnum)
115353 +{
115354 + tree arg;
115355 + unsigned int argnum;
115356 +
115357 + argnum = get_correct_arg_count(orig_argnum, gimple_call_fndecl(stmt));
115358 + gcc_assert(argnum != 0);
115359 + if (argnum == CANNOT_FIND_ARG)
115360 + return;
115361 +
115362 + arg = gimple_call_arg(stmt, argnum - 1);
115363 + gcc_assert(arg != NULL_TREE);
115364 +
115365 + // skip all ptr - ptr expressions
115366 + insert_mark_not_intentional_asm_at_ptr(arg);
115367 +
115368 + create_size_overflow_asm(stmt, arg, argnum);
115369 +}
115370 +
115371 +// If a function arg or the return value is marked by the size_overflow attribute then set its index in the array.
115372 +static void set_argnum_attribute(const_tree attr, bool *argnums)
115373 +{
115374 + unsigned int argnum;
115375 + tree attr_value;
115376 +
115377 + for (attr_value = TREE_VALUE(attr); attr_value; attr_value = TREE_CHAIN(attr_value)) {
115378 + argnum = TREE_INT_CST_LOW(TREE_VALUE(attr_value));
115379 + argnums[argnum] = true;
115380 + }
115381 +}
115382 +
115383 +// If a function arg or the return value is in the hash table then set its index in the array.
115384 +static void set_argnum_hash(tree fndecl, bool *argnums)
115385 +{
115386 + unsigned int num;
115387 + const struct size_overflow_hash *hash;
115388 +
115389 + hash = get_function_hash(DECL_ORIGIN(fndecl));
115390 + if (!hash)
115391 + return;
115392 +
115393 + for (num = 0; num <= MAX_PARAM; num++) {
115394 + if (!(hash->param & (1U << num)))
115395 + continue;
115396 +
115397 + argnums[num] = true;
115398 + }
115399 +}
115400 +
115401 +static bool is_all_the_argnums_empty(bool *argnums)
115402 +{
115403 + unsigned int i;
115404 +
115405 + for (i = 0; i <= MAX_PARAM; i++)
115406 + if (argnums[i])
115407 + return false;
115408 + return true;
115409 +}
115410 +
115411 +// Check whether the arguments or the return value of the function are in the hash table or are marked by the size_overflow attribute.
115412 +static void search_interesting_args(tree fndecl, bool *argnums)
115413 +{
115414 + const_tree attr;
115415 +
115416 + set_argnum_hash(fndecl, argnums);
115417 + if (!is_all_the_argnums_empty(argnums))
115418 + return;
115419 +
115420 + attr = lookup_attribute("size_overflow", DECL_ATTRIBUTES(fndecl));
115421 + if (attr && TREE_VALUE(attr))
115422 + set_argnum_attribute(attr, argnums);
115423 +}
115424 +
115425 +/*
115426 + * Look up the intentional_overflow attribute that turns off ipa based duplication
115427 + * on the callee function.
115428 + */
115429 +static bool is_mark_turn_off_attribute(gimple stmt)
115430 +{
115431 + enum mark mark;
115432 + const_tree fndecl = gimple_call_fndecl(stmt);
115433 +
115434 + mark = get_intentional_attr_type(DECL_ORIGIN(fndecl));
115435 + if (mark == MARK_TURN_OFF)
115436 + return true;
115437 + return false;
115438 +}
115439 +
115440 +// 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
115441 +static void handle_interesting_function(gimple stmt)
115442 +{
115443 + unsigned int argnum;
115444 + tree fndecl;
115445 + bool orig_argnums[MAX_PARAM + 1] = {false};
115446 +
115447 + if (gimple_call_num_args(stmt) == 0)
115448 + return;
115449 + fndecl = gimple_call_fndecl(stmt);
115450 + if (fndecl == NULL_TREE)
115451 + return;
115452 + fndecl = DECL_ORIGIN(fndecl);
115453 +
115454 + if (is_mark_turn_off_attribute(stmt)) {
115455 + create_mark_asm(stmt, MARK_TURN_OFF);
115456 + return;
115457 + }
115458 +
115459 + search_interesting_args(fndecl, orig_argnums);
115460 +
115461 + for (argnum = 1; argnum < MAX_PARAM; argnum++)
115462 + if (orig_argnums[argnum])
115463 + insert_asm_arg(stmt, argnum);
115464 +}
115465 +
115466 +// 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
115467 +static void handle_interesting_ret(gimple stmt)
115468 +{
115469 + bool orig_argnums[MAX_PARAM + 1] = {false};
115470 +
115471 + search_interesting_args(current_function_decl, orig_argnums);
115472 +
115473 + if (orig_argnums[0])
115474 + insert_asm_ret(stmt);
115475 +}
115476 +
115477 +// Iterate over all the stmts and search for call and return stmts and mark them if they're in the hash table
115478 +static unsigned int search_interesting_functions(void)
115479 +{
115480 + basic_block bb;
115481 +
115482 + FOR_ALL_BB_FN(bb, cfun) {
115483 + gimple_stmt_iterator gsi;
115484 +
115485 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
115486 + gimple stmt = gsi_stmt(gsi);
115487 +
115488 + if (is_size_overflow_asm(stmt))
115489 + continue;
115490 +
115491 + if (is_gimple_call(stmt))
115492 + handle_interesting_function(stmt);
115493 + else if (gimple_code(stmt) == GIMPLE_RETURN)
115494 + handle_interesting_ret(stmt);
115495 + }
115496 + }
115497 + return 0;
115498 +}
115499 +
115500 +/*
115501 + * A lot of functions get inlined before the ipa passes so after the build_ssa gimple pass
115502 + * this pass inserts asm stmts to mark the interesting args
115503 + * that the ipa pass will detect and insert the size overflow checks for.
115504 + */
115505 +#if BUILDING_GCC_VERSION >= 4009
115506 +static const struct pass_data insert_size_overflow_asm_pass_data = {
115507 +#else
115508 +static struct gimple_opt_pass insert_size_overflow_asm_pass = {
115509 + .pass = {
115510 +#endif
115511 + .type = GIMPLE_PASS,
115512 + .name = "insert_size_overflow_asm",
115513 +#if BUILDING_GCC_VERSION >= 4008
115514 + .optinfo_flags = OPTGROUP_NONE,
115515 +#endif
115516 +#if BUILDING_GCC_VERSION >= 4009
115517 + .has_gate = false,
115518 + .has_execute = true,
115519 +#else
115520 + .gate = NULL,
115521 + .execute = search_interesting_functions,
115522 + .sub = NULL,
115523 + .next = NULL,
115524 + .static_pass_number = 0,
115525 +#endif
115526 + .tv_id = TV_NONE,
115527 + .properties_required = PROP_cfg,
115528 + .properties_provided = 0,
115529 + .properties_destroyed = 0,
115530 + .todo_flags_start = 0,
115531 + .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
115532 +#if BUILDING_GCC_VERSION < 4009
115533 + }
115534 +#endif
115535 +};
115536 +
115537 +#if BUILDING_GCC_VERSION >= 4009
115538 +namespace {
115539 +class insert_size_overflow_asm_pass : public gimple_opt_pass {
115540 +public:
115541 + insert_size_overflow_asm_pass() : gimple_opt_pass(insert_size_overflow_asm_pass_data, g) {}
115542 + unsigned int execute() { return search_interesting_functions(); }
115543 +};
115544 +}
115545 +#endif
115546 +
115547 +struct opt_pass *make_insert_size_overflow_asm_pass(void)
115548 +{
115549 +#if BUILDING_GCC_VERSION >= 4009
115550 + return new insert_size_overflow_asm_pass();
115551 +#else
115552 + return &insert_size_overflow_asm_pass.pass;
115553 +#endif
115554 +}
115555 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
115556 new file mode 100644
115557 index 0000000..73f0a12
115558 --- /dev/null
115559 +++ b/tools/gcc/size_overflow_plugin/insert_size_overflow_check_core.c
115560 @@ -0,0 +1,943 @@
115561 +/*
115562 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
115563 + * Licensed under the GPL v2, or (at your option) v3
115564 + *
115565 + * Homepage:
115566 + * http://www.grsecurity.net/~ephox/overflow_plugin/
115567 + *
115568 + * Documentation:
115569 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
115570 + *
115571 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
115572 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
115573 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
115574 + *
115575 + * Usage:
115576 + * $ make
115577 + * $ make run
115578 + */
115579 +
115580 +#include "gcc-common.h"
115581 +#include "size_overflow.h"
115582 +
115583 +#define MIN_CHECK true
115584 +#define MAX_CHECK false
115585 +
115586 +static tree get_size_overflow_type(struct visited *visited, const_gimple stmt, const_tree node)
115587 +{
115588 + const_tree type;
115589 + tree new_type;
115590 +
115591 + gcc_assert(node != NULL_TREE);
115592 +
115593 + type = TREE_TYPE(node);
115594 +
115595 + if (pointer_set_contains(visited->my_stmts, stmt))
115596 + return TREE_TYPE(node);
115597 +
115598 + switch (TYPE_MODE(type)) {
115599 + case QImode:
115600 + new_type = size_overflow_type_HI;
115601 + break;
115602 + case HImode:
115603 + new_type = size_overflow_type_SI;
115604 + break;
115605 + case SImode:
115606 + new_type = size_overflow_type_DI;
115607 + break;
115608 + case DImode:
115609 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
115610 + new_type = TYPE_UNSIGNED(type) ? unsigned_intDI_type_node : intDI_type_node;
115611 + else
115612 + new_type = size_overflow_type_TI;
115613 + break;
115614 + case TImode:
115615 + gcc_assert(!TYPE_UNSIGNED(type));
115616 + new_type = size_overflow_type_TI;
115617 + break;
115618 + default:
115619 + debug_tree((tree)node);
115620 + error("%s: unsupported gcc configuration (%qE).", __func__, current_function_decl);
115621 + gcc_unreachable();
115622 + }
115623 +
115624 + if (TYPE_QUALS(type) != 0)
115625 + return build_qualified_type(new_type, TYPE_QUALS(type));
115626 + return new_type;
115627 +}
115628 +
115629 +static tree get_lhs(const_gimple stmt)
115630 +{
115631 + switch (gimple_code(stmt)) {
115632 + case GIMPLE_ASSIGN:
115633 + case GIMPLE_CALL:
115634 + return gimple_get_lhs(stmt);
115635 + case GIMPLE_PHI:
115636 + return gimple_phi_result(stmt);
115637 + default:
115638 + return NULL_TREE;
115639 + }
115640 +}
115641 +
115642 +static tree cast_to_new_size_overflow_type(struct visited *visited, gimple stmt, tree rhs, tree size_overflow_type, bool before)
115643 +{
115644 + gimple_stmt_iterator gsi;
115645 + tree lhs;
115646 + gimple new_stmt;
115647 +
115648 + if (rhs == NULL_TREE)
115649 + return NULL_TREE;
115650 +
115651 + gsi = gsi_for_stmt(stmt);
115652 + new_stmt = build_cast_stmt(visited, size_overflow_type, rhs, CREATE_NEW_VAR, &gsi, before, false);
115653 + pointer_set_insert(visited->my_stmts, new_stmt);
115654 +
115655 + lhs = get_lhs(new_stmt);
115656 + gcc_assert(lhs != NULL_TREE);
115657 + return lhs;
115658 +}
115659 +
115660 +tree create_assign(struct visited *visited, gimple oldstmt, tree rhs1, bool before)
115661 +{
115662 + tree lhs, dst_type;
115663 + gimple_stmt_iterator gsi;
115664 +
115665 + if (rhs1 == NULL_TREE) {
115666 + debug_gimple_stmt(oldstmt);
115667 + error("%s: rhs1 is NULL_TREE", __func__);
115668 + gcc_unreachable();
115669 + }
115670 +
115671 + switch (gimple_code(oldstmt)) {
115672 + case GIMPLE_ASM:
115673 + lhs = rhs1;
115674 + break;
115675 + case GIMPLE_CALL:
115676 + case GIMPLE_ASSIGN:
115677 + lhs = gimple_get_lhs(oldstmt);
115678 + break;
115679 + default:
115680 + debug_gimple_stmt(oldstmt);
115681 + gcc_unreachable();
115682 + }
115683 +
115684 + gsi = gsi_for_stmt(oldstmt);
115685 + pointer_set_insert(visited->stmts, oldstmt);
115686 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
115687 + basic_block next_bb, cur_bb;
115688 + const_edge e;
115689 +
115690 + gcc_assert(before == false);
115691 + gcc_assert(stmt_can_throw_internal(oldstmt));
115692 + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
115693 + gcc_assert(!gsi_end_p(gsi));
115694 +
115695 + cur_bb = gimple_bb(oldstmt);
115696 + next_bb = cur_bb->next_bb;
115697 + e = find_edge(cur_bb, next_bb);
115698 + gcc_assert(e != NULL);
115699 + gcc_assert(e->flags & EDGE_FALLTHRU);
115700 +
115701 + gsi = gsi_after_labels(next_bb);
115702 + gcc_assert(!gsi_end_p(gsi));
115703 +
115704 + before = true;
115705 + oldstmt = gsi_stmt(gsi);
115706 + }
115707 +
115708 + dst_type = get_size_overflow_type(visited, oldstmt, lhs);
115709 +
115710 + if (is_gimple_constant(rhs1))
115711 + return cast_a_tree(dst_type, rhs1);
115712 + return cast_to_new_size_overflow_type(visited, oldstmt, rhs1, dst_type, before);
115713 +}
115714 +
115715 +tree dup_assign(struct visited *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3)
115716 +{
115717 + gimple stmt;
115718 + gimple_stmt_iterator gsi;
115719 + tree size_overflow_type, new_var, lhs = gimple_assign_lhs(oldstmt);
115720 +
115721 + if (pointer_set_contains(visited->my_stmts, oldstmt))
115722 + return lhs;
115723 +
115724 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
115725 + rhs1 = gimple_assign_rhs1(oldstmt);
115726 + rhs1 = create_assign(visited, oldstmt, rhs1, BEFORE_STMT);
115727 + }
115728 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
115729 + rhs2 = gimple_assign_rhs2(oldstmt);
115730 + rhs2 = create_assign(visited, oldstmt, rhs2, BEFORE_STMT);
115731 + }
115732 +
115733 + stmt = gimple_copy(oldstmt);
115734 + gimple_set_location(stmt, gimple_location(oldstmt));
115735 + pointer_set_insert(visited->my_stmts, stmt);
115736 +
115737 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
115738 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
115739 +
115740 + size_overflow_type = get_size_overflow_type(visited, oldstmt, node);
115741 +
115742 + new_var = create_new_var(size_overflow_type);
115743 + new_var = make_ssa_name(new_var, stmt);
115744 + gimple_assign_set_lhs(stmt, new_var);
115745 +
115746 + if (rhs1 != NULL_TREE)
115747 + gimple_assign_set_rhs1(stmt, rhs1);
115748 +
115749 + if (rhs2 != NULL_TREE)
115750 + gimple_assign_set_rhs2(stmt, rhs2);
115751 +#if BUILDING_GCC_VERSION >= 4006
115752 + if (rhs3 != NULL_TREE)
115753 + gimple_assign_set_rhs3(stmt, rhs3);
115754 +#endif
115755 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
115756 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
115757 +
115758 + gsi = gsi_for_stmt(oldstmt);
115759 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
115760 + update_stmt(stmt);
115761 + pointer_set_insert(visited->stmts, oldstmt);
115762 + return gimple_assign_lhs(stmt);
115763 +}
115764 +
115765 +static tree cast_parm_decl(struct visited *visited, tree phi_ssa_name, tree arg, tree size_overflow_type, basic_block bb)
115766 +{
115767 + gimple assign;
115768 + gimple_stmt_iterator gsi;
115769 + basic_block first_bb;
115770 +
115771 + gcc_assert(SSA_NAME_IS_DEFAULT_DEF(arg));
115772 +
115773 + if (bb->index == 0) {
115774 + first_bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
115775 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
115776 + set_immediate_dominator(CDI_DOMINATORS, first_bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
115777 + bb = first_bb;
115778 + }
115779 +
115780 + gsi = gsi_after_labels(bb);
115781 + assign = build_cast_stmt(visited, size_overflow_type, arg, phi_ssa_name, &gsi, BEFORE_STMT, false);
115782 + pointer_set_insert(visited->my_stmts, assign);
115783 +
115784 + return gimple_assign_lhs(assign);
115785 +}
115786 +
115787 +static tree use_phi_ssa_name(struct visited *visited, tree ssa_name_var, tree new_arg)
115788 +{
115789 + gimple_stmt_iterator gsi;
115790 + gimple assign, def_stmt = get_def_stmt(new_arg);
115791 +
115792 + if (gimple_code(def_stmt) == GIMPLE_PHI) {
115793 + gsi = gsi_after_labels(gimple_bb(def_stmt));
115794 + assign = build_cast_stmt(visited, TREE_TYPE(new_arg), new_arg, ssa_name_var, &gsi, BEFORE_STMT, true);
115795 + } else {
115796 + gsi = gsi_for_stmt(def_stmt);
115797 + assign = build_cast_stmt(visited, TREE_TYPE(new_arg), new_arg, ssa_name_var, &gsi, AFTER_STMT, true);
115798 + }
115799 +
115800 + pointer_set_insert(visited->my_stmts, assign);
115801 + return gimple_assign_lhs(assign);
115802 +}
115803 +
115804 +static tree cast_visited_phi_arg(struct visited *visited, tree ssa_name_var, tree arg, tree size_overflow_type)
115805 +{
115806 + basic_block bb;
115807 + gimple_stmt_iterator gsi;
115808 + const_gimple def_stmt;
115809 + gimple assign;
115810 +
115811 + def_stmt = get_def_stmt(arg);
115812 + bb = gimple_bb(def_stmt);
115813 + gcc_assert(bb->index != 0);
115814 + gsi = gsi_after_labels(bb);
115815 +
115816 + assign = build_cast_stmt(visited, size_overflow_type, arg, ssa_name_var, &gsi, BEFORE_STMT, false);
115817 + pointer_set_insert(visited->my_stmts, assign);
115818 + return gimple_assign_lhs(assign);
115819 +}
115820 +
115821 +static tree create_new_phi_arg(struct visited *visited, tree ssa_name_var, tree new_arg, gimple oldstmt, unsigned int i)
115822 +{
115823 + tree size_overflow_type;
115824 + tree arg;
115825 + const_gimple def_stmt;
115826 +
115827 + if (new_arg != NULL_TREE && is_gimple_constant(new_arg))
115828 + return new_arg;
115829 +
115830 + arg = gimple_phi_arg_def(oldstmt, i);
115831 + def_stmt = get_def_stmt(arg);
115832 + gcc_assert(def_stmt != NULL);
115833 + size_overflow_type = get_size_overflow_type(visited, oldstmt, arg);
115834 +
115835 + switch (gimple_code(def_stmt)) {
115836 + case GIMPLE_PHI:
115837 + return cast_visited_phi_arg(visited, ssa_name_var, arg, size_overflow_type);
115838 + case GIMPLE_NOP: {
115839 + basic_block bb;
115840 +
115841 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
115842 + return cast_parm_decl(visited, ssa_name_var, arg, size_overflow_type, bb);
115843 + }
115844 + case GIMPLE_ASM: {
115845 + gimple_stmt_iterator gsi;
115846 + gimple assign, stmt = get_def_stmt(arg);
115847 +
115848 + gsi = gsi_for_stmt(stmt);
115849 + assign = build_cast_stmt(visited, size_overflow_type, arg, ssa_name_var, &gsi, AFTER_STMT, false);
115850 + pointer_set_insert(visited->my_stmts, assign);
115851 + return gimple_assign_lhs(assign);
115852 + }
115853 + default:
115854 + gcc_assert(new_arg != NULL_TREE);
115855 + gcc_assert(types_compatible_p(TREE_TYPE(new_arg), size_overflow_type));
115856 + return use_phi_ssa_name(visited, ssa_name_var, new_arg);
115857 + }
115858 +}
115859 +
115860 +static gimple overflow_create_phi_node(struct visited *visited, gimple oldstmt, tree result)
115861 +{
115862 + basic_block bb;
115863 + gimple phi;
115864 + gimple_seq seq;
115865 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
115866 +
115867 + bb = gsi_bb(gsi);
115868 +
115869 + if (result == NULL_TREE) {
115870 + tree old_result = gimple_phi_result(oldstmt);
115871 + tree size_overflow_type = get_size_overflow_type(visited, oldstmt, old_result);
115872 +
115873 + result = create_new_var(size_overflow_type);
115874 + }
115875 +
115876 + phi = create_phi_node(result, bb);
115877 + gimple_phi_set_result(phi, make_ssa_name(result, phi));
115878 + seq = phi_nodes(bb);
115879 + gsi = gsi_last(seq);
115880 + gsi_remove(&gsi, false);
115881 +
115882 + gsi = gsi_for_stmt(oldstmt);
115883 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
115884 + gimple_set_bb(phi, bb);
115885 + return phi;
115886 +}
115887 +
115888 +#if BUILDING_GCC_VERSION <= 4007
115889 +static tree create_new_phi_node(struct visited *visited, VEC(tree, heap) **args, tree ssa_name_var, gimple oldstmt)
115890 +#else
115891 +static tree create_new_phi_node(struct visited *visited, vec<tree, va_heap, vl_embed> *&args, tree ssa_name_var, gimple oldstmt)
115892 +#endif
115893 +{
115894 + gimple new_phi;
115895 + unsigned int i;
115896 + tree arg, result;
115897 + location_t loc = gimple_location(oldstmt);
115898 +
115899 +#if BUILDING_GCC_VERSION <= 4007
115900 + gcc_assert(!VEC_empty(tree, *args));
115901 +#else
115902 + gcc_assert(!args->is_empty());
115903 +#endif
115904 +
115905 + new_phi = overflow_create_phi_node(visited, oldstmt, ssa_name_var);
115906 + result = gimple_phi_result(new_phi);
115907 + ssa_name_var = SSA_NAME_VAR(result);
115908 +
115909 +#if BUILDING_GCC_VERSION <= 4007
115910 + FOR_EACH_VEC_ELT(tree, *args, i, arg) {
115911 +#else
115912 + FOR_EACH_VEC_SAFE_ELT(args, i, arg) {
115913 +#endif
115914 + arg = create_new_phi_arg(visited, ssa_name_var, arg, oldstmt, i);
115915 + add_phi_arg(new_phi, arg, gimple_phi_arg_edge(oldstmt, i), loc);
115916 + }
115917 +
115918 +#if BUILDING_GCC_VERSION <= 4007
115919 + VEC_free(tree, heap, *args);
115920 +#else
115921 + vec_free(args);
115922 +#endif
115923 + update_stmt(new_phi);
115924 + pointer_set_insert(visited->my_stmts, new_phi);
115925 + return result;
115926 +}
115927 +
115928 +static tree handle_phi(struct visited *visited, struct cgraph_node *caller_node, tree orig_result)
115929 +{
115930 + tree ssa_name_var = NULL_TREE;
115931 +#if BUILDING_GCC_VERSION <= 4007
115932 + VEC(tree, heap) *args = NULL;
115933 +#else
115934 + vec<tree, va_heap, vl_embed> *args = NULL;
115935 +#endif
115936 + gimple oldstmt = get_def_stmt(orig_result);
115937 + unsigned int i, len = gimple_phi_num_args(oldstmt);
115938 +
115939 + pointer_set_insert(visited->stmts, oldstmt);
115940 + for (i = 0; i < len; i++) {
115941 + tree arg, new_arg;
115942 +
115943 + arg = gimple_phi_arg_def(oldstmt, i);
115944 + new_arg = expand(visited, caller_node, arg);
115945 +
115946 + if (ssa_name_var == NULL_TREE && new_arg != NULL_TREE)
115947 + ssa_name_var = SSA_NAME_VAR(new_arg);
115948 +
115949 + if (is_gimple_constant(arg)) {
115950 + tree size_overflow_type = get_size_overflow_type(visited, oldstmt, arg);
115951 +
115952 + new_arg = cast_a_tree(size_overflow_type, arg);
115953 + }
115954 +
115955 +#if BUILDING_GCC_VERSION <= 4007
115956 + VEC_safe_push(tree, heap, args, new_arg);
115957 +#else
115958 + vec_safe_push(args, new_arg);
115959 +#endif
115960 + }
115961 +
115962 +#if BUILDING_GCC_VERSION <= 4007
115963 + return create_new_phi_node(visited, &args, ssa_name_var, oldstmt);
115964 +#else
115965 + return create_new_phi_node(visited, args, ssa_name_var, oldstmt);
115966 +#endif
115967 +}
115968 +
115969 +static tree create_cast_assign(struct visited *visited, gimple stmt)
115970 +{
115971 + tree rhs1 = gimple_assign_rhs1(stmt);
115972 + tree lhs = gimple_assign_lhs(stmt);
115973 + const_tree rhs1_type = TREE_TYPE(rhs1);
115974 + const_tree lhs_type = TREE_TYPE(lhs);
115975 +
115976 + if (TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
115977 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115978 +
115979 + return create_assign(visited, stmt, rhs1, AFTER_STMT);
115980 +}
115981 +
115982 +static bool skip_lhs_cast_check(const_gimple stmt)
115983 +{
115984 + const_tree rhs = gimple_assign_rhs1(stmt);
115985 + const_gimple def_stmt = get_def_stmt(rhs);
115986 +
115987 + // 3.8.2 kernel/futex_compat.c compat_exit_robust_list(): get_user() 64 ulong -> int (compat_long_t), int max
115988 + if (gimple_code(def_stmt) == GIMPLE_ASM)
115989 + return true;
115990 +
115991 + if (is_const_plus_unsigned_signed_truncation(rhs))
115992 + return true;
115993 +
115994 + return false;
115995 +}
115996 +
115997 +static tree create_string_param(tree string)
115998 +{
115999 + tree i_type, a_type;
116000 + const int length = TREE_STRING_LENGTH(string);
116001 +
116002 + gcc_assert(length > 0);
116003 +
116004 + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
116005 + a_type = build_array_type(char_type_node, i_type);
116006 +
116007 + TREE_TYPE(string) = a_type;
116008 + TREE_CONSTANT(string) = 1;
116009 + TREE_READONLY(string) = 1;
116010 +
116011 + return build1(ADDR_EXPR, ptr_type_node, string);
116012 +}
116013 +
116014 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
116015 +{
116016 + gimple cond_stmt;
116017 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
116018 +
116019 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
116020 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
116021 + update_stmt(cond_stmt);
116022 +}
116023 +
116024 +static void insert_cond_result(struct cgraph_node *caller_node, basic_block bb_true, const_gimple stmt, const_tree arg, bool min)
116025 +{
116026 + gimple func_stmt;
116027 + const_gimple def_stmt;
116028 + const_tree loc_line;
116029 + tree loc_file, ssa_name, current_func;
116030 + expanded_location xloc;
116031 + char *ssa_name_buf;
116032 + int len;
116033 + struct cgraph_edge *edge;
116034 + struct cgraph_node *callee_node;
116035 + int frequency;
116036 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
116037 +
116038 + def_stmt = get_def_stmt(arg);
116039 + xloc = expand_location(gimple_location(def_stmt));
116040 +
116041 + if (!gimple_has_location(def_stmt)) {
116042 + xloc = expand_location(gimple_location(stmt));
116043 + if (!gimple_has_location(stmt))
116044 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
116045 + }
116046 +
116047 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
116048 +
116049 + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
116050 + loc_file = create_string_param(loc_file);
116051 +
116052 + current_func = build_string(DECL_NAME_LENGTH(current_function_decl) + 1, DECL_NAME_POINTER(current_function_decl));
116053 + current_func = create_string_param(current_func);
116054 +
116055 + gcc_assert(DECL_NAME(SSA_NAME_VAR(arg)) != NULL);
116056 + call_count++;
116057 + 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);
116058 + gcc_assert(len > 0);
116059 + ssa_name = build_string(len + 1, ssa_name_buf);
116060 + free(ssa_name_buf);
116061 + ssa_name = create_string_param(ssa_name);
116062 +
116063 + // void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
116064 + func_stmt = gimple_build_call(report_size_overflow_decl, 4, loc_file, loc_line, current_func, ssa_name);
116065 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
116066 +
116067 + callee_node = cgraph_get_create_node(report_size_overflow_decl);
116068 + frequency = compute_call_stmt_bb_frequency(current_function_decl, bb_true);
116069 +
116070 + edge = cgraph_create_edge(caller_node, callee_node, func_stmt, bb_true->count, frequency, bb_true->loop_depth);
116071 + gcc_assert(edge != NULL);
116072 +}
116073 +
116074 +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)
116075 +{
116076 + basic_block cond_bb, join_bb, bb_true;
116077 + edge e;
116078 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
116079 +
116080 + cond_bb = gimple_bb(stmt);
116081 + if (before)
116082 + gsi_prev(&gsi);
116083 + if (gsi_end_p(gsi))
116084 + e = split_block_after_labels(cond_bb);
116085 + else
116086 + e = split_block(cond_bb, gsi_stmt(gsi));
116087 + cond_bb = e->src;
116088 + join_bb = e->dest;
116089 + e->flags = EDGE_FALSE_VALUE;
116090 + e->probability = REG_BR_PROB_BASE;
116091 +
116092 + bb_true = create_empty_bb(cond_bb);
116093 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
116094 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
116095 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
116096 +
116097 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
116098 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
116099 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
116100 +
116101 + if (current_loops != NULL) {
116102 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
116103 + add_bb_to_loop(bb_true, cond_bb->loop_father);
116104 + }
116105 +
116106 + insert_cond(cond_bb, arg, cond_code, type_value);
116107 + insert_cond_result(caller_node, bb_true, stmt, arg, min);
116108 +
116109 +// print_the_code_insertions(stmt);
116110 +}
116111 +
116112 +void check_size_overflow(struct cgraph_node *caller_node, gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before)
116113 +{
116114 + const_tree rhs_type = TREE_TYPE(rhs);
116115 + tree cast_rhs_type, type_max_type, type_min_type, type_max, type_min;
116116 +
116117 + gcc_assert(rhs_type != NULL_TREE);
116118 + if (TREE_CODE(rhs_type) == POINTER_TYPE)
116119 + return;
116120 +
116121 + gcc_assert(TREE_CODE(rhs_type) == INTEGER_TYPE || TREE_CODE(rhs_type) == ENUMERAL_TYPE);
116122 +
116123 + if (is_const_plus_unsigned_signed_truncation(rhs))
116124 + return;
116125 +
116126 + type_max = cast_a_tree(size_overflow_type, TYPE_MAX_VALUE(rhs_type));
116127 + // typemax (-1) < typemin (0)
116128 + if (TREE_OVERFLOW(type_max))
116129 + return;
116130 +
116131 + type_min = cast_a_tree(size_overflow_type, TYPE_MIN_VALUE(rhs_type));
116132 +
116133 + cast_rhs_type = TREE_TYPE(cast_rhs);
116134 + type_max_type = TREE_TYPE(type_max);
116135 + gcc_assert(types_compatible_p(cast_rhs_type, type_max_type));
116136 +
116137 + insert_check_size_overflow(caller_node, stmt, GT_EXPR, cast_rhs, type_max, before, MAX_CHECK);
116138 +
116139 + // special case: get_size_overflow_type(), 32, u64->s
116140 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode) && TYPE_UNSIGNED(size_overflow_type) && !TYPE_UNSIGNED(rhs_type))
116141 + return;
116142 +
116143 + type_min_type = TREE_TYPE(type_min);
116144 + gcc_assert(types_compatible_p(type_max_type, type_min_type));
116145 + insert_check_size_overflow(caller_node, stmt, LT_EXPR, cast_rhs, type_min, before, MIN_CHECK);
116146 +}
116147 +
116148 +static tree create_cast_overflow_check(struct visited *visited, struct cgraph_node *caller_node, tree new_rhs1, gimple stmt)
116149 +{
116150 + bool cast_lhs, cast_rhs;
116151 + tree lhs = gimple_assign_lhs(stmt);
116152 + tree rhs = gimple_assign_rhs1(stmt);
116153 + const_tree lhs_type = TREE_TYPE(lhs);
116154 + const_tree rhs_type = TREE_TYPE(rhs);
116155 + enum machine_mode lhs_mode = TYPE_MODE(lhs_type);
116156 + enum machine_mode rhs_mode = TYPE_MODE(rhs_type);
116157 + unsigned int lhs_size = GET_MODE_BITSIZE(lhs_mode);
116158 + unsigned int rhs_size = GET_MODE_BITSIZE(rhs_mode);
116159 +
116160 + static bool check_lhs[3][4] = {
116161 + // ss su us uu
116162 + { false, true, true, false }, // lhs > rhs
116163 + { false, false, false, false }, // lhs = rhs
116164 + { true, true, true, true }, // lhs < rhs
116165 + };
116166 +
116167 + static bool check_rhs[3][4] = {
116168 + // ss su us uu
116169 + { true, false, true, true }, // lhs > rhs
116170 + { true, false, true, true }, // lhs = rhs
116171 + { true, false, true, true }, // lhs < rhs
116172 + };
116173 +
116174 + // skip lhs check on signed SI -> HI cast or signed SI -> QI cast !!!!
116175 + if (rhs_mode == SImode && !TYPE_UNSIGNED(rhs_type) && (lhs_mode == HImode || lhs_mode == QImode))
116176 + return create_assign(visited, stmt, lhs, AFTER_STMT);
116177 +
116178 + if (lhs_size > rhs_size) {
116179 + cast_lhs = check_lhs[0][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
116180 + cast_rhs = check_rhs[0][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
116181 + } else if (lhs_size == rhs_size) {
116182 + cast_lhs = check_lhs[1][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
116183 + cast_rhs = check_rhs[1][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
116184 + } else {
116185 + cast_lhs = check_lhs[2][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
116186 + cast_rhs = check_rhs[2][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
116187 + }
116188 +
116189 + if (!cast_lhs && !cast_rhs)
116190 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
116191 +
116192 + if (cast_lhs && !skip_lhs_cast_check(stmt))
116193 + check_size_overflow(caller_node, stmt, TREE_TYPE(new_rhs1), new_rhs1, lhs, BEFORE_STMT);
116194 +
116195 + if (cast_rhs)
116196 + check_size_overflow(caller_node, stmt, TREE_TYPE(new_rhs1), new_rhs1, rhs, BEFORE_STMT);
116197 +
116198 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
116199 +}
116200 +
116201 +static tree handle_unary_rhs(struct visited *visited, struct cgraph_node *caller_node, gimple stmt)
116202 +{
116203 + enum tree_code rhs_code;
116204 + tree rhs1, new_rhs1, lhs = gimple_assign_lhs(stmt);
116205 +
116206 + if (pointer_set_contains(visited->my_stmts, stmt))
116207 + return lhs;
116208 +
116209 + rhs1 = gimple_assign_rhs1(stmt);
116210 + if (TREE_CODE(TREE_TYPE(rhs1)) == POINTER_TYPE)
116211 + return create_assign(visited, stmt, lhs, AFTER_STMT);
116212 +
116213 + new_rhs1 = expand(visited, caller_node, rhs1);
116214 +
116215 + if (new_rhs1 == NULL_TREE)
116216 + return create_cast_assign(visited, stmt);
116217 +
116218 + if (pointer_set_contains(visited->no_cast_check, stmt))
116219 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
116220 +
116221 + rhs_code = gimple_assign_rhs_code(stmt);
116222 + if (rhs_code == BIT_NOT_EXPR || rhs_code == NEGATE_EXPR) {
116223 + tree size_overflow_type = get_size_overflow_type(visited, stmt, rhs1);
116224 +
116225 + new_rhs1 = cast_to_new_size_overflow_type(visited, stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
116226 + check_size_overflow(caller_node, stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
116227 + return create_assign(visited, stmt, lhs, AFTER_STMT);
116228 + }
116229 +
116230 + if (!gimple_assign_cast_p(stmt))
116231 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
116232 +
116233 + return create_cast_overflow_check(visited, caller_node, new_rhs1, stmt);
116234 +}
116235 +
116236 +static tree handle_unary_ops(struct visited *visited, struct cgraph_node *caller_node, gimple stmt)
116237 +{
116238 + tree rhs1, lhs = gimple_assign_lhs(stmt);
116239 + gimple def_stmt = get_def_stmt(lhs);
116240 +
116241 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP);
116242 + rhs1 = gimple_assign_rhs1(def_stmt);
116243 +
116244 + if (is_gimple_constant(rhs1))
116245 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
116246 +
116247 + switch (TREE_CODE(rhs1)) {
116248 + case SSA_NAME: {
116249 + tree ret = handle_unary_rhs(visited, caller_node, def_stmt);
116250 +
116251 + if (gimple_assign_cast_p(stmt))
116252 + unsigned_signed_cast_intentional_overflow(visited, stmt);
116253 + return ret;
116254 + }
116255 + case ARRAY_REF:
116256 + case BIT_FIELD_REF:
116257 + case ADDR_EXPR:
116258 + case COMPONENT_REF:
116259 + case INDIRECT_REF:
116260 +#if BUILDING_GCC_VERSION >= 4006
116261 + case MEM_REF:
116262 +#endif
116263 + case TARGET_MEM_REF:
116264 + case VIEW_CONVERT_EXPR:
116265 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
116266 + case PARM_DECL:
116267 + case VAR_DECL:
116268 + return create_assign(visited, stmt, lhs, AFTER_STMT);
116269 +
116270 + default:
116271 + debug_gimple_stmt(def_stmt);
116272 + debug_tree(rhs1);
116273 + gcc_unreachable();
116274 + }
116275 +}
116276 +
116277 +static void __unused print_the_code_insertions(const_gimple stmt)
116278 +{
116279 + location_t loc = gimple_location(stmt);
116280 +
116281 + inform(loc, "Integer size_overflow check applied here.");
116282 +}
116283 +
116284 +static bool is_from_cast(const_tree node)
116285 +{
116286 + gimple def_stmt = get_def_stmt(node);
116287 +
116288 + if (!def_stmt)
116289 + return false;
116290 +
116291 + if (gimple_assign_cast_p(def_stmt))
116292 + return true;
116293 +
116294 + return false;
116295 +}
116296 +
116297 +// Skip duplication when there is a minus expr and the type of rhs1 or rhs2 is a pointer_type.
116298 +static bool is_a_ptr_minus(gimple stmt)
116299 +{
116300 + const_tree rhs1, rhs2, ptr1_rhs, ptr2_rhs;
116301 +
116302 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
116303 + return false;
116304 +
116305 + rhs1 = gimple_assign_rhs1(stmt);
116306 + if (!is_from_cast(rhs1))
116307 + return false;
116308 +
116309 + rhs2 = gimple_assign_rhs2(stmt);
116310 + if (!is_from_cast(rhs2))
116311 + return false;
116312 +
116313 + ptr1_rhs = gimple_assign_rhs1(get_def_stmt(rhs1));
116314 + ptr2_rhs = gimple_assign_rhs1(get_def_stmt(rhs2));
116315 +
116316 + if (TREE_CODE(TREE_TYPE(ptr1_rhs)) != POINTER_TYPE && TREE_CODE(TREE_TYPE(ptr2_rhs)) != POINTER_TYPE)
116317 + return false;
116318 +
116319 + return true;
116320 +}
116321 +
116322 +static tree handle_binary_ops(struct visited *visited, struct cgraph_node *caller_node, tree lhs)
116323 +{
116324 + enum intentional_overflow_type res;
116325 + tree rhs1, rhs2, new_lhs;
116326 + gimple def_stmt = get_def_stmt(lhs);
116327 + tree new_rhs1 = NULL_TREE;
116328 + tree new_rhs2 = NULL_TREE;
116329 +
116330 + if (is_a_ptr_minus(def_stmt))
116331 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
116332 +
116333 + rhs1 = gimple_assign_rhs1(def_stmt);
116334 + rhs2 = gimple_assign_rhs2(def_stmt);
116335 +
116336 + /* no DImode/TImode division in the 32/64 bit kernel */
116337 + switch (gimple_assign_rhs_code(def_stmt)) {
116338 + case RDIV_EXPR:
116339 + case TRUNC_DIV_EXPR:
116340 + case CEIL_DIV_EXPR:
116341 + case FLOOR_DIV_EXPR:
116342 + case ROUND_DIV_EXPR:
116343 + case TRUNC_MOD_EXPR:
116344 + case CEIL_MOD_EXPR:
116345 + case FLOOR_MOD_EXPR:
116346 + case ROUND_MOD_EXPR:
116347 + case EXACT_DIV_EXPR:
116348 + case POINTER_PLUS_EXPR:
116349 + case BIT_AND_EXPR:
116350 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
116351 + default:
116352 + break;
116353 + }
116354 +
116355 + new_lhs = handle_integer_truncation(visited, caller_node, lhs);
116356 + if (new_lhs != NULL_TREE)
116357 + return new_lhs;
116358 +
116359 + if (TREE_CODE(rhs1) == SSA_NAME)
116360 + new_rhs1 = expand(visited, caller_node, rhs1);
116361 + if (TREE_CODE(rhs2) == SSA_NAME)
116362 + new_rhs2 = expand(visited, caller_node, rhs2);
116363 +
116364 + res = add_mul_intentional_overflow(def_stmt);
116365 + if (res != NO_INTENTIONAL_OVERFLOW) {
116366 + new_lhs = dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
116367 + insert_cast_expr(visited, get_def_stmt(new_lhs), res);
116368 + return new_lhs;
116369 + }
116370 +
116371 + if (skip_expr_on_double_type(def_stmt)) {
116372 + new_lhs = dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
116373 + insert_cast_expr(visited, get_def_stmt(new_lhs), NO_INTENTIONAL_OVERFLOW);
116374 + return new_lhs;
116375 + }
116376 +
116377 + if (is_a_neg_overflow(def_stmt, rhs2))
116378 + return handle_intentional_overflow(visited, caller_node, true, def_stmt, new_rhs1, NULL_TREE);
116379 + if (is_a_neg_overflow(def_stmt, rhs1))
116380 + return handle_intentional_overflow(visited, caller_node, true, def_stmt, new_rhs2, new_rhs2);
116381 +
116382 +
116383 + if (is_a_constant_overflow(def_stmt, rhs2))
116384 + return handle_intentional_overflow(visited, caller_node, !is_a_cast_and_const_overflow(rhs1), def_stmt, new_rhs1, NULL_TREE);
116385 + if (is_a_constant_overflow(def_stmt, rhs1))
116386 + return handle_intentional_overflow(visited, caller_node, !is_a_cast_and_const_overflow(rhs2), def_stmt, new_rhs2, new_rhs2);
116387 +
116388 + // the const is between 0 and (signed) MAX
116389 + if (is_gimple_constant(rhs1))
116390 + new_rhs1 = create_assign(visited, def_stmt, rhs1, BEFORE_STMT);
116391 + if (is_gimple_constant(rhs2))
116392 + new_rhs2 = create_assign(visited, def_stmt, rhs2, BEFORE_STMT);
116393 +
116394 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
116395 +}
116396 +
116397 +#if BUILDING_GCC_VERSION >= 4006
116398 +static tree get_new_rhs(struct visited *visited, struct cgraph_node *caller_node, tree size_overflow_type, tree rhs)
116399 +{
116400 + if (is_gimple_constant(rhs))
116401 + return cast_a_tree(size_overflow_type, rhs);
116402 + if (TREE_CODE(rhs) != SSA_NAME)
116403 + return NULL_TREE;
116404 + return expand(visited, caller_node, rhs);
116405 +}
116406 +
116407 +static tree handle_ternary_ops(struct visited *visited, struct cgraph_node *caller_node, tree lhs)
116408 +{
116409 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3, size_overflow_type;
116410 + gimple def_stmt = get_def_stmt(lhs);
116411 +
116412 + size_overflow_type = get_size_overflow_type(visited, def_stmt, lhs);
116413 +
116414 + rhs1 = gimple_assign_rhs1(def_stmt);
116415 + rhs2 = gimple_assign_rhs2(def_stmt);
116416 + rhs3 = gimple_assign_rhs3(def_stmt);
116417 + new_rhs1 = get_new_rhs(visited, caller_node, size_overflow_type, rhs1);
116418 + new_rhs2 = get_new_rhs(visited, caller_node, size_overflow_type, rhs2);
116419 + new_rhs3 = get_new_rhs(visited, caller_node, size_overflow_type, rhs3);
116420 +
116421 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, new_rhs3);
116422 +}
116423 +#endif
116424 +
116425 +static tree get_my_stmt_lhs(struct visited *visited, gimple stmt)
116426 +{
116427 + gimple_stmt_iterator gsi;
116428 + gimple next_stmt = NULL;
116429 +
116430 + gsi = gsi_for_stmt(stmt);
116431 +
116432 + do {
116433 + gsi_next(&gsi);
116434 + next_stmt = gsi_stmt(gsi);
116435 +
116436 + if (gimple_code(stmt) == GIMPLE_PHI && !pointer_set_contains(visited->my_stmts, next_stmt))
116437 + return NULL_TREE;
116438 +
116439 + if (pointer_set_contains(visited->my_stmts, next_stmt) && !pointer_set_contains(visited->skip_expr_casts, next_stmt))
116440 + break;
116441 +
116442 + gcc_assert(pointer_set_contains(visited->my_stmts, next_stmt));
116443 + } while (!gsi_end_p(gsi));
116444 +
116445 + gcc_assert(next_stmt);
116446 + return get_lhs(next_stmt);
116447 +}
116448 +
116449 +static tree expand_visited(struct visited *visited, gimple def_stmt)
116450 +{
116451 + gimple_stmt_iterator gsi;
116452 + enum gimple_code code = gimple_code(def_stmt);
116453 +
116454 + if (code == GIMPLE_ASM)
116455 + return NULL_TREE;
116456 +
116457 + gsi = gsi_for_stmt(def_stmt);
116458 + gsi_next(&gsi);
116459 +
116460 + if (gimple_code(def_stmt) == GIMPLE_PHI && gsi_end_p(gsi))
116461 + return NULL_TREE;
116462 + return get_my_stmt_lhs(visited, def_stmt);
116463 +}
116464 +
116465 +tree expand(struct visited *visited, struct cgraph_node *caller_node, tree lhs)
116466 +{
116467 + gimple def_stmt;
116468 +
116469 + def_stmt = get_def_stmt(lhs);
116470 +
116471 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
116472 + return NULL_TREE;
116473 +
116474 + if (pointer_set_contains(visited->my_stmts, def_stmt))
116475 + return lhs;
116476 +
116477 + if (pointer_set_contains(visited->stmts, def_stmt))
116478 + return expand_visited(visited, def_stmt);
116479 +
116480 + switch (gimple_code(def_stmt)) {
116481 + case GIMPLE_PHI:
116482 + return handle_phi(visited, caller_node, lhs);
116483 + case GIMPLE_CALL:
116484 + case GIMPLE_ASM:
116485 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
116486 + case GIMPLE_ASSIGN:
116487 + switch (gimple_num_ops(def_stmt)) {
116488 + case 2:
116489 + return handle_unary_ops(visited, caller_node, def_stmt);
116490 + case 3:
116491 + return handle_binary_ops(visited, caller_node, lhs);
116492 +#if BUILDING_GCC_VERSION >= 4006
116493 + case 4:
116494 + return handle_ternary_ops(visited, caller_node, lhs);
116495 +#endif
116496 + }
116497 + default:
116498 + debug_gimple_stmt(def_stmt);
116499 + error("%s: unknown gimple code", __func__);
116500 + gcc_unreachable();
116501 + }
116502 +}
116503 +
116504 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
116505 new file mode 100644
116506 index 0000000..df50164
116507 --- /dev/null
116508 +++ b/tools/gcc/size_overflow_plugin/insert_size_overflow_check_ipa.c
116509 @@ -0,0 +1,1141 @@
116510 +/*
116511 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
116512 + * Licensed under the GPL v2, or (at your option) v3
116513 + *
116514 + * Homepage:
116515 + * http://www.grsecurity.net/~ephox/overflow_plugin/
116516 + *
116517 + * Documentation:
116518 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
116519 + *
116520 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
116521 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
116522 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
116523 + *
116524 + * Usage:
116525 + * $ make
116526 + * $ make run
116527 + */
116528 +
116529 +#include "gcc-common.h"
116530 +#include "size_overflow.h"
116531 +
116532 +#define VEC_LEN 128
116533 +#define RET_CHECK NULL_TREE
116534 +#define WRONG_NODE 32
116535 +#define NOT_INTENTIONAL_ASM NULL
116536 +
116537 +unsigned int call_count;
116538 +
116539 +static void set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree lhs);
116540 +static void walk_use_def(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs);
116541 +
116542 +struct visited_fns {
116543 + struct visited_fns *next;
116544 + const_tree fndecl;
116545 + unsigned int num;
116546 + const_gimple first_stmt;
116547 +};
116548 +
116549 +struct next_cgraph_node {
116550 + struct next_cgraph_node *next;
116551 + struct cgraph_node *current_function;
116552 + tree callee_fndecl;
116553 + unsigned int num;
116554 +};
116555 +
116556 +// Don't want to duplicate entries in next_cgraph_node
116557 +static bool is_in_next_cgraph_node(struct next_cgraph_node *head, struct cgraph_node *node, const_tree fndecl, unsigned int num)
116558 +{
116559 + const_tree new_callee_fndecl;
116560 + struct next_cgraph_node *cur_node;
116561 +
116562 + if (fndecl == RET_CHECK)
116563 + new_callee_fndecl = NODE_DECL(node);
116564 + else
116565 + new_callee_fndecl = fndecl;
116566 +
116567 + for (cur_node = head; cur_node; cur_node = cur_node->next) {
116568 + if (!operand_equal_p(NODE_DECL(cur_node->current_function), NODE_DECL(node), 0))
116569 + continue;
116570 + if (!operand_equal_p(cur_node->callee_fndecl, new_callee_fndecl, 0))
116571 + continue;
116572 + if (num == cur_node->num)
116573 + return true;
116574 + }
116575 + return false;
116576 +}
116577 +
116578 +/* Add a next_cgraph_node into the list for handle_function().
116579 + * handle_function() iterates over all the next cgraph nodes and
116580 + * starts the overflow check insertion process.
116581 + */
116582 +static struct next_cgraph_node *create_new_next_cgraph_node(struct next_cgraph_node *head, struct cgraph_node *node, tree fndecl, unsigned int num)
116583 +{
116584 + struct next_cgraph_node *new_node;
116585 +
116586 + if (is_in_next_cgraph_node(head, node, fndecl, num))
116587 + return head;
116588 +
116589 + new_node = (struct next_cgraph_node *)xmalloc(sizeof(*new_node));
116590 + new_node->current_function = node;
116591 + new_node->next = NULL;
116592 + new_node->num = num;
116593 + if (fndecl == RET_CHECK)
116594 + new_node->callee_fndecl = NODE_DECL(node);
116595 + else
116596 + new_node->callee_fndecl = fndecl;
116597 +
116598 + if (!head)
116599 + return new_node;
116600 +
116601 + new_node->next = head;
116602 + return new_node;
116603 +}
116604 +
116605 +static struct next_cgraph_node *create_new_next_cgraph_nodes(struct next_cgraph_node *head, struct cgraph_node *node, unsigned int num)
116606 +{
116607 + struct cgraph_edge *e;
116608 +
116609 + if (num == 0)
116610 + return create_new_next_cgraph_node(head, node, RET_CHECK, num);
116611 +
116612 + for (e = node->callers; e; e = e->next_caller) {
116613 + tree fndecl = gimple_call_fndecl(e->call_stmt);
116614 +
116615 + gcc_assert(fndecl != NULL_TREE);
116616 + head = create_new_next_cgraph_node(head, e->caller, fndecl, num);
116617 + }
116618 +
116619 + return head;
116620 +}
116621 +
116622 +struct missing_functions {
116623 + struct missing_functions *next;
116624 + const_tree node;
116625 + tree fndecl;
116626 +};
116627 +
116628 +static struct missing_functions *create_new_missing_function(struct missing_functions *missing_fn_head, tree node)
116629 +{
116630 + struct missing_functions *new_function;
116631 +
116632 + new_function = (struct missing_functions *)xmalloc(sizeof(*new_function));
116633 + new_function->node = node;
116634 + new_function->next = NULL;
116635 +
116636 + if (TREE_CODE(node) == FUNCTION_DECL)
116637 + new_function->fndecl = node;
116638 + else
116639 + new_function->fndecl = current_function_decl;
116640 + gcc_assert(new_function->fndecl);
116641 +
116642 + if (!missing_fn_head)
116643 + return new_function;
116644 +
116645 + new_function->next = missing_fn_head;
116646 + return new_function;
116647 +}
116648 +
116649 +/* If the function is missing from the hash table and it is a static function
116650 + * then create a next_cgraph_node from it for handle_function()
116651 + */
116652 +static struct next_cgraph_node *check_missing_overflow_attribute_and_create_next_node(struct next_cgraph_node *cnodes, struct missing_functions *missing_fn_head)
116653 +{
116654 + unsigned int num;
116655 + const_tree orig_fndecl;
116656 + struct cgraph_node *next_node = NULL;
116657 +
116658 + orig_fndecl = DECL_ORIGIN(missing_fn_head->fndecl);
116659 +
116660 + num = get_function_num(missing_fn_head->node, orig_fndecl);
116661 + if (num == CANNOT_FIND_ARG)
116662 + return cnodes;
116663 +
116664 + if (!is_missing_function(orig_fndecl, num))
116665 + return cnodes;
116666 +
116667 + next_node = cgraph_get_node(missing_fn_head->fndecl);
116668 + if (next_node && next_node->local.local)
116669 + cnodes = create_new_next_cgraph_nodes(cnodes, next_node, num);
116670 + return cnodes;
116671 +}
116672 +
116673 +/* Search for missing size_overflow attributes on the last nodes in ipa and collect them
116674 + * into the next_cgraph_node list. They will be the next interesting returns or callees.
116675 + */
116676 +static struct next_cgraph_node *search_overflow_attribute(struct next_cgraph_node *cnodes, struct interesting_node *cur_node)
116677 +{
116678 + unsigned int i;
116679 + tree node;
116680 + struct missing_functions *cur, *missing_fn_head = NULL;
116681 +
116682 +#if BUILDING_GCC_VERSION <= 4007
116683 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, node) {
116684 +#else
116685 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, node) {
116686 +#endif
116687 + switch (TREE_CODE(node)) {
116688 + case PARM_DECL:
116689 + if (TREE_CODE(TREE_TYPE(node)) != INTEGER_TYPE)
116690 + break;
116691 + case FUNCTION_DECL:
116692 + missing_fn_head = create_new_missing_function(missing_fn_head, node);
116693 + break;
116694 + default:
116695 + break;
116696 + }
116697 + }
116698 +
116699 + while (missing_fn_head) {
116700 + cnodes = check_missing_overflow_attribute_and_create_next_node(cnodes, missing_fn_head);
116701 +
116702 + cur = missing_fn_head->next;
116703 + free(missing_fn_head);
116704 + missing_fn_head = cur;
116705 + }
116706 +
116707 + return cnodes;
116708 +}
116709 +
116710 +static void walk_phi_set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree result)
116711 +{
116712 + gimple phi = get_def_stmt(result);
116713 + unsigned int i, n = gimple_phi_num_args(phi);
116714 +
116715 + pointer_set_insert(visited, phi);
116716 + for (i = 0; i < n; i++) {
116717 + const_tree arg = gimple_phi_arg_def(phi, i);
116718 +
116719 + set_conditions(visited, interesting_conditions, arg);
116720 + }
116721 +}
116722 +
116723 +enum conditions {
116724 + FROM_CONST, NOT_UNARY, CAST, RET, PHI
116725 +};
116726 +
116727 +// Search for constants, cast assignments and binary/ternary assignments
116728 +static void set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree lhs)
116729 +{
116730 + gimple def_stmt = get_def_stmt(lhs);
116731 +
116732 + if (is_gimple_constant(lhs)) {
116733 + interesting_conditions[FROM_CONST] = true;
116734 + return;
116735 + }
116736 +
116737 + if (!def_stmt)
116738 + return;
116739 +
116740 + if (pointer_set_contains(visited, def_stmt))
116741 + return;
116742 +
116743 + switch (gimple_code(def_stmt)) {
116744 + case GIMPLE_CALL:
116745 + if (lhs == gimple_call_lhs(def_stmt))
116746 + interesting_conditions[RET] = true;
116747 + return;
116748 + case GIMPLE_NOP:
116749 + case GIMPLE_ASM:
116750 + return;
116751 + case GIMPLE_PHI:
116752 + interesting_conditions[PHI] = true;
116753 + return walk_phi_set_conditions(visited, interesting_conditions, lhs);
116754 + case GIMPLE_ASSIGN:
116755 + if (gimple_num_ops(def_stmt) == 2) {
116756 + const_tree rhs = gimple_assign_rhs1(def_stmt);
116757 +
116758 + if (gimple_assign_cast_p(def_stmt))
116759 + interesting_conditions[CAST] = true;
116760 +
116761 + return set_conditions(visited, interesting_conditions, rhs);
116762 + } else {
116763 + interesting_conditions[NOT_UNARY] = true;
116764 + return;
116765 + }
116766 + default:
116767 + debug_gimple_stmt(def_stmt);
116768 + gcc_unreachable();
116769 + }
116770 +}
116771 +
116772 +// determine whether duplication will be necessary or not.
116773 +static void search_interesting_conditions(struct interesting_node *cur_node, bool *interesting_conditions)
116774 +{
116775 + struct pointer_set_t *visited;
116776 +
116777 + if (gimple_assign_cast_p(cur_node->first_stmt))
116778 + interesting_conditions[CAST] = true;
116779 + else if (is_gimple_assign(cur_node->first_stmt) && gimple_num_ops(cur_node->first_stmt) > 2)
116780 + interesting_conditions[NOT_UNARY] = true;
116781 +
116782 + visited = pointer_set_create();
116783 + set_conditions(visited, interesting_conditions, cur_node->node);
116784 + pointer_set_destroy(visited);
116785 +}
116786 +
116787 +// Remove the size_overflow asm stmt and create an assignment from the input and output of the asm
116788 +static void replace_size_overflow_asm_with_assign(gimple asm_stmt, tree lhs, tree rhs)
116789 +{
116790 + gimple assign;
116791 + gimple_stmt_iterator gsi;
116792 +
116793 + // already removed
116794 + if (gimple_bb(asm_stmt) == NULL)
116795 + return;
116796 + gsi = gsi_for_stmt(asm_stmt);
116797 +
116798 + assign = gimple_build_assign(lhs, rhs);
116799 + gsi_insert_before(&gsi, assign, GSI_SAME_STMT);
116800 + SSA_NAME_DEF_STMT(lhs) = assign;
116801 +
116802 + gsi_remove(&gsi, true);
116803 +}
116804 +
116805 +/* Get the fndecl of an interesting stmt, the fndecl is the caller function if the interesting
116806 + * stmt is a return otherwise it is the callee function.
116807 + */
116808 +const_tree get_interesting_orig_fndecl(const_gimple stmt, unsigned int argnum)
116809 +{
116810 + const_tree fndecl;
116811 +
116812 + if (argnum == 0)
116813 + fndecl = current_function_decl;
116814 + else
116815 + fndecl = gimple_call_fndecl(stmt);
116816 +
116817 + if (fndecl == NULL_TREE)
116818 + return NULL_TREE;
116819 +
116820 + return DECL_ORIGIN(fndecl);
116821 +}
116822 +
116823 +// e.g., 3.8.2, 64, arch/x86/ia32/ia32_signal.c copy_siginfo_from_user32(): compat_ptr() u32 max
116824 +static bool skip_asm(const_tree arg)
116825 +{
116826 + gimple def_stmt = get_def_stmt(arg);
116827 +
116828 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
116829 + return false;
116830 +
116831 + def_stmt = get_def_stmt(gimple_assign_rhs1(def_stmt));
116832 + return def_stmt && gimple_code(def_stmt) == GIMPLE_ASM;
116833 +}
116834 +
116835 +static void walk_use_def_phi(struct pointer_set_t *visited, struct interesting_node *cur_node, tree result)
116836 +{
116837 + gimple phi = get_def_stmt(result);
116838 + unsigned int i, n = gimple_phi_num_args(phi);
116839 +
116840 + pointer_set_insert(visited, phi);
116841 + for (i = 0; i < n; i++) {
116842 + tree arg = gimple_phi_arg_def(phi, i);
116843 +
116844 + walk_use_def(visited, cur_node, arg);
116845 + }
116846 +}
116847 +
116848 +static void walk_use_def_binary(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs)
116849 +{
116850 + gimple def_stmt = get_def_stmt(lhs);
116851 + tree rhs1, rhs2;
116852 +
116853 + rhs1 = gimple_assign_rhs1(def_stmt);
116854 + rhs2 = gimple_assign_rhs2(def_stmt);
116855 +
116856 + walk_use_def(visited, cur_node, rhs1);
116857 + walk_use_def(visited, cur_node, rhs2);
116858 +}
116859 +
116860 +static void insert_last_node(struct interesting_node *cur_node, tree node)
116861 +{
116862 + unsigned int i;
116863 + tree element;
116864 + enum tree_code code;
116865 +
116866 + gcc_assert(node != NULL_TREE);
116867 +
116868 + if (is_gimple_constant(node))
116869 + return;
116870 +
116871 + code = TREE_CODE(node);
116872 + if (code == VAR_DECL) {
116873 + node = DECL_ORIGIN(node);
116874 + code = TREE_CODE(node);
116875 + }
116876 +
116877 + if (code != PARM_DECL && code != FUNCTION_DECL && code != COMPONENT_REF)
116878 + return;
116879 +
116880 +#if BUILDING_GCC_VERSION <= 4007
116881 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, element) {
116882 +#else
116883 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, element) {
116884 +#endif
116885 + if (operand_equal_p(node, element, 0))
116886 + return;
116887 + }
116888 +
116889 +#if BUILDING_GCC_VERSION <= 4007
116890 + gcc_assert(VEC_length(tree, cur_node->last_nodes) < VEC_LEN);
116891 + VEC_safe_push(tree, gc, cur_node->last_nodes, node);
116892 +#else
116893 + gcc_assert(cur_node->last_nodes->length() < VEC_LEN);
116894 + vec_safe_push(cur_node->last_nodes, node);
116895 +#endif
116896 +}
116897 +
116898 +// a size_overflow asm stmt in the control flow doesn't stop the recursion
116899 +static void handle_asm_stmt(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs, const_gimple stmt)
116900 +{
116901 + if (!is_size_overflow_asm(stmt))
116902 + walk_use_def(visited, cur_node, SSA_NAME_VAR(lhs));
116903 +}
116904 +
116905 +/* collect the parm_decls and fndecls (for checking a missing size_overflow attribute (ret or arg) or intentional_overflow)
116906 + * and component refs (for checking the intentional_overflow attribute).
116907 + */
116908 +static void walk_use_def(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs)
116909 +{
116910 + const_gimple def_stmt;
116911 +
116912 + if (TREE_CODE(lhs) != SSA_NAME) {
116913 + insert_last_node(cur_node, lhs);
116914 + return;
116915 + }
116916 +
116917 + def_stmt = get_def_stmt(lhs);
116918 + if (!def_stmt)
116919 + return;
116920 +
116921 + if (pointer_set_insert(visited, def_stmt))
116922 + return;
116923 +
116924 + switch (gimple_code(def_stmt)) {
116925 + case GIMPLE_NOP:
116926 + return walk_use_def(visited, cur_node, SSA_NAME_VAR(lhs));
116927 + case GIMPLE_ASM:
116928 + return handle_asm_stmt(visited, cur_node, lhs, def_stmt);
116929 + case GIMPLE_CALL: {
116930 + tree fndecl = gimple_call_fndecl(def_stmt);
116931 +
116932 + if (fndecl == NULL_TREE)
116933 + return;
116934 + insert_last_node(cur_node, fndecl);
116935 + return;
116936 + }
116937 + case GIMPLE_PHI:
116938 + return walk_use_def_phi(visited, cur_node, lhs);
116939 + case GIMPLE_ASSIGN:
116940 + switch (gimple_num_ops(def_stmt)) {
116941 + case 2:
116942 + return walk_use_def(visited, cur_node, gimple_assign_rhs1(def_stmt));
116943 + case 3:
116944 + return walk_use_def_binary(visited, cur_node, lhs);
116945 + }
116946 + default:
116947 + debug_gimple_stmt((gimple)def_stmt);
116948 + error("%s: unknown gimple code", __func__);
116949 + gcc_unreachable();
116950 + }
116951 +}
116952 +
116953 +// Collect all the last nodes for checking the intentional_overflow and size_overflow attributes
116954 +static void set_last_nodes(struct interesting_node *cur_node)
116955 +{
116956 + struct pointer_set_t *visited;
116957 +
116958 + visited = pointer_set_create();
116959 + walk_use_def(visited, cur_node, cur_node->node);
116960 + pointer_set_destroy(visited);
116961 +}
116962 +
116963 +enum precond {
116964 + NO_ATTRIBUTE_SEARCH, NO_CHECK_INSERT, NONE
116965 +};
116966 +
116967 +/* 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.
116968 + * There is only missing size_overflow attribute checking if the intentional_overflow attribute is the mark_no type.
116969 + * Stmt duplication is unnecessary if there are no binary/ternary assignements or if the unary assignment isn't a cast.
116970 + * It skips the possible error codes too.
116971 + */
116972 +static enum precond check_preconditions(struct interesting_node *cur_node)
116973 +{
116974 + bool interesting_conditions[5] = {false, false, false, false, false};
116975 +
116976 + set_last_nodes(cur_node);
116977 +
116978 + check_intentional_attribute_ipa(cur_node);
116979 + if (cur_node->intentional_attr_decl == MARK_TURN_OFF || cur_node->intentional_attr_cur_fndecl == MARK_TURN_OFF)
116980 + return NO_ATTRIBUTE_SEARCH;
116981 +
116982 + search_interesting_conditions(cur_node, interesting_conditions);
116983 +
116984 + // error code: a phi, unary assign (not cast) and returns only
116985 + if (!interesting_conditions[NOT_UNARY] && interesting_conditions[PHI] && interesting_conditions[RET] && !interesting_conditions[CAST])
116986 + return NO_ATTRIBUTE_SEARCH;
116987 +
116988 + // error code: def_stmts trace back to a constant and there are no binary/ternary assigments
116989 + if (interesting_conditions[CAST] && interesting_conditions[FROM_CONST] && !interesting_conditions[NOT_UNARY])
116990 + return NO_ATTRIBUTE_SEARCH;
116991 +
116992 + // unnecessary overflow check
116993 + if (!interesting_conditions[CAST] && !interesting_conditions[NOT_UNARY])
116994 + return NO_CHECK_INSERT;
116995 +
116996 + if (cur_node->intentional_attr_cur_fndecl != MARK_NO)
116997 + return NO_CHECK_INSERT;
116998 +
116999 + return NONE;
117000 +}
117001 +
117002 +static tree cast_to_orig_type(struct visited *visited, gimple stmt, const_tree orig_node, tree new_node)
117003 +{
117004 + const_gimple assign;
117005 + tree orig_type = TREE_TYPE(orig_node);
117006 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
117007 +
117008 + assign = build_cast_stmt(visited, orig_type, new_node, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
117009 + return gimple_assign_lhs(assign);
117010 +}
117011 +
117012 +static void change_orig_node(struct visited *visited, struct interesting_node *cur_node, tree new_node)
117013 +{
117014 + void (*set_rhs)(gimple, tree);
117015 + gimple stmt = cur_node->first_stmt;
117016 + const_tree orig_node = cur_node->node;
117017 +
117018 + switch (gimple_code(stmt)) {
117019 + case GIMPLE_RETURN:
117020 + gimple_return_set_retval(stmt, cast_to_orig_type(visited, stmt, orig_node, new_node));
117021 + break;
117022 + case GIMPLE_CALL:
117023 + gimple_call_set_arg(stmt, cur_node->num - 1, cast_to_orig_type(visited, stmt, orig_node, new_node));
117024 + break;
117025 + case GIMPLE_ASSIGN:
117026 + switch (cur_node->num) {
117027 + case 1:
117028 + set_rhs = &gimple_assign_set_rhs1;
117029 + break;
117030 + case 2:
117031 + set_rhs = &gimple_assign_set_rhs2;
117032 + break;
117033 +#if BUILDING_GCC_VERSION >= 4006
117034 + case 3:
117035 + set_rhs = &gimple_assign_set_rhs3;
117036 + break;
117037 +#endif
117038 + default:
117039 + gcc_unreachable();
117040 + }
117041 +
117042 + set_rhs(stmt, cast_to_orig_type(visited, stmt, orig_node, new_node));
117043 + break;
117044 + default:
117045 + debug_gimple_stmt(stmt);
117046 + gcc_unreachable();
117047 + }
117048 +
117049 + update_stmt(stmt);
117050 +}
117051 +
117052 +static struct visited *create_visited(void)
117053 +{
117054 + struct visited *new_node;
117055 +
117056 + new_node = (struct visited *)xmalloc(sizeof(*new_node));
117057 + new_node->stmts = pointer_set_create();
117058 + new_node->my_stmts = pointer_set_create();
117059 + new_node->skip_expr_casts = pointer_set_create();
117060 + new_node->no_cast_check = pointer_set_create();
117061 + return new_node;
117062 +}
117063 +
117064 +static void free_visited(struct visited *visited)
117065 +{
117066 + pointer_set_destroy(visited->stmts);
117067 + pointer_set_destroy(visited->my_stmts);
117068 + pointer_set_destroy(visited->skip_expr_casts);
117069 + pointer_set_destroy(visited->no_cast_check);
117070 +
117071 + free(visited);
117072 +}
117073 +
117074 +/* This function calls the main recursion function (expand) that duplicates the stmts. Before that it checks the intentional_overflow attribute and asm stmts,
117075 + * 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
117076 + * in the original stmt (first stmt) and it inserts the overflow check for the arg of the callee or for the return value.
117077 + */
117078 +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)
117079 +{
117080 + enum precond ret;
117081 + tree new_node, orig_node = cur_node->node;
117082 +
117083 + ret = check_preconditions(cur_node);
117084 + if (ret == NO_ATTRIBUTE_SEARCH)
117085 + return cnodes;
117086 +
117087 + cnodes = search_overflow_attribute(cnodes, cur_node);
117088 +
117089 + if (ret == NO_CHECK_INSERT)
117090 + return cnodes;
117091 +
117092 + new_node = expand(visited, caller_node, orig_node);
117093 + if (new_node == NULL_TREE)
117094 + return cnodes;
117095 +
117096 + change_orig_node(visited, cur_node, new_node);
117097 + check_size_overflow(caller_node, cur_node->first_stmt, TREE_TYPE(new_node), new_node, orig_node, BEFORE_STMT);
117098 +
117099 + return cnodes;
117100 +}
117101 +
117102 +// Check visited_fns interesting nodes.
117103 +static bool is_in_interesting_node(struct interesting_node *head, const_gimple first_stmt, const_tree node, unsigned int num)
117104 +{
117105 + struct interesting_node *cur;
117106 +
117107 + for (cur = head; cur; cur = cur->next) {
117108 + if (!operand_equal_p(node, cur->node, 0))
117109 + continue;
117110 + if (num != cur->num)
117111 + continue;
117112 + if (first_stmt == cur->first_stmt)
117113 + return true;
117114 + }
117115 + return false;
117116 +}
117117 +
117118 +/* Create an interesting node. The ipa pass starts to duplicate from these stmts.
117119 + 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
117120 + 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
117121 + the intentional_overflow attribute check. They are collected by set_last_nodes().
117122 + num: arg count of a call stmt or 0 when it is a ret
117123 + node: the recursion starts from here, it is a call arg or a return value
117124 + 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.
117125 + intentional_attr_decl: intentional_overflow attribute of the callee function
117126 + intentional_attr_cur_fndecl: intentional_overflow attribute of the caller function
117127 + intentional_mark_from_gimple: the intentional overflow type of size_overflow asm stmt from gimple if it exists
117128 + */
117129 +static struct interesting_node *create_new_interesting_node(struct interesting_node *head, gimple first_stmt, tree node, unsigned int num, gimple asm_stmt)
117130 +{
117131 + struct interesting_node *new_node;
117132 + tree fndecl;
117133 + enum gimple_code code;
117134 +
117135 + gcc_assert(node != NULL_TREE);
117136 + code = gimple_code(first_stmt);
117137 + gcc_assert(code == GIMPLE_CALL || code == GIMPLE_ASM || code == GIMPLE_ASSIGN || code == GIMPLE_RETURN);
117138 +
117139 + if (num == CANNOT_FIND_ARG)
117140 + return head;
117141 +
117142 + if (skip_types(node))
117143 + return head;
117144 +
117145 + if (skip_asm(node))
117146 + return head;
117147 +
117148 + if (is_gimple_call(first_stmt))
117149 + fndecl = gimple_call_fndecl(first_stmt);
117150 + else
117151 + fndecl = current_function_decl;
117152 +
117153 + if (fndecl == NULL_TREE)
117154 + return head;
117155 +
117156 + if (is_in_interesting_node(head, first_stmt, node, num))
117157 + return head;
117158 +
117159 + new_node = (struct interesting_node *)xmalloc(sizeof(*new_node));
117160 +
117161 + new_node->next = NULL;
117162 + new_node->first_stmt = first_stmt;
117163 +#if BUILDING_GCC_VERSION <= 4007
117164 + new_node->last_nodes = VEC_alloc(tree, gc, VEC_LEN);
117165 +#else
117166 + vec_alloc(new_node->last_nodes, VEC_LEN);
117167 +#endif
117168 + new_node->num = num;
117169 + new_node->node = node;
117170 + new_node->fndecl = fndecl;
117171 + new_node->intentional_attr_decl = MARK_NO;
117172 + new_node->intentional_attr_cur_fndecl = MARK_NO;
117173 + new_node->intentional_mark_from_gimple = asm_stmt;
117174 +
117175 + if (!head)
117176 + return new_node;
117177 +
117178 + new_node->next = head;
117179 + return new_node;
117180 +}
117181 +
117182 +/* 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).
117183 + * If the ret stmt is in the next cgraph node list then it's an interesting ret.
117184 + */
117185 +static struct interesting_node *handle_stmt_by_cgraph_nodes_ret(struct interesting_node *head, gimple stmt, struct next_cgraph_node *next_node)
117186 +{
117187 + struct next_cgraph_node *cur_node;
117188 + tree ret = gimple_return_retval(stmt);
117189 +
117190 + if (ret == NULL_TREE)
117191 + return head;
117192 +
117193 + for (cur_node = next_node; cur_node; cur_node = cur_node->next) {
117194 + if (!operand_equal_p(cur_node->callee_fndecl, DECL_ORIGIN(current_function_decl), 0))
117195 + continue;
117196 + if (cur_node->num == 0)
117197 + head = create_new_interesting_node(head, stmt, ret, 0, NOT_INTENTIONAL_ASM);
117198 + }
117199 +
117200 + return head;
117201 +}
117202 +
117203 +/* 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).
117204 + * If the call stmt is in the next cgraph node list then it's an interesting call.
117205 + */
117206 +static struct interesting_node *handle_stmt_by_cgraph_nodes_call(struct interesting_node *head, gimple stmt, struct next_cgraph_node *next_node)
117207 +{
117208 + unsigned int argnum;
117209 + tree arg;
117210 + const_tree fndecl;
117211 + struct next_cgraph_node *cur_node;
117212 +
117213 + fndecl = gimple_call_fndecl(stmt);
117214 + if (fndecl == NULL_TREE)
117215 + return head;
117216 +
117217 + for (cur_node = next_node; cur_node; cur_node = cur_node->next) {
117218 + if (!operand_equal_p(cur_node->callee_fndecl, fndecl, 0))
117219 + continue;
117220 + argnum = get_correct_arg_count(cur_node->num, fndecl);
117221 + gcc_assert(argnum != CANNOT_FIND_ARG);
117222 + if (argnum == 0)
117223 + continue;
117224 +
117225 + arg = gimple_call_arg(stmt, argnum - 1);
117226 + head = create_new_interesting_node(head, stmt, arg, argnum, NOT_INTENTIONAL_ASM);
117227 + }
117228 +
117229 + return head;
117230 +}
117231 +
117232 +static unsigned int check_ops(const_tree orig_node, const_tree node, unsigned int ret_count)
117233 +{
117234 + if (!operand_equal_p(orig_node, node, 0))
117235 + return WRONG_NODE;
117236 + if (skip_types(node))
117237 + return WRONG_NODE;
117238 + return ret_count;
117239 +}
117240 +
117241 +// Get the index of the rhs node in an assignment
117242 +static unsigned int get_assign_ops_count(const_gimple stmt, tree node)
117243 +{
117244 + const_tree rhs1, rhs2;
117245 + unsigned int ret;
117246 +
117247 + gcc_assert(stmt);
117248 + gcc_assert(is_gimple_assign(stmt));
117249 +
117250 + rhs1 = gimple_assign_rhs1(stmt);
117251 + gcc_assert(rhs1 != NULL_TREE);
117252 +
117253 + switch (gimple_num_ops(stmt)) {
117254 + case 2:
117255 + return check_ops(node, rhs1, 1);
117256 + case 3:
117257 + ret = check_ops(node, rhs1, 1);
117258 + if (ret != WRONG_NODE)
117259 + return ret;
117260 +
117261 + rhs2 = gimple_assign_rhs2(stmt);
117262 + gcc_assert(rhs2 != NULL_TREE);
117263 + return check_ops(node, rhs2, 2);
117264 + default:
117265 + gcc_unreachable();
117266 + }
117267 +}
117268 +
117269 +// Find the correct arg number of a call stmt. It is needed when the interesting function is a cloned function.
117270 +static unsigned int find_arg_number_gimple(const_tree arg, const_gimple stmt)
117271 +{
117272 + unsigned int i;
117273 +
117274 + if (gimple_call_fndecl(stmt) == NULL_TREE)
117275 + return CANNOT_FIND_ARG;
117276 +
117277 + for (i = 0; i < gimple_call_num_args(stmt); i++) {
117278 + tree node;
117279 +
117280 + node = gimple_call_arg(stmt, i);
117281 + if (!operand_equal_p(arg, node, 0))
117282 + continue;
117283 + if (!skip_types(node))
117284 + return i + 1;
117285 + }
117286 +
117287 + return CANNOT_FIND_ARG;
117288 +}
117289 +
117290 +/* starting from the size_overflow asm stmt collect interesting stmts. They can be
117291 + * any of return, call or assignment stmts (because of inlining).
117292 + */
117293 +static struct interesting_node *get_interesting_ret_or_call(struct pointer_set_t *visited, struct interesting_node *head, tree node, gimple intentional_asm)
117294 +{
117295 + use_operand_p use_p;
117296 + imm_use_iterator imm_iter;
117297 + unsigned int argnum;
117298 +
117299 + gcc_assert(TREE_CODE(node) == SSA_NAME);
117300 +
117301 + if (pointer_set_insert(visited, node))
117302 + return head;
117303 +
117304 + FOR_EACH_IMM_USE_FAST(use_p, imm_iter, node) {
117305 + gimple stmt = USE_STMT(use_p);
117306 +
117307 + if (stmt == NULL)
117308 + return head;
117309 + if (is_gimple_debug(stmt))
117310 + continue;
117311 +
117312 + switch (gimple_code(stmt)) {
117313 + case GIMPLE_CALL:
117314 + argnum = find_arg_number_gimple(node, stmt);
117315 + head = create_new_interesting_node(head, stmt, node, argnum, intentional_asm);
117316 + break;
117317 + case GIMPLE_RETURN:
117318 + head = create_new_interesting_node(head, stmt, node, 0, intentional_asm);
117319 + break;
117320 + case GIMPLE_ASSIGN:
117321 + argnum = get_assign_ops_count(stmt, node);
117322 + head = create_new_interesting_node(head, stmt, node, argnum, intentional_asm);
117323 + break;
117324 + case GIMPLE_PHI: {
117325 + tree result = gimple_phi_result(stmt);
117326 + head = get_interesting_ret_or_call(visited, head, result, intentional_asm);
117327 + break;
117328 + }
117329 + case GIMPLE_ASM:
117330 + if (gimple_asm_noutputs(stmt) != 0)
117331 + break;
117332 + if (!is_size_overflow_asm(stmt))
117333 + break;
117334 + head = create_new_interesting_node(head, stmt, node, 1, intentional_asm);
117335 + break;
117336 + case GIMPLE_COND:
117337 + case GIMPLE_SWITCH:
117338 + break;
117339 + default:
117340 + debug_gimple_stmt(stmt);
117341 + gcc_unreachable();
117342 + break;
117343 + }
117344 + }
117345 + return head;
117346 +}
117347 +
117348 +static void remove_size_overflow_asm(gimple stmt)
117349 +{
117350 + gimple_stmt_iterator gsi;
117351 + tree input, output;
117352 +
117353 + if (!is_size_overflow_asm(stmt))
117354 + return;
117355 +
117356 + if (gimple_asm_noutputs(stmt) == 0) {
117357 + gsi = gsi_for_stmt(stmt);
117358 + ipa_remove_stmt_references(cgraph_get_create_node(current_function_decl), stmt);
117359 + gsi_remove(&gsi, true);
117360 + return;
117361 + }
117362 +
117363 + input = gimple_asm_input_op(stmt, 0);
117364 + output = gimple_asm_output_op(stmt, 0);
117365 + replace_size_overflow_asm_with_assign(stmt, TREE_VALUE(output), TREE_VALUE(input));
117366 +}
117367 +
117368 +/* handle the size_overflow asm stmts from the gimple pass and collect the interesting stmts.
117369 + * If the asm stmt is a parm_decl kind (noutputs == 0) then remove it.
117370 + * If it is a simple asm stmt then replace it with an assignment from the asm input to the asm output.
117371 + */
117372 +static struct interesting_node *handle_stmt_by_size_overflow_asm(gimple stmt, struct interesting_node *head)
117373 +{
117374 + const_tree output;
117375 + struct pointer_set_t *visited;
117376 + gimple intentional_asm = NOT_INTENTIONAL_ASM;
117377 +
117378 + if (!is_size_overflow_asm(stmt))
117379 + return head;
117380 +
117381 + if (is_size_overflow_intentional_asm_yes(stmt) || is_size_overflow_intentional_asm_turn_off(stmt))
117382 + intentional_asm = stmt;
117383 +
117384 + gcc_assert(gimple_asm_ninputs(stmt) == 1);
117385 +
117386 + if (gimple_asm_noutputs(stmt) == 0 && is_size_overflow_intentional_asm_turn_off(stmt))
117387 + return head;
117388 +
117389 + if (gimple_asm_noutputs(stmt) == 0) {
117390 + const_tree input;
117391 +
117392 + if (!is_size_overflow_intentional_asm_turn_off(stmt))
117393 + return head;
117394 +
117395 + input = gimple_asm_input_op(stmt, 0);
117396 + remove_size_overflow_asm(stmt);
117397 + if (is_gimple_constant(TREE_VALUE(input)))
117398 + return head;
117399 + visited = pointer_set_create();
117400 + head = get_interesting_ret_or_call(visited, head, TREE_VALUE(input), intentional_asm);
117401 + pointer_set_destroy(visited);
117402 + return head;
117403 + }
117404 +
117405 + if (!is_size_overflow_intentional_asm_yes(stmt) && !is_size_overflow_intentional_asm_turn_off(stmt))
117406 + remove_size_overflow_asm(stmt);
117407 +
117408 + visited = pointer_set_create();
117409 + output = gimple_asm_output_op(stmt, 0);
117410 + head = get_interesting_ret_or_call(visited, head, TREE_VALUE(output), intentional_asm);
117411 + pointer_set_destroy(visited);
117412 + return head;
117413 +}
117414 +
117415 +/* Iterate over all the stmts of a function and look for the size_overflow asm stmts (they were created in the gimple pass)
117416 + * or a call stmt or a return stmt and store them in the interesting_node list
117417 + */
117418 +static struct interesting_node *collect_interesting_stmts(struct next_cgraph_node *next_node)
117419 +{
117420 + basic_block bb;
117421 + struct interesting_node *head = NULL;
117422 +
117423 + FOR_ALL_BB_FN(bb, cfun) {
117424 + gimple_stmt_iterator gsi;
117425 +
117426 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
117427 + enum gimple_code code;
117428 + gimple stmt = gsi_stmt(gsi);
117429 +
117430 + code = gimple_code(stmt);
117431 +
117432 + if (code == GIMPLE_ASM)
117433 + head = handle_stmt_by_size_overflow_asm(stmt, head);
117434 +
117435 + if (!next_node)
117436 + continue;
117437 + if (code == GIMPLE_CALL)
117438 + head = handle_stmt_by_cgraph_nodes_call(head, stmt, next_node);
117439 + if (code == GIMPLE_RETURN)
117440 + head = handle_stmt_by_cgraph_nodes_ret(head, stmt, next_node);
117441 + }
117442 + }
117443 + return head;
117444 +}
117445 +
117446 +static void free_interesting_node(struct interesting_node *head)
117447 +{
117448 + struct interesting_node *cur;
117449 +
117450 + while (head) {
117451 + cur = head->next;
117452 +#if BUILDING_GCC_VERSION <= 4007
117453 + VEC_free(tree, gc, head->last_nodes);
117454 +#else
117455 + vec_free(head->last_nodes);
117456 +#endif
117457 + free(head);
117458 + head = cur;
117459 + }
117460 +}
117461 +
117462 +static struct visited_fns *insert_visited_fns_function(struct visited_fns *head, struct interesting_node *cur_node)
117463 +{
117464 + struct visited_fns *new_visited_fns;
117465 +
117466 + new_visited_fns = (struct visited_fns *)xmalloc(sizeof(*new_visited_fns));
117467 + new_visited_fns->fndecl = cur_node->fndecl;
117468 + new_visited_fns->num = cur_node->num;
117469 + new_visited_fns->first_stmt = cur_node->first_stmt;
117470 + new_visited_fns->next = NULL;
117471 +
117472 + if (!head)
117473 + return new_visited_fns;
117474 +
117475 + new_visited_fns->next = head;
117476 + return new_visited_fns;
117477 +}
117478 +
117479 +/* 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
117480 + * it is a visited_fns function.
117481 + */
117482 +static bool is_visited_fns_function(struct visited_fns *head, struct interesting_node *cur_node)
117483 +{
117484 + struct visited_fns *cur;
117485 +
117486 + if (!head)
117487 + return false;
117488 +
117489 + for (cur = head; cur; cur = cur->next) {
117490 + if (cur_node->first_stmt != cur->first_stmt)
117491 + continue;
117492 + if (!operand_equal_p(cur_node->fndecl, cur->fndecl, 0))
117493 + continue;
117494 + if (cur_node->num == cur->num)
117495 + return true;
117496 + }
117497 + return false;
117498 +}
117499 +
117500 +static void free_next_cgraph_node(struct next_cgraph_node *head)
117501 +{
117502 + struct next_cgraph_node *cur;
117503 +
117504 + while (head) {
117505 + cur = head->next;
117506 + free(head);
117507 + head = cur;
117508 + }
117509 +}
117510 +
117511 +static void remove_all_size_overflow_asm(void)
117512 +{
117513 + basic_block bb;
117514 +
117515 + FOR_ALL_BB_FN(bb, cfun) {
117516 + gimple_stmt_iterator si;
117517 +
117518 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
117519 + remove_size_overflow_asm(gsi_stmt(si));
117520 + }
117521 +}
117522 +
117523 +/* Main recursive walk of the ipa pass: iterate over the collected interesting stmts in a function
117524 + * (they are interesting if they have an associated size_overflow asm stmt) and recursively walk
117525 + * the newly collected interesting functions (they are interesting if there is control flow between
117526 + * the interesting stmts and them).
117527 + */
117528 +static struct visited_fns *handle_function(struct cgraph_node *node, struct next_cgraph_node *next_node, struct visited_fns *visited_fns)
117529 +{
117530 + struct visited *visited;
117531 + struct interesting_node *head, *cur_node;
117532 + struct next_cgraph_node *cur_cnodes, *cnodes_head = NULL;
117533 +
117534 + set_current_function_decl(NODE_DECL(node));
117535 + call_count = 0;
117536 +
117537 + head = collect_interesting_stmts(next_node);
117538 +
117539 + visited = create_visited();
117540 + for (cur_node = head; cur_node; cur_node = cur_node->next) {
117541 + if (is_visited_fns_function(visited_fns, cur_node))
117542 + continue;
117543 + cnodes_head = handle_interesting_stmt(visited, cnodes_head, cur_node, node);
117544 + visited_fns = insert_visited_fns_function(visited_fns, cur_node);
117545 + }
117546 +
117547 + free_visited(visited);
117548 + free_interesting_node(head);
117549 + remove_all_size_overflow_asm();
117550 + unset_current_function_decl();
117551 +
117552 + for (cur_cnodes = cnodes_head; cur_cnodes; cur_cnodes = cur_cnodes->next)
117553 + visited_fns = handle_function(cur_cnodes->current_function, cur_cnodes, visited_fns);
117554 +
117555 + free_next_cgraph_node(cnodes_head);
117556 + return visited_fns;
117557 +}
117558 +
117559 +static void free_visited_fns(struct visited_fns *head)
117560 +{
117561 + struct visited_fns *cur;
117562 +
117563 + while (head) {
117564 + cur = head->next;
117565 + free(head);
117566 + head = cur;
117567 + }
117568 +}
117569 +
117570 +// Main entry point of the ipa pass: erases the plf flag of all stmts and iterates over all the functions
117571 +unsigned int search_function(void)
117572 +{
117573 + struct cgraph_node *node;
117574 + struct visited_fns *visited_fns = NULL;
117575 +
117576 + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) {
117577 + gcc_assert(cgraph_function_flags_ready);
117578 +#if BUILDING_GCC_VERSION <= 4007
117579 + gcc_assert(node->reachable);
117580 +#endif
117581 +
117582 + visited_fns = handle_function(node, NULL, visited_fns);
117583 + }
117584 +
117585 + free_visited_fns(visited_fns);
117586 + return 0;
117587 +}
117588 +
117589 +#if BUILDING_GCC_VERSION >= 4009
117590 +static const struct pass_data insert_size_overflow_check_data = {
117591 +#else
117592 +static struct ipa_opt_pass_d insert_size_overflow_check = {
117593 + .pass = {
117594 +#endif
117595 + .type = SIMPLE_IPA_PASS,
117596 + .name = "size_overflow",
117597 +#if BUILDING_GCC_VERSION >= 4008
117598 + .optinfo_flags = OPTGROUP_NONE,
117599 +#endif
117600 +#if BUILDING_GCC_VERSION >= 4009
117601 + .has_gate = false,
117602 + .has_execute = true,
117603 +#else
117604 + .gate = NULL,
117605 + .execute = search_function,
117606 + .sub = NULL,
117607 + .next = NULL,
117608 + .static_pass_number = 0,
117609 +#endif
117610 + .tv_id = TV_NONE,
117611 + .properties_required = 0,
117612 + .properties_provided = 0,
117613 + .properties_destroyed = 0,
117614 + .todo_flags_start = 0,
117615 + .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,
117616 +#if BUILDING_GCC_VERSION < 4009
117617 + },
117618 + .generate_summary = NULL,
117619 + .write_summary = NULL,
117620 + .read_summary = NULL,
117621 +#if BUILDING_GCC_VERSION >= 4006
117622 + .write_optimization_summary = NULL,
117623 + .read_optimization_summary = NULL,
117624 +#endif
117625 + .stmt_fixup = NULL,
117626 + .function_transform_todo_flags_start = 0,
117627 + .function_transform = NULL,
117628 + .variable_transform = NULL,
117629 +#endif
117630 +};
117631 +
117632 +#if BUILDING_GCC_VERSION >= 4009
117633 +namespace {
117634 +class insert_size_overflow_check : public ipa_opt_pass_d {
117635 +public:
117636 + insert_size_overflow_check() : ipa_opt_pass_d(insert_size_overflow_check_data, g, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL) {}
117637 + unsigned int execute() { return search_function(); }
117638 +};
117639 +}
117640 +#endif
117641 +
117642 +struct opt_pass *make_insert_size_overflow_check(void)
117643 +{
117644 +#if BUILDING_GCC_VERSION >= 4009
117645 + return new insert_size_overflow_check();
117646 +#else
117647 + return &insert_size_overflow_check.pass;
117648 +#endif
117649 +}
117650 +
117651 diff --git a/tools/gcc/size_overflow_plugin/intentional_overflow.c b/tools/gcc/size_overflow_plugin/intentional_overflow.c
117652 new file mode 100644
117653 index 0000000..d71d72a
117654 --- /dev/null
117655 +++ b/tools/gcc/size_overflow_plugin/intentional_overflow.c
117656 @@ -0,0 +1,736 @@
117657 +/*
117658 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
117659 + * Licensed under the GPL v2, or (at your option) v3
117660 + *
117661 + * Homepage:
117662 + * http://www.grsecurity.net/~ephox/overflow_plugin/
117663 + *
117664 + * Documentation:
117665 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
117666 + *
117667 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
117668 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
117669 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
117670 + *
117671 + * Usage:
117672 + * $ make
117673 + * $ make run
117674 + */
117675 +
117676 +#include "gcc-common.h"
117677 +#include "size_overflow.h"
117678 +
117679 +/* Get the param of the intentional_overflow attribute.
117680 + * * 0: MARK_NOT_INTENTIONAL
117681 + * * 1..MAX_PARAM: MARK_YES
117682 + * * -1: MARK_TURN_OFF
117683 + */
117684 +static tree get_attribute_param(const_tree decl)
117685 +{
117686 + const_tree attr;
117687 +
117688 + if (decl == NULL_TREE)
117689 + return NULL_TREE;
117690 +
117691 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(decl));
117692 + if (!attr || !TREE_VALUE(attr))
117693 + return NULL_TREE;
117694 +
117695 + return TREE_VALUE(attr);
117696 +}
117697 +
117698 +// MARK_TURN_OFF
117699 +bool is_turn_off_intentional_attr(const_tree decl)
117700 +{
117701 + const_tree param_head;
117702 +
117703 + param_head = get_attribute_param(decl);
117704 + if (param_head == NULL_TREE)
117705 + return false;
117706 +
117707 + if (TREE_INT_CST_HIGH(TREE_VALUE(param_head)) == -1)
117708 + return true;
117709 + return false;
117710 +}
117711 +
117712 +// MARK_NOT_INTENTIONAL
117713 +bool is_end_intentional_intentional_attr(const_tree decl, unsigned int argnum)
117714 +{
117715 + const_tree param_head;
117716 +
117717 + if (argnum == 0)
117718 + return false;
117719 +
117720 + param_head = get_attribute_param(decl);
117721 + if (param_head == NULL_TREE)
117722 + return false;
117723 +
117724 + if (!TREE_INT_CST_LOW(TREE_VALUE(param_head)))
117725 + return true;
117726 + return false;
117727 +}
117728 +
117729 +// MARK_YES
117730 +bool is_yes_intentional_attr(const_tree decl, unsigned int argnum)
117731 +{
117732 + tree param, param_head;
117733 +
117734 + if (argnum == 0)
117735 + return false;
117736 +
117737 + param_head = get_attribute_param(decl);
117738 + for (param = param_head; param; param = TREE_CHAIN(param))
117739 + if (argnum == TREE_INT_CST_LOW(TREE_VALUE(param)))
117740 + return true;
117741 + return false;
117742 +}
117743 +
117744 +void print_missing_intentional(enum mark callee_attr, enum mark caller_attr, const_tree decl, unsigned int argnum)
117745 +{
117746 + location_t loc;
117747 +
117748 + if (caller_attr == MARK_NO || caller_attr == MARK_NOT_INTENTIONAL || caller_attr == MARK_TURN_OFF)
117749 + return;
117750 +
117751 + if (callee_attr == MARK_NOT_INTENTIONAL || callee_attr == MARK_YES)
117752 + return;
117753 +
117754 + loc = DECL_SOURCE_LOCATION(decl);
117755 + inform(loc, "The intentional_overflow attribute is missing from +%s+%u+", DECL_NAME_POINTER(decl), argnum);
117756 +}
117757 +
117758 +// Get the field decl of a component ref for intentional_overflow checking
117759 +static const_tree search_field_decl(const_tree comp_ref)
117760 +{
117761 + const_tree field = NULL_TREE;
117762 + unsigned int i, len = TREE_OPERAND_LENGTH(comp_ref);
117763 +
117764 + for (i = 0; i < len; i++) {
117765 + field = TREE_OPERAND(comp_ref, i);
117766 + if (TREE_CODE(field) == FIELD_DECL)
117767 + break;
117768 + }
117769 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
117770 + return field;
117771 +}
117772 +
117773 +/* Get the type of the intentional_overflow attribute of a node
117774 + * * MARK_TURN_OFF
117775 + * * MARK_YES
117776 + * * MARK_NO
117777 + * * MARK_NOT_INTENTIONAL
117778 + */
117779 +enum mark get_intentional_attr_type(const_tree node)
117780 +{
117781 + const_tree cur_decl;
117782 +
117783 + if (node == NULL_TREE)
117784 + return MARK_NO;
117785 +
117786 + switch (TREE_CODE(node)) {
117787 + case COMPONENT_REF:
117788 + cur_decl = search_field_decl(node);
117789 + if (is_turn_off_intentional_attr(cur_decl))
117790 + return MARK_TURN_OFF;
117791 + if (is_end_intentional_intentional_attr(cur_decl, 1))
117792 + return MARK_YES;
117793 + break;
117794 + case PARM_DECL: {
117795 + unsigned int argnum;
117796 +
117797 + cur_decl = DECL_ORIGIN(current_function_decl);
117798 + argnum = find_arg_number_tree(node, cur_decl);
117799 + if (argnum == CANNOT_FIND_ARG)
117800 + return MARK_NO;
117801 + if (is_yes_intentional_attr(cur_decl, argnum))
117802 + return MARK_YES;
117803 + if (is_end_intentional_intentional_attr(cur_decl, argnum))
117804 + return MARK_NOT_INTENTIONAL;
117805 + break;
117806 + }
117807 + case FUNCTION_DECL:
117808 + if (is_turn_off_intentional_attr(DECL_ORIGIN(node)))
117809 + return MARK_TURN_OFF;
117810 + break;
117811 + default:
117812 + break;
117813 + }
117814 + return MARK_NO;
117815 +}
117816 +
117817 +// Search for the intentional_overflow attribute on the last nodes
117818 +static enum mark search_last_nodes_intentional(struct interesting_node *cur_node)
117819 +{
117820 + unsigned int i;
117821 + tree last_node;
117822 + enum mark mark = MARK_NO;
117823 +
117824 +#if BUILDING_GCC_VERSION <= 4007
117825 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, last_node) {
117826 +#else
117827 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, last_node) {
117828 +#endif
117829 + mark = get_intentional_attr_type(last_node);
117830 + if (mark != MARK_NO)
117831 + break;
117832 + }
117833 + return mark;
117834 +}
117835 +
117836 +/* Check the intentional kind of size_overflow asm stmt (created by the gimple pass) and
117837 + * set the appropriate intentional_overflow type. Delete the asm stmt in the end.
117838 + */
117839 +static bool is_intentional_attribute_from_gimple(struct interesting_node *cur_node)
117840 +{
117841 + if (!cur_node->intentional_mark_from_gimple)
117842 + return false;
117843 +
117844 + if (is_size_overflow_intentional_asm_yes(cur_node->intentional_mark_from_gimple))
117845 + cur_node->intentional_attr_cur_fndecl = MARK_YES;
117846 + else
117847 + cur_node->intentional_attr_cur_fndecl = MARK_TURN_OFF;
117848 +
117849 + // skip param decls
117850 + if (gimple_asm_noutputs(cur_node->intentional_mark_from_gimple) == 0)
117851 + return true;
117852 + return true;
117853 +}
117854 +
117855 +/* Search intentional_overflow attribute on caller and on callee too.
117856 + * 0</MARK_YES: no dup, search size_overflow and intentional_overflow attributes
117857 + * 0/MARK_NOT_INTENTIONAL: no dup, search size_overflow attribute (int)
117858 + * -1/MARK_TURN_OFF: no dup, no search, current_function_decl -> no dup
117859 +*/
117860 +void check_intentional_attribute_ipa(struct interesting_node *cur_node)
117861 +{
117862 + const_tree fndecl;
117863 +
117864 + if (is_intentional_attribute_from_gimple(cur_node))
117865 + return;
117866 +
117867 + if (is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl))) {
117868 + cur_node->intentional_attr_cur_fndecl = MARK_TURN_OFF;
117869 + return;
117870 + }
117871 +
117872 + if (gimple_code(cur_node->first_stmt) == GIMPLE_ASM) {
117873 + cur_node->intentional_attr_cur_fndecl = MARK_NOT_INTENTIONAL;
117874 + return;
117875 + }
117876 +
117877 + if (gimple_code(cur_node->first_stmt) == GIMPLE_ASSIGN)
117878 + return;
117879 +
117880 + fndecl = get_interesting_orig_fndecl(cur_node->first_stmt, cur_node->num);
117881 + if (is_turn_off_intentional_attr(fndecl)) {
117882 + cur_node->intentional_attr_decl = MARK_TURN_OFF;
117883 + return;
117884 + }
117885 +
117886 + if (is_end_intentional_intentional_attr(fndecl, cur_node->num))
117887 + cur_node->intentional_attr_decl = MARK_NOT_INTENTIONAL;
117888 + else if (is_yes_intentional_attr(fndecl, cur_node->num))
117889 + cur_node->intentional_attr_decl = MARK_YES;
117890 +
117891 + cur_node->intentional_attr_cur_fndecl = search_last_nodes_intentional(cur_node);
117892 + print_missing_intentional(cur_node->intentional_attr_decl, cur_node->intentional_attr_cur_fndecl, cur_node->fndecl, cur_node->num);
117893 +}
117894 +
117895 +bool is_a_cast_and_const_overflow(const_tree no_const_rhs)
117896 +{
117897 + const_tree rhs1, lhs, rhs1_type, lhs_type;
117898 + enum machine_mode lhs_mode, rhs_mode;
117899 + gimple def_stmt = get_def_stmt(no_const_rhs);
117900 +
117901 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
117902 + return false;
117903 +
117904 + rhs1 = gimple_assign_rhs1(def_stmt);
117905 + lhs = gimple_assign_lhs(def_stmt);
117906 + rhs1_type = TREE_TYPE(rhs1);
117907 + lhs_type = TREE_TYPE(lhs);
117908 + rhs_mode = TYPE_MODE(rhs1_type);
117909 + lhs_mode = TYPE_MODE(lhs_type);
117910 + if (TYPE_UNSIGNED(lhs_type) == TYPE_UNSIGNED(rhs1_type) || lhs_mode != rhs_mode)
117911 + return false;
117912 +
117913 + return true;
117914 +}
117915 +
117916 +static unsigned int uses_num(tree node)
117917 +{
117918 + imm_use_iterator imm_iter;
117919 + use_operand_p use_p;
117920 + unsigned int num = 0;
117921 +
117922 + FOR_EACH_IMM_USE_FAST(use_p, imm_iter, node) {
117923 + gimple use_stmt = USE_STMT(use_p);
117924 +
117925 + if (use_stmt == NULL)
117926 + return num;
117927 + if (is_gimple_debug(use_stmt))
117928 + continue;
117929 + if (gimple_assign_cast_p(use_stmt) && is_size_overflow_type(gimple_assign_lhs(use_stmt)))
117930 + continue;
117931 + num++;
117932 + }
117933 + return num;
117934 +}
117935 +
117936 +static bool no_uses(tree node)
117937 +{
117938 + return !uses_num(node);
117939 +}
117940 +
117941 +// 3.8.5 mm/page-writeback.c __ilog2_u64(): ret, uint + uintmax; uint -> int; int max
117942 +bool is_const_plus_unsigned_signed_truncation(const_tree lhs)
117943 +{
117944 + tree rhs1, lhs_type, rhs_type, rhs2, not_const_rhs;
117945 + gimple def_stmt = get_def_stmt(lhs);
117946 +
117947 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
117948 + return false;
117949 +
117950 + rhs1 = gimple_assign_rhs1(def_stmt);
117951 + rhs_type = TREE_TYPE(rhs1);
117952 + lhs_type = TREE_TYPE(lhs);
117953 + if (TYPE_UNSIGNED(lhs_type) || !TYPE_UNSIGNED(rhs_type))
117954 + return false;
117955 + if (TYPE_MODE(lhs_type) != TYPE_MODE(rhs_type))
117956 + return false;
117957 +
117958 + def_stmt = get_def_stmt(rhs1);
117959 + if (!def_stmt || !is_gimple_assign(def_stmt) || gimple_num_ops(def_stmt) != 3)
117960 + return false;
117961 +
117962 + if (gimple_assign_rhs_code(def_stmt) != PLUS_EXPR)
117963 + return false;
117964 +
117965 + rhs1 = gimple_assign_rhs1(def_stmt);
117966 + rhs2 = gimple_assign_rhs2(def_stmt);
117967 + if (!is_gimple_constant(rhs1) && !is_gimple_constant(rhs2))
117968 + return false;
117969 +
117970 + if (is_gimple_constant(rhs2))
117971 + not_const_rhs = rhs1;
117972 + else
117973 + not_const_rhs = rhs2;
117974 +
117975 + return no_uses(not_const_rhs);
117976 +}
117977 +
117978 +static bool is_lt_signed_type_max(const_tree rhs)
117979 +{
117980 + const_tree new_type, type_max, type = TREE_TYPE(rhs);
117981 +
117982 + if (!TYPE_UNSIGNED(type))
117983 + return true;
117984 +
117985 + switch (TYPE_MODE(type)) {
117986 + case QImode:
117987 + new_type = intQI_type_node;
117988 + break;
117989 + case HImode:
117990 + new_type = intHI_type_node;
117991 + break;
117992 + case SImode:
117993 + new_type = intSI_type_node;
117994 + break;
117995 + case DImode:
117996 + new_type = intDI_type_node;
117997 + break;
117998 + default:
117999 + debug_tree((tree)type);
118000 + gcc_unreachable();
118001 + }
118002 +
118003 + type_max = TYPE_MAX_VALUE(new_type);
118004 + if (!tree_int_cst_lt(type_max, rhs))
118005 + return true;
118006 +
118007 + return false;
118008 +}
118009 +
118010 +static bool is_gt_zero(const_tree rhs)
118011 +{
118012 + const_tree type = TREE_TYPE(rhs);
118013 +
118014 + if (TYPE_UNSIGNED(type))
118015 + return true;
118016 +
118017 + if (!tree_int_cst_lt(rhs, integer_zero_node))
118018 + return true;
118019 +
118020 + return false;
118021 +}
118022 +
118023 +bool is_a_constant_overflow(const_gimple stmt, const_tree rhs)
118024 +{
118025 + if (gimple_assign_rhs_code(stmt) == MIN_EXPR)
118026 + return false;
118027 + if (!is_gimple_constant(rhs))
118028 + return false;
118029 +
118030 + // If the const is between 0 and the max value of the signed type of the same bitsize then there is no intentional overflow
118031 + if (is_lt_signed_type_max(rhs) && is_gt_zero(rhs))
118032 + return false;
118033 +
118034 + return true;
118035 +}
118036 +
118037 +static tree change_assign_rhs(struct visited *visited, gimple stmt, const_tree orig_rhs, tree new_rhs)
118038 +{
118039 + gimple assign;
118040 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
118041 + tree origtype = TREE_TYPE(orig_rhs);
118042 +
118043 + gcc_assert(is_gimple_assign(stmt));
118044 +
118045 + assign = build_cast_stmt(visited, origtype, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
118046 + pointer_set_insert(visited->my_stmts, assign);
118047 + return gimple_assign_lhs(assign);
118048 +}
118049 +
118050 +tree handle_intentional_overflow(struct visited *visited, struct cgraph_node *caller_node, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs2)
118051 +{
118052 + tree new_rhs, orig_rhs;
118053 + void (*gimple_assign_set_rhs)(gimple, tree);
118054 + tree rhs1 = gimple_assign_rhs1(stmt);
118055 + tree rhs2 = gimple_assign_rhs2(stmt);
118056 + tree lhs = gimple_assign_lhs(stmt);
118057 +
118058 + if (!check_overflow)
118059 + return create_assign(visited, stmt, lhs, AFTER_STMT);
118060 +
118061 + if (change_rhs == NULL_TREE)
118062 + return create_assign(visited, stmt, lhs, AFTER_STMT);
118063 +
118064 + if (new_rhs2 == NULL_TREE) {
118065 + orig_rhs = rhs1;
118066 + gimple_assign_set_rhs = &gimple_assign_set_rhs1;
118067 + } else {
118068 + orig_rhs = rhs2;
118069 + gimple_assign_set_rhs = &gimple_assign_set_rhs2;
118070 + }
118071 +
118072 + check_size_overflow(caller_node, stmt, TREE_TYPE(change_rhs), change_rhs, orig_rhs, BEFORE_STMT);
118073 +
118074 + new_rhs = change_assign_rhs(visited, stmt, orig_rhs, change_rhs);
118075 + gimple_assign_set_rhs(stmt, new_rhs);
118076 + update_stmt(stmt);
118077 +
118078 + return create_assign(visited, stmt, lhs, AFTER_STMT);
118079 +}
118080 +
118081 +static bool is_subtraction_special(struct visited *visited, const_gimple stmt)
118082 +{
118083 + gimple rhs1_def_stmt, rhs2_def_stmt;
118084 + const_tree rhs1_def_stmt_rhs1, rhs2_def_stmt_rhs1, rhs1_def_stmt_lhs, rhs2_def_stmt_lhs;
118085 + enum machine_mode rhs1_def_stmt_rhs1_mode, rhs2_def_stmt_rhs1_mode, rhs1_def_stmt_lhs_mode, rhs2_def_stmt_lhs_mode;
118086 + const_tree rhs1 = gimple_assign_rhs1(stmt);
118087 + const_tree rhs2 = gimple_assign_rhs2(stmt);
118088 +
118089 + if (is_gimple_constant(rhs1) || is_gimple_constant(rhs2))
118090 + return false;
118091 +
118092 + gcc_assert(TREE_CODE(rhs1) == SSA_NAME && TREE_CODE(rhs2) == SSA_NAME);
118093 +
118094 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
118095 + return false;
118096 +
118097 + rhs1_def_stmt = get_def_stmt(rhs1);
118098 + rhs2_def_stmt = get_def_stmt(rhs2);
118099 + if (!gimple_assign_cast_p(rhs1_def_stmt) || !gimple_assign_cast_p(rhs2_def_stmt))
118100 + return false;
118101 +
118102 + rhs1_def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
118103 + rhs2_def_stmt_rhs1 = gimple_assign_rhs1(rhs2_def_stmt);
118104 + rhs1_def_stmt_lhs = gimple_assign_lhs(rhs1_def_stmt);
118105 + rhs2_def_stmt_lhs = gimple_assign_lhs(rhs2_def_stmt);
118106 + rhs1_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_rhs1));
118107 + rhs2_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_rhs1));
118108 + rhs1_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_lhs));
118109 + rhs2_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_lhs));
118110 + if (GET_MODE_BITSIZE(rhs1_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs1_def_stmt_lhs_mode))
118111 + return false;
118112 + if (GET_MODE_BITSIZE(rhs2_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs2_def_stmt_lhs_mode))
118113 + return false;
118114 +
118115 + pointer_set_insert(visited->no_cast_check, rhs1_def_stmt);
118116 + pointer_set_insert(visited->no_cast_check, rhs2_def_stmt);
118117 + return true;
118118 +}
118119 +
118120 +static gimple create_binary_assign(struct visited *visited, enum tree_code code, gimple stmt, tree rhs1, tree rhs2)
118121 +{
118122 + gimple assign;
118123 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
118124 + tree type = TREE_TYPE(rhs1);
118125 + tree lhs = create_new_var(type);
118126 +
118127 + gcc_assert(types_compatible_p(type, TREE_TYPE(rhs2)));
118128 + assign = gimple_build_assign_with_ops(code, lhs, rhs1, rhs2);
118129 + gimple_assign_set_lhs(assign, make_ssa_name(lhs, assign));
118130 +
118131 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
118132 + update_stmt(assign);
118133 + pointer_set_insert(visited->my_stmts, assign);
118134 + return assign;
118135 +}
118136 +
118137 +static tree cast_to_TI_type(struct visited *visited, gimple stmt, tree node)
118138 +{
118139 + gimple_stmt_iterator gsi;
118140 + gimple cast_stmt;
118141 + tree type = TREE_TYPE(node);
118142 +
118143 + if (types_compatible_p(type, intTI_type_node))
118144 + return node;
118145 +
118146 + gsi = gsi_for_stmt(stmt);
118147 + cast_stmt = build_cast_stmt(visited, intTI_type_node, node, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
118148 + pointer_set_insert(visited->my_stmts, cast_stmt);
118149 + return gimple_assign_lhs(cast_stmt);
118150 +}
118151 +
118152 +static tree get_def_stmt_rhs(struct visited *visited, const_tree var)
118153 +{
118154 + tree rhs1, def_stmt_rhs1;
118155 + gimple rhs1_def_stmt, def_stmt_rhs1_def_stmt, def_stmt;
118156 +
118157 + def_stmt = get_def_stmt(var);
118158 + if (!gimple_assign_cast_p(def_stmt))
118159 + return NULL_TREE;
118160 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP && pointer_set_contains(visited->my_stmts, def_stmt) && gimple_assign_cast_p(def_stmt));
118161 +
118162 + rhs1 = gimple_assign_rhs1(def_stmt);
118163 + rhs1_def_stmt = get_def_stmt(rhs1);
118164 + if (!gimple_assign_cast_p(rhs1_def_stmt))
118165 + return rhs1;
118166 +
118167 + def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
118168 + def_stmt_rhs1_def_stmt = get_def_stmt(def_stmt_rhs1);
118169 +
118170 + switch (gimple_code(def_stmt_rhs1_def_stmt)) {
118171 + case GIMPLE_CALL:
118172 + case GIMPLE_NOP:
118173 + case GIMPLE_ASM:
118174 + case GIMPLE_PHI:
118175 + return def_stmt_rhs1;
118176 + case GIMPLE_ASSIGN:
118177 + return rhs1;
118178 + default:
118179 + debug_gimple_stmt(def_stmt_rhs1_def_stmt);
118180 + gcc_unreachable();
118181 + }
118182 +}
118183 +
118184 +tree handle_integer_truncation(struct visited *visited, struct cgraph_node *caller_node, const_tree lhs)
118185 +{
118186 + tree new_rhs1, new_rhs2;
118187 + tree new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1, new_lhs;
118188 + gimple assign, stmt = get_def_stmt(lhs);
118189 + tree rhs1 = gimple_assign_rhs1(stmt);
118190 + tree rhs2 = gimple_assign_rhs2(stmt);
118191 +
118192 + if (!is_subtraction_special(visited, stmt))
118193 + return NULL_TREE;
118194 +
118195 + new_rhs1 = expand(visited, caller_node, rhs1);
118196 + new_rhs2 = expand(visited, caller_node, rhs2);
118197 +
118198 + new_rhs1_def_stmt_rhs1 = get_def_stmt_rhs(visited, new_rhs1);
118199 + new_rhs2_def_stmt_rhs1 = get_def_stmt_rhs(visited, new_rhs2);
118200 +
118201 + if (new_rhs1_def_stmt_rhs1 == NULL_TREE || new_rhs2_def_stmt_rhs1 == NULL_TREE)
118202 + return NULL_TREE;
118203 +
118204 + if (!types_compatible_p(TREE_TYPE(new_rhs1_def_stmt_rhs1), TREE_TYPE(new_rhs2_def_stmt_rhs1))) {
118205 + new_rhs1_def_stmt_rhs1 = cast_to_TI_type(visited, stmt, new_rhs1_def_stmt_rhs1);
118206 + new_rhs2_def_stmt_rhs1 = cast_to_TI_type(visited, stmt, new_rhs2_def_stmt_rhs1);
118207 + }
118208 +
118209 + assign = create_binary_assign(visited, MINUS_EXPR, stmt, new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1);
118210 + new_lhs = gimple_assign_lhs(assign);
118211 + check_size_overflow(caller_node, assign, TREE_TYPE(new_lhs), new_lhs, rhs1, AFTER_STMT);
118212 +
118213 + return dup_assign(visited, stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
118214 +}
118215 +
118216 +bool is_a_neg_overflow(const_gimple stmt, const_tree rhs)
118217 +{
118218 + const_gimple def_stmt;
118219 +
118220 + if (TREE_CODE(rhs) != SSA_NAME)
118221 + return false;
118222 +
118223 + if (gimple_assign_rhs_code(stmt) != PLUS_EXPR)
118224 + return false;
118225 +
118226 + def_stmt = get_def_stmt(rhs);
118227 + if (!is_gimple_assign(def_stmt) || gimple_assign_rhs_code(def_stmt) != BIT_NOT_EXPR)
118228 + return false;
118229 +
118230 + return true;
118231 +}
118232 +
118233 +/* e.g., drivers/acpi/acpica/utids.c acpi_ut_execute_CID()
118234 + * ((count - 1) * sizeof(struct acpi_pnp_dee_id_list) -> (count + fffffff) * 16
118235 + * fffffff * 16 > signed max -> truncate
118236 + */
118237 +static bool look_for_mult_and_add(const_gimple stmt)
118238 +{
118239 + const_tree res;
118240 + tree rhs1, rhs2, def_rhs1, def_rhs2, const_rhs, def_const_rhs;
118241 + const_gimple def_stmt;
118242 +
118243 + if (!stmt || gimple_code(stmt) == GIMPLE_NOP)
118244 + return false;
118245 + if (!is_gimple_assign(stmt))
118246 + return false;
118247 + if (gimple_assign_rhs_code(stmt) != MULT_EXPR)
118248 + return false;
118249 +
118250 + rhs1 = gimple_assign_rhs1(stmt);
118251 + rhs2 = gimple_assign_rhs2(stmt);
118252 + if (is_gimple_constant(rhs1)) {
118253 + const_rhs = rhs1;
118254 + def_stmt = get_def_stmt(rhs2);
118255 + } else if (is_gimple_constant(rhs2)) {
118256 + const_rhs = rhs2;
118257 + def_stmt = get_def_stmt(rhs1);
118258 + } else
118259 + return false;
118260 +
118261 + if (!is_gimple_assign(def_stmt))
118262 + return false;
118263 +
118264 + if (gimple_assign_rhs_code(def_stmt) != PLUS_EXPR && gimple_assign_rhs_code(def_stmt) != MINUS_EXPR)
118265 + return false;
118266 +
118267 + def_rhs1 = gimple_assign_rhs1(def_stmt);
118268 + def_rhs2 = gimple_assign_rhs2(def_stmt);
118269 + if (is_gimple_constant(def_rhs1))
118270 + def_const_rhs = def_rhs1;
118271 + else if (is_gimple_constant(def_rhs2))
118272 + def_const_rhs = def_rhs2;
118273 + else
118274 + return false;
118275 +
118276 + res = fold_binary_loc(gimple_location(def_stmt), MULT_EXPR, TREE_TYPE(const_rhs), const_rhs, def_const_rhs);
118277 + if (is_lt_signed_type_max(res) && is_gt_zero(res))
118278 + return false;
118279 + return true;
118280 +}
118281 +
118282 +enum intentional_overflow_type add_mul_intentional_overflow(const_gimple stmt)
118283 +{
118284 + const_gimple def_stmt_1, def_stmt_2;
118285 + const_tree rhs1, rhs2;
118286 + bool add_mul_rhs1, add_mul_rhs2;
118287 +
118288 + rhs1 = gimple_assign_rhs1(stmt);
118289 + def_stmt_1 = get_def_stmt(rhs1);
118290 + add_mul_rhs1 = look_for_mult_and_add(def_stmt_1);
118291 +
118292 + rhs2 = gimple_assign_rhs2(stmt);
118293 + def_stmt_2 = get_def_stmt(rhs2);
118294 + add_mul_rhs2 = look_for_mult_and_add(def_stmt_2);
118295 +
118296 + if (add_mul_rhs1)
118297 + return RHS1_INTENTIONAL_OVERFLOW;
118298 + if (add_mul_rhs2)
118299 + return RHS2_INTENTIONAL_OVERFLOW;
118300 + return NO_INTENTIONAL_OVERFLOW;
118301 +}
118302 +
118303 +static gimple get_dup_stmt(struct visited *visited, gimple stmt)
118304 +{
118305 + gimple my_stmt;
118306 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
118307 +
118308 + gsi_next(&gsi);
118309 + my_stmt = gsi_stmt(gsi);
118310 +
118311 + gcc_assert(pointer_set_contains(visited->my_stmts, my_stmt));
118312 + gcc_assert(gimple_assign_rhs_code(stmt) == gimple_assign_rhs_code(my_stmt));
118313 +
118314 + return my_stmt;
118315 +}
118316 +
118317 +/* unsigned type -> unary or binary assign (rhs1 or rhs2 is constant)
118318 + * unsigned type cast to signed type, unsigned type: no more uses
118319 + * e.g., lib/vsprintf.c:simple_strtol()
118320 + * _10 = (unsigned long int) _9
118321 + * _11 = -_10;
118322 + * _12 = (long int) _11; (_11_ no more uses)
118323 + */
118324 +static bool is_call_or_cast(gimple stmt)
118325 +{
118326 + return gimple_assign_cast_p(stmt) || is_gimple_call(stmt);
118327 +}
118328 +
118329 +static bool is_unsigned_cast_or_call_def_stmt(const_tree node)
118330 +{
118331 + const_tree rhs;
118332 + gimple def_stmt;
118333 +
118334 + if (node == NULL_TREE)
118335 + return true;
118336 + if (is_gimple_constant(node))
118337 + return true;
118338 +
118339 + def_stmt = get_def_stmt(node);
118340 + if (!def_stmt)
118341 + return false;
118342 +
118343 + if (is_call_or_cast(def_stmt))
118344 + return true;
118345 +
118346 + if (!is_gimple_assign(def_stmt) || gimple_num_ops(def_stmt) != 2)
118347 + return false;
118348 + rhs = gimple_assign_rhs1(def_stmt);
118349 + def_stmt = get_def_stmt(rhs);
118350 + if (!def_stmt)
118351 + return false;
118352 + return is_call_or_cast(def_stmt);
118353 +}
118354 +
118355 +void unsigned_signed_cast_intentional_overflow(struct visited *visited, gimple stmt)
118356 +{
118357 + unsigned int use_num;
118358 + gimple so_stmt;
118359 + const_gimple def_stmt;
118360 + const_tree rhs1, rhs2;
118361 + tree rhs = gimple_assign_rhs1(stmt);
118362 + tree lhs_type = TREE_TYPE(gimple_assign_lhs(stmt));
118363 + const_tree rhs_type = TREE_TYPE(rhs);
118364 +
118365 + if (!(TYPE_UNSIGNED(rhs_type) && !TYPE_UNSIGNED(lhs_type)))
118366 + return;
118367 + if (GET_MODE_BITSIZE(TYPE_MODE(rhs_type)) != GET_MODE_BITSIZE(TYPE_MODE(lhs_type)))
118368 + return;
118369 + use_num = uses_num(rhs);
118370 + if (use_num != 1)
118371 + return;
118372 +
118373 + def_stmt = get_def_stmt(rhs);
118374 + if (!def_stmt)
118375 + return;
118376 + if (!is_gimple_assign(def_stmt))
118377 + return;
118378 +
118379 + rhs1 = gimple_assign_rhs1(def_stmt);
118380 + if (!is_unsigned_cast_or_call_def_stmt(rhs1))
118381 + return;
118382 +
118383 + rhs2 = gimple_assign_rhs2(def_stmt);
118384 + if (!is_unsigned_cast_or_call_def_stmt(rhs2))
118385 + return;
118386 + if (gimple_num_ops(def_stmt) == 3 && !is_gimple_constant(rhs1) && !is_gimple_constant(rhs2))
118387 + return;
118388 +
118389 + so_stmt = get_dup_stmt(visited, stmt);
118390 + create_up_and_down_cast(visited, so_stmt, lhs_type, gimple_assign_rhs1(so_stmt));
118391 +}
118392 +
118393 diff --git a/tools/gcc/size_overflow_plugin/misc.c b/tools/gcc/size_overflow_plugin/misc.c
118394 new file mode 100644
118395 index 0000000..4bddad2
118396 --- /dev/null
118397 +++ b/tools/gcc/size_overflow_plugin/misc.c
118398 @@ -0,0 +1,203 @@
118399 +/*
118400 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
118401 + * Licensed under the GPL v2, or (at your option) v3
118402 + *
118403 + * Homepage:
118404 + * http://www.grsecurity.net/~ephox/overflow_plugin/
118405 + *
118406 + * Documentation:
118407 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
118408 + *
118409 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
118410 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
118411 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
118412 + *
118413 + * Usage:
118414 + * $ make
118415 + * $ make run
118416 + */
118417 +
118418 +#include "gcc-common.h"
118419 +#include "size_overflow.h"
118420 +
118421 +void set_current_function_decl(tree fndecl)
118422 +{
118423 + gcc_assert(fndecl != NULL_TREE);
118424 +
118425 + push_cfun(DECL_STRUCT_FUNCTION(fndecl));
118426 + calculate_dominance_info(CDI_DOMINATORS);
118427 + current_function_decl = fndecl;
118428 +}
118429 +
118430 +void unset_current_function_decl(void)
118431 +{
118432 + free_dominance_info(CDI_DOMINATORS);
118433 + pop_cfun();
118434 + current_function_decl = NULL_TREE;
118435 +}
118436 +
118437 +static bool is_bool(const_tree node)
118438 +{
118439 + const_tree type;
118440 +
118441 + if (node == NULL_TREE)
118442 + return false;
118443 +
118444 + type = TREE_TYPE(node);
118445 + if (!INTEGRAL_TYPE_P(type))
118446 + return false;
118447 + if (TREE_CODE(type) == BOOLEAN_TYPE)
118448 + return true;
118449 + if (TYPE_PRECISION(type) == 1)
118450 + return true;
118451 + return false;
118452 +}
118453 +
118454 +bool skip_types(const_tree var)
118455 +{
118456 + tree type;
118457 + enum tree_code code;
118458 +
118459 + if (is_gimple_constant(var))
118460 + return true;
118461 +
118462 + switch (TREE_CODE(var)) {
118463 + case ADDR_EXPR:
118464 +#if BUILDING_GCC_VERSION >= 4006
118465 + case MEM_REF:
118466 +#endif
118467 + case ARRAY_REF:
118468 + case BIT_FIELD_REF:
118469 + case INDIRECT_REF:
118470 + case TARGET_MEM_REF:
118471 + case COMPONENT_REF:
118472 + case VAR_DECL:
118473 + case VIEW_CONVERT_EXPR:
118474 + return true;
118475 + default:
118476 + break;
118477 + }
118478 +
118479 + code = TREE_CODE(var);
118480 + gcc_assert(code == SSA_NAME || code == PARM_DECL);
118481 +
118482 + type = TREE_TYPE(var);
118483 + switch (TREE_CODE(type)) {
118484 + case INTEGER_TYPE:
118485 + case ENUMERAL_TYPE:
118486 + return false;
118487 + case BOOLEAN_TYPE:
118488 + return is_bool(var);
118489 + default:
118490 + return true;
118491 + }
118492 +}
118493 +
118494 +gimple get_def_stmt(const_tree node)
118495 +{
118496 + gcc_assert(node != NULL_TREE);
118497 +
118498 + if (skip_types(node))
118499 + return NULL;
118500 +
118501 + if (TREE_CODE(node) != SSA_NAME)
118502 + return NULL;
118503 + return SSA_NAME_DEF_STMT(node);
118504 +}
118505 +
118506 +tree create_new_var(tree type)
118507 +{
118508 + tree new_var = create_tmp_var(type, "cicus");
118509 +
118510 + add_referenced_var(new_var);
118511 + return new_var;
118512 +}
118513 +
118514 +static bool skip_cast(tree dst_type, const_tree rhs, bool force)
118515 +{
118516 + const_gimple def_stmt = get_def_stmt(rhs);
118517 +
118518 + if (force)
118519 + return false;
118520 +
118521 + if (is_gimple_constant(rhs))
118522 + return false;
118523 +
118524 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
118525 + return false;
118526 +
118527 + if (!types_compatible_p(dst_type, TREE_TYPE(rhs)))
118528 + return false;
118529 +
118530 + // DI type can be on 32 bit (from create_assign) but overflow type stays DI
118531 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
118532 + return false;
118533 +
118534 + return true;
118535 +}
118536 +
118537 +tree cast_a_tree(tree type, tree var)
118538 +{
118539 + gcc_assert(type != NULL_TREE);
118540 + gcc_assert(var != NULL_TREE);
118541 + gcc_assert(fold_convertible_p(type, var));
118542 +
118543 + return fold_convert(type, var);
118544 +}
118545 +
118546 +gimple build_cast_stmt(struct visited *visited, tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before, bool force)
118547 +{
118548 + gimple assign, def_stmt;
118549 +
118550 + gcc_assert(dst_type != NULL_TREE && rhs != NULL_TREE);
118551 + gcc_assert(!is_gimple_constant(rhs));
118552 + if (gsi_end_p(*gsi) && before == AFTER_STMT)
118553 + gcc_unreachable();
118554 +
118555 + def_stmt = get_def_stmt(rhs);
118556 + if (def_stmt && gimple_code(def_stmt) != GIMPLE_NOP && skip_cast(dst_type, rhs, force) && pointer_set_contains(visited->my_stmts, def_stmt))
118557 + return def_stmt;
118558 +
118559 + if (lhs == CREATE_NEW_VAR)
118560 + lhs = create_new_var(dst_type);
118561 +
118562 + assign = gimple_build_assign(lhs, cast_a_tree(dst_type, rhs));
118563 +
118564 + if (!gsi_end_p(*gsi)) {
118565 + location_t loc = gimple_location(gsi_stmt(*gsi));
118566 + gimple_set_location(assign, loc);
118567 + }
118568 +
118569 + gimple_assign_set_lhs(assign, make_ssa_name(lhs, assign));
118570 +
118571 + if (before)
118572 + gsi_insert_before(gsi, assign, GSI_NEW_STMT);
118573 + else
118574 + gsi_insert_after(gsi, assign, GSI_NEW_STMT);
118575 + update_stmt(assign);
118576 + return assign;
118577 +}
118578 +
118579 +bool is_size_overflow_type(const_tree var)
118580 +{
118581 + const char *name;
118582 + const_tree type_name, type;
118583 +
118584 + if (var == NULL_TREE)
118585 + return false;
118586 +
118587 + type = TREE_TYPE(var);
118588 + type_name = TYPE_NAME(type);
118589 + if (type_name == NULL_TREE)
118590 + return false;
118591 +
118592 + if (DECL_P(type_name))
118593 + name = DECL_NAME_POINTER(type_name);
118594 + else
118595 + name = IDENTIFIER_POINTER(type_name);
118596 +
118597 + if (!strncmp(name, "size_overflow_type", 18))
118598 + return true;
118599 + return false;
118600 +}
118601 +
118602 diff --git a/tools/gcc/size_overflow_plugin/remove_unnecessary_dup.c b/tools/gcc/size_overflow_plugin/remove_unnecessary_dup.c
118603 new file mode 100644
118604 index 0000000..7c9e6d1
118605 --- /dev/null
118606 +++ b/tools/gcc/size_overflow_plugin/remove_unnecessary_dup.c
118607 @@ -0,0 +1,138 @@
118608 +/*
118609 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
118610 + * Licensed under the GPL v2, or (at your option) v3
118611 + *
118612 + * Homepage:
118613 + * http://www.grsecurity.net/~ephox/overflow_plugin/
118614 + *
118615 + * Documentation:
118616 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
118617 + *
118618 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
118619 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
118620 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
118621 + *
118622 + * Usage:
118623 + * $ make
118624 + * $ make run
118625 + */
118626 +
118627 +#include "gcc-common.h"
118628 +#include "size_overflow.h"
118629 +
118630 +bool skip_expr_on_double_type(const_gimple stmt)
118631 +{
118632 + enum tree_code code = gimple_assign_rhs_code(stmt);
118633 +
118634 + switch (code) {
118635 + case RSHIFT_EXPR:
118636 + case TRUNC_DIV_EXPR:
118637 + case CEIL_DIV_EXPR:
118638 + case FLOOR_DIV_EXPR:
118639 + case ROUND_DIV_EXPR:
118640 + case EXACT_DIV_EXPR:
118641 + case RDIV_EXPR:
118642 + case TRUNC_MOD_EXPR:
118643 + case CEIL_MOD_EXPR:
118644 + case FLOOR_MOD_EXPR:
118645 + case ROUND_MOD_EXPR:
118646 + return true;
118647 + default:
118648 + return false;
118649 + }
118650 +}
118651 +
118652 +void create_up_and_down_cast(struct visited *visited, gimple use_stmt, tree orig_type, tree rhs)
118653 +{
118654 + const_tree orig_rhs1;
118655 + tree down_lhs, new_lhs, dup_type = TREE_TYPE(rhs);
118656 + gimple down_cast, up_cast;
118657 + gimple_stmt_iterator gsi = gsi_for_stmt(use_stmt);
118658 +
118659 + down_cast = build_cast_stmt(visited, orig_type, rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
118660 + down_lhs = gimple_assign_lhs(down_cast);
118661 +
118662 + gsi = gsi_for_stmt(use_stmt);
118663 + up_cast = build_cast_stmt(visited, dup_type, down_lhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
118664 + new_lhs = gimple_assign_lhs(up_cast);
118665 +
118666 + orig_rhs1 = gimple_assign_rhs1(use_stmt);
118667 + if (operand_equal_p(orig_rhs1, rhs, 0))
118668 + gimple_assign_set_rhs1(use_stmt, new_lhs);
118669 + else
118670 + gimple_assign_set_rhs2(use_stmt, new_lhs);
118671 + update_stmt(use_stmt);
118672 +
118673 + pointer_set_insert(visited->my_stmts, up_cast);
118674 + pointer_set_insert(visited->my_stmts, down_cast);
118675 + pointer_set_insert(visited->skip_expr_casts, up_cast);
118676 + pointer_set_insert(visited->skip_expr_casts, down_cast);
118677 +}
118678 +
118679 +static tree get_proper_unsigned_half_type(const_tree node)
118680 +{
118681 + tree new_type, type;
118682 +
118683 + gcc_assert(is_size_overflow_type(node));
118684 +
118685 + type = TREE_TYPE(node);
118686 + switch (TYPE_MODE(type)) {
118687 + case HImode:
118688 + new_type = unsigned_intQI_type_node;
118689 + break;
118690 + case SImode:
118691 + new_type = unsigned_intHI_type_node;
118692 + break;
118693 + case DImode:
118694 + new_type = unsigned_intSI_type_node;
118695 + break;
118696 + case TImode:
118697 + new_type = unsigned_intDI_type_node;
118698 + break;
118699 + default:
118700 + gcc_unreachable();
118701 + }
118702 +
118703 + if (TYPE_QUALS(type) != 0)
118704 + return build_qualified_type(new_type, TYPE_QUALS(type));
118705 + return new_type;
118706 +}
118707 +
118708 +static void insert_cast_rhs(struct visited *visited, gimple stmt, tree rhs)
118709 +{
118710 + tree type;
118711 +
118712 + if (rhs == NULL_TREE)
118713 + return;
118714 + if (!is_size_overflow_type(rhs))
118715 + return;
118716 +
118717 + type = get_proper_unsigned_half_type(rhs);
118718 + if (is_gimple_constant(rhs))
118719 + return;
118720 + create_up_and_down_cast(visited, stmt, type, rhs);
118721 +}
118722 +
118723 +static void insert_cast(struct visited *visited, gimple stmt, tree rhs)
118724 +{
118725 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode) && !is_size_overflow_type(rhs))
118726 + return;
118727 + gcc_assert(is_size_overflow_type(rhs));
118728 + insert_cast_rhs(visited, stmt, rhs);
118729 +}
118730 +
118731 +void insert_cast_expr(struct visited *visited, gimple stmt, enum intentional_overflow_type type)
118732 +{
118733 + tree rhs1, rhs2;
118734 +
118735 + if (type == NO_INTENTIONAL_OVERFLOW || type == RHS1_INTENTIONAL_OVERFLOW) {
118736 + rhs1 = gimple_assign_rhs1(stmt);
118737 + insert_cast(visited, stmt, rhs1);
118738 + }
118739 +
118740 + if (type == NO_INTENTIONAL_OVERFLOW || type == RHS2_INTENTIONAL_OVERFLOW) {
118741 + rhs2 = gimple_assign_rhs2(stmt);
118742 + insert_cast(visited, stmt, rhs2);
118743 + }
118744 +}
118745 +
118746 diff --git a/tools/gcc/size_overflow_plugin/size_overflow.h b/tools/gcc/size_overflow_plugin/size_overflow.h
118747 new file mode 100644
118748 index 0000000..e5b4e50
118749 --- /dev/null
118750 +++ b/tools/gcc/size_overflow_plugin/size_overflow.h
118751 @@ -0,0 +1,127 @@
118752 +#ifndef SIZE_OVERFLOW_H
118753 +#define SIZE_OVERFLOW_H
118754 +
118755 +#define CREATE_NEW_VAR NULL_TREE
118756 +#define CANNOT_FIND_ARG 32
118757 +#define MAX_PARAM 31
118758 +#define BEFORE_STMT true
118759 +#define AFTER_STMT false
118760 +
118761 +#define TURN_OFF_ASM_STR "# size_overflow MARK_TURN_OFF "
118762 +#define YES_ASM_STR "# size_overflow MARK_YES "
118763 +#define OK_ASM_STR "# size_overflow "
118764 +
118765 +enum mark {
118766 + MARK_NO, MARK_YES, MARK_NOT_INTENTIONAL, MARK_TURN_OFF
118767 +};
118768 +
118769 +enum intentional_overflow_type {
118770 + NO_INTENTIONAL_OVERFLOW, RHS1_INTENTIONAL_OVERFLOW, RHS2_INTENTIONAL_OVERFLOW
118771 +};
118772 +
118773 +struct visited {
118774 + struct pointer_set_t *stmts;
118775 + struct pointer_set_t *my_stmts;
118776 + struct pointer_set_t *skip_expr_casts;
118777 + struct pointer_set_t *no_cast_check;
118778 +};
118779 +
118780 +// size_overflow_plugin.c
118781 +extern tree report_size_overflow_decl;
118782 +extern tree size_overflow_type_HI;
118783 +extern tree size_overflow_type_SI;
118784 +extern tree size_overflow_type_DI;
118785 +extern tree size_overflow_type_TI;
118786 +
118787 +
118788 +// size_overflow_plugin_hash.c
118789 +struct size_overflow_hash {
118790 + const struct size_overflow_hash * const next;
118791 + const char * const name;
118792 + const unsigned int param;
118793 +};
118794 +
118795 +struct interesting_node {
118796 + struct interesting_node *next;
118797 + gimple first_stmt;
118798 + const_tree fndecl;
118799 + tree node;
118800 +#if BUILDING_GCC_VERSION <= 4007
118801 + VEC(tree, gc) *last_nodes;
118802 +#else
118803 + vec<tree, va_gc> *last_nodes;
118804 +#endif
118805 + unsigned int num;
118806 + enum mark intentional_attr_decl;
118807 + enum mark intentional_attr_cur_fndecl;
118808 + gimple intentional_mark_from_gimple;
118809 +};
118810 +
118811 +extern bool is_size_overflow_asm(const_gimple stmt);
118812 +extern unsigned int get_function_num(const_tree node, const_tree orig_fndecl);
118813 +extern unsigned int get_correct_arg_count(unsigned int argnum, const_tree fndecl);
118814 +extern bool is_missing_function(const_tree orig_fndecl, unsigned int num);
118815 +extern bool is_a_return_check(const_tree node);
118816 +extern const struct size_overflow_hash *get_function_hash(const_tree fndecl);
118817 +extern unsigned int find_arg_number_tree(const_tree arg, const_tree func);
118818 +
118819 +
118820 +// size_overflow_debug.c
118821 +extern struct opt_pass *make_dump_pass(void);
118822 +
118823 +
118824 +// intentional_overflow.c
118825 +extern enum mark get_intentional_attr_type(const_tree node);
118826 +extern bool is_size_overflow_intentional_asm_yes(const_gimple stmt);
118827 +extern bool is_size_overflow_intentional_asm_turn_off(const_gimple stmt);
118828 +extern bool is_end_intentional_intentional_attr(const_tree decl, unsigned int argnum);
118829 +extern bool is_yes_intentional_attr(const_tree decl, unsigned int argnum);
118830 +extern bool is_turn_off_intentional_attr(const_tree decl);
118831 +extern void print_missing_intentional(enum mark callee_attr, enum mark caller_attr, const_tree decl, unsigned int argnum);
118832 +extern void check_intentional_attribute_ipa(struct interesting_node *cur_node);
118833 +extern bool is_a_cast_and_const_overflow(const_tree no_const_rhs);
118834 +extern bool is_const_plus_unsigned_signed_truncation(const_tree lhs);
118835 +extern bool is_a_constant_overflow(const_gimple stmt, const_tree rhs);
118836 +extern tree handle_intentional_overflow(struct visited *visited, struct cgraph_node *caller_node, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs2);
118837 +extern tree handle_integer_truncation(struct visited *visited, struct cgraph_node *caller_node, const_tree lhs);
118838 +extern bool is_a_neg_overflow(const_gimple stmt, const_tree rhs);
118839 +extern enum intentional_overflow_type add_mul_intentional_overflow(const_gimple def_stmt);
118840 +extern void unsigned_signed_cast_intentional_overflow(struct visited *visited, gimple stmt);
118841 +
118842 +
118843 +// insert_size_overflow_check_ipa.c
118844 +extern unsigned int search_function(void);
118845 +extern unsigned int call_count;
118846 +extern struct opt_pass *make_insert_size_overflow_check(void);
118847 +extern const_tree get_interesting_orig_fndecl(const_gimple stmt, unsigned int argnum);
118848 +
118849 +
118850 +// insert_size_overflow_asm.c
118851 +extern struct opt_pass *make_insert_size_overflow_asm_pass(void);
118852 +
118853 +
118854 +// misc.c
118855 +extern void set_current_function_decl(tree fndecl);
118856 +extern void unset_current_function_decl(void);
118857 +extern gimple get_def_stmt(const_tree node);
118858 +extern tree create_new_var(tree type);
118859 +extern gimple build_cast_stmt(struct visited *visited, tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before, bool force);
118860 +extern bool skip_types(const_tree var);
118861 +extern tree cast_a_tree(tree type, tree var);
118862 +extern bool is_size_overflow_type(const_tree var);
118863 +
118864 +
118865 +// insert_size_overflow_check_core.c
118866 +extern tree expand(struct visited *visited, struct cgraph_node *caller_node, tree lhs);
118867 +extern void check_size_overflow(struct cgraph_node *caller_node, gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before);
118868 +extern tree dup_assign(struct visited *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3);
118869 +extern tree create_assign(struct visited *visited, gimple oldstmt, tree rhs1, bool before);
118870 +
118871 +
118872 +// remove_unnecessary_dup.c
118873 +extern struct opt_pass *make_remove_unnecessary_dup_pass(void);
118874 +extern void insert_cast_expr(struct visited *visited, gimple stmt, enum intentional_overflow_type type);
118875 +extern bool skip_expr_on_double_type(const_gimple stmt);
118876 +extern void create_up_and_down_cast(struct visited *visited, gimple use_stmt, tree orig_type, tree rhs);
118877 +
118878 +#endif
118879 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_debug.c b/tools/gcc/size_overflow_plugin/size_overflow_debug.c
118880 new file mode 100644
118881 index 0000000..4378111
118882 --- /dev/null
118883 +++ b/tools/gcc/size_overflow_plugin/size_overflow_debug.c
118884 @@ -0,0 +1,116 @@
118885 +/*
118886 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
118887 + * Licensed under the GPL v2, or (at your option) v3
118888 + *
118889 + * Homepage:
118890 + * http://www.grsecurity.net/~ephox/overflow_plugin/
118891 + *
118892 + * Documentation:
118893 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
118894 + *
118895 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
118896 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
118897 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
118898 + *
118899 + * Usage:
118900 + * $ make
118901 + * $ make run
118902 + */
118903 +
118904 +#include "gcc-common.h"
118905 +
118906 +static unsigned int dump_functions(void)
118907 +{
118908 + struct cgraph_node *node;
118909 +
118910 + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) {
118911 + basic_block bb;
118912 +
118913 + push_cfun(DECL_STRUCT_FUNCTION(NODE_DECL(node)));
118914 + current_function_decl = NODE_DECL(node);
118915 +
118916 + fprintf(stderr, "-----------------------------------------\n%s\n-----------------------------------------\n", DECL_NAME_POINTER(current_function_decl));
118917 +
118918 + FOR_ALL_BB_FN(bb, cfun) {
118919 + gimple_stmt_iterator si;
118920 +
118921 + fprintf(stderr, "<bb %u>:\n", bb->index);
118922 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
118923 + debug_gimple_stmt(gsi_stmt(si));
118924 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
118925 + debug_gimple_stmt(gsi_stmt(si));
118926 + fprintf(stderr, "\n");
118927 + }
118928 +
118929 + fprintf(stderr, "-------------------------------------------------------------------------\n");
118930 +
118931 + pop_cfun();
118932 + current_function_decl = NULL_TREE;
118933 + }
118934 +
118935 + fprintf(stderr, "###############################################################################\n");
118936 +
118937 + return 0;
118938 +}
118939 +
118940 +#if BUILDING_GCC_VERSION >= 4009
118941 +static const struct pass_data dump_pass_data = {
118942 +#else
118943 +static struct ipa_opt_pass_d dump_pass = {
118944 + .pass = {
118945 +#endif
118946 + .type = SIMPLE_IPA_PASS,
118947 + .name = "dump",
118948 +#if BUILDING_GCC_VERSION >= 4008
118949 + .optinfo_flags = OPTGROUP_NONE,
118950 +#endif
118951 +#if BUILDING_GCC_VERSION >= 4009
118952 + .has_gate = false,
118953 + .has_execute = true,
118954 +#else
118955 + .gate = NULL,
118956 + .execute = dump_functions,
118957 + .sub = NULL,
118958 + .next = NULL,
118959 + .static_pass_number = 0,
118960 +#endif
118961 + .tv_id = TV_NONE,
118962 + .properties_required = 0,
118963 + .properties_provided = 0,
118964 + .properties_destroyed = 0,
118965 + .todo_flags_start = 0,
118966 + .todo_flags_finish = 0,
118967 +#if BUILDING_GCC_VERSION < 4009
118968 + },
118969 + .generate_summary = NULL,
118970 + .write_summary = NULL,
118971 + .read_summary = NULL,
118972 +#if BUILDING_GCC_VERSION >= 4006
118973 + .write_optimization_summary = NULL,
118974 + .read_optimization_summary = NULL,
118975 +#endif
118976 + .stmt_fixup = NULL,
118977 + .function_transform_todo_flags_start = 0,
118978 + .function_transform = NULL,
118979 + .variable_transform = NULL,
118980 +#endif
118981 +};
118982 +
118983 +#if BUILDING_GCC_VERSION >= 4009
118984 +namespace {
118985 +class dump_pass : public ipa_opt_pass_d {
118986 +public:
118987 + dump_pass() : ipa_opt_pass_d(dump_pass_data, g, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL) {}
118988 + unsigned int execute() { return dump_functions(); }
118989 +};
118990 +}
118991 +#endif
118992 +
118993 +struct opt_pass *make_dump_pass(void)
118994 +{
118995 +#if BUILDING_GCC_VERSION >= 4009
118996 + return new dump_pass();
118997 +#else
118998 + return &dump_pass.pass;
118999 +#endif
119000 +}
119001 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_hash.data b/tools/gcc/size_overflow_plugin/size_overflow_hash.data
119002 new file mode 100644
119003 index 0000000..9addbd7
119004 --- /dev/null
119005 +++ b/tools/gcc/size_overflow_plugin/size_overflow_hash.data
119006 @@ -0,0 +1,5912 @@
119007 +intel_fake_agp_alloc_by_type_1 intel_fake_agp_alloc_by_type 1 1 NULL
119008 +storvsc_connect_to_vsp_22 storvsc_connect_to_vsp 2 22 NULL
119009 +compat_sock_setsockopt_23 compat_sock_setsockopt 5 23 NULL
119010 +carl9170_alloc_27 carl9170_alloc 1 27 NULL
119011 +sel_read_policyvers_55 sel_read_policyvers 3 55 NULL nohasharray
119012 +padzero_55 padzero 1 55 &sel_read_policyvers_55
119013 +cfg80211_disconnected_57 cfg80211_disconnected 4 57 NULL
119014 +__skb_to_sgvec_72 __skb_to_sgvec 0 72 NULL
119015 +snd_korg1212_copy_to_92 snd_korg1212_copy_to 6 92 NULL
119016 +load_msg_95 load_msg 2 95 NULL
119017 +ipath_verbs_send_117 ipath_verbs_send 5-3 117 NULL
119018 +init_q_132 init_q 4 132 NULL
119019 +memstick_alloc_host_142 memstick_alloc_host 1 142 NULL
119020 +hva_to_gfn_memslot_149 hva_to_gfn_memslot 0-1 149 NULL
119021 +ping_v6_sendmsg_152 ping_v6_sendmsg 4 152 NULL
119022 +ext4_ext_get_actual_len_153 ext4_ext_get_actual_len 0 153 NULL nohasharray
119023 +tracing_trace_options_write_153 tracing_trace_options_write 3 153 &ext4_ext_get_actual_len_153
119024 +xfs_buf_item_get_format_189 xfs_buf_item_get_format 2 189 NULL
119025 +iscsi_session_setup_196 iscsi_session_setup 4-5 196 NULL
119026 +obd_proc_jobid_var_seq_write_199 obd_proc_jobid_var_seq_write 3 199 NULL
119027 +ll_xattr_cache_seq_write_250 ll_xattr_cache_seq_write 3 250 NULL
119028 +br_port_info_size_268 br_port_info_size 0 268 NULL
119029 +read_file_war_stats_292 read_file_war_stats 3 292 NULL
119030 +SYSC_connect_304 SYSC_connect 3 304 NULL
119031 +syslog_print_307 syslog_print 2 307 NULL
119032 +dn_setsockopt_314 dn_setsockopt 5 314 NULL
119033 +mlx5_core_access_reg_361 mlx5_core_access_reg 3-5 361 NULL
119034 +aio_read_events_ring_410 aio_read_events_ring 3-0 410 NULL
119035 +lbs_rdmac_read_418 lbs_rdmac_read 3 418 NULL
119036 +snd_ca0106_ptr_read_467 snd_ca0106_ptr_read 0 467 NULL
119037 +cfs_trace_set_debug_mb_usrstr_486 cfs_trace_set_debug_mb_usrstr 2 486 NULL
119038 +nvme_trans_modesel_data_488 nvme_trans_modesel_data 4 488 NULL
119039 +iwl_dbgfs_protection_mode_write_502 iwl_dbgfs_protection_mode_write 3 502 NULL
119040 +rx_rx_defrag_end_read_505 rx_rx_defrag_end_read 3 505 NULL
119041 +ocfs2_validate_meta_ecc_bhs_527 ocfs2_validate_meta_ecc_bhs 0 527 NULL
119042 +zlib_deflate_workspacesize_537 zlib_deflate_workspacesize 0-1-2 537 NULL
119043 +iwl_dbgfs_wowlan_sram_read_540 iwl_dbgfs_wowlan_sram_read 3 540 NULL
119044 +sco_sock_setsockopt_552 sco_sock_setsockopt 5 552 NULL
119045 +lpfc_nlp_state_name_556 lpfc_nlp_state_name 2 556 NULL
119046 +snd_aw2_saa7146_get_hw_ptr_playback_558 snd_aw2_saa7146_get_hw_ptr_playback 0 558 NULL
119047 +start_isoc_chain_565 start_isoc_chain 2 565 NULL nohasharray
119048 +dev_hard_header_565 dev_hard_header 0 565 &start_isoc_chain_565
119049 +smk_write_load_self2_591 smk_write_load_self2 3 591 NULL
119050 +btrfs_stack_file_extent_offset_607 btrfs_stack_file_extent_offset 0 607 NULL
119051 +ni_gpct_device_construct_610 ni_gpct_device_construct 5 610 NULL
119052 +fuse_request_alloc_nofs_617 fuse_request_alloc_nofs 1 617 NULL
119053 +ptlrpc_lprocfs_nrs_seq_write_621 ptlrpc_lprocfs_nrs_seq_write 3 621 NULL
119054 +viafb_dfpl_proc_write_627 viafb_dfpl_proc_write 3 627 NULL
119055 +ceph_osdc_new_request_635 ceph_osdc_new_request 6 635 NULL
119056 +cfs_hash_bkt_size_643 cfs_hash_bkt_size 0 643 NULL
119057 +unlink_queued_645 unlink_queued 4 645 NULL
119058 +dtim_interval_read_654 dtim_interval_read 3 654 NULL
119059 +nvif_notify_new_671 nvif_notify_new 6 671 NULL
119060 +mem_rx_free_mem_blks_read_675 mem_rx_free_mem_blks_read 3 675 NULL
119061 +persistent_ram_vmap_709 persistent_ram_vmap 2-1 709 NULL
119062 +sctp_setsockopt_peer_addr_params_734 sctp_setsockopt_peer_addr_params 3 734 NULL
119063 +dvb_video_write_754 dvb_video_write 3 754 NULL
119064 +cfs_trace_allocate_string_buffer_781 cfs_trace_allocate_string_buffer 2 781 NULL
119065 +ath6kl_disconnect_timeout_write_794 ath6kl_disconnect_timeout_write 3 794 NULL
119066 +if_writecmd_815 if_writecmd 2 815 NULL
119067 +aac_change_queue_depth_825 aac_change_queue_depth 2 825 NULL
119068 +error_state_read_859 error_state_read 6 859 NULL
119069 +lustre_init_msg_v2_864 lustre_init_msg_v2 2 864 NULL
119070 +o2net_send_message_vec_879 o2net_send_message_vec 4 879 NULL nohasharray
119071 +iwl_dbgfs_fh_reg_read_879 iwl_dbgfs_fh_reg_read 3 879 &o2net_send_message_vec_879
119072 +snd_pcm_action_single_905 snd_pcm_action_single 0 905 NULL
119073 +carl9170_cmd_buf_950 carl9170_cmd_buf 3 950 NULL
119074 +__nodes_weight_956 __nodes_weight 2-0 956 NULL
119075 +bnx2x_fill_fw_str_968 bnx2x_fill_fw_str 3 968 NULL
119076 +usnic_ib_qp_grp_dump_hdr_989 usnic_ib_qp_grp_dump_hdr 2 989 NULL
119077 +readreg_1017 readreg 0-1 1017 NULL
119078 +smk_write_cipso2_1021 smk_write_cipso2 3 1021 NULL
119079 +gigaset_initdriver_1060 gigaset_initdriver 2 1060 NULL
119080 +mce_request_packet_1073 mce_request_packet 3 1073 NULL
119081 +agp_create_memory_1075 agp_create_memory 1 1075 NULL
119082 +_scsih_adjust_queue_depth_1083 _scsih_adjust_queue_depth 2 1083 NULL
119083 +llcp_sock_sendmsg_1092 llcp_sock_sendmsg 4 1092 NULL
119084 +nfs4_init_nonuniform_client_string_1097 nfs4_init_nonuniform_client_string 3 1097 NULL
119085 +__arch_hweight8_1105 __arch_hweight8 0 1105 NULL
119086 +utf8s_to_utf16s_1115 utf8s_to_utf16s 0 1115 NULL
119087 +cfg80211_report_obss_beacon_1133 cfg80211_report_obss_beacon 3 1133 NULL
119088 +i2400m_rx_ctl_1157 i2400m_rx_ctl 4 1157 NULL
119089 +ipc_alloc_1192 ipc_alloc 1 1192 NULL
119090 +ib_create_send_mad_1196 ib_create_send_mad 5 1196 NULL
119091 +pstore_ftrace_knob_write_1198 pstore_ftrace_knob_write 3 1198 NULL
119092 +i2400m_rx_ctl_ack_1199 i2400m_rx_ctl_ack 3 1199 NULL
119093 +dgrp_dpa_read_1204 dgrp_dpa_read 3 1204 NULL
119094 +i2cdev_read_1206 i2cdev_read 3 1206 NULL
119095 +lov_ost_pool_init_1215 lov_ost_pool_init 2 1215 NULL
119096 +kernfs_file_direct_read_1238 kernfs_file_direct_read 3 1238 NULL
119097 +acpi_battery_write_alarm_1240 acpi_battery_write_alarm 3 1240 NULL
119098 +drm_primary_helper_create_plane_1262 drm_primary_helper_create_plane 3 1262 NULL
119099 +ocfs2_extend_file_1266 ocfs2_extend_file 3 1266 NULL
119100 +qla4xxx_change_queue_depth_1268 qla4xxx_change_queue_depth 2 1268 NULL
119101 +ioctl_private_iw_point_1273 ioctl_private_iw_point 7 1273 NULL
119102 +SyS_flistxattr_1287 SyS_flistxattr 3 1287 NULL
119103 +tx_frag_in_process_called_read_1290 tx_frag_in_process_called_read 3 1290 NULL
119104 +posix_acl_xattr_set_1301 posix_acl_xattr_set 4 1301 NULL
119105 +ffs_1322 ffs 0 1322 NULL
119106 +qlcnic_pci_sriov_configure_1327 qlcnic_pci_sriov_configure 2 1327 NULL
119107 +btrfs_submit_compressed_write_1347 btrfs_submit_compressed_write 5 1347 NULL
119108 +bond_verify_device_path_1352 bond_verify_device_path 3 1352 NULL
119109 +snd_pcm_lib_write1_1358 snd_pcm_lib_write1 0-3 1358 NULL
119110 +ipx_sendmsg_1362 ipx_sendmsg 4 1362 NULL
119111 +fw_stats_raw_read_1369 fw_stats_raw_read 3 1369 NULL
119112 +ocfs2_prepare_inode_for_write_1372 ocfs2_prepare_inode_for_write 3 1372 NULL
119113 +xpcs_reg_addr_read_1381 xpcs_reg_addr_read 3 1381 NULL
119114 +sctp_setsockopt_initmsg_1383 sctp_setsockopt_initmsg 3 1383 NULL
119115 +do_msgsnd_1387 do_msgsnd 4 1387 NULL
119116 +SYSC_io_getevents_1392 SYSC_io_getevents 3 1392 NULL
119117 +cfs_trace_copyout_string_1416 cfs_trace_copyout_string 2 1416 NULL
119118 +init_rs_internal_1436 init_rs_internal 1 1436 NULL
119119 +stack_max_size_read_1445 stack_max_size_read 3 1445 NULL
119120 +tx_queue_len_read_1463 tx_queue_len_read 3 1463 NULL
119121 +xprt_alloc_1475 xprt_alloc 2 1475 NULL
119122 +SYSC_syslog_1477 SYSC_syslog 3 1477 NULL
119123 +sta_num_ps_buf_frames_read_1488 sta_num_ps_buf_frames_read 3 1488 NULL
119124 +fpregs_set_1497 fpregs_set 4 1497 NULL
119125 +tomoyo_round2_1518 tomoyo_round2 0 1518 NULL
119126 +alloc_perm_bits_1532 alloc_perm_bits 2 1532 NULL
119127 +ath6kl_init_get_fwcaps_1557 ath6kl_init_get_fwcaps 3 1557 NULL
119128 +ffs_mutex_lock_1564 ffs_mutex_lock 0 1564 NULL
119129 +ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime_1589 ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime 3 1589 NULL
119130 +ipath_ht_handle_hwerrors_1592 ipath_ht_handle_hwerrors 3 1592 NULL
119131 +packet_buffer_init_1607 packet_buffer_init 2 1607 NULL
119132 +btmrvl_hscmd_read_1614 btmrvl_hscmd_read 3 1614 NULL
119133 +v9fs_fid_xattr_get_1618 v9fs_fid_xattr_get 0 1618 NULL
119134 +ikconfig_read_current_1658 ikconfig_read_current 3 1658 NULL
119135 +mei_cl_recv_1665 mei_cl_recv 3 1665 NULL
119136 +rmap_add_1677 rmap_add 3 1677 NULL
119137 +configfs_read_file_1683 configfs_read_file 3 1683 NULL
119138 +iwl_dbgfs_d0i3_refs_read_1705 iwl_dbgfs_d0i3_refs_read 3 1705 NULL
119139 +pdu_write_u_1710 pdu_write_u 3 1710 NULL
119140 +coda_psdev_write_1711 coda_psdev_write 3 1711 NULL
119141 +btrfs_dir_data_len_1714 btrfs_dir_data_len 0 1714 NULL
119142 +internal_create_group_1733 internal_create_group 0 1733 NULL
119143 +dev_irnet_read_1741 dev_irnet_read 3 1741 NULL
119144 +usb_ep_align_maybe_1743 usb_ep_align_maybe 0-3 1743 NULL
119145 +tx_frag_called_read_1748 tx_frag_called_read 3 1748 NULL
119146 +cosa_write_1774 cosa_write 3 1774 NULL
119147 +fcoe_ctlr_device_add_1793 fcoe_ctlr_device_add 3 1793 NULL
119148 +__nodelist_scnprintf_1815 __nodelist_scnprintf 2-0 1815 NULL
119149 +sb_issue_zeroout_1884 sb_issue_zeroout 3 1884 NULL
119150 +rx_defrag_called_read_1897 rx_defrag_called_read 3 1897 NULL
119151 +nfs_parse_server_name_1899 nfs_parse_server_name 2 1899 NULL
119152 +SyS_add_key_1900 SyS_add_key 4 1900 NULL
119153 +uhid_char_read_1920 uhid_char_read 3 1920 NULL
119154 +tx_tx_retry_data_read_1926 tx_tx_retry_data_read 3 1926 NULL
119155 +azx_get_position_1927 azx_get_position 0 1927 NULL
119156 +bdev_erase_1933 bdev_erase 3 1933 NULL
119157 +ext3_fiemap_1936 ext3_fiemap 4 1936 NULL
119158 +cyttsp_probe_1940 cyttsp_probe 4 1940 NULL nohasharray
119159 +nvif_object_sclass_1940 nvif_object_sclass 3 1940 &cyttsp_probe_1940
119160 +ieee80211_if_fmt_dot11MeshConfirmTimeout_1945 ieee80211_if_fmt_dot11MeshConfirmTimeout 3 1945 NULL
119161 +ivtv_v4l2_read_1964 ivtv_v4l2_read 3 1964 NULL
119162 +sel_read_avc_hash_stats_1984 sel_read_avc_hash_stats 3 1984 NULL
119163 +gpio_power_write_1991 gpio_power_write 3 1991 NULL
119164 +__alloc_bootmem_node_1992 __alloc_bootmem_node 2 1992 NULL
119165 +rx_rx_defrag_read_2010 rx_rx_defrag_read 3 2010 NULL
119166 +ocfs2_global_qinit_alloc_2018 ocfs2_global_qinit_alloc 0 2018 NULL
119167 +write_flush_pipefs_2021 write_flush_pipefs 3 2021 NULL
119168 +BcmCopySection_2035 BcmCopySection 5 2035 NULL
119169 +ath6kl_fwlog_mask_read_2050 ath6kl_fwlog_mask_read 3 2050 NULL
119170 +ocfs2_expand_inline_dir_2063 ocfs2_expand_inline_dir 3 2063 NULL
119171 +__generic_copy_from_user_intel_2073 __generic_copy_from_user_intel 0-3 2073 NULL
119172 +diva_set_driver_dbg_mask_2077 diva_set_driver_dbg_mask 0 2077 NULL
119173 +iwl_dbgfs_current_sleep_command_read_2081 iwl_dbgfs_current_sleep_command_read 3 2081 NULL
119174 +xgmac_reg_value_read_2095 xgmac_reg_value_read 3 2095 NULL
119175 +idetape_chrdev_read_2097 idetape_chrdev_read 3 2097 NULL
119176 +audit_expand_2098 audit_expand 0 2098 NULL
119177 +__set_print_fmt_2106 __set_print_fmt 0 2106 NULL
119178 +iwl_dbgfs_log_event_read_2107 iwl_dbgfs_log_event_read 3 2107 NULL
119179 +ecryptfs_encrypt_and_encode_filename_2109 ecryptfs_encrypt_and_encode_filename 6 2109 NULL
119180 +btrfs_file_extent_inline_len_2116 btrfs_file_extent_inline_len 0 2116 NULL
119181 +enable_read_2117 enable_read 3 2117 NULL
119182 +pcf50633_write_block_2124 pcf50633_write_block 2-3 2124 NULL
119183 +check_load_and_stores_2143 check_load_and_stores 2 2143 NULL
119184 +iov_iter_count_2152 iov_iter_count 0 2152 NULL
119185 +__copy_to_user_ll_2157 __copy_to_user_ll 0-3 2157 NULL
119186 +_ore_get_io_state_2166 _ore_get_io_state 3-4-5 2166 NULL
119187 +bio_integrity_alloc_2194 bio_integrity_alloc 3 2194 NULL
119188 +picolcd_debug_reset_write_2195 picolcd_debug_reset_write 3 2195 NULL
119189 +u32_array_read_2219 u32_array_read 3 2219 NULL nohasharray
119190 +mei_dbgfs_read_meclients_2219 mei_dbgfs_read_meclients 3 2219 &u32_array_read_2219
119191 +ieee80211_if_read_dot11MeshHWMPRannInterval_2249 ieee80211_if_read_dot11MeshHWMPRannInterval 3 2249 NULL
119192 +netlbl_secattr_catmap_walk_2255 netlbl_secattr_catmap_walk 0-2 2255 NULL
119193 +sel_write_avc_cache_threshold_2256 sel_write_avc_cache_threshold 3 2256 NULL
119194 +do_update_counters_2259 do_update_counters 4 2259 NULL
119195 +ath6kl_wmi_bssinfo_event_rx_2275 ath6kl_wmi_bssinfo_event_rx 3 2275 NULL
119196 +debug_debug5_read_2291 debug_debug5_read 3 2291 NULL
119197 +sr_read_cmd_2299 sr_read_cmd 5 2299 NULL
119198 +kvm_clear_guest_page_2308 kvm_clear_guest_page 4 2308 NULL
119199 +intel_sdvo_set_value_2311 intel_sdvo_set_value 4 2311 NULL
119200 +hfsplus_find_init_2318 hfsplus_find_init 0 2318 NULL nohasharray
119201 +picolcd_fb_write_2318 picolcd_fb_write 3 2318 &hfsplus_find_init_2318
119202 +dice_hwdep_read_2326 dice_hwdep_read 3 2326 NULL
119203 +__erst_read_to_erange_2341 __erst_read_to_erange 0 2341 NULL
119204 +zr364xx_read_2354 zr364xx_read 3 2354 NULL
119205 +viafb_iga2_odev_proc_write_2363 viafb_iga2_odev_proc_write 3 2363 NULL
119206 +xfs_buf_map_from_irec_2368 xfs_buf_map_from_irec 5 2368 NULL nohasharray
119207 +rose_recvmsg_2368 rose_recvmsg 4 2368 &xfs_buf_map_from_irec_2368
119208 +il_dbgfs_sensitivity_read_2370 il_dbgfs_sensitivity_read 3 2370 NULL
119209 +rxpipe_rx_prep_beacon_drop_read_2403 rxpipe_rx_prep_beacon_drop_read 3 2403 NULL
119210 +isdn_v110_open_2418 isdn_v110_open 3 2418 NULL
119211 +raid1_size_2419 raid1_size 0-2 2419 NULL
119212 +b43legacy_debugfs_read_2473 b43legacy_debugfs_read 3 2473 NULL
119213 +wiphy_new_2482 wiphy_new 2 2482 NULL
119214 +bio_alloc_bioset_2484 bio_alloc_bioset 2 2484 NULL
119215 +squashfs_read_fragment_index_table_2506 squashfs_read_fragment_index_table 4 2506 NULL
119216 +v9fs_cached_file_read_2514 v9fs_cached_file_read 3 2514 NULL
119217 +ext4_get_inode_loc_2516 ext4_get_inode_loc 0 2516 NULL
119218 +batadv_tvlv_container_list_size_2524 batadv_tvlv_container_list_size 0 2524 NULL
119219 +smk_write_syslog_2529 smk_write_syslog 3 2529 NULL
119220 +__ceph_setxattr_2532 __ceph_setxattr 4 2532 NULL
119221 +sfw_create_rpc_2562 sfw_create_rpc 4 2562 NULL
119222 +gspca_dev_probe_2570 gspca_dev_probe 4 2570 NULL
119223 +pcm_sanity_check_2574 pcm_sanity_check 0 2574 NULL
119224 +mdc_max_rpcs_in_flight_seq_write_2594 mdc_max_rpcs_in_flight_seq_write 3 2594 NULL
119225 +slot_bytes_2609 slot_bytes 0 2609 NULL
119226 +smk_write_logging_2618 smk_write_logging 3 2618 NULL
119227 +switch_status_2629 switch_status 5 2629 NULL
119228 +_proc_do_string_2632 _proc_do_string 2 2632 NULL
119229 +tcp_xmit_size_goal_2661 tcp_xmit_size_goal 2 2661 NULL
119230 +osc_build_ppga_2670 osc_build_ppga 2 2670 NULL
119231 +ffs_ep0_read_2672 ffs_ep0_read 3 2672 NULL
119232 +oti6858_write_2692 oti6858_write 4 2692 NULL
119233 +nfc_llcp_send_ui_frame_2702 nfc_llcp_send_ui_frame 5 2702 NULL
119234 +memcpy_fromiovecend_2707 memcpy_fromiovecend 3-4 2707 NULL
119235 +lprocfs_stats_counter_size_2708 lprocfs_stats_counter_size 0 2708 NULL
119236 +xfs_readdir_2767 xfs_readdir 3 2767 NULL
119237 +fsl_edma_alloc_desc_2769 fsl_edma_alloc_desc 2 2769 NULL
119238 +mon_bin_ioctl_2771 mon_bin_ioctl 3 2771 NULL
119239 +set_msr_hyperv_pw_2785 set_msr_hyperv_pw 3 2785 NULL
119240 +device_add_attrs_2789 device_add_attrs 0 2789 NULL
119241 +iwl_dbgfs_clear_ucode_statistics_write_2804 iwl_dbgfs_clear_ucode_statistics_write 3 2804 NULL
119242 +sel_read_enforce_2828 sel_read_enforce 3 2828 NULL
119243 +vb2_dc_get_userptr_2829 vb2_dc_get_userptr 2-3 2829 NULL
119244 +sock_create_2838 sock_create 0 2838 NULL
119245 +wait_for_avail_2847 wait_for_avail 0 2847 NULL
119246 +sfq_alloc_2861 sfq_alloc 1 2861 NULL
119247 +irnet_ctrl_read_2863 irnet_ctrl_read 4 2863 NULL
119248 +move_addr_to_user_2868 move_addr_to_user 2 2868 NULL
119249 +nla_padlen_2883 nla_padlen 1 2883 NULL
119250 +cmm_write_2896 cmm_write 3 2896 NULL
119251 +osc_import_seq_write_2923 osc_import_seq_write 3 2923 NULL
119252 +xfs_trans_get_buf_map_2927 xfs_trans_get_buf_map 4 2927 NULL
119253 +nes_read_indexed_2946 nes_read_indexed 0 2946 NULL
119254 +tm6000_i2c_recv_regs16_2949 tm6000_i2c_recv_regs16 5 2949 NULL
119255 +i40e_dbg_prep_dump_buf_2951 i40e_dbg_prep_dump_buf 2 2951 NULL
119256 +set_fast_connectable_2952 set_fast_connectable 4 2952 NULL
119257 +free_area_init_core_2962 free_area_init_core 2-3 2962 NULL
119258 +bio_setup_sector_2970 bio_setup_sector 3 2970 NULL
119259 +do_strnlen_user_2976 do_strnlen_user 0-2 2976 NULL
119260 +p9_nr_pages_2992 p9_nr_pages 0-2 2992 NULL
119261 +lov_stripetype_seq_write_3013 lov_stripetype_seq_write 3 3013 NULL
119262 +do_dmabuf_dirty_sou_3017 do_dmabuf_dirty_sou 7 3017 NULL
119263 +depth_write_3021 depth_write 3 3021 NULL
119264 +snd_azf3328_codec_inl_3022 snd_azf3328_codec_inl 0 3022 NULL
119265 +nvme_split_and_submit_3027 nvme_split_and_submit 3 3027 NULL
119266 +kvm_unmap_hva_3028 kvm_unmap_hva 2 3028 NULL
119267 +xfrm_dst_alloc_copy_3034 xfrm_dst_alloc_copy 3 3034 NULL
119268 +lpfc_idiag_mbxacc_write_3038 lpfc_idiag_mbxacc_write 3 3038 NULL nohasharray
119269 +iwl_dbgfs_sleep_level_override_read_3038 iwl_dbgfs_sleep_level_override_read 3 3038 &lpfc_idiag_mbxacc_write_3038
119270 +nr_free_buffer_pages_3044 nr_free_buffer_pages 0 3044 NULL
119271 +il3945_ucode_rx_stats_read_3048 il3945_ucode_rx_stats_read 3 3048 NULL
119272 +qp_alloc_ppn_set_3068 qp_alloc_ppn_set 2-4 3068 NULL
119273 +__blk_end_bidi_request_3070 __blk_end_bidi_request 3-4 3070 NULL
119274 +hfsplus_asc2uni_3071 hfsplus_asc2uni 0 3071 NULL nohasharray
119275 +dac960_user_command_proc_write_3071 dac960_user_command_proc_write 3 3071 &hfsplus_asc2uni_3071
119276 +read_file_antenna_diversity_3077 read_file_antenna_diversity 3 3077 NULL
119277 +ttusb2_msg_3100 ttusb2_msg 4 3100 NULL
119278 +rb_alloc_3102 rb_alloc 1 3102 NULL
119279 +ufshcd_get_rsp_upiu_result_3114 ufshcd_get_rsp_upiu_result 0 3114 NULL
119280 +simple_write_to_buffer_3122 simple_write_to_buffer 5-2 3122 NULL
119281 +print_time_3132 print_time 0 3132 NULL
119282 +fill_write_buffer_3142 fill_write_buffer 3 3142 NULL
119283 +CIFSSMBSetPosixACL_3154 CIFSSMBSetPosixACL 5 3154 NULL
119284 +uv_num_possible_blades_3177 uv_num_possible_blades 0 3177 NULL
119285 +pkcs7_sig_note_signature_3178 pkcs7_sig_note_signature 5 3178 NULL
119286 +uinput_ioctl_handler_3181 uinput_ioctl_handler 2 3181 NULL nohasharray
119287 +uvc_video_stats_dump_3181 uvc_video_stats_dump 3 3181 &uinput_ioctl_handler_3181
119288 +compat_do_ip6t_set_ctl_3184 compat_do_ip6t_set_ctl 4 3184 NULL
119289 +mempool_create_node_3191 mempool_create_node 1 3191 NULL
119290 +alloc_context_3194 alloc_context 1 3194 NULL
119291 +shmem_pread_slow_3198 shmem_pread_slow 3-2 3198 NULL
119292 +codec_reg_write_file_3204 codec_reg_write_file 3 3204 NULL
119293 +SyS_sendto_3219 SyS_sendto 6 3219 NULL
119294 +btrfs_prealloc_file_range_3227 btrfs_prealloc_file_range 3 3227 NULL
119295 +kimage_crash_alloc_3233 kimage_crash_alloc 3 3233 NULL
119296 +write_adapter_mem_3234 write_adapter_mem 3 3234 NULL
119297 +do_read_log_to_user_3236 do_read_log_to_user 4 3236 NULL
119298 +ext3_xattr_find_entry_3237 ext3_xattr_find_entry 0 3237 NULL
119299 +key_key_read_3241 key_key_read 3 3241 NULL
119300 +__ilog2_u64_3284 __ilog2_u64 0 3284 NULL
119301 +ieee80211_if_write_beacon_loss_3296 ieee80211_if_write_beacon_loss 3 3296 NULL
119302 +cgroup_name_3300 cgroup_name 3 3300 NULL
119303 +__iovec_copy_from_user_inatomic_3314 __iovec_copy_from_user_inatomic 0-4-3 3314 NULL
119304 +_iwl_dbgfs_d3_sram_write_3315 _iwl_dbgfs_d3_sram_write 3 3315 NULL
119305 +dbDiscardAG_3322 dbDiscardAG 3 3322 NULL
119306 +read_from_oldmem_3337 read_from_oldmem 2 3337 NULL
119307 +sysfs_create_group_3339 sysfs_create_group 0 3339 NULL
119308 +tty_port_register_device_attr_3341 tty_port_register_device_attr 3 3341 NULL
119309 +il_dbgfs_interrupt_read_3351 il_dbgfs_interrupt_read 3 3351 NULL
119310 +gsm_control_rls_3353 gsm_control_rls 3 3353 NULL
119311 +scnprintf_3360 scnprintf 0-2 3360 NULL
119312 +sr_read_3366 sr_read 3 3366 NULL
119313 +mtdchar_writeoob_3393 mtdchar_writeoob 4 3393 NULL
119314 +isdn_readbchan_3401 isdn_readbchan 0-5 3401 NULL
119315 +mei_io_cb_alloc_resp_buf_3414 mei_io_cb_alloc_resp_buf 2 3414 NULL
119316 +pci_add_cap_save_buffer_3426 pci_add_cap_save_buffer 3 3426 NULL
119317 +crystalhd_create_dio_pool_3427 crystalhd_create_dio_pool 2 3427 NULL
119318 +SyS_msgsnd_3436 SyS_msgsnd 3 3436 NULL
119319 +softsynth_write_3455 softsynth_write 3 3455 NULL
119320 +snd_pcm_lib_readv_transfer_3464 snd_pcm_lib_readv_transfer 5-4-2 3464 NULL
119321 +security_context_to_sid_default_3492 security_context_to_sid_default 2 3492 NULL
119322 +xfrm_migrate_msgsize_3496 xfrm_migrate_msgsize 1 3496 NULL
119323 +mem_tx_free_mem_blks_read_3521 mem_tx_free_mem_blks_read 3 3521 NULL
119324 +SyS_semtimedop_3532 SyS_semtimedop 3 3532 NULL
119325 +SyS_readv_3539 SyS_readv 3 3539 NULL
119326 +btrfs_dir_name_len_3549 btrfs_dir_name_len 0 3549 NULL
119327 +alloc_smp_resp_3566 alloc_smp_resp 1 3566 NULL
119328 +evtchn_read_3569 evtchn_read 3 3569 NULL
119329 +ll_track_ppid_seq_write_3582 ll_track_ppid_seq_write 3 3582 NULL
119330 +vc_resize_3585 vc_resize 3-2 3585 NULL
119331 +kvm_mmu_notifier_change_pte_3596 kvm_mmu_notifier_change_pte 3 3596 NULL
119332 +sctp_getsockopt_events_3607 sctp_getsockopt_events 2 3607 NULL
119333 +edac_mc_alloc_3611 edac_mc_alloc 4 3611 NULL
119334 +tx_tx_starts_read_3617 tx_tx_starts_read 3 3617 NULL
119335 +aligned_kmalloc_3628 aligned_kmalloc 1 3628 NULL
119336 +ath6kl_disconnect_timeout_read_3650 ath6kl_disconnect_timeout_read 3 3650 NULL
119337 +i915_compat_ioctl_3656 i915_compat_ioctl 2 3656 NULL
119338 +_iwl_dbgfs_tx_flush_write_3675 _iwl_dbgfs_tx_flush_write 3 3675 NULL
119339 +snd_m3_assp_read_3703 snd_m3_assp_read 0 3703 NULL
119340 +ci_ll_write_3740 ci_ll_write 4 3740 NULL
119341 +msm_otg_mode_write_3788 msm_otg_mode_write 3 3788 NULL
119342 +sctp_setsockopt_auth_key_3793 sctp_setsockopt_auth_key 3 3793 NULL
119343 +ncp_file_write_3813 ncp_file_write 3 3813 NULL
119344 +llc_ui_recvmsg_3826 llc_ui_recvmsg 4 3826 NULL
119345 +create_one_cdev_3852 create_one_cdev 2 3852 NULL
119346 +smk_read_onlycap_3855 smk_read_onlycap 3 3855 NULL
119347 +get_fd_set_3866 get_fd_set 1 3866 NULL
119348 +garp_attr_create_3883 garp_attr_create 3 3883 NULL
119349 +efivarfs_file_read_3893 efivarfs_file_read 3 3893 NULL
119350 +nvram_write_3894 nvram_write 3 3894 NULL
119351 +pipeline_pre_proc_swi_read_3898 pipeline_pre_proc_swi_read 3 3898 NULL
119352 +comedi_buf_read_n_available_3899 comedi_buf_read_n_available 0 3899 NULL
119353 +vcs_write_3910 vcs_write 3 3910 NULL
119354 +SyS_move_pages_3920 SyS_move_pages 2 3920 NULL
119355 +hdlc_irq_one_3944 hdlc_irq_one 2 3944 NULL
119356 +brcmf_debugfs_fws_stats_read_3947 brcmf_debugfs_fws_stats_read 3 3947 NULL
119357 +mite_bytes_written_to_memory_lb_3987 mite_bytes_written_to_memory_lb 0 3987 NULL
119358 +copy_from_user_atomic_iovec_3990 copy_from_user_atomic_iovec 0-4 3990 NULL
119359 +do_add_counters_3992 do_add_counters 3 3992 NULL
119360 +userspace_status_4004 userspace_status 4 4004 NULL
119361 +xfs_check_block_4005 xfs_check_block 4 4005 NULL nohasharray
119362 +mei_write_4005 mei_write 3 4005 &xfs_check_block_4005
119363 +snd_hdsp_capture_copy_4011 snd_hdsp_capture_copy 5 4011 NULL
119364 +blk_end_request_4024 blk_end_request 3 4024 NULL
119365 +ext4_xattr_find_entry_4025 ext4_xattr_find_entry 0 4025 NULL
119366 +mtip_hw_read_registers_4037 mtip_hw_read_registers 3 4037 NULL
119367 +read_file_queues_4078 read_file_queues 3 4078 NULL
119368 +fbcon_do_set_font_4079 fbcon_do_set_font 2-3 4079 NULL
119369 +C_SYSC_rt_sigpending_4114 C_SYSC_rt_sigpending 2 4114 NULL
119370 +tm6000_read_4151 tm6000_read 3 4151 NULL
119371 +mpt_raid_phys_disk_get_num_paths_4155 mpt_raid_phys_disk_get_num_paths 0 4155 NULL
119372 +msg_bits_4158 msg_bits 0-3-4 4158 NULL
119373 +get_alua_req_4166 get_alua_req 3 4166 NULL
119374 +blk_dropped_read_4168 blk_dropped_read 3 4168 NULL
119375 +read_file_bool_4180 read_file_bool 3 4180 NULL
119376 +lstcon_test_add_4190 lstcon_test_add 10 4190 NULL
119377 +vring_new_virtqueue_4199 vring_new_virtqueue 2 4199 NULL
119378 +f1x_determine_channel_4202 f1x_determine_channel 2 4202 NULL
119379 +_osd_req_list_objects_4204 _osd_req_list_objects 6 4204 NULL
119380 +__snd_gf1_read_addr_4210 __snd_gf1_read_addr 0 4210 NULL
119381 +ath6kl_force_roam_write_4282 ath6kl_force_roam_write 3 4282 NULL
119382 +goldfish_audio_write_4284 goldfish_audio_write 3 4284 NULL
119383 +get_connectors_for_crtc_4291 get_connectors_for_crtc 0 4291 NULL
119384 +__usbnet_read_cmd_4299 __usbnet_read_cmd 7 4299 NULL
119385 +dvb_ringbuffer_pkt_read_user_4303 dvb_ringbuffer_pkt_read_user 2-3-5 4303 NULL
119386 +count_strings_4315 count_strings 0 4315 NULL
119387 +nouveau_fifo_create__4327 nouveau_fifo_create_ 5-6 4327 NULL
119388 +snd_rawmidi_kernel_read_4328 snd_rawmidi_kernel_read 3 4328 NULL
119389 +ima_eventdigest_init_common_4338 ima_eventdigest_init_common 2 4338 NULL
119390 +__copy_from_user_inatomic_4365 __copy_from_user_inatomic 0-3 4365 NULL nohasharray
119391 +lookup_string_4365 lookup_string 0 4365 &__copy_from_user_inatomic_4365
119392 +irda_sendmsg_4388 irda_sendmsg 4 4388 NULL
119393 +access_process_vm_4412 access_process_vm 0 4412 NULL nohasharray
119394 +cxacru_cm_get_array_4412 cxacru_cm_get_array 4 4412 &access_process_vm_4412
119395 +libfc_vport_create_4415 libfc_vport_create 2 4415 NULL
119396 +rtw_android_get_rssi_4421 rtw_android_get_rssi 0 4421 NULL
119397 +do_pages_stat_4437 do_pages_stat 2 4437 NULL
119398 +at76_set_card_command_4471 at76_set_card_command 4 4471 NULL
119399 +snd_seq_expand_var_event_4481 snd_seq_expand_var_event 5-0 4481 NULL
119400 +vmbus_establish_gpadl_4495 vmbus_establish_gpadl 3 4495 NULL
119401 +set_link_security_4502 set_link_security 4 4502 NULL
119402 +ll_max_readahead_per_file_mb_seq_write_4531 ll_max_readahead_per_file_mb_seq_write 3 4531 NULL
119403 +tty_register_device_4544 tty_register_device 2 4544 NULL
119404 +fsl_edma_prep_slave_sg_4555 fsl_edma_prep_slave_sg 3 4555 NULL
119405 +btrfs_file_extent_inline_item_len_4575 btrfs_file_extent_inline_item_len 0 4575 NULL
119406 +xfs_buf_get_maps_4581 xfs_buf_get_maps 2 4581 NULL
119407 +bch_alloc_4593 bch_alloc 1 4593 NULL
119408 +ll_rw_extents_stats_seq_write_4633 ll_rw_extents_stats_seq_write 3 4633 NULL
119409 +iwl_dbgfs_tx_queue_read_4635 iwl_dbgfs_tx_queue_read 3 4635 NULL
119410 +nve0_gpio_intr_mask_4665 nve0_gpio_intr_mask 4-3 4665 NULL
119411 +skb_add_data_nocache_4682 skb_add_data_nocache 4 4682 NULL
119412 +cx18_read_pos_4683 cx18_read_pos 3 4683 NULL
119413 +short_retry_limit_read_4687 short_retry_limit_read 3 4687 NULL
119414 +kone_receive_4690 kone_receive 4 4690 NULL
119415 +hash_netportnet6_expire_4702 hash_netportnet6_expire 4 4702 NULL
119416 +cxgbi_alloc_big_mem_4707 cxgbi_alloc_big_mem 1 4707 NULL
119417 +ati_create_gatt_pages_4722 ati_create_gatt_pages 1 4722 NULL nohasharray
119418 +show_header_4722 show_header 3 4722 &ati_create_gatt_pages_4722
119419 +ll_rw_offset_stats_seq_write_4736 ll_rw_offset_stats_seq_write 3 4736 NULL nohasharray
119420 +bitmap_startwrite_4736 bitmap_startwrite 2 4736 &ll_rw_offset_stats_seq_write_4736
119421 +lu_buf_alloc_4753 lu_buf_alloc 2 4753 NULL
119422 +pwr_rcvd_bcns_cnt_read_4774 pwr_rcvd_bcns_cnt_read 3 4774 NULL
119423 +create_subvol_4791 create_subvol 4 4791 NULL
119424 +ncp__vol2io_4804 ncp__vol2io 5 4804 NULL
119425 +C_SYSC_setsockopt_4806 C_SYSC_setsockopt 5 4806 NULL
119426 +repair_io_failure_4815 repair_io_failure 4-3 4815 NULL
119427 +scsi_end_request_4839 scsi_end_request 3-4 4839 NULL
119428 +comedi_buf_write_free_4847 comedi_buf_write_free 2 4847 NULL
119429 +gigaset_if_receive_4861 gigaset_if_receive 3 4861 NULL
119430 +key_tx_spec_read_4862 key_tx_spec_read 3 4862 NULL
119431 +ocfs2_defrag_extent_4873 ocfs2_defrag_extent 2 4873 NULL
119432 +hid_register_field_4874 hid_register_field 2-3 4874 NULL
119433 +vga_arb_read_4886 vga_arb_read 3 4886 NULL
119434 +ieee80211_if_fmt_ave_beacon_4941 ieee80211_if_fmt_ave_beacon 3 4941 NULL
119435 +compat_rawv6_setsockopt_4967 compat_rawv6_setsockopt 5 4967 NULL
119436 +ath10k_read_chip_id_4969 ath10k_read_chip_id 3 4969 NULL
119437 +skb_network_header_len_4971 skb_network_header_len 0 4971 NULL
119438 +ieee80211_if_fmt_dot11MeshHWMPconfirmationInterval_4976 ieee80211_if_fmt_dot11MeshHWMPconfirmationInterval 3 4976 NULL
119439 +compat_SyS_ipc_5000 compat_SyS_ipc 3 5000 NULL
119440 +do_mincore_5018 do_mincore 0-2-1 5018 NULL
119441 +cfg80211_rx_mgmt_5056 cfg80211_rx_mgmt 5 5056 NULL
119442 +ocfs2_check_range_for_holes_5066 ocfs2_check_range_for_holes 3-2 5066 NULL
119443 +snd_mixart_BA1_read_5082 snd_mixart_BA1_read 5 5082 NULL
119444 +snd_emu10k1_ptr20_read_5087 snd_emu10k1_ptr20_read 0 5087 NULL
119445 +get_random_bytes_5091 get_random_bytes 2 5091 NULL nohasharray
119446 +kfifo_copy_from_user_5091 kfifo_copy_from_user 3-4-0 5091 &get_random_bytes_5091 nohasharray
119447 +blk_rq_sectors_5091 blk_rq_sectors 0 5091 &kfifo_copy_from_user_5091
119448 +sound_write_5102 sound_write 3 5102 NULL
119449 +i40e_dbg_netdev_ops_write_5117 i40e_dbg_netdev_ops_write 3 5117 NULL
119450 +qib_7220_handle_hwerrors_5142 qib_7220_handle_hwerrors 3 5142 NULL
119451 +bucket_table_alloc_5149 bucket_table_alloc 1 5149 NULL
119452 +__uwb_addr_print_5161 __uwb_addr_print 2 5161 NULL
119453 +iwl_dbgfs_status_read_5171 iwl_dbgfs_status_read 3 5171 NULL
119454 +acpi_pcc_get_sqty_5176 acpi_pcc_get_sqty 0 5176 NULL
119455 +trf7970a_read_cont_5179 trf7970a_read_cont 4 5179 NULL
119456 +ppp_cp_parse_cr_5214 ppp_cp_parse_cr 4 5214 NULL
119457 +dwc2_hcd_urb_alloc_5217 dwc2_hcd_urb_alloc 2 5217 NULL
119458 +ath6kl_debug_roam_tbl_event_5224 ath6kl_debug_roam_tbl_event 3 5224 NULL
119459 +xgmac_reg_addr_read_5278 xgmac_reg_addr_read 3 5278 NULL
119460 +usb_descriptor_fillbuf_5302 usb_descriptor_fillbuf 0 5302 NULL
119461 +r592_write_fifo_pio_5315 r592_write_fifo_pio 3 5315 NULL
119462 +sbc_get_write_same_sectors_5317 sbc_get_write_same_sectors 0 5317 NULL
119463 +pwr_elp_enter_read_5324 pwr_elp_enter_read 3 5324 NULL
119464 +uinput_ioctl_5342 uinput_ioctl 2 5342 NULL
119465 +cq_free_res_5355 cq_free_res 5 5355 NULL
119466 +ps_pspoll_utilization_read_5361 ps_pspoll_utilization_read 3 5361 NULL
119467 +cciss_allocate_sg_chain_blocks_5368 cciss_allocate_sg_chain_blocks 3-2 5368 NULL
119468 +xfs_efd_init_5463 xfs_efd_init 3 5463 NULL
119469 +ll_xattr_cache_refill_5468 ll_xattr_cache_refill 0 5468 NULL
119470 +kernfs_fop_write_5471 kernfs_fop_write 3 5471 NULL
119471 +xfs_efi_init_5476 xfs_efi_init 2 5476 NULL
119472 +cifs_security_flags_proc_write_5484 cifs_security_flags_proc_write 3 5484 NULL
119473 +tty_write_5494 tty_write 3 5494 NULL
119474 +tomoyo_update_domain_5498 tomoyo_update_domain 2 5498 NULL nohasharray
119475 +ieee80211_if_fmt_last_beacon_5498 ieee80211_if_fmt_last_beacon 3 5498 &tomoyo_update_domain_5498
119476 +__max_nr_grant_frames_5505 __max_nr_grant_frames 0 5505 NULL
119477 +ieee80211_if_fmt_auto_open_plinks_5534 ieee80211_if_fmt_auto_open_plinks 3 5534 NULL
119478 +get_entry_msg_len_5552 get_entry_msg_len 0 5552 NULL
119479 +le_readq_5557 le_readq 0 5557 NULL
119480 +inw_5558 inw 0 5558 NULL
119481 +bioset_create_5580 bioset_create 1 5580 NULL
119482 +oz_ep_alloc_5587 oz_ep_alloc 1 5587 NULL
119483 +SYSC_fsetxattr_5639 SYSC_fsetxattr 4 5639 NULL
119484 +ext4_xattr_get_5661 ext4_xattr_get 0 5661 NULL
119485 +posix_clock_register_5662 posix_clock_register 2 5662 NULL
119486 +get_arg_5694 get_arg 3 5694 NULL
119487 +subbuf_read_actor_5708 subbuf_read_actor 3 5708 NULL
119488 +vmw_kms_readback_5727 vmw_kms_readback 6 5727 NULL
119489 +sctp_setsockopt_autoclose_5775 sctp_setsockopt_autoclose 3 5775 NULL
119490 +__vxge_hw_blockpool_malloc_5786 __vxge_hw_blockpool_malloc 2 5786 NULL
119491 +nvme_trans_bdev_char_page_5797 nvme_trans_bdev_char_page 3 5797 NULL
119492 +skb_copy_datagram_iovec_5806 skb_copy_datagram_iovec 2-4 5806 NULL
119493 +nv50_disp_pioc_create__5812 nv50_disp_pioc_create_ 5 5812 NULL
119494 +ceph_x_encrypt_buflen_5829 ceph_x_encrypt_buflen 0-1 5829 NULL
119495 +ceph_msg_new_5846 ceph_msg_new 2 5846 NULL
119496 +setup_req_5848 setup_req 3 5848 NULL
119497 +ria_page_count_5849 ria_page_count 0 5849 NULL
119498 +rx_filter_max_arp_queue_dep_read_5851 rx_filter_max_arp_queue_dep_read 3 5851 NULL
119499 +uinput_compat_ioctl_5861 uinput_compat_ioctl 2 5861 NULL
119500 +config_buf_5862 config_buf 0 5862 NULL nohasharray
119501 +ufshcd_check_query_response_5862 ufshcd_check_query_response 0 5862 &config_buf_5862
119502 +lprocfs_fid_width_seq_write_5889 lprocfs_fid_width_seq_write 3 5889 NULL
119503 +port_show_regs_5904 port_show_regs 3 5904 NULL
119504 +rbd_segment_length_5907 rbd_segment_length 0-3-2 5907 NULL
119505 +uhci_debug_read_5911 uhci_debug_read 3 5911 NULL
119506 +lbs_highsnr_read_5931 lbs_highsnr_read 3 5931 NULL
119507 +ps_poll_ps_poll_timeouts_read_5934 ps_poll_ps_poll_timeouts_read 3 5934 NULL
119508 +edac_device_alloc_ctl_info_5941 edac_device_alloc_ctl_info 1 5941 NULL
119509 +ll_statahead_one_5962 ll_statahead_one 3 5962 NULL
119510 +__apu_get_register_5967 __apu_get_register 0 5967 NULL
119511 +ieee80211_if_fmt_rc_rateidx_mask_5ghz_5971 ieee80211_if_fmt_rc_rateidx_mask_5ghz 3 5971 NULL
119512 +SyS_semop_5980 SyS_semop 3 5980 NULL
119513 +btrfs_item_offset_6019 btrfs_item_offset 0 6019 NULL
119514 +alloc_msg_6072 alloc_msg 1 6072 NULL
119515 +sctp_setsockopt_connectx_6073 sctp_setsockopt_connectx 3 6073 NULL
119516 +_random_read_6098 _random_read 3 6098 NULL
119517 +ipmi_addr_length_6110 ipmi_addr_length 0 6110 NULL nohasharray
119518 +force_static_address_read_6110 force_static_address_read 3 6110 &ipmi_addr_length_6110
119519 +dfs_global_file_write_6112 dfs_global_file_write 3 6112 NULL
119520 +nouveau_parent_create__6131 nouveau_parent_create_ 7 6131 NULL
119521 +ieee80211_if_fmt_beacon_timeout_6153 ieee80211_if_fmt_beacon_timeout 3 6153 NULL
119522 +ivtv_copy_buf_to_user_6159 ivtv_copy_buf_to_user 4 6159 NULL
119523 +maybe_insert_hole_6167 maybe_insert_hole 3 6167 NULL
119524 +wl1251_cmd_template_set_6172 wl1251_cmd_template_set 4 6172 NULL
119525 +SyS_setgroups_6182 SyS_setgroups 1 6182 NULL
119526 +snd_efw_command_get_phys_meters_6190 snd_efw_command_get_phys_meters 3 6190 NULL
119527 +mxt_show_instance_6207 mxt_show_instance 2-0 6207 NULL
119528 +v4l2_ctrl_new_std_menu_6221 v4l2_ctrl_new_std_menu 4 6221 NULL
119529 +mqueue_read_file_6228 mqueue_read_file 3 6228 NULL
119530 +f_hidg_read_6238 f_hidg_read 3 6238 NULL
119531 +fbcon_prepare_logo_6246 fbcon_prepare_logo 5 6246 NULL
119532 +of_gpio_count_6270 of_gpio_count 0 6270 NULL
119533 +tx_tx_start_null_frame_read_6281 tx_tx_start_null_frame_read 3 6281 NULL
119534 +snd_hda_override_conn_list_6282 snd_hda_override_conn_list 3-0 6282 NULL nohasharray
119535 +xenbus_file_write_6282 xenbus_file_write 3 6282 &snd_hda_override_conn_list_6282
119536 +posix_acl_fix_xattr_to_user_6283 posix_acl_fix_xattr_to_user 2 6283 NULL
119537 +serial_port_in_6291 serial_port_in 0 6291 NULL
119538 +qlcnic_sriov_alloc_bc_msg_6309 qlcnic_sriov_alloc_bc_msg 2 6309 NULL
119539 +hfsplus_direct_IO_6313 hfsplus_direct_IO 4 6313 NULL
119540 +SyS_mincore_6329 SyS_mincore 2-1 6329 NULL nohasharray
119541 +hfa384x_inw_6329 hfa384x_inw 0 6329 &SyS_mincore_6329
119542 +fuse_get_req_for_background_6337 fuse_get_req_for_background 2 6337 NULL
119543 +ucs2_strnlen_6342 ucs2_strnlen 0 6342 NULL
119544 +regcache_sync_block_raw_6350 regcache_sync_block_raw 5-4 6350 NULL
119545 +mei_dbgfs_read_devstate_6352 mei_dbgfs_read_devstate 3 6352 NULL
119546 +arch_gnttab_valloc_6372 arch_gnttab_valloc 2 6372 NULL
119547 +osd_req_read_sg_kern_6378 osd_req_read_sg_kern 5 6378 NULL nohasharray
119548 +sync_fence_alloc_6378 sync_fence_alloc 1 6378 &osd_req_read_sg_kern_6378
119549 +posix_acl_fix_xattr_userns_6420 posix_acl_fix_xattr_userns 4 6420 NULL
119550 +add_transaction_credits_6422 add_transaction_credits 2-3 6422 NULL
119551 +ipr_change_queue_depth_6431 ipr_change_queue_depth 2 6431 NULL
119552 +__alloc_bootmem_node_nopanic_6432 __alloc_bootmem_node_nopanic 2 6432 NULL
119553 +C_SYSC_vmsplice_6470 C_SYSC_vmsplice 3 6470 NULL
119554 +ieee80211_if_fmt_dot11MeshMaxRetries_6476 ieee80211_if_fmt_dot11MeshMaxRetries 3 6476 NULL
119555 +qp_memcpy_from_queue_6479 qp_memcpy_from_queue 5-4 6479 NULL
119556 +cipso_v4_map_lvl_hton_6490 cipso_v4_map_lvl_hton 0 6490 NULL
119557 +dbg_intr_buf_6501 dbg_intr_buf 2 6501 NULL
119558 +mei_read_6507 mei_read 3 6507 NULL
119559 +rndis_set_oid_6547 rndis_set_oid 4 6547 NULL
119560 +wdm_read_6549 wdm_read 3 6549 NULL
119561 +dm_stats_create_6551 dm_stats_create 4-2-3 6551 NULL
119562 +fb_alloc_cmap_6554 fb_alloc_cmap 2 6554 NULL
119563 +SyS_semtimedop_6563 SyS_semtimedop 3 6563 NULL
119564 +ecryptfs_filldir_6622 ecryptfs_filldir 3 6622 NULL
119565 +xfs_do_div_6649 xfs_do_div 0-2 6649 NULL
119566 +process_rcvd_data_6679 process_rcvd_data 3 6679 NULL
119567 +btrfs_lookup_csums_range_6696 btrfs_lookup_csums_range 2-3 6696 NULL
119568 +ps_pspoll_max_apturn_read_6699 ps_pspoll_max_apturn_read 3 6699 NULL
119569 +bnad_debugfs_write_regrd_6706 bnad_debugfs_write_regrd 3 6706 NULL
119570 +mpeg_read_6708 mpeg_read 3 6708 NULL
119571 +ibmpex_query_sensor_count_6709 ibmpex_query_sensor_count 0 6709 NULL
119572 +check_clk_sync_6717 check_clk_sync 2 6717 NULL
119573 +video_proc_write_6724 video_proc_write 3 6724 NULL
119574 +posix_acl_xattr_count_6725 posix_acl_xattr_count 0-1 6725 NULL
119575 +inet_recv_error_6744 inet_recv_error 3 6744 NULL
119576 +kobject_add_varg_6781 kobject_add_varg 0 6781 NULL
119577 +iwl_dbgfs_channels_read_6784 iwl_dbgfs_channels_read 3 6784 NULL
119578 +ieee80211_if_read_6785 ieee80211_if_read 3 6785 NULL
119579 +zone_spanned_pages_in_node_6787 zone_spanned_pages_in_node 0-3-4 6787 NULL
119580 +hdlcdrv_register_6792 hdlcdrv_register 2 6792 NULL
119581 +ll_xattr_cache_find_6798 ll_xattr_cache_find 0 6798 NULL
119582 +tx_tx_done_data_read_6799 tx_tx_done_data_read 3 6799 NULL
119583 +lbs_rdrf_write_6826 lbs_rdrf_write 3 6826 NULL
119584 +calc_pages_for_6838 calc_pages_for 0-1-2 6838 NULL
119585 +mon_bin_read_6841 mon_bin_read 3 6841 NULL
119586 +snd_cs4281_BA0_read_6847 snd_cs4281_BA0_read 5 6847 NULL
119587 +perf_output_sample_ustack_6868 perf_output_sample_ustack 2 6868 NULL
119588 +dio_complete_6879 dio_complete 0-3-2 6879 NULL
119589 +raw_seticmpfilter_6888 raw_seticmpfilter 3 6888 NULL nohasharray
119590 +ieee80211_if_fmt_path_refresh_time_6888 ieee80211_if_fmt_path_refresh_time 3 6888 &raw_seticmpfilter_6888
119591 +dlmfs_file_write_6892 dlmfs_file_write 3 6892 NULL
119592 +proc_sessionid_read_6911 proc_sessionid_read 3 6911 NULL nohasharray
119593 +spi_show_regs_6911 spi_show_regs 3 6911 &proc_sessionid_read_6911 nohasharray
119594 +acm_alloc_minor_6911 acm_alloc_minor 0 6911 &spi_show_regs_6911
119595 +__kfifo_dma_in_finish_r_6913 __kfifo_dma_in_finish_r 2-3 6913 NULL
119596 +do_msgrcv_6921 do_msgrcv 3 6921 NULL
119597 +cache_do_downcall_6926 cache_do_downcall 3 6926 NULL
119598 +ipath_verbs_send_dma_6929 ipath_verbs_send_dma 6 6929 NULL
119599 +qsfp_cks_6945 qsfp_cks 2-0 6945 NULL
119600 +tg3_nvram_write_block_unbuffered_6955 tg3_nvram_write_block_unbuffered 3 6955 NULL
119601 +pch_uart_hal_read_6961 pch_uart_hal_read 0 6961 NULL
119602 +i40e_dbg_dump_write_6973 i40e_dbg_dump_write 3 6973 NULL nohasharray
119603 +rsa_extract_mpi_6973 rsa_extract_mpi 5 6973 &i40e_dbg_dump_write_6973
119604 +lustre_pack_reply_6982 lustre_pack_reply 2 6982 NULL
119605 +request_key_async_6990 request_key_async 4 6990 NULL
119606 +tpl_write_6998 tpl_write 3 6998 NULL
119607 +cipso_v4_gentag_enum_7006 cipso_v4_gentag_enum 0 7006 NULL
119608 +tracing_cpumask_read_7010 tracing_cpumask_read 3 7010 NULL
119609 +ld_usb_write_7022 ld_usb_write 3 7022 NULL
119610 +wimax_msg_7030 wimax_msg 4 7030 NULL
119611 +ceph_kvmalloc_7033 ceph_kvmalloc 1 7033 NULL
119612 +ipath_get_base_info_7043 ipath_get_base_info 3 7043 NULL
119613 +snd_pcm_oss_bytes_7051 snd_pcm_oss_bytes 2 7051 NULL
119614 +nouveau_device_create__7063 nouveau_device_create_ 7 7063 NULL
119615 +hci_sock_recvmsg_7072 hci_sock_recvmsg 4 7072 NULL
119616 +event_enable_read_7074 event_enable_read 3 7074 NULL
119617 +beacon_interval_read_7091 beacon_interval_read 3 7091 NULL nohasharray
119618 +tipc_send_packet_7091 tipc_send_packet 4 7091 &beacon_interval_read_7091
119619 +pipeline_enc_rx_stat_fifo_int_read_7107 pipeline_enc_rx_stat_fifo_int_read 3 7107 NULL
119620 +osc_resend_count_seq_write_7120 osc_resend_count_seq_write 3 7120 NULL
119621 +qib_format_hwerrors_7133 qib_format_hwerrors 5 7133 NULL
119622 +kvm_mmu_notifier_test_young_7139 kvm_mmu_notifier_test_young 3 7139 NULL
119623 +__alloc_objio_seg_7203 __alloc_objio_seg 1 7203 NULL
119624 +hdlc_loop_7255 hdlc_loop 0 7255 NULL
119625 +rx_rate_rx_frames_per_rates_read_7282 rx_rate_rx_frames_per_rates_read 3 7282 NULL nohasharray
119626 +kimage_alloc_init_7282 kimage_alloc_init 3 7282 &rx_rate_rx_frames_per_rates_read_7282
119627 +get_string_7302 get_string 0 7302 NULL
119628 +pci_vpd_info_field_size_7324 pci_vpd_info_field_size 0 7324 NULL
119629 +mgmt_control_7349 mgmt_control 3 7349 NULL
119630 +at_est2timeout_7365 at_est2timeout 0-1 7365 NULL
119631 +ieee80211_if_read_dot11MeshHWMPactivePathTimeout_7368 ieee80211_if_read_dot11MeshHWMPactivePathTimeout 3 7368 NULL
119632 +ath10k_read_fw_stats_7387 ath10k_read_fw_stats 3 7387 NULL
119633 +hweight_long_7388 hweight_long 0-1 7388 NULL
119634 +sl_change_mtu_7396 sl_change_mtu 2 7396 NULL
119635 +_ore_add_stripe_unit_7399 _ore_add_stripe_unit 6-3 7399 NULL
119636 +audmux_read_file_7400 audmux_read_file 3 7400 NULL
119637 +readb_7401 readb 0 7401 NULL
119638 +tipc_recvmsg_7402 tipc_recvmsg 4 7402 NULL
119639 +drm_property_create_blob_7414 drm_property_create_blob 2 7414 NULL
119640 +__copy_to_user_nocheck_7443 __copy_to_user_nocheck 0-3 7443 NULL
119641 +ip_options_get_alloc_7448 ip_options_get_alloc 1 7448 NULL
119642 +SYSC_setgroups_7454 SYSC_setgroups 1 7454 NULL
119643 +rt2x00debug_read_queue_stats_7455 rt2x00debug_read_queue_stats 3 7455 NULL
119644 +l2tp_ip6_sendmsg_7461 l2tp_ip6_sendmsg 4 7461 NULL
119645 +garp_request_join_7471 garp_request_join 4 7471 NULL nohasharray
119646 +ReadHSCX_7471 ReadHSCX 0 7471 &garp_request_join_7471
119647 +snd_pcm_lib_read1_7491 snd_pcm_lib_read1 0-3 7491 NULL
119648 +ahash_instance_headroom_7509 ahash_instance_headroom 0 7509 NULL nohasharray
119649 +sdhci_alloc_host_7509 sdhci_alloc_host 2 7509 &ahash_instance_headroom_7509
119650 +array_zalloc_7519 array_zalloc 1-2 7519 NULL
119651 +ath10k_read_htt_stats_mask_7557 ath10k_read_htt_stats_mask 3 7557 NULL
119652 +smk_read_mapped_7562 smk_read_mapped 3 7562 NULL
119653 +netvsc_get_slots_7565 netvsc_get_slots 0 7565 NULL
119654 +cfs_cpt_num_estimate_7571 cfs_cpt_num_estimate 0 7571 NULL
119655 +groups_alloc_7614 groups_alloc 1 7614 NULL nohasharray
119656 +create_dir_7614 create_dir 0 7614 &groups_alloc_7614
119657 +_rtw_zmalloc_7636 _rtw_zmalloc 1 7636 NULL
119658 +fault_inject_write_7662 fault_inject_write 3 7662 NULL
119659 +acpi_ex_allocate_name_string_7685 acpi_ex_allocate_name_string 2-1 7685 NULL
119660 +acpi_ns_get_pathname_length_7699 acpi_ns_get_pathname_length 0 7699 NULL
119661 +dev_write_7708 dev_write 3 7708 NULL
119662 +pci_raw_set_power_state_7729 pci_raw_set_power_state 0 7729 NULL
119663 +vxge_device_register_7752 vxge_device_register 4 7752 NULL
119664 +iwl_dbgfs_bt_cmd_read_7770 iwl_dbgfs_bt_cmd_read 3 7770 NULL
119665 +alloc_candev_7776 alloc_candev 1-2 7776 NULL
119666 +__videobuf_read_start_7782 __videobuf_read_start 0 7782 NULL
119667 +dfs_global_file_read_7787 dfs_global_file_read 3 7787 NULL
119668 +bnx2_nvram_write_7790 bnx2_nvram_write 4-2 7790 NULL
119669 +diva_os_copy_from_user_7792 diva_os_copy_from_user 4 7792 NULL nohasharray
119670 +lustre_packed_msg_size_7792 lustre_packed_msg_size 0 7792 &diva_os_copy_from_user_7792
119671 +seq_buf_alloc_7828 seq_buf_alloc 1 7828 NULL
119672 +cfs_trace_dump_debug_buffer_usrstr_7861 cfs_trace_dump_debug_buffer_usrstr 2 7861 NULL
119673 +tipc_alloc_entry_7875 tipc_alloc_entry 2 7875 NULL
119674 +config_desc_7878 config_desc 0 7878 NULL
119675 +dvb_dmxdev_read_sec_7892 dvb_dmxdev_read_sec 4 7892 NULL
119676 +xfs_trans_get_efi_7898 xfs_trans_get_efi 2 7898 NULL
119677 +libfc_host_alloc_7917 libfc_host_alloc 2 7917 NULL
119678 +f_hidg_write_7932 f_hidg_write 3 7932 NULL
119679 +integrity_digsig_verify_7956 integrity_digsig_verify 3 7956 NULL
119680 +smk_write_load_self_7958 smk_write_load_self 3 7958 NULL
119681 +tt3650_ci_msg_locked_8013 tt3650_ci_msg_locked 4 8013 NULL
119682 +vcs_read_8017 vcs_read 3 8017 NULL
119683 +vhost_add_used_and_signal_n_8038 vhost_add_used_and_signal_n 4 8038 NULL
119684 +dgrp_mon_read_8065 dgrp_mon_read 3 8065 NULL
119685 +spi_write_then_read_8073 spi_write_then_read 5-3 8073 NULL
119686 +qla4xxx_post_ping_evt_work_8074 qla4xxx_post_ping_evt_work 4 8074 NULL
119687 +venus_lookup_8121 venus_lookup 4 8121 NULL
119688 +ieee80211_if_fmt_num_buffered_multicast_8127 ieee80211_if_fmt_num_buffered_multicast 3 8127 NULL
119689 +xfs_file_fallocate_8150 xfs_file_fallocate 3-4 8150 NULL
119690 +ufshcd_wait_for_dev_cmd_8168 ufshcd_wait_for_dev_cmd 0 8168 NULL
119691 +__sk_mem_schedule_8185 __sk_mem_schedule 2 8185 NULL
119692 +ieee80211_if_fmt_dot11MeshHoldingTimeout_8187 ieee80211_if_fmt_dot11MeshHoldingTimeout 3 8187 NULL
119693 +recent_mt_proc_write_8206 recent_mt_proc_write 3 8206 NULL
119694 +rt2x00debug_write_bbp_8212 rt2x00debug_write_bbp 3 8212 NULL
119695 +ad7879_spi_multi_read_8218 ad7879_spi_multi_read 3 8218 NULL
119696 +play_iframe_8219 play_iframe 3 8219 NULL
119697 +kvm_mmu_page_set_gfn_8225 kvm_mmu_page_set_gfn 2 8225 NULL
119698 +sctp_ssnmap_size_8228 sctp_ssnmap_size 0-1-2 8228 NULL
119699 +check_xattr_ref_inode_8244 check_xattr_ref_inode 0 8244 NULL
119700 +t3_init_l2t_8261 t3_init_l2t 1 8261 NULL
119701 +init_cdev_8274 init_cdev 1 8274 NULL
119702 +rproc_recovery_write_8281 rproc_recovery_write 3 8281 NULL
119703 +qib_decode_7220_err_8315 qib_decode_7220_err 3 8315 NULL
119704 +ipwireless_send_packet_8328 ipwireless_send_packet 4 8328 NULL
119705 +rtw_cfg80211_rx_action_8329 rtw_cfg80211_rx_action 3 8329 NULL
119706 +tracing_entries_read_8345 tracing_entries_read 3 8345 NULL
119707 +ieee80211_if_fmt_ht_opmode_8347 ieee80211_if_fmt_ht_opmode 3 8347 NULL
119708 +generic_write_sync_8358 generic_write_sync 0 8358 NULL
119709 +ping_getfrag_8360 ping_getfrag 4-3 8360 NULL
119710 +ath6kl_lrssi_roam_write_8362 ath6kl_lrssi_roam_write 3 8362 NULL
119711 +xdi_copy_from_user_8395 xdi_copy_from_user 4 8395 NULL
119712 +zd_rf_scnprint_id_8406 zd_rf_scnprint_id 0-3 8406 NULL
119713 +smk_write_change_rule_8411 smk_write_change_rule 3 8411 NULL nohasharray
119714 +uvc_v4l2_ioctl_8411 uvc_v4l2_ioctl 2 8411 &smk_write_change_rule_8411
119715 +roccat_common2_sysfs_read_8431 roccat_common2_sysfs_read 6 8431 NULL
119716 +afs_cell_lookup_8482 afs_cell_lookup 2 8482 NULL
119717 +fore200e_chunk_alloc_8501 fore200e_chunk_alloc 4-3 8501 NULL
119718 +batadv_tt_len_8502 batadv_tt_len 0-1 8502 NULL
119719 +dev_config_8506 dev_config 3 8506 NULL
119720 +ACL_to_cifs_posix_8509 ACL_to_cifs_posix 3 8509 NULL
119721 +nouveau_platform_device_create__8514 nouveau_platform_device_create_ 2 8514 NULL
119722 +opticon_process_data_packet_8524 opticon_process_data_packet 3 8524 NULL
119723 +user_on_off_8552 user_on_off 2 8552 NULL
119724 +profile_remove_8556 profile_remove 3 8556 NULL
119725 +cache_slow_downcall_8570 cache_slow_downcall 2 8570 NULL
119726 +isr_dma0_done_read_8574 isr_dma0_done_read 3 8574 NULL
119727 +tower_write_8580 tower_write 3 8580 NULL
119728 +cfs_cpt_number_8618 cfs_cpt_number 0 8618 NULL
119729 +shash_setkey_unaligned_8620 shash_setkey_unaligned 3 8620 NULL
119730 +it821x_firmware_command_8628 it821x_firmware_command 3 8628 NULL
119731 +scsi_dma_map_8632 scsi_dma_map 0 8632 NULL
119732 +fuse_send_write_pages_8636 fuse_send_write_pages 5-0 8636 NULL
119733 +mlx5_vzalloc_8663 mlx5_vzalloc 1 8663 NULL
119734 +dio_bio_alloc_8677 dio_bio_alloc 5 8677 NULL
119735 +lbs_bcnmiss_read_8678 lbs_bcnmiss_read 3 8678 NULL
119736 +bpf_prog_size_8685 bpf_prog_size 0 8685 NULL
119737 +rproc_trace_read_8686 rproc_trace_read 3 8686 NULL
119738 +skb_frag_size_8695 skb_frag_size 0 8695 NULL
119739 +arcfb_write_8702 arcfb_write 3 8702 NULL
119740 +i_size_read_8703 i_size_read 0 8703 NULL nohasharray
119741 +init_header_8703 init_header 0 8703 &i_size_read_8703
119742 +ufshcd_get_tr_ocs_8706 ufshcd_get_tr_ocs 0 8706 NULL
119743 +HDLC_irq_8709 HDLC_irq 2 8709 NULL
119744 +ctrl_out_8712 ctrl_out 3-5 8712 NULL
119745 +tracing_max_lat_write_8728 tracing_max_lat_write 3 8728 NULL
119746 +jffs2_acl_count_8729 jffs2_acl_count 0-1 8729 NULL
119747 +tx_tx_exch_expiry_read_8749 tx_tx_exch_expiry_read 3 8749 NULL
119748 +compound_order_8750 compound_order 0 8750 NULL
119749 +yurex_write_8761 yurex_write 3 8761 NULL
119750 +joydev_compat_ioctl_8765 joydev_compat_ioctl 2 8765 NULL
119751 +kstrtoint_from_user_8778 kstrtoint_from_user 2 8778 NULL
119752 +paging32_prefetch_gpte_8783 paging32_prefetch_gpte 4 8783 NULL
119753 +ext4_try_to_write_inline_data_8785 ext4_try_to_write_inline_data 4-3 8785 NULL
119754 +__bitmap_weight_8796 __bitmap_weight 0-2 8796 NULL
119755 +metronomefb_write_8823 metronomefb_write 3 8823 NULL
119756 +SyS_llistxattr_8824 SyS_llistxattr 3 8824 NULL
119757 +ll_xattr_cache_get_8829 ll_xattr_cache_get 0 8829 NULL
119758 +get_queue_depth_8833 get_queue_depth 0 8833 NULL
119759 +dvb_ringbuffer_pkt_next_8834 dvb_ringbuffer_pkt_next 0-2 8834 NULL
119760 +usb_ep_queue_8839 usb_ep_queue 0 8839 NULL
119761 +iwl_rx_packet_len_8854 iwl_rx_packet_len 0 8854 NULL
119762 +debug_debug1_read_8856 debug_debug1_read 3 8856 NULL
119763 +wa_nep_queue_8858 wa_nep_queue 2 8858 NULL
119764 +xgmac_reg_value_write_8860 xgmac_reg_value_write 3 8860 NULL
119765 +radeon_drm_ioctl_8875 radeon_drm_ioctl 2 8875 NULL
119766 +compressed_bio_size_8887 compressed_bio_size 0-2 8887 NULL
119767 +ab3100_get_set_reg_8890 ab3100_get_set_reg 3 8890 NULL nohasharray
119768 +tracing_max_lat_read_8890 tracing_max_lat_read 3 8890 &ab3100_get_set_reg_8890
119769 +sdio_max_byte_size_8907 sdio_max_byte_size 0 8907 NULL
119770 +sysfs_merge_group_8917 sysfs_merge_group 0 8917 NULL
119771 +write_file_ani_8918 write_file_ani 3 8918 NULL
119772 +layout_commit_8926 layout_commit 3 8926 NULL
119773 +cp2112_hid_get_8933 cp2112_hid_get 4 8933 NULL
119774 +adjust_priv_size_8935 adjust_priv_size 0-1 8935 NULL
119775 +driver_stats_read_8944 driver_stats_read 3 8944 NULL
119776 +read_file_tgt_stats_8959 read_file_tgt_stats 3 8959 NULL
119777 +usb_allocate_stream_buffers_8964 usb_allocate_stream_buffers 3 8964 NULL
119778 +qib_qsfp_dump_8966 qib_qsfp_dump 0-3 8966 NULL
119779 +venus_mkdir_8967 venus_mkdir 4 8967 NULL
119780 +seq_open_net_8968 seq_open_net 4 8968 NULL nohasharray
119781 +vol_cdev_read_8968 vol_cdev_read 3 8968 &seq_open_net_8968
119782 +bio_integrity_get_tag_8974 bio_integrity_get_tag 3 8974 NULL
119783 +sony_register_touchpad_8981 sony_register_touchpad 2 8981 NULL
119784 +jbd2_journal_blocks_per_page_9004 jbd2_journal_blocks_per_page 0 9004 NULL
119785 +il_dbgfs_clear_ucode_stats_write_9016 il_dbgfs_clear_ucode_stats_write 3 9016 NULL
119786 +snd_emu10k1_ptr_read_9026 snd_emu10k1_ptr_read 0-2 9026 NULL
119787 +fd_ioctl_9028 fd_ioctl 3 9028 NULL
119788 +nla_put_9042 nla_put 3 9042 NULL
119789 +sta_tx_latency_stat_header_9050 sta_tx_latency_stat_header 0-3-4 9050 NULL
119790 +snd_emu10k1_synth_copy_from_user_9061 snd_emu10k1_synth_copy_from_user 3-5 9061 NULL
119791 +snd_gus_dram_peek_9062 snd_gus_dram_peek 4 9062 NULL
119792 +fib_info_hash_alloc_9075 fib_info_hash_alloc 1 9075 NULL
119793 +create_queues_9088 create_queues 2-3 9088 NULL
119794 +nvkm_output_create__9091 nvkm_output_create_ 6 9091 NULL
119795 +ftdi_prepare_write_buffer_9093 ftdi_prepare_write_buffer 3 9093 NULL
119796 +adxl34x_spi_read_block_9108 adxl34x_spi_read_block 3 9108 NULL
119797 +gfn_to_rmap_9110 gfn_to_rmap 3-2 9110 NULL nohasharray
119798 +caif_stream_sendmsg_9110 caif_stream_sendmsg 4 9110 &gfn_to_rmap_9110
119799 +pmcraid_change_queue_depth_9116 pmcraid_change_queue_depth 2 9116 NULL
119800 +vb2_dma_sg_alloc_9157 vb2_dma_sg_alloc 2 9157 NULL
119801 +dbg_command_buf_9165 dbg_command_buf 2 9165 NULL
119802 +isr_irqs_read_9181 isr_irqs_read 3 9181 NULL
119803 +count_leading_zeros_9183 count_leading_zeros 0 9183 NULL
119804 +altera_swap_ir_9194 altera_swap_ir 2 9194 NULL
119805 +snd_m3_get_pointer_9206 snd_m3_get_pointer 0 9206 NULL
119806 +iwl_dbgfs_frame_stats_read_9211 iwl_dbgfs_frame_stats_read 3 9211 NULL
119807 +card_send_command_9215 card_send_command 3 9215 NULL
119808 +virtqueue_add_9217 virtqueue_add 4-5 9217 NULL
119809 +tx_tx_prepared_descs_read_9221 tx_tx_prepared_descs_read 3 9221 NULL
119810 +l2cap_create_connless_pdu_9222 l2cap_create_connless_pdu 3 9222 NULL
119811 +sctp_getsockopt_delayed_ack_9232 sctp_getsockopt_delayed_ack 2 9232 NULL
119812 +hfsplus_bnode_read_u16_9262 hfsplus_bnode_read_u16 0 9262 NULL
119813 +hdpvr_read_9273 hdpvr_read 3 9273 NULL
119814 +flakey_status_9274 flakey_status 5 9274 NULL
119815 +iwl_dbgfs_stations_read_9309 iwl_dbgfs_stations_read 3 9309 NULL
119816 +ceph_sync_setxattr_9310 ceph_sync_setxattr 4 9310 NULL
119817 +__blockdev_direct_IO_9321 __blockdev_direct_IO 0-6 9321 NULL
119818 +ieee80211_if_fmt_txpower_9334 ieee80211_if_fmt_txpower 3 9334 NULL
119819 +nvme_trans_fmt_get_parm_header_9340 nvme_trans_fmt_get_parm_header 2 9340 NULL
119820 +ocfs2_orphan_for_truncate_9342 ocfs2_orphan_for_truncate 4 9342 NULL
119821 +ll_direct_rw_pages_9361 ll_direct_rw_pages 0 9361 NULL
119822 +sta_beacon_loss_count_read_9370 sta_beacon_loss_count_read 3 9370 NULL
119823 +virtqueue_add_outbuf_9395 virtqueue_add_outbuf 3 9395 NULL
119824 +read_9397 read 3 9397 NULL
119825 +hash_ipportip4_expire_9415 hash_ipportip4_expire 4 9415 NULL
119826 +btrfs_drop_extents_9423 btrfs_drop_extents 4 9423 NULL
119827 +bm_realloc_pages_9431 bm_realloc_pages 2 9431 NULL
119828 +ffs_ep0_write_9438 ffs_ep0_write 3 9438 NULL
119829 +ieee80211_if_fmt_fwded_unicast_9454 ieee80211_if_fmt_fwded_unicast 3 9454 NULL
119830 +get_registers_9470 get_registers 4 9470 NULL nohasharray
119831 +agp_generic_alloc_user_9470 agp_generic_alloc_user 1 9470 &get_registers_9470
119832 +crypt_status_9492 crypt_status 5 9492 NULL
119833 +lbs_threshold_write_9502 lbs_threshold_write 5 9502 NULL
119834 +lp_write_9511 lp_write 3 9511 NULL
119835 +mext_calc_swap_extents_9517 mext_calc_swap_extents 4 9517 NULL
119836 +scsi_tgt_kspace_exec_9522 scsi_tgt_kspace_exec 8 9522 NULL
119837 +ll_max_read_ahead_whole_mb_seq_write_9528 ll_max_read_ahead_whole_mb_seq_write 3 9528 NULL
119838 +read_file_dma_9530 read_file_dma 3 9530 NULL
119839 +iwl_dbgfs_bf_params_read_9542 iwl_dbgfs_bf_params_read 3 9542 NULL
119840 +il_dbgfs_missed_beacon_write_9546 il_dbgfs_missed_beacon_write 3 9546 NULL
119841 +compat_SyS_pwritev64_9548 compat_SyS_pwritev64 3 9548 NULL
119842 +fw_node_create_9559 fw_node_create 2 9559 NULL
119843 +kobj_map_9566 kobj_map 2-3 9566 NULL
119844 +f2fs_read_data_pages_9574 f2fs_read_data_pages 4 9574 NULL
119845 +snd_emu10k1_fx8010_read_9605 snd_emu10k1_fx8010_read 5-6 9605 NULL
119846 +lov_ost_pool_add_9626 lov_ost_pool_add 3 9626 NULL
119847 +saa7164_buffer_alloc_user_9627 saa7164_buffer_alloc_user 2 9627 NULL
119848 +ceph_copy_user_to_page_vector_9635 ceph_copy_user_to_page_vector 4-3 9635 NULL
119849 +acpi_ex_insert_into_field_9638 acpi_ex_insert_into_field 3 9638 NULL
119850 +ll_checksum_seq_write_9648 ll_checksum_seq_write 3 9648 NULL
119851 +ocfs2_xattr_get_rec_9652 ocfs2_xattr_get_rec 0 9652 NULL
119852 +queue_received_packet_9657 queue_received_packet 5 9657 NULL
119853 +tipc_port_mcast_xmit_9663 tipc_port_mcast_xmit 4 9663 NULL
119854 +snd_opl4_mem_proc_write_9670 snd_opl4_mem_proc_write 5 9670 NULL
119855 +dns_query_9676 dns_query 3 9676 NULL
119856 +qib_7322_handle_hwerrors_9678 qib_7322_handle_hwerrors 3 9678 NULL
119857 +__erst_read_from_storage_9690 __erst_read_from_storage 0 9690 NULL
119858 +lowpan_control_write_9699 lowpan_control_write 3 9699 NULL
119859 +vx_transfer_end_9701 vx_transfer_end 0 9701 NULL
119860 +fuse_iter_npages_9705 fuse_iter_npages 0 9705 NULL nohasharray
119861 +ieee80211_if_read_aid_9705 ieee80211_if_read_aid 3 9705 &fuse_iter_npages_9705
119862 +cfg80211_tx_mlme_mgmt_9715 cfg80211_tx_mlme_mgmt 3 9715 NULL
119863 +parse_uac2_sample_rate_range_9718 parse_uac2_sample_rate_range 0 9718 NULL
119864 +btrfs_stack_file_extent_num_bytes_9720 btrfs_stack_file_extent_num_bytes 0 9720 NULL
119865 +SYSC_ppoll_9721 SYSC_ppoll 2 9721 NULL
119866 +nla_get_u8_9736 nla_get_u8 0 9736 NULL
119867 +ieee80211_if_fmt_num_mcast_sta_9738 ieee80211_if_fmt_num_mcast_sta 3 9738 NULL
119868 +ddb_input_read_9743 ddb_input_read 3-0 9743 NULL
119869 +regmap_multi_reg_write_bypassed_9751 regmap_multi_reg_write_bypassed 3 9751 NULL nohasharray
119870 +sta_last_ack_signal_read_9751 sta_last_ack_signal_read 3 9751 &regmap_multi_reg_write_bypassed_9751
119871 +btrfs_super_root_9763 btrfs_super_root 0 9763 NULL
119872 +copy_page_from_iter_bvec_9767 copy_page_from_iter_bvec 0-3 9767 NULL
119873 +__blk_queue_init_tags_9778 __blk_queue_init_tags 2 9778 NULL
119874 +kvm_age_hva_9795 kvm_age_hva 2 9795 NULL
119875 +bio_alloc_map_data_9798 bio_alloc_map_data 1 9798 NULL
119876 +ieee80211_if_read_state_9813 ieee80211_if_read_state 3 9813 NULL nohasharray
119877 +udpv6_recvmsg_9813 udpv6_recvmsg 4 9813 &ieee80211_if_read_state_9813
119878 +compat_SyS_vmsplice_9828 compat_SyS_vmsplice 3 9828 NULL
119879 +pmcraid_alloc_sglist_9864 pmcraid_alloc_sglist 1 9864 NULL
119880 +f1x_translate_sysaddr_to_cs_9868 f1x_translate_sysaddr_to_cs 2 9868 NULL
119881 +wil_read_file_ioblob_9878 wil_read_file_ioblob 3 9878 NULL
119882 +bm_register_write_9893 bm_register_write 3 9893 NULL nohasharray
119883 +snd_midi_event_new_9893 snd_midi_event_new 1 9893 &bm_register_write_9893
119884 +snd_gf1_pcm_playback_copy_9895 snd_gf1_pcm_playback_copy 3-5 9895 NULL
119885 +nonpaging_page_fault_9908 nonpaging_page_fault 2 9908 NULL
119886 +iwl_dbgfs_prph_reg_read_9928 iwl_dbgfs_prph_reg_read 3 9928 NULL
119887 +root_nfs_parse_options_9937 root_nfs_parse_options 3 9937 NULL
119888 +pstore_ftrace_knob_read_9947 pstore_ftrace_knob_read 3 9947 NULL
119889 +read_file_misc_9948 read_file_misc 3 9948 NULL
119890 +csum_partial_copy_fromiovecend_9957 csum_partial_copy_fromiovecend 3-4 9957 NULL
119891 +SyS_gethostname_9964 SyS_gethostname 2 9964 NULL
119892 +get_free_serial_index_9969 get_free_serial_index 0 9969 NULL
119893 +btrfs_add_link_9973 btrfs_add_link 5 9973 NULL
119894 +SYSC_move_pages_9986 SYSC_move_pages 2 9986 NULL
119895 +ceph_oloc_oid_to_pg_10003 ceph_oloc_oid_to_pg 0 10003 NULL
119896 +aat2870_dump_reg_10019 aat2870_dump_reg 0 10019 NULL
119897 +ieee80211_set_probe_resp_10077 ieee80211_set_probe_resp 3 10077 NULL
119898 +get_elem_size_10110 get_elem_size 0-2 10110 NULL nohasharray
119899 +dynamic_ps_timeout_read_10110 dynamic_ps_timeout_read 3 10110 &get_elem_size_10110
119900 +gfs2_meta_read_10112 gfs2_meta_read 0 10112 NULL
119901 +SyS_migrate_pages_10134 SyS_migrate_pages 2 10134 NULL
119902 +aes_decrypt_packets_read_10155 aes_decrypt_packets_read 3 10155 NULL
119903 +rx_out_of_mem_read_10157 rx_out_of_mem_read 3 10157 NULL nohasharray
119904 +tracing_nsecs_write_10157 tracing_nsecs_write 3 10157 &rx_out_of_mem_read_10157
119905 +hidg_alloc_ep_req_10159 hidg_alloc_ep_req 2 10159 NULL
119906 +asd_store_update_bios_10165 asd_store_update_bios 4 10165 NULL
119907 +kstrtol_from_user_10168 kstrtol_from_user 2 10168 NULL
119908 +proc_pid_attr_read_10173 proc_pid_attr_read 3 10173 NULL
119909 +jffs2_user_setxattr_10182 jffs2_user_setxattr 4 10182 NULL
119910 +hdlc_rpr_irq_10240 hdlc_rpr_irq 2 10240 NULL
119911 +lmv_hsm_req_count_10245 lmv_hsm_req_count 0 10245 NULL
119912 +cciss_proc_write_10259 cciss_proc_write 3 10259 NULL
119913 +__qlcnic_pci_sriov_enable_10281 __qlcnic_pci_sriov_enable 2 10281 NULL
119914 +snd_rme9652_capture_copy_10287 snd_rme9652_capture_copy 5 10287 NULL
119915 +nvif_object_new_10300 nvif_object_new 5 10300 NULL
119916 +read_emulate_10310 read_emulate 2-4 10310 NULL
119917 +read_file_spectral_count_10320 read_file_spectral_count 3 10320 NULL
119918 +compat_SyS_writev_10327 compat_SyS_writev 3 10327 NULL
119919 +tun_sendmsg_10337 tun_sendmsg 4 10337 NULL
119920 +ufx_alloc_urb_list_10349 ufx_alloc_urb_list 3 10349 NULL
119921 +whci_add_cap_10350 whci_add_cap 0 10350 NULL
119922 +dbAllocAny_10354 dbAllocAny 0 10354 NULL
119923 +ath6kl_listen_int_read_10355 ath6kl_listen_int_read 3 10355 NULL
119924 +sta_ht_capa_read_10366 sta_ht_capa_read 3 10366 NULL
119925 +ecryptfs_decode_and_decrypt_filename_10379 ecryptfs_decode_and_decrypt_filename 5 10379 NULL
119926 +do_compat_pselect_10398 do_compat_pselect 1 10398 NULL
119927 +fwtty_rx_10434 fwtty_rx 3 10434 NULL
119928 +event_phy_transmit_error_read_10471 event_phy_transmit_error_read 3 10471 NULL
119929 +hash_ipportip6_expire_10478 hash_ipportip6_expire 4 10478 NULL
119930 +nouveau_pwr_create__10483 nouveau_pwr_create_ 4 10483 NULL
119931 +ext4_itable_unused_count_10501 ext4_itable_unused_count 0 10501 NULL
119932 +qib_alloc_fast_reg_page_list_10507 qib_alloc_fast_reg_page_list 2 10507 NULL
119933 +sel_write_disable_10511 sel_write_disable 3 10511 NULL
119934 +osd_req_write_sg_kern_10514 osd_req_write_sg_kern 5 10514 NULL
119935 +rds_message_alloc_10517 rds_message_alloc 1 10517 NULL
119936 +qlcnic_pci_sriov_enable_10519 qlcnic_pci_sriov_enable 2 10519 NULL
119937 +kstrtouint_from_user_10536 kstrtouint_from_user 2 10536 NULL nohasharray
119938 +snd_pcm_lib_read_10536 snd_pcm_lib_read 0-3 10536 &kstrtouint_from_user_10536
119939 +ext4_write_begin_10576 ext4_write_begin 3-4 10576 NULL
119940 +scrub_remap_extent_10588 scrub_remap_extent 2 10588 NULL
119941 +otp_read_10594 otp_read 2-4-5 10594 NULL
119942 +supply_map_read_file_10608 supply_map_read_file 3 10608 NULL
119943 +ima_show_htable_violations_10619 ima_show_htable_violations 3 10619 NULL
119944 +fq_alloc_node_10633 fq_alloc_node 1 10633 NULL
119945 +nfs_idmap_lookup_id_10660 nfs_idmap_lookup_id 2 10660 NULL
119946 +efx_max_tx_len_10662 efx_max_tx_len 0-2 10662 NULL
119947 +parport_write_10669 parport_write 0 10669 NULL
119948 +edge_write_10692 edge_write 4 10692 NULL
119949 +selinux_inode_setxattr_10708 selinux_inode_setxattr 4 10708 NULL nohasharray
119950 +inl_10708 inl 0 10708 &selinux_inode_setxattr_10708
119951 +pvr2_ioread_read_10720 pvr2_ioread_read 3 10720 NULL nohasharray
119952 +shash_async_setkey_10720 shash_async_setkey 3 10720 &pvr2_ioread_read_10720
119953 +spi_sync_10731 spi_sync 0 10731 NULL
119954 +sctp_getsockopt_maxseg_10737 sctp_getsockopt_maxseg 2 10737 NULL nohasharray
119955 +apu_get_register_10737 apu_get_register 0 10737 &sctp_getsockopt_maxseg_10737
119956 +SyS_io_getevents_10756 SyS_io_getevents 3 10756 NULL
119957 +vhost_add_used_n_10760 vhost_add_used_n 3 10760 NULL
119958 +rd_build_prot_space_10761 rd_build_prot_space 2-3 10761 NULL
119959 +kvm_read_guest_atomic_10765 kvm_read_guest_atomic 4 10765 NULL
119960 +__qp_memcpy_to_queue_10779 __qp_memcpy_to_queue 2-4 10779 NULL
119961 +diva_set_trace_filter_10820 diva_set_trace_filter 0-1 10820 NULL
119962 +lbs_sleepparams_read_10840 lbs_sleepparams_read 3 10840 NULL
119963 +ext4_direct_IO_10843 ext4_direct_IO 4 10843 NULL
119964 +ida_get_new_above_10853 ida_get_new_above 0 10853 NULL
119965 +fuse_conn_max_background_read_10855 fuse_conn_max_background_read 3 10855 NULL
119966 +snd_pcm_oss_write1_10872 snd_pcm_oss_write1 3 10872 NULL
119967 +wiidebug_drm_write_10879 wiidebug_drm_write 3 10879 NULL
119968 +get_scq_10897 get_scq 2 10897 NULL
119969 +tifm_alloc_adapter_10903 tifm_alloc_adapter 1 10903 NULL
119970 +lprocfs_wr_atomic_10912 lprocfs_wr_atomic 3 10912 NULL
119971 +__copy_from_user_10918 __copy_from_user 0-3 10918 NULL
119972 +kobject_add_10919 kobject_add 0 10919 NULL
119973 +ar9003_dump_modal_eeprom_10959 ar9003_dump_modal_eeprom 3-2-0 10959 NULL
119974 +ci_port_test_write_10962 ci_port_test_write 3 10962 NULL
119975 +bm_entry_read_10976 bm_entry_read 3 10976 NULL
119976 +sched_autogroup_write_10984 sched_autogroup_write 3 10984 NULL
119977 +xfrm_hash_alloc_10997 xfrm_hash_alloc 1 10997 NULL
119978 +rx_filter_accum_arp_pend_requests_read_11003 rx_filter_accum_arp_pend_requests_read 3 11003 NULL
119979 +SetLineNumber_11023 SetLineNumber 0 11023 NULL
119980 +nouveau_gpio_create__11048 nouveau_gpio_create_ 4 11048 NULL
119981 +tda10048_writeregbulk_11050 tda10048_writeregbulk 4 11050 NULL
119982 +insert_inline_extent_backref_11063 insert_inline_extent_backref 8 11063 NULL
119983 +xfs_collapse_file_space_11075 xfs_collapse_file_space 2-3 11075 NULL
119984 +tcp_send_mss_11079 tcp_send_mss 0 11079 NULL
119985 +count_argc_11083 count_argc 0 11083 NULL
119986 +kvm_write_guest_cached_11106 kvm_write_guest_cached 4 11106 NULL
119987 +tw_change_queue_depth_11116 tw_change_queue_depth 2 11116 NULL
119988 +page_offset_11120 page_offset 0 11120 NULL
119989 +tracing_buffers_read_11124 tracing_buffers_read 3 11124 NULL
119990 +alloc_alien_cache_11127 alloc_alien_cache 2 11127 NULL
119991 +snd_gf1_pcm_playback_silence_11172 snd_gf1_pcm_playback_silence 3-4 11172 NULL
119992 +il_dbgfs_rx_queue_read_11221 il_dbgfs_rx_queue_read 3 11221 NULL
119993 +comedi_alloc_spriv_11234 comedi_alloc_spriv 2 11234 NULL
119994 +of_irq_count_11253 of_irq_count 0 11253 NULL
119995 +hugetlbfs_read_11268 hugetlbfs_read 3 11268 NULL
119996 +ath6kl_power_params_write_11274 ath6kl_power_params_write 3 11274 NULL
119997 +SYSC_getrandom_11294 SYSC_getrandom 2 11294 NULL
119998 +tipc_msg_build_11304 tipc_msg_build 3-4-5 11304 NULL
119999 +__proc_daemon_file_11305 __proc_daemon_file 5 11305 NULL
120000 +ext4_xattr_check_names_11314 ext4_xattr_check_names 0 11314 NULL
120001 +bcache_dev_sectors_dirty_add_11315 bcache_dev_sectors_dirty_add 3-4 11315 NULL
120002 +sk_filter_size_11316 sk_filter_size 0 11316 NULL nohasharray
120003 +tcp_send_rcvq_11316 tcp_send_rcvq 3 11316 &sk_filter_size_11316
120004 +construct_key_11329 construct_key 3 11329 NULL nohasharray
120005 +__kfifo_out_peek_11329 __kfifo_out_peek 0-3 11329 &construct_key_11329
120006 +next_segment_11330 next_segment 0-2-1 11330 NULL
120007 +persistent_ram_buffer_map_11332 persistent_ram_buffer_map 1-2 11332 NULL
120008 +ext4_get_inline_size_11349 ext4_get_inline_size 0 11349 NULL
120009 +sel_write_create_11353 sel_write_create 3 11353 NULL nohasharray
120010 +nl80211_send_mgmt_11353 nl80211_send_mgmt 7 11353 &sel_write_create_11353
120011 +of_get_available_child_count_11361 of_get_available_child_count 0 11361 NULL
120012 +qib_get_base_info_11369 qib_get_base_info 3 11369 NULL
120013 +tcf_register_action_11381 tcf_register_action 2 11381 NULL nohasharray
120014 +nft_value_dump_11381 nft_value_dump 3 11381 &tcf_register_action_11381
120015 +isku_sysfs_read_keys_capslock_11392 isku_sysfs_read_keys_capslock 6 11392 NULL
120016 +dev_irnet_write_11398 dev_irnet_write 3 11398 NULL
120017 +lprocfs_wr_evict_client_11402 lprocfs_wr_evict_client 3 11402 NULL
120018 +___alloc_bootmem_11410 ___alloc_bootmem 1 11410 NULL
120019 +str_to_user_11411 str_to_user 2 11411 NULL
120020 +mem_fw_gen_free_mem_blks_read_11413 mem_fw_gen_free_mem_blks_read 3 11413 NULL
120021 +ath6kl_wmi_test_rx_11414 ath6kl_wmi_test_rx 3 11414 NULL
120022 +adis16480_show_firmware_revision_11417 adis16480_show_firmware_revision 3 11417 NULL
120023 +trace_options_read_11419 trace_options_read 3 11419 NULL
120024 +i40e_dbg_command_write_11421 i40e_dbg_command_write 3 11421 NULL
120025 +bttv_read_11432 bttv_read 3 11432 NULL
120026 +create_zero_mask_11453 create_zero_mask 0-1 11453 NULL
120027 +ufshcd_change_queue_depth_11477 ufshcd_change_queue_depth 2 11477 NULL
120028 +sca3000_read_first_n_hw_rb_11479 sca3000_read_first_n_hw_rb 2 11479 NULL nohasharray
120029 +pci_set_power_state_11479 pci_set_power_state 0 11479 &sca3000_read_first_n_hw_rb_11479
120030 +sd_do_mode_sense_11507 sd_do_mode_sense 5 11507 NULL
120031 +kmem_zalloc_11510 kmem_zalloc 1 11510 NULL
120032 +ll_direct_IO_26_seg_11518 ll_direct_IO_26_seg 0 11518 NULL
120033 +twl_direction_in_11527 twl_direction_in 2 11527 NULL
120034 +skb_cow_data_11565 skb_cow_data 0 11565 NULL
120035 +lpfc_idiag_ctlacc_write_11576 lpfc_idiag_ctlacc_write 3 11576 NULL
120036 +oprofilefs_ulong_to_user_11582 oprofilefs_ulong_to_user 3 11582 NULL
120037 +batadv_iv_ogm_orig_add_if_11586 batadv_iv_ogm_orig_add_if 2 11586 NULL
120038 +snd_pcm_action_11589 snd_pcm_action 0 11589 NULL
120039 +fw_device_op_ioctl_11595 fw_device_op_ioctl 2 11595 NULL
120040 +batadv_iv_ogm_orig_del_if_11604 batadv_iv_ogm_orig_del_if 2 11604 NULL
120041 +SYSC_mq_timedsend_11607 SYSC_mq_timedsend 3 11607 NULL
120042 +C_SYSC_migrate_pages_11618 C_SYSC_migrate_pages 2 11618 NULL
120043 +sisusb_send_bridge_packet_11649 sisusb_send_bridge_packet 2 11649 NULL
120044 +nla_total_size_11658 nla_total_size 0-1 11658 NULL
120045 +srpc_create_client_rpc_11664 srpc_create_client_rpc 3 11664 NULL nohasharray
120046 +slab_ksize_11664 slab_ksize 0 11664 &srpc_create_client_rpc_11664
120047 +ide_queue_pc_tail_11673 ide_queue_pc_tail 5 11673 NULL
120048 +compat_SyS_msgsnd_11675 compat_SyS_msgsnd 3 11675 NULL
120049 +btrfs_alloc_delayed_item_11678 btrfs_alloc_delayed_item 1 11678 NULL
120050 +sctp_setsockopt_hmac_ident_11687 sctp_setsockopt_hmac_ident 3 11687 NULL
120051 +split_11691 split 2 11691 NULL
120052 +compat_SyS_keyctl_11695 compat_SyS_keyctl 4 11695 NULL nohasharray
120053 +snd_ctl_elem_user_tlv_11695 snd_ctl_elem_user_tlv 3 11695 &compat_SyS_keyctl_11695
120054 +blk_rq_cur_bytes_11723 blk_rq_cur_bytes 0 11723 NULL
120055 +dm_bio_prison_create_11749 dm_bio_prison_create 1 11749 NULL
120056 +iwl_dbgfs_qos_read_11753 iwl_dbgfs_qos_read 3 11753 NULL
120057 +ieee80211_get_num_supported_channels_11768 ieee80211_get_num_supported_channels 0 11768 NULL
120058 +tipc_sendmsg_11769 tipc_sendmsg 4 11769 NULL
120059 +ps_pspoll_timeouts_read_11776 ps_pspoll_timeouts_read 3 11776 NULL
120060 +btrfs_key_blockptr_11786 btrfs_key_blockptr 0 11786 NULL
120061 +pcpu_fc_alloc_11818 pcpu_fc_alloc 2 11818 NULL
120062 +umc_device_register_11824 umc_device_register 0 11824 NULL
120063 +zerocopy_sg_from_iovec_11828 zerocopy_sg_from_iovec 3 11828 NULL
120064 +sctp_setsockopt_maxseg_11829 sctp_setsockopt_maxseg 3 11829 NULL
120065 +rts51x_read_status_11830 rts51x_read_status 4 11830 NULL
120066 +unix_stream_connect_11844 unix_stream_connect 3 11844 NULL
120067 +ecryptfs_copy_filename_11868 ecryptfs_copy_filename 4 11868 NULL
120068 +l2cap_chan_send_11878 l2cap_chan_send 3 11878 NULL
120069 +ieee80211_rx_bss_info_11887 ieee80211_rx_bss_info 3 11887 NULL
120070 +mdc_rename_11899 mdc_rename 4-6 11899 NULL
120071 +xstateregs_get_11906 xstateregs_get 4 11906 NULL
120072 +ti_write_11916 ti_write 4 11916 NULL
120073 +fs_devrw_entry_11924 fs_devrw_entry 3 11924 NULL
120074 +bitmap_remap_11929 bitmap_remap 5 11929 NULL
120075 +atomic_sub_return_11939 atomic_sub_return 0-1 11939 NULL
120076 +r1_sync_page_io_11963 r1_sync_page_io 3 11963 NULL
120077 +f1x_swap_interleaved_region_11970 f1x_swap_interleaved_region 0-2 11970 NULL
120078 +read_and_add_raw_conns_11987 read_and_add_raw_conns 0 11987 NULL
120079 +ftdi_elan_total_command_size_12045 ftdi_elan_total_command_size 0 12045 NULL
120080 +ieee80211_if_read_user_power_level_12050 ieee80211_if_read_user_power_level 3 12050 NULL
120081 +il4965_ucode_tx_stats_read_12064 il4965_ucode_tx_stats_read 3 12064 NULL
120082 +ptc_proc_write_12076 ptc_proc_write 3 12076 NULL
120083 +batadv_tt_global_size_mod_12085 batadv_tt_global_size_mod 3 12085 NULL
120084 +rtw_malloc2d_12102 rtw_malloc2d 1-2-3 12102 NULL
120085 +alloc_bulk_urbs_generic_12127 alloc_bulk_urbs_generic 5 12127 NULL
120086 +set_powered_12129 set_powered 4 12129 NULL
120087 +ramoops_init_prz_12134 ramoops_init_prz 5 12134 NULL
120088 +xfs_handle_to_dentry_12135 xfs_handle_to_dentry 3 12135 NULL
120089 +rawv6_seticmpfilter_12137 rawv6_seticmpfilter 5 12137 NULL
120090 +rawsock_recvmsg_12144 rawsock_recvmsg 4 12144 NULL
120091 +btmrvl_sdio_host_to_card_12152 btmrvl_sdio_host_to_card 3 12152 NULL
120092 +vmbus_open_12154 vmbus_open 2-3 12154 NULL
120093 +fnic_reset_stats_write_12177 fnic_reset_stats_write 3 12177 NULL
120094 +LNetEQAlloc_12178 LNetEQAlloc 1 12178 NULL
120095 +ddp_make_gl_12179 ddp_make_gl 1 12179 NULL
120096 +compat_do_arpt_set_ctl_12184 compat_do_arpt_set_ctl 4 12184 NULL
120097 +ip_generic_getfrag_12187 ip_generic_getfrag 3-4 12187 NULL
120098 +snd_pcm_kernel_ioctl_12219 snd_pcm_kernel_ioctl 0 12219 NULL
120099 +fuse_get_req_12221 fuse_get_req 2 12221 NULL nohasharray
120100 +aat2870_reg_read_file_12221 aat2870_reg_read_file 3 12221 &fuse_get_req_12221
120101 +__alloc_bootmem_low_nopanic_12235 __alloc_bootmem_low_nopanic 1 12235 NULL
120102 +usnic_ib_qp_grp_dump_rows_12239 usnic_ib_qp_grp_dump_rows 3 12239 NULL
120103 +ib_uverbs_unmarshall_recv_12251 ib_uverbs_unmarshall_recv 5 12251 NULL
120104 +shash_compat_setkey_12267 shash_compat_setkey 3 12267 NULL
120105 +add_sctp_bind_addr_12269 add_sctp_bind_addr 3 12269 NULL
120106 +note_last_dentry_12285 note_last_dentry 3 12285 NULL
120107 +roundup_to_multiple_of_64_12288 roundup_to_multiple_of_64 0-1 12288 NULL nohasharray
120108 +il_dbgfs_nvm_read_12288 il_dbgfs_nvm_read 3 12288 &roundup_to_multiple_of_64_12288
120109 +bt_sock_recvmsg_12316 bt_sock_recvmsg 4 12316 NULL
120110 +usnic_transport_sock_to_str_12322 usnic_transport_sock_to_str 2-0 12322 NULL
120111 +ufshcd_copy_query_response_12324 ufshcd_copy_query_response 0 12324 NULL
120112 +pcbit_writecmd_12332 pcbit_writecmd 2 12332 NULL
120113 +mptctl_ioctl_12355 mptctl_ioctl 2 12355 NULL
120114 +__nf_ct_ext_add_length_12364 __nf_ct_ext_add_length 3 12364 NULL
120115 +xfs_iext_inline_to_direct_12384 xfs_iext_inline_to_direct 2 12384 NULL
120116 +write_file_dump_12391 write_file_dump 3 12391 NULL nohasharray
120117 +btrfs_file_extent_ram_bytes_12391 btrfs_file_extent_ram_bytes 0 12391 &write_file_dump_12391 nohasharray
120118 +populate_dir_12391 populate_dir 0 12391 &btrfs_file_extent_ram_bytes_12391
120119 +hbucket_elem_add_12416 hbucket_elem_add 3 12416 NULL
120120 +ieee80211_if_read_num_mcast_sta_12419 ieee80211_if_read_num_mcast_sta 3 12419 NULL
120121 +cfs_array_alloc_12441 cfs_array_alloc 1-2 12441 NULL
120122 +skb_do_copy_data_nocache_12465 skb_do_copy_data_nocache 5 12465 NULL
120123 +x25_sendmsg_12487 x25_sendmsg 4 12487 NULL
120124 +fnic_trace_ctrl_read_12497 fnic_trace_ctrl_read 3 12497 NULL
120125 +__ceph_osdc_start_request_12502 __ceph_osdc_start_request 0 12502 NULL
120126 +qib_alloc_fast_reg_mr_12526 qib_alloc_fast_reg_mr 2 12526 NULL
120127 +nvkm_event_init_12565 nvkm_event_init 3-2 12565 NULL
120128 +hvc_alloc_12579 hvc_alloc 4 12579 NULL
120129 +pcpu_extend_area_map_12589 pcpu_extend_area_map 2 12589 NULL
120130 +_iwl_dbgfs_prph_reg_write_12597 _iwl_dbgfs_prph_reg_write 3 12597 NULL
120131 +tlbflush_write_file_12598 tlbflush_write_file 3 12598 NULL
120132 +vhci_put_user_12604 vhci_put_user 4 12604 NULL
120133 +sdhci_pltfm_init_12627 sdhci_pltfm_init 3 12627 NULL
120134 +pwr_rcvd_awake_bcns_cnt_read_12632 pwr_rcvd_awake_bcns_cnt_read 3 12632 NULL
120135 +pn_sendmsg_12640 pn_sendmsg 4 12640 NULL
120136 +dwc3_link_state_write_12641 dwc3_link_state_write 3 12641 NULL
120137 +nr_recvmsg_12649 nr_recvmsg 4 12649 NULL
120138 +rtw_android_get_link_speed_12655 rtw_android_get_link_speed 0 12655 NULL
120139 +ocfs2_read_block_12659 ocfs2_read_block 0 12659 NULL
120140 +lustre_pack_request_v2_12665 lustre_pack_request_v2 2 12665 NULL
120141 +sel_read_class_12669 sel_read_class 3 12669 NULL nohasharray
120142 +sparse_mem_maps_populate_node_12669 sparse_mem_maps_populate_node 4 12669 &sel_read_class_12669
120143 +ext4_writepage_trans_blocks_12674 ext4_writepage_trans_blocks 0 12674 NULL
120144 +iwl_dbgfs_calib_disabled_write_12707 iwl_dbgfs_calib_disabled_write 3 12707 NULL
120145 +ieee80211_if_read_num_buffered_multicast_12716 ieee80211_if_read_num_buffered_multicast 3 12716 NULL
120146 +ivtv_write_12721 ivtv_write 3 12721 NULL
120147 +key_rx_spec_read_12736 key_rx_spec_read 3 12736 NULL
120148 +__mei_cl_async_send_12737 __mei_cl_async_send 3 12737 NULL
120149 +ieee80211_if_read_dot11MeshMaxRetries_12756 ieee80211_if_read_dot11MeshMaxRetries 3 12756 NULL
120150 +listxattr_12769 listxattr 3 12769 NULL
120151 +sctp_ssnmap_init_12772 sctp_ssnmap_init 2-3 12772 NULL
120152 +scsi_adjust_queue_depth_12802 scsi_adjust_queue_depth 3 12802 NULL
120153 +xfs_inumbers_fmt_12817 xfs_inumbers_fmt 3 12817 NULL
120154 +SyS_add_key_12834 SyS_add_key 4 12834 NULL
120155 +TSS_authhmac_12839 TSS_authhmac 3 12839 NULL
120156 +spidev_sync_12842 spidev_sync 0 12842 NULL
120157 +spidev_ioctl_12846 spidev_ioctl 2 12846 NULL
120158 +ath9k_dump_4k_modal_eeprom_12883 ath9k_dump_4k_modal_eeprom 3-2 12883 NULL
120159 +get_leb_cnt_12892 get_leb_cnt 0-2 12892 NULL
120160 +get_virtual_node_size_12908 get_virtual_node_size 0 12908 NULL
120161 +rds_pages_in_vec_12922 rds_pages_in_vec 0 12922 NULL
120162 +do_inode_permission_12946 do_inode_permission 0 12946 NULL
120163 +bm_status_write_12964 bm_status_write 3 12964 NULL
120164 +raid56_parity_recover_12987 raid56_parity_recover 5 12987 NULL
120165 +TransmitTcb_12989 TransmitTcb 4 12989 NULL
120166 +sk_peek_offset_12991 sk_peek_offset 0 12991 NULL
120167 +bset_prev_bytes_13020 bset_prev_bytes 0 13020 NULL
120168 +subsystem_filter_write_13022 subsystem_filter_write 3 13022 NULL
120169 +ocfs2_write_begin_13045 ocfs2_write_begin 3-4 13045 NULL
120170 +__dn_setsockopt_13060 __dn_setsockopt 5 13060 NULL nohasharray
120171 +ptlrpc_lprocfs_threads_min_seq_write_13060 ptlrpc_lprocfs_threads_min_seq_write 3 13060 &__dn_setsockopt_13060
120172 +ufshcd_compose_upiu_13076 ufshcd_compose_upiu 0 13076 NULL
120173 +xattr_getsecurity_13090 xattr_getsecurity 0 13090 NULL
120174 +ttm_dma_pool_alloc_new_pages_13105 ttm_dma_pool_alloc_new_pages 3 13105 NULL
120175 +SyS_msgrcv_13109 SyS_msgrcv 3 13109 NULL
120176 +snd_rme96_playback_copy_13111 snd_rme96_playback_copy 5 13111 NULL
120177 +bfad_debugfs_read_13119 bfad_debugfs_read 3 13119 NULL
120178 +blk_update_request_13146 blk_update_request 3 13146 NULL
120179 +caif_stream_recvmsg_13173 caif_stream_recvmsg 4 13173 NULL
120180 +pwr_disable_ps_read_13176 pwr_disable_ps_read 3 13176 NULL
120181 +ucs2_strlen_13178 ucs2_strlen 0 13178 NULL
120182 +dgrp_net_ioctl_13183 dgrp_net_ioctl 2 13183 NULL
120183 +create_trace_uprobe_13184 create_trace_uprobe 1 13184 NULL
120184 +comedi_read_13199 comedi_read 3 13199 NULL
120185 +hash_ipport4_expire_13201 hash_ipport4_expire 4 13201 NULL
120186 +mmc_ext_csd_read_13205 mmc_ext_csd_read 3 13205 NULL
120187 +svm_msrpm_offset_13220 svm_msrpm_offset 0-1 13220 NULL
120188 +fnic_trace_ctrl_write_13229 fnic_trace_ctrl_write 3 13229 NULL
120189 +_iwl_dbgfs_disable_power_off_write_13243 _iwl_dbgfs_disable_power_off_write 3 13243 NULL
120190 +asix_read_cmd_13245 asix_read_cmd 5 13245 NULL
120191 +init_tid_tabs_13252 init_tid_tabs 2-3-4 13252 NULL
120192 +bio_integrity_trim_13259 bio_integrity_trim 3-2 13259 NULL
120193 +simple_attr_write_13260 simple_attr_write 3 13260 NULL
120194 +pmcraid_notify_aen_13274 pmcraid_notify_aen 3 13274 NULL
120195 +nvkm_ltc_create__13275 nvkm_ltc_create_ 4 13275 NULL
120196 +il4965_stats_flag_13281 il4965_stats_flag 0-3 13281 NULL
120197 +lpfc_idiag_mbxacc_get_setup_13282 lpfc_idiag_mbxacc_get_setup 0 13282 NULL
120198 +nvkm_i2c_pad_create__13292 nvkm_i2c_pad_create_ 5 13292 NULL
120199 +sd_major_13294 sd_major 0-1 13294 NULL
120200 +read_file_phy_err_13318 read_file_phy_err 3 13318 NULL
120201 +kvm_read_nested_guest_page_13337 kvm_read_nested_guest_page 5 13337 NULL
120202 +round_event_name_len_13348 round_event_name_len 0 13348 NULL
120203 +hscx_empty_fifo_13360 hscx_empty_fifo 2 13360 NULL
120204 +iso_sched_alloc_13377 iso_sched_alloc 1 13377 NULL nohasharray
120205 +wep_key_not_found_read_13377 wep_key_not_found_read 3 13377 &iso_sched_alloc_13377
120206 +ext4_meta_trans_blocks_13380 ext4_meta_trans_blocks 0-3-2 13380 NULL
120207 +lov_mds_md_size_13388 lov_mds_md_size 0-1 13388 NULL nohasharray
120208 +dis_bypass_write_13388 dis_bypass_write 3 13388 &lov_mds_md_size_13388
120209 +netxen_alloc_sds_rings_13417 netxen_alloc_sds_rings 2 13417 NULL
120210 +sctp_setsockopt_peer_primary_addr_13440 sctp_setsockopt_peer_primary_addr 3 13440 NULL
120211 +ath6kl_cfg80211_connect_event_13443 ath6kl_cfg80211_connect_event 7-8-9 13443 NULL
120212 +sb_init_dio_done_wq_13482 sb_init_dio_done_wq 0 13482 NULL
120213 +data_read_13494 data_read 3 13494 NULL nohasharray
120214 +ext_prop_data_store_13494 ext_prop_data_store 3 13494 &data_read_13494
120215 +ocfs2_align_bytes_to_blocks_13512 ocfs2_align_bytes_to_blocks 0-2 13512 NULL
120216 +core_status_13515 core_status 4 13515 NULL
120217 +smk_write_mapped_13519 smk_write_mapped 3 13519 NULL
120218 +bm_init_13529 bm_init 2 13529 NULL
120219 +llcp_sock_recvmsg_13556 llcp_sock_recvmsg 4 13556 NULL
120220 +ieee80211_if_read_ap_power_level_13558 ieee80211_if_read_ap_power_level 3 13558 NULL
120221 +hash_net4_expire_13559 hash_net4_expire 4 13559 NULL
120222 +read_file_antenna_13574 read_file_antenna 3 13574 NULL
120223 +cache_write_13589 cache_write 3 13589 NULL
120224 +Rd_Indx_13602 Rd_Indx 3-2 13602 NULL
120225 +wm8994_bulk_write_13615 wm8994_bulk_write 2-3 13615 NULL
120226 +pmcraid_get_minor_13619 pmcraid_get_minor 0 13619 NULL
120227 +packet_snd_13634 packet_snd 3 13634 NULL
120228 +blk_msg_write_13655 blk_msg_write 3 13655 NULL
120229 +cache_downcall_13666 cache_downcall 3 13666 NULL
120230 +usb_get_string_13693 usb_get_string 0 13693 NULL
120231 +fw_iso_buffer_alloc_13704 fw_iso_buffer_alloc 2 13704 NULL
120232 +audit_unpack_string_13748 audit_unpack_string 3 13748 NULL
120233 +udf_direct_IO_13765 udf_direct_IO 4 13765 NULL
120234 +ieee802154_alloc_device_13767 ieee802154_alloc_device 1 13767 NULL
120235 +fb_sys_read_13778 fb_sys_read 3 13778 NULL
120236 +ath6kl_mgmt_powersave_ap_13791 ath6kl_mgmt_powersave_ap 6 13791 NULL
120237 +random_read_13815 random_read 3 13815 NULL
120238 +mutex_lock_interruptible_nested_13817 mutex_lock_interruptible_nested 0 13817 NULL
120239 +hsi_register_board_info_13820 hsi_register_board_info 2 13820 NULL
120240 +___mei_cl_send_13821 ___mei_cl_send 3 13821 NULL
120241 +qce_ahash_hmac_setkey_13837 qce_ahash_hmac_setkey 3 13837 NULL
120242 +enc_pools_insert_13849 enc_pools_insert 3 13849 NULL
120243 +evdev_ioctl_compat_13851 evdev_ioctl_compat 2 13851 NULL
120244 +compat_ip_setsockopt_13870 compat_ip_setsockopt 5 13870 NULL
120245 +qp_memcpy_to_queue_13886 qp_memcpy_to_queue 5-2 13886 NULL
120246 +snd_pcm_aio_read_13900 snd_pcm_aio_read 3 13900 NULL
120247 +cfg80211_inform_bss_width_13933 cfg80211_inform_bss_width 9 13933 NULL
120248 +ext3_xattr_block_get_13936 ext3_xattr_block_get 0 13936 NULL
120249 +ieee80211_if_read_dot11MeshForwarding_13940 ieee80211_if_read_dot11MeshForwarding 3 13940 NULL nohasharray
120250 +ocfs2_xa_value_truncate_13940 ocfs2_xa_value_truncate 2 13940 &ieee80211_if_read_dot11MeshForwarding_13940
120251 +iwl_dbgfs_protection_mode_read_13943 iwl_dbgfs_protection_mode_read 3 13943 NULL
120252 +ieee80211_if_read_min_discovery_timeout_13946 ieee80211_if_read_min_discovery_timeout 3 13946 NULL
120253 +lpfc_idiag_queacc_read_13950 lpfc_idiag_queacc_read 3 13950 NULL
120254 +osc_grant_shrink_interval_seq_write_13952 osc_grant_shrink_interval_seq_write 3 13952 NULL
120255 +snd_pcm_plug_slave_size_13967 snd_pcm_plug_slave_size 0-2 13967 NULL
120256 +qcam_read_13977 qcam_read 3 13977 NULL
120257 +dsp_read_13980 dsp_read 2 13980 NULL
120258 +dvb_demux_read_13981 dvb_demux_read 3 13981 NULL
120259 +sddr09_write_data_14014 sddr09_write_data 3 14014 NULL
120260 +btrfs_get_blocks_direct_14016 btrfs_get_blocks_direct 2 14016 NULL
120261 +dmi_format_ids_14018 dmi_format_ids 2 14018 NULL
120262 +iscsi_create_flashnode_conn_14022 iscsi_create_flashnode_conn 4 14022 NULL
120263 +pci_add_ext_cap_save_buffer_14032 pci_add_ext_cap_save_buffer 3 14032 NULL
120264 +dvb_usercopy_14036 dvb_usercopy 2 14036 NULL
120265 +ieee80211_if_fmt_aid_14055 ieee80211_if_fmt_aid 3 14055 NULL
120266 +ovs_nla_alloc_flow_actions_14056 ovs_nla_alloc_flow_actions 1 14056 NULL
120267 +sta_agg_status_read_14058 sta_agg_status_read 3 14058 NULL
120268 +lov_stripeoffset_seq_write_14078 lov_stripeoffset_seq_write 3 14078 NULL
120269 +do_proc_readlink_14096 do_proc_readlink 3 14096 NULL
120270 +ext4_journal_blocks_per_page_14127 ext4_journal_blocks_per_page 0 14127 NULL
120271 +isku_sysfs_read_light_14140 isku_sysfs_read_light 6 14140 NULL
120272 +em_canid_change_14150 em_canid_change 3 14150 NULL
120273 +gsm_dlci_data_14155 gsm_dlci_data 3 14155 NULL
120274 +midi_alloc_ep_req_14159 midi_alloc_ep_req 2 14159 NULL
120275 +print_input_mask_14168 print_input_mask 3-0 14168 NULL
120276 +ocfs2_xattr_value_truncate_14183 ocfs2_xattr_value_truncate 3 14183 NULL
120277 +datafab_read_data_14186 datafab_read_data 4 14186 NULL
120278 +hfsplus_brec_find_14200 hfsplus_brec_find 0 14200 NULL
120279 +alloc_async_14208 alloc_async 1 14208 NULL
120280 +ath6kl_regread_write_14220 ath6kl_regread_write 3 14220 NULL
120281 +ieee80211_if_write_uapsd_max_sp_len_14233 ieee80211_if_write_uapsd_max_sp_len 3 14233 NULL
120282 +dma_declare_coherent_memory_14244 dma_declare_coherent_memory 4 14244 NULL
120283 +btrfs_token_file_extent_ram_bytes_14247 btrfs_token_file_extent_ram_bytes 0 14247 NULL
120284 +ath6kl_connect_event_14267 ath6kl_connect_event 7-8-9 14267 NULL
120285 +rr_status_14293 rr_status 5 14293 NULL
120286 +read_default_ldt_14302 read_default_ldt 2 14302 NULL nohasharray
120287 +lustre_pack_reply_flags_14302 lustre_pack_reply_flags 2 14302 &read_default_ldt_14302
120288 +oo_objects_14319 oo_objects 0 14319 NULL
120289 +p9_client_zc_rpc_14345 p9_client_zc_rpc 7 14345 NULL
120290 +alloc_tx_struct_14349 alloc_tx_struct 1 14349 NULL
120291 +hash_ipportnet4_expire_14354 hash_ipportnet4_expire 4 14354 NULL
120292 +snd_pcm_lib_readv_14363 snd_pcm_lib_readv 0-3 14363 NULL
120293 +lowpan_read_14369 lowpan_read 3 14369 NULL
120294 +ath6kl_regdump_read_14393 ath6kl_regdump_read 3 14393 NULL
120295 +smk_write_onlycap_14400 smk_write_onlycap 3 14400 NULL
120296 +mtd_concat_create_14416 mtd_concat_create 2 14416 NULL
120297 +get_kcore_size_14425 get_kcore_size 0 14425 NULL
120298 +_iwl_dbgfs_sram_write_14439 _iwl_dbgfs_sram_write 3 14439 NULL
120299 +block_size_14443 block_size 0 14443 NULL
120300 +lmv_user_md_size_14456 lmv_user_md_size 0-1 14456 NULL
120301 +snd_emu10k1_proc_spdif_status_14457 snd_emu10k1_proc_spdif_status 4-5 14457 NULL
120302 +ath10k_write_htt_stats_mask_14458 ath10k_write_htt_stats_mask 3 14458 NULL
120303 +lustre_msg_size_v2_14470 lustre_msg_size_v2 0-1 14470 NULL
120304 +dma_transfer_size_14473 dma_transfer_size 0 14473 NULL
120305 +udplite_getfrag_14479 udplite_getfrag 3-4 14479 NULL
120306 +ieee80211_if_read_dot11MeshGateAnnouncementProtocol_14486 ieee80211_if_read_dot11MeshGateAnnouncementProtocol 3 14486 NULL
120307 +ocfs2_debug_read_14507 ocfs2_debug_read 3 14507 NULL
120308 +dataflash_read_user_otp_14536 dataflash_read_user_otp 3-2 14536 NULL nohasharray
120309 +ep0_write_14536 ep0_write 3 14536 &dataflash_read_user_otp_14536
120310 +picolcd_debug_eeprom_read_14549 picolcd_debug_eeprom_read 3 14549 NULL
120311 +qp_host_alloc_queue_14566 qp_host_alloc_queue 1 14566 NULL
120312 +SyS_setdomainname_14569 SyS_setdomainname 2 14569 NULL
120313 +idmap_pipe_downcall_14591 idmap_pipe_downcall 3 14591 NULL
120314 +ceph_osdc_alloc_request_14597 ceph_osdc_alloc_request 3 14597 NULL
120315 +ufshcd_compose_dev_cmd_14626 ufshcd_compose_dev_cmd 0 14626 NULL
120316 +dbJoin_14644 dbJoin 0 14644 NULL
120317 +profile_replace_14652 profile_replace 3 14652 NULL
120318 +usnic_vnic_dump_14662 usnic_vnic_dump 3 14662 NULL
120319 +min_bytes_needed_14675 min_bytes_needed 0 14675 NULL
120320 +nvme_trans_log_info_exceptions_14677 nvme_trans_log_info_exceptions 3 14677 NULL
120321 +pipeline_enc_tx_stat_fifo_int_read_14680 pipeline_enc_tx_stat_fifo_int_read 3 14680 NULL
120322 +ieee80211_if_fmt_rc_rateidx_mask_2ghz_14683 ieee80211_if_fmt_rc_rateidx_mask_2ghz 3 14683 NULL
120323 +SyS_fsetxattr_14702 SyS_fsetxattr 4 14702 NULL
120324 +persistent_ram_ecc_string_14704 persistent_ram_ecc_string 0 14704 NULL
120325 +u_audio_playback_14709 u_audio_playback 3 14709 NULL
120326 +rtw_cbuf_alloc_14710 rtw_cbuf_alloc 1 14710 NULL
120327 +vfd_write_14717 vfd_write 3 14717 NULL
120328 +__blk_end_request_14729 __blk_end_request 3 14729 NULL
120329 +raid1_resize_14740 raid1_resize 2 14740 NULL
120330 +i915_error_state_buf_init_14742 i915_error_state_buf_init 2 14742 NULL
120331 +btrfs_inode_extref_name_len_14752 btrfs_inode_extref_name_len 0 14752 NULL
120332 +rx_rx_cmplt_read_14753 rx_rx_cmplt_read 3 14753 NULL
120333 +regmap_range_read_file_14775 regmap_range_read_file 3 14775 NULL
120334 +sta_dev_read_14782 sta_dev_read 3 14782 NULL
120335 +keys_proc_write_14792 keys_proc_write 3 14792 NULL
120336 +ext4_kvmalloc_14796 ext4_kvmalloc 1 14796 NULL
120337 +__kfifo_in_14797 __kfifo_in 3-0 14797 NULL nohasharray
120338 +ttm_page_pool_free_14797 ttm_page_pool_free 2-0 14797 &__kfifo_in_14797
120339 +hpet_readl_14801 hpet_readl 0 14801 NULL nohasharray
120340 +snd_als300_gcr_read_14801 snd_als300_gcr_read 0 14801 &hpet_readl_14801
120341 +do_tune_cpucache_14828 do_tune_cpucache 2 14828 NULL
120342 +mrp_attr_create_14853 mrp_attr_create 3 14853 NULL
120343 +lcd_write_14857 lcd_write 3 14857 NULL
120344 +get_user_cpu_mask_14861 get_user_cpu_mask 2 14861 NULL
120345 +acpi_os_allocate_14892 acpi_os_allocate 1 14892 NULL
120346 +SYSC_readv_14901 SYSC_readv 3 14901 NULL
120347 +netlbl_catmap_walk_14902 netlbl_catmap_walk 0-2 14902 NULL
120348 +__arch_hweight64_14923 __arch_hweight64 0 14923 NULL nohasharray
120349 +qp_memcpy_to_queue_iov_14923 qp_memcpy_to_queue_iov 5-2 14923 &__arch_hweight64_14923 nohasharray
120350 +ptlrpc_prep_req_pool_14923 ptlrpc_prep_req_pool 4 14923 &qp_memcpy_to_queue_iov_14923
120351 +ocfs2_expand_nonsparse_inode_14936 ocfs2_expand_nonsparse_inode 3-4 14936 NULL
120352 +queue_cnt_14951 queue_cnt 0 14951 NULL
120353 +unix_dgram_recvmsg_14952 unix_dgram_recvmsg 4 14952 NULL
120354 +videobuf_read_stream_14956 videobuf_read_stream 3 14956 NULL
120355 +mce_flush_rx_buffer_14976 mce_flush_rx_buffer 2 14976 NULL
120356 +setkey_14987 setkey 3 14987 NULL nohasharray
120357 +gpio_twl4030_write_14987 gpio_twl4030_write 1 14987 &setkey_14987
120358 +sctp_setsockopt_default_sndinfo_15011 sctp_setsockopt_default_sndinfo 3 15011 NULL
120359 +blk_integrity_tuple_size_15027 blk_integrity_tuple_size 0 15027 NULL
120360 +read_file_node_aggr_15040 read_file_node_aggr 3 15040 NULL
120361 +cld_pipe_downcall_15058 cld_pipe_downcall 3 15058 NULL
120362 +ieee80211_if_read_uapsd_max_sp_len_15067 ieee80211_if_read_uapsd_max_sp_len 3 15067 NULL
120363 +nfs4_write_cached_acl_15070 nfs4_write_cached_acl 4 15070 NULL
120364 +ntfs_copy_from_user_15072 ntfs_copy_from_user 3-5-0 15072 NULL
120365 +pppoe_recvmsg_15073 pppoe_recvmsg 4 15073 NULL
120366 +smscore_load_firmware_family2_15086 smscore_load_firmware_family2 3 15086 NULL
120367 +compat_SyS_pwritev_15118 compat_SyS_pwritev 3 15118 NULL
120368 +hex_dump_to_buffer_15121 hex_dump_to_buffer 6 15121 NULL
120369 +start_port_15124 start_port 0 15124 NULL
120370 +ipwireless_ppp_mru_15153 ipwireless_ppp_mru 0 15153 NULL
120371 +SYSC_setdomainname_15180 SYSC_setdomainname 2 15180 NULL
120372 +iscsi_create_endpoint_15193 iscsi_create_endpoint 1 15193 NULL
120373 +mtt_alloc_res_15211 mtt_alloc_res 5 15211 NULL
120374 +bfad_debugfs_write_regrd_15218 bfad_debugfs_write_regrd 3 15218 NULL
120375 +iwl_dbgfs_sram_write_15239 iwl_dbgfs_sram_write 3 15239 NULL
120376 +il_dbgfs_rx_stats_read_15243 il_dbgfs_rx_stats_read 3 15243 NULL
120377 +wacom_led_putimage_15264 wacom_led_putimage 4 15264 NULL
120378 +simple_strtol_15273 simple_strtol 0 15273 NULL
120379 +fw_realloc_buffer_15280 fw_realloc_buffer 2 15280 NULL
120380 +kovaplus_sysfs_read_15337 kovaplus_sysfs_read 6 15337 NULL
120381 +ioread16_15342 ioread16 0 15342 NULL
120382 +ept_prefetch_gpte_15348 ept_prefetch_gpte 4 15348 NULL
120383 +acpi_ut_create_string_object_15360 acpi_ut_create_string_object 1 15360 NULL
120384 +graph_depth_read_15371 graph_depth_read 3 15371 NULL
120385 +fq_codel_zalloc_15378 fq_codel_zalloc 1 15378 NULL
120386 +alloc_fddidev_15382 alloc_fddidev 1 15382 NULL
120387 +pipeline_csum_to_rx_xfer_swi_read_15403 pipeline_csum_to_rx_xfer_swi_read 3 15403 NULL
120388 +get_modalias_15406 get_modalias 2 15406 NULL
120389 +__videobuf_copy_to_user_15423 __videobuf_copy_to_user 4-0 15423 NULL
120390 +tcp_mtu_to_mss_15438 tcp_mtu_to_mss 2-0 15438 NULL
120391 +hpsa_change_queue_depth_15449 hpsa_change_queue_depth 2 15449 NULL
120392 +memweight_15450 memweight 2 15450 NULL
120393 +__clone_and_map_data_bio_15498 __clone_and_map_data_bio 3 15498 NULL
120394 +zd_chip_is_zd1211b_15518 zd_chip_is_zd1211b 0 15518 NULL
120395 +ifx_spi_write_15531 ifx_spi_write 3 15531 NULL
120396 +p9_check_zc_errors_15534 p9_check_zc_errors 4 15534 NULL
120397 +xfrm_state_mtu_15548 xfrm_state_mtu 0-2 15548 NULL
120398 +persistent_status_15574 persistent_status 4 15574 NULL
120399 +bnx2fc_process_unsol_compl_15576 bnx2fc_process_unsol_compl 2 15576 NULL
120400 +vme_user_write_15587 vme_user_write 3 15587 NULL
120401 +compat_fillonedir_15620 compat_fillonedir 3 15620 NULL
120402 +proc_loginuid_read_15631 proc_loginuid_read 3 15631 NULL
120403 +tomoyo_scan_bprm_15642 tomoyo_scan_bprm 2-4 15642 NULL nohasharray
120404 +pipeline_hs_tx_stat_fifo_int_read_15642 pipeline_hs_tx_stat_fifo_int_read 3 15642 &tomoyo_scan_bprm_15642 nohasharray
120405 +sk_memory_allocated_add_15642 sk_memory_allocated_add 2 15642 &pipeline_hs_tx_stat_fifo_int_read_15642
120406 +joydev_handle_JSIOCSBTNMAP_15643 joydev_handle_JSIOCSBTNMAP 3 15643 NULL
120407 +fs_path_add_15648 fs_path_add 3 15648 NULL
120408 +xsd_read_15653 xsd_read 3 15653 NULL
120409 +unix_bind_15668 unix_bind 3 15668 NULL
120410 +dm_read_15674 dm_read 3 15674 NULL nohasharray
120411 +SyS_connect_15674 SyS_connect 3 15674 &dm_read_15674
120412 +uinput_str_to_user_15695 uinput_str_to_user 3 15695 NULL
120413 +__sk_migrate_realloc_15709 __sk_migrate_realloc 3 15709 NULL
120414 +tracing_snapshot_write_15719 tracing_snapshot_write 3 15719 NULL
120415 +HiSax_readstatus_15752 HiSax_readstatus 2 15752 NULL
120416 +smk_read_direct_15803 smk_read_direct 3 15803 NULL
120417 +gnttab_expand_15817 gnttab_expand 1 15817 NULL nohasharray
120418 +nameseq_list_15817 nameseq_list 3-0 15817 &gnttab_expand_15817
120419 +afs_proc_rootcell_write_15822 afs_proc_rootcell_write 3 15822 NULL
120420 +table_size_15851 table_size 0-1-2 15851 NULL
120421 +write_file_tx99_15856 write_file_tx99 3 15856 NULL
120422 +media_entity_init_15870 media_entity_init 2-4 15870 NULL
120423 +__mptctl_ioctl_15875 __mptctl_ioctl 2 15875 NULL
120424 +parse_audio_stream_data_15937 parse_audio_stream_data 3 15937 NULL
120425 +power_read_15939 power_read 3 15939 NULL
120426 +lpfc_idiag_drbacc_read_15948 lpfc_idiag_drbacc_read 3 15948 NULL
120427 +snd_pcm_lib_read_transfer_15952 snd_pcm_lib_read_transfer 5-2-4 15952 NULL
120428 +memblock_virt_alloc_try_nid_15954 memblock_virt_alloc_try_nid 1 15954 NULL
120429 +smk_read_ptrace_15974 smk_read_ptrace 3 15974 NULL
120430 +viafb_vt1636_proc_write_16018 viafb_vt1636_proc_write 3 16018 NULL
120431 +dccp_recvmsg_16056 dccp_recvmsg 4 16056 NULL
120432 +read_file_spectral_period_16057 read_file_spectral_period 3 16057 NULL
120433 +SYSC_kexec_file_load_16058 SYSC_kexec_file_load 3 16058 NULL
120434 +si5351_msynth_params_address_16062 si5351_msynth_params_address 0-1 16062 NULL
120435 +isr_tx_exch_complete_read_16103 isr_tx_exch_complete_read 3 16103 NULL
120436 +isr_hw_pm_mode_changes_read_16110 isr_hw_pm_mode_changes_read 3 16110 NULL nohasharray
120437 +dma_tx_requested_read_16110 dma_tx_requested_read 3 16110 &isr_hw_pm_mode_changes_read_16110
120438 +udelay_test_write_16111 udelay_test_write 3 16111 NULL
120439 +snd_dma_pointer_16126 snd_dma_pointer 0-2 16126 NULL
120440 +fsm_init_16134 fsm_init 2 16134 NULL
120441 +ext4_xattr_block_get_16148 ext4_xattr_block_get 0 16148 NULL
120442 +optimal_reclaimed_pages_16172 optimal_reclaimed_pages 0 16172 NULL
120443 +mapping_level_16188 mapping_level 2-0 16188 NULL
120444 +i40e_allocate_virt_mem_d_16191 i40e_allocate_virt_mem_d 3 16191 NULL
120445 +ath10k_htt_rx_ring_size_16201 ath10k_htt_rx_ring_size 0 16201 NULL
120446 +cipso_v4_map_cat_rng_hton_16203 cipso_v4_map_cat_rng_hton 0 16203 NULL
120447 +SyS_pselect6_16210 SyS_pselect6 1 16210 NULL
120448 +create_table_16213 create_table 2 16213 NULL
120449 +ath9k_hw_ar9287_dump_eeprom_16224 ath9k_hw_ar9287_dump_eeprom 5-4 16224 NULL
120450 +atomic_read_file_16227 atomic_read_file 3 16227 NULL
120451 +BcmGetSectionValStartOffset_16235 BcmGetSectionValStartOffset 0 16235 NULL
120452 +lov_prep_brw_set_16246 lov_prep_brw_set 3 16246 NULL
120453 +i40e_dbg_dump_read_16247 i40e_dbg_dump_read 3 16247 NULL
120454 +il_dbgfs_disable_ht40_write_16249 il_dbgfs_disable_ht40_write 3 16249 NULL
120455 +SyS_fgetxattr_16254 SyS_fgetxattr 4 16254 NULL
120456 +reiserfs_acl_count_16265 reiserfs_acl_count 0-1 16265 NULL
120457 +ocfs2_xattr_bucket_value_truncate_16279 ocfs2_xattr_bucket_value_truncate 4 16279 NULL
120458 +nand_bch_init_16280 nand_bch_init 3-2 16280 NULL nohasharray
120459 +drbd_setsockopt_16280 drbd_setsockopt 5 16280 &nand_bch_init_16280
120460 +account_16283 account 0-4-2 16283 NULL nohasharray
120461 +mirror_status_16283 mirror_status 5 16283 &account_16283
120462 +jumpshot_read_data_16287 jumpshot_read_data 4 16287 NULL
120463 +mo_xattr_get_16288 mo_xattr_get 0 16288 NULL
120464 +stk_allocate_buffers_16291 stk_allocate_buffers 2 16291 NULL
120465 +rbd_segment_offset_16293 rbd_segment_offset 0-2 16293 NULL
120466 +rsc_mgr_init_16299 rsc_mgr_init 3 16299 NULL
120467 +kvm_handle_hva_range_16312 kvm_handle_hva_range 3-2 16312 NULL
120468 +sysfs_create_groups_16360 sysfs_create_groups 0 16360 NULL
120469 +total_ps_buffered_read_16365 total_ps_buffered_read 3 16365 NULL
120470 +iscsi_tcp_conn_setup_16376 iscsi_tcp_conn_setup 2 16376 NULL
120471 +nv50_pioc_create_16389 nv50_pioc_create 5 16389 NULL
120472 +ieee80211_if_read_tsf_16420 ieee80211_if_read_tsf 3 16420 NULL
120473 +rxrpc_server_keyring_16431 rxrpc_server_keyring 3 16431 NULL
120474 +__bio_add_page_16435 __bio_add_page 0-4 16435 NULL
120475 +cmdline_store_16442 cmdline_store 4 16442 NULL
120476 +copy_from_user_bvec_16447 copy_from_user_bvec 0-4 16447 NULL
120477 +btrfs_truncate_inode_items_16452 btrfs_truncate_inode_items 4 16452 NULL
120478 +netlink_change_ngroups_16457 netlink_change_ngroups 2 16457 NULL
120479 +req_capsule_get_size_16467 req_capsule_get_size 0 16467 NULL
120480 +tracing_readme_read_16493 tracing_readme_read 3 16493 NULL
120481 +KEY_OFFSET_16504 KEY_OFFSET 0 16504 NULL
120482 +snd_interval_max_16529 snd_interval_max 0 16529 NULL
120483 +raid10_resize_16537 raid10_resize 2 16537 NULL
120484 +lpfc_debugfs_read_16566 lpfc_debugfs_read 3 16566 NULL
120485 +agp_allocate_memory_wrap_16576 agp_allocate_memory_wrap 1 16576 NULL
120486 +lustre_msg_hdr_size_v2_16589 lustre_msg_hdr_size_v2 0-1 16589 NULL
120487 +compat_SyS_migrate_pages_16618 compat_SyS_migrate_pages 2 16618 NULL
120488 +rtw_set_wpa_ie_16633 rtw_set_wpa_ie 3 16633 NULL
120489 +btrfs_get_token_32_16651 btrfs_get_token_32 0 16651 NULL
120490 +__wa_populate_dto_urb_16699 __wa_populate_dto_urb 3-4 16699 NULL
120491 +_iwl_dbgfs_bt_force_ant_write_16701 _iwl_dbgfs_bt_force_ant_write 3 16701 NULL
120492 +__proc_lnet_buffers_16717 __proc_lnet_buffers 5 16717 NULL
120493 +__copy_to_user_swizzled_16748 __copy_to_user_swizzled 3-4 16748 NULL
120494 +arcmsr_adjust_disk_queue_depth_16756 arcmsr_adjust_disk_queue_depth 2 16756 NULL
120495 +blk_rq_map_user_iov_16772 blk_rq_map_user_iov 5 16772 NULL
120496 +i2o_parm_issue_16790 i2o_parm_issue 0 16790 NULL
120497 +get_server_iovec_16804 get_server_iovec 2 16804 NULL
120498 +drm_malloc_ab_16831 drm_malloc_ab 1-2 16831 NULL
120499 +scsi_mode_sense_16835 scsi_mode_sense 5 16835 NULL
120500 +hfsplus_min_io_size_16859 hfsplus_min_io_size 0 16859 NULL
120501 +alloc_idx_lebs_16872 alloc_idx_lebs 2 16872 NULL
120502 +carl9170_debugfs_ampdu_state_read_16873 carl9170_debugfs_ampdu_state_read 3 16873 NULL
120503 +st_write_16874 st_write 3 16874 NULL
120504 +__kfifo_peek_n_16877 __kfifo_peek_n 0 16877 NULL
120505 +psb_unlocked_ioctl_16926 psb_unlocked_ioctl 2 16926 NULL nohasharray
120506 +snd_gf1_mem_proc_dump_16926 snd_gf1_mem_proc_dump 5 16926 &psb_unlocked_ioctl_16926
120507 +_sp2d_alloc_16944 _sp2d_alloc 1-2-3 16944 NULL
120508 +squashfs_read_table_16945 squashfs_read_table 3 16945 NULL
120509 +svcxdr_dupstr_16963 svcxdr_dupstr 3 16963 NULL
120510 +keyctl_instantiate_key_iov_16969 keyctl_instantiate_key_iov 3 16969 NULL
120511 +ceph_read_dir_17005 ceph_read_dir 3 17005 NULL
120512 +copy_counters_to_user_17027 copy_counters_to_user 5 17027 NULL
120513 +C_SYSC_keyctl_17041 C_SYSC_keyctl 4 17041 NULL
120514 +jffs2_trusted_setxattr_17048 jffs2_trusted_setxattr 4 17048 NULL
120515 +__arch_hweight32_17060 __arch_hweight32 0 17060 NULL
120516 +sddr55_read_data_17072 sddr55_read_data 4 17072 NULL
120517 +dvb_dvr_read_17073 dvb_dvr_read 3 17073 NULL
120518 +simple_transaction_read_17076 simple_transaction_read 3 17076 NULL
120519 +carl9170_debugfs_mem_usage_read_17084 carl9170_debugfs_mem_usage_read 3 17084 NULL
120520 +entry_length_17093 entry_length 0 17093 NULL
120521 +write_mem_17114 write_mem 3 17114 NULL
120522 +pvr2_hdw_state_report_17121 pvr2_hdw_state_report 3 17121 NULL
120523 +do_blockdev_direct_IO_17143 do_blockdev_direct_IO 0-6 17143 NULL
120524 +nouveau_instobj_create__17144 nouveau_instobj_create_ 4 17144 NULL
120525 +jumpshot_write_data_17151 jumpshot_write_data 4 17151 NULL
120526 +mxt_upload_cfg_mem_17157 mxt_upload_cfg_mem 4 17157 NULL
120527 +sep_read_17161 sep_read 3 17161 NULL
120528 +befs_nls2utf_17163 befs_nls2utf 3 17163 NULL
120529 +tx_tx_start_templates_read_17164 tx_tx_start_templates_read 3 17164 NULL
120530 +UniStrnlen_17169 UniStrnlen 0 17169 NULL
120531 +access_remote_vm_17189 access_remote_vm 0 17189 NULL nohasharray
120532 +iwl_dbgfs_txfifo_flush_write_17189 iwl_dbgfs_txfifo_flush_write 3 17189 &access_remote_vm_17189
120533 +driver_state_read_17194 driver_state_read 3 17194 NULL nohasharray
120534 +iscsit_find_cmd_from_itt_or_dump_17194 iscsit_find_cmd_from_itt_or_dump 3 17194 &driver_state_read_17194
120535 +sync_request_17208 sync_request 2 17208 NULL
120536 +dn_recvmsg_17213 dn_recvmsg 4 17213 NULL
120537 +lprocfs_read_frac_helper_17261 lprocfs_read_frac_helper 0 17261 NULL
120538 +error_error_frame_cts_nul_flid_read_17262 error_error_frame_cts_nul_flid_read 3 17262 NULL
120539 +alloc_ep_17269 alloc_ep 1 17269 NULL
120540 +pg_read_17276 pg_read 3 17276 NULL
120541 +raw_recvmsg_17277 raw_recvmsg 4 17277 NULL
120542 +hmac_sha256_17278 hmac_sha256 2 17278 NULL
120543 +neigh_hash_grow_17283 neigh_hash_grow 2 17283 NULL
120544 +minstrel_stats_read_17290 minstrel_stats_read 3 17290 NULL
120545 +__ptlrpc_request_bufs_pack_17298 __ptlrpc_request_bufs_pack 4 17298 NULL
120546 +ieee80211_if_fmt_dot11MeshForwarding_17301 ieee80211_if_fmt_dot11MeshForwarding 3 17301 NULL
120547 +mb_cache_create_17307 mb_cache_create 2 17307 NULL
120548 +gnttab_map_frames_v2_17314 gnttab_map_frames_v2 2 17314 NULL
120549 +ieee80211_if_read_dot11MeshHWMPperrMinInterval_17346 ieee80211_if_read_dot11MeshHWMPperrMinInterval 3 17346 NULL
120550 +ath6kl_wmi_send_mgmt_cmd_17347 ath6kl_wmi_send_mgmt_cmd 7 17347 NULL
120551 +mdc_import_seq_write_17409 mdc_import_seq_write 3 17409 NULL
120552 +lpfc_debugfs_dif_err_write_17424 lpfc_debugfs_dif_err_write 3 17424 NULL
120553 +sta_connected_time_read_17435 sta_connected_time_read 3 17435 NULL
120554 +libcfs_ipif_enumerate_17445 libcfs_ipif_enumerate 0 17445 NULL
120555 +nla_get_u32_17455 nla_get_u32 0 17455 NULL
120556 +__ref_totlen_17461 __ref_totlen 0 17461 NULL
120557 +probe_kernel_write_17481 probe_kernel_write 3 17481 NULL
120558 +TSS_rawhmac_17486 TSS_rawhmac 3 17486 NULL
120559 +copy_page_from_iter_17512 copy_page_from_iter 3-0 17512 NULL
120560 +reiserfs_direct_IO_17513 reiserfs_direct_IO 4 17513 NULL
120561 +lbs_highrssi_write_17515 lbs_highrssi_write 3 17515 NULL
120562 +qp_free_res_17541 qp_free_res 5 17541 NULL
120563 +__copy_to_user_17551 __copy_to_user 0-3 17551 NULL
120564 +copy_from_user_17559 copy_from_user 3-0 17559 NULL
120565 +hash_netport4_expire_17573 hash_netport4_expire 4 17573 NULL
120566 +wil_write_file_rxon_17581 wil_write_file_rxon 3 17581 NULL
120567 +acpi_ut_create_package_object_17594 acpi_ut_create_package_object 1 17594 NULL
120568 +neigh_hash_alloc_17595 neigh_hash_alloc 1 17595 NULL
120569 +osst_execute_17607 osst_execute 7-6 17607 NULL
120570 +ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout_17618 ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout 3 17618 NULL
120571 +dma_map_page_17628 dma_map_page 0 17628 NULL
120572 +twl4030_set_gpio_direction_17645 twl4030_set_gpio_direction 1 17645 NULL
120573 +SYSC_migrate_pages_17657 SYSC_migrate_pages 2 17657 NULL
120574 +packet_setsockopt_17662 packet_setsockopt 5 17662 NULL
120575 +pwr_enable_ps_read_17686 pwr_enable_ps_read 3 17686 NULL
120576 +venus_rename_17707 venus_rename 4-5 17707 NULL
120577 +exofs_read_lookup_dev_table_17733 exofs_read_lookup_dev_table 3 17733 NULL
120578 +sctpprobe_read_17741 sctpprobe_read 3 17741 NULL
120579 +nv92_gpio_intr_mask_17773 nv92_gpio_intr_mask 4-3 17773 NULL
120580 +shrink_slab_node_17794 shrink_slab_node 3 17794 NULL
120581 +lpuart_copy_rx_to_tty_17801 lpuart_copy_rx_to_tty 3 17801 NULL
120582 +gnet_stats_copy_app_17821 gnet_stats_copy_app 3 17821 NULL
120583 +cipso_v4_gentag_rbm_17836 cipso_v4_gentag_rbm 0 17836 NULL
120584 +em28xx_audio_ep_packet_size_17844 em28xx_audio_ep_packet_size 0 17844 NULL
120585 +dm_stats_message_17863 dm_stats_message 5 17863 NULL
120586 +sisusb_send_bulk_msg_17864 sisusb_send_bulk_msg 3 17864 NULL
120587 +alloc_sja1000dev_17868 alloc_sja1000dev 1 17868 NULL
120588 +virtio_cread32_17873 virtio_cread32 0 17873 NULL
120589 +ray_cs_essid_proc_write_17875 ray_cs_essid_proc_write 3 17875 NULL
120590 +orinoco_set_key_17878 orinoco_set_key 5-7 17878 NULL nohasharray
120591 +i40e_align_l2obj_base_17878 i40e_align_l2obj_base 0-1 17878 &orinoco_set_key_17878
120592 +init_per_cpu_17880 init_per_cpu 1 17880 NULL
120593 +ieee80211_if_fmt_dot11MeshMaxPeerLinks_17883 ieee80211_if_fmt_dot11MeshMaxPeerLinks 3 17883 NULL
120594 +ieee80211_if_fmt_dot11MeshHWMPRootMode_17890 ieee80211_if_fmt_dot11MeshHWMPRootMode 3 17890 NULL
120595 +dev_pm_opp_get_opp_count_17911 dev_pm_opp_get_opp_count 0 17911 NULL
120596 +xfs_buf_associate_memory_17915 xfs_buf_associate_memory 3 17915 NULL
120597 +tipc_port_iovec_rcv_17921 tipc_port_iovec_rcv 3 17921 NULL
120598 +scsi_bufflen_17933 scsi_bufflen 0 17933 NULL
120599 +__mutex_lock_check_stamp_17947 __mutex_lock_check_stamp 0 17947 NULL
120600 +beacon_interval_write_17952 beacon_interval_write 3 17952 NULL
120601 +calc_nr_buckets_17976 calc_nr_buckets 0 17976 NULL
120602 +ext4_ext_calc_credits_for_single_extent_17983 ext4_ext_calc_credits_for_single_extent 0-2 17983 NULL
120603 +smk_write_cipso_17989 smk_write_cipso 3 17989 NULL
120604 +gnttab_max_grant_frames_17993 gnttab_max_grant_frames 0 17993 NULL
120605 +pvr2_v4l2_read_18006 pvr2_v4l2_read 3 18006 NULL
120606 +o2hb_highest_node_18034 o2hb_highest_node 0 18034 NULL
120607 +cryptd_alloc_instance_18048 cryptd_alloc_instance 2-3 18048 NULL
120608 +__btrfs_drop_extents_18049 __btrfs_drop_extents 5 18049 NULL
120609 +ddebug_proc_write_18055 ddebug_proc_write 3 18055 NULL
120610 +lua_sysfs_read_18062 lua_sysfs_read 6 18062 NULL
120611 +fpregs_get_18066 fpregs_get 4 18066 NULL
120612 +kvm_read_guest_page_18074 kvm_read_guest_page 5 18074 NULL
120613 +SYSC_pselect6_18076 SYSC_pselect6 1 18076 NULL
120614 +SYSC_semtimedop_18091 SYSC_semtimedop 3 18091 NULL
120615 +mpi_alloc_18094 mpi_alloc 1 18094 NULL
120616 +dfs_file_read_18116 dfs_file_read 3 18116 NULL
120617 +svc_getnl_18120 svc_getnl 0 18120 NULL
120618 +paging32_gpte_to_gfn_lvl_18131 paging32_gpte_to_gfn_lvl 0-2-1 18131 NULL
120619 +selinux_inode_setsecurity_18148 selinux_inode_setsecurity 4 18148 NULL
120620 +enable_ints_write_18170 enable_ints_write 3 18170 NULL
120621 +pccard_store_cis_18176 pccard_store_cis 6 18176 NULL
120622 +orinoco_add_extscan_result_18207 orinoco_add_extscan_result 3 18207 NULL
120623 +gsm_control_message_18209 gsm_control_message 4 18209 NULL
120624 +do_ipv6_setsockopt_18215 do_ipv6_setsockopt 5 18215 NULL
120625 +fill_ext_prop_18233 fill_ext_prop 0 18233 NULL
120626 +gnttab_alloc_grant_references_18240 gnttab_alloc_grant_references 1 18240 NULL
120627 +alloc_trace_uprobe_18247 alloc_trace_uprobe 3 18247 NULL
120628 +rfcomm_sock_setsockopt_18254 rfcomm_sock_setsockopt 5 18254 NULL
120629 +qdisc_class_hash_alloc_18262 qdisc_class_hash_alloc 1 18262 NULL
120630 +gfs2_alloc_sort_buffer_18275 gfs2_alloc_sort_buffer 1 18275 NULL
120631 +alloc_ring_18278 alloc_ring 2-4 18278 NULL
120632 +bio_phys_segments_18281 bio_phys_segments 0 18281 NULL nohasharray
120633 +nouveau_subdev_create__18281 nouveau_subdev_create_ 7 18281 &bio_phys_segments_18281
120634 +ext4_readpages_18283 ext4_readpages 4 18283 NULL
120635 +mmc_send_bus_test_18285 mmc_send_bus_test 4 18285 NULL
120636 +um_idi_write_18293 um_idi_write 3 18293 NULL
120637 +nouveau_disp_create__18305 nouveau_disp_create_ 4-7 18305 NULL
120638 +lustre_msg_hdr_size_18308 lustre_msg_hdr_size 2 18308 NULL
120639 +class_add_profile_18315 class_add_profile 1-3-5 18315 NULL
120640 +csio_mem_read_18319 csio_mem_read 3 18319 NULL
120641 +alloc_and_copy_string_18321 alloc_and_copy_string 2 18321 NULL
120642 +ecryptfs_send_message_18322 ecryptfs_send_message 2 18322 NULL
120643 +bio_integrity_advance_18324 bio_integrity_advance 2 18324 NULL
120644 +copy_page_to_iter_18345 copy_page_to_iter 0-3 18345 NULL
120645 +lcd_proc_write_18351 lcd_proc_write 3 18351 NULL
120646 +pwr_power_save_off_read_18355 pwr_power_save_off_read 3 18355 NULL
120647 +SyS_process_vm_readv_18366 SyS_process_vm_readv 3-5 18366 NULL
120648 +ep_io_18367 ep_io 0 18367 NULL
120649 +qib_user_sdma_num_pages_18371 qib_user_sdma_num_pages 0 18371 NULL
120650 +__ceph_getxattr_18386 __ceph_getxattr 0 18386 NULL
120651 +ci_role_write_18388 ci_role_write 3 18388 NULL
120652 +hdlc_empty_fifo_18397 hdlc_empty_fifo 2 18397 NULL
120653 +adis16136_show_serial_18402 adis16136_show_serial 3 18402 NULL
120654 +nvif_device_init_18418 nvif_device_init 6 18418 NULL
120655 +memblock_virt_alloc_node_nopanic_18431 memblock_virt_alloc_node_nopanic 1 18431 NULL
120656 +iscsi_create_flashnode_sess_18433 iscsi_create_flashnode_sess 4 18433 NULL
120657 +snd_hda_get_connections_18437 snd_hda_get_connections 0 18437 NULL
120658 +fuse_perform_write_18457 fuse_perform_write 4 18457 NULL
120659 +regset_tls_set_18459 regset_tls_set 4 18459 NULL
120660 +pci_vpd_lrdt_size_18479 pci_vpd_lrdt_size 0 18479 NULL nohasharray
120661 +mite_bytes_in_transit_18479 mite_bytes_in_transit 0 18479 &pci_vpd_lrdt_size_18479
120662 +udpv6_setsockopt_18487 udpv6_setsockopt 5 18487 NULL
120663 +btrfs_fiemap_18501 btrfs_fiemap 3 18501 NULL
120664 +__copy_user_zeroing_intel_18510 __copy_user_zeroing_intel 0-3 18510 NULL
120665 +snd_vx_inb_18514 snd_vx_inb 0 18514 NULL
120666 +snd_gus_dram_poke_18525 snd_gus_dram_poke 4 18525 NULL
120667 +nouveau_fifo_channel_create__18530 nouveau_fifo_channel_create_ 9 18530 NULL
120668 +tipc_send2port_18531 tipc_send2port 4 18531 NULL
120669 +seq_copy_in_user_18543 seq_copy_in_user 3 18543 NULL
120670 +sas_change_queue_depth_18555 sas_change_queue_depth 2 18555 NULL
120671 +smk_write_rules_list_18565 smk_write_rules_list 3 18565 NULL
120672 +debug_output_18575 debug_output 3 18575 NULL
120673 +filemap_fdatawait_range_18600 filemap_fdatawait_range 0 18600 NULL nohasharray
120674 +slabinfo_write_18600 slabinfo_write 3 18600 &filemap_fdatawait_range_18600
120675 +iowarrior_write_18604 iowarrior_write 3 18604 NULL
120676 +from_buffer_18625 from_buffer 3 18625 NULL
120677 +kmalloc_kernel_18641 kmalloc_kernel 1 18641 NULL
120678 +snd_pcm_oss_write3_18657 snd_pcm_oss_write3 0-3 18657 NULL
120679 +ieee80211_if_fmt_rssi_threshold_18664 ieee80211_if_fmt_rssi_threshold 3 18664 NULL
120680 +xfs_iext_insert_18667 xfs_iext_insert 3 18667 NULL
120681 +fnic_stats_debugfs_read_18688 fnic_stats_debugfs_read 3 18688 NULL
120682 +echo_client_prep_commit_18693 echo_client_prep_commit 8 18693 NULL
120683 +iwl_dbgfs_rx_handlers_read_18708 iwl_dbgfs_rx_handlers_read 3 18708 NULL
120684 +ceph_alloc_page_vector_18710 ceph_alloc_page_vector 1 18710 NULL
120685 +blk_rq_bytes_18715 blk_rq_bytes 0 18715 NULL
120686 +nfs4_init_callback_netid_18717 nfs4_init_callback_netid 3 18717 NULL
120687 +snd_als4k_gcr_read_addr_18741 snd_als4k_gcr_read_addr 0 18741 NULL
120688 +o2hb_debug_create_18744 o2hb_debug_create 4 18744 NULL
120689 +__erst_read_to_erange_from_nvram_18748 __erst_read_to_erange_from_nvram 0 18748 NULL
120690 +wep_packets_read_18751 wep_packets_read 3 18751 NULL
120691 +read_file_dump_nfcal_18766 read_file_dump_nfcal 3 18766 NULL
120692 +SyS_lsetxattr_18776 SyS_lsetxattr 4 18776 NULL
120693 +alloc_fcdev_18780 alloc_fcdev 1 18780 NULL
120694 +fence_context_alloc_18792 fence_context_alloc 1 18792 NULL
120695 +dm_stats_print_18815 dm_stats_print 7 18815 NULL
120696 +sys_modify_ldt_18824 sys_modify_ldt 3 18824 NULL
120697 +mtf_test_write_18844 mtf_test_write 3 18844 NULL
120698 +sctp_setsockopt_events_18862 sctp_setsockopt_events 3 18862 NULL
120699 +ieee80211_if_read_element_ttl_18869 ieee80211_if_read_element_ttl 3 18869 NULL
120700 +xlog_find_verify_log_record_18870 xlog_find_verify_log_record 2 18870 NULL
120701 +devm_mdiobus_alloc_size_18902 devm_mdiobus_alloc_size 2 18902 NULL
120702 +tracing_thresh_write_18909 tracing_thresh_write 3 18909 NULL
120703 +ceph_setxattr_18913 ceph_setxattr 4 18913 NULL
120704 +ieee80211_rx_mgmt_disassoc_18927 ieee80211_rx_mgmt_disassoc 3 18927 NULL
120705 +snapshot_write_next_18937 snapshot_write_next 0 18937 NULL
120706 +__nla_reserve_18974 __nla_reserve 3 18974 NULL
120707 +layout_in_gaps_19006 layout_in_gaps 2 19006 NULL
120708 +huge_page_size_19008 huge_page_size 0 19008 NULL
120709 +hash_netport6_expire_19013 hash_netport6_expire 4 19013 NULL
120710 +sysfs_create_dir_ns_19033 sysfs_create_dir_ns 0 19033 NULL
120711 +revalidate_19043 revalidate 2 19043 NULL
120712 +afs_vnode_store_data_19048 afs_vnode_store_data 2-3-4-5 19048 NULL
120713 +osc_pinger_recov_seq_write_19056 osc_pinger_recov_seq_write 3 19056 NULL
120714 +create_gpadl_header_19064 create_gpadl_header 2 19064 NULL
120715 +ceph_create_snap_context_19082 ceph_create_snap_context 1 19082 NULL
120716 +sta_last_seq_ctrl_read_19106 sta_last_seq_ctrl_read 3 19106 NULL
120717 +cifs_readv_from_socket_19109 cifs_readv_from_socket 3 19109 NULL
120718 +skb_gro_offset_19123 skb_gro_offset 0 19123 NULL
120719 +cma_bitmap_maxno_19135 cma_bitmap_maxno 0 19135 NULL
120720 +snd_als4k_iobase_readl_19136 snd_als4k_iobase_readl 0 19136 NULL
120721 +alloc_irdadev_19140 alloc_irdadev 1 19140 NULL
120722 +sleep_auth_read_19159 sleep_auth_read 3 19159 NULL
120723 +smk_write_access2_19170 smk_write_access2 3 19170 NULL
120724 +read_extent_buffer_to_user_19189 read_extent_buffer_to_user 4-3 19189 NULL
120725 +iwl_dbgfs_reply_tx_error_read_19205 iwl_dbgfs_reply_tx_error_read 3 19205 NULL
120726 +__copy_to_user_inatomic_19214 __copy_to_user_inatomic 0-3 19214 NULL
120727 +dev_counters_read_19216 dev_counters_read 3 19216 NULL
120728 +wbcir_tx_19219 wbcir_tx 3 19219 NULL
120729 +snd_mask_max_19224 snd_mask_max 0 19224 NULL
120730 +bio_alloc_mddev_19238 bio_alloc_mddev 2 19238 NULL
120731 +ucma_query_19260 ucma_query 4 19260 NULL
120732 +il_dbgfs_rxon_filter_flags_read_19281 il_dbgfs_rxon_filter_flags_read 3 19281 NULL
120733 +batadv_tt_save_orig_buffer_19288 batadv_tt_save_orig_buffer 4 19288 NULL nohasharray
120734 +cfg80211_rx_unprot_mlme_mgmt_19288 cfg80211_rx_unprot_mlme_mgmt 3 19288 &batadv_tt_save_orig_buffer_19288
120735 +qc_capture_19298 qc_capture 3 19298 NULL
120736 +ocfs2_prepare_inode_for_refcount_19303 ocfs2_prepare_inode_for_refcount 4-3 19303 NULL
120737 +event_tx_stuck_read_19305 event_tx_stuck_read 3 19305 NULL
120738 +debug_read_19322 debug_read 3 19322 NULL
120739 +lbs_host_sleep_write_19332 lbs_host_sleep_write 3 19332 NULL nohasharray
120740 +cfg80211_inform_bss_19332 cfg80211_inform_bss 8 19332 &lbs_host_sleep_write_19332
120741 +closure_sub_19359 closure_sub 2 19359 NULL
120742 +firmware_data_write_19360 firmware_data_write 6-5 19360 NULL
120743 +read_zero_19366 read_zero 3 19366 NULL
120744 +interpret_user_input_19393 interpret_user_input 2 19393 NULL
120745 +sync_fill_pt_info_19397 sync_fill_pt_info 0 19397 NULL
120746 +pep_recvmsg_19402 pep_recvmsg 4 19402 NULL
120747 +hid_hw_raw_request_19408 hid_hw_raw_request 0 19408 NULL
120748 +dvbdmx_write_19423 dvbdmx_write 3 19423 NULL
120749 +SyS_sched_getaffinity_19444 SyS_sched_getaffinity 2 19444 NULL
120750 +xfrm_alg_auth_len_19454 xfrm_alg_auth_len 0 19454 NULL
120751 +gnet_stats_copy_19458 gnet_stats_copy 4 19458 NULL
120752 +gp2ap020a00f_get_thresh_reg_19468 gp2ap020a00f_get_thresh_reg 0 19468 NULL
120753 +sky2_read16_19475 sky2_read16 0 19475 NULL
120754 +__read_status_pciv2_19492 __read_status_pciv2 0 19492 NULL
120755 +kstrtoll_from_user_19500 kstrtoll_from_user 2 19500 NULL
120756 +ext4_add_new_descs_19509 ext4_add_new_descs 3 19509 NULL
120757 +batadv_tvlv_container_register_19520 batadv_tvlv_container_register 5 19520 NULL
120758 +ttm_dma_page_pool_free_19527 ttm_dma_page_pool_free 2-0 19527 NULL
120759 +cfc_write_array_to_buffer_19529 cfc_write_array_to_buffer 3 19529 NULL
120760 +nfc_llcp_build_tlv_19536 nfc_llcp_build_tlv 3 19536 NULL
120761 +gfn_to_index_19558 gfn_to_index 0-1-3-2 19558 NULL
120762 +ocfs2_control_message_19564 ocfs2_control_message 3 19564 NULL
120763 +nfsd_read_19568 nfsd_read 5 19568 NULL
120764 +ieee80211_key_alloc_19575 ieee80211_key_alloc 3 19575 NULL
120765 +bm_status_read_19583 bm_status_read 3 19583 NULL
120766 +load_xattr_datum_19594 load_xattr_datum 0 19594 NULL
120767 +drbg_sec_strength_19604 drbg_sec_strength 0 19604 NULL
120768 +__mei_cl_recv_19636 __mei_cl_recv 3 19636 NULL
120769 +parser_init_19651 parser_init 2 19651 NULL
120770 +LoadBitmap_19658 LoadBitmap 2 19658 NULL
120771 +memblock_virt_alloc_low_nopanic_19714 memblock_virt_alloc_low_nopanic 1 19714 NULL
120772 +read_reg_19723 read_reg 0 19723 NULL
120773 +wm8350_block_write_19727 wm8350_block_write 2-3 19727 NULL
120774 +memcpy_toiovecend_19736 memcpy_toiovecend 4-3 19736 NULL
120775 +snd_es1968_get_dma_ptr_19747 snd_es1968_get_dma_ptr 0 19747 NULL
120776 +p9_client_read_19750 p9_client_read 5-0 19750 NULL
120777 +pnpbios_proc_write_19758 pnpbios_proc_write 3 19758 NULL
120778 +ocfs2_readpages_19759 ocfs2_readpages 4 19759 NULL
120779 +jffs2_acl_from_medium_19762 jffs2_acl_from_medium 2 19762 NULL
120780 +readhscx_19769 readhscx 0 19769 NULL
120781 +ath10k_write_htt_max_amsdu_ampdu_19820 ath10k_write_htt_max_amsdu_ampdu 3 19820 NULL
120782 +irda_setsockopt_19824 irda_setsockopt 5 19824 NULL
120783 +vfs_getxattr_19832 vfs_getxattr 0 19832 NULL
120784 +crypt_alloc_buffer_19846 crypt_alloc_buffer 2 19846 NULL
120785 +cfg80211_mlme_register_mgmt_19852 cfg80211_mlme_register_mgmt 5 19852 NULL
120786 +__nla_put_19857 __nla_put 3 19857 NULL
120787 +mrp_request_join_19882 mrp_request_join 4 19882 NULL
120788 +aes_decrypt_interrupt_read_19910 aes_decrypt_interrupt_read 3 19910 NULL
120789 +ps_upsd_max_apturn_read_19918 ps_upsd_max_apturn_read 3 19918 NULL
120790 +mangle_name_19923 mangle_name 0 19923 NULL
120791 +cgroup_task_count_19930 cgroup_task_count 0 19930 NULL
120792 +guest_read_tsc_19931 guest_read_tsc 0 19931 NULL
120793 +azx_get_pos_lpib_19933 azx_get_pos_lpib 0 19933 NULL
120794 +v4l2_ctrl_new_19942 v4l2_ctrl_new 8-12 19942 NULL
120795 +iwl_dbgfs_rx_queue_read_19943 iwl_dbgfs_rx_queue_read 3 19943 NULL
120796 +cfg80211_rx_assoc_resp_19944 cfg80211_rx_assoc_resp 4 19944 NULL
120797 +ll_xattr_cache_list_19954 ll_xattr_cache_list 0 19954 NULL
120798 +get_jack_mode_name_19976 get_jack_mode_name 4 19976 NULL
120799 +attach_hdlc_protocol_19986 attach_hdlc_protocol 3 19986 NULL
120800 +rtw_set_wps_probe_resp_19989 rtw_set_wps_probe_resp 3 19989 NULL
120801 +lustre_pack_request_19992 lustre_pack_request 3 19992 NULL
120802 +find_overflow_devnum_19995 find_overflow_devnum 0 19995 NULL
120803 +diva_um_idi_read_20003 diva_um_idi_read 0 20003 NULL
120804 +lov_stripe_md_size_20009 lov_stripe_md_size 0-1 20009 NULL nohasharray
120805 +event_trigger_write_20009 event_trigger_write 3 20009 &lov_stripe_md_size_20009
120806 +tree_mod_log_eb_move_20011 tree_mod_log_eb_move 5 20011 NULL
120807 +SYSC_fgetxattr_20027 SYSC_fgetxattr 4 20027 NULL
120808 +split_scan_timeout_read_20029 split_scan_timeout_read 3 20029 NULL
120809 +iwl_mvm_power_mac_dbgfs_read_20067 iwl_mvm_power_mac_dbgfs_read 0-4 20067 NULL
120810 +target_message_20072 target_message 2 20072 NULL
120811 +rawv6_sendmsg_20080 rawv6_sendmsg 4 20080 NULL
120812 +fuse_conn_limit_read_20084 fuse_conn_limit_read 3 20084 NULL
120813 +aat2870_reg_write_file_20086 aat2870_reg_write_file 3 20086 NULL
120814 +team_options_register_20091 team_options_register 3 20091 NULL
120815 +qla2x00_adjust_sdev_qdepth_up_20097 qla2x00_adjust_sdev_qdepth_up 2 20097 NULL
120816 +root_nfs_copy_20111 root_nfs_copy 3 20111 NULL
120817 +hptiop_adjust_disk_queue_depth_20122 hptiop_adjust_disk_queue_depth 2 20122 NULL
120818 +ext4_ext_direct_IO_20165 ext4_ext_direct_IO 4 20165 NULL
120819 +tomoyo_commit_ok_20167 tomoyo_commit_ok 2 20167 NULL
120820 +read_flush_pipefs_20171 read_flush_pipefs 3 20171 NULL
120821 +wep_addr_key_count_read_20174 wep_addr_key_count_read 3 20174 NULL
120822 +crystalhd_map_dio_20181 crystalhd_map_dio 3 20181 NULL
120823 +pvr2_ctrl_value_to_sym_20229 pvr2_ctrl_value_to_sym 5 20229 NULL
120824 +rose_sendmsg_20249 rose_sendmsg 4 20249 NULL
120825 +tm6000_i2c_send_regs_20250 tm6000_i2c_send_regs 5 20250 NULL
120826 +btrfs_header_nritems_20296 btrfs_header_nritems 0 20296 NULL
120827 +r10_sync_page_io_20307 r10_sync_page_io 3 20307 NULL
120828 +dm_get_reserved_bio_based_ios_20315 dm_get_reserved_bio_based_ios 0 20315 NULL
120829 +tx_tx_burst_programmed_read_20320 tx_tx_burst_programmed_read 3 20320 NULL
120830 +vx_send_msg_nolock_20322 vx_send_msg_nolock 0 20322 NULL
120831 +snd_cs4281_BA1_read_20323 snd_cs4281_BA1_read 5 20323 NULL
120832 +gfs2_glock_nq_m_20347 gfs2_glock_nq_m 1 20347 NULL
120833 +handle_arr_calc_size_20355 handle_arr_calc_size 0-1 20355 NULL
120834 +smk_set_cipso_20379 smk_set_cipso 3 20379 NULL
120835 +snd_nm256_readl_20394 snd_nm256_readl 0 20394 NULL
120836 +SyS_get_mempolicy_20399 SyS_get_mempolicy 3 20399 NULL nohasharray
120837 +__kfifo_from_user_20399 __kfifo_from_user 3 20399 &SyS_get_mempolicy_20399
120838 +compat_ipv6_setsockopt_20468 compat_ipv6_setsockopt 5 20468 NULL
120839 +read_buf_20469 read_buf 2 20469 NULL
120840 +bio_trim_20472 bio_trim 2 20472 NULL
120841 +btrfs_get_32_20476 btrfs_get_32 0 20476 NULL
120842 +xfs_iext_realloc_direct_20521 xfs_iext_realloc_direct 2 20521 NULL
120843 +drbd_bm_resize_20522 drbd_bm_resize 2 20522 NULL
120844 +amd_create_gatt_pages_20537 amd_create_gatt_pages 1 20537 NULL
120845 +scsi_report_opcode_20551 scsi_report_opcode 3 20551 NULL
120846 +venus_create_20555 venus_create 4 20555 NULL
120847 +btrfs_super_log_root_20565 btrfs_super_log_root 0 20565 NULL
120848 +crypto_ahash_reqsize_20569 crypto_ahash_reqsize 0 20569 NULL
120849 +kvm_test_age_hva_20593 kvm_test_age_hva 2 20593 NULL
120850 +set_secure_conn_20596 set_secure_conn 4 20596 NULL
120851 +sync_timeline_create_20601 sync_timeline_create 2 20601 NULL
120852 +lirc_write_20604 lirc_write 3 20604 NULL
120853 +qib_qsfp_write_20614 qib_qsfp_write 0-4-2 20614 NULL
120854 +snd_pcm_oss_prepare_20641 snd_pcm_oss_prepare 0 20641 NULL
120855 +get_extent_skip_holes_20642 get_extent_skip_holes 2 20642 NULL
120856 +kfifo_copy_to_user_20646 kfifo_copy_to_user 3-4 20646 NULL
120857 +cpulist_scnprintf_20648 cpulist_scnprintf 2-0 20648 NULL
120858 +oz_add_farewell_20652 oz_add_farewell 5 20652 NULL
120859 +oz_cdev_read_20659 oz_cdev_read 3 20659 NULL
120860 +snd_hdsp_playback_copy_20676 snd_hdsp_playback_copy 5 20676 NULL
120861 +dvb_dmxdev_buffer_read_20682 dvb_dmxdev_buffer_read 0-4 20682 NULL
120862 +cpumask_size_20683 cpumask_size 0 20683 NULL
120863 +btrfs_node_blockptr_20685 btrfs_node_blockptr 0 20685 NULL
120864 +xpcs_reg_addr_write_20694 xpcs_reg_addr_write 3 20694 NULL
120865 +read_file_tgt_int_stats_20697 read_file_tgt_int_stats 3 20697 NULL
120866 +__maestro_read_20700 __maestro_read 0 20700 NULL
120867 +cipso_v4_gentag_rng_20703 cipso_v4_gentag_rng 0 20703 NULL
120868 +pcpu_page_first_chunk_20712 pcpu_page_first_chunk 1 20712 NULL
120869 +hfs_direct_IO_20714 hfs_direct_IO 4 20714 NULL
120870 +ocfs2_read_xattr_bucket_20722 ocfs2_read_xattr_bucket 0 20722 NULL
120871 +security_context_to_sid_force_20724 security_context_to_sid_force 2 20724 NULL
120872 +fb_prepare_logo_20743 fb_prepare_logo 0 20743 NULL
120873 +vol_cdev_direct_write_20751 vol_cdev_direct_write 3 20751 NULL
120874 +ocfs2_align_bytes_to_clusters_20754 ocfs2_align_bytes_to_clusters 2 20754 NULL
120875 +brcmf_p2p_escan_20763 brcmf_p2p_escan 2 20763 NULL
120876 +fb_alloc_cmap_gfp_20792 fb_alloc_cmap_gfp 2 20792 NULL
120877 +iwl_dbgfs_rxon_flags_read_20795 iwl_dbgfs_rxon_flags_read 3 20795 NULL
120878 +edid_write_20797 edid_write 3 20797 NULL
120879 +lowpan_write_20800 lowpan_write 3 20800 NULL
120880 +strndup_user_20819 strndup_user 2 20819 NULL
120881 +tipc_msg_build_20825 tipc_msg_build 3 20825 NULL
120882 +wl1271_format_buffer_20834 wl1271_format_buffer 2 20834 NULL
120883 +uvc_alloc_entity_20836 uvc_alloc_entity 4-3 20836 NULL
120884 +p9_tag_alloc_20845 p9_tag_alloc 3 20845 NULL
120885 +nvme_trans_supported_vpd_pages_20847 nvme_trans_supported_vpd_pages 4 20847 NULL
120886 +get_name_20855 get_name 4 20855 NULL
120887 +iwl_dbgfs_pm_params_read_20866 iwl_dbgfs_pm_params_read 3 20866 NULL
120888 +snd_pcm_capture_avail_20867 snd_pcm_capture_avail 0 20867 NULL
120889 +srq_free_res_20868 srq_free_res 5 20868 NULL
120890 +cfs_cpt_table_create_20884 cfs_cpt_table_create 1 20884 NULL
120891 +req_capsule_filled_sizes_20888 req_capsule_filled_sizes 0 20888 NULL
120892 +rb_simple_write_20890 rb_simple_write 3 20890 NULL
120893 +sisusb_send_packet_20891 sisusb_send_packet 2 20891 NULL
120894 +key_icverrors_read_20895 key_icverrors_read 3 20895 NULL
120895 +vfio_msi_enable_20906 vfio_msi_enable 2 20906 NULL
120896 +lbs_rdbbp_write_20918 lbs_rdbbp_write 3 20918 NULL
120897 +htable_bits_20933 htable_bits 0 20933 NULL
120898 +altera_set_ir_post_20948 altera_set_ir_post 2 20948 NULL
120899 +rx_rx_phy_hdr_read_20950 rx_rx_phy_hdr_read 3 20950 NULL
120900 +rsxx_cram_read_20957 rsxx_cram_read 3 20957 NULL
120901 +nfs_map_name_to_uid_20962 nfs_map_name_to_uid 3 20962 NULL
120902 +snd_rme9652_playback_copy_20970 snd_rme9652_playback_copy 5 20970 NULL
120903 +alg_setsockopt_20985 alg_setsockopt 5 20985 NULL
120904 +qib_verbs_send_20999 qib_verbs_send 5-3 20999 NULL
120905 +btrfs_inode_ref_name_len_21024 btrfs_inode_ref_name_len 0 21024 NULL
120906 +arch_gnttab_init_21030 arch_gnttab_init 1 21030 NULL
120907 +rx_defrag_tkip_called_read_21031 rx_defrag_tkip_called_read 3 21031 NULL
120908 +srp_change_queue_depth_21038 srp_change_queue_depth 2 21038 NULL
120909 +fsl_edma_prep_dma_cyclic_21042 fsl_edma_prep_dma_cyclic 4-3 21042 NULL
120910 +lbs_threshold_read_21046 lbs_threshold_read 5 21046 NULL
120911 +proc_fault_inject_write_21058 proc_fault_inject_write 3 21058 NULL
120912 +qdisc_get_default_21072 qdisc_get_default 2 21072 NULL
120913 +event_calibration_read_21083 event_calibration_read 3 21083 NULL
120914 +bl_add_page_to_bio_21094 bl_add_page_to_bio 2 21094 NULL nohasharray
120915 +multipath_status_21094 multipath_status 5 21094 &bl_add_page_to_bio_21094
120916 +rate_control_pid_events_read_21099 rate_control_pid_events_read 3 21099 NULL
120917 +ath6kl_send_go_probe_resp_21113 ath6kl_send_go_probe_resp 3 21113 NULL
120918 +_efx_mcdi_rpc_async_21119 _efx_mcdi_rpc_async 4-5 21119 NULL
120919 +i2400m_rx_trace_21127 i2400m_rx_trace 3 21127 NULL
120920 +mei_dbgfs_read_active_21172 mei_dbgfs_read_active 3 21172 NULL
120921 +cx18_v4l2_read_21196 cx18_v4l2_read 3 21196 NULL
120922 +ipc_rcu_alloc_21208 ipc_rcu_alloc 1 21208 NULL
120923 +scsi_execute_req_flags_21215 scsi_execute_req_flags 5 21215 NULL
120924 +get_numpages_21227 get_numpages 0-1-2 21227 NULL
120925 +input_ff_create_21240 input_ff_create 2 21240 NULL
120926 +cfg80211_notify_new_peer_candidate_21242 cfg80211_notify_new_peer_candidate 4 21242 NULL
120927 +fru_length_21257 fru_length 0 21257 NULL
120928 +rtw_set_wps_beacon_21262 rtw_set_wps_beacon 3 21262 NULL
120929 +ocfs2_blocks_for_bytes_21268 ocfs2_blocks_for_bytes 0-2 21268 NULL
120930 +drm_universal_plane_init_21296 drm_universal_plane_init 6 21296 NULL
120931 +do_msg_fill_21307 do_msg_fill 3 21307 NULL
120932 +add_res_range_21310 add_res_range 4 21310 NULL
120933 +get_zeroed_page_21322 get_zeroed_page 0 21322 NULL
120934 +ftrace_profile_read_21327 ftrace_profile_read 3 21327 NULL
120935 +read_file_bool_bmps_21344 read_file_bool_bmps 3 21344 NULL
120936 +azx_get_delay_from_lpib_21348 azx_get_delay_from_lpib 3 21348 NULL
120937 +gfs2_ea_get_copy_21353 gfs2_ea_get_copy 0 21353 NULL
120938 +allocate_cmdlines_buffer_21355 allocate_cmdlines_buffer 1 21355 NULL
120939 +alloc_orinocodev_21371 alloc_orinocodev 1 21371 NULL
120940 +SYSC_rt_sigpending_21379 SYSC_rt_sigpending 2 21379 NULL
120941 +video_ioctl2_21380 video_ioctl2 2 21380 NULL
120942 +insert_ptr_21386 insert_ptr 6 21386 NULL
120943 +diva_get_driver_dbg_mask_21399 diva_get_driver_dbg_mask 0 21399 NULL
120944 +snd_m3_inw_21406 snd_m3_inw 0 21406 NULL
120945 +usnic_ib_dump_vf_hdr_21423 usnic_ib_dump_vf_hdr 3 21423 NULL
120946 +snapshot_read_next_21426 snapshot_read_next 0 21426 NULL
120947 +tcp_bound_to_half_wnd_21429 tcp_bound_to_half_wnd 0-2 21429 NULL
120948 +aggr_size_tx_agg_vs_rate_read_21438 aggr_size_tx_agg_vs_rate_read 3 21438 NULL
120949 +nouveau_clock_create__21449 nouveau_clock_create_ 8 21449 NULL
120950 +__ertm_hdr_size_21450 __ertm_hdr_size 0 21450 NULL
120951 +mei_nfc_send_21477 mei_nfc_send 3 21477 NULL
120952 +read_file_xmit_21487 read_file_xmit 3 21487 NULL
120953 +mmc_alloc_sg_21504 mmc_alloc_sg 1 21504 NULL
120954 +il_dbgfs_stations_read_21532 il_dbgfs_stations_read 3 21532 NULL
120955 +cipso_v4_map_cat_enum_hton_21540 cipso_v4_map_cat_enum_hton 0 21540 NULL
120956 +rxrpc_send_data_21553 rxrpc_send_data 5 21553 NULL
120957 +rx_rx_beacon_early_term_read_21559 rx_rx_beacon_early_term_read 3 21559 NULL
120958 +xfs_buf_read_uncached_21585 xfs_buf_read_uncached 3 21585 NULL
120959 +snd_es18xx_mixer_read_21586 snd_es18xx_mixer_read 0 21586 NULL
120960 +ocfs2_acl_from_xattr_21604 ocfs2_acl_from_xattr 2 21604 NULL
120961 +filemap_get_page_21606 filemap_get_page 2 21606 NULL
120962 +ocfs2_refcount_cow_hunk_21630 ocfs2_refcount_cow_hunk 3-4 21630 NULL
120963 +__jfs_getxattr_21631 __jfs_getxattr 0 21631 NULL
120964 +atalk_sendmsg_21677 atalk_sendmsg 4 21677 NULL
120965 +ocfs2_xattr_get_nolock_21678 ocfs2_xattr_get_nolock 0 21678 NULL
120966 +regmap_register_patch_21681 regmap_register_patch 3 21681 NULL
120967 +rtllib_alloc_txb_21687 rtllib_alloc_txb 1 21687 NULL
120968 +evdev_ioctl_handler_21705 evdev_ioctl_handler 2 21705 NULL
120969 +unix_skb_len_21722 unix_skb_len 0 21722 NULL
120970 +lprocfs_wr_import_21728 lprocfs_wr_import 3 21728 NULL
120971 +mthca_alloc_init_21754 mthca_alloc_init 2 21754 NULL
120972 +usbat_flash_read_data_21762 usbat_flash_read_data 4 21762 NULL
120973 +gen_pool_add_21776 gen_pool_add 3 21776 NULL
120974 +xfs_da_grow_inode_int_21785 xfs_da_grow_inode_int 3 21785 NULL
120975 +dvb_generic_ioctl_21810 dvb_generic_ioctl 2 21810 NULL
120976 +_iwl_dbgfs_sta_drain_write_21837 _iwl_dbgfs_sta_drain_write 3 21837 NULL
120977 +oom_adj_read_21847 oom_adj_read 3 21847 NULL
120978 +lpfc_idiag_extacc_avail_get_21865 lpfc_idiag_extacc_avail_get 0-3 21865 NULL
120979 +brcms_debugfs_hardware_read_21867 brcms_debugfs_hardware_read 3 21867 NULL
120980 +sisusbcon_bmove_21873 sisusbcon_bmove 6-5-7 21873 NULL
120981 +ldlm_lock_create_21888 ldlm_lock_create 7 21888 NULL
120982 +__btrfs_direct_write_21894 __btrfs_direct_write 3 21894 NULL
120983 +dbAllocCtl_21911 dbAllocCtl 0 21911 NULL
120984 +qsfp_1_read_21915 qsfp_1_read 3 21915 NULL
120985 +twl_i2c_write_u16_21953 twl_i2c_write_u16 3 21953 NULL
120986 +__build_xattrs_21979 __build_xattrs 0 21979 NULL
120987 +SYSC_prctl_21980 SYSC_prctl 4 21980 NULL
120988 +compat_rw_copy_check_uvector_22001 compat_rw_copy_check_uvector 0-3 22001 NULL nohasharray
120989 +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
120990 +regcache_sync_block_raw_flush_22021 regcache_sync_block_raw_flush 3-4 22021 NULL
120991 +btrfs_get_16_22023 btrfs_get_16 0 22023 NULL
120992 +_sp2d_min_pg_22032 _sp2d_min_pg 0 22032 NULL
120993 +zd_usb_read_fw_22049 zd_usb_read_fw 4 22049 NULL
120994 +ieee80211_if_fmt_dropped_frames_ttl_22054 ieee80211_if_fmt_dropped_frames_ttl 3 22054 NULL
120995 +btrfs_reloc_clone_csums_22077 btrfs_reloc_clone_csums 2-3 22077 NULL
120996 +mem_rw_22085 mem_rw 3 22085 NULL
120997 +kstrtos32_from_user_22087 kstrtos32_from_user 2 22087 NULL
120998 +rt2x00debug_read_crypto_stats_22109 rt2x00debug_read_crypto_stats 3 22109 NULL
120999 +snd_hda_codec_read_22130 snd_hda_codec_read 0 22130 NULL
121000 +SyS_sched_setaffinity_22148 SyS_sched_setaffinity 2 22148 NULL
121001 +do_tcp_sendpages_22155 do_tcp_sendpages 4 22155 NULL
121002 +nve0_aux_mask_22158 nve0_aux_mask 2 22158 NULL
121003 +__kfifo_alloc_22173 __kfifo_alloc 3 22173 NULL
121004 +rfcomm_sock_recvmsg_22227 rfcomm_sock_recvmsg 4 22227 NULL
121005 +mem_write_22232 mem_write 3 22232 NULL
121006 +p9_virtio_zc_request_22240 p9_virtio_zc_request 6-5 22240 NULL
121007 +prepare_to_wait_event_22247 prepare_to_wait_event 0 22247 NULL
121008 +compat_process_vm_rw_22254 compat_process_vm_rw 3-5 22254 NULL
121009 +ping_common_sendmsg_22261 ping_common_sendmsg 5 22261 NULL
121010 +add_res_tree_22263 add_res_tree 7 22263 NULL
121011 +queue_max_sectors_22280 queue_max_sectors 0 22280 NULL
121012 +__tun_chr_ioctl_22300 __tun_chr_ioctl 4 22300 NULL nohasharray
121013 +pci_vpd_srdt_size_22300 pci_vpd_srdt_size 0 22300 &__tun_chr_ioctl_22300
121014 +mesh_table_alloc_22305 mesh_table_alloc 1 22305 NULL
121015 +lov_setstripe_22307 lov_setstripe 2 22307 NULL
121016 +udpv6_sendmsg_22316 udpv6_sendmsg 4 22316 NULL
121017 +C_SYSC_msgrcv_22320 C_SYSC_msgrcv 3 22320 NULL
121018 +atomic_read_22342 atomic_read 0 22342 NULL
121019 +ll_lazystatfs_seq_write_22353 ll_lazystatfs_seq_write 3 22353 NULL
121020 +snd_pcm_alsa_frames_22363 snd_pcm_alsa_frames 2 22363 NULL
121021 +evdev_ioctl_22371 evdev_ioctl 2 22371 NULL
121022 +alloc_large_system_hash_22391 alloc_large_system_hash 2 22391 NULL
121023 +zoran_write_22404 zoran_write 3 22404 NULL
121024 +queue_reply_22416 queue_reply 3 22416 NULL
121025 +__set_enter_print_fmt_22431 __set_enter_print_fmt 0 22431 NULL
121026 +queue_max_segments_22441 queue_max_segments 0 22441 NULL
121027 +handle_received_packet_22457 handle_received_packet 3 22457 NULL
121028 +ecryptfs_write_22488 ecryptfs_write 4-3 22488 NULL
121029 +qib_user_sdma_alloc_header_22490 qib_user_sdma_alloc_header 2 22490 NULL
121030 +cache_write_procfs_22491 cache_write_procfs 3 22491 NULL
121031 +mutex_lock_interruptible_22505 mutex_lock_interruptible 0 22505 NULL
121032 +trim_no_bitmap_22524 trim_no_bitmap 4-3 22524 NULL
121033 +ocfs2_read_extent_block_22550 ocfs2_read_extent_block 0 22550 NULL
121034 +agp_alloc_page_array_22554 agp_alloc_page_array 1 22554 NULL
121035 +dbFindCtl_22587 dbFindCtl 0 22587 NULL
121036 +cfs_expr_list_values_22600 cfs_expr_list_values 0 22600 NULL
121037 +snapshot_read_22601 snapshot_read 3 22601 NULL
121038 +sctp_setsockopt_connectx_old_22631 sctp_setsockopt_connectx_old 3 22631 NULL
121039 +ide_core_cp_entry_22636 ide_core_cp_entry 3 22636 NULL
121040 +wl1271_rx_filter_get_fields_size_22638 wl1271_rx_filter_get_fields_size 0 22638 NULL
121041 +pwr_wake_on_timer_exp_read_22640 pwr_wake_on_timer_exp_read 3 22640 NULL
121042 +iwl_dbgfs_calib_disabled_read_22649 iwl_dbgfs_calib_disabled_read 3 22649 NULL
121043 +compat_SyS_msgrcv_22661 compat_SyS_msgrcv 3 22661 NULL
121044 +l2tp_ip_recvmsg_22681 l2tp_ip_recvmsg 4 22681 NULL
121045 +bch_dump_read_22685 bch_dump_read 3 22685 NULL
121046 +reg_umr_22686 reg_umr 5 22686 NULL
121047 +SYSC_vmsplice_22697 SYSC_vmsplice 3 22697 NULL
121048 +nr_cpusets_22705 nr_cpusets 0 22705 NULL
121049 +alloc_libipw_22708 alloc_libipw 1 22708 NULL
121050 +cx18_copy_buf_to_user_22735 cx18_copy_buf_to_user 4-0 22735 NULL
121051 +ceph_decode_32_22738 ceph_decode_32 0 22738 NULL nohasharray
121052 +__mei_cl_send_22738 __mei_cl_send 3 22738 &ceph_decode_32_22738
121053 +iio_debugfs_write_reg_22742 iio_debugfs_write_reg 3 22742 NULL
121054 +qlcnic_sriov_init_22762 qlcnic_sriov_init 2 22762 NULL
121055 +print_frame_22769 print_frame 0 22769 NULL
121056 +ftrace_arch_read_dyn_info_22773 ftrace_arch_read_dyn_info 0 22773 NULL
121057 +vnic_dev_get_res_count_22791 vnic_dev_get_res_count 0 22791 NULL
121058 +__generic_copy_to_user_intel_22806 __generic_copy_to_user_intel 0-3 22806 NULL
121059 +create_attr_set_22861 create_attr_set 1 22861 NULL
121060 +hash_ip6_expire_22867 hash_ip6_expire 4 22867 NULL
121061 +vmw_execbuf_process_22885 vmw_execbuf_process 5 22885 NULL
121062 +usblp_new_writeurb_22894 usblp_new_writeurb 2 22894 NULL
121063 +mdc800_device_read_22896 mdc800_device_read 3 22896 NULL
121064 +ion_handle_test_kernel_22900 ion_handle_test_kernel 4-3 22900 NULL nohasharray
121065 +policy_emit_config_values_22900 policy_emit_config_values 3 22900 &ion_handle_test_kernel_22900
121066 +nfs4_acl_bytes_22915 nfs4_acl_bytes 0-1 22915 NULL
121067 +__set_xattr_22923 __set_xattr 0 22923 NULL
121068 +xstateregs_set_22932 xstateregs_set 4 22932 NULL
121069 +pcpu_mem_zalloc_22948 pcpu_mem_zalloc 1 22948 NULL
121070 +alloc_sglist_22960 alloc_sglist 2-3 22960 NULL
121071 +caif_seqpkt_sendmsg_22961 caif_seqpkt_sendmsg 4 22961 NULL
121072 +vme_get_size_22964 vme_get_size 0 22964 NULL
121073 +tx_frag_key_not_found_read_22971 tx_frag_key_not_found_read 3 22971 NULL
121074 +cached_dev_cache_miss_22979 cached_dev_cache_miss 4 22979 NULL
121075 +usb_get_langid_22983 usb_get_langid 0 22983 NULL
121076 +remote_settings_file_write_22987 remote_settings_file_write 3 22987 NULL
121077 +viafb_dvp0_proc_write_23023 viafb_dvp0_proc_write 3 23023 NULL
121078 +cifs_local_to_utf16_bytes_23025 cifs_local_to_utf16_bytes 0 23025 NULL
121079 +ocfs2_refcount_cow_xattr_23029 ocfs2_refcount_cow_xattr 6-7 23029 NULL
121080 +st_status_23032 st_status 5 23032 NULL
121081 +nv50_disp_chan_create__23056 nv50_disp_chan_create_ 5 23056 NULL
121082 +comedi_buf_write_n_available_23057 comedi_buf_write_n_available 0 23057 NULL
121083 +reiserfs_add_entry_23062 reiserfs_add_entry 4 23062 NULL nohasharray
121084 +unix_seqpacket_recvmsg_23062 unix_seqpacket_recvmsg 4 23062 &reiserfs_add_entry_23062
121085 +mei_cl_send_23068 mei_cl_send 3 23068 NULL
121086 +kvm_mmu_gva_to_gpa_write_23075 kvm_mmu_gva_to_gpa_write 0 23075 NULL
121087 +raw_sendmsg_23078 raw_sendmsg 4 23078 NULL
121088 +get_user_hdr_len_23079 get_user_hdr_len 0 23079 NULL
121089 +isr_tx_procs_read_23084 isr_tx_procs_read 3 23084 NULL
121090 +rt2x00debug_write_eeprom_23091 rt2x00debug_write_eeprom 3 23091 NULL
121091 +ntfs_ucstonls_23097 ntfs_ucstonls 3-5 23097 NULL
121092 +dgram_recvmsg_23104 dgram_recvmsg 4 23104 NULL
121093 +mwl8k_cmd_set_beacon_23110 mwl8k_cmd_set_beacon 4 23110 NULL
121094 +bset_tree_bytes_23111 bset_tree_bytes 0 23111 NULL nohasharray
121095 +nl80211_send_rx_auth_23111 nl80211_send_rx_auth 4 23111 &bset_tree_bytes_23111
121096 +__clear_user_23118 __clear_user 0-2 23118 NULL
121097 +drm_mode_create_tv_properties_23122 drm_mode_create_tv_properties 2 23122 NULL
121098 +ata_scsi_change_queue_depth_23126 ata_scsi_change_queue_depth 2 23126 NULL
121099 +read_file_ani_23161 read_file_ani 3 23161 NULL
121100 +usblp_write_23178 usblp_write 3 23178 NULL
121101 +gss_pipe_downcall_23182 gss_pipe_downcall 3 23182 NULL
121102 +mpi_alloc_limb_space_23190 mpi_alloc_limb_space 1 23190 NULL
121103 +tipc_sendmcast_23214 tipc_sendmcast 4 23214 NULL
121104 +nft_hash_tbl_alloc_23224 nft_hash_tbl_alloc 1 23224 NULL
121105 +tty_buffer_request_room_23228 tty_buffer_request_room 2-0 23228 NULL
121106 +xlog_get_bp_23229 xlog_get_bp 2 23229 NULL nohasharray
121107 +__read_status_pci_23229 __read_status_pci 0 23229 &xlog_get_bp_23229
121108 +ft1000_read_dpram_mag_32_23232 ft1000_read_dpram_mag_32 0 23232 NULL
121109 +rxrpc_client_sendmsg_23236 rxrpc_client_sendmsg 5 23236 NULL
121110 +__gfn_to_rmap_23240 __gfn_to_rmap 1-2 23240 NULL
121111 +nv50_ram_create__23241 nv50_ram_create_ 4 23241 NULL
121112 +sctp_recvmsg_23265 sctp_recvmsg 4 23265 NULL
121113 +uwb_dev_addr_print_23282 uwb_dev_addr_print 2 23282 NULL
121114 +ec_i2c_count_message_23285 ec_i2c_count_message 0-2 23285 NULL
121115 +diva_get_trace_filter_23286 diva_get_trace_filter 0 23286 NULL
121116 +i2cdev_write_23310 i2cdev_write 3 23310 NULL
121117 +__aa_kvmalloc_23320 __aa_kvmalloc 1 23320 NULL
121118 +page_readlink_23346 page_readlink 3 23346 NULL
121119 +kmem_zalloc_large_23351 kmem_zalloc_large 1 23351 NULL
121120 +get_dst_timing_23358 get_dst_timing 0 23358 NULL
121121 +fd_setup_write_same_buf_23369 fd_setup_write_same_buf 3 23369 NULL
121122 +iscsi_change_queue_depth_23416 iscsi_change_queue_depth 2 23416 NULL
121123 +ocfs2_zero_tail_23447 ocfs2_zero_tail 3 23447 NULL
121124 +hidraw_send_report_23449 hidraw_send_report 3 23449 NULL
121125 +__ata_change_queue_depth_23484 __ata_change_queue_depth 3 23484 NULL
121126 +linear_conf_23485 linear_conf 2 23485 NULL
121127 +event_filter_read_23494 event_filter_read 3 23494 NULL
121128 +lustre_acl_xattr_merge2ext_23502 lustre_acl_xattr_merge2ext 2 23502 NULL
121129 +devm_iio_device_alloc_23511 devm_iio_device_alloc 2 23511 NULL
121130 +__proc_cpt_table_23516 __proc_cpt_table 5 23516 NULL
121131 +hash_ipmark6_expire_23518 hash_ipmark6_expire 4 23518 NULL
121132 +ima_show_measurements_count_23536 ima_show_measurements_count 3 23536 NULL
121133 +tcp_current_mss_23552 tcp_current_mss 0 23552 NULL
121134 +btrfs_super_bytenr_23561 btrfs_super_bytenr 0 23561 NULL
121135 +venus_symlink_23570 venus_symlink 6-4 23570 NULL
121136 +iwl_dbgfs_interrupt_read_23574 iwl_dbgfs_interrupt_read 3 23574 NULL
121137 +xfpregs_get_23586 xfpregs_get 4 23586 NULL
121138 +snd_interval_min_23590 snd_interval_min 0 23590 NULL
121139 +islpci_mgt_transaction_23610 islpci_mgt_transaction 5 23610 NULL
121140 +__i2400mu_send_barker_23652 __i2400mu_send_barker 3 23652 NULL
121141 +sInW_23663 sInW 0 23663 NULL
121142 +SyS_connect_23669 SyS_connect 3 23669 NULL
121143 +cx18_read_23699 cx18_read 3 23699 NULL
121144 +at_get_23708 at_get 0 23708 NULL
121145 +get_conn_info_23723 get_conn_info 4 23723 NULL
121146 +rx_rx_dropped_frame_read_23748 rx_rx_dropped_frame_read 3 23748 NULL
121147 +__kfifo_max_r_23768 __kfifo_max_r 0-2-1 23768 NULL
121148 +__build_packet_message_23778 __build_packet_message 4-10 23778 NULL
121149 +security_inode_getxattr_23781 security_inode_getxattr 0 23781 NULL
121150 +cfg80211_inform_bss_width_frame_23782 cfg80211_inform_bss_width_frame 5 23782 NULL
121151 +mpt_free_res_23793 mpt_free_res 5 23793 NULL
121152 +map_write_23795 map_write 3 23795 NULL
121153 +rx_path_reset_read_23801 rx_path_reset_read 3 23801 NULL
121154 +__earlyonly_bootmem_alloc_23824 __earlyonly_bootmem_alloc 2 23824 NULL
121155 +lustre_msg_buflen_23827 lustre_msg_buflen 0 23827 NULL
121156 +pgdat_end_pfn_23842 pgdat_end_pfn 0 23842 NULL
121157 +iwl_dbgfs_nvm_read_23845 iwl_dbgfs_nvm_read 3 23845 NULL
121158 +p54_init_common_23850 p54_init_common 1 23850 NULL
121159 +bin_to_hex_dup_23853 bin_to_hex_dup 2 23853 NULL
121160 +ocfs2_xattr_get_clusters_23857 ocfs2_xattr_get_clusters 0 23857 NULL
121161 +ieee80211_if_read_dot11MeshMaxPeerLinks_23878 ieee80211_if_read_dot11MeshMaxPeerLinks 3 23878 NULL
121162 +tipc_snprintf_23893 tipc_snprintf 2-0 23893 NULL
121163 +iov_iter_get_pages_alloc_23903 iov_iter_get_pages_alloc 3-0 23903 NULL
121164 +add_new_gdb_meta_bg_23911 add_new_gdb_meta_bg 3 23911 NULL nohasharray
121165 +ieee80211_if_read_hw_queues_23911 ieee80211_if_read_hw_queues 3 23911 &add_new_gdb_meta_bg_23911
121166 +f2fs_getxattr_23917 f2fs_getxattr 0 23917 NULL
121167 +ipath_reg_phys_mr_23918 ipath_reg_phys_mr 3 23918 NULL nohasharray
121168 +mpihelp_mul_karatsuba_case_23918 mpihelp_mul_karatsuba_case 5-3 23918 &ipath_reg_phys_mr_23918
121169 +kvm_read_guest_23928 kvm_read_guest 4-2 23928 NULL
121170 +uvc_endpoint_max_bpi_23944 uvc_endpoint_max_bpi 0 23944 NULL
121171 +cifs_setxattr_23957 cifs_setxattr 4 23957 NULL
121172 +size_roundup_power2_23958 size_roundup_power2 0-1 23958 NULL
121173 +sddr55_write_data_23983 sddr55_write_data 4 23983 NULL
121174 +zd_usb_iowrite16v_async_23984 zd_usb_iowrite16v_async 3 23984 NULL
121175 +cxgb_alloc_mem_24007 cxgb_alloc_mem 1 24007 NULL
121176 +give_pages_24021 give_pages 3 24021 NULL
121177 +adis16400_show_serial_number_24037 adis16400_show_serial_number 3 24037 NULL
121178 +hmac_setkey_24043 hmac_setkey 3 24043 NULL
121179 +afs_cell_alloc_24052 afs_cell_alloc 2 24052 NULL
121180 +iwl_dbgfs_low_latency_read_24062 iwl_dbgfs_low_latency_read 3 24062 NULL
121181 +vb2_fop_read_24080 vb2_fop_read 3 24080 NULL
121182 +C_SYSC_process_vm_writev_24102 C_SYSC_process_vm_writev 3-5 24102 NULL
121183 +pipeline_post_proc_swi_read_24108 pipeline_post_proc_swi_read 3 24108 NULL
121184 +request_key_auth_read_24109 request_key_auth_read 3 24109 NULL
121185 +lov_brw_24122 lov_brw 4 24122 NULL
121186 +mpu401_read_24126 mpu401_read 3 24126 NULL
121187 +_picolcd_flash_write_24134 _picolcd_flash_write 4 24134 NULL
121188 +irnet_ctrl_write_24139 irnet_ctrl_write 3 24139 NULL
121189 +SyS_sethostname_24150 SyS_sethostname 2 24150 NULL
121190 +trim_bitmaps_24158 trim_bitmaps 3 24158 NULL
121191 +adu_read_24177 adu_read 3 24177 NULL
121192 +safe_prepare_write_buffer_24187 safe_prepare_write_buffer 3 24187 NULL
121193 +nv94_aux_24197 nv94_aux 3-6 24197 NULL
121194 +ieee80211_if_read_dot11MeshHWMPpreqMinInterval_24208 ieee80211_if_read_dot11MeshHWMPpreqMinInterval 3 24208 NULL
121195 +tcpprobe_sprint_24222 tcpprobe_sprint 0-2 24222 NULL
121196 +pcpu_embed_first_chunk_24224 pcpu_embed_first_chunk 3-2-1 24224 NULL nohasharray
121197 +mei_amthif_read_24224 mei_amthif_read 4 24224 &pcpu_embed_first_chunk_24224
121198 +pci_num_vf_24235 pci_num_vf 0 24235 NULL
121199 +sel_read_bool_24236 sel_read_bool 3 24236 NULL
121200 +em28xx_alloc_urbs_24260 em28xx_alloc_urbs 4-6 24260 NULL
121201 +calculate_sizes_24273 calculate_sizes 2 24273 NULL
121202 +thin_status_24278 thin_status 5 24278 NULL
121203 +msg_size_24288 msg_size 0 24288 NULL
121204 +btmrvl_pscmd_read_24308 btmrvl_pscmd_read 3 24308 NULL
121205 +ath6kl_add_bss_if_needed_24317 ath6kl_add_bss_if_needed 6 24317 NULL
121206 +si476x_radio_read_acf_blob_24336 si476x_radio_read_acf_blob 3 24336 NULL
121207 +C_SYSC_pwritev_24345 C_SYSC_pwritev 3 24345 NULL
121208 +kzalloc_node_24352 kzalloc_node 1 24352 NULL
121209 +qla2x00_handle_queue_full_24365 qla2x00_handle_queue_full 2 24365 NULL
121210 +cfi_read_pri_24366 cfi_read_pri 3 24366 NULL
121211 +btrfs_item_size_nr_24367 btrfs_item_size_nr 0 24367 NULL
121212 +igetword_24373 igetword 0 24373 NULL
121213 +mpt_alloc_res_24387 mpt_alloc_res 5 24387 NULL
121214 +osc_cur_grant_bytes_seq_write_24396 osc_cur_grant_bytes_seq_write 3 24396 NULL
121215 +getxattr_24398 getxattr 4 24398 NULL nohasharray
121216 +pvr2_v4l2_ioctl_24398 pvr2_v4l2_ioctl 2 24398 &getxattr_24398
121217 +blk_update_bidi_request_24415 blk_update_bidi_request 3-4 24415 NULL
121218 +nvme_trans_log_supp_pages_24418 nvme_trans_log_supp_pages 3 24418 NULL
121219 +b43_debugfs_read_24425 b43_debugfs_read 3 24425 NULL
121220 +xenbus_file_read_24427 xenbus_file_read 3 24427 NULL
121221 +ieee80211_rx_mgmt_beacon_24430 ieee80211_rx_mgmt_beacon 3 24430 NULL
121222 +copy_and_ioctl_24434 copy_and_ioctl 4 24434 NULL
121223 +ixgbe_alloc_q_vector_24439 ixgbe_alloc_q_vector 4-6 24439 NULL
121224 +smk_user_access_24440 smk_user_access 3 24440 NULL nohasharray
121225 +rtw_set_wps_assoc_resp_24440 rtw_set_wps_assoc_resp 3 24440 &smk_user_access_24440
121226 +evdev_do_ioctl_24459 evdev_do_ioctl 2 24459 NULL
121227 +lbs_highsnr_write_24460 lbs_highsnr_write 3 24460 NULL
121228 +skb_copy_and_csum_datagram_iovec_24466 skb_copy_and_csum_datagram_iovec 2 24466 NULL
121229 +dut_mode_read_24489 dut_mode_read 3 24489 NULL
121230 +read_file_spec_scan_ctl_24491 read_file_spec_scan_ctl 3 24491 NULL
121231 +pd_video_read_24510 pd_video_read 3 24510 NULL
121232 +request_key_with_auxdata_24515 request_key_with_auxdata 4 24515 NULL
121233 +xfs_buf_get_map_24522 xfs_buf_get_map 3 24522 NULL
121234 +do_mpage_readpage_24536 do_mpage_readpage 3 24536 NULL
121235 +write_cache_pages_24562 write_cache_pages 0 24562 NULL
121236 +SyS_pselect6_24582 SyS_pselect6 1 24582 NULL
121237 +udf_compute_nr_groups_24594 udf_compute_nr_groups 0 24594 NULL
121238 +sensor_hub_get_physical_device_count_24605 sensor_hub_get_physical_device_count 0 24605 NULL nohasharray
121239 +lov_alloc_memmd_24605 lov_alloc_memmd 2 24605 &sensor_hub_get_physical_device_count_24605
121240 +SyS_poll_24620 SyS_poll 2 24620 NULL
121241 +context_alloc_24645 context_alloc 3 24645 NULL
121242 +blk_rq_err_bytes_24650 blk_rq_err_bytes 0 24650 NULL
121243 +datafab_write_data_24696 datafab_write_data 4 24696 NULL
121244 +intelfbhw_get_p1p2_24703 intelfbhw_get_p1p2 2 24703 NULL
121245 +simple_attr_read_24738 simple_attr_read 3 24738 NULL
121246 +qla2x00_change_queue_depth_24742 qla2x00_change_queue_depth 2 24742 NULL
121247 +get_dma_residue_24749 get_dma_residue 0 24749 NULL
121248 +ocfs2_cow_file_pos_24751 ocfs2_cow_file_pos 3 24751 NULL
121249 +kgdb_hex2mem_24755 kgdb_hex2mem 3 24755 NULL
121250 +ocfs2_read_blocks_24777 ocfs2_read_blocks 0 24777 NULL
121251 +datablob_hmac_verify_24786 datablob_hmac_verify 4 24786 NULL
121252 +cache_read_24790 cache_read 3 24790 NULL
121253 +user_regset_copyout_24796 user_regset_copyout 7 24796 NULL
121254 +kvm_read_guest_virt_helper_24804 kvm_read_guest_virt_helper 3-1 24804 NULL
121255 +ath6kl_fwlog_mask_write_24810 ath6kl_fwlog_mask_write 3 24810 NULL
121256 +snd_als4k_gcr_read_24840 snd_als4k_gcr_read 0 24840 NULL
121257 +snd_pcm_lib_buffer_bytes_24865 snd_pcm_lib_buffer_bytes 0 24865 NULL
121258 +pnp_alloc_24869 pnp_alloc 1 24869 NULL nohasharray
121259 +l2cap_create_basic_pdu_24869 l2cap_create_basic_pdu 3 24869 &pnp_alloc_24869
121260 +queues_read_24877 queues_read 3 24877 NULL
121261 +iov_iter_npages_bvec_24905 iov_iter_npages_bvec 0-2 24905 NULL
121262 +codec_list_read_file_24910 codec_list_read_file 3 24910 NULL
121263 +xpcs_reg_value_write_24922 xpcs_reg_value_write 3 24922 NULL
121264 +v4l2_ctrl_new_24927 v4l2_ctrl_new 7 24927 NULL
121265 +ocfs2_fiemap_24949 ocfs2_fiemap 4-3 24949 NULL
121266 +packet_sendmsg_24954 packet_sendmsg 4 24954 NULL
121267 +twl_i2c_write_u8_24976 twl_i2c_write_u8 3 24976 NULL
121268 +llc_ui_sendmsg_24987 llc_ui_sendmsg 4 24987 NULL
121269 +info_debugfs_read_helper_24988 info_debugfs_read_helper 0 24988 NULL
121270 +key_conf_hw_key_idx_read_25003 key_conf_hw_key_idx_read 3 25003 NULL
121271 +il_dbgfs_channels_read_25005 il_dbgfs_channels_read 3 25005 NULL
121272 +ni_660x_num_counters_25031 ni_660x_num_counters 0 25031 NULL
121273 +nfs_dns_resolve_name_25036 nfs_dns_resolve_name 3 25036 NULL
121274 +load_unaligned_zeropad_25050 load_unaligned_zeropad 0 25050 NULL
121275 +btrfs_stack_key_blockptr_25058 btrfs_stack_key_blockptr 0 25058 NULL
121276 +gs_buf_alloc_25067 gs_buf_alloc 2 25067 NULL
121277 +ll_track_pid_seq_write_25068 ll_track_pid_seq_write 3 25068 NULL
121278 +SYSC_listxattr_25072 SYSC_listxattr 3 25072 NULL
121279 +ima_appraise_measurement_25093 ima_appraise_measurement 6 25093 NULL
121280 +snd_rawmidi_kernel_write_25106 snd_rawmidi_kernel_write 3 25106 NULL
121281 +ipath_init_qp_table_25167 ipath_init_qp_table 2 25167 NULL
121282 +kvm_mmu_notifier_change_pte_25169 kvm_mmu_notifier_change_pte 3 25169 NULL
121283 +sctp_getsockopt_local_addrs_25178 sctp_getsockopt_local_addrs 2 25178 NULL
121284 +security_socket_post_create_25221 security_socket_post_create 0 25221 NULL
121285 +mon_stat_read_25238 mon_stat_read 3 25238 NULL
121286 +stripe_status_25259 stripe_status 5 25259 NULL
121287 +snd_pcm_start_25273 snd_pcm_start 0 25273 NULL
121288 +crypto_alloc_instance2_25277 crypto_alloc_instance2 3 25277 NULL
121289 +vfs_writev_25278 vfs_writev 3 25278 NULL
121290 +l2tp_session_create_25286 l2tp_session_create 1 25286 NULL
121291 +ath9k_debugfs_read_buf_25316 ath9k_debugfs_read_buf 3 25316 NULL
121292 +rng_buffer_size_25348 rng_buffer_size 0 25348 NULL
121293 +SYSC_kexec_load_25361 SYSC_kexec_load 2 25361 NULL
121294 +unix_mkname_25368 unix_mkname 0-2 25368 NULL
121295 +sel_read_mls_25369 sel_read_mls 3 25369 NULL
121296 +vsp1_entity_init_25407 vsp1_entity_init 3 25407 NULL
121297 +mcp795_rtcc_read_25415 mcp795_rtcc_read 4 25415 NULL
121298 +dai_list_read_file_25421 dai_list_read_file 3 25421 NULL
121299 +ipath_decode_err_25468 ipath_decode_err 3 25468 NULL
121300 +crypto_hash_digestsize_25469 crypto_hash_digestsize 0 25469 NULL
121301 +ivtv_buf_copy_from_user_25502 ivtv_buf_copy_from_user 4-0 25502 NULL
121302 +snd_pcm_plugin_build_25505 snd_pcm_plugin_build 5 25505 NULL
121303 +mxt_obj_size_25510 mxt_obj_size 0 25510 NULL
121304 +sb_permission_25523 sb_permission 0 25523 NULL
121305 +ext3_get_inode_loc_25542 ext3_get_inode_loc 0 25542 NULL
121306 +ieee80211_if_read_path_refresh_time_25545 ieee80211_if_read_path_refresh_time 3 25545 NULL
121307 +wimax_addr_scnprint_25548 wimax_addr_scnprint 2 25548 NULL
121308 +ht_print_chan_25556 ht_print_chan 0-3-4 25556 NULL
121309 +skb_tailroom_25567 skb_tailroom 0 25567 NULL
121310 +ping_recvmsg_25597 ping_recvmsg 4 25597 NULL
121311 +copy_user_generic_25611 copy_user_generic 0 25611 NULL
121312 +proc_coredump_filter_write_25625 proc_coredump_filter_write 3 25625 NULL
121313 +befs_utf2nls_25628 befs_utf2nls 3 25628 NULL nohasharray
121314 +__get_user_pages_25628 __get_user_pages 0 25628 &befs_utf2nls_25628
121315 +__direct_map_25647 __direct_map 6-5 25647 NULL
121316 +aircable_prepare_write_buffer_25669 aircable_prepare_write_buffer 3 25669 NULL
121317 +lpfc_idiag_cmd_get_25672 lpfc_idiag_cmd_get 2 25672 NULL
121318 +sta_inactive_ms_read_25690 sta_inactive_ms_read 3 25690 NULL
121319 +prom_early_alloc_25692 prom_early_alloc 1 25692 NULL
121320 +rx_filter_mc_filter_read_25712 rx_filter_mc_filter_read 3 25712 NULL
121321 +ibmasm_new_command_25714 ibmasm_new_command 2 25714 NULL
121322 +__alloc_bootmem_low_node_25726 __alloc_bootmem_low_node 2 25726 NULL nohasharray
121323 +sel_write_context_25726 sel_write_context 3 25726 &__alloc_bootmem_low_node_25726
121324 +xgbe_common_read_25743 xgbe_common_read 2 25743 NULL
121325 +cxgbi_device_portmap_create_25747 cxgbi_device_portmap_create 3 25747 NULL
121326 +event_rx_pool_read_25792 event_rx_pool_read 3 25792 NULL
121327 +sg_read_25799 sg_read 3 25799 NULL
121328 +system_enable_read_25815 system_enable_read 3 25815 NULL
121329 +realloc_buffer_25816 realloc_buffer 2 25816 NULL
121330 +pwr_missing_bcns_read_25824 pwr_missing_bcns_read 3 25824 NULL
121331 +parport_read_25855 parport_read 0 25855 NULL
121332 +xfs_dir2_sf_hdr_size_25858 xfs_dir2_sf_hdr_size 0 25858 NULL
121333 +key_attr_size_25865 key_attr_size 0 25865 NULL
121334 +ath6kl_regread_read_25884 ath6kl_regread_read 3 25884 NULL
121335 +run_delalloc_nocow_25896 run_delalloc_nocow 3-4 25896 NULL
121336 +sisusbcon_scroll_area_25899 sisusbcon_scroll_area 4-3 25899 NULL
121337 +lpfc_change_queue_depth_25905 lpfc_change_queue_depth 2 25905 NULL
121338 +nvme_trans_mode_page_create_25908 nvme_trans_mode_page_create 7-4 25908 NULL
121339 +do_jffs2_setxattr_25910 do_jffs2_setxattr 5 25910 NULL
121340 +rcname_read_25919 rcname_read 3 25919 NULL
121341 +snd_es1938_capture_copy_25930 snd_es1938_capture_copy 5 25930 NULL
121342 +key_flags_read_25931 key_flags_read 3 25931 NULL
121343 +copy_play_buf_25932 copy_play_buf 3 25932 NULL
121344 +flush_25957 flush 2 25957 NULL
121345 +_regmap_multi_reg_write_25967 _regmap_multi_reg_write 3 25967 NULL
121346 +udp_setsockopt_25985 udp_setsockopt 5 25985 NULL
121347 +lustre_msg_buflen_v2_25997 lustre_msg_buflen_v2 0 25997 NULL
121348 +SyS_process_vm_readv_26019 SyS_process_vm_readv 3-5 26019 NULL
121349 +mptscsih_change_queue_depth_26036 mptscsih_change_queue_depth 2 26036 NULL
121350 +selinux_inode_post_setxattr_26037 selinux_inode_post_setxattr 4 26037 NULL
121351 +keyctl_update_key_26061 keyctl_update_key 3 26061 NULL
121352 +pri_wm_latency_write_26063 pri_wm_latency_write 3 26063 NULL
121353 +rx_rx_wa_density_dropped_frame_read_26095 rx_rx_wa_density_dropped_frame_read 3 26095 NULL
121354 +i8042_pnp_id_to_string_26108 i8042_pnp_id_to_string 3 26108 NULL
121355 +read_sb_page_26119 read_sb_page 5 26119 NULL
121356 +ath9k_hw_name_26146 ath9k_hw_name 3 26146 NULL
121357 +copy_oldmem_page_26164 copy_oldmem_page 3 26164 NULL
121358 +gfs2_xattr_acl_get_26166 gfs2_xattr_acl_get 0 26166 NULL nohasharray
121359 +ath6kl_roam_table_read_26166 ath6kl_roam_table_read 3 26166 &gfs2_xattr_acl_get_26166
121360 +disk_devt_26180 disk_devt 0 26180 NULL
121361 +ieee80211_if_fmt_dot11MeshTTL_26198 ieee80211_if_fmt_dot11MeshTTL 3 26198 NULL
121362 +xfs_idata_realloc_26199 xfs_idata_realloc 2 26199 NULL
121363 +mce_write_26201 mce_write 3 26201 NULL
121364 +mwifiex_regrdwr_write_26225 mwifiex_regrdwr_write 3 26225 NULL
121365 +_scsih_change_queue_depth_26230 _scsih_change_queue_depth 2 26230 NULL
121366 +rxrpc_recvmsg_26233 rxrpc_recvmsg 4 26233 NULL
121367 +genwqe_ffdc_buff_size_26263 genwqe_ffdc_buff_size 0 26263 NULL
121368 +crypto_ctxsize_26278 crypto_ctxsize 0 26278 NULL
121369 +wacom_set_device_mode_26280 wacom_set_device_mode 3 26280 NULL
121370 +snd_pcm_plug_client_channels_buf_26309 snd_pcm_plug_client_channels_buf 0-3 26309 NULL
121371 +pwr_wake_on_host_read_26321 pwr_wake_on_host_read 3 26321 NULL
121372 +check_can_nocow_26336 check_can_nocow 2 26336 NULL
121373 +snd_vx_check_reg_bit_26344 snd_vx_check_reg_bit 0 26344 NULL
121374 +ocfs2_duplicate_clusters_by_page_26357 ocfs2_duplicate_clusters_by_page 6-3 26357 NULL
121375 +cifs_readdata_alloc_26360 cifs_readdata_alloc 1 26360 NULL
121376 +invalidate_inode_pages2_range_26403 invalidate_inode_pages2_range 0 26403 NULL
121377 +ntty_write_26404 ntty_write 3 26404 NULL
121378 +firmware_store_26408 firmware_store 4 26408 NULL
121379 +pagemap_read_26441 pagemap_read 3 26441 NULL
121380 +tower_read_26461 tower_read 3 26461 NULL nohasharray
121381 +enc_pools_add_pages_26461 enc_pools_add_pages 1 26461 &tower_read_26461
121382 +ib_alloc_device_26483 ib_alloc_device 1 26483 NULL
121383 +ulong_write_file_26485 ulong_write_file 3 26485 NULL
121384 +dvb_ca_en50221_io_ioctl_26490 dvb_ca_en50221_io_ioctl 2 26490 NULL
121385 +read_vmcore_26501 read_vmcore 3 26501 NULL
121386 +uhid_char_write_26502 uhid_char_write 3 26502 NULL
121387 +vfio_pci_set_msi_trigger_26507 vfio_pci_set_msi_trigger 4-3 26507 NULL
121388 +iwl_dbgfs_rf_reset_read_26512 iwl_dbgfs_rf_reset_read 3 26512 NULL
121389 +alloc_ep_req_26521 alloc_ep_req 3-2 26521 NULL
121390 +SyS_rt_sigpending_26538 SyS_rt_sigpending 2 26538 NULL
121391 +__vhost_add_used_n_26554 __vhost_add_used_n 3 26554 NULL
121392 +dio_new_bio_26562 dio_new_bio 0 26562 NULL
121393 +rts51x_read_mem_26577 rts51x_read_mem 4 26577 NULL
121394 +kernfs_name_locked_26617 kernfs_name_locked 3 26617 NULL
121395 +pwr_fix_tsf_ps_read_26627 pwr_fix_tsf_ps_read 3 26627 NULL
121396 +amdtp_stream_get_max_payload_26645 amdtp_stream_get_max_payload 0 26645 NULL
121397 +irq_alloc_generic_chip_26650 irq_alloc_generic_chip 2 26650 NULL
121398 +nouveau_volt_create__26654 nouveau_volt_create_ 4 26654 NULL
121399 +cipso_v4_map_cat_rbm_hton_26680 cipso_v4_map_cat_rbm_hton 0 26680 NULL
121400 +flowinfo_read_26683 flowinfo_read 3 26683 NULL
121401 +sysfs_add_file_26716 sysfs_add_file 0 26716 NULL
121402 +nouveau_namedb_create__26732 nouveau_namedb_create_ 7 26732 NULL
121403 +pipeline_tcp_rx_stat_fifo_int_read_26745 pipeline_tcp_rx_stat_fifo_int_read 3 26745 NULL
121404 +bos_desc_26752 bos_desc 0 26752 NULL
121405 +snd_hda_get_raw_connections_26762 snd_hda_get_raw_connections 0 26762 NULL
121406 +dma_map_single_attrs_26779 dma_map_single_attrs 0 26779 NULL
121407 +qlcnic_alloc_sds_rings_26795 qlcnic_alloc_sds_rings 2 26795 NULL
121408 +cipso_v4_genopt_26812 cipso_v4_genopt 0 26812 NULL
121409 +iwl_trans_read_mem32_26825 iwl_trans_read_mem32 0 26825 NULL
121410 +smk_write_load_26829 smk_write_load 3 26829 NULL
121411 +scnprint_id_26842 scnprint_id 3-0 26842 NULL
121412 +ecryptfs_miscdev_write_26847 ecryptfs_miscdev_write 3 26847 NULL
121413 +ss_alloc_ep_req_26848 ss_alloc_ep_req 2 26848 NULL
121414 +tipc_conn_sendmsg_26867 tipc_conn_sendmsg 5 26867 NULL
121415 +ath6kl_create_qos_write_26879 ath6kl_create_qos_write 3 26879 NULL
121416 +svc_print_xprts_26881 svc_print_xprts 0 26881 NULL
121417 +skb_zerocopy_headlen_26910 skb_zerocopy_headlen 0 26910 NULL
121418 +hhf_zalloc_26912 hhf_zalloc 1 26912 NULL
121419 +cfg80211_process_auth_26916 cfg80211_process_auth 3 26916 NULL
121420 +x25_asy_change_mtu_26928 x25_asy_change_mtu 2 26928 NULL
121421 +brcmf_usb_dl_cmd_26931 brcmf_usb_dl_cmd 4 26931 NULL
121422 +scsi_tgt_copy_sense_26933 scsi_tgt_copy_sense 3 26933 NULL
121423 +sctp_setsockopt_adaptation_layer_26935 sctp_setsockopt_adaptation_layer 3 26935 NULL nohasharray
121424 +pwr_ps_enter_read_26935 pwr_ps_enter_read 3 26935 &sctp_setsockopt_adaptation_layer_26935
121425 +hecubafb_write_26942 hecubafb_write 3 26942 NULL
121426 +do_trimming_26952 do_trimming 3 26952 NULL nohasharray
121427 +extract_entropy_user_26952 extract_entropy_user 3 26952 &do_trimming_26952
121428 +do_direct_IO_26979 do_direct_IO 0 26979 NULL
121429 +lustre_msg_size_26995 lustre_msg_size 2 26995 NULL
121430 +sc16is7xx_port_read_27051 sc16is7xx_port_read 0 27051 NULL
121431 +__videobuf_alloc_vb_27062 __videobuf_alloc_vb 1 27062 NULL
121432 +ext4_convert_unwritten_extents_27064 ext4_convert_unwritten_extents 4-3 27064 NULL
121433 +snd_pcm_lib_period_bytes_27071 snd_pcm_lib_period_bytes 0 27071 NULL
121434 +paravirt_read_msr_27077 paravirt_read_msr 0 27077 NULL
121435 +alloc_fdmem_27083 alloc_fdmem 1 27083 NULL
121436 +btmrvl_hscmd_write_27089 btmrvl_hscmd_write 3 27089 NULL nohasharray
121437 +ath9k_hw_4k_dump_eeprom_27089 ath9k_hw_4k_dump_eeprom 5-4 27089 &btmrvl_hscmd_write_27089
121438 +__devcgroup_inode_permission_27108 __devcgroup_inode_permission 0 27108 NULL
121439 +drbd_get_capacity_27141 drbd_get_capacity 0 27141 NULL
121440 +pms_capture_27142 pms_capture 4 27142 NULL
121441 +btmrvl_hscfgcmd_write_27143 btmrvl_hscfgcmd_write 3 27143 NULL
121442 +wil_write_file_wmi_27150 wil_write_file_wmi 3 27150 NULL
121443 +snd_compr_calc_avail_27165 snd_compr_calc_avail 0 27165 NULL
121444 +ieee80211_if_read_rc_rateidx_mask_5ghz_27183 ieee80211_if_read_rc_rateidx_mask_5ghz 3 27183 NULL
121445 +write_kmem_27225 write_kmem 3 27225 NULL nohasharray
121446 +svcxdr_tmpalloc_27225 svcxdr_tmpalloc 2 27225 &write_kmem_27225
121447 +dbAllocAG_27228 dbAllocAG 0 27228 NULL
121448 +rxrpc_request_key_27235 rxrpc_request_key 3 27235 NULL
121449 +ll_track_gid_seq_write_27267 ll_track_gid_seq_write 3 27267 NULL
121450 +comedi_alloc_devpriv_27272 comedi_alloc_devpriv 2 27272 NULL
121451 +get_rx_fifo_content_27283 get_rx_fifo_content 0 27283 NULL
121452 +copy_from_buf_27308 copy_from_buf 4-2 27308 NULL
121453 +virtqueue_add_inbuf_27312 virtqueue_add_inbuf 3 27312 NULL
121454 +snd_pcm_oss_write2_27332 snd_pcm_oss_write2 3-0 27332 NULL
121455 +afs_cell_create_27346 afs_cell_create 2 27346 NULL
121456 +iwl_dbgfs_csr_write_27363 iwl_dbgfs_csr_write 3 27363 NULL
121457 +pcbit_stat_27364 pcbit_stat 2 27364 NULL
121458 +seq_read_27411 seq_read 3 27411 NULL
121459 +ib_dma_map_sg_27413 ib_dma_map_sg 0 27413 NULL
121460 +ieee80211_if_read_smps_27416 ieee80211_if_read_smps 3 27416 NULL
121461 +ocfs2_refcount_cal_cow_clusters_27422 ocfs2_refcount_cal_cow_clusters 3-4 27422 NULL
121462 +cypress_write_27423 cypress_write 4 27423 NULL
121463 +sddr09_read_data_27447 sddr09_read_data 3 27447 NULL
121464 +v4l2_ctrl_new_std_menu_items_27487 v4l2_ctrl_new_std_menu_items 4 27487 NULL
121465 +hcd_buffer_alloc_27495 hcd_buffer_alloc 2 27495 NULL
121466 +ip_set_get_h32_27498 ip_set_get_h32 0 27498 NULL
121467 +btrfs_get_64_27499 btrfs_get_64 0 27499 NULL
121468 +garmin_read_process_27509 garmin_read_process 3 27509 NULL
121469 +oti_alloc_cookies_27510 oti_alloc_cookies 2 27510 NULL
121470 +ib_copy_to_udata_27525 ib_copy_to_udata 3 27525 NULL
121471 +snd_sonicvibes_getdmaa_27552 snd_sonicvibes_getdmaa 0 27552 NULL
121472 +SyS_fgetxattr_27571 SyS_fgetxattr 4 27571 NULL
121473 +sco_sock_recvmsg_27572 sco_sock_recvmsg 4 27572 NULL
121474 +libipw_alloc_txb_27579 libipw_alloc_txb 1 27579 NULL
121475 +C_SYSC_mbind_27636 C_SYSC_mbind 5 27636 NULL
121476 +ocfs2_xattr_ibody_get_27642 ocfs2_xattr_ibody_get 0 27642 NULL nohasharray
121477 +read_flush_procfs_27642 read_flush_procfs 3 27642 &ocfs2_xattr_ibody_get_27642 nohasharray
121478 +nl80211_send_connect_result_27642 nl80211_send_connect_result 5-7 27642 &read_flush_procfs_27642
121479 +add_new_gdb_27643 add_new_gdb 3 27643 NULL
121480 +btrfs_fallocate_27647 btrfs_fallocate 3-4 27647 NULL
121481 +qnx6_readpages_27657 qnx6_readpages 4 27657 NULL
121482 +cdrom_read_cdda_old_27664 cdrom_read_cdda_old 4 27664 NULL
121483 +ocfs2_extend_dir_27695 ocfs2_extend_dir 4 27695 NULL
121484 +fs_path_add_from_extent_buffer_27702 fs_path_add_from_extent_buffer 4 27702 NULL
121485 +evm_write_key_27715 evm_write_key 3 27715 NULL
121486 +ieee80211_if_fmt_dot11MeshGateAnnouncementProtocol_27722 ieee80211_if_fmt_dot11MeshGateAnnouncementProtocol 3 27722 NULL
121487 +xfs_dir2_block_sfsize_27727 xfs_dir2_block_sfsize 0 27727 NULL
121488 +load_scode_27738 load_scode 2 27738 NULL
121489 +SyS_setsockopt_27759 SyS_setsockopt 5 27759 NULL
121490 +transport_init_session_tags_27776 transport_init_session_tags 1-2 27776 NULL
121491 +__lov_setstripe_27782 __lov_setstripe 2 27782 NULL
121492 +twl4030_set_gpio_dataout_27792 twl4030_set_gpio_dataout 1 27792 NULL
121493 +SyS_readv_27804 SyS_readv 3 27804 NULL
121494 +mpihelp_mul_27805 mpihelp_mul 5-3 27805 NULL
121495 +hpt374_read_freq_27828 hpt374_read_freq 0 27828 NULL
121496 +init_header_complete_27833 init_header_complete 0 27833 NULL
121497 +read_profile_27859 read_profile 3 27859 NULL
121498 +sky2_pci_read16_27863 sky2_pci_read16 0 27863 NULL
121499 +ieee80211_if_read_dot11MeshHWMProotInterval_27873 ieee80211_if_read_dot11MeshHWMProotInterval 3 27873 NULL
121500 +unix_seqpacket_sendmsg_27893 unix_seqpacket_sendmsg 4 27893 NULL
121501 +i915_error_object_create_sized_27919 i915_error_object_create_sized 4 27919 NULL
121502 +check_mapped_name_27943 check_mapped_name 3 27943 NULL
121503 +bio_next_split_27961 bio_next_split 2 27961 NULL nohasharray
121504 +tracing_clock_write_27961 tracing_clock_write 3 27961 &bio_next_split_27961
121505 +tipc_media_addr_printf_27971 tipc_media_addr_printf 2 27971 NULL
121506 +mic_rx_pkts_read_27972 mic_rx_pkts_read 3 27972 NULL nohasharray
121507 +device_register_27972 device_register 0 27972 &mic_rx_pkts_read_27972
121508 +compat_SyS_set_mempolicy_27975 compat_SyS_set_mempolicy 3 27975 NULL
121509 +pci_enable_device_flags_27977 pci_enable_device_flags 0 27977 NULL
121510 +edt_ft5x06_debugfs_raw_data_read_28002 edt_ft5x06_debugfs_raw_data_read 3 28002 NULL
121511 +seq_get_buf_28006 seq_get_buf 0 28006 NULL
121512 +snd_rawmidi_write_28008 snd_rawmidi_write 3 28008 NULL
121513 +powercap_register_zone_28028 powercap_register_zone 6 28028 NULL
121514 +sctp_setsockopt_maxburst_28041 sctp_setsockopt_maxburst 3 28041 NULL
121515 +cx231xx_init_vbi_isoc_28053 cx231xx_init_vbi_isoc 3-2-4 28053 NULL
121516 +pool_status_28055 pool_status 5 28055 NULL
121517 +init_rs_non_canonical_28059 init_rs_non_canonical 1 28059 NULL
121518 +lpfc_idiag_mbxacc_read_28061 lpfc_idiag_mbxacc_read 3 28061 NULL
121519 +tx_frag_bad_mblk_num_read_28064 tx_frag_bad_mblk_num_read 3 28064 NULL
121520 +acpi_gsb_i2c_write_bytes_28082 acpi_gsb_i2c_write_bytes 4 28082 NULL
121521 +mmc_test_alloc_mem_28102 mmc_test_alloc_mem 3-2 28102 NULL
121522 +rx_defrag_need_defrag_read_28117 rx_defrag_need_defrag_read 3 28117 NULL
121523 +vgacon_adjust_height_28124 vgacon_adjust_height 2 28124 NULL
121524 +m25p80_read_reg_28132 m25p80_read_reg 4 28132 NULL
121525 +video_read_28148 video_read 3 28148 NULL
121526 +snd_midi_channel_alloc_set_28153 snd_midi_channel_alloc_set 1 28153 NULL
121527 +stats_dot11FCSErrorCount_read_28154 stats_dot11FCSErrorCount_read 3 28154 NULL
121528 +vread_28173 vread 0-3 28173 NULL
121529 +macvtap_get_user_28185 macvtap_get_user 4 28185 NULL
121530 +counter_free_res_28187 counter_free_res 5 28187 NULL
121531 +read_disk_sb_28188 read_disk_sb 2 28188 NULL
121532 +nvkm_output_dp_create__28192 nvkm_output_dp_create_ 6 28192 NULL
121533 +nouveau_mxm_create__28200 nouveau_mxm_create_ 4 28200 NULL
121534 +__qp_memcpy_from_queue_28220 __qp_memcpy_from_queue 3-4 28220 NULL
121535 +line6_alloc_sysex_buffer_28225 line6_alloc_sysex_buffer 4 28225 NULL
121536 +amd_nb_num_28228 amd_nb_num 0 28228 NULL
121537 +usemap_size_28281 usemap_size 0 28281 NULL
121538 +inline_xattr_size_28285 inline_xattr_size 0 28285 NULL
121539 +dma_map_sg_attrs_28289 dma_map_sg_attrs 0 28289 NULL
121540 +SyS_ppoll_28290 SyS_ppoll 2 28290 NULL
121541 +kstrtos16_from_user_28300 kstrtos16_from_user 2 28300 NULL
121542 +nouveau_compat_ioctl_28305 nouveau_compat_ioctl 2 28305 NULL
121543 +snd_pcm_oss_read_28317 snd_pcm_oss_read 3 28317 NULL
121544 +xpcs_mmd_read_28331 xpcs_mmd_read 3 28331 NULL
121545 +bm_entry_write_28338 bm_entry_write 3 28338 NULL
121546 +tcp_copy_to_iovec_28344 tcp_copy_to_iovec 3 28344 NULL
121547 +snapshot_write_28351 snapshot_write 3 28351 NULL
121548 +xfs_iomap_write_unwritten_28365 xfs_iomap_write_unwritten 3-2 28365 NULL
121549 +batadv_handle_tt_response_28370 batadv_handle_tt_response 4 28370 NULL
121550 +dlmfs_file_read_28385 dlmfs_file_read 3 28385 NULL
121551 +tx_frag_cache_miss_read_28394 tx_frag_cache_miss_read 3 28394 NULL
121552 +bypass_pwup_write_28416 bypass_pwup_write 3 28416 NULL
121553 +subdev_ioctl_28417 subdev_ioctl 2 28417 NULL
121554 +__videobuf_mmap_setup_28421 __videobuf_mmap_setup 0 28421 NULL
121555 +ksocknal_alloc_tx_28426 ksocknal_alloc_tx 2 28426 NULL
121556 +hid_hw_output_report_28429 hid_hw_output_report 0 28429 NULL
121557 +mpage_readpages_28436 mpage_readpages 3 28436 NULL
121558 +snd_emu10k1_efx_read_28452 snd_emu10k1_efx_read 2 28452 NULL
121559 +key_mic_failures_read_28457 key_mic_failures_read 3 28457 NULL
121560 +alloc_irq_cpu_rmap_28459 alloc_irq_cpu_rmap 1 28459 NULL
121561 +ps_poll_upsd_utilization_read_28519 ps_poll_upsd_utilization_read 3 28519 NULL
121562 +sh_irda_init_iobuf_28527 sh_irda_init_iobuf 2 28527 NULL nohasharray
121563 +i2400m_tx_stats_read_28527 i2400m_tx_stats_read 3 28527 &sh_irda_init_iobuf_28527
121564 +early_init_dt_alloc_memory_arch_28528 early_init_dt_alloc_memory_arch 1 28528 NULL
121565 +sel_read_policycap_28544 sel_read_policycap 3 28544 NULL
121566 +run_delalloc_range_28545 run_delalloc_range 3-4 28545 NULL nohasharray
121567 +aio_read_events_28545 aio_read_events 3 28545 &run_delalloc_range_28545 nohasharray
121568 +mptctl_getiocinfo_28545 mptctl_getiocinfo 2 28545 &aio_read_events_28545
121569 +b43legacy_debugfs_write_28556 b43legacy_debugfs_write 3 28556 NULL
121570 +asymmetric_verify_28567 asymmetric_verify 3 28567 NULL
121571 +oxygen_read32_28582 oxygen_read32 0 28582 NULL
121572 +task_cgroup_path_28599 task_cgroup_path 3 28599 NULL
121573 +extract_entropy_28604 extract_entropy 5-3 28604 NULL
121574 +xgbe_common_write_28609 xgbe_common_write 2 28609 NULL
121575 +kfifo_unused_28612 kfifo_unused 0 28612 NULL
121576 +snd_nm256_capture_copy_28622 snd_nm256_capture_copy 5-3 28622 NULL
121577 +setup_usemap_28636 setup_usemap 3-4 28636 NULL
121578 +qib_handle_6120_hwerrors_28642 qib_handle_6120_hwerrors 3 28642 NULL
121579 +p9_fcall_alloc_28652 p9_fcall_alloc 1 28652 NULL
121580 +blk_queue_resize_tags_28670 blk_queue_resize_tags 2 28670 NULL
121581 +SyS_setgroups16_28686 SyS_setgroups16 1 28686 NULL
121582 +kvm_mmu_get_page_28692 kvm_mmu_get_page 2 28692 NULL
121583 +drm_plane_init_28731 drm_plane_init 6 28731 NULL
121584 +spi_execute_28736 spi_execute 5 28736 NULL
121585 +snd_pcm_aio_write_28738 snd_pcm_aio_write 3 28738 NULL
121586 +read_file_btcoex_28743 read_file_btcoex 3 28743 NULL
121587 +max_hw_blocks_28748 max_hw_blocks 0 28748 NULL
121588 +nv50_dmac_create_28762 nv50_dmac_create 5 28762 NULL
121589 +rpc_pipe_generic_upcall_28766 rpc_pipe_generic_upcall 4 28766 NULL
121590 +ath6kl_get_num_reg_28780 ath6kl_get_num_reg 0 28780 NULL
121591 +sel_write_member_28800 sel_write_member 3 28800 NULL
121592 +iwl_dbgfs_rxon_filter_flags_read_28832 iwl_dbgfs_rxon_filter_flags_read 3 28832 NULL
121593 +kernel_tree_alloc_28833 kernel_tree_alloc 1 28833 NULL
121594 +parser_init_byteStream_28841 parser_init_byteStream 2 28841 NULL
121595 +vp_request_msix_vectors_28849 vp_request_msix_vectors 2 28849 NULL
121596 +ipv6_renew_options_28867 ipv6_renew_options 5 28867 NULL
121597 +packet_sendmsg_spkt_28885 packet_sendmsg_spkt 4 28885 NULL
121598 +da9055_group_write_28904 da9055_group_write 2-3 28904 NULL
121599 +ps_upsd_timeouts_read_28924 ps_upsd_timeouts_read 3 28924 NULL
121600 +iwl_dbgfs_sleep_level_override_write_28925 iwl_dbgfs_sleep_level_override_write 3 28925 NULL
121601 +push_rx_28939 push_rx 3 28939 NULL
121602 +mxuport_prepare_write_buffer_28943 mxuport_prepare_write_buffer 3 28943 NULL
121603 +btrfs_trim_block_group_28963 btrfs_trim_block_group 3-4 28963 NULL
121604 +alloc_sched_domains_28972 alloc_sched_domains 1 28972 NULL
121605 +hash_net6_expire_28979 hash_net6_expire 4 28979 NULL
121606 +hci_sock_setsockopt_28993 hci_sock_setsockopt 5 28993 NULL
121607 +bin_uuid_28999 bin_uuid 3 28999 NULL
121608 +fd_execute_rw_29004 fd_execute_rw 3 29004 NULL
121609 +ieee80211_if_read_ht_opmode_29044 ieee80211_if_read_ht_opmode 3 29044 NULL
121610 +rxrpc_sendmsg_29049 rxrpc_sendmsg 4 29049 NULL
121611 +btrfs_root_bytenr_29058 btrfs_root_bytenr 0 29058 NULL
121612 +iso_packets_buffer_init_29061 iso_packets_buffer_init 3-4 29061 NULL
121613 +lpfc_idiag_extacc_drivr_get_29067 lpfc_idiag_extacc_drivr_get 0-3 29067 NULL
121614 +sctp_getsockopt_assoc_stats_29074 sctp_getsockopt_assoc_stats 2 29074 NULL
121615 +iwl_dbgfs_log_event_write_29088 iwl_dbgfs_log_event_write 3 29088 NULL
121616 +ccp_init_dm_workarea_29097 ccp_init_dm_workarea 3 29097 NULL
121617 +__compat_sys_preadv64_29103 __compat_sys_preadv64 3 29103 NULL
121618 +isdn_ppp_write_29109 isdn_ppp_write 4 29109 NULL
121619 +snprintf_29125 snprintf 0 29125 NULL
121620 +iov_shorten_29130 iov_shorten 0 29130 NULL
121621 +proc_scsi_write_29142 proc_scsi_write 3 29142 NULL
121622 +kvm_mmu_notifier_clear_flush_young_29154 kvm_mmu_notifier_clear_flush_young 3 29154 NULL
121623 +drm_property_create_enum_29201 drm_property_create_enum 5 29201 NULL
121624 +wusb_prf_256_29203 wusb_prf_256 7 29203 NULL
121625 +iwl_dbgfs_temperature_read_29224 iwl_dbgfs_temperature_read 3 29224 NULL
121626 +nvme_trans_copy_from_user_29227 nvme_trans_copy_from_user 3 29227 NULL
121627 +irq_domain_add_linear_29236 irq_domain_add_linear 2 29236 NULL
121628 +evdev_handle_get_val_29242 evdev_handle_get_val 5-6 29242 NULL
121629 +security_context_to_sid_core_29248 security_context_to_sid_core 2 29248 NULL
121630 +rbd_osd_req_create_29260 rbd_osd_req_create 3 29260 NULL
121631 +mwifiex_hscfg_write_29262 mwifiex_hscfg_write 3 29262 NULL
121632 +prism2_set_genericelement_29277 prism2_set_genericelement 3 29277 NULL
121633 +ext4_fiemap_29296 ext4_fiemap 4 29296 NULL
121634 +sn9c102_read_29305 sn9c102_read 3 29305 NULL
121635 +__fuse_get_req_29315 __fuse_get_req 2 29315 NULL
121636 +lprocfs_write_helper_29323 lprocfs_write_helper 2 29323 NULL
121637 +kvm_handle_hva_29326 kvm_handle_hva 2 29326 NULL
121638 +obd_proc_jobid_name_seq_write_29332 obd_proc_jobid_name_seq_write 3 29332 NULL
121639 +tun_put_user_29337 tun_put_user 5 29337 NULL
121640 +__alloc_ei_netdev_29338 __alloc_ei_netdev 1 29338 NULL
121641 +l2cap_sock_setsockopt_old_29346 l2cap_sock_setsockopt_old 4 29346 NULL
121642 +read_file_tx99_power_29405 read_file_tx99_power 3 29405 NULL
121643 +mempool_create_29437 mempool_create 1 29437 NULL
121644 +crypto_ahash_alignmask_29445 crypto_ahash_alignmask 0 29445 NULL
121645 +p9_client_prepare_req_29448 p9_client_prepare_req 3 29448 NULL
121646 +validate_scan_freqs_29462 validate_scan_freqs 0 29462 NULL
121647 +SyS_flistxattr_29474 SyS_flistxattr 3 29474 NULL
121648 +do_register_entry_29478 do_register_entry 4 29478 NULL
121649 +simple_strtoul_29480 simple_strtoul 0 29480 NULL
121650 +btmrvl_pscmd_write_29504 btmrvl_pscmd_write 3 29504 NULL
121651 +btrfs_file_extent_disk_bytenr_29505 btrfs_file_extent_disk_bytenr 0 29505 NULL
121652 +usnic_vnic_spec_dump_29508 usnic_vnic_spec_dump 2 29508 NULL
121653 +write_file_regidx_29517 write_file_regidx 3 29517 NULL
121654 +atk_debugfs_ggrp_read_29522 atk_debugfs_ggrp_read 3 29522 NULL
121655 +mic_vringh_copy_29531 mic_vringh_copy 4 29531 NULL
121656 +ftrace_write_29551 ftrace_write 3 29551 NULL
121657 +idetape_queue_rw_tail_29562 idetape_queue_rw_tail 3 29562 NULL
121658 +leaf_dealloc_29566 leaf_dealloc 3 29566 NULL
121659 +kvm_read_guest_virt_system_29569 kvm_read_guest_virt_system 4-2 29569 NULL
121660 +lbs_lowsnr_read_29571 lbs_lowsnr_read 3 29571 NULL
121661 +iwl_dbgfs_missed_beacon_write_29586 iwl_dbgfs_missed_beacon_write 3 29586 NULL
121662 +pvr2_hdw_report_unlocked_29589 pvr2_hdw_report_unlocked 4-0 29589 NULL
121663 +dio_set_defer_completion_29599 dio_set_defer_completion 0 29599 NULL
121664 +slots_per_page_29601 slots_per_page 0 29601 NULL
121665 +osc_cached_mb_seq_write_29610 osc_cached_mb_seq_write 3 29610 NULL
121666 +lstcon_rpc_init_29623 lstcon_rpc_init 4 29623 NULL
121667 +nla_get_u16_29624 nla_get_u16 0 29624 NULL
121668 +tx_frag_cache_hit_read_29639 tx_frag_cache_hit_read 3 29639 NULL
121669 +sctp_make_abort_user_29654 sctp_make_abort_user 3 29654 NULL nohasharray
121670 +spmi_controller_alloc_29654 spmi_controller_alloc 2 29654 &sctp_make_abort_user_29654
121671 +sisusb_write_mem_bulk_29678 sisusb_write_mem_bulk 4 29678 NULL
121672 +lustre_posix_acl_xattr_2ext_29693 lustre_posix_acl_xattr_2ext 2 29693 NULL
121673 +posix_acl_from_xattr_29708 posix_acl_from_xattr 3 29708 NULL
121674 +probes_write_29711 probes_write 3 29711 NULL
121675 +read_cis_cache_29735 read_cis_cache 4 29735 NULL
121676 +xfs_new_eof_29737 xfs_new_eof 2 29737 NULL
121677 +std_nic_write_29752 std_nic_write 3 29752 NULL
121678 +static_key_count_29771 static_key_count 0 29771 NULL
121679 +dbAlloc_29794 dbAlloc 0 29794 NULL
121680 +tcp_sendpage_29829 tcp_sendpage 4 29829 NULL
121681 +__probe_kernel_write_29842 __probe_kernel_write 3 29842 NULL
121682 +kvm_read_hva_atomic_29848 kvm_read_hva_atomic 3 29848 NULL
121683 +count_partial_29850 count_partial 0 29850 NULL
121684 +write_file_bool_bmps_29870 write_file_bool_bmps 3 29870 NULL
121685 +ipv6_setsockopt_29871 ipv6_setsockopt 5 29871 NULL
121686 +crypto_aead_alignmask_29885 crypto_aead_alignmask 0 29885 NULL
121687 +rtw_cfg80211_indicate_sta_assoc_29897 rtw_cfg80211_indicate_sta_assoc 3 29897 NULL
121688 +nv94_gpio_intr_mask_29907 nv94_gpio_intr_mask 4-3 29907 NULL
121689 +lov_ost_pool_extend_29914 lov_ost_pool_extend 2 29914 NULL
121690 +write_file_queue_29922 write_file_queue 3 29922 NULL
121691 +__btrfs_getxattr_29947 __btrfs_getxattr 0 29947 NULL nohasharray
121692 +ipv6_recv_error_29947 ipv6_recv_error 3 29947 &__btrfs_getxattr_29947
121693 +dev_mem_write_30028 dev_mem_write 3 30028 NULL
121694 +alloc_netdev_mqs_30030 alloc_netdev_mqs 1 30030 NULL
121695 +sysfs_add_file_mode_ns_30038 sysfs_add_file_mode_ns 0 30038 NULL
121696 +scsi_vpd_inquiry_30040 scsi_vpd_inquiry 0-4 30040 NULL
121697 +drp_wmove_30043 drp_wmove 4 30043 NULL
121698 +cxgbi_ddp_reserve_30091 cxgbi_ddp_reserve 4 30091 NULL
121699 +snd_midi_channel_init_set_30092 snd_midi_channel_init_set 1 30092 NULL
121700 +rx_filter_data_filter_read_30098 rx_filter_data_filter_read 3 30098 NULL
121701 +defragment_dma_buffer_30113 defragment_dma_buffer 0 30113 NULL
121702 +spi_async_locked_30117 spi_async_locked 0 30117 NULL
121703 +u_memcpya_30139 u_memcpya 3-2 30139 NULL
121704 +dbg_port_buf_30145 dbg_port_buf 2 30145 NULL
121705 +elfcorehdr_read_30159 elfcorehdr_read 2 30159 NULL
121706 +alloc_switch_ctx_30165 alloc_switch_ctx 2 30165 NULL
121707 +expand_inode_data_30169 expand_inode_data 3-2 30169 NULL
121708 +mempool_create_page_pool_30189 mempool_create_page_pool 1 30189 NULL
121709 +drm_property_create_bitmask_30195 drm_property_create_bitmask 5 30195 NULL
121710 +__genwqe_readq_30197 __genwqe_readq 0 30197 NULL
121711 +usblp_ioctl_30203 usblp_ioctl 2 30203 NULL
121712 +SyS_semop_30227 SyS_semop 3 30227 NULL
121713 +bitmap_file_set_bit_30228 bitmap_file_set_bit 2 30228 NULL
121714 +rawv6_recvmsg_30265 rawv6_recvmsg 4 30265 NULL
121715 +isr_pci_pm_read_30271 isr_pci_pm_read 3 30271 NULL
121716 +compat_readv_30273 compat_readv 3 30273 NULL
121717 +skcipher_sendmsg_30290 skcipher_sendmsg 4 30290 NULL
121718 +pipeline_sec_frag_swi_read_30294 pipeline_sec_frag_swi_read 3 30294 NULL
121719 +tcp_sendmsg_30296 tcp_sendmsg 4 30296 NULL
121720 +osc_contention_seconds_seq_write_30305 osc_contention_seconds_seq_write 3 30305 NULL
121721 +ext4_acl_from_disk_30320 ext4_acl_from_disk 2 30320 NULL
121722 +i8254_read_30330 i8254_read 0 30330 NULL
121723 +resource_from_user_30341 resource_from_user 3 30341 NULL
121724 +o2nm_this_node_30342 o2nm_this_node 0 30342 NULL
121725 +kstrtou32_from_user_30361 kstrtou32_from_user 2 30361 NULL
121726 +pvscsi_change_queue_depth_30365 pvscsi_change_queue_depth 2 30365 NULL
121727 +C_SYSC_readv_30369 C_SYSC_readv 3 30369 NULL
121728 +blkdev_issue_zeroout_30392 blkdev_issue_zeroout 3 30392 NULL
121729 +c4iw_init_resource_30393 c4iw_init_resource 2-3 30393 NULL
121730 +vb2_fop_write_30420 vb2_fop_write 3 30420 NULL
121731 +tx_tx_template_prepared_read_30424 tx_tx_template_prepared_read 3 30424 NULL
121732 +lstcon_session_info_30425 lstcon_session_info 6 30425 NULL
121733 +enable_write_30456 enable_write 3 30456 NULL
121734 +tx_tx_template_programmed_read_30461 tx_tx_template_programmed_read 3 30461 NULL
121735 +urandom_read_30462 urandom_read 3 30462 NULL
121736 +zoran_ioctl_30465 zoran_ioctl 2 30465 NULL
121737 +adu_write_30487 adu_write 3 30487 NULL
121738 +dtim_interval_write_30489 dtim_interval_write 3 30489 NULL
121739 +batadv_send_tt_request_30493 batadv_send_tt_request 5 30493 NULL
121740 +memblock_virt_alloc_node_30515 memblock_virt_alloc_node 1 30515 NULL
121741 +dwc3_testmode_write_30516 dwc3_testmode_write 3 30516 NULL
121742 +debug_debug2_read_30526 debug_debug2_read 3 30526 NULL nohasharray
121743 +set_config_30526 set_config 0 30526 &debug_debug2_read_30526
121744 +xfs_sb_version_hasftype_30559 xfs_sb_version_hasftype 0 30559 NULL
121745 +disk_expand_part_tbl_30561 disk_expand_part_tbl 2 30561 NULL
121746 +set_le_30581 set_le 4 30581 NULL
121747 +blk_init_tags_30592 blk_init_tags 1 30592 NULL
121748 +sgl_map_user_pages_30610 sgl_map_user_pages 2 30610 NULL
121749 +SyS_msgrcv_30611 SyS_msgrcv 3 30611 NULL
121750 +macvtap_sendmsg_30629 macvtap_sendmsg 4 30629 NULL
121751 +ieee80211_if_read_dot11MeshAwakeWindowDuration_30631 ieee80211_if_read_dot11MeshAwakeWindowDuration 3 30631 NULL
121752 +compat_raw_setsockopt_30634 compat_raw_setsockopt 5 30634 NULL
121753 +mlx5_ib_alloc_fast_reg_page_list_30638 mlx5_ib_alloc_fast_reg_page_list 2 30638 NULL
121754 +SyS_listxattr_30647 SyS_listxattr 3 30647 NULL
121755 +jffs2_flash_read_30667 jffs2_flash_read 0 30667 NULL
121756 +ni_ai_fifo_read_30681 ni_ai_fifo_read 3 30681 NULL
121757 +sst_hsw_get_dsp_position_30691 sst_hsw_get_dsp_position 0 30691 NULL
121758 +get_pages_alloc_iovec_30699 get_pages_alloc_iovec 3-0 30699 NULL
121759 +dccp_setsockopt_ccid_30701 dccp_setsockopt_ccid 4 30701 NULL
121760 +lbs_wrbbp_write_30712 lbs_wrbbp_write 3 30712 NULL
121761 +lbs_debugfs_read_30721 lbs_debugfs_read 3 30721 NULL
121762 +snd_nm256_playback_silence_30727 snd_nm256_playback_silence 4-3 30727 NULL
121763 +snapshot_status_30744 snapshot_status 5 30744 NULL
121764 +fuse_direct_IO_30753 fuse_direct_IO 4 30753 NULL
121765 +fuse_conn_limit_write_30777 fuse_conn_limit_write 3 30777 NULL
121766 +__bio_alloc_30787 __bio_alloc 3 30787 NULL
121767 +smk_read_doi_30813 smk_read_doi 3 30813 NULL
121768 +get_kobj_path_length_30831 get_kobj_path_length 0 30831 NULL
121769 +ath10k_write_fw_dbglog_30835 ath10k_write_fw_dbglog 3 30835 NULL
121770 +of_gpio_named_count_30841 of_gpio_named_count 0 30841 NULL
121771 +sctp_setsockopt_auth_chunk_30843 sctp_setsockopt_auth_chunk 3 30843 NULL
121772 +wd_autoreset_write_30862 wd_autoreset_write 3 30862 NULL
121773 +ieee80211_if_fmt_dropped_frames_no_route_30884 ieee80211_if_fmt_dropped_frames_no_route 3 30884 NULL
121774 +pn_recvmsg_30887 pn_recvmsg 4 30887 NULL
121775 +usnic_debugfs_buildinfo_read_30928 usnic_debugfs_buildinfo_read 3 30928 NULL
121776 +sctp_setsockopt_rtoinfo_30941 sctp_setsockopt_rtoinfo 3 30941 NULL
121777 +tty_insert_flip_string_flags_30969 tty_insert_flip_string_flags 4 30969 NULL
121778 +huge_page_mask_30981 huge_page_mask 0 30981 NULL
121779 +read_file_bt_ant_diversity_30983 read_file_bt_ant_diversity 3 30983 NULL
121780 +lbs_host_sleep_read_31013 lbs_host_sleep_read 3 31013 NULL
121781 +ima_eventsig_init_31022 ima_eventsig_init 5 31022 NULL
121782 +template_fmt_size_31033 template_fmt_size 0 31033 NULL
121783 +stride_pg_count_31053 stride_pg_count 0-3-2-1-4-5 31053 NULL
121784 +lbs_failcount_read_31063 lbs_failcount_read 3 31063 NULL
121785 +sctp_setsockopt_context_31091 sctp_setsockopt_context 3 31091 NULL
121786 +proc_gid_map_write_31093 proc_gid_map_write 3 31093 NULL
121787 +depth_read_31112 depth_read 3 31112 NULL
121788 +hash_ipportnet6_expire_31118 hash_ipportnet6_expire 4 31118 NULL
121789 +kimage_normal_alloc_31140 kimage_normal_alloc 3 31140 NULL
121790 +size_inside_page_31141 size_inside_page 0 31141 NULL
121791 +w9966_v4l_read_31148 w9966_v4l_read 3 31148 NULL
121792 +ch_do_scsi_31171 ch_do_scsi 4 31171 NULL
121793 +r592_read_fifo_pio_31198 r592_read_fifo_pio 3 31198 NULL
121794 +mtdchar_readoob_31200 mtdchar_readoob 4 31200 NULL
121795 +cpumask_weight_31215 cpumask_weight 0 31215 NULL
121796 +__read_reg_31216 __read_reg 0 31216 NULL
121797 +atm_get_addr_31221 atm_get_addr 3 31221 NULL
121798 +tcp_recvmsg_31238 tcp_recvmsg 4 31238 NULL
121799 +cyy_readb_31240 cyy_readb 0 31240 NULL
121800 +_create_sg_bios_31244 _create_sg_bios 4 31244 NULL
121801 +ieee80211_if_read_last_beacon_31257 ieee80211_if_read_last_beacon 3 31257 NULL
121802 +hash_netportnet4_expire_31290 hash_netportnet4_expire 4 31290 NULL
121803 +uvc_simplify_fraction_31303 uvc_simplify_fraction 3 31303 NULL
121804 +sisusbcon_scroll_31315 sisusbcon_scroll 5-2-3 31315 NULL
121805 +command_file_write_31318 command_file_write 3 31318 NULL
121806 +hwerr_crcbits_31334 hwerr_crcbits 4 31334 NULL
121807 +_regmap_raw_multi_reg_write_31336 _regmap_raw_multi_reg_write 3 31336 NULL
121808 +em28xx_init_usb_xfer_31337 em28xx_init_usb_xfer 4-6 31337 NULL
121809 +outlen_write_31358 outlen_write 3 31358 NULL
121810 +ieee80211_rx_mgmt_auth_31366 ieee80211_rx_mgmt_auth 3 31366 NULL
121811 +xprt_rdma_allocate_31372 xprt_rdma_allocate 2 31372 NULL
121812 +vb2_vmalloc_get_userptr_31374 vb2_vmalloc_get_userptr 3-2 31374 NULL
121813 +trace_parser_get_init_31379 trace_parser_get_init 2 31379 NULL
121814 +inb_31388 inb 0 31388 NULL
121815 +mp_ioapic_pin_count_31393 mp_ioapic_pin_count 0 31393 NULL
121816 +key_ifindex_read_31411 key_ifindex_read 3 31411 NULL
121817 +_sp2d_max_pg_31422 _sp2d_max_pg 0 31422 NULL
121818 +TSS_checkhmac1_31429 TSS_checkhmac1 5 31429 NULL
121819 +snd_aw2_saa7146_get_hw_ptr_capture_31431 snd_aw2_saa7146_get_hw_ptr_capture 0 31431 NULL
121820 +transport_alloc_session_tags_31449 transport_alloc_session_tags 2-3 31449 NULL
121821 +opera1_xilinx_rw_31453 opera1_xilinx_rw 5 31453 NULL
121822 +xfs_btree_get_numrecs_31477 xfs_btree_get_numrecs 0 31477 NULL
121823 +alg_setkey_31485 alg_setkey 3 31485 NULL
121824 +rds_message_map_pages_31487 rds_message_map_pages 2 31487 NULL
121825 +qsfp_2_read_31491 qsfp_2_read 3 31491 NULL
121826 +__alloc_bootmem_31498 __alloc_bootmem 1 31498 NULL
121827 +hidraw_write_31536 hidraw_write 3 31536 NULL
121828 +usbvision_read_31555 usbvision_read 3 31555 NULL
121829 +tx_frag_tkip_called_read_31575 tx_frag_tkip_called_read 3 31575 NULL
121830 +get_max_inline_xattr_value_size_31578 get_max_inline_xattr_value_size 0 31578 NULL
121831 +osst_write_31581 osst_write 3 31581 NULL
121832 +snd_compr_get_avail_31584 snd_compr_get_avail 0 31584 NULL
121833 +iwl_dbgfs_ucode_tx_stats_read_31611 iwl_dbgfs_ucode_tx_stats_read 3 31611 NULL
121834 +memblock_virt_alloc_nopanic_31617 memblock_virt_alloc_nopanic 1 31617 NULL nohasharray
121835 +arvo_sysfs_read_31617 arvo_sysfs_read 6 31617 &memblock_virt_alloc_nopanic_31617
121836 +usnic_ib_dump_vf_31623 usnic_ib_dump_vf 3 31623 NULL
121837 +videobuf_read_one_31637 videobuf_read_one 3 31637 NULL
121838 +pod_alloc_sysex_buffer_31651 pod_alloc_sysex_buffer 3 31651 NULL
121839 +xfer_secondary_pool_31661 xfer_secondary_pool 2 31661 NULL
121840 +__lgread_31668 __lgread 4 31668 NULL
121841 +copy_from_user_nmi_31672 copy_from_user_nmi 3-0 31672 NULL
121842 +forced_ps_read_31685 forced_ps_read 3 31685 NULL
121843 +fst_recover_rx_error_31687 fst_recover_rx_error 3 31687 NULL
121844 +rs_pretty_print_rate_31727 rs_pretty_print_rate 0 31727 NULL
121845 +lu_buf_check_and_grow_31735 lu_buf_check_and_grow 2 31735 NULL nohasharray
121846 +utf16s_to_utf8s_31735 utf16s_to_utf8s 0 31735 &lu_buf_check_and_grow_31735
121847 +shmem_pwrite_slow_31741 shmem_pwrite_slow 3-2 31741 NULL
121848 +input_abs_get_max_31742 input_abs_get_max 0 31742 NULL nohasharray
121849 +NCR_700_change_queue_depth_31742 NCR_700_change_queue_depth 2 31742 &input_abs_get_max_31742
121850 +bcm_char_read_31750 bcm_char_read 3 31750 NULL
121851 +snd_seq_device_new_31753 snd_seq_device_new 4 31753 NULL
121852 +SyS_lsetxattr_31766 SyS_lsetxattr 4 31766 NULL
121853 +usblp_cache_device_id_string_31790 usblp_cache_device_id_string 0 31790 NULL
121854 +get_count_order_31800 get_count_order 0 31800 NULL
121855 +ecryptfs_send_message_locked_31801 ecryptfs_send_message_locked 2 31801 NULL
121856 +isr_rx_procs_read_31804 isr_rx_procs_read 3 31804 NULL
121857 +data_write_31805 data_write 3 31805 NULL
121858 +SyS_msgsnd_31814 SyS_msgsnd 3 31814 NULL
121859 +strnlen_user_31815 strnlen_user 0-2 31815 NULL
121860 +sta_last_signal_read_31818 sta_last_signal_read 3 31818 NULL
121861 +clone_bio_31854 clone_bio 4-3 31854 NULL
121862 +SyS_ppoll_31855 SyS_ppoll 2 31855 NULL
121863 +iwl_dbgfs_disable_ht40_write_31876 iwl_dbgfs_disable_ht40_write 3 31876 NULL
121864 +drm_mode_crtc_set_gamma_size_31881 drm_mode_crtc_set_gamma_size 2 31881 NULL
121865 +ddb_output_write_31902 ddb_output_write 3-0 31902 NULL
121866 +xattr_permission_31907 xattr_permission 0 31907 NULL
121867 +lu_buf_realloc_31915 lu_buf_realloc 2 31915 NULL
121868 +new_dir_31919 new_dir 3 31919 NULL
121869 +kmem_alloc_31920 kmem_alloc 1 31920 NULL
121870 +era_status_31934 era_status 5 31934 NULL
121871 +SYSC_sethostname_31940 SYSC_sethostname 2 31940 NULL
121872 +read_mem_31942 read_mem 3 31942 NULL
121873 +ext4_zero_range_31944 ext4_zero_range 3-2 31944 NULL
121874 +vb2_write_31948 vb2_write 3 31948 NULL
121875 +pvr2_ctrl_get_valname_31951 pvr2_ctrl_get_valname 4 31951 NULL
121876 +regcache_rbtree_sync_31964 regcache_rbtree_sync 2 31964 NULL
121877 +iwl_rx_packet_payload_len_31965 iwl_rx_packet_payload_len 0 31965 NULL
121878 +copy_from_user_toio_31966 copy_from_user_toio 3 31966 NULL
121879 +iblock_execute_rw_31982 iblock_execute_rw 3 31982 NULL nohasharray
121880 +vx_read_status_31982 vx_read_status 0 31982 &iblock_execute_rw_31982
121881 +find_next_zero_bit_31990 find_next_zero_bit 0 31990 NULL
121882 +lustre_acl_xattr_merge2posix_31992 lustre_acl_xattr_merge2posix 2 31992 NULL
121883 +sysfs_create_file_31996 sysfs_create_file 0 31996 NULL
121884 +calc_hmac_32010 calc_hmac 3 32010 NULL
121885 +aead_len_32021 aead_len 0 32021 NULL
121886 +sci_dma_rx_push_32029 sci_dma_rx_push 2 32029 NULL
121887 +stk_read_32038 stk_read 3 32038 NULL
121888 +SYSC_llistxattr_32061 SYSC_llistxattr 3 32061 NULL
121889 +proc_scsi_devinfo_write_32064 proc_scsi_devinfo_write 3 32064 NULL
121890 +cow_file_range_inline_32091 cow_file_range_inline 3 32091 NULL
121891 +kiblnd_alloc_pages_32092 kiblnd_alloc_pages 3 32092 NULL
121892 +bio_alloc_32095 bio_alloc 2 32095 NULL
121893 +ath6kl_fwlog_read_32101 ath6kl_fwlog_read 3 32101 NULL
121894 +disk_status_32120 disk_status 4 32120 NULL
121895 +kobject_add_internal_32133 kobject_add_internal 0 32133 NULL
121896 +venus_link_32165 venus_link 5 32165 NULL
121897 +ocfs2_direct_IO_32168 ocfs2_direct_IO 4 32168 NULL
121898 +do_writepages_32173 do_writepages 0 32173 NULL
121899 +del_ptr_32197 del_ptr 4 32197 NULL
121900 +wusb_ccm_mac_32199 wusb_ccm_mac 7 32199 NULL
121901 +riva_get_cmap_len_32218 riva_get_cmap_len 0 32218 NULL
121902 +caif_seqpkt_recvmsg_32241 caif_seqpkt_recvmsg 4 32241 NULL
121903 +lbs_lowrssi_read_32242 lbs_lowrssi_read 3 32242 NULL
121904 +ocfs2_xattr_find_entry_32260 ocfs2_xattr_find_entry 0 32260 NULL
121905 +kvm_set_spte_hva_32312 kvm_set_spte_hva 2 32312 NULL
121906 +cas_calc_tabort_32316 cas_calc_tabort 0 32316 NULL
121907 +SyS_select_32319 SyS_select 1 32319 NULL
121908 +nouveau_bar_create__32332 nouveau_bar_create_ 4 32332 NULL
121909 +nl80211_send_mlme_event_32337 nl80211_send_mlme_event 4 32337 NULL
121910 +t4_alloc_mem_32342 t4_alloc_mem 1 32342 NULL
121911 +dispatch_ioctl_32357 dispatch_ioctl 2 32357 NULL nohasharray
121912 +rx_streaming_always_write_32357 rx_streaming_always_write 3 32357 &dispatch_ioctl_32357
121913 +sel_read_initcon_32362 sel_read_initcon 3 32362 NULL nohasharray
121914 +ReadHDLCPCI_32362 ReadHDLCPCI 0 32362 &sel_read_initcon_32362
121915 +ll_setxattr_common_32398 ll_setxattr_common 4 32398 NULL
121916 +xfs_iext_add_indirect_multi_32400 xfs_iext_add_indirect_multi 3 32400 NULL
121917 +vmci_qp_alloc_32405 vmci_qp_alloc 5-3 32405 NULL
121918 +cache_status_32462 cache_status 5 32462 NULL
121919 +fill_readbuf_32464 fill_readbuf 3 32464 NULL
121920 +ide_driver_proc_write_32493 ide_driver_proc_write 3 32493 NULL
121921 +bypass_pwoff_write_32499 bypass_pwoff_write 3 32499 NULL
121922 +mdc_pinger_recov_seq_write_32510 mdc_pinger_recov_seq_write 3 32510 NULL
121923 +ctrl_std_val_to_sym_32516 ctrl_std_val_to_sym 5 32516 NULL
121924 +disconnect_32521 disconnect 4 32521 NULL
121925 +qsfp_read_32522 qsfp_read 0-2-4 32522 NULL
121926 +ilo_read_32531 ilo_read 3 32531 NULL
121927 +ieee80211_if_read_estab_plinks_32533 ieee80211_if_read_estab_plinks 3 32533 NULL
121928 +format_devstat_counter_32550 format_devstat_counter 3 32550 NULL
121929 +aes_encrypt_fail_read_32562 aes_encrypt_fail_read 3 32562 NULL
121930 +osc_iocontrol_32565 osc_iocontrol 3 32565 NULL
121931 +mem_swapout_entry_32586 mem_swapout_entry 3 32586 NULL
121932 +pipeline_tcp_tx_stat_fifo_int_read_32589 pipeline_tcp_tx_stat_fifo_int_read 3 32589 NULL
121933 +read_file_beacon_32595 read_file_beacon 3 32595 NULL
121934 +ieee80211_if_read_dropped_frames_congestion_32603 ieee80211_if_read_dropped_frames_congestion 3 32603 NULL
121935 +irda_recvmsg_dgram_32631 irda_recvmsg_dgram 4 32631 NULL
121936 +cfg80211_roamed_32632 cfg80211_roamed 5-7 32632 NULL
121937 +xpcs_reg_value_read_32644 xpcs_reg_value_read 3 32644 NULL
121938 +kvmalloc_32646 kvmalloc 1 32646 NULL
121939 +ib_sg_dma_len_32649 ib_sg_dma_len 0 32649 NULL
121940 +generic_readlink_32654 generic_readlink 3 32654 NULL
121941 +move_addr_to_kernel_32673 move_addr_to_kernel 2 32673 NULL
121942 +compat_SyS_preadv_32679 compat_SyS_preadv 3 32679 NULL
121943 +jfs_readpages_32702 jfs_readpages 4 32702 NULL
121944 +rt2x00debug_read_queue_dump_32712 rt2x00debug_read_queue_dump 3 32712 NULL
121945 +_xfs_buf_get_pages_32715 _xfs_buf_get_pages 2 32715 NULL
121946 +megasas_change_queue_depth_32747 megasas_change_queue_depth 2 32747 NULL
121947 +stats_read_ul_32751 stats_read_ul 3 32751 NULL
121948 +vmci_transport_dgram_dequeue_32775 vmci_transport_dgram_dequeue 4 32775 NULL
121949 +sctp_tsnmap_grow_32784 sctp_tsnmap_grow 2 32784 NULL
121950 +rproc_name_read_32805 rproc_name_read 3 32805 NULL
121951 +sta_tx_latency_stat_read_32862 sta_tx_latency_stat_read 3 32862 NULL
121952 +new_tape_buffer_32866 new_tape_buffer 2 32866 NULL
121953 +cifs_writedata_alloc_32880 cifs_writedata_alloc 1 32880 NULL nohasharray
121954 +ath6kl_usb_submit_ctrl_in_32880 ath6kl_usb_submit_ctrl_in 6 32880 &cifs_writedata_alloc_32880
121955 +vp702x_usb_inout_cmd_32884 vp702x_usb_inout_cmd 4-6 32884 NULL
121956 +visorchannel_dump_section_32893 visorchannel_dump_section 4 32893 NULL
121957 +tipc_link_iovec_xmit_fast_32913 tipc_link_iovec_xmit_fast 3 32913 NULL nohasharray
121958 +il_dbgfs_tx_stats_read_32913 il_dbgfs_tx_stats_read 3 32913 &tipc_link_iovec_xmit_fast_32913
121959 +zlib_inflate_workspacesize_32927 zlib_inflate_workspacesize 0 32927 NULL
121960 +rmap_recycle_32938 rmap_recycle 3 32938 NULL
121961 +ptlrpc_prep_bulk_imp_32997 ptlrpc_prep_bulk_imp 2 32997 NULL
121962 +compat_filldir_32999 compat_filldir 3 32999 NULL
121963 +SyS_syslog_33007 SyS_syslog 3 33007 NULL
121964 +br_multicast_set_hash_max_33012 br_multicast_set_hash_max 2 33012 NULL
121965 +write_file_bt_ant_diversity_33019 write_file_bt_ant_diversity 3 33019 NULL
121966 +mic_virtio_copy_to_user_33048 mic_virtio_copy_to_user 3 33048 NULL
121967 +SYSC_lgetxattr_33049 SYSC_lgetxattr 4 33049 NULL
121968 +pipeline_dec_packet_in_fifo_full_read_33052 pipeline_dec_packet_in_fifo_full_read 3 33052 NULL
121969 +ebt_compat_match_offset_33053 ebt_compat_match_offset 0-2 33053 NULL
121970 +bitmap_resize_33054 bitmap_resize 2 33054 NULL
121971 +stats_dot11RTSSuccessCount_read_33065 stats_dot11RTSSuccessCount_read 3 33065 NULL
121972 +sel_read_checkreqprot_33068 sel_read_checkreqprot 3 33068 NULL
121973 +alloc_tio_33077 alloc_tio 3 33077 NULL
121974 +acl_permission_check_33083 acl_permission_check 0 33083 NULL
121975 +f2fs_llseek_33098 f2fs_llseek 2 33098 NULL
121976 +fb_sys_write_33130 fb_sys_write 3 33130 NULL
121977 +SyS_poll_33152 SyS_poll 2 33152 NULL
121978 +_pci_add_cap_save_buffer_33153 _pci_add_cap_save_buffer 4 33153 NULL
121979 +debug_debug6_read_33168 debug_debug6_read 3 33168 NULL
121980 +dataflash_read_fact_otp_33204 dataflash_read_fact_otp 3-2 33204 NULL
121981 +pp_read_33210 pp_read 3 33210 NULL
121982 +snd_pcm_plug_client_size_33267 snd_pcm_plug_client_size 0-2 33267 NULL
121983 +cachefiles_cook_key_33274 cachefiles_cook_key 2 33274 NULL
121984 +sync_pt_create_33282 sync_pt_create 2 33282 NULL
121985 +mcs7830_get_reg_33308 mcs7830_get_reg 3 33308 NULL
121986 +isku_sysfs_read_keys_easyzone_33318 isku_sysfs_read_keys_easyzone 6 33318 NULL
121987 +vx_send_irq_dsp_33329 vx_send_irq_dsp 0 33329 NULL
121988 +joydev_ioctl_33343 joydev_ioctl 2 33343 NULL
121989 +lov_stripesize_seq_write_33353 lov_stripesize_seq_write 3 33353 NULL
121990 +create_xattr_datum_33356 create_xattr_datum 5 33356 NULL nohasharray
121991 +irq_pkt_threshold_read_33356 irq_pkt_threshold_read 3 33356 &create_xattr_datum_33356
121992 +read_file_regidx_33370 read_file_regidx 3 33370 NULL
121993 +ieee80211_if_read_dropped_frames_no_route_33383 ieee80211_if_read_dropped_frames_no_route 3 33383 NULL
121994 +scsi_varlen_cdb_length_33385 scsi_varlen_cdb_length 0 33385 NULL
121995 +nvc0_ram_create__33391 nvc0_ram_create_ 5 33391 NULL
121996 +ocfs2_allocate_unwritten_extents_33394 ocfs2_allocate_unwritten_extents 3-2 33394 NULL
121997 +cfs_trace_copyin_string_33396 cfs_trace_copyin_string 4 33396 NULL
121998 +snd_pcm_capture_ioctl1_33408 snd_pcm_capture_ioctl1 0 33408 NULL
121999 +hash_netiface6_expire_33421 hash_netiface6_expire 4 33421 NULL
122000 +dis_tap_write_33426 dis_tap_write 3 33426 NULL
122001 +message_stats_list_33440 message_stats_list 5 33440 NULL
122002 +ovs_vport_alloc_33475 ovs_vport_alloc 1 33475 NULL
122003 +create_entry_33479 create_entry 2 33479 NULL
122004 +ip_setsockopt_33487 ip_setsockopt 5 33487 NULL
122005 +res_counter_read_33499 res_counter_read 4 33499 NULL
122006 +hash_netnet4_expire_33500 hash_netnet4_expire 4 33500 NULL
122007 +fb_read_33506 fb_read 3 33506 NULL
122008 +musb_test_mode_write_33518 musb_test_mode_write 3 33518 NULL
122009 +ahash_setkey_unaligned_33521 ahash_setkey_unaligned 3 33521 NULL
122010 +nes_alloc_fast_reg_page_list_33523 nes_alloc_fast_reg_page_list 2 33523 NULL
122011 +aggr_size_rx_size_read_33526 aggr_size_rx_size_read 3 33526 NULL
122012 +tomoyo_read_self_33539 tomoyo_read_self 3 33539 NULL nohasharray
122013 +osc_max_rpcs_in_flight_seq_write_33539 osc_max_rpcs_in_flight_seq_write 3 33539 &tomoyo_read_self_33539
122014 +count_subheaders_33591 count_subheaders 0 33591 NULL
122015 +scsi_execute_33596 scsi_execute 5 33596 NULL
122016 +comedi_buf_write_n_allocated_33604 comedi_buf_write_n_allocated 0 33604 NULL
122017 +xt_compat_target_offset_33608 xt_compat_target_offset 0 33608 NULL
122018 +il_dbgfs_qos_read_33615 il_dbgfs_qos_read 3 33615 NULL nohasharray
122019 +usb_gstrings_attach_33615 usb_gstrings_attach 3 33615 &il_dbgfs_qos_read_33615
122020 +stride_page_count_33641 stride_page_count 2 33641 NULL
122021 +irq_blk_threshold_read_33666 irq_blk_threshold_read 3 33666 NULL
122022 +inw_p_33668 inw_p 0 33668 NULL
122023 +arp_hdr_len_33671 arp_hdr_len 0 33671 NULL
122024 +i2c_hid_alloc_buffers_33673 i2c_hid_alloc_buffers 2 33673 NULL
122025 +nv50_disp_dmac_create__33696 nv50_disp_dmac_create_ 6 33696 NULL
122026 +netlink_sendmsg_33708 netlink_sendmsg 4 33708 NULL
122027 +tipc_link_stats_33716 tipc_link_stats 3 33716 NULL
122028 +pvr2_stream_buffer_count_33719 pvr2_stream_buffer_count 2 33719 NULL
122029 +write_file_spectral_count_33723 write_file_spectral_count 3 33723 NULL
122030 +read_file_node_recv_33729 read_file_node_recv 3 33729 NULL
122031 +__mutex_lock_interruptible_slowpath_33735 __mutex_lock_interruptible_slowpath 0 33735 NULL
122032 +vifs_state_read_33762 vifs_state_read 3 33762 NULL
122033 +hashtab_create_33769 hashtab_create 3 33769 NULL
122034 +__btrfs_free_reserved_extent_33782 __btrfs_free_reserved_extent 2 33782 NULL
122035 +if_sdio_read_rx_len_33800 if_sdio_read_rx_len 0 33800 NULL
122036 +filter_write_33819 filter_write 3 33819 NULL
122037 +sep_create_msgarea_context_33829 sep_create_msgarea_context 4 33829 NULL
122038 +scrub_setup_recheck_block_33831 scrub_setup_recheck_block 5-4 33831 NULL
122039 +ext4_journal_extend_33835 ext4_journal_extend 2 33835 NULL
122040 +oz_cdev_write_33852 oz_cdev_write 3 33852 NULL
122041 +azx_get_pos_posbuf_33867 azx_get_pos_posbuf 0 33867 NULL
122042 +get_user_pages_33908 get_user_pages 0 33908 NULL
122043 +sg_nents_33909 sg_nents 0 33909 NULL
122044 +ath6kl_roam_mode_write_33912 ath6kl_roam_mode_write 3 33912 NULL
122045 +queue_logical_block_size_33918 queue_logical_block_size 0 33918 NULL
122046 +sel_read_avc_cache_threshold_33942 sel_read_avc_cache_threshold 3 33942 NULL
122047 +lpfc_idiag_ctlacc_read_33943 lpfc_idiag_ctlacc_read 3 33943 NULL
122048 +read_file_tgt_rx_stats_33944 read_file_tgt_rx_stats 3 33944 NULL
122049 +rs_sta_dbgfs_drv_tx_stats_read_33946 rs_sta_dbgfs_drv_tx_stats_read 3 33946 NULL
122050 +__proc_dump_kernel_33954 __proc_dump_kernel 5 33954 NULL
122051 +vga_switcheroo_debugfs_write_33984 vga_switcheroo_debugfs_write 3 33984 NULL
122052 +lbs_lowrssi_write_34025 lbs_lowrssi_write 3 34025 NULL
122053 +ppp_write_34034 ppp_write 3 34034 NULL
122054 +tty_insert_flip_string_34042 tty_insert_flip_string 3-0 34042 NULL
122055 +bm_page_io_async_34050 bm_page_io_async 2 34050 NULL
122056 +calc_linear_pos_34067 calc_linear_pos 0-4 34067 NULL
122057 +memcg_update_all_caches_34068 memcg_update_all_caches 1 34068 NULL
122058 +pipeline_pipeline_fifo_full_read_34095 pipeline_pipeline_fifo_full_read 3 34095 NULL
122059 +__irq_domain_add_34101 __irq_domain_add 2 34101 NULL
122060 +proc_scsi_host_write_34107 proc_scsi_host_write 3 34107 NULL
122061 +islpci_mgt_transmit_34133 islpci_mgt_transmit 5 34133 NULL
122062 +ttm_dma_page_pool_free_34135 ttm_dma_page_pool_free 2-0 34135 NULL
122063 +ixgbe_dbg_netdev_ops_write_34141 ixgbe_dbg_netdev_ops_write 3 34141 NULL
122064 +shmem_pread_fast_34147 shmem_pread_fast 3 34147 NULL
122065 +skb_to_sgvec_34171 skb_to_sgvec 0 34171 NULL
122066 +rsi_debug_zone_write_34206 rsi_debug_zone_write 3 34206 NULL
122067 +ext4_da_write_begin_34215 ext4_da_write_begin 3-4 34215 NULL
122068 +bl_pipe_downcall_34264 bl_pipe_downcall 3 34264 NULL
122069 +device_private_init_34279 device_private_init 0 34279 NULL
122070 +xgmac_reg_addr_write_34284 xgmac_reg_addr_write 3 34284 NULL
122071 +ext4_get_groups_count_34324 ext4_get_groups_count 0 34324 NULL
122072 +pcpu_need_to_extend_34326 pcpu_need_to_extend 0 34326 NULL nohasharray
122073 +iov_iter_single_seg_count_34326 iov_iter_single_seg_count 0 34326 &pcpu_need_to_extend_34326
122074 +proc_thread_self_readlink_34357 proc_thread_self_readlink 3 34357 NULL
122075 +crypto_ablkcipher_ivsize_34363 crypto_ablkcipher_ivsize 0 34363 NULL nohasharray
122076 +sync_page_io_34363 sync_page_io 3 34363 &crypto_ablkcipher_ivsize_34363
122077 +rngapi_reset_34366 rngapi_reset 3 34366 NULL
122078 +ea_read_34378 ea_read 0 34378 NULL nohasharray
122079 +_iwl_dbgfs_low_latency_write_34378 _iwl_dbgfs_low_latency_write 3 34378 &ea_read_34378
122080 +fuse_send_read_34379 fuse_send_read 0-4 34379 NULL
122081 +av7110_vbi_write_34384 av7110_vbi_write 3 34384 NULL
122082 +usbvision_v4l2_read_34386 usbvision_v4l2_read 3 34386 NULL
122083 +read_rbu_image_type_34387 read_rbu_image_type 6 34387 NULL
122084 +ivtv_read_pos_34400 ivtv_read_pos 3 34400 NULL nohasharray
122085 +iwl_calib_set_34400 iwl_calib_set 3 34400 &ivtv_read_pos_34400
122086 +wd_exp_mode_write_34407 wd_exp_mode_write 3 34407 NULL
122087 +nl80211_send_disassoc_34424 nl80211_send_disassoc 4 34424 NULL
122088 +security_socket_create_34439 security_socket_create 0 34439 NULL
122089 +usbtest_alloc_urb_34446 usbtest_alloc_urb 3-5 34446 NULL
122090 +mwifiex_regrdwr_read_34472 mwifiex_regrdwr_read 3 34472 NULL
122091 +skcipher_sndbuf_34476 skcipher_sndbuf 0 34476 NULL
122092 +i2o_parm_field_get_34477 i2o_parm_field_get 5 34477 NULL
122093 +security_inode_permission_34488 security_inode_permission 0 34488 NULL
122094 +SyS_pwritev_34494 SyS_pwritev 3 34494 NULL
122095 +qp_alloc_res_34496 qp_alloc_res 5 34496 NULL
122096 +lu_buf_check_and_alloc_34505 lu_buf_check_and_alloc 2 34505 NULL
122097 +ext4_fallocate_34537 ext4_fallocate 4-3 34537 NULL nohasharray
122098 +tracing_stats_read_34537 tracing_stats_read 3 34537 &ext4_fallocate_34537
122099 +hugetlbfs_read_actor_34547 hugetlbfs_read_actor 2-5-4-0 34547 NULL
122100 +dbBackSplit_34561 dbBackSplit 0 34561 NULL
122101 +alloc_ieee80211_rsl_34564 alloc_ieee80211_rsl 1 34564 NULL
122102 +ext4_ind_direct_IO_34574 ext4_ind_direct_IO 4 34574 NULL
122103 +lov_stripecount_seq_write_34582 lov_stripecount_seq_write 3 34582 NULL
122104 +init_send_hfcd_34586 init_send_hfcd 1 34586 NULL
122105 +inet6_ifla6_size_34591 inet6_ifla6_size 0 34591 NULL
122106 +ceph_msgpool_init_34599 ceph_msgpool_init 4 34599 NULL nohasharray
122107 +cw1200_queue_init_34599 cw1200_queue_init 4 34599 &ceph_msgpool_init_34599
122108 +bio_integrity_bytes_34602 bio_integrity_bytes 2 34602 NULL
122109 +__jffs2_ref_totlen_34609 __jffs2_ref_totlen 0 34609 NULL
122110 +__cfg80211_disconnected_34622 __cfg80211_disconnected 3 34622 NULL
122111 +cnic_alloc_dma_34641 cnic_alloc_dma 3 34641 NULL
122112 +kvm_set_spte_hva_34671 kvm_set_spte_hva 2 34671 NULL
122113 +sleep_auth_write_34676 sleep_auth_write 3 34676 NULL
122114 +f2fs_direct_IO_34685 f2fs_direct_IO 4 34685 NULL
122115 +isr_fiqs_read_34687 isr_fiqs_read 3 34687 NULL
122116 +batadv_tvlv_realloc_packet_buff_34688 batadv_tvlv_realloc_packet_buff 3-4 34688 NULL
122117 +port_print_34704 port_print 3 34704 NULL
122118 +ieee80211_if_read_num_sta_ps_34722 ieee80211_if_read_num_sta_ps 3 34722 NULL
122119 +platform_list_read_file_34734 platform_list_read_file 3 34734 NULL
122120 +reg_w_ixbuf_34736 reg_w_ixbuf 4 34736 NULL
122121 +lsm_alloc_plain_34755 lsm_alloc_plain 1 34755 NULL
122122 +bootmode_store_34762 bootmode_store 4 34762 NULL
122123 +device_add_34766 device_add 0 34766 NULL
122124 +qib_cdev_init_34778 qib_cdev_init 1 34778 NULL
122125 +ext3_direct_IO_34798 ext3_direct_IO 4 34798 NULL
122126 +SYSC_keyctl_34800 SYSC_keyctl 4 34800 NULL
122127 +can_nocow_extent_34801 can_nocow_extent 2 34801 NULL
122128 +drbd_get_max_capacity_34804 drbd_get_max_capacity 0 34804 NULL
122129 +ll_setxattr_34806 ll_setxattr 4 34806 NULL
122130 +file_page_index_34820 file_page_index 0-2 34820 NULL
122131 +bio_segments_34832 bio_segments 0 34832 NULL
122132 +b43_debugfs_write_34838 b43_debugfs_write 3 34838 NULL
122133 +nl_portid_hash_zalloc_34843 nl_portid_hash_zalloc 1 34843 NULL
122134 +acpi_system_write_wakeup_device_34853 acpi_system_write_wakeup_device 3 34853 NULL
122135 +usb_serial_generic_prepare_write_buffer_34857 usb_serial_generic_prepare_write_buffer 3 34857 NULL
122136 +ieee80211_if_read_txpower_34871 ieee80211_if_read_txpower 3 34871 NULL
122137 +msg_print_text_34889 msg_print_text 0 34889 NULL
122138 +ieee80211_if_write_34894 ieee80211_if_write 3 34894 NULL
122139 +si476x_radio_read_rsq_primary_blob_34916 si476x_radio_read_rsq_primary_blob 3 34916 NULL
122140 +btrfs_super_chunk_root_34925 btrfs_super_chunk_root 0 34925 NULL nohasharray
122141 +__inode_permission_34925 __inode_permission 0 34925 &btrfs_super_chunk_root_34925
122142 +sec_flags2str_34933 sec_flags2str 3 34933 NULL
122143 +snd_info_entry_read_34938 snd_info_entry_read 3 34938 NULL
122144 +compat_SyS_kexec_load_34947 compat_SyS_kexec_load 2 34947 NULL
122145 +do_add_page_to_bio_34974 do_add_page_to_bio 2-10 34974 NULL
122146 +sdebug_change_qdepth_34994 sdebug_change_qdepth 2 34994 NULL
122147 +rx_rx_hdr_overflow_read_35002 rx_rx_hdr_overflow_read 3 35002 NULL
122148 +l2cap_skbuff_fromiovec_35003 l2cap_skbuff_fromiovec 4-3 35003 NULL
122149 +sisusb_copy_memory_35016 sisusb_copy_memory 4 35016 NULL
122150 +coda_psdev_read_35029 coda_psdev_read 3 35029 NULL
122151 +hwdep_read_locked_35037 hwdep_read_locked 3 35037 NULL
122152 +pwr_connection_out_of_sync_read_35061 pwr_connection_out_of_sync_read 3 35061 NULL
122153 +__kfifo_uint_must_check_helper_35097 __kfifo_uint_must_check_helper 0-1 35097 NULL
122154 +capi_write_35104 capi_write 3 35104 NULL nohasharray
122155 +tx_tx_done_template_read_35104 tx_tx_done_template_read 3 35104 &capi_write_35104
122156 +ide_settings_proc_write_35110 ide_settings_proc_write 3 35110 NULL
122157 +ceph_osdc_start_request_35122 ceph_osdc_start_request 0 35122 NULL
122158 +addrs_per_inode_35151 addrs_per_inode 0 35151 NULL
122159 +message_stats_print_35158 message_stats_print 6 35158 NULL
122160 +iscsi_conn_setup_35159 iscsi_conn_setup 2 35159 NULL
122161 +ieee80211_if_read_bssid_35161 ieee80211_if_read_bssid 3 35161 NULL
122162 +compat_SyS_pselect6_35203 compat_SyS_pselect6 1 35203 NULL
122163 +unix_stream_recvmsg_35210 unix_stream_recvmsg 4 35210 NULL
122164 +striped_read_35218 striped_read 0-2 35218 NULL nohasharray
122165 +security_key_getsecurity_35218 security_key_getsecurity 0 35218 &striped_read_35218
122166 +rx_rx_cmplt_task_read_35226 rx_rx_cmplt_task_read 3 35226 NULL
122167 +kimage_file_prepare_segments_35232 kimage_file_prepare_segments 5 35232 NULL
122168 +set_fd_set_35249 set_fd_set 1 35249 NULL
122169 +ioapic_setup_resources_35255 ioapic_setup_resources 1 35255 NULL
122170 +dis_disc_write_35265 dis_disc_write 3 35265 NULL
122171 +dma_show_regs_35266 dma_show_regs 3 35266 NULL
122172 +irda_recvmsg_stream_35280 irda_recvmsg_stream 4 35280 NULL
122173 +i2o_block_end_request_35282 i2o_block_end_request 3 35282 NULL
122174 +isr_rx_rdys_read_35283 isr_rx_rdys_read 3 35283 NULL
122175 +__btrfs_buffered_write_35311 __btrfs_buffered_write 3 35311 NULL nohasharray
122176 +brcmf_sdio_forensic_read_35311 brcmf_sdio_forensic_read 3 35311 &__btrfs_buffered_write_35311
122177 +tracing_read_pipe_35312 tracing_read_pipe 3 35312 NULL
122178 +sta_tx_latency_stat_write_35323 sta_tx_latency_stat_write 3 35323 NULL
122179 +ieee80211_if_fmt_ap_power_level_35347 ieee80211_if_fmt_ap_power_level 3 35347 NULL
122180 +nouveau_devinit_create__35348 nouveau_devinit_create_ 4 35348 NULL
122181 +ieee80211_rx_mgmt_deauth_35351 ieee80211_rx_mgmt_deauth 3 35351 NULL
122182 +compat_filldir64_35354 compat_filldir64 3 35354 NULL
122183 +read_kmem_35372 read_kmem 3 35372 NULL
122184 +SyS_getxattr_35408 SyS_getxattr 4 35408 NULL
122185 +rawv6_send_hdrinc_35425 rawv6_send_hdrinc 3 35425 NULL
122186 +iwl_dbgfs_drv_rx_stats_read_35430 iwl_dbgfs_drv_rx_stats_read 3 35430 NULL
122187 +buffer_to_user_35439 buffer_to_user 3 35439 NULL
122188 +efx_mcdi_rpc_async_quiet_35460 efx_mcdi_rpc_async_quiet 4-5 35460 NULL
122189 +macvtap_do_read_35475 macvtap_do_read 3 35475 NULL
122190 +fiemap_prepare_and_copy_exts_35494 fiemap_prepare_and_copy_exts 5 35494 NULL
122191 +btrfs_prealloc_file_range_trans_35500 btrfs_prealloc_file_range_trans 4 35500 NULL
122192 +async_setkey_35521 async_setkey 3 35521 NULL
122193 +__filemap_fdatawrite_range_35528 __filemap_fdatawrite_range 0 35528 NULL
122194 +iwl_dbgfs_bt_traffic_read_35534 iwl_dbgfs_bt_traffic_read 3 35534 NULL
122195 +pstore_mkfile_35536 pstore_mkfile 7 35536 NULL
122196 +rxpipe_tx_xfr_host_int_trig_rx_data_read_35538 rxpipe_tx_xfr_host_int_trig_rx_data_read 3 35538 NULL
122197 +ocfs2_write_zero_page_35539 ocfs2_write_zero_page 3 35539 NULL
122198 +ibnl_put_attr_35541 ibnl_put_attr 3 35541 NULL
122199 +ieee80211_if_write_smps_35550 ieee80211_if_write_smps 3 35550 NULL
122200 +C_SYSC_kexec_load_35565 C_SYSC_kexec_load 2 35565 NULL
122201 +ext4_blocks_for_truncate_35579 ext4_blocks_for_truncate 0 35579 NULL
122202 +ext2_acl_from_disk_35580 ext2_acl_from_disk 2 35580 NULL
122203 +spk_msg_set_35586 spk_msg_set 3 35586 NULL
122204 +kernel_readv_35617 kernel_readv 3 35617 NULL
122205 +reiserfs_readpages_35629 reiserfs_readpages 4 35629 NULL
122206 +ptlrpcd_steal_rqset_35637 ptlrpcd_steal_rqset 0 35637 NULL
122207 +spi_register_board_info_35651 spi_register_board_info 2 35651 NULL
122208 +rdmaltWithLock_35669 rdmaltWithLock 0 35669 NULL
122209 +SYSC_pwritev_35690 SYSC_pwritev 3 35690 NULL
122210 +rds_page_copy_user_35691 rds_page_copy_user 4 35691 NULL
122211 +md_super_write_35703 md_super_write 4 35703 NULL
122212 +iwl_dbgfs_disable_ht40_read_35761 iwl_dbgfs_disable_ht40_read 3 35761 NULL
122213 +udf_alloc_i_data_35786 udf_alloc_i_data 2 35786 NULL
122214 +alloc_netdev_mqs_35806 alloc_netdev_mqs 1 35806 NULL
122215 +pvr2_hdw_cpufw_get_35824 pvr2_hdw_cpufw_get 0-4-2 35824 NULL
122216 +tx_tx_cmplt_read_35854 tx_tx_cmplt_read 3 35854 NULL
122217 +vx_query_hbuffer_size_35859 vx_query_hbuffer_size 0 35859 NULL
122218 +mthca_buf_alloc_35861 mthca_buf_alloc 2 35861 NULL
122219 +kvm_dirty_bitmap_bytes_35886 kvm_dirty_bitmap_bytes 0 35886 NULL
122220 +ieee80211_if_fmt_dot11MeshRetryTimeout_35890 ieee80211_if_fmt_dot11MeshRetryTimeout 3 35890 NULL
122221 +uwb_rc_cmd_done_35892 uwb_rc_cmd_done 4 35892 NULL
122222 +kernel_setsockopt_35913 kernel_setsockopt 5 35913 NULL
122223 +rbio_nr_pages_35916 rbio_nr_pages 0-1-2 35916 NULL
122224 +sctp_tsnmap_mark_35929 sctp_tsnmap_mark 2 35929 NULL
122225 +rx_defrag_init_called_read_35935 rx_defrag_init_called_read 3 35935 NULL
122226 +put_cmsg_compat_35937 put_cmsg_compat 4 35937 NULL
122227 +generic_ocp_read_35974 generic_ocp_read 3 35974 NULL nohasharray
122228 +ceph_buffer_new_35974 ceph_buffer_new 1 35974 &generic_ocp_read_35974
122229 +acl_alloc_35979 acl_alloc 1 35979 NULL
122230 +device_add_class_symlinks_35985 device_add_class_symlinks 0 35985 NULL
122231 +write_file_antenna_35998 write_file_antenna 3 35998 NULL nohasharray
122232 +kuc_alloc_35998 kuc_alloc 1 35998 &write_file_antenna_35998
122233 +lov_mds_md_max_stripe_count_36008 lov_mds_md_max_stripe_count 0-1 36008 NULL
122234 +il3945_ucode_tx_stats_read_36016 il3945_ucode_tx_stats_read 3 36016 NULL
122235 +__videobuf_alloc_36031 __videobuf_alloc 1 36031 NULL
122236 +account_shadowed_36048 account_shadowed 2 36048 NULL
122237 +gpio_power_read_36059 gpio_power_read 3 36059 NULL
122238 +write_emulate_36065 write_emulate 2-4 36065 NULL
122239 +stack_max_size_write_36068 stack_max_size_write 3 36068 NULL
122240 +radeon_vm_num_pdes_36070 radeon_vm_num_pdes 0 36070 NULL
122241 +ieee80211_if_fmt_peer_36071 ieee80211_if_fmt_peer 3 36071 NULL
122242 +ieee80211_if_write_tsf_36077 ieee80211_if_write_tsf 3 36077 NULL
122243 +snd_pcm_plug_read_transfer_36080 snd_pcm_plug_read_transfer 0-3 36080 NULL
122244 +mtip_hw_read_device_status_36082 mtip_hw_read_device_status 3 36082 NULL
122245 +vga_arb_write_36112 vga_arb_write 3 36112 NULL
122246 +simple_xattr_alloc_36118 simple_xattr_alloc 2 36118 NULL
122247 +ext3_readpages_36144 ext3_readpages 4 36144 NULL
122248 +twl_set_36154 twl_set 2 36154 NULL
122249 +b1_alloc_card_36155 b1_alloc_card 1 36155 NULL
122250 +snd_korg1212_copy_from_36169 snd_korg1212_copy_from 6 36169 NULL
122251 +SyS_kexec_load_36176 SyS_kexec_load 2 36176 NULL
122252 +ramoops_init_przs_36199 ramoops_init_przs 4 36199 NULL
122253 +SYSC_sched_getaffinity_36208 SYSC_sched_getaffinity 2 36208 NULL
122254 +SYSC_process_vm_readv_36216 SYSC_process_vm_readv 3-5 36216 NULL
122255 +atomic_stats_read_36228 atomic_stats_read 3 36228 NULL
122256 +viafb_iga1_odev_proc_write_36241 viafb_iga1_odev_proc_write 3 36241 NULL
122257 +SYSC_getxattr_36242 SYSC_getxattr 4 36242 NULL
122258 +vmsplice_to_user_36245 vmsplice_to_user 3 36245 NULL nohasharray
122259 +rproc_recovery_read_36245 rproc_recovery_read 3 36245 &vmsplice_to_user_36245
122260 +cfs_hash_buckets_realloc_36276 cfs_hash_buckets_realloc 4 36276 NULL
122261 +codec_reg_read_file_36280 codec_reg_read_file 3 36280 NULL
122262 +crypto_shash_digestsize_36284 crypto_shash_digestsize 0 36284 NULL
122263 +lpfc_debugfs_dif_err_read_36303 lpfc_debugfs_dif_err_read 3 36303 NULL
122264 +cfg80211_rx_mlme_mgmt_36306 cfg80211_rx_mlme_mgmt 3 36306 NULL
122265 +ad7879_spi_xfer_36311 ad7879_spi_xfer 3 36311 NULL
122266 +fat_compat_ioctl_filldir_36328 fat_compat_ioctl_filldir 3 36328 NULL nohasharray
122267 +__compat_sys_pwritev64_36328 __compat_sys_pwritev64 3 36328 &fat_compat_ioctl_filldir_36328
122268 +lc_create_36332 lc_create 4 36332 NULL
122269 +jbd2_journal_init_revoke_table_36336 jbd2_journal_init_revoke_table 1 36336 NULL
122270 +isku_sysfs_read_key_mask_36343 isku_sysfs_read_key_mask 6 36343 NULL
122271 +ath6kl_regwrite_write_36351 ath6kl_regwrite_write 3 36351 NULL
122272 +v9fs_file_readn_36353 v9fs_file_readn 4 36353 NULL
122273 +to_sector_36361 to_sector 0-1 36361 NULL
122274 +tunables_read_36385 tunables_read 3 36385 NULL
122275 +afs_alloc_flat_call_36399 afs_alloc_flat_call 2-3 36399 NULL
122276 +sierra_write_36402 sierra_write 4 36402 NULL
122277 +SyS_sethostname_36417 SyS_sethostname 2 36417 NULL
122278 +soc_pcm_codec_params_fixup_36434 soc_pcm_codec_params_fixup 2 36434 NULL
122279 +ReadW6692B_36445 ReadW6692B 0 36445 NULL
122280 +sctp_tsnmap_init_36446 sctp_tsnmap_init 2 36446 NULL
122281 +alloc_etherdev_mqs_36450 alloc_etherdev_mqs 1 36450 NULL
122282 +SyS_process_vm_writev_36476 SyS_process_vm_writev 3-5 36476 NULL
122283 +b43_nphy_load_samples_36481 b43_nphy_load_samples 3 36481 NULL
122284 +ds1343_nvram_write_36489 ds1343_nvram_write 5-6 36489 NULL
122285 +tx_tx_checksum_result_read_36490 tx_tx_checksum_result_read 3 36490 NULL nohasharray
122286 +ip6_append_data_36490 ip6_append_data 4 36490 &tx_tx_checksum_result_read_36490
122287 +cmd_loop_36491 cmd_loop 0 36491 NULL
122288 +__hwahc_op_set_ptk_36510 __hwahc_op_set_ptk 5 36510 NULL
122289 +mcam_v4l_read_36513 mcam_v4l_read 3 36513 NULL
122290 +_iwl_dbgfs_fw_nmi_write_36515 _iwl_dbgfs_fw_nmi_write 3 36515 NULL
122291 +get_param_l_36518 get_param_l 0 36518 NULL
122292 +ieee80211_if_read_fwded_frames_36520 ieee80211_if_read_fwded_frames 3 36520 NULL
122293 +crypto_aead_authsize_36537 crypto_aead_authsize 0 36537 NULL
122294 +cpu_type_read_36540 cpu_type_read 3 36540 NULL
122295 +__kfifo_to_user_36555 __kfifo_to_user 3-0 36555 NULL
122296 +btrfs_get_token_64_36572 btrfs_get_token_64 0 36572 NULL
122297 +__erst_read_36579 __erst_read 0 36579 NULL
122298 +put_cmsg_36589 put_cmsg 4 36589 NULL
122299 +fat_ioctl_filldir_36621 fat_ioctl_filldir 3 36621 NULL
122300 +vxge_config_vpaths_36636 vxge_config_vpaths 0 36636 NULL
122301 +convert_extent_item_v0_36645 convert_extent_item_v0 4 36645 NULL
122302 +ced_ioctl_36647 ced_ioctl 2 36647 NULL
122303 +lpfc_idiag_extacc_alloc_get_36648 lpfc_idiag_extacc_alloc_get 0-3 36648 NULL
122304 +osd_req_list_collection_objects_36664 osd_req_list_collection_objects 5 36664 NULL
122305 +iscsi_host_alloc_36671 iscsi_host_alloc 2 36671 NULL
122306 +xillybus_read_36678 xillybus_read 3 36678 NULL
122307 +gsmtty_write_36702 gsmtty_write 3 36702 NULL
122308 +snd_rawmidi_kernel_read1_36740 snd_rawmidi_kernel_read1 4-0 36740 NULL
122309 +cxgbi_device_register_36746 cxgbi_device_register 1-2 36746 NULL
122310 +ps_poll_upsd_timeouts_read_36755 ps_poll_upsd_timeouts_read 3 36755 NULL
122311 +ptp_filter_init_36780 ptp_filter_init 2 36780 NULL
122312 +i40e_init_lan_hmc_36796 i40e_init_lan_hmc 5-4-3-2 36796 NULL
122313 +proc_fault_inject_read_36802 proc_fault_inject_read 3 36802 NULL
122314 +hiddev_ioctl_36816 hiddev_ioctl 2 36816 NULL
122315 +int_hardware_entry_36833 int_hardware_entry 3 36833 NULL
122316 +fc_change_queue_depth_36841 fc_change_queue_depth 2 36841 NULL
122317 +keyctl_describe_key_36853 keyctl_describe_key 3 36853 NULL
122318 +cm_write_36858 cm_write 3 36858 NULL
122319 +tipc_link_iovec_long_xmit_36871 tipc_link_iovec_long_xmit 3 36871 NULL nohasharray
122320 +tx_tx_data_programmed_read_36871 tx_tx_data_programmed_read 3 36871 &tipc_link_iovec_long_xmit_36871
122321 +svc_setsockopt_36876 svc_setsockopt 5 36876 NULL
122322 +raid56_parity_write_36877 raid56_parity_write 5 36877 NULL
122323 +__btrfs_map_block_36883 __btrfs_map_block 3 36883 NULL
122324 +ib_ucm_alloc_data_36885 ib_ucm_alloc_data 3 36885 NULL
122325 +selinux_inode_notifysecctx_36896 selinux_inode_notifysecctx 3 36896 NULL
122326 +il4965_rs_sta_dbgfs_scale_table_write_36979 il4965_rs_sta_dbgfs_scale_table_write 3 36979 NULL
122327 +drbd_new_dev_size_36998 drbd_new_dev_size 0-3 36998 NULL
122328 +auok190xfb_write_37001 auok190xfb_write 3 37001 NULL
122329 +setxattr_37006 setxattr 4 37006 NULL
122330 +ec_i2c_xfer_37029 ec_i2c_xfer 3 37029 NULL
122331 +ieee80211_chsw_switch_vifs_37030 ieee80211_chsw_switch_vifs 2 37030 NULL
122332 +command_file_read_37038 command_file_read 3 37038 NULL
122333 +figure_loop_size_37051 figure_loop_size 2-3 37051 NULL
122334 +qp_broker_create_37053 qp_broker_create 6-5 37053 NULL nohasharray
122335 +ieee80211_if_read_drop_unencrypted_37053 ieee80211_if_read_drop_unencrypted 3 37053 &qp_broker_create_37053
122336 +_iwl_dbgfs_bcast_filters_macs_write_37069 _iwl_dbgfs_bcast_filters_macs_write 3 37069 NULL
122337 +SYSC_setxattr_37078 SYSC_setxattr 4 37078 NULL
122338 +parse_command_37079 parse_command 2 37079 NULL
122339 +pipeline_cs_rx_packet_in_read_37089 pipeline_cs_rx_packet_in_read 3 37089 NULL
122340 +tun_get_user_37094 tun_get_user 5 37094 NULL
122341 +has_wrprotected_page_37123 has_wrprotected_page 3-2 37123 NULL
122342 +snd_hda_get_conn_list_37132 snd_hda_get_conn_list 0 37132 NULL
122343 +mtt_free_res_37144 mtt_free_res 5 37144 NULL
122344 +msg_word_37164 msg_word 0 37164 NULL
122345 +vcc_recvmsg_37198 vcc_recvmsg 4 37198 NULL
122346 +forced_ps_write_37209 forced_ps_write 3 37209 NULL
122347 +crypto_shash_descsize_37212 crypto_shash_descsize 0 37212 NULL
122348 +bchannel_get_rxbuf_37213 bchannel_get_rxbuf 2-0 37213 NULL
122349 +regmap_access_read_file_37223 regmap_access_read_file 3 37223 NULL
122350 +__do_replace_37227 __do_replace 5 37227 NULL
122351 +iwl_dbgfs_d3_sram_read_37237 iwl_dbgfs_d3_sram_read 3 37237 NULL
122352 +rx_filter_dup_filter_read_37238 rx_filter_dup_filter_read 3 37238 NULL nohasharray
122353 +__btrfs_inc_extent_ref_37238 __btrfs_inc_extent_ref 7 37238 &rx_filter_dup_filter_read_37238
122354 +exofs_max_io_pages_37263 exofs_max_io_pages 0-2 37263 NULL
122355 +_iwl_dbgfs_fw_restart_write_37270 _iwl_dbgfs_fw_restart_write 3 37270 NULL
122356 +ieee80211_if_read_power_mode_37305 ieee80211_if_read_power_mode 3 37305 NULL
122357 +jffs2_write_dirent_37311 jffs2_write_dirent 5 37311 NULL
122358 +tipc_send_37315 tipc_send 3 37315 NULL
122359 +l2cap_create_connless_pdu_37327 l2cap_create_connless_pdu 3 37327 NULL nohasharray
122360 +bnx2x_vf_fill_fw_str_37327 bnx2x_vf_fill_fw_str 3 37327 &l2cap_create_connless_pdu_37327
122361 +scsi_mode_select_37330 scsi_mode_select 6 37330 NULL
122362 +rxrpc_server_sendmsg_37331 rxrpc_server_sendmsg 4 37331 NULL
122363 +security_inode_getsecurity_37354 security_inode_getsecurity 0 37354 NULL
122364 +seek_firmware_37372 seek_firmware 2 37372 NULL
122365 +hci_sock_sendmsg_37420 hci_sock_sendmsg 4 37420 NULL
122366 +acpi_os_allocate_zeroed_37422 acpi_os_allocate_zeroed 1 37422 NULL
122367 +tty_insert_flip_string_fixed_flag_37428 tty_insert_flip_string_fixed_flag 4-0 37428 NULL
122368 +iwl_print_last_event_logs_37433 iwl_print_last_event_logs 0-7-9 37433 NULL
122369 +fru_alloc_37442 fru_alloc 1 37442 NULL
122370 +tcp_established_options_37450 tcp_established_options 0 37450 NULL
122371 +brcmf_sdio_dump_console_37455 brcmf_sdio_dump_console 4 37455 NULL
122372 +get_est_timing_37484 get_est_timing 0 37484 NULL
122373 +kmem_realloc_37489 kmem_realloc 2 37489 NULL
122374 +bitmap_dirty_bits_37503 bitmap_dirty_bits 2 37503 NULL
122375 +osc_active_seq_write_37514 osc_active_seq_write 3 37514 NULL
122376 +bdev_writeseg_37519 bdev_writeseg 2-3 37519 NULL
122377 +xz_dec_test_write_37527 xz_dec_test_write 3 37527 NULL
122378 +fault_inject_read_37534 fault_inject_read 3 37534 NULL
122379 +hdr_size_37536 hdr_size 0 37536 NULL
122380 +extent_map_end_37550 extent_map_end 0 37550 NULL
122381 +sep_create_dcb_dmatables_context_37551 sep_create_dcb_dmatables_context 6 37551 NULL
122382 +xhci_alloc_streams_37586 xhci_alloc_streams 5 37586 NULL
122383 +qla2x00_debounce_register_37597 qla2x00_debounce_register 0 37597 NULL
122384 +kvm_read_guest_page_mmu_37611 kvm_read_guest_page_mmu 6 37611 NULL
122385 +SYSC_mbind_37622 SYSC_mbind 5 37622 NULL
122386 +SyS_mbind_37638 SyS_mbind 5 37638 NULL
122387 +bio_copy_user_iov_37660 bio_copy_user_iov 4 37660 NULL
122388 +vmw_framebuffer_dmabuf_dirty_37661 vmw_framebuffer_dmabuf_dirty 6 37661 NULL nohasharray
122389 +rfcomm_sock_sendmsg_37661 rfcomm_sock_sendmsg 4 37661 &vmw_framebuffer_dmabuf_dirty_37661
122390 +SYSC_get_mempolicy_37664 SYSC_get_mempolicy 3 37664 NULL
122391 +__wa_seg_calculate_isoc_frame_count_37672 __wa_seg_calculate_isoc_frame_count 0 37672 NULL
122392 +ieee80211_if_read_rc_rateidx_mcs_mask_2ghz_37675 ieee80211_if_read_rc_rateidx_mcs_mask_2ghz 3 37675 NULL
122393 +tracing_saved_cmdlines_size_write_37684 tracing_saved_cmdlines_size_write 3 37684 NULL
122394 +regmap_map_read_file_37685 regmap_map_read_file 3 37685 NULL
122395 +nametbl_header_37698 nametbl_header 2-0 37698 NULL
122396 +__le32_to_cpup_37702 __le32_to_cpup 0 37702 NULL
122397 +dynamic_ps_timeout_write_37713 dynamic_ps_timeout_write 3 37713 NULL
122398 +read_enabled_file_bool_37744 read_enabled_file_bool 3 37744 NULL
122399 +ocfs2_control_cfu_37750 ocfs2_control_cfu 2 37750 NULL
122400 +ipath_cdev_init_37752 ipath_cdev_init 1 37752 NULL
122401 +dccp_setsockopt_cscov_37766 dccp_setsockopt_cscov 2 37766 NULL
122402 +il4965_rs_sta_dbgfs_rate_scale_data_read_37792 il4965_rs_sta_dbgfs_rate_scale_data_read 3 37792 NULL
122403 +smk_read_logging_37804 smk_read_logging 3 37804 NULL
122404 +nvkm_notify_init_37806 nvkm_notify_init 6 37806 NULL
122405 +ocrdma_alloc_frmr_page_list_37815 ocrdma_alloc_frmr_page_list 2 37815 NULL
122406 +rx_decrypt_key_not_found_read_37820 rx_decrypt_key_not_found_read 3 37820 NULL
122407 +android_get_p2p_addr_37832 android_get_p2p_addr 0 37832 NULL
122408 +o2hb_debug_read_37851 o2hb_debug_read 3 37851 NULL
122409 +xfs_dir2_block_to_sf_37868 xfs_dir2_block_to_sf 3 37868 NULL
122410 +btrfs_leaf_data_37869 btrfs_leaf_data 0 37869 NULL
122411 +btrfs_stack_file_extent_disk_bytenr_37888 btrfs_stack_file_extent_disk_bytenr 0 37888 NULL
122412 +_rtw_malloc_37928 _rtw_malloc 1 37928 NULL nohasharray
122413 +pkt_alloc_packet_data_37928 pkt_alloc_packet_data 1 37928 &_rtw_malloc_37928
122414 +read_rbu_packet_size_37939 read_rbu_packet_size 6 37939 NULL
122415 +write_file_bool_37957 write_file_bool 3 37957 NULL
122416 +fifo_alloc_37961 fifo_alloc 1 37961 NULL
122417 +rds_rdma_extra_size_37990 rds_rdma_extra_size 0 37990 NULL
122418 +persistent_ram_old_size_37997 persistent_ram_old_size 0 37997 NULL
122419 +vfs_readv_38011 vfs_readv 3 38011 NULL
122420 +aggr_recv_addba_req_evt_38037 aggr_recv_addba_req_evt 4 38037 NULL
122421 +il_dbgfs_chain_noise_read_38044 il_dbgfs_chain_noise_read 3 38044 NULL nohasharray
122422 +klsi_105_prepare_write_buffer_38044 klsi_105_prepare_write_buffer 3 38044 &il_dbgfs_chain_noise_read_38044
122423 +parser_init_guts_38046 parser_init_guts 2 38046 NULL
122424 +SyS_llistxattr_38048 SyS_llistxattr 3 38048 NULL
122425 +sysfs_do_create_link_38051 sysfs_do_create_link 0 38051 NULL
122426 +_xfs_buf_alloc_38058 _xfs_buf_alloc 3 38058 NULL
122427 +nsm_create_handle_38060 nsm_create_handle 4 38060 NULL
122428 +alloc_ltalkdev_38071 alloc_ltalkdev 1 38071 NULL
122429 +cifs_send_async_read_38077 cifs_send_async_read 2 38077 NULL
122430 +xfs_buf_readahead_map_38081 xfs_buf_readahead_map 3 38081 NULL
122431 +uwb_mac_addr_print_38085 uwb_mac_addr_print 2 38085 NULL
122432 +request_key_auth_new_38092 request_key_auth_new 3 38092 NULL
122433 +proc_self_readlink_38094 proc_self_readlink 3 38094 NULL
122434 +ep0_read_38095 ep0_read 3 38095 NULL
122435 +osc_checksum_seq_write_38096 osc_checksum_seq_write 3 38096 NULL nohasharray
122436 +sk_wmem_schedule_38096 sk_wmem_schedule 2 38096 &osc_checksum_seq_write_38096
122437 +o2hb_read_slots_38105 o2hb_read_slots 2 38105 NULL
122438 +snd_pcm_oss_write_38108 snd_pcm_oss_write 3 38108 NULL
122439 +vmw_kms_present_38130 vmw_kms_present 9 38130 NULL
122440 +__ntfs_copy_from_user_iovec_inatomic_38153 __ntfs_copy_from_user_iovec_inatomic 3-4-0 38153 NULL
122441 +btrfs_extent_same_38163 btrfs_extent_same 3-2-5 38163 NULL
122442 +kvm_clear_guest_38164 kvm_clear_guest 3-2 38164 NULL
122443 +cdev_add_38176 cdev_add 2-3 38176 NULL
122444 +rt2x00debug_write_rf_38195 rt2x00debug_write_rf 3 38195 NULL
122445 +get_ucode_user_38202 get_ucode_user 3 38202 NULL
122446 +osd_req_list_partition_collections_38223 osd_req_list_partition_collections 5 38223 NULL
122447 +ceph_decode_16_38239 ceph_decode_16 0 38239 NULL
122448 +_ipw_read_reg32_38245 _ipw_read_reg32 0 38245 NULL
122449 +nvkm_dmaobj_create__38250 nvkm_dmaobj_create_ 6 38250 NULL
122450 +mthca_alloc_icm_table_38268 mthca_alloc_icm_table 4-3 38268 NULL nohasharray
122451 +ieee80211_if_read_auto_open_plinks_38268 ieee80211_if_read_auto_open_plinks 3 38268 &mthca_alloc_icm_table_38268 nohasharray
122452 +SYSC_msgrcv_38268 SYSC_msgrcv 3 38268 &ieee80211_if_read_auto_open_plinks_38268
122453 +xfs_bmbt_to_bmdr_38275 xfs_bmbt_to_bmdr 3 38275 NULL nohasharray
122454 +xfs_bmdr_to_bmbt_38275 xfs_bmdr_to_bmbt 5 38275 &xfs_bmbt_to_bmdr_38275
122455 +ftdi_process_packet_38281 ftdi_process_packet 4 38281 NULL
122456 +C_SYSC_pselect6_38296 C_SYSC_pselect6 1 38296 NULL
122457 +ucma_query_path_38305 ucma_query_path 3 38305 NULL
122458 +isr_rx_headers_read_38325 isr_rx_headers_read 3 38325 NULL
122459 +ida_simple_get_38326 ida_simple_get 0 38326 NULL
122460 +__snd_gf1_look8_38333 __snd_gf1_look8 0 38333 NULL
122461 +usb_ext_prop_put_name_38352 usb_ext_prop_put_name 0-3 38352 NULL
122462 +btrfs_file_extent_disk_num_bytes_38363 btrfs_file_extent_disk_num_bytes 0 38363 NULL
122463 +xfs_free_file_space_38383 xfs_free_file_space 2-3 38383 NULL
122464 +dn_sendmsg_38390 dn_sendmsg 4 38390 NULL
122465 +ieee80211_if_read_dtim_count_38419 ieee80211_if_read_dtim_count 3 38419 NULL
122466 +pmcraid_copy_sglist_38431 pmcraid_copy_sglist 3 38431 NULL
122467 +iov_iter_npages_iovec_38448 iov_iter_npages_iovec 0-2 38448 NULL
122468 +kvm_write_guest_38454 kvm_write_guest 4-2 38454 NULL
122469 +videobuf_waiton_38459 videobuf_waiton 0 38459 NULL
122470 +_iwl_dbgfs_scan_ant_rxchain_write_38479 _iwl_dbgfs_scan_ant_rxchain_write 3 38479 NULL
122471 +blk_end_bidi_request_38482 blk_end_bidi_request 3-4 38482 NULL
122472 +dev_names_read_38509 dev_names_read 3 38509 NULL
122473 +iscsi_create_iface_38510 iscsi_create_iface 5 38510 NULL
122474 +event_rx_mismatch_read_38518 event_rx_mismatch_read 3 38518 NULL
122475 +ubifs_idx_node_sz_38546 ubifs_idx_node_sz 0-2 38546 NULL
122476 +btrfs_discard_extent_38547 btrfs_discard_extent 2 38547 NULL
122477 +kuc_len_38557 kuc_len 0-1 38557 NULL
122478 +irda_sendmsg_dgram_38563 irda_sendmsg_dgram 4 38563 NULL
122479 +il4965_rs_sta_dbgfs_scale_table_read_38564 il4965_rs_sta_dbgfs_scale_table_read 3 38564 NULL
122480 +_ipw_read32_38565 _ipw_read32 0 38565 NULL
122481 +snd_nm256_playback_copy_38567 snd_nm256_playback_copy 5-3 38567 NULL
122482 +copy_ctl_value_to_user_38587 copy_ctl_value_to_user 4 38587 NULL
122483 +rd_allocate_sgl_table_38607 rd_allocate_sgl_table 3 38607 NULL
122484 +icn_writecmd_38629 icn_writecmd 2 38629 NULL
122485 +write_enabled_file_bool_38630 write_enabled_file_bool 3 38630 NULL
122486 +ext2_readpages_38640 ext2_readpages 4 38640 NULL
122487 +audit_init_entry_38644 audit_init_entry 1 38644 NULL
122488 +qp_broker_alloc_38646 qp_broker_alloc 6-5 38646 NULL
122489 +mmc_send_cxd_data_38655 mmc_send_cxd_data 5 38655 NULL
122490 +nouveau_instmem_create__38664 nouveau_instmem_create_ 4 38664 NULL
122491 +ufshcd_read_sdev_qdepth_38676 ufshcd_read_sdev_qdepth 0 38676 NULL
122492 +iscsit_dump_data_payload_38683 iscsit_dump_data_payload 2 38683 NULL
122493 +tracing_nsecs_read_38689 tracing_nsecs_read 3 38689 NULL
122494 +rbio_add_io_page_38700 rbio_add_io_page 6 38700 NULL
122495 +w83977af_sir_interrupt_38738 w83977af_sir_interrupt 0 38738 NULL
122496 +udf_readpages_38761 udf_readpages 4 38761 NULL
122497 +iwl_dbgfs_thermal_throttling_read_38779 iwl_dbgfs_thermal_throttling_read 3 38779 NULL
122498 +bcache_device_init_38781 bcache_device_init 3 38781 NULL
122499 +snd_gus_dram_write_38784 snd_gus_dram_write 4 38784 NULL
122500 +do_pci_enable_device_38802 do_pci_enable_device 0 38802 NULL
122501 +err_decode_38804 err_decode 2 38804 NULL
122502 +ipv6_renew_option_38813 ipv6_renew_option 3 38813 NULL
122503 +direct_entry_38836 direct_entry 3 38836 NULL
122504 +compat_udp_setsockopt_38840 compat_udp_setsockopt 5 38840 NULL
122505 +interfaces_38859 interfaces 2 38859 NULL
122506 +dbgfs_state_38894 dbgfs_state 3 38894 NULL
122507 +il_dbgfs_sram_write_38942 il_dbgfs_sram_write 3 38942 NULL
122508 +__ath6kl_wmi_send_mgmt_cmd_38971 __ath6kl_wmi_send_mgmt_cmd 7 38971 NULL
122509 +usb_maxpacket_38977 usb_maxpacket 0 38977 NULL nohasharray
122510 +C_SYSC_preadv64_38977 C_SYSC_preadv64 3 38977 &usb_maxpacket_38977
122511 +OSDSetBlock_38986 OSDSetBlock 2-4 38986 NULL
122512 +bio_clone_range_38997 bio_clone_range 2 38997 NULL
122513 +lpfc_idiag_extacc_write_38998 lpfc_idiag_extacc_write 3 38998 NULL
122514 +get_nodes_39012 get_nodes 3 39012 NULL
122515 +twl6030_interrupt_unmask_39013 twl6030_interrupt_unmask 2 39013 NULL
122516 +force_sc_support_read_39014 force_sc_support_read 3 39014 NULL
122517 +__blkdev_issue_zeroout_39020 __blkdev_issue_zeroout 3 39020 NULL
122518 +_zd_iowrite32v_async_locked_39034 _zd_iowrite32v_async_locked 3 39034 NULL
122519 +do_write_kmem_39051 do_write_kmem 0-1-3 39051 NULL
122520 +tomoyo_truncate_39105 tomoyo_truncate 0 39105 NULL
122521 +__kfifo_to_user_r_39123 __kfifo_to_user_r 5-3 39123 NULL
122522 +ea_foreach_39133 ea_foreach 0 39133 NULL
122523 +generic_permission_39150 generic_permission 0 39150 NULL
122524 +proc_coredump_filter_read_39153 proc_coredump_filter_read 3 39153 NULL
122525 +ath9k_hw_ar9003_dump_eeprom_39156 ath9k_hw_ar9003_dump_eeprom 5-4 39156 NULL
122526 +echo_client_kbrw_39170 echo_client_kbrw 6 39170 NULL
122527 +ext3_xattr_check_names_39174 ext3_xattr_check_names 0 39174 NULL
122528 +ubi_more_update_data_39189 ubi_more_update_data 4 39189 NULL
122529 +qcam_read_bytes_39205 qcam_read_bytes 0 39205 NULL
122530 +ivtv_v4l2_write_39226 ivtv_v4l2_write 3 39226 NULL
122531 +SyS_getrandom_39235 SyS_getrandom 2 39235 NULL
122532 +posix_acl_to_xattr_39237 posix_acl_to_xattr 0 39237 NULL
122533 +snd_pcm_capture_forward_39248 snd_pcm_capture_forward 2 39248 NULL
122534 +r128_compat_ioctl_39250 r128_compat_ioctl 2 39250 NULL nohasharray
122535 +pwr_cont_miss_bcns_spread_read_39250 pwr_cont_miss_bcns_spread_read 3 39250 &r128_compat_ioctl_39250
122536 +i915_error_state_read_39254 i915_error_state_read 3 39254 NULL
122537 +rx_filter_protection_filter_read_39282 rx_filter_protection_filter_read 3 39282 NULL
122538 +_iwl_dbgfs_pm_params_write_39325 _iwl_dbgfs_pm_params_write 3 39325 NULL
122539 +__cfg80211_connect_result_39326 __cfg80211_connect_result 4-6 39326 NULL
122540 +insert_reserved_file_extent_39327 insert_reserved_file_extent 3 39327 NULL
122541 +wimax_msg_alloc_39343 wimax_msg_alloc 4 39343 NULL
122542 +ide_complete_rq_39354 ide_complete_rq 3 39354 NULL
122543 +do_write_log_from_user_39362 do_write_log_from_user 3-0 39362 NULL
122544 +vortex_wtdma_getlinearpos_39371 vortex_wtdma_getlinearpos 0 39371 NULL
122545 +regmap_name_read_file_39379 regmap_name_read_file 3 39379 NULL
122546 +fnic_trace_debugfs_read_39380 fnic_trace_debugfs_read 3 39380 NULL
122547 +ps_poll_ps_poll_utilization_read_39383 ps_poll_ps_poll_utilization_read 3 39383 NULL
122548 +__send_to_port_39386 __send_to_port 3 39386 NULL
122549 +user_power_read_39414 user_power_read 3 39414 NULL
122550 +hash_ipmark4_expire_39419 hash_ipmark4_expire 4 39419 NULL
122551 +alloc_agpphysmem_i8xx_39427 alloc_agpphysmem_i8xx 1 39427 NULL
122552 +mic_desc_size_39464 mic_desc_size 0 39464 NULL
122553 +setkey_unaligned_39474 setkey_unaligned 3 39474 NULL
122554 +usif_ioctl_39481 usif_ioctl 3 39481 NULL
122555 +ieee80211_if_fmt_dot11MeshHWMPmaxPREQretries_39499 ieee80211_if_fmt_dot11MeshHWMPmaxPREQretries 3 39499 NULL
122556 +cl_req_alloc_39523 cl_req_alloc 4 39523 NULL
122557 +int_proc_write_39542 int_proc_write 3 39542 NULL
122558 +pp_write_39554 pp_write 3 39554 NULL
122559 +datablob_format_39571 datablob_format 2 39571 NULL nohasharray
122560 +ieee80211_if_read_fwded_mcast_39571 ieee80211_if_read_fwded_mcast 3 39571 &datablob_format_39571
122561 +memblock_virt_alloc_internal_39600 memblock_virt_alloc_internal 1 39600 NULL
122562 +ext_depth_39607 ext_depth 0 39607 NULL
122563 +batadv_tt_tvlv_generate_39615 batadv_tt_tvlv_generate 4 39615 NULL
122564 +nfs_idmap_get_key_39616 nfs_idmap_get_key 2 39616 NULL
122565 +sdio_readb_39618 sdio_readb 0 39618 NULL
122566 +set_dev_class_39645 set_dev_class 4 39645 NULL
122567 +snd_rme32_capture_copy_39653 snd_rme32_capture_copy 5 39653 NULL
122568 +tcp_try_rmem_schedule_39657 tcp_try_rmem_schedule 3 39657 NULL
122569 +kvm_read_guest_cached_39666 kvm_read_guest_cached 4 39666 NULL
122570 +v4l_stk_read_39672 v4l_stk_read 3 39672 NULL
122571 +hsc_msg_len_get_39673 hsc_msg_len_get 0 39673 NULL
122572 +do_surface_dirty_sou_39678 do_surface_dirty_sou 7 39678 NULL
122573 +ftrace_pid_write_39710 ftrace_pid_write 3 39710 NULL
122574 +adt7316_spi_multi_read_39765 adt7316_spi_multi_read 3 39765 NULL
122575 +security_inode_listsecurity_39812 security_inode_listsecurity 0 39812 NULL
122576 +snd_pcm_oss_writev3_39818 snd_pcm_oss_writev3 3 39818 NULL
122577 +get_priv_size_39828 get_priv_size 0-1 39828 NULL
122578 +netlbl_catmap_walkrng_39885 netlbl_catmap_walkrng 0-2 39885 NULL
122579 +pkt_add_39897 pkt_add 3 39897 NULL
122580 +read_file_modal_eeprom_39909 read_file_modal_eeprom 3 39909 NULL
122581 +gen_pool_add_virt_39913 gen_pool_add_virt 4 39913 NULL
122582 +dw210x_op_rw_39915 dw210x_op_rw 6 39915 NULL
122583 +aes_encrypt_interrupt_read_39919 aes_encrypt_interrupt_read 3 39919 NULL
122584 +oom_score_adj_read_39921 oom_score_adj_read 3 39921 NULL nohasharray
122585 +exofs_read_kern_39921 exofs_read_kern 6 39921 &oom_score_adj_read_39921
122586 +__spi_async_39932 __spi_async 0 39932 NULL
122587 +__get_order_39935 __get_order 0 39935 NULL
122588 +error_error_frame_read_39947 error_error_frame_read 3 39947 NULL
122589 +tty_prepare_flip_string_39955 tty_prepare_flip_string 3-0 39955 NULL
122590 +lstcon_group_list_39958 lstcon_group_list 2 39958 NULL
122591 +bio_chain_clone_range_39967 bio_chain_clone_range 3 39967 NULL
122592 +dma_push_rx_39973 dma_push_rx 2 39973 NULL
122593 +broadsheetfb_write_39976 broadsheetfb_write 3 39976 NULL
122594 +lustre_pack_reply_v2_39978 lustre_pack_reply_v2 2 39978 NULL
122595 +mthca_array_init_39987 mthca_array_init 2 39987 NULL
122596 +fw_device_op_read_39990 fw_device_op_read 3 39990 NULL
122597 +server_name2svname_39998 server_name2svname 4 39998 NULL
122598 +xen_hvm_config_40018 xen_hvm_config 2 40018 NULL
122599 +ivtvfb_write_40023 ivtvfb_write 3 40023 NULL
122600 +disc_pwup_write_40027 disc_pwup_write 3 40027 NULL
122601 +ea_foreach_i_40028 ea_foreach_i 0 40028 NULL
122602 +datablob_hmac_append_40038 datablob_hmac_append 3 40038 NULL
122603 +l2cap_create_iframe_pdu_40055 l2cap_create_iframe_pdu 3 40055 NULL nohasharray
122604 +add_tty_40055 add_tty 1 40055 &l2cap_create_iframe_pdu_40055
122605 +atomic_xchg_40070 atomic_xchg 0 40070 NULL
122606 +sctp_setsockopt_delayed_ack_40129 sctp_setsockopt_delayed_ack 3 40129 NULL
122607 +dwc2_max_desc_num_40132 dwc2_max_desc_num 0 40132 NULL
122608 +rx_rx_frame_checksum_read_40140 rx_rx_frame_checksum_read 3 40140 NULL
122609 +ath10k_write_simulate_fw_crash_40143 ath10k_write_simulate_fw_crash 3 40143 NULL
122610 +iwch_alloc_fastreg_pbl_40153 iwch_alloc_fastreg_pbl 2 40153 NULL
122611 +pt_write_40159 pt_write 3 40159 NULL
122612 +scsi_sg_count_40182 scsi_sg_count 0 40182 NULL
122613 +ipr_alloc_ucode_buffer_40199 ipr_alloc_ucode_buffer 1 40199 NULL
122614 +allocate_probes_40204 allocate_probes 1 40204 NULL
122615 +au0828_v4l2_read_40220 au0828_v4l2_read 3 40220 NULL
122616 +compress_file_range_40225 compress_file_range 3-4 40225 NULL
122617 +ocrdma_dbgfs_ops_read_40232 ocrdma_dbgfs_ops_read 3 40232 NULL
122618 +osst_read_40237 osst_read 3 40237 NULL
122619 +lpage_info_slot_40243 lpage_info_slot 1-3 40243 NULL
122620 +ocfs2_zero_extend_get_range_40248 ocfs2_zero_extend_get_range 4-3 40248 NULL
122621 +of_get_child_count_40254 of_get_child_count 0 40254 NULL nohasharray
122622 +fsl_edma_prep_dma_cyclic_40254 fsl_edma_prep_dma_cyclic 3-4 40254 &of_get_child_count_40254
122623 +rs_sta_dbgfs_scale_table_read_40262 rs_sta_dbgfs_scale_table_read 3 40262 NULL
122624 +ext2_fiemap_40271 ext2_fiemap 4 40271 NULL
122625 +usbnet_read_cmd_40275 usbnet_read_cmd 7 40275 NULL
122626 +rx_xfr_hint_trig_read_40283 rx_xfr_hint_trig_read 3 40283 NULL
122627 +tracing_thresh_read_40295 tracing_thresh_read 3 40295 NULL
122628 +SyS_bind_40303 SyS_bind 3 40303 NULL
122629 +ib_get_mad_data_offset_40336 ib_get_mad_data_offset 0 40336 NULL
122630 +mmio_read_40348 mmio_read 4 40348 NULL
122631 +event_rx_mem_empty_read_40363 event_rx_mem_empty_read 3 40363 NULL
122632 +ocfs2_check_range_for_refcount_40365 ocfs2_check_range_for_refcount 3-2 40365 NULL
122633 +get_chars_40373 get_chars 3 40373 NULL
122634 +fb_prepare_extra_logos_40429 fb_prepare_extra_logos 0-2 40429 NULL
122635 +proc_write_driver_40432 proc_write_driver 3 40432 NULL
122636 +tomoyo_update_policy_40458 tomoyo_update_policy 2 40458 NULL
122637 +zd_usb_scnprint_id_40459 zd_usb_scnprint_id 0-3 40459 NULL
122638 +gp2ap020a00f_write_event_threshold_40461 gp2ap020a00f_write_event_threshold 2 40461 NULL
122639 +SyS_writev_40467 SyS_writev 3 40467 NULL
122640 +SyS_select_40473 SyS_select 1 40473 NULL
122641 +afs_fs_store_data_40484 afs_fs_store_data 3-4-5-6 40484 NULL
122642 +batadv_hash_new_40491 batadv_hash_new 1 40491 NULL
122643 +devcgroup_inode_permission_40492 devcgroup_inode_permission 0 40492 NULL
122644 +__ethtool_get_sset_count_40511 __ethtool_get_sset_count 0 40511 NULL
122645 +TSS_checkhmac2_40520 TSS_checkhmac2 5-7 40520 NULL
122646 +ixgbe_dbg_reg_ops_read_40540 ixgbe_dbg_reg_ops_read 3 40540 NULL
122647 +ima_write_policy_40548 ima_write_policy 3 40548 NULL
122648 +esp_alloc_tmp_40558 esp_alloc_tmp 3-2 40558 NULL
122649 +get_priv_descr_and_size_40612 get_priv_descr_and_size 0 40612 NULL
122650 +twl4030_kpwrite_u8_40665 twl4030_kpwrite_u8 3 40665 NULL
122651 +__cfg80211_roamed_40668 __cfg80211_roamed 4-6 40668 NULL
122652 +pipeline_rx_complete_stat_fifo_int_read_40671 pipeline_rx_complete_stat_fifo_int_read 3 40671 NULL
122653 +fops_read_40672 fops_read 3 40672 NULL
122654 +idr_get_empty_slot_40674 idr_get_empty_slot 0 40674 NULL
122655 +alloc_rbio_40676 alloc_rbio 4 40676 NULL
122656 +videobuf_dma_init_user_locked_40678 videobuf_dma_init_user_locked 4-3 40678 NULL
122657 +pci_enable_resources_40680 pci_enable_resources 0 40680 NULL
122658 +nfc_hci_set_param_40697 nfc_hci_set_param 5 40697 NULL
122659 +__seq_open_private_40715 __seq_open_private 3 40715 NULL
122660 +lnet_new_text_buf_40717 lnet_new_text_buf 1 40717 NULL
122661 +ip_skb_dst_mtu_40718 ip_skb_dst_mtu 0 40718 NULL
122662 +of_pdt_build_one_prop_40735 of_pdt_build_one_prop 5 40735 NULL
122663 +fuse_readpages_40737 fuse_readpages 4 40737 NULL
122664 +xfs_iext_remove_direct_40744 xfs_iext_remove_direct 3 40744 NULL
122665 +security_inode_listxattr_40752 security_inode_listxattr 0 40752 NULL
122666 +card_send_command_40757 card_send_command 3 40757 NULL
122667 +ad1889_readl_40765 ad1889_readl 0 40765 NULL
122668 +pg_write_40766 pg_write 3 40766 NULL
122669 +kernfs_fop_read_40770 kernfs_fop_read 3 40770 NULL
122670 +show_list_40775 show_list 3-0 40775 NULL
122671 +kfifo_out_copy_r_40784 kfifo_out_copy_r 0-3 40784 NULL
122672 +bitmap_weight_40791 bitmap_weight 0-2 40791 NULL
122673 +pyra_sysfs_read_40795 pyra_sysfs_read 6 40795 NULL
122674 +rtw_add_beacon_40801 rtw_add_beacon 3-5 40801 NULL
122675 +add_action_40811 add_action 4 40811 NULL
122676 +nl80211_send_roamed_40825 nl80211_send_roamed 5-7 40825 NULL
122677 +nilfs_mdt_init_40849 nilfs_mdt_init 3 40849 NULL
122678 +v9fs_file_read_40858 v9fs_file_read 3 40858 NULL
122679 +read_file_queue_40895 read_file_queue 3 40895 NULL
122680 +waiters_read_40902 waiters_read 3 40902 NULL
122681 +isdn_add_channels_40905 isdn_add_channels 3 40905 NULL
122682 +gfs2_ea_find_40913 gfs2_ea_find 0 40913 NULL
122683 +vol_cdev_write_40915 vol_cdev_write 3 40915 NULL
122684 +snd_vx_create_40948 snd_vx_create 4 40948 NULL
122685 +rds_sendmsg_40976 rds_sendmsg 4 40976 NULL
122686 +ima_appraise_measurement_40978 ima_appraise_measurement 6 40978 NULL
122687 +il_dbgfs_fh_reg_read_40993 il_dbgfs_fh_reg_read 3 40993 NULL
122688 +iwl_dbgfs_scan_ant_rxchain_read_40999 iwl_dbgfs_scan_ant_rxchain_read 3 40999 NULL
122689 +mac80211_format_buffer_41010 mac80211_format_buffer 2 41010 NULL
122690 +get_pages_alloc_bvec_41012 get_pages_alloc_bvec 0-3 41012 NULL
122691 +__proc_dobitmasks_41029 __proc_dobitmasks 5 41029 NULL
122692 +_req_append_segment_41031 _req_append_segment 2 41031 NULL
122693 +mISDN_sock_sendmsg_41035 mISDN_sock_sendmsg 4 41035 NULL
122694 +ocfs2_xattr_index_block_find_41040 ocfs2_xattr_index_block_find 0 41040 NULL
122695 +lprocfs_write_frac_helper_41050 lprocfs_write_frac_helper 2 41050 NULL
122696 +vfs_listxattr_41062 vfs_listxattr 0 41062 NULL nohasharray
122697 +beacon_filtering_write_41062 beacon_filtering_write 3 41062 &vfs_listxattr_41062
122698 +sc_only_mode_read_41076 sc_only_mode_read 3 41076 NULL
122699 +cfg80211_inform_bss_frame_41078 cfg80211_inform_bss_frame 4 41078 NULL
122700 +nvme_map_user_pages_41093 nvme_map_user_pages 4-3 41093 NULL nohasharray
122701 +roccat_read_41093 roccat_read 3 41093 &nvme_map_user_pages_41093
122702 +dma_attach_41094 dma_attach 5-6 41094 NULL
122703 +provide_user_output_41105 provide_user_output 3 41105 NULL
122704 +f_audio_buffer_alloc_41110 f_audio_buffer_alloc 1 41110 NULL
122705 +ath10k_read_wmi_services_41112 ath10k_read_wmi_services 3 41112 NULL
122706 +v4l2_ctrl_new_int_menu_41151 v4l2_ctrl_new_int_menu 4 41151 NULL
122707 +tx_frag_mpdu_alloc_failed_read_41167 tx_frag_mpdu_alloc_failed_read 3 41167 NULL
122708 +dvb_ca_write_41171 dvb_ca_write 3 41171 NULL
122709 +dfs_file_write_41196 dfs_file_write 3 41196 NULL
122710 +nfs_page_array_len_41219 nfs_page_array_len 0-2-1 41219 NULL
122711 +cfg80211_process_disassoc_41231 cfg80211_process_disassoc 3 41231 NULL
122712 +hiddev_compat_ioctl_41255 hiddev_compat_ioctl 2 41255 NULL
122713 +erst_read_41260 erst_read 0 41260 NULL
122714 +alloc_context_41283 alloc_context 1 41283 NULL
122715 +of_count_phandle_with_args_41291 of_count_phandle_with_args 0 41291 NULL
122716 +virtscsi_change_queue_depth_41327 virtscsi_change_queue_depth 2 41327 NULL
122717 +o2hb_setup_one_bio_41341 o2hb_setup_one_bio 4 41341 NULL
122718 +twl_change_queue_depth_41342 twl_change_queue_depth 2 41342 NULL
122719 +rtw_android_set_block_41347 rtw_android_set_block 0 41347 NULL
122720 +ceph_do_getattr_41349 ceph_do_getattr 0 41349 NULL
122721 +cnic_init_id_tbl_41354 cnic_init_id_tbl 2 41354 NULL
122722 +kmp_init_41373 kmp_init 2 41373 NULL
122723 +isr_commands_read_41398 isr_commands_read 3 41398 NULL
122724 +rx_defrag_decrypt_failed_read_41411 rx_defrag_decrypt_failed_read 3 41411 NULL
122725 +xfs_iext_add_41422 xfs_iext_add 3 41422 NULL
122726 +isdn_ppp_fill_rq_41428 isdn_ppp_fill_rq 2 41428 NULL
122727 +lbs_rdrf_read_41431 lbs_rdrf_read 3 41431 NULL
122728 +iio_device_alloc_41440 iio_device_alloc 1 41440 NULL
122729 +ntfs_file_buffered_write_41442 ntfs_file_buffered_write 6-4 41442 NULL
122730 +pcpu_build_alloc_info_41443 pcpu_build_alloc_info 1-2-3 41443 NULL
122731 +se_io_cb_41461 se_io_cb 3 41461 NULL
122732 +layout_leb_in_gaps_41470 layout_leb_in_gaps 0 41470 NULL
122733 +rt2x00debug_write_rfcsr_41473 rt2x00debug_write_rfcsr 3 41473 NULL
122734 +bl_alloc_init_bio_41478 bl_alloc_init_bio 1 41478 NULL
122735 +kvm_unmap_hva_range_41484 kvm_unmap_hva_range 3-2 41484 NULL
122736 +wep_interrupt_read_41492 wep_interrupt_read 3 41492 NULL
122737 +hpfs_translate_name_41497 hpfs_translate_name 3 41497 NULL
122738 +xfrm_hash_new_size_41505 xfrm_hash_new_size 0-1 41505 NULL
122739 +SyS_preadv_41523 SyS_preadv 3 41523 NULL
122740 +dm_get_reserved_rq_based_ios_41529 dm_get_reserved_rq_based_ios 0 41529 NULL
122741 +tx_tx_frame_checksum_read_41553 tx_tx_frame_checksum_read 3 41553 NULL
122742 +ath6kl_endpoint_stats_read_41554 ath6kl_endpoint_stats_read 3 41554 NULL
122743 +nr_status_frames_41559 nr_status_frames 0-1 41559 NULL nohasharray
122744 +si476x_radio_fops_read_41559 si476x_radio_fops_read 3 41559 &nr_status_frames_41559
122745 +rng_dev_read_41581 rng_dev_read 3 41581 NULL
122746 +nfsd_readv_41585 nfsd_readv 4 41585 NULL
122747 +batadv_tvlv_container_ogm_append_41588 batadv_tvlv_container_ogm_append 4 41588 NULL
122748 +tcp_hdrlen_41610 tcp_hdrlen 0 41610 NULL
122749 +lbs_bcnmiss_write_41613 lbs_bcnmiss_write 3 41613 NULL nohasharray
122750 +usb_endpoint_maxp_41613 usb_endpoint_maxp 0 41613 &lbs_bcnmiss_write_41613
122751 +a2mp_send_41615 a2mp_send 4 41615 NULL
122752 +lstcon_batch_list_41627 lstcon_batch_list 2 41627 NULL
122753 +mempool_create_kmalloc_pool_41650 mempool_create_kmalloc_pool 1 41650 NULL
122754 +rx_rx_pre_complt_read_41653 rx_rx_pre_complt_read 3 41653 NULL
122755 +get_std_timing_41654 get_std_timing 0 41654 NULL
122756 +ieee80211_if_fmt_bssid_41677 ieee80211_if_fmt_bssid 3 41677 NULL
122757 +fill_pcm_stream_name_41685 fill_pcm_stream_name 2 41685 NULL
122758 +lov_unpackmd_41701 lov_unpackmd 4 41701 NULL
122759 +connector_write_41709 connector_write 3 41709 NULL
122760 +fillonedir_41746 fillonedir 3 41746 NULL
122761 +iwl_dbgfs_bt_notif_read_41794 iwl_dbgfs_bt_notif_read 3 41794 NULL
122762 +hsi_alloc_controller_41802 hsi_alloc_controller 1 41802 NULL
122763 +ptlrpc_new_bulk_41804 ptlrpc_new_bulk 1 41804 NULL
122764 +rtw_android_get_macaddr_41812 rtw_android_get_macaddr 0 41812 NULL
122765 +sco_send_frame_41815 sco_send_frame 3 41815 NULL
122766 +kimage_file_alloc_init_41827 kimage_file_alloc_init 5 41827 NULL
122767 +copy_page_to_iter_bvec_41830 copy_page_to_iter_bvec 0-3 41830 NULL
122768 +ixgbe_dbg_netdev_ops_read_41839 ixgbe_dbg_netdev_ops_read 3 41839 NULL
122769 +do_ip_setsockopt_41852 do_ip_setsockopt 5 41852 NULL
122770 +keyctl_instantiate_key_41855 keyctl_instantiate_key 3 41855 NULL
122771 +pci_map_single_41869 pci_map_single 0 41869 NULL
122772 +usb_gadget_get_string_41871 usb_gadget_get_string 0 41871 NULL
122773 +v_APCI3120_InterruptDmaMoveBlock16bit_41914 v_APCI3120_InterruptDmaMoveBlock16bit 4 41914 NULL
122774 +get_fdb_entries_41916 get_fdb_entries 3 41916 NULL
122775 +ext4_da_write_inline_data_begin_41935 ext4_da_write_inline_data_begin 4-3 41935 NULL
122776 +sci_rxfill_41945 sci_rxfill 0 41945 NULL
122777 +read_gssp_41947 read_gssp 3 41947 NULL
122778 +ocfs2_xattr_bucket_get_name_value_41949 ocfs2_xattr_bucket_get_name_value 0 41949 NULL
122779 +portnames_read_41958 portnames_read 3 41958 NULL
122780 +dst_mtu_41969 dst_mtu 0 41969 NULL
122781 +cx24116_writeregN_41975 cx24116_writeregN 4 41975 NULL
122782 +pool_allocate_42012 pool_allocate 3 42012 NULL
122783 +spidev_sync_read_42014 spidev_sync_read 0 42014 NULL
122784 +rs_sta_dbgfs_scale_table_write_42017 rs_sta_dbgfs_scale_table_write 3 42017 NULL
122785 +acpi_ut_create_buffer_object_42030 acpi_ut_create_buffer_object 1 42030 NULL
122786 +__hwahc_op_set_gtk_42038 __hwahc_op_set_gtk 4 42038 NULL
122787 +alloc_trace_kprobe_42041 alloc_trace_kprobe 6 42041 NULL
122788 +irda_sendmsg_ultra_42047 irda_sendmsg_ultra 4 42047 NULL
122789 +jffs2_do_link_42048 jffs2_do_link 6 42048 NULL
122790 +ps_poll_upsd_max_ap_turn_read_42050 ps_poll_upsd_max_ap_turn_read 3 42050 NULL
122791 +InterfaceTransmitPacket_42058 InterfaceTransmitPacket 3 42058 NULL
122792 +ufshcd_dev_cmd_completion_42080 ufshcd_dev_cmd_completion 0 42080 NULL
122793 +scsi_execute_req_42088 scsi_execute_req 5 42088 NULL
122794 +sk_chk_filter_42095 sk_chk_filter 2 42095 NULL
122795 +submit_inquiry_42108 submit_inquiry 3 42108 NULL
122796 +dw_dma_cyclic_prep_42113 dw_dma_cyclic_prep 3-4 42113 NULL
122797 +blk_ioctl_zeroout_42160 blk_ioctl_zeroout 3 42160 NULL
122798 +mmc_align_data_size_42161 mmc_align_data_size 0-2 42161 NULL
122799 +read_file_base_eeprom_42168 read_file_base_eeprom 3 42168 NULL
122800 +oprofilefs_str_to_user_42182 oprofilefs_str_to_user 3 42182 NULL
122801 +write_file_beacon_42185 write_file_beacon 3 42185 NULL
122802 +get_znodes_to_commit_42201 get_znodes_to_commit 0 42201 NULL
122803 +blockdev_direct_IO_42235 blockdev_direct_IO 5 42235 NULL nohasharray
122804 +pla_ocp_read_42235 pla_ocp_read 3 42235 &blockdev_direct_IO_42235
122805 +rx_defrag_need_decrypt_read_42253 rx_defrag_need_decrypt_read 3 42253 NULL
122806 +find_last_bit_42260 find_last_bit 0 42260 NULL
122807 +__pcpu_size_to_slot_42271 __pcpu_size_to_slot 0 42271 NULL
122808 +__tty_buffer_request_room_42276 __tty_buffer_request_room 2-0 42276 NULL
122809 +snd_pcm_hw_param_value_max_42280 snd_pcm_hw_param_value_max 0 42280 NULL
122810 +__cpus_weight_42299 __cpus_weight 2-0 42299 NULL
122811 +sel_read_perm_42302 sel_read_perm 3 42302 NULL
122812 +sctp_setsockopt_del_key_42304 sctp_setsockopt_del_key 3 42304 NULL nohasharray
122813 +ulong_read_file_42304 ulong_read_file 3 42304 &sctp_setsockopt_del_key_42304
122814 +xfs_vm_readpages_42308 xfs_vm_readpages 4 42308 NULL
122815 +hysdn_conf_read_42324 hysdn_conf_read 3 42324 NULL
122816 +tcp_sync_mss_42330 tcp_sync_mss 2-0 42330 NULL
122817 +ide_raw_taskfile_42355 ide_raw_taskfile 4 42355 NULL
122818 +drbd_md_last_sector_42378 drbd_md_last_sector 0 42378 NULL
122819 +il_dbgfs_disable_ht40_read_42386 il_dbgfs_disable_ht40_read 3 42386 NULL
122820 +msnd_fifo_read_42406 msnd_fifo_read 0-3 42406 NULL
122821 +krng_get_random_42420 krng_get_random 3 42420 NULL
122822 +gsm_data_alloc_42437 gsm_data_alloc 3 42437 NULL
122823 +spr_wm_latency_write_42441 spr_wm_latency_write 3 42441 NULL
122824 +key_conf_keyidx_read_42443 key_conf_keyidx_read 3 42443 NULL
122825 +snd_pcm_action_group_42452 snd_pcm_action_group 0 42452 NULL
122826 +tcm_loop_change_queue_depth_42454 tcm_loop_change_queue_depth 2 42454 NULL
122827 +kuc_free_42455 kuc_free 2 42455 NULL
122828 +cp2112_gpio_get_42467 cp2112_gpio_get 2 42467 NULL
122829 +__simple_xattr_set_42474 __simple_xattr_set 4 42474 NULL
122830 +omfs_readpages_42490 omfs_readpages 4 42490 NULL
122831 +bypass_write_42498 bypass_write 3 42498 NULL
122832 +SyS_mincore_42511 SyS_mincore 1-2 42511 NULL
122833 +kvm_write_wall_clock_42520 kvm_write_wall_clock 2 42520 NULL
122834 +dio_bio_complete_42524 dio_bio_complete 0 42524 NULL
122835 +smk_write_netlbladdr_42525 smk_write_netlbladdr 3 42525 NULL
122836 +dbAllocNear_42546 dbAllocNear 0 42546 NULL
122837 +ath6kl_wmi_proc_events_vif_42549 ath6kl_wmi_proc_events_vif 5 42549 NULL
122838 +udp_recvmsg_42558 udp_recvmsg 4 42558 NULL
122839 +iwl_print_event_log_42566 iwl_print_event_log 0-7-5 42566 NULL
122840 +xfrm_new_hash_mask_42579 xfrm_new_hash_mask 0-1 42579 NULL
122841 +oom_score_adj_write_42594 oom_score_adj_write 3 42594 NULL
122842 +ieee80211_if_fmt_dot11MeshHWMPactivePathTimeout_42635 ieee80211_if_fmt_dot11MeshHWMPactivePathTimeout 3 42635 NULL
122843 +scsi_activate_tcq_42640 scsi_activate_tcq 2 42640 NULL
122844 +br_mdb_rehash_42643 br_mdb_rehash 2 42643 NULL
122845 +parport_pc_compat_write_block_pio_42644 parport_pc_compat_write_block_pio 3 42644 NULL
122846 +_regmap_raw_write_42652 _regmap_raw_write 4-2 42652 NULL
122847 +request_key_and_link_42693 request_key_and_link 4 42693 NULL
122848 +vb2_read_42703 vb2_read 3 42703 NULL
122849 +read_status_42722 read_status 0 42722 NULL
122850 +iwl_mvm_coex_dump_mbox_old_42727 iwl_mvm_coex_dump_mbox_old 4-3-0 42727 NULL
122851 +dvb_demux_ioctl_42733 dvb_demux_ioctl 2 42733 NULL
122852 +set_aoe_iflist_42737 set_aoe_iflist 2 42737 NULL
122853 +ax25_setsockopt_42740 ax25_setsockopt 5 42740 NULL
122854 +dpm_sysfs_add_42756 dpm_sysfs_add 0 42756 NULL
122855 +x25_recvmsg_42777 x25_recvmsg 4 42777 NULL
122856 +snd_midi_event_decode_42780 snd_midi_event_decode 0 42780 NULL
122857 +cryptd_hash_setkey_42781 cryptd_hash_setkey 3 42781 NULL nohasharray
122858 +isku_sysfs_read_info_42781 isku_sysfs_read_info 6 42781 &cryptd_hash_setkey_42781
122859 +elfcorehdr_read_notes_42786 elfcorehdr_read_notes 2 42786 NULL
122860 +koneplus_sysfs_read_42792 koneplus_sysfs_read 6 42792 NULL
122861 +ntfs_attr_extend_allocation_42796 ntfs_attr_extend_allocation 0 42796 NULL
122862 +fw_device_op_compat_ioctl_42804 fw_device_op_compat_ioctl 2 42804 NULL
122863 +drm_ioctl_42813 drm_ioctl 2 42813 NULL
122864 +iwl_dbgfs_ucode_bt_stats_read_42820 iwl_dbgfs_ucode_bt_stats_read 3 42820 NULL
122865 +set_arg_42824 set_arg 3 42824 NULL
122866 +si476x_radio_read_rsq_blob_42827 si476x_radio_read_rsq_blob 3 42827 NULL
122867 +ocfs2_clusters_for_bytes_42872 ocfs2_clusters_for_bytes 0-2 42872 NULL
122868 +nvme_trans_unit_serial_page_42879 nvme_trans_unit_serial_page 4 42879 NULL
122869 +xpc_kmalloc_cacheline_aligned_42895 xpc_kmalloc_cacheline_aligned 1 42895 NULL
122870 +hd_end_request_42904 hd_end_request 2 42904 NULL
122871 +sta_last_rx_rate_read_42909 sta_last_rx_rate_read 3 42909 NULL
122872 +sctp_getsockopt_maxburst_42941 sctp_getsockopt_maxburst 2 42941 NULL
122873 +vx_reset_chk_42946 vx_reset_chk 0 42946 NULL
122874 +compat_udpv6_setsockopt_42981 compat_udpv6_setsockopt 5 42981 NULL
122875 +nfs_idmap_get_desc_42990 nfs_idmap_get_desc 4-2 42990 NULL nohasharray
122876 +rtw_os_xmit_resource_alloc_42990 rtw_os_xmit_resource_alloc 3 42990 &nfs_idmap_get_desc_42990
122877 +isr_rx_mem_overflow_read_43025 isr_rx_mem_overflow_read 3 43025 NULL
122878 +wep_default_key_count_read_43035 wep_default_key_count_read 3 43035 NULL
122879 +nouveau_gpuobj_create__43072 nouveau_gpuobj_create_ 9 43072 NULL
122880 +nfs_map_group_to_gid_43082 nfs_map_group_to_gid 3 43082 NULL
122881 +_xfer_secondary_pool_43089 _xfer_secondary_pool 2 43089 NULL
122882 +sysfs_create_file_ns_43103 sysfs_create_file_ns 0 43103 NULL
122883 +ieee80211_if_fmt_drop_unencrypted_43107 ieee80211_if_fmt_drop_unencrypted 3 43107 NULL
122884 +calculate_node_totalpages_43118 calculate_node_totalpages 2-3 43118 NULL
122885 +read_file_dfs_43145 read_file_dfs 3 43145 NULL
122886 +cfs_cpt_table_alloc_43159 cfs_cpt_table_alloc 1 43159 NULL
122887 +usb_string_sub_43164 usb_string_sub 0 43164 NULL
122888 +il_dbgfs_power_save_status_read_43165 il_dbgfs_power_save_status_read 3 43165 NULL
122889 +ath6kl_set_assoc_req_ies_43185 ath6kl_set_assoc_req_ies 3 43185 NULL
122890 +ext4_xattr_ibody_get_43200 ext4_xattr_ibody_get 0 43200 NULL
122891 +uio_write_43202 uio_write 3 43202 NULL
122892 +iso_callback_43208 iso_callback 3 43208 NULL
122893 +ath10k_p2p_calc_noa_ie_len_43209 ath10k_p2p_calc_noa_ie_len 0 43209 NULL
122894 +f2fs_acl_from_disk_43210 f2fs_acl_from_disk 2 43210 NULL
122895 +atomic_long_add_return_43217 atomic_long_add_return 1 43217 NULL
122896 +gfs2_direct_IO_43220 gfs2_direct_IO 4 43220 NULL
122897 +batadv_tt_tvlv_unicast_handler_v1_43239 batadv_tt_tvlv_unicast_handler_v1 5 43239 NULL
122898 +vmemmap_alloc_block_43245 vmemmap_alloc_block 1 43245 NULL
122899 +ide_end_rq_43269 ide_end_rq 4 43269 NULL
122900 +evtchn_write_43278 evtchn_write 3 43278 NULL nohasharray
122901 +parport_pc_ecp_write_block_pio_43278 parport_pc_ecp_write_block_pio 3 43278 &evtchn_write_43278
122902 +filemap_write_and_wait_range_43279 filemap_write_and_wait_range 0 43279 NULL
122903 +mpage_alloc_43299 mpage_alloc 3 43299 NULL
122904 +mmu_set_spte_43327 mmu_set_spte 7-6 43327 NULL
122905 +__ext4_get_inode_loc_43332 __ext4_get_inode_loc 0 43332 NULL
122906 +xenfb_write_43412 xenfb_write 3 43412 NULL
122907 +ext4_xattr_check_names_43422 ext4_xattr_check_names 0 43422 NULL
122908 +__alloc_bootmem_low_43423 __alloc_bootmem_low 1 43423 NULL
122909 +usb_alloc_urb_43436 usb_alloc_urb 1 43436 NULL
122910 +ath6kl_wmi_roam_tbl_event_rx_43440 ath6kl_wmi_roam_tbl_event_rx 3 43440 NULL
122911 +usemap_size_43443 usemap_size 0-2-1 43443 NULL nohasharray
122912 +usb_string_43443 usb_string 0 43443 &usemap_size_43443
122913 +get_vm_area_size_43444 get_vm_area_size 0 43444 NULL
122914 +fs_path_prepare_for_add_43453 fs_path_prepare_for_add 2 43453 NULL
122915 +nvme_trans_device_id_page_43466 nvme_trans_device_id_page 4 43466 NULL
122916 +tx_tx_data_prepared_read_43497 tx_tx_data_prepared_read 3 43497 NULL
122917 +ieee80211_if_fmt_dot11MeshHWMPnetDiameterTraversalTime_43505 ieee80211_if_fmt_dot11MeshHWMPnetDiameterTraversalTime 3 43505 NULL
122918 +ll_direct_IO_26_43530 ll_direct_IO_26 4 43530 NULL
122919 +dvb_ca_en50221_io_write_43533 dvb_ca_en50221_io_write 3 43533 NULL
122920 +read_events_43534 read_events 3 43534 NULL
122921 +cachefiles_daemon_write_43535 cachefiles_daemon_write 3 43535 NULL
122922 +tx_frag_failed_read_43540 tx_frag_failed_read 3 43540 NULL
122923 +request_resource_43548 request_resource 0 43548 NULL
122924 +rpc_malloc_43573 rpc_malloc 2 43573 NULL
122925 +handle_frequent_errors_43599 handle_frequent_errors 4 43599 NULL
122926 +lpfc_idiag_drbacc_read_reg_43606 lpfc_idiag_drbacc_read_reg 0-3 43606 NULL
122927 +proc_read_43614 proc_read 3 43614 NULL
122928 +disable_dma_on_even_43618 disable_dma_on_even 0 43618 NULL
122929 +alloc_thread_groups_43625 alloc_thread_groups 2 43625 NULL
122930 +random_write_43656 random_write 3 43656 NULL
122931 +bio_integrity_tag_43658 bio_integrity_tag 3 43658 NULL
122932 +ext4_acl_count_43659 ext4_acl_count 0-1 43659 NULL
122933 +write_file_tx99_power_43670 write_file_tx99_power 3 43670 NULL
122934 +dmam_declare_coherent_memory_43679 dmam_declare_coherent_memory 4 43679 NULL
122935 +max77693_bulk_write_43698 max77693_bulk_write 2-3 43698 NULL
122936 +nvkm_connector_create__43711 nvkm_connector_create_ 6 43711 NULL
122937 +fuse_send_read_43725 fuse_send_read 4-0 43725 NULL
122938 +drbd_md_first_sector_43729 drbd_md_first_sector 0 43729 NULL
122939 +snd_rme32_playback_copy_43732 snd_rme32_playback_copy 5 43732 NULL
122940 +__alloc_alien_cache_43734 __alloc_alien_cache 2 43734 NULL
122941 +fuse_conn_congestion_threshold_write_43736 fuse_conn_congestion_threshold_write 3 43736 NULL
122942 +gigaset_initcs_43753 gigaset_initcs 2 43753 NULL
122943 +sctp_setsockopt_active_key_43755 sctp_setsockopt_active_key 3 43755 NULL
122944 +ocfs2_xattr_get_value_outside_43787 ocfs2_xattr_get_value_outside 0 43787 NULL nohasharray
122945 +byte_pos_43787 byte_pos 0 43787 &ocfs2_xattr_get_value_outside_43787
122946 +btrfs_copy_from_user_43806 btrfs_copy_from_user 0-3-1 43806 NULL
122947 +ieee80211_if_fmt_element_ttl_43825 ieee80211_if_fmt_element_ttl 3 43825 NULL
122948 +ieee80211_alloc_hw_43829 ieee80211_alloc_hw 1 43829 NULL
122949 +read_flush_43851 read_flush 3 43851 NULL
122950 +pm860x_bulk_write_43875 pm860x_bulk_write 2-3 43875 NULL
122951 +ec_dbgfs_cmd_write_43895 ec_dbgfs_cmd_write 3 43895 NULL
122952 +SendString_43928 SendString 3 43928 NULL
122953 +stats_dot11RTSFailureCount_read_43948 stats_dot11RTSFailureCount_read 3 43948 NULL
122954 +__get_required_blob_size_43980 __get_required_blob_size 0-3-2 43980 NULL
122955 +nla_reserve_43984 nla_reserve 3 43984 NULL
122956 +__clkdev_alloc_43990 __clkdev_alloc 1 43990 NULL
122957 +kvm_read_guest_virt_43992 kvm_read_guest_virt 4-2 43992 NULL nohasharray
122958 +scsi_command_size_43992 scsi_command_size 0 43992 &kvm_read_guest_virt_43992 nohasharray
122959 +bcm_recvmsg_43992 bcm_recvmsg 4 43992 &scsi_command_size_43992
122960 +emit_flags_44006 emit_flags 4-3 44006 NULL
122961 +write_flush_procfs_44011 write_flush_procfs 3 44011 NULL
122962 +fru_strlen_44046 fru_strlen 0 44046 NULL
122963 +ath9k_def_dump_modal_eeprom_44078 ath9k_def_dump_modal_eeprom 3-2-0 44078 NULL
122964 +SYSC_add_key_44079 SYSC_add_key 4 44079 NULL
122965 +pci_msix_vec_count_44093 pci_msix_vec_count 0 44093 NULL
122966 +xlog_recover_add_to_cont_trans_44102 xlog_recover_add_to_cont_trans 4 44102 NULL
122967 +skb_frag_dma_map_44112 skb_frag_dma_map 0 44112 NULL
122968 +nouveau_clock_create__44116 nouveau_clock_create_ 6 44116 NULL
122969 +tracing_set_trace_read_44122 tracing_set_trace_read 3 44122 NULL
122970 +SyS_process_vm_writev_44129 SyS_process_vm_writev 3-5 44129 NULL
122971 +tracing_resize_saved_cmdlines_44140 tracing_resize_saved_cmdlines 1 44140 NULL
122972 +ttm_get_pages_44142 ttm_get_pages 2 44142 NULL
122973 +scsi_get_resid_44147 scsi_get_resid 0 44147 NULL
122974 +ocfs2_xattr_bucket_find_44174 ocfs2_xattr_bucket_find 0 44174 NULL
122975 +SYSC_set_mempolicy_44176 SYSC_set_mempolicy 3 44176 NULL
122976 +readreg_ipac_44186 readreg_ipac 0 44186 NULL
122977 +handle_eviocgbit_44193 handle_eviocgbit 3 44193 NULL
122978 +btrfs_item_offset_nr_44220 btrfs_item_offset_nr 0 44220 NULL
122979 +srp_alloc_iu_44227 srp_alloc_iu 2 44227 NULL
122980 +scsi_track_queue_full_44239 scsi_track_queue_full 2 44239 NULL
122981 +sigma_action_write_regmap_44240 sigma_action_write_regmap 3 44240 NULL
122982 +device_create_file_44285 device_create_file 0 44285 NULL
122983 +ath6kl_keepalive_read_44303 ath6kl_keepalive_read 3 44303 NULL
122984 +bitmap_scnprintf_44318 bitmap_scnprintf 0-2 44318 NULL
122985 +dispatch_proc_write_44320 dispatch_proc_write 3 44320 NULL
122986 +ccp_init_data_44324 ccp_init_data 5 44324 NULL
122987 +rs_init_44327 rs_init 1 44327 NULL
122988 +nfs_fscache_get_super_cookie_44355 nfs_fscache_get_super_cookie 3 44355 NULL nohasharray
122989 +blk_queue_init_tags_44355 blk_queue_init_tags 2 44355 &nfs_fscache_get_super_cookie_44355
122990 +rts_threshold_read_44384 rts_threshold_read 3 44384 NULL
122991 +mtip_hw_read_flags_44396 mtip_hw_read_flags 3 44396 NULL
122992 +aoedev_flush_44398 aoedev_flush 2 44398 NULL
122993 +strlcpy_44400 strlcpy 3 44400 NULL
122994 +drm_buffer_alloc_44405 drm_buffer_alloc 2 44405 NULL
122995 +osst_do_scsi_44410 osst_do_scsi 4 44410 NULL
122996 +ieee80211_if_read_rc_rateidx_mcs_mask_5ghz_44423 ieee80211_if_read_rc_rateidx_mcs_mask_5ghz 3 44423 NULL
122997 +mic_virtio_copy_to_user_44472 mic_virtio_copy_to_user 3-4 44472 NULL
122998 +write_file_debug_44476 write_file_debug 3 44476 NULL
122999 +btrfs_chunk_item_size_44478 btrfs_chunk_item_size 0-1 44478 NULL
123000 +sdio_align_size_44489 sdio_align_size 0-2 44489 NULL
123001 +bio_advance_44496 bio_advance 2 44496 NULL
123002 +ieee80211_if_read_dropped_frames_ttl_44500 ieee80211_if_read_dropped_frames_ttl 3 44500 NULL
123003 +ac_register_board_44504 ac_register_board 3 44504 NULL
123004 +security_getprocattr_44505 security_getprocattr 0 44505 NULL nohasharray
123005 +iwl_dbgfs_sram_read_44505 iwl_dbgfs_sram_read 3 44505 &security_getprocattr_44505
123006 +spidev_write_44510 spidev_write 3 44510 NULL
123007 +SyS_io_getevents_44519 SyS_io_getevents 3 44519 NULL
123008 +ieee80211_rx_mgmt_assoc_resp_44525 ieee80211_rx_mgmt_assoc_resp 3 44525 NULL
123009 +comm_write_44537 comm_write 3 44537 NULL
123010 +dgrp_config_proc_write_44571 dgrp_config_proc_write 3 44571 NULL
123011 +l2cap_sock_memcpy_fromiovec_cb_44573 l2cap_sock_memcpy_fromiovec_cb 4 44573 NULL
123012 +nouveau_perfmon_create__44602 nouveau_perfmon_create_ 4 44602 NULL
123013 +xpcs_mmd_write_44633 xpcs_mmd_write 3 44633 NULL
123014 +alloc_ctrl_packet_44667 alloc_ctrl_packet 1 44667 NULL
123015 +mpi_resize_44674 mpi_resize 2 44674 NULL
123016 +sysfs_create_link_44685 sysfs_create_link 0 44685 NULL
123017 +ts_read_44687 ts_read 3 44687 NULL
123018 +lov_emerg_alloc_44698 lov_emerg_alloc 1 44698 NULL
123019 +C_SYSC_select_44701 C_SYSC_select 1 44701 NULL
123020 +__generic_block_fiemap_44713 __generic_block_fiemap 4 44713 NULL nohasharray
123021 +xfer_to_user_44713 xfer_to_user 3 44713 &__generic_block_fiemap_44713
123022 +nft_hash_tbl_size_44724 nft_hash_tbl_size 0 44724 NULL
123023 +_zd_iowrite32v_locked_44725 _zd_iowrite32v_locked 3 44725 NULL
123024 +clusterip_proc_write_44729 clusterip_proc_write 3 44729 NULL
123025 +fib_count_nexthops_44730 fib_count_nexthops 0 44730 NULL
123026 +key_tx_rx_count_read_44742 key_tx_rx_count_read 3 44742 NULL
123027 +bch_bio_max_sectors_44755 bch_bio_max_sectors 0 44755 NULL
123028 +tnode_new_44757 tnode_new 3 44757 NULL nohasharray
123029 +pty_write_44757 pty_write 3 44757 &tnode_new_44757
123030 +__videobuf_copy_stream_44769 __videobuf_copy_stream 4-0 44769 NULL
123031 +handsfree_ramp_44777 handsfree_ramp 2 44777 NULL
123032 +irq_domain_add_legacy_44781 irq_domain_add_legacy 4-2 44781 NULL
123033 +sctp_setsockopt_44788 sctp_setsockopt 5 44788 NULL
123034 +rx_dropped_read_44799 rx_dropped_read 3 44799 NULL
123035 +qla4xxx_alloc_work_44813 qla4xxx_alloc_work 2 44813 NULL
123036 +force_static_address_write_44819 force_static_address_write 3 44819 NULL
123037 +mei_cl_read_start_44824 mei_cl_read_start 2 44824 NULL
123038 +rmap_write_protect_44833 rmap_write_protect 2 44833 NULL
123039 +sisusb_write_44834 sisusb_write 3 44834 NULL
123040 +kvm_read_hva_44847 kvm_read_hva 3 44847 NULL
123041 +qib_verbs_send_dma_44850 qib_verbs_send_dma 6 44850 NULL
123042 +copydesc_user_44855 copydesc_user 3 44855 NULL
123043 +set_advertising_44870 set_advertising 4 44870 NULL
123044 +init_rs_44873 init_rs 1 44873 NULL
123045 +skb_availroom_44883 skb_availroom 0 44883 NULL
123046 +do_tty_write_44896 do_tty_write 5 44896 NULL
123047 +regmap_spi_read_44921 regmap_spi_read 3-5 44921 NULL
123048 +tx_queue_status_read_44978 tx_queue_status_read 3 44978 NULL
123049 +bytepos_delta_45017 bytepos_delta 0 45017 NULL
123050 +ptrace_writedata_45021 ptrace_writedata 4 45021 NULL
123051 +dm_kvzalloc_45025 dm_kvzalloc 1 45025 NULL
123052 +sysfs_do_create_link_sd_45057 sysfs_do_create_link_sd 0 45057 NULL
123053 +sel_write_user_45060 sel_write_user 3 45060 NULL
123054 +snd_mixart_BA0_read_45069 snd_mixart_BA0_read 5 45069 NULL
123055 +lnet_expand1tb_45102 lnet_expand1tb 6 45102 NULL
123056 +snd_card_new_45104 snd_card_new 5 45104 NULL
123057 +kvm_mmu_page_get_gfn_45110 kvm_mmu_page_get_gfn 0-2 45110 NULL
123058 +pwr_missing_bcns_cnt_read_45113 pwr_missing_bcns_cnt_read 3 45113 NULL
123059 +usbdev_read_45114 usbdev_read 3 45114 NULL
123060 +send_to_tty_45141 send_to_tty 3 45141 NULL
123061 +cfs_trace_daemon_command_usrstr_45147 cfs_trace_daemon_command_usrstr 2 45147 NULL
123062 +gen_bitmask_string_45149 gen_bitmask_string 6 45149 NULL
123063 +device_write_45156 device_write 3 45156 NULL nohasharray
123064 +ocfs2_remove_inode_range_45156 ocfs2_remove_inode_range 3-4 45156 &device_write_45156
123065 +tomoyo_write_self_45161 tomoyo_write_self 3 45161 NULL
123066 +sta_agg_status_write_45164 sta_agg_status_write 3 45164 NULL
123067 +snd_sb_csp_load_user_45190 snd_sb_csp_load_user 3 45190 NULL nohasharray
123068 +sctp_pack_cookie_45190 sctp_pack_cookie 6 45190 &snd_sb_csp_load_user_45190
123069 +iso_alloc_urb_45206 iso_alloc_urb 4-5 45206 NULL
123070 +spi_alloc_master_45223 spi_alloc_master 2 45223 NULL
123071 +ieee80211_if_read_peer_45233 ieee80211_if_read_peer 3 45233 NULL
123072 +event_enable_write_45238 event_enable_write 3 45238 NULL
123073 +prism2_pda_proc_read_45246 prism2_pda_proc_read 3 45246 NULL
123074 +input_mt_init_slots_45279 input_mt_init_slots 2 45279 NULL
123075 +gfs2_fiemap_45282 gfs2_fiemap 4 45282 NULL
123076 +snd_pcm_oss_sync1_45298 snd_pcm_oss_sync1 2 45298 NULL
123077 +e1000_tx_map_45309 e1000_tx_map 5 45309 NULL
123078 +copy_vm86_regs_from_user_45340 copy_vm86_regs_from_user 3 45340 NULL
123079 +brcmf_sdio_died_dump_45359 brcmf_sdio_died_dump 3 45359 NULL
123080 +null_alloc_repbuf_45375 null_alloc_repbuf 3 45375 NULL
123081 +count_skb_frag_slots_45395 count_skb_frag_slots 0 45395 NULL
123082 +sock_recv_errqueue_45412 sock_recv_errqueue 3 45412 NULL
123083 +ieee80211_if_fmt_dot11MeshHWMProotInterval_45421 ieee80211_if_fmt_dot11MeshHWMProotInterval 3 45421 NULL
123084 +ll_iocontrol_register_45430 ll_iocontrol_register 2 45430 NULL
123085 +tty_buffer_alloc_45437 tty_buffer_alloc 2 45437 NULL
123086 +blkdev_direct_IO_45440 blkdev_direct_IO 4 45440 NULL
123087 +__node_remap_45458 __node_remap 4 45458 NULL
123088 +rds_ib_set_wr_signal_state_45463 rds_ib_set_wr_signal_state 0 45463 NULL
123089 +tracing_read_dyn_info_45468 tracing_read_dyn_info 3 45468 NULL
123090 +__calc_request_pg_45470 __calc_request_pg 0 45470 NULL
123091 +rds_message_copy_from_user_45510 rds_message_copy_from_user 3 45510 NULL
123092 +copy_macs_45534 copy_macs 4 45534 NULL
123093 +nla_attr_size_45545 nla_attr_size 0-1 45545 NULL
123094 +v9fs_direct_read_45546 v9fs_direct_read 3 45546 NULL
123095 +cx18_copy_mdl_to_user_45549 cx18_copy_mdl_to_user 4 45549 NULL
123096 +stats_dot11ACKFailureCount_read_45558 stats_dot11ACKFailureCount_read 3 45558 NULL
123097 +_regmap_bus_raw_write_45559 _regmap_bus_raw_write 2 45559 NULL
123098 +posix_acl_xattr_size_45561 posix_acl_xattr_size 0-1 45561 NULL
123099 +venus_rmdir_45564 venus_rmdir 4 45564 NULL
123100 +ath6kl_keepalive_write_45600 ath6kl_keepalive_write 3 45600 NULL
123101 +hidraw_get_report_45609 hidraw_get_report 3 45609 NULL
123102 +ip_dst_mtu_maybe_forward_45627 ip_dst_mtu_maybe_forward 0 45627 NULL
123103 +compat_mpctl_ioctl_45671 compat_mpctl_ioctl 2 45671 NULL
123104 +dgram_sendmsg_45679 dgram_sendmsg 4 45679 NULL
123105 +smk_write_ambient_45691 smk_write_ambient 3 45691 NULL
123106 +bscnl_emit_45699 bscnl_emit 2-5-0 45699 NULL nohasharray
123107 +unix_dgram_sendmsg_45699 unix_dgram_sendmsg 4 45699 &bscnl_emit_45699
123108 +sg_proc_write_adio_45704 sg_proc_write_adio 3 45704 NULL
123109 +wlcore_smart_config_decode_event_45714 wlcore_smart_config_decode_event 2-4 45714 NULL
123110 +snd_cs46xx_io_read_45734 snd_cs46xx_io_read 5 45734 NULL
123111 +rw_copy_check_uvector_45748 rw_copy_check_uvector 3-0 45748 NULL nohasharray
123112 +v4l2_ctrl_new_std_45748 v4l2_ctrl_new_std 5 45748 &rw_copy_check_uvector_45748
123113 +lkdtm_debugfs_read_45752 lkdtm_debugfs_read 3 45752 NULL
123114 +alloc_ts_config_45775 alloc_ts_config 1 45775 NULL
123115 +osc_checksum_type_seq_write_45785 osc_checksum_type_seq_write 3 45785 NULL
123116 +raw_setsockopt_45800 raw_setsockopt 5 45800 NULL
123117 +rds_tcp_inc_copy_to_user_45804 rds_tcp_inc_copy_to_user 3 45804 NULL
123118 +lbs_rdbbp_read_45805 lbs_rdbbp_read 3 45805 NULL
123119 +pcpu_alloc_alloc_info_45813 pcpu_alloc_alloc_info 1-2 45813 NULL
123120 +ll_max_readahead_mb_seq_write_45815 ll_max_readahead_mb_seq_write 3 45815 NULL
123121 +memcg_update_cache_size_45828 memcg_update_cache_size 2 45828 NULL
123122 +ipv6_recv_rxpmtu_45830 ipv6_recv_rxpmtu 3 45830 NULL
123123 +x509_process_extension_45854 x509_process_extension 5 45854 NULL
123124 +efx_tx_queue_insert_45859 efx_tx_queue_insert 2 45859 NULL
123125 +isdn_write_45863 isdn_write 3 45863 NULL
123126 +get_rdac_req_45882 get_rdac_req 3 45882 NULL
123127 +ocfs2_xattr_block_find_45891 ocfs2_xattr_block_find 0 45891 NULL
123128 +cfs_cpt_weight_45903 cfs_cpt_weight 0 45903 NULL
123129 +wm_adsp_region_to_reg_45915 wm_adsp_region_to_reg 0-2 45915 NULL
123130 +dbgfs_frame_45917 dbgfs_frame 3 45917 NULL
123131 +btree_keys_cachelines_45928 btree_keys_cachelines 0 45928 NULL
123132 +alloc_mr_45935 alloc_mr 1 45935 NULL
123133 +copy_to_45969 copy_to 3 45969 NULL
123134 +rb_simple_read_45972 rb_simple_read 3 45972 NULL
123135 +ioat2_dca_count_dca_slots_45984 ioat2_dca_count_dca_slots 0 45984 NULL
123136 +sierra_setup_urb_46029 sierra_setup_urb 5 46029 NULL
123137 +fnic_reset_stats_read_46030 fnic_reset_stats_read 3 46030 NULL nohasharray
123138 +get_free_entries_46030 get_free_entries 1 46030 &fnic_reset_stats_read_46030
123139 +__access_remote_vm_46031 __access_remote_vm 0 46031 NULL
123140 +snd_emu10k1x_ptr_read_46049 snd_emu10k1x_ptr_read 0 46049 NULL
123141 +dma_tx_errors_read_46060 dma_tx_errors_read 3 46060 NULL nohasharray
123142 +__ocfs2_move_extent_46060 __ocfs2_move_extent 3-4 46060 &dma_tx_errors_read_46060
123143 +sel_commit_bools_write_46077 sel_commit_bools_write 3 46077 NULL
123144 +memcg_update_array_size_46111 memcg_update_array_size 1 46111 NULL nohasharray
123145 +il3945_ucode_general_stats_read_46111 il3945_ucode_general_stats_read 3 46111 &memcg_update_array_size_46111
123146 +C_SYSC_writev_46113 C_SYSC_writev 3 46113 NULL
123147 +mlx4_ib_alloc_fast_reg_page_list_46119 mlx4_ib_alloc_fast_reg_page_list 2 46119 NULL
123148 +rtw_buf_update_46138 rtw_buf_update 4 46138 NULL
123149 +vb2_dma_sg_get_userptr_46146 vb2_dma_sg_get_userptr 3-2 46146 NULL
123150 +__netlink_change_ngroups_46156 __netlink_change_ngroups 2 46156 NULL
123151 +twl_direction_out_46182 twl_direction_out 2 46182 NULL
123152 +vxge_os_dma_malloc_46184 vxge_os_dma_malloc 2 46184 NULL
123153 +fq_resize_46195 fq_resize 2 46195 NULL
123154 +add_conn_list_46197 add_conn_list 3-0 46197 NULL
123155 +i2400m_op_msg_from_user_46213 i2400m_op_msg_from_user 4 46213 NULL
123156 +tm6000_i2c_recv_regs_46215 tm6000_i2c_recv_regs 5 46215 NULL
123157 +dsp_write_46218 dsp_write 2 46218 NULL
123158 +hash_netiface4_expire_46226 hash_netiface4_expire 4 46226 NULL
123159 +xen_setup_msi_irqs_46245 xen_setup_msi_irqs 2 46245 NULL
123160 +mpi_read_raw_data_46248 mpi_read_raw_data 2 46248 NULL
123161 +sg_proc_write_dressz_46316 sg_proc_write_dressz 3 46316 NULL
123162 +C_SYSC_ppoll_46319 C_SYSC_ppoll 2 46319 NULL
123163 +__hwahc_dev_set_key_46328 __hwahc_dev_set_key 5 46328 NULL nohasharray
123164 +compat_SyS_readv_46328 compat_SyS_readv 3 46328 &__hwahc_dev_set_key_46328
123165 +iwl_dbgfs_chain_noise_read_46355 iwl_dbgfs_chain_noise_read 3 46355 NULL
123166 +smk_write_direct_46363 smk_write_direct 3 46363 NULL
123167 +crypto_ablkcipher_reqsize_46411 crypto_ablkcipher_reqsize 0 46411 NULL
123168 +ttm_page_pool_get_pages_46431 ttm_page_pool_get_pages 0-5 46431 NULL
123169 +cfs_power2_roundup_46433 cfs_power2_roundup 0-1 46433 NULL
123170 +wdata_alloc_and_fillpages_46437 wdata_alloc_and_fillpages 1 46437 NULL
123171 +cp210x_set_config_46447 cp210x_set_config 4 46447 NULL
123172 +parport_pc_fifo_write_block_46455 parport_pc_fifo_write_block 3 46455 NULL
123173 +il_dbgfs_clear_traffic_stats_write_46458 il_dbgfs_clear_traffic_stats_write 3 46458 NULL
123174 +filldir64_46469 filldir64 3 46469 NULL
123175 +fill_in_write_vector_46498 fill_in_write_vector 0 46498 NULL
123176 +pin_code_reply_46510 pin_code_reply 4 46510 NULL
123177 +mthca_alloc_cq_buf_46512 mthca_alloc_cq_buf 3 46512 NULL
123178 +kmsg_read_46514 kmsg_read 3 46514 NULL nohasharray
123179 +nouveau_drm_ioctl_46514 nouveau_drm_ioctl 2 46514 &kmsg_read_46514
123180 +nl80211_send_rx_assoc_46538 nl80211_send_rx_assoc 4 46538 NULL
123181 +__btrfs_free_extent_46573 __btrfs_free_extent 7 46573 NULL
123182 +dn_current_mss_46574 dn_current_mss 0 46574 NULL
123183 +serverworks_create_gatt_pages_46582 serverworks_create_gatt_pages 1 46582 NULL
123184 +snd_compr_write_data_46592 snd_compr_write_data 3 46592 NULL
123185 +il3945_stats_flag_46606 il3945_stats_flag 0-3 46606 NULL
123186 +vscnprintf_46617 vscnprintf 0-2 46617 NULL
123187 +__kfifo_out_r_46623 __kfifo_out_r 0-3 46623 NULL
123188 +request_key_async_with_auxdata_46624 request_key_async_with_auxdata 4 46624 NULL
123189 +pci_enable_device_46642 pci_enable_device 0 46642 NULL
123190 +vfs_getxattr_alloc_46649 vfs_getxattr_alloc 0 46649 NULL
123191 +e1000_tx_map_46672 e1000_tx_map 4 46672 NULL
123192 +l2cap_create_le_flowctl_pdu_46682 l2cap_create_le_flowctl_pdu 3 46682 NULL
123193 +alloc_data_packet_46698 alloc_data_packet 1 46698 NULL
123194 +__ilog2_u32_46706 __ilog2_u32 0 46706 NULL
123195 +erst_dbg_write_46715 erst_dbg_write 3 46715 NULL
123196 +wl1271_rx_filter_alloc_field_46721 wl1271_rx_filter_alloc_field 5 46721 NULL
123197 +irq_domain_add_simple_46734 irq_domain_add_simple 2 46734 NULL
123198 +read_file_tx99_46741 read_file_tx99 3 46741 NULL
123199 +ext4_count_free_46754 ext4_count_free 2 46754 NULL
123200 +hest_ghes_dev_register_46766 hest_ghes_dev_register 1 46766 NULL
123201 +int_hw_irq_en_46776 int_hw_irq_en 3 46776 NULL
123202 +xfs_iroot_realloc_46826 xfs_iroot_realloc 2 46826 NULL
123203 +shmem_pwrite_fast_46842 shmem_pwrite_fast 3 46842 NULL
123204 +readreg_46845 readreg 0 46845 NULL
123205 +spi_async_46857 spi_async 0 46857 NULL
123206 +vsnprintf_46863 vsnprintf 0 46863 NULL
123207 +nvme_alloc_queue_46865 nvme_alloc_queue 3 46865 NULL
123208 +qp_memcpy_from_queue_iov_46874 qp_memcpy_from_queue_iov 5-4 46874 NULL
123209 +lov_iocontrol_46876 lov_iocontrol 3 46876 NULL
123210 +ixgbe_dbg_reg_ops_write_46895 ixgbe_dbg_reg_ops_write 3 46895 NULL
123211 +sk_mem_pages_46896 sk_mem_pages 0-1 46896 NULL
123212 +ieee80211_if_fmt_power_mode_46906 ieee80211_if_fmt_power_mode 3 46906 NULL
123213 +wlcore_alloc_hw_46917 wlcore_alloc_hw 1-3 46917 NULL
123214 +fb_write_46924 fb_write 3 46924 NULL
123215 +__sctp_setsockopt_connectx_46949 __sctp_setsockopt_connectx 3 46949 NULL
123216 +qla4xxx_post_aen_work_46953 qla4xxx_post_aen_work 3 46953 NULL
123217 +SYSC_poll_46965 SYSC_poll 2 46965 NULL
123218 +crypto_tfm_alg_alignmask_46971 crypto_tfm_alg_alignmask 0 46971 NULL
123219 +mgmt_pending_add_46976 mgmt_pending_add 5 46976 NULL
123220 +strlcat_46985 strlcat 3 46985 NULL
123221 +bitmap_file_clear_bit_46990 bitmap_file_clear_bit 2 46990 NULL
123222 +sel_write_bool_46996 sel_write_bool 3 46996 NULL
123223 +blk_rq_map_kern_47004 blk_rq_map_kern 4 47004 NULL
123224 +cx231xx_init_bulk_47024 cx231xx_init_bulk 3-2-4 47024 NULL
123225 +fs_path_len_47060 fs_path_len 0 47060 NULL
123226 +event_trigger_regex_write_47067 event_trigger_regex_write 3 47067 NULL
123227 +pipeline_dec_packet_in_read_47076 pipeline_dec_packet_in_read 3 47076 NULL
123228 +scsi_deactivate_tcq_47086 scsi_deactivate_tcq 2 47086 NULL
123229 +iwl_dump_nic_event_log_47089 iwl_dump_nic_event_log 0 47089 NULL
123230 +ptlrpc_lprocfs_threads_max_seq_write_47104 ptlrpc_lprocfs_threads_max_seq_write 3 47104 NULL
123231 +mousedev_read_47123 mousedev_read 3 47123 NULL
123232 +upcall_msg_size_47141 upcall_msg_size 2 47141 NULL
123233 +acpi_ut_initialize_buffer_47143 acpi_ut_initialize_buffer 2 47143 NULL nohasharray
123234 +ses_recv_diag_47143 ses_recv_diag 4 47143 &acpi_ut_initialize_buffer_47143
123235 +mxms_headerlen_47161 mxms_headerlen 0 47161 NULL
123236 +rs_sta_dbgfs_rate_scale_data_read_47165 rs_sta_dbgfs_rate_scale_data_read 3 47165 NULL
123237 +options_write_47243 options_write 3 47243 NULL
123238 +portcntrs_1_read_47253 portcntrs_1_read 3 47253 NULL
123239 +ablkcipher_next_slow_47274 ablkcipher_next_slow 4-3 47274 NULL
123240 +gfs2_readpages_47285 gfs2_readpages 4 47285 NULL
123241 +vsnprintf_47291 vsnprintf 0 47291 NULL
123242 +SYSC_semop_47292 SYSC_semop 3 47292 NULL
123243 +tx_internal_desc_overflow_read_47300 tx_internal_desc_overflow_read 3 47300 NULL
123244 +nouveau_fb_create__47316 nouveau_fb_create_ 4 47316 NULL
123245 +ieee80211_if_read_dot11MeshHoldingTimeout_47356 ieee80211_if_read_dot11MeshHoldingTimeout 3 47356 NULL
123246 +avc_get_hash_stats_47359 avc_get_hash_stats 0 47359 NULL
123247 +kvm_arch_create_memslot_47364 kvm_arch_create_memslot 3 47364 NULL nohasharray
123248 +__output_copy_user_47364 __output_copy_user 3 47364 &kvm_arch_create_memslot_47364
123249 +__bio_map_kern_47379 __bio_map_kern 3 47379 NULL
123250 +nv_rd32_47390 nv_rd32 0 47390 NULL nohasharray
123251 +trace_options_core_read_47390 trace_options_core_read 3 47390 &nv_rd32_47390
123252 +nametbl_list_47391 nametbl_list 2 47391 NULL
123253 +dgrp_net_write_47392 dgrp_net_write 3 47392 NULL
123254 +pfkey_sendmsg_47394 pfkey_sendmsg 4 47394 NULL
123255 +lbs_wrmac_write_47400 lbs_wrmac_write 3 47400 NULL
123256 +sta_vht_capa_read_47409 sta_vht_capa_read 3 47409 NULL
123257 +crypto_ablkcipher_alignmask_47410 crypto_ablkcipher_alignmask 0 47410 NULL
123258 +lbs_wrrf_write_47418 lbs_wrrf_write 3 47418 NULL
123259 +C_SYSC_set_mempolicy_47466 C_SYSC_set_mempolicy 3 47466 NULL
123260 +lprocfs_fid_write_common_47471 lprocfs_fid_write_common 2 47471 NULL
123261 +nvme_trans_send_fw_cmd_47479 nvme_trans_send_fw_cmd 4 47479 NULL
123262 +newpart_47485 newpart 6-4 47485 NULL
123263 +mcp23s17_read_regs_47491 mcp23s17_read_regs 4 47491 NULL
123264 +core_sys_select_47494 core_sys_select 1 47494 NULL
123265 +as3722_block_write_47503 as3722_block_write 2-3 47503 NULL
123266 +alloc_arraycache_47505 alloc_arraycache 2 47505 NULL
123267 +unlink_simple_47506 unlink_simple 3 47506 NULL
123268 +pstore_decompress_47510 pstore_decompress 0 47510 NULL
123269 +ec_i2c_count_response_47518 ec_i2c_count_response 0 47518 NULL
123270 +__proc_lnet_portal_rotor_47529 __proc_lnet_portal_rotor 5 47529 NULL
123271 +process_vm_rw_47533 process_vm_rw 3-5 47533 NULL nohasharray
123272 +vscnprintf_47533 vscnprintf 0-2 47533 &process_vm_rw_47533
123273 +ieee80211_if_fmt_min_discovery_timeout_47539 ieee80211_if_fmt_min_discovery_timeout 3 47539 NULL
123274 +drbg_statelen_47551 drbg_statelen 0 47551 NULL
123275 +read_ldt_47570 read_ldt 2 47570 NULL
123276 +isku_sysfs_read_last_set_47572 isku_sysfs_read_last_set 6 47572 NULL
123277 +btrfs_stack_header_bytenr_47589 btrfs_stack_header_bytenr 0 47589 NULL
123278 +ext4_kvzalloc_47605 ext4_kvzalloc 1 47605 NULL
123279 +sctp_ssnmap_new_47608 sctp_ssnmap_new 2-1 47608 NULL
123280 +cache_read_pipefs_47615 cache_read_pipefs 3 47615 NULL
123281 +twl4030_clear_set_47624 twl4030_clear_set 4 47624 NULL
123282 +ccp_sha_setkey_47633 ccp_sha_setkey 3 47633 NULL
123283 +get_size_47644 get_size 1-2 47644 NULL
123284 +osc_brw_prep_request_47680 osc_brw_prep_request 5 47680 NULL
123285 +packet_recvmsg_47700 packet_recvmsg 4 47700 NULL nohasharray
123286 +ipath_format_hwmsg_47700 ipath_format_hwmsg 2 47700 &packet_recvmsg_47700
123287 +save_microcode_47717 save_microcode 3 47717 NULL
123288 +bits_to_user_47733 bits_to_user 2-3 47733 NULL
123289 +carl9170_debugfs_read_47738 carl9170_debugfs_read 3 47738 NULL
123290 +ir_prepare_write_buffer_47747 ir_prepare_write_buffer 3 47747 NULL
123291 +mvumi_alloc_mem_resource_47750 mvumi_alloc_mem_resource 3 47750 NULL
123292 +alloc_sched_domains_47756 alloc_sched_domains 1 47756 NULL
123293 +uwb_ie_dump_hex_47774 uwb_ie_dump_hex 4 47774 NULL
123294 +SyS_setgroups16_47780 SyS_setgroups16 1 47780 NULL
123295 +error_error_numll_frame_cts_start_read_47781 error_error_numll_frame_cts_start_read 3 47781 NULL
123296 +ptlrpc_prep_req_47792 ptlrpc_prep_req 4 47792 NULL
123297 +posix_acl_fix_xattr_from_user_47793 posix_acl_fix_xattr_from_user 2 47793 NULL
123298 +W6692_empty_Bfifo_47804 W6692_empty_Bfifo 2 47804 NULL
123299 +lov_packmd_47810 lov_packmd 0 47810 NULL
123300 +tree_mod_log_insert_move_47823 tree_mod_log_insert_move 5 47823 NULL
123301 +pinconf_dbg_config_write_47835 pinconf_dbg_config_write 3 47835 NULL
123302 +KEY_SIZE_47855 KEY_SIZE 0 47855 NULL
123303 +vhci_read_47878 vhci_read 3 47878 NULL
123304 +keyctl_instantiate_key_common_47889 keyctl_instantiate_key_common 4 47889 NULL
123305 +cfs_percpt_alloc_47918 cfs_percpt_alloc 2 47918 NULL
123306 +comedi_write_47926 comedi_write 3 47926 NULL
123307 +nvme_trans_get_blk_desc_len_47946 nvme_trans_get_blk_desc_len 0-2 47946 NULL
123308 +gether_get_ifname_47972 gether_get_ifname 3 47972 NULL
123309 +mempool_resize_47983 mempool_resize 2 47983 NULL nohasharray
123310 +iwl_dbgfs_ucode_tracing_read_47983 iwl_dbgfs_ucode_tracing_read 3 47983 &mempool_resize_47983
123311 +dbg_port_buf_47990 dbg_port_buf 2 47990 NULL
123312 +ib_umad_write_47993 ib_umad_write 3 47993 NULL
123313 +lustre_cfg_len_48002 lustre_cfg_len 0-1 48002 NULL
123314 +gdm_tty_recv_complete_48011 gdm_tty_recv_complete 2 48011 NULL
123315 +bio_integrity_set_tag_48035 bio_integrity_set_tag 3 48035 NULL
123316 +pppoe_sendmsg_48039 pppoe_sendmsg 4 48039 NULL
123317 +SYSC_writev_48040 SYSC_writev 3 48040 NULL
123318 +wpan_phy_alloc_48056 wpan_phy_alloc 1 48056 NULL
123319 +posix_acl_alloc_48063 posix_acl_alloc 1 48063 NULL
123320 +palmas_bulk_write_48068 palmas_bulk_write 2-3-5 48068 NULL
123321 +disc_write_48070 disc_write 3 48070 NULL
123322 +mmc_alloc_host_48097 mmc_alloc_host 1 48097 NULL
123323 +skb_copy_datagram_const_iovec_48102 skb_copy_datagram_const_iovec 4-2-5 48102 NULL
123324 +wm_latency_write_48125 wm_latency_write 3 48125 NULL
123325 +load_firmware_48128 load_firmware 2 48128 NULL
123326 +vmw_framebuffer_surface_dirty_48132 vmw_framebuffer_surface_dirty 6 48132 NULL
123327 +set_discoverable_48141 set_discoverable 4 48141 NULL
123328 +dn_fib_count_nhs_48145 dn_fib_count_nhs 0 48145 NULL
123329 +SyS_vmsplice_48150 SyS_vmsplice 3 48150 NULL
123330 +_add_to_r4w_48152 _add_to_r4w 4 48152 NULL
123331 +isr_dma1_done_read_48159 isr_dma1_done_read 3 48159 NULL
123332 +c4iw_id_table_alloc_48163 c4iw_id_table_alloc 3 48163 NULL
123333 +rbd_obj_method_sync_48170 rbd_obj_method_sync 8 48170 NULL
123334 +alloc_cc770dev_48186 alloc_cc770dev 1 48186 NULL
123335 +cfg80211_process_deauth_48200 cfg80211_process_deauth 3 48200 NULL
123336 +ext4_index_trans_blocks_48205 ext4_index_trans_blocks 0-2 48205 NULL
123337 +snd_seq_dump_var_event_48209 snd_seq_dump_var_event 0 48209 NULL
123338 +uv_blade_nr_possible_cpus_48226 uv_blade_nr_possible_cpus 0 48226 NULL
123339 +nilfs_readpages_48229 nilfs_readpages 4 48229 NULL
123340 +read_file_recv_48232 read_file_recv 3 48232 NULL
123341 +unaccount_shadowed_48233 unaccount_shadowed 2 48233 NULL
123342 +nouveau_i2c_port_create__48240 nouveau_i2c_port_create_ 7 48240 NULL
123343 +nfsctl_transaction_read_48250 nfsctl_transaction_read 3 48250 NULL
123344 +batadv_socket_read_48257 batadv_socket_read 3 48257 NULL
123345 +__videobuf_free_48260 __videobuf_free 0 48260 NULL
123346 +cache_write_pipefs_48270 cache_write_pipefs 3 48270 NULL
123347 +trace_options_write_48275 trace_options_write 3 48275 NULL
123348 +send_set_info_48288 send_set_info 7 48288 NULL
123349 +lpfc_idiag_extacc_read_48301 lpfc_idiag_extacc_read 3 48301 NULL
123350 +timblogiw_read_48305 timblogiw_read 3 48305 NULL
123351 +hash_setkey_48310 hash_setkey 3 48310 NULL
123352 +kvm_mmu_pte_write_48340 kvm_mmu_pte_write 2 48340 NULL
123353 +skb_add_data_48363 skb_add_data 3 48363 NULL
123354 +tx_frag_init_called_read_48377 tx_frag_init_called_read 3 48377 NULL
123355 +ath10k_read_htt_max_amsdu_ampdu_48401 ath10k_read_htt_max_amsdu_ampdu 3 48401 NULL
123356 +lbs_debugfs_write_48413 lbs_debugfs_write 3 48413 NULL
123357 +uhid_event_from_user_48417 uhid_event_from_user 2 48417 NULL
123358 +div64_u64_rem_48418 div64_u64_rem 0-1-2 48418 NULL
123359 +pwr_tx_without_ps_read_48423 pwr_tx_without_ps_read 3 48423 NULL
123360 +print_filtered_48442 print_filtered 2-0 48442 NULL
123361 +tun_recvmsg_48463 tun_recvmsg 4 48463 NULL
123362 +copy_page_from_iter_iovec_48466 copy_page_from_iter_iovec 3-0 48466 NULL
123363 +compat_SyS_preadv64_48469 compat_SyS_preadv64 3 48469 NULL
123364 +_iwl_dbgfs_bt_tx_prio_write_48473 _iwl_dbgfs_bt_tx_prio_write 3 48473 NULL
123365 +ipath_format_hwerrors_48487 ipath_format_hwerrors 5 48487 NULL
123366 +r8712_usbctrl_vendorreq_48489 r8712_usbctrl_vendorreq 6 48489 NULL
123367 +ocfs2_refcount_cow_48495 ocfs2_refcount_cow 3 48495 NULL
123368 +send_control_msg_48498 send_control_msg 6 48498 NULL
123369 +count_masked_bytes_48507 count_masked_bytes 0-1 48507 NULL
123370 +diva_os_copy_to_user_48508 diva_os_copy_to_user 4 48508 NULL
123371 +brcmf_sdio_trap_info_48510 brcmf_sdio_trap_info 4 48510 NULL
123372 +phantom_get_free_48514 phantom_get_free 0 48514 NULL
123373 +drbd_bm_capacity_48530 drbd_bm_capacity 0 48530 NULL
123374 +raid10_size_48571 raid10_size 0-2-3 48571 NULL
123375 +nvif_notify_init_48578 nvif_notify_init 7 48578 NULL
123376 +llog_data_len_48607 llog_data_len 1 48607 NULL
123377 +do_ip_vs_set_ctl_48641 do_ip_vs_set_ctl 4 48641 NULL
123378 +kernel_sock_ioctl_48644 kernel_sock_ioctl 0 48644 NULL
123379 +ll_rw_extents_stats_pp_seq_write_48651 ll_rw_extents_stats_pp_seq_write 3 48651 NULL
123380 +mtd_read_48655 mtd_read 0 48655 NULL
123381 +aes_encrypt_packets_read_48666 aes_encrypt_packets_read 3 48666 NULL
123382 +sm501_create_subdev_48668 sm501_create_subdev 3-4 48668 NULL
123383 +hysdn_log_write_48694 hysdn_log_write 3 48694 NULL
123384 +altera_drscan_48698 altera_drscan 2 48698 NULL
123385 +kvm_set_irq_routing_48704 kvm_set_irq_routing 3 48704 NULL
123386 +lpfc_idiag_drbacc_write_48712 lpfc_idiag_drbacc_write 3 48712 NULL
123387 +SyS_lgetxattr_48719 SyS_lgetxattr 4 48719 NULL
123388 +ath6kl_usb_bmi_read_48745 ath6kl_usb_bmi_read 3 48745 NULL
123389 +ath6kl_regwrite_read_48747 ath6kl_regwrite_read 3 48747 NULL
123390 +l2cap_segment_sdu_48772 l2cap_segment_sdu 4 48772 NULL
123391 +il3945_sta_dbgfs_stats_table_read_48802 il3945_sta_dbgfs_stats_table_read 3 48802 NULL
123392 +twa_change_queue_depth_48808 twa_change_queue_depth 2 48808 NULL
123393 +atomic_counters_read_48827 atomic_counters_read 3 48827 NULL
123394 +azx_get_position_48841 azx_get_position 0 48841 NULL
123395 +vc_do_resize_48842 vc_do_resize 3-4 48842 NULL
123396 +comedi_buf_write_alloc_48846 comedi_buf_write_alloc 0-2 48846 NULL
123397 +suspend_dtim_interval_write_48854 suspend_dtim_interval_write 3 48854 NULL
123398 +viafb_dvp1_proc_write_48864 viafb_dvp1_proc_write 3 48864 NULL nohasharray
123399 +C_SYSC_pwritev64_48864 C_SYSC_pwritev64 3 48864 &viafb_dvp1_proc_write_48864
123400 +__ffs_ep0_read_events_48868 __ffs_ep0_read_events 3 48868 NULL
123401 +crypto_cipher_ctxsize_48890 crypto_cipher_ctxsize 0 48890 NULL
123402 +joydev_handle_JSIOCSAXMAP_48898 joydev_handle_JSIOCSAXMAP 3 48898 NULL
123403 +xdi_copy_to_user_48900 xdi_copy_to_user 4 48900 NULL
123404 +msg_hdr_sz_48908 msg_hdr_sz 0 48908 NULL
123405 +sep_crypto_dma_48937 sep_crypto_dma 0 48937 NULL
123406 +si5351_write_parameters_48940 si5351_write_parameters 2 48940 NULL
123407 +event_heart_beat_read_48961 event_heart_beat_read 3 48961 NULL
123408 +nand_ecc_test_run_48966 nand_ecc_test_run 1 48966 NULL
123409 +vmci_handle_arr_create_48971 vmci_handle_arr_create 1 48971 NULL
123410 +nilfs_direct_IO_48981 nilfs_direct_IO 4 48981 NULL
123411 +rds_rm_size_48996 rds_rm_size 0-2 48996 NULL
123412 +sel_write_enforce_48998 sel_write_enforce 3 48998 NULL
123413 +null_alloc_rs_49019 null_alloc_rs 2 49019 NULL
123414 +filemap_check_errors_49022 filemap_check_errors 0 49022 NULL
123415 +transient_status_49027 transient_status 4 49027 NULL
123416 +ll_xattr_cache_add_49032 ll_xattr_cache_add 4-0 49032 NULL
123417 +scsi_register_49094 scsi_register 2 49094 NULL
123418 +compat_do_readv_writev_49102 compat_do_readv_writev 4 49102 NULL
123419 +xfrm_replay_state_esn_len_49119 xfrm_replay_state_esn_len 0 49119 NULL
123420 +ll_max_cached_mb_seq_write_49122 ll_max_cached_mb_seq_write 3 49122 NULL
123421 +pt_read_49136 pt_read 3 49136 NULL
123422 +ipwireless_tty_received_49154 ipwireless_tty_received 3 49154 NULL
123423 +f2fs_acl_count_49155 f2fs_acl_count 0-1 49155 NULL
123424 +ipw_queue_tx_init_49161 ipw_queue_tx_init 3 49161 NULL
123425 +__jfs_setxattr_49175 __jfs_setxattr 5 49175 NULL
123426 +ath6kl_bgscan_int_write_49178 ath6kl_bgscan_int_write 3 49178 NULL
123427 +dvb_dvr_ioctl_49182 dvb_dvr_ioctl 2 49182 NULL
123428 +print_queue_49191 print_queue 0-4 49191 NULL
123429 +root_nfs_cat_49192 root_nfs_cat 3 49192 NULL
123430 +iwl_dbgfs_ucode_general_stats_read_49199 iwl_dbgfs_ucode_general_stats_read 3 49199 NULL
123431 +il4965_rs_sta_dbgfs_stats_table_read_49206 il4965_rs_sta_dbgfs_stats_table_read 3 49206 NULL
123432 +do_jffs2_getxattr_49210 do_jffs2_getxattr 0 49210 NULL
123433 +nouveau_therm_create__49228 nouveau_therm_create_ 4 49228 NULL
123434 +ieee80211_if_read_rssi_threshold_49260 ieee80211_if_read_rssi_threshold 3 49260 NULL
123435 +isku_sysfs_read_keys_media_49268 isku_sysfs_read_keys_media 6 49268 NULL
123436 +ptlrpc_check_set_49277 ptlrpc_check_set 0 49277 NULL
123437 +rx_filter_beacon_filter_read_49279 rx_filter_beacon_filter_read 3 49279 NULL
123438 +viafb_dfph_proc_write_49288 viafb_dfph_proc_write 3 49288 NULL
123439 +uio_read_49300 uio_read 3 49300 NULL
123440 +isku_sysfs_read_keys_macro_49312 isku_sysfs_read_keys_macro 6 49312 NULL
123441 +SYSC_mincore_49319 SYSC_mincore 2-1 49319 NULL
123442 +fwtty_port_handler_49327 fwtty_port_handler 9 49327 NULL
123443 +srpt_alloc_ioctx_ring_49330 srpt_alloc_ioctx_ring 2-4-3 49330 NULL
123444 +joydev_ioctl_common_49359 joydev_ioctl_common 2 49359 NULL
123445 +iscsi_alloc_session_49390 iscsi_alloc_session 3 49390 NULL
123446 +ext4_ext_index_trans_blocks_49396 ext4_ext_index_trans_blocks 0 49396 NULL
123447 +rx_streaming_always_read_49401 rx_streaming_always_read 3 49401 NULL
123448 +tnode_alloc_49407 tnode_alloc 1 49407 NULL
123449 +samples_to_bytes_49426 samples_to_bytes 0-2 49426 NULL
123450 +compat_do_msg_fill_49440 compat_do_msg_fill 3 49440 NULL
123451 +__hfsplus_getxattr_49460 __hfsplus_getxattr 0 49460 NULL
123452 +agp_3_5_isochronous_node_enable_49465 agp_3_5_isochronous_node_enable 3 49465 NULL
123453 +xfs_iformat_local_49472 xfs_iformat_local 4 49472 NULL
123454 +tipc_bclink_get_mtu_49483 tipc_bclink_get_mtu 0 49483 NULL
123455 +isr_decrypt_done_read_49490 isr_decrypt_done_read 3 49490 NULL
123456 +iwl_dbgfs_disable_power_off_read_49517 iwl_dbgfs_disable_power_off_read 3 49517 NULL
123457 +SyS_listxattr_49519 SyS_listxattr 3 49519 NULL
123458 +emulator_write_phys_49520 emulator_write_phys 2-4 49520 NULL
123459 +smk_write_access_49561 smk_write_access 3 49561 NULL
123460 +alloc_chunk_49575 alloc_chunk 1 49575 NULL
123461 +sctp_setsockopt_default_send_param_49578 sctp_setsockopt_default_send_param 3 49578 NULL
123462 +readfifo_49583 readfifo 1 49583 NULL
123463 +tap_write_49595 tap_write 3 49595 NULL
123464 +isr_wakeups_read_49607 isr_wakeups_read 3 49607 NULL
123465 +btrfs_mksubvol_49616 btrfs_mksubvol 3 49616 NULL
123466 +heap_init_49617 heap_init 2 49617 NULL
123467 +smk_write_doi_49621 smk_write_doi 3 49621 NULL
123468 +port_fops_read_49626 port_fops_read 3 49626 NULL
123469 +btrfsic_cmp_log_and_dev_bytenr_49628 btrfsic_cmp_log_and_dev_bytenr 2 49628 NULL
123470 +aa_simple_write_to_buffer_49683 aa_simple_write_to_buffer 3-4 49683 NULL
123471 +SyS_pwritev_49688 SyS_pwritev 3 49688 NULL
123472 +__copy_from_user_nocheck_49699 __copy_from_user_nocheck 0-3 49699 NULL
123473 +cx2341x_ctrl_new_menu_49700 cx2341x_ctrl_new_menu 3 49700 NULL
123474 +write_pool_49718 write_pool 3 49718 NULL
123475 +kvm_mmu_notifier_invalidate_page_49723 kvm_mmu_notifier_invalidate_page 3 49723 NULL nohasharray
123476 +sfw_create_test_rpc_49723 sfw_create_test_rpc 4 49723 &kvm_mmu_notifier_invalidate_page_49723
123477 +sep_create_dcb_dmatables_context_kernel_49728 sep_create_dcb_dmatables_context_kernel 6 49728 NULL
123478 +zd_usb_iowrite16v_49744 zd_usb_iowrite16v 3 49744 NULL
123479 +btrfs_chunk_num_stripes_49751 btrfs_chunk_num_stripes 0 49751 NULL
123480 +fuse_wr_pages_49753 fuse_wr_pages 0-1-2 49753 NULL
123481 +key_conf_keylen_read_49758 key_conf_keylen_read 3 49758 NULL
123482 +fuse_conn_waiting_read_49762 fuse_conn_waiting_read 3 49762 NULL
123483 +w83977af_fir_interrupt_49775 w83977af_fir_interrupt 0 49775 NULL
123484 +ceph_osdc_readpages_49789 ceph_osdc_readpages 0 49789 NULL
123485 +nfs4_acl_new_49806 nfs4_acl_new 1 49806 NULL
123486 +__of_parse_phandle_with_args_49807 __of_parse_phandle_with_args 0 49807 NULL
123487 +ntfs_copy_from_user_iovec_49829 ntfs_copy_from_user_iovec 3-6-0 49829 NULL
123488 +add_uuid_49831 add_uuid 4 49831 NULL
123489 +iraw_loop_49842 iraw_loop 0-1 49842 NULL
123490 +twl4030_write_49846 twl4030_write 2 49846 NULL
123491 +scsi_dispatch_cmd_entry_49848 scsi_dispatch_cmd_entry 3 49848 NULL
123492 +timeradd_entry_49850 timeradd_entry 3 49850 NULL
123493 +fiemap_count_to_size_49869 fiemap_count_to_size 0-1 49869 NULL
123494 +sctp_setsockopt_bindx_49870 sctp_setsockopt_bindx 3 49870 NULL
123495 +osc_brw_49896 osc_brw 4 49896 NULL
123496 +fuse_send_write_49915 fuse_send_write 4-0 49915 NULL
123497 +ieee80211_if_fmt_dtim_count_49987 ieee80211_if_fmt_dtim_count 3 49987 NULL
123498 +drm_buffer_copy_from_user_49990 drm_buffer_copy_from_user 3 49990 NULL
123499 +l2cap_chan_send_49995 l2cap_chan_send 3 49995 NULL
123500 +dn_mss_from_pmtu_50011 dn_mss_from_pmtu 0-2 50011 NULL
123501 +security_context_to_sid_50019 security_context_to_sid 2 50019 NULL
123502 +isdn_read_50021 isdn_read 3 50021 NULL
123503 +mdc_rename_pack_50023 mdc_rename_pack 4-6 50023 NULL
123504 +brcmf_debugfs_chipinfo_read_50033 brcmf_debugfs_chipinfo_read 3 50033 NULL
123505 +ioread8_50049 ioread8 0 50049 NULL
123506 +fuse_conn_max_background_write_50061 fuse_conn_max_background_write 3 50061 NULL
123507 +__kfifo_dma_in_prepare_50081 __kfifo_dma_in_prepare 4 50081 NULL
123508 +dev_set_alias_50084 dev_set_alias 3 50084 NULL
123509 +libcfs_ioctl_popdata_50087 libcfs_ioctl_popdata 3 50087 NULL
123510 +sock_setsockopt_50088 sock_setsockopt 5 50088 NULL
123511 +altera_swap_dr_50090 altera_swap_dr 2 50090 NULL
123512 +android_set_cntry_50100 android_set_cntry 0 50100 NULL
123513 +read_file_slot_50111 read_file_slot 3 50111 NULL
123514 +rx_streaming_interval_write_50120 rx_streaming_interval_write 3 50120 NULL
123515 +SYSC_preadv_50134 SYSC_preadv 3 50134 NULL
123516 +tx_frag_need_fragmentation_read_50153 tx_frag_need_fragmentation_read 3 50153 NULL
123517 +kmalloc_node_50163 kmalloc_node 1 50163 NULL
123518 +rx_filter_ibss_filter_read_50167 rx_filter_ibss_filter_read 3 50167 NULL
123519 +ahd_probe_stack_size_50168 ahd_probe_stack_size 0 50168 NULL
123520 +odev_update_50169 odev_update 2 50169 NULL
123521 +ubi_resize_volume_50172 ubi_resize_volume 2 50172 NULL nohasharray
123522 +ieee80211_if_fmt_dot11MeshHWMPRannInterval_50172 ieee80211_if_fmt_dot11MeshHWMPRannInterval 3 50172 &ubi_resize_volume_50172
123523 +cfg80211_roamed_bss_50198 cfg80211_roamed_bss 4-6 50198 NULL
123524 +cyttsp4_probe_50201 cyttsp4_probe 4 50201 NULL
123525 +rx_rx_timeout_wa_read_50204 rx_rx_timeout_wa_read 3 50204 NULL
123526 +l2cap_sock_setsockopt_50207 l2cap_sock_setsockopt 5 50207 NULL
123527 +mon_bin_compat_ioctl_50234 mon_bin_compat_ioctl 3 50234 NULL
123528 +sg_kmalloc_50240 sg_kmalloc 1 50240 NULL
123529 +rxrpc_setsockopt_50286 rxrpc_setsockopt 5 50286 NULL
123530 +soc_codec_reg_show_50302 soc_codec_reg_show 0-3 50302 NULL
123531 +SYSC_flistxattr_50307 SYSC_flistxattr 3 50307 NULL
123532 +SYSC_sched_setaffinity_50310 SYSC_sched_setaffinity 2 50310 NULL
123533 +soc_camera_read_50319 soc_camera_read 3 50319 NULL
123534 +do_launder_page_50329 do_launder_page 0 50329 NULL
123535 +nouveau_engine_create__50331 nouveau_engine_create_ 7 50331 NULL
123536 +lpfc_idiag_pcicfg_read_50334 lpfc_idiag_pcicfg_read 3 50334 NULL
123537 +snd_pcm_lib_writev_50337 snd_pcm_lib_writev 0-3 50337 NULL
123538 +tpm_read_50344 tpm_read 3 50344 NULL
123539 +isdn_ppp_read_50356 isdn_ppp_read 4 50356 NULL
123540 +iwl_dbgfs_echo_test_write_50362 iwl_dbgfs_echo_test_write 3 50362 NULL
123541 +xfrm_send_migrate_50365 xfrm_send_migrate 5 50365 NULL
123542 +roccat_common2_receive_50369 roccat_common2_receive 4 50369 NULL
123543 +sl_alloc_bufs_50380 sl_alloc_bufs 2 50380 NULL
123544 +l2tp_ip_sendmsg_50411 l2tp_ip_sendmsg 4 50411 NULL
123545 +iscsi_create_conn_50425 iscsi_create_conn 2 50425 NULL
123546 +validate_acl_mac_addrs_50429 validate_acl_mac_addrs 0 50429 NULL
123547 +btrfs_error_discard_extent_50444 btrfs_error_discard_extent 2 50444 NULL
123548 +pgctrl_write_50453 pgctrl_write 3 50453 NULL
123549 +device_create_sys_dev_entry_50458 device_create_sys_dev_entry 0 50458 NULL
123550 +cfs_size_round_50472 cfs_size_round 0-1 50472 NULL
123551 +cdrom_read_cdda_50478 cdrom_read_cdda 4 50478 NULL
123552 +mei_io_cb_alloc_req_buf_50493 mei_io_cb_alloc_req_buf 2 50493 NULL
123553 +pwr_rcvd_awake_beacons_read_50505 pwr_rcvd_awake_beacons_read 3 50505 NULL
123554 +ath6kl_set_ap_probe_resp_ies_50539 ath6kl_set_ap_probe_resp_ies 3 50539 NULL
123555 +trigger_request_store_50548 trigger_request_store 4 50548 NULL
123556 +usbat_flash_write_data_50553 usbat_flash_write_data 4 50553 NULL
123557 +fat_readpages_50582 fat_readpages 4 50582 NULL
123558 +iwl_dbgfs_missed_beacon_read_50584 iwl_dbgfs_missed_beacon_read 3 50584 NULL
123559 +xillybus_write_50605 xillybus_write 3 50605 NULL
123560 +rx_rx_checksum_result_read_50617 rx_rx_checksum_result_read 3 50617 NULL
123561 +sparse_early_usemaps_alloc_node_50623 sparse_early_usemaps_alloc_node 4 50623 NULL
123562 +simple_transaction_get_50633 simple_transaction_get 3 50633 NULL
123563 +ath6kl_tm_rx_event_50664 ath6kl_tm_rx_event 3 50664 NULL
123564 +bnad_debugfs_read_50665 bnad_debugfs_read 3 50665 NULL
123565 +prism2_read_fid_reg_50689 prism2_read_fid_reg 0 50689 NULL
123566 +xfs_growfs_get_hdr_buf_50697 xfs_growfs_get_hdr_buf 3 50697 NULL
123567 +dev_mem_read_50706 dev_mem_read 3 50706 NULL
123568 +blk_check_plugged_50736 blk_check_plugged 3 50736 NULL
123569 +__ext3_get_inode_loc_50744 __ext3_get_inode_loc 0 50744 NULL
123570 +ocfs2_xattr_block_get_50773 ocfs2_xattr_block_get 0 50773 NULL
123571 +tm6000_read_write_usb_50774 tm6000_read_write_usb 7 50774 NULL
123572 +tpm_write_50798 tpm_write 3 50798 NULL
123573 +tun_do_read_50800 tun_do_read 4 50800 NULL
123574 +write_flush_50803 write_flush 3 50803 NULL
123575 +dvb_play_50814 dvb_play 3 50814 NULL
123576 +btrfs_stack_file_extent_disk_num_bytes_50825 btrfs_stack_file_extent_disk_num_bytes 0 50825 NULL
123577 +dpcm_show_state_50827 dpcm_show_state 0 50827 NULL
123578 +SetArea_50835 SetArea 4 50835 NULL
123579 +nft_trans_alloc_50836 nft_trans_alloc 3 50836 NULL
123580 +videobuf_dma_init_user_50839 videobuf_dma_init_user 4-3 50839 NULL
123581 +carl9170_debugfs_write_50857 carl9170_debugfs_write 3 50857 NULL
123582 +SyS_lgetxattr_50889 SyS_lgetxattr 4 50889 NULL
123583 +netlbl_secattr_catmap_walk_rng_50894 netlbl_secattr_catmap_walk_rng 0-2 50894 NULL
123584 +__bdev_writeseg_50903 __bdev_writeseg 4 50903 NULL
123585 +xfs_iext_remove_50909 xfs_iext_remove 3 50909 NULL
123586 +blk_rq_cur_sectors_50910 blk_rq_cur_sectors 0 50910 NULL
123587 +hash_recvmsg_50924 hash_recvmsg 4 50924 NULL
123588 +chd_dec_fetch_cdata_50926 chd_dec_fetch_cdata 3 50926 NULL
123589 +show_device_status_50947 show_device_status 0 50947 NULL
123590 +irq_timeout_write_50950 irq_timeout_write 3 50950 NULL
123591 +virtio_cread16_50951 virtio_cread16 0 50951 NULL
123592 +sdio_uart_write_50954 sdio_uart_write 3 50954 NULL
123593 +SyS_setxattr_50957 SyS_setxattr 4 50957 NULL
123594 +of_modalias_node_50975 of_modalias_node 3 50975 NULL
123595 +iwl_statistics_flag_50981 iwl_statistics_flag 0-3 50981 NULL
123596 +timeout_write_50991 timeout_write 3 50991 NULL
123597 +proc_write_51003 proc_write 3 51003 NULL
123598 +jbd2_journal_extend_51012 jbd2_journal_extend 2 51012 NULL
123599 +lbs_dev_info_51023 lbs_dev_info 3 51023 NULL
123600 +fuse_conn_congestion_threshold_read_51028 fuse_conn_congestion_threshold_read 3 51028 NULL
123601 +BcmGetSectionValEndOffset_51039 BcmGetSectionValEndOffset 0 51039 NULL
123602 +dump_midi_51040 dump_midi 3 51040 NULL
123603 +usb_get_descriptor_51041 usb_get_descriptor 0 51041 NULL
123604 +srpt_alloc_ioctx_51042 srpt_alloc_ioctx 2-3 51042 NULL
123605 +do_arpt_set_ctl_51053 do_arpt_set_ctl 4 51053 NULL
123606 +wusb_prf_64_51065 wusb_prf_64 7 51065 NULL
123607 +jbd2_journal_init_revoke_51088 jbd2_journal_init_revoke 2 51088 NULL
123608 +__ocfs2_find_path_51096 __ocfs2_find_path 0 51096 NULL
123609 +ti_recv_51110 ti_recv 3 51110 NULL
123610 +alloc_rtllib_51136 alloc_rtllib 1 51136 NULL
123611 +simple_xattr_set_51140 simple_xattr_set 4 51140 NULL
123612 +xfs_trans_get_efd_51148 xfs_trans_get_efd 3 51148 NULL
123613 +iwl_dbgfs_bcast_filters_macs_read_51231 iwl_dbgfs_bcast_filters_macs_read 3 51231 NULL
123614 +nf_ct_ext_create_51232 nf_ct_ext_create 3 51232 NULL
123615 +snd_pcm_write_51235 snd_pcm_write 3 51235 NULL
123616 +drm_property_create_51239 drm_property_create 4 51239 NULL
123617 +st_read_51251 st_read 3 51251 NULL
123618 +compat_dccp_setsockopt_51263 compat_dccp_setsockopt 5 51263 NULL
123619 +target_alloc_sgl_51264 target_alloc_sgl 3 51264 NULL
123620 +dvb_audio_write_51275 dvb_audio_write 3 51275 NULL
123621 +ipwireless_network_packet_received_51277 ipwireless_network_packet_received 4 51277 NULL
123622 +pvr2_std_id_to_str_51288 pvr2_std_id_to_str 2 51288 NULL
123623 +bnad_debugfs_read_regrd_51308 bnad_debugfs_read_regrd 3 51308 NULL
123624 +init_map_ipmac_51317 init_map_ipmac 5 51317 NULL
123625 +alloc_hippi_dev_51320 alloc_hippi_dev 1 51320 NULL
123626 +ext2_xattr_get_51327 ext2_xattr_get 0 51327 NULL
123627 +smk_write_ptrace_51333 smk_write_ptrace 3 51333 NULL
123628 +alloc_smp_req_51337 alloc_smp_req 1 51337 NULL
123629 +ipw_get_event_log_len_51341 ipw_get_event_log_len 0 51341 NULL
123630 +ieee80211_if_fmt_estab_plinks_51370 ieee80211_if_fmt_estab_plinks 3 51370 NULL
123631 +radeon_kms_compat_ioctl_51371 radeon_kms_compat_ioctl 2 51371 NULL
123632 +blk_register_region_51424 blk_register_region 1-2 51424 NULL
123633 +mwifiex_rdeeprom_read_51429 mwifiex_rdeeprom_read 3 51429 NULL
123634 +hfsplus_brec_read_51436 hfsplus_brec_read 0 51436 NULL
123635 +ieee80211_if_read_dot11MeshHWMPRootMode_51441 ieee80211_if_read_dot11MeshHWMPRootMode 3 51441 NULL
123636 +print_devstats_dot11ACKFailureCount_51443 print_devstats_dot11ACKFailureCount 3 51443 NULL
123637 +____alloc_ei_netdev_51475 ____alloc_ei_netdev 1 51475 NULL
123638 +xfs_buf_get_uncached_51477 xfs_buf_get_uncached 2 51477 NULL
123639 +osc_brw_internal_51489 osc_brw_internal 5 51489 NULL
123640 +kvm_fetch_guest_virt_51493 kvm_fetch_guest_virt 4-2 51493 NULL
123641 +ieee80211_if_write_uapsd_queues_51526 ieee80211_if_write_uapsd_queues 3 51526 NULL
123642 +__alloc_eip_netdev_51549 __alloc_eip_netdev 1 51549 NULL
123643 +batadv_tt_prepare_tvlv_local_data_51568 batadv_tt_prepare_tvlv_local_data 0 51568 NULL
123644 +ixgb_get_eeprom_len_51586 ixgb_get_eeprom_len 0 51586 NULL
123645 +aac_convert_sgraw2_51598 aac_convert_sgraw2 4 51598 NULL
123646 +table_size_to_number_of_entries_51613 table_size_to_number_of_entries 0-1 51613 NULL
123647 +extent_fiemap_51621 extent_fiemap 3 51621 NULL
123648 +sctp_auth_create_key_51641 sctp_auth_create_key 1 51641 NULL
123649 +iscsi_create_session_51647 iscsi_create_session 3 51647 NULL
123650 +ps_upsd_utilization_read_51669 ps_upsd_utilization_read 3 51669 NULL
123651 +sctp_setsockopt_associnfo_51684 sctp_setsockopt_associnfo 3 51684 NULL
123652 +rtw_os_xmit_resource_alloc23a_51693 rtw_os_xmit_resource_alloc23a 3 51693 NULL
123653 +host_mapping_level_51696 host_mapping_level 0 51696 NULL
123654 +sel_write_access_51704 sel_write_access 3 51704 NULL
123655 +tty_cdev_add_51714 tty_cdev_add 2-4 51714 NULL
123656 +v9fs_alloc_rdir_buf_51716 v9fs_alloc_rdir_buf 2 51716 NULL
123657 +drm_compat_ioctl_51717 drm_compat_ioctl 2 51717 NULL
123658 +sg_read_oxfer_51724 sg_read_oxfer 3 51724 NULL
123659 +str_read_51731 str_read 4 51731 NULL
123660 +cm4040_read_51732 cm4040_read 3 51732 NULL
123661 +get_user_pages_fast_51751 get_user_pages_fast 0 51751 NULL
123662 +ifx_spi_insert_flip_string_51752 ifx_spi_insert_flip_string 3 51752 NULL
123663 +if_write_51756 if_write 3 51756 NULL
123664 +ssd1307fb_alloc_array_51788 ssd1307fb_alloc_array 1 51788 NULL
123665 +qib_alloc_devdata_51819 qib_alloc_devdata 2 51819 NULL
123666 +buffer_from_user_51826 buffer_from_user 3 51826 NULL
123667 +ioread32_51847 ioread32 0 51847 NULL nohasharray
123668 +read_file_tgt_tx_stats_51847 read_file_tgt_tx_stats 3 51847 &ioread32_51847
123669 +do_readv_writev_51849 do_readv_writev 4 51849 NULL
123670 +SYSC_sendto_51852 SYSC_sendto 6 51852 NULL
123671 +bm_page_io_async_51858 bm_page_io_async 2 51858 NULL
123672 +pointer_size_read_51863 pointer_size_read 3 51863 NULL
123673 +get_indirect_ea_51869 get_indirect_ea 4 51869 NULL
123674 +user_read_51881 user_read 3 51881 NULL
123675 +dbAdjCtl_51888 dbAdjCtl 0 51888 NULL
123676 +SyS_mq_timedsend_51896 SyS_mq_timedsend 3 51896 NULL
123677 +wmi_set_ie_51919 wmi_set_ie 3 51919 NULL
123678 +dbg_status_buf_51930 dbg_status_buf 2 51930 NULL
123679 +__tcp_mtu_to_mss_51938 __tcp_mtu_to_mss 0-2 51938 NULL
123680 +xfrm_alg_len_51940 xfrm_alg_len 0 51940 NULL
123681 +scsi_get_vpd_page_51951 scsi_get_vpd_page 4 51951 NULL
123682 +get_clock_info_51952 get_clock_info 4 51952 NULL
123683 +snd_mask_min_51969 snd_mask_min 0 51969 NULL
123684 +get_zone_51981 get_zone 0-1 51981 NULL
123685 +ath6kl_sdio_alloc_prep_scat_req_51986 ath6kl_sdio_alloc_prep_scat_req 2 51986 NULL
123686 +_c4iw_write_mem_dma_51991 _c4iw_write_mem_dma 3 51991 NULL
123687 +dwc3_mode_write_51997 dwc3_mode_write 3 51997 NULL
123688 +skb_copy_datagram_from_iovec_52014 skb_copy_datagram_from_iovec 4-2-5 52014 NULL
123689 +rdmalt_52022 rdmalt 0 52022 NULL
123690 +override_release_52032 override_release 2 52032 NULL
123691 +end_port_52042 end_port 0 52042 NULL
123692 +dma_rx_errors_read_52045 dma_rx_errors_read 3 52045 NULL
123693 +msnd_fifo_write_52052 msnd_fifo_write 0-3 52052 NULL
123694 +dvb_ringbuffer_avail_52057 dvb_ringbuffer_avail 0 52057 NULL
123695 +__fuse_request_alloc_52060 __fuse_request_alloc 1 52060 NULL
123696 +isofs_readpages_52067 isofs_readpages 4 52067 NULL
123697 +mxuport_process_read_urb_data_52072 mxuport_process_read_urb_data 3 52072 NULL
123698 +nsm_get_handle_52089 nsm_get_handle 4 52089 NULL
123699 +o2net_debug_read_52105 o2net_debug_read 3 52105 NULL
123700 +smsdvb_stats_read_52114 smsdvb_stats_read 3 52114 NULL
123701 +split_scan_timeout_write_52128 split_scan_timeout_write 3 52128 NULL
123702 +retry_count_read_52129 retry_count_read 3 52129 NULL
123703 +gdm_usb_hci_send_52138 gdm_usb_hci_send 3 52138 NULL
123704 +sub_alloc_52140 sub_alloc 0 52140 NULL
123705 +hysdn_conf_write_52145 hysdn_conf_write 3 52145 NULL
123706 +htable_size_52148 htable_size 0-1 52148 NULL
123707 +smk_write_load2_52155 smk_write_load2 3 52155 NULL
123708 +tipc_node_get_mtu_52157 tipc_node_get_mtu 0 52157 NULL
123709 +ieee80211_if_read_dot11MeshRetryTimeout_52168 ieee80211_if_read_dot11MeshRetryTimeout 3 52168 NULL
123710 +mga_compat_ioctl_52170 mga_compat_ioctl 2 52170 NULL
123711 +print_prefix_52176 print_prefix 0 52176 NULL
123712 +proc_pid_readlink_52186 proc_pid_readlink 3 52186 NULL
123713 +reiserfs_posix_acl_from_disk_52191 reiserfs_posix_acl_from_disk 2 52191 NULL
123714 +f2fs_seek_block_52194 f2fs_seek_block 2 52194 NULL
123715 +vmci_qp_broker_alloc_52216 vmci_qp_broker_alloc 6-5 52216 NULL
123716 +fuse_request_alloc_52243 fuse_request_alloc 1 52243 NULL
123717 +mdiobus_alloc_size_52259 mdiobus_alloc_size 1 52259 NULL
123718 +shrink_slab_52261 shrink_slab 2 52261 NULL
123719 +ext2_direct_IO_52270 ext2_direct_IO 4 52270 NULL
123720 +sisusbcon_do_font_op_52271 sisusbcon_do_font_op 9 52271 NULL
123721 +handle_supp_msgs_52284 handle_supp_msgs 4 52284 NULL
123722 +kobject_set_name_vargs_52309 kobject_set_name_vargs 0 52309 NULL
123723 +read_file_reset_52310 read_file_reset 3 52310 NULL
123724 +ssd1307fb_write_52315 ssd1307fb_write 3 52315 NULL
123725 +request_asymmetric_key_52317 request_asymmetric_key 2-4 52317 NULL
123726 +hwflags_read_52318 hwflags_read 3 52318 NULL
123727 +test_unaligned_bulk_52333 test_unaligned_bulk 3 52333 NULL
123728 +hur_len_52339 hur_len 0 52339 NULL
123729 +bytes_to_frames_52362 bytes_to_frames 0-2 52362 NULL
123730 +copy_entries_to_user_52367 copy_entries_to_user 1 52367 NULL
123731 +iwl_dump_fh_52371 iwl_dump_fh 0 52371 NULL
123732 +hfsplus_find_attr_52374 hfsplus_find_attr 0 52374 NULL
123733 +mq_emit_config_values_52378 mq_emit_config_values 3 52378 NULL
123734 +isdn_writebuf_stub_52383 isdn_writebuf_stub 4 52383 NULL
123735 +jfs_setxattr_52389 jfs_setxattr 4 52389 NULL
123736 +aer_inject_write_52399 aer_inject_write 3 52399 NULL
123737 +line6_midibuf_init_52425 line6_midibuf_init 2 52425 NULL
123738 +hso_serial_common_create_52428 hso_serial_common_create 4 52428 NULL
123739 +delay_status_52431 delay_status 5 52431 NULL
123740 +ath6kl_delete_qos_write_52435 ath6kl_delete_qos_write 3 52435 NULL
123741 +ieee80211_if_fmt_num_sta_ps_52438 ieee80211_if_fmt_num_sta_ps 3 52438 NULL
123742 +alauda_read_data_52452 alauda_read_data 3 52452 NULL
123743 +bt_alloc_52457 bt_alloc 2 52457 NULL
123744 +ieee80211_alloc_txb_52477 ieee80211_alloc_txb 1 52477 NULL
123745 +usb_tranzport_write_52479 usb_tranzport_write 3 52479 NULL
123746 +ocfs2_extend_no_holes_52483 ocfs2_extend_no_holes 3-4 52483 NULL
123747 +fd_do_rw_52495 fd_do_rw 3 52495 NULL
123748 +int_tasklet_entry_52500 int_tasklet_entry 3 52500 NULL
123749 +lmv_get_easize_52504 lmv_get_easize 0 52504 NULL
123750 +pm_qos_power_write_52513 pm_qos_power_write 3 52513 NULL
123751 +bt_sock_stream_recvmsg_52518 bt_sock_stream_recvmsg 4 52518 NULL
123752 +dup_variable_bug_52525 dup_variable_bug 3 52525 NULL
123753 +raw_recvmsg_52529 raw_recvmsg 4 52529 NULL
123754 +SyS_vmsplice_52540 SyS_vmsplice 3 52540 NULL
123755 +dccpprobe_read_52549 dccpprobe_read 3 52549 NULL
123756 +debug_level_proc_write_52572 debug_level_proc_write 3 52572 NULL
123757 +isku_sysfs_read_macro_52587 isku_sysfs_read_macro 6 52587 NULL
123758 +SyS_setsockopt_52610 SyS_setsockopt 5 52610 NULL
123759 +ll_sa_entry_alloc_52611 ll_sa_entry_alloc 4 52611 NULL
123760 +tps80031_writes_52638 tps80031_writes 3-4 52638 NULL
123761 +brcmf_sdio_assert_info_52653 brcmf_sdio_assert_info 4 52653 NULL
123762 +nvme_queue_extra_52661 nvme_queue_extra 0-1 52661 NULL
123763 +SYSC_gethostname_52677 SYSC_gethostname 2 52677 NULL
123764 +nvd0_disp_pioc_create__52693 nvd0_disp_pioc_create_ 5 52693 NULL
123765 +nouveau_client_create__52715 nouveau_client_create_ 5 52715 NULL
123766 +__dm_stat_bio_52722 __dm_stat_bio 3 52722 NULL
123767 +cx25840_ir_rx_read_52724 cx25840_ir_rx_read 3 52724 NULL
123768 +blkcipher_next_slow_52733 blkcipher_next_slow 3-4 52733 NULL
123769 +relay_alloc_page_array_52735 relay_alloc_page_array 1 52735 NULL
123770 +hfcsusb_rx_frame_52745 hfcsusb_rx_frame 3 52745 NULL
123771 +carl9170_debugfs_vif_dump_read_52755 carl9170_debugfs_vif_dump_read 3 52755 NULL
123772 +ieee80211_if_read_beacon_timeout_52756 ieee80211_if_read_beacon_timeout 3 52756 NULL
123773 +nvme_trans_ext_inq_page_52776 nvme_trans_ext_inq_page 3 52776 NULL
123774 +xenvif_write_io_ring_52802 xenvif_write_io_ring 3 52802 NULL
123775 +pwr_rcvd_beacons_read_52836 pwr_rcvd_beacons_read 3 52836 NULL
123776 +lb_alloc_ep_req_52837 lb_alloc_ep_req 2 52837 NULL
123777 +mon_bin_get_event_52863 mon_bin_get_event 4-6 52863 NULL
123778 +twl6030_gpadc_write_52867 twl6030_gpadc_write 1 52867 NULL
123779 +qib_decode_6120_err_52876 qib_decode_6120_err 3 52876 NULL
123780 +twlreg_write_52880 twlreg_write 3 52880 NULL
123781 +pvr2_ctrl_value_to_sym_internal_52881 pvr2_ctrl_value_to_sym_internal 5 52881 NULL
123782 +cache_read_procfs_52882 cache_read_procfs 3 52882 NULL
123783 +kvm_kvzalloc_52894 kvm_kvzalloc 1 52894 NULL
123784 +dio_bio_reap_52913 dio_bio_reap 0 52913 NULL
123785 +__kfifo_out_peek_r_52919 __kfifo_out_peek_r 3 52919 NULL
123786 +iblock_get_bio_52936 iblock_get_bio 3 52936 NULL
123787 +__nodes_remap_52951 __nodes_remap 5 52951 NULL
123788 +ieee80211_if_fmt_fwded_mcast_52961 ieee80211_if_fmt_fwded_mcast 3 52961 NULL
123789 +tx_tx_exch_read_52986 tx_tx_exch_read 3 52986 NULL
123790 +num_node_state_52989 num_node_state 0 52989 NULL
123791 +efivarfs_file_write_53000 efivarfs_file_write 3 53000 NULL
123792 +btrfs_free_and_pin_reserved_extent_53016 btrfs_free_and_pin_reserved_extent 2 53016 NULL
123793 +tx_tx_exch_pending_read_53018 tx_tx_exch_pending_read 3 53018 NULL
123794 +bio_cur_bytes_53037 bio_cur_bytes 0 53037 NULL
123795 +nv50_chan_create_53039 nv50_chan_create 5 53039 NULL
123796 +regcache_lzo_block_count_53056 regcache_lzo_block_count 0 53056 NULL
123797 +cfi_read_query_53066 cfi_read_query 0 53066 NULL
123798 +iwl_dbgfs_interrupt_write_53069 iwl_dbgfs_interrupt_write 3 53069 NULL
123799 +mwifiex_debug_read_53074 mwifiex_debug_read 3 53074 NULL
123800 +mic_virtio_copy_from_user_53107 mic_virtio_copy_from_user 3 53107 NULL
123801 +verity_status_53120 verity_status 5 53120 NULL
123802 +brcmf_usb_dl_cmd_53130 brcmf_usb_dl_cmd 4 53130 NULL
123803 +ps_poll_ps_poll_max_ap_turn_read_53140 ps_poll_ps_poll_max_ap_turn_read 3 53140 NULL
123804 +copy_user_segment_list_53150 copy_user_segment_list 2 53150 NULL
123805 +ieee80211_bss_info_update_53170 ieee80211_bss_info_update 4 53170 NULL
123806 +btrfs_io_bio_alloc_53179 btrfs_io_bio_alloc 2 53179 NULL
123807 +clear_capture_buf_53192 clear_capture_buf 2 53192 NULL
123808 +tx_tx_start_data_read_53219 tx_tx_start_data_read 3 53219 NULL
123809 +ptlrpc_lprocfs_req_history_max_seq_write_53243 ptlrpc_lprocfs_req_history_max_seq_write 3 53243 NULL
123810 +xfs_trans_read_buf_map_53258 xfs_trans_read_buf_map 5 53258 NULL
123811 +wil_write_file_ssid_53266 wil_write_file_ssid 3 53266 NULL
123812 +btrfs_file_extent_num_bytes_53269 btrfs_file_extent_num_bytes 0 53269 NULL
123813 +f2fs_fiemap_53310 f2fs_fiemap 4 53310 NULL
123814 +ftrace_profile_write_53327 ftrace_profile_write 3 53327 NULL
123815 +find_nr_power_limit_53330 find_nr_power_limit 0 53330 NULL
123816 +gsm_control_reply_53333 gsm_control_reply 4 53333 NULL
123817 +btree_keys_bytes_53348 btree_keys_bytes 0 53348 NULL
123818 +sock_setbindtodevice_53369 sock_setbindtodevice 3 53369 NULL
123819 +get_random_bytes_arch_53370 get_random_bytes_arch 2 53370 NULL
123820 +test_fw_misc_read_53384 test_fw_misc_read 3 53384 NULL
123821 +isr_cmd_cmplt_read_53439 isr_cmd_cmplt_read 3 53439 NULL
123822 +mwifiex_info_read_53447 mwifiex_info_read 3 53447 NULL
123823 +apei_exec_run_optional_53452 apei_exec_run_optional 0 53452 NULL
123824 +paging64_prefetch_gpte_53468 paging64_prefetch_gpte 4 53468 NULL
123825 +ima_write_template_field_data_53475 ima_write_template_field_data 2 53475 NULL nohasharray
123826 +create_trace_kprobe_53475 create_trace_kprobe 1 53475 &ima_write_template_field_data_53475
123827 +iowarrior_read_53483 iowarrior_read 3 53483 NULL
123828 +osd_req_write_kern_53486 osd_req_write_kern 5 53486 NULL
123829 +do_verify_xattr_datum_53499 do_verify_xattr_datum 0 53499 NULL
123830 +snd_pcm_format_physical_width_53505 snd_pcm_format_physical_width 0 53505 NULL
123831 +dbAllocNext_53506 dbAllocNext 0 53506 NULL
123832 +check_acl_53512 check_acl 0 53512 NULL nohasharray
123833 +force_sc_support_write_53512 force_sc_support_write 3 53512 &check_acl_53512
123834 +nft_data_dump_53549 nft_data_dump 5 53549 NULL
123835 +SYSC_bind_53582 SYSC_bind 3 53582 NULL
123836 +cifs_utf16_bytes_53593 cifs_utf16_bytes 0 53593 NULL
123837 +proc_uid_map_write_53596 proc_uid_map_write 3 53596 NULL
123838 +pfkey_recvmsg_53604 pfkey_recvmsg 4 53604 NULL
123839 +___alloc_bootmem_nopanic_53626 ___alloc_bootmem_nopanic 1 53626 NULL nohasharray
123840 +wil_write_file_txmgmt_53626 wil_write_file_txmgmt 3 53626 &___alloc_bootmem_nopanic_53626
123841 +ccid_getsockopt_builtin_ccids_53634 ccid_getsockopt_builtin_ccids 2 53634 NULL
123842 +nr_sendmsg_53656 nr_sendmsg 4 53656 NULL
123843 +fuse_fill_write_pages_53682 fuse_fill_write_pages 0-4 53682 NULL
123844 +v4l2_event_subscribe_53687 v4l2_event_subscribe 3 53687 NULL
123845 +bdev_logical_block_size_53690 bdev_logical_block_size 0 53690 NULL nohasharray
123846 +igb_alloc_q_vector_53690 igb_alloc_q_vector 4-6 53690 &bdev_logical_block_size_53690
123847 +find_overflow_devnum_53711 find_overflow_devnum 0 53711 NULL
123848 +__proc_debug_mb_53732 __proc_debug_mb 5 53732 NULL
123849 +wdm_write_53735 wdm_write 3 53735 NULL
123850 +lpfc_idiag_queacc_read_qe_53755 lpfc_idiag_queacc_read_qe 0-2 53755 NULL
123851 +wa_populate_buf_in_urb_53758 wa_populate_buf_in_urb 3-4 53758 NULL
123852 +ext2_acl_count_53773 ext2_acl_count 0-1 53773 NULL
123853 +__kfifo_dma_in_prepare_r_53792 __kfifo_dma_in_prepare_r 4-5 53792 NULL
123854 +qp_alloc_host_work_53798 qp_alloc_host_work 5-3 53798 NULL
123855 +regmap_raw_write_53803 regmap_raw_write 2-4 53803 NULL
123856 +lpfc_idiag_ctlacc_read_reg_53809 lpfc_idiag_ctlacc_read_reg 0-3 53809 NULL
123857 +nls_nullsize_53815 nls_nullsize 0 53815 NULL
123858 +setup_data_read_53822 setup_data_read 3 53822 NULL
123859 +btrfs_free_reserved_extent_53873 btrfs_free_reserved_extent 2 53873 NULL nohasharray
123860 +pms_read_53873 pms_read 3 53873 &btrfs_free_reserved_extent_53873
123861 +ieee80211_if_fmt_dropped_frames_congestion_53883 ieee80211_if_fmt_dropped_frames_congestion 3 53883 NULL
123862 +SyS_setgroups_53900 SyS_setgroups 1 53900 NULL
123863 +batadv_tt_tvlv_ogm_handler_v1_53909 batadv_tt_tvlv_ogm_handler_v1 5 53909 NULL
123864 +azx_via_get_position_53916 azx_via_get_position 0 53916 NULL
123865 +usb_serial_generic_write_53927 usb_serial_generic_write 4 53927 NULL
123866 +idetape_chrdev_write_53976 idetape_chrdev_write 3 53976 NULL
123867 +__ocfs2_xattr_set_value_outside_53981 __ocfs2_xattr_set_value_outside 5 53981 NULL
123868 +ieee80211_if_fmt_dot11MeshHWMPperrMinInterval_53998 ieee80211_if_fmt_dot11MeshHWMPperrMinInterval 3 53998 NULL
123869 +hfsplus_attr_build_key_54013 hfsplus_attr_build_key 0 54013 NULL
123870 +snd_pcm_lib_write_transfer_54018 snd_pcm_lib_write_transfer 5-2-4 54018 NULL
123871 +mdc_kuc_write_54019 mdc_kuc_write 3 54019 NULL
123872 +ipxrtr_route_packet_54036 ipxrtr_route_packet 4 54036 NULL
123873 +batadv_tt_update_orig_54049 batadv_tt_update_orig 6-4 54049 NULL
123874 +pipeline_dec_packet_out_read_54052 pipeline_dec_packet_out_read 3 54052 NULL
123875 +nl80211_send_disconnected_54056 nl80211_send_disconnected 5 54056 NULL
123876 +rproc_state_read_54057 rproc_state_read 3 54057 NULL
123877 +bitmap_bitremap_54096 bitmap_bitremap 4 54096 NULL
123878 +altera_set_ir_pre_54103 altera_set_ir_pre 2 54103 NULL nohasharray
123879 +lustre_posix_acl_xattr_filter_54103 lustre_posix_acl_xattr_filter 2 54103 &altera_set_ir_pre_54103
123880 +__comedi_buf_write_alloc_54112 __comedi_buf_write_alloc 0-2 54112 NULL
123881 +strn_len_54122 strn_len 0 54122 NULL
123882 +isku_receive_54130 isku_receive 4 54130 NULL
123883 +isr_host_acknowledges_read_54136 isr_host_acknowledges_read 3 54136 NULL
123884 +irq_blk_threshold_write_54138 irq_blk_threshold_write 3 54138 NULL
123885 +memcpy_toiovec_54166 memcpy_toiovec 3 54166 NULL
123886 +nouveau_falcon_create__54169 nouveau_falcon_create_ 8 54169 NULL
123887 +p9_client_prepare_req_54175 p9_client_prepare_req 3 54175 NULL
123888 +do_sys_poll_54221 do_sys_poll 2 54221 NULL
123889 +__register_chrdev_54223 __register_chrdev 2-3 54223 NULL
123890 +pi_read_regr_54231 pi_read_regr 0 54231 NULL
123891 +mcp23s08_read_regs_54246 mcp23s08_read_regs 4 54246 NULL
123892 +reada_add_block_54247 reada_add_block 2 54247 NULL
123893 +xfs_dir2_sf_addname_hard_54254 xfs_dir2_sf_addname_hard 3 54254 NULL
123894 +ceph_msgpool_get_54258 ceph_msgpool_get 2 54258 NULL
123895 +audio_write_54261 audio_write 4 54261 NULL nohasharray
123896 +wusb_prf_54261 wusb_prf 7 54261 &audio_write_54261
123897 +mwifiex_getlog_read_54269 mwifiex_getlog_read 3 54269 NULL
123898 +kstrtou16_from_user_54274 kstrtou16_from_user 2 54274 NULL
123899 +sizeof_long_54276 sizeof_long 0 54276 NULL
123900 +altera_set_dr_post_54291 altera_set_dr_post 2 54291 NULL
123901 +dlm_alloc_pagevec_54296 dlm_alloc_pagevec 1 54296 NULL
123902 +reclaim_pages_54301 reclaim_pages 3 54301 NULL
123903 +sprintf_54306 sprintf 0 54306 NULL
123904 +bio_add_pc_page_54319 bio_add_pc_page 4 54319 NULL
123905 +br_fdb_fillbuf_54339 br_fdb_fillbuf 0 54339 NULL
123906 +__alloc_dev_table_54343 __alloc_dev_table 2 54343 NULL
123907 +__get_free_pages_54352 __get_free_pages 0 54352 NULL
123908 +readlink_copy_54366 readlink_copy 2 54366 NULL
123909 +read_file_credit_dist_stats_54367 read_file_credit_dist_stats 3 54367 NULL
123910 +intel_sdvo_write_cmd_54377 intel_sdvo_write_cmd 4 54377 NULL nohasharray
123911 +do_dccp_setsockopt_54377 do_dccp_setsockopt 5 54377 &intel_sdvo_write_cmd_54377
123912 +ah_alloc_tmp_54378 ah_alloc_tmp 3-2 54378 NULL
123913 +snd_pcm_oss_read2_54387 snd_pcm_oss_read2 0-3 54387 NULL
123914 +iwl_dbgfs_power_save_status_read_54392 iwl_dbgfs_power_save_status_read 3 54392 NULL
123915 +ll_ra_count_get_54410 ll_ra_count_get 3 54410 NULL
123916 +copy_gadget_strings_54417 copy_gadget_strings 2-3 54417 NULL
123917 +sparse_early_mem_maps_alloc_node_54485 sparse_early_mem_maps_alloc_node 4 54485 NULL
123918 +simple_strtoull_54493 simple_strtoull 0 54493 NULL
123919 +l2cap_create_basic_pdu_54508 l2cap_create_basic_pdu 3 54508 NULL
123920 +btrfs_ordered_sum_size_54509 btrfs_ordered_sum_size 0-2 54509 NULL
123921 +rfc4106_set_key_54519 rfc4106_set_key 3 54519 NULL
123922 +vmci_transport_dgram_enqueue_54525 vmci_transport_dgram_enqueue 4 54525 NULL
123923 +viacam_read_54526 viacam_read 3 54526 NULL
123924 +unix_dgram_connect_54535 unix_dgram_connect 3 54535 NULL
123925 +setsockopt_54539 setsockopt 5 54539 NULL
123926 +lbs_lowsnr_write_54549 lbs_lowsnr_write 3 54549 NULL
123927 +SYSC_setsockopt_54561 SYSC_setsockopt 5 54561 NULL
123928 +nfsd_vfs_write_54577 nfsd_vfs_write 6 54577 NULL
123929 +fw_iso_buffer_init_54582 fw_iso_buffer_init 3 54582 NULL
123930 +nvme_npages_54601 nvme_npages 0-1 54601 NULL
123931 +irq_pkt_threshold_write_54605 irq_pkt_threshold_write 3 54605 NULL
123932 +port_fops_write_54627 port_fops_write 3 54627 NULL
123933 +tipc_send_stream_54648 tipc_send_stream 4 54648 NULL
123934 +irq_timeout_read_54653 irq_timeout_read 3 54653 NULL
123935 +dns_resolver_read_54658 dns_resolver_read 3 54658 NULL
123936 +twl6030_interrupt_mask_54659 twl6030_interrupt_mask 2 54659 NULL
123937 +tdp_page_fault_54663 tdp_page_fault 2 54663 NULL
123938 +bus_add_device_54665 bus_add_device 0 54665 NULL
123939 +cw1200_queue_stats_init_54670 cw1200_queue_stats_init 2 54670 NULL
123940 +bio_kmalloc_54672 bio_kmalloc 2 54672 NULL
123941 +evm_read_key_54674 evm_read_key 3 54674 NULL
123942 +jfs_direct_IO_54687 jfs_direct_IO 4 54687 NULL
123943 +rfkill_fop_read_54711 rfkill_fop_read 3 54711 NULL
123944 +ocfs2_control_write_54737 ocfs2_control_write 3 54737 NULL
123945 +kzalloc_54740 kzalloc 1 54740 NULL
123946 +wep_iv_read_54744 wep_iv_read 3 54744 NULL
123947 +lpfc_idiag_pcicfg_write_54749 lpfc_idiag_pcicfg_write 3 54749 NULL
123948 +crystalhd_user_data_54754 crystalhd_user_data 3 54754 NULL
123949 +iio_event_chrdev_read_54757 iio_event_chrdev_read 3 54757 NULL
123950 +adis16480_show_firmware_date_54762 adis16480_show_firmware_date 3 54762 NULL
123951 +ldsem_atomic_update_54774 ldsem_atomic_update 1 54774 NULL
123952 +flexcop_device_kmalloc_54793 flexcop_device_kmalloc 1 54793 NULL
123953 +nfsd_write_54809 nfsd_write 6 54809 NULL
123954 +ar9287_dump_modal_eeprom_54814 ar9287_dump_modal_eeprom 3-2 54814 NULL
123955 +kvzalloc_54815 kvzalloc 1 54815 NULL nohasharray
123956 +crypto_tfm_ctx_alignment_54815 crypto_tfm_ctx_alignment 0 54815 &kvzalloc_54815 nohasharray
123957 +aes_decrypt_fail_read_54815 aes_decrypt_fail_read 3 54815 &crypto_tfm_ctx_alignment_54815
123958 +generic_perform_write_54832 generic_perform_write 3 54832 NULL
123959 +write_rio_54837 write_rio 3 54837 NULL
123960 +ext3_acl_from_disk_54839 ext3_acl_from_disk 2 54839 NULL nohasharray
123961 +nouveau_engctx_create__54839 nouveau_engctx_create_ 8 54839 &ext3_acl_from_disk_54839
123962 +ufx_ops_write_54848 ufx_ops_write 3 54848 NULL
123963 +printer_read_54851 printer_read 3 54851 NULL
123964 +broadsheet_spiflash_rewrite_sector_54864 broadsheet_spiflash_rewrite_sector 2 54864 NULL
123965 +prism_build_supp_rates_54865 prism_build_supp_rates 0 54865 NULL
123966 +iscsi_pool_init_54913 iscsi_pool_init 2-4 54913 NULL nohasharray
123967 +kobject_set_name_vargs_54913 kobject_set_name_vargs 0 54913 &iscsi_pool_init_54913
123968 +btrfs_stack_chunk_num_stripes_54923 btrfs_stack_chunk_num_stripes 0 54923 NULL
123969 +bio_add_page_54933 bio_add_page 0-3 54933 NULL
123970 +mxms_structlen_54939 mxms_structlen 0 54939 NULL
123971 +add_port_54941 add_port 2 54941 NULL
123972 +tipc_send2name_54946 tipc_send2name 5 54946 NULL
123973 +ath9k_dump_btcoex_54949 ath9k_dump_btcoex 0-3 54949 NULL
123974 +alauda_write_data_54967 alauda_write_data 3 54967 NULL
123975 +c4_add_card_54968 c4_add_card 3 54968 NULL
123976 +ext3_xattr_get_54989 ext3_xattr_get 0 54989 NULL
123977 +cx231xx_v4l2_read_55014 cx231xx_v4l2_read 3 55014 NULL
123978 +error_error_null_Frame_tx_start_read_55024 error_error_null_Frame_tx_start_read 3 55024 NULL
123979 +efw_transaction_55052 efw_transaction 5-7 55052 NULL
123980 +apei_exec_run_55075 apei_exec_run 0 55075 NULL
123981 +bitmap_storage_alloc_55077 bitmap_storage_alloc 2 55077 NULL
123982 +read_dma_55086 read_dma 3 55086 NULL
123983 +rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read_55106 rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read 3 55106 NULL
123984 +crypto_ahash_setkey_55134 crypto_ahash_setkey 3 55134 NULL
123985 +filldir_55137 filldir 3 55137 NULL
123986 +ocfs2_truncate_file_55148 ocfs2_truncate_file 3 55148 NULL
123987 +npages_to_npools_55149 npages_to_npools 0-1 55149 NULL
123988 +ieee80211_if_read_uapsd_queues_55150 ieee80211_if_read_uapsd_queues 3 55150 NULL
123989 +sel_write_relabel_55195 sel_write_relabel 3 55195 NULL
123990 +compat_SyS_ppoll_55196 compat_SyS_ppoll 2 55196 NULL
123991 +sched_feat_write_55202 sched_feat_write 3 55202 NULL
123992 +ht40allow_map_read_55209 ht40allow_map_read 3 55209 NULL
123993 +__kfifo_dma_out_prepare_r_55211 __kfifo_dma_out_prepare_r 4-5 55211 NULL
123994 +do_raw_setsockopt_55215 do_raw_setsockopt 5 55215 NULL
123995 +qxl_alloc_client_monitors_config_55216 qxl_alloc_client_monitors_config 2 55216 NULL
123996 +nouveau_mc_create__55217 nouveau_mc_create_ 4 55217 NULL
123997 +dbAllocDmap_55227 dbAllocDmap 0 55227 NULL
123998 +memcpy_fromiovec_55247 memcpy_fromiovec 3 55247 NULL
123999 +lbs_failcount_write_55276 lbs_failcount_write 3 55276 NULL
124000 +persistent_ram_new_55286 persistent_ram_new 1-2 55286 NULL
124001 +rx_streaming_interval_read_55291 rx_streaming_interval_read 3 55291 NULL
124002 +lov_get_stripecnt_55297 lov_get_stripecnt 0-3 55297 NULL
124003 +gsm_control_modem_55303 gsm_control_modem 3 55303 NULL
124004 +wimax_msg_len_55304 wimax_msg_len 0 55304 NULL
124005 +qp_alloc_guest_work_55305 qp_alloc_guest_work 5-3 55305 NULL nohasharray
124006 +compat_SyS_process_vm_readv_55305 compat_SyS_process_vm_readv 3-5 55305 &qp_alloc_guest_work_55305
124007 +compat_SyS_mbind_55329 compat_SyS_mbind 5 55329 NULL
124008 +vme_user_read_55338 vme_user_read 3 55338 NULL
124009 +__wa_xfer_setup_sizes_55342 __wa_xfer_setup_sizes 0 55342 NULL nohasharray
124010 +sctp_datamsg_from_user_55342 sctp_datamsg_from_user 4 55342 &__wa_xfer_setup_sizes_55342
124011 +cw1200_sdio_align_size_55391 cw1200_sdio_align_size 2 55391 NULL
124012 +iwl_dbgfs_plcp_delta_read_55407 iwl_dbgfs_plcp_delta_read 3 55407 NULL
124013 +nouveau_cli_create_55425 nouveau_cli_create 3 55425 NULL
124014 +si476x_radio_read_rds_blckcnt_blob_55427 si476x_radio_read_rds_blckcnt_blob 3 55427 NULL
124015 +__vxge_hw_channel_allocate_55462 __vxge_hw_channel_allocate 3 55462 NULL
124016 +cx23888_ir_rx_read_55473 cx23888_ir_rx_read 3 55473 NULL
124017 +ufshcd_exec_dev_cmd_55479 ufshcd_exec_dev_cmd 0 55479 NULL
124018 +snd_pcm_lib_write_55483 snd_pcm_lib_write 0-3 55483 NULL
124019 +i2o_pool_alloc_55485 i2o_pool_alloc 4 55485 NULL
124020 +batadv_tt_entries_55487 batadv_tt_entries 0-1 55487 NULL
124021 +ras_stride_increase_window_55501 ras_stride_increase_window 3 55501 NULL
124022 +tx_tx_done_int_template_read_55511 tx_tx_done_int_template_read 3 55511 NULL
124023 +ea_get_55522 ea_get 3-0 55522 NULL
124024 +buffer_size_55534 buffer_size 0 55534 NULL
124025 +set_msr_interception_55538 set_msr_interception 2 55538 NULL
124026 +tty_port_register_device_55543 tty_port_register_device 3 55543 NULL
124027 +hash_ipport6_expire_55549 hash_ipport6_expire 4 55549 NULL
124028 +dm_stats_list_55551 dm_stats_list 4 55551 NULL
124029 +compat_SyS_setsockopt_55581 compat_SyS_setsockopt 5 55581 NULL
124030 +add_partition_55588 add_partition 2 55588 NULL
124031 +kstrtou8_from_user_55599 kstrtou8_from_user 2 55599 NULL
124032 +SyS_keyctl_55602 SyS_keyctl 4 55602 NULL
124033 +macvtap_put_user_55609 macvtap_put_user 4 55609 NULL
124034 +selinux_setprocattr_55611 selinux_setprocattr 4 55611 NULL
124035 +edge_tty_recv_55622 edge_tty_recv 3 55622 NULL
124036 +reiserfs_xattr_get_55628 reiserfs_xattr_get 0 55628 NULL nohasharray
124037 +pktgen_if_write_55628 pktgen_if_write 3 55628 &reiserfs_xattr_get_55628
124038 +osc_obd_max_pages_per_rpc_seq_write_55636 osc_obd_max_pages_per_rpc_seq_write 3 55636 NULL
124039 +xfs_bmbt_maxrecs_55649 xfs_bmbt_maxrecs 0-2 55649 NULL
124040 +lpfc_idiag_queinfo_read_55662 lpfc_idiag_queinfo_read 3 55662 NULL
124041 +il_dbgfs_tx_queue_read_55668 il_dbgfs_tx_queue_read 3 55668 NULL
124042 +get_info_55681 get_info 3 55681 NULL
124043 +iwl_dbgfs_plcp_delta_write_55682 iwl_dbgfs_plcp_delta_write 3 55682 NULL
124044 +ext4_alloc_file_blocks_55689 ext4_alloc_file_blocks 3 55689 NULL
124045 +genl_allocate_reserve_groups_55705 genl_allocate_reserve_groups 1 55705 NULL
124046 +pm8001_store_update_fw_55716 pm8001_store_update_fw 4 55716 NULL
124047 +tap_pwup_write_55723 tap_pwup_write 3 55723 NULL
124048 +__iio_allocate_kfifo_55738 __iio_allocate_kfifo 2 55738 NULL
124049 +set_local_name_55757 set_local_name 4 55757 NULL
124050 +ethtool_copy_validate_indir_55769 ethtool_copy_validate_indir 4 55769 NULL
124051 +strlen_55778 strlen 0 55778 NULL
124052 +set_spte_55783 set_spte 4-5 55783 NULL
124053 +conf_read_55786 conf_read 3 55786 NULL nohasharray
124054 +req_bio_endio_55786 req_bio_endio 3 55786 &conf_read_55786
124055 +uwb_rc_neh_grok_event_55799 uwb_rc_neh_grok_event 3 55799 NULL
124056 +sb16_copy_from_user_55836 sb16_copy_from_user 10-6-7 55836 NULL
124057 +ip_hdrlen_55849 ip_hdrlen 0 55849 NULL
124058 +hcd_alloc_coherent_55862 hcd_alloc_coherent 5 55862 NULL
124059 +shmem_setxattr_55867 shmem_setxattr 4 55867 NULL
124060 +hsc_write_55875 hsc_write 3 55875 NULL
124061 +ramdisk_store_55885 ramdisk_store 4 55885 NULL
124062 +pm_qos_power_read_55891 pm_qos_power_read 3 55891 NULL
124063 +hash_ip4_expire_55911 hash_ip4_expire 4 55911 NULL
124064 +snd_pcm_hw_param_value_min_55917 snd_pcm_hw_param_value_min 0 55917 NULL
124065 +kvm_write_guest_virt_system_55944 kvm_write_guest_virt_system 4-2 55944 NULL
124066 +sel_read_policy_55947 sel_read_policy 3 55947 NULL
124067 +ceph_get_direct_page_vector_55956 ceph_get_direct_page_vector 2 55956 NULL
124068 +simple_read_from_buffer_55957 simple_read_from_buffer 5-2-0 55957 NULL
124069 +tx_tx_imm_resp_read_55964 tx_tx_imm_resp_read 3 55964 NULL
124070 +btrfs_clone_55977 btrfs_clone 5-3-6 55977 NULL
124071 +wa_xfer_create_subset_sg_55992 wa_xfer_create_subset_sg 3-2 55992 NULL
124072 +nvme_alloc_iod_56027 nvme_alloc_iod 1-2 56027 NULL
124073 +iwl_trans_read_prph_56052 iwl_trans_read_prph 0 56052 NULL
124074 +dccp_sendmsg_56058 dccp_sendmsg 4 56058 NULL
124075 +pscsi_get_bio_56103 pscsi_get_bio 1 56103 NULL
124076 +usb_alloc_stream_buffers_56123 usb_alloc_stream_buffers 3 56123 NULL
124077 +sel_read_handle_status_56139 sel_read_handle_status 3 56139 NULL
124078 +write_file_frameerrors_56145 write_file_frameerrors 3 56145 NULL
124079 +rawv6_setsockopt_56165 rawv6_setsockopt 5 56165 NULL
124080 +ath9k_dump_legacy_btcoex_56194 ath9k_dump_legacy_btcoex 0-3 56194 NULL
124081 +vring_add_indirect_56222 vring_add_indirect 4 56222 NULL
124082 +ocfs2_find_xe_in_bucket_56224 ocfs2_find_xe_in_bucket 0 56224 NULL
124083 +ufshcd_query_descriptor_56236 ufshcd_query_descriptor 0 56236 NULL
124084 +do_ipt_set_ctl_56238 do_ipt_set_ctl 4 56238 NULL
124085 +fd_copyin_56247 fd_copyin 3 56247 NULL
124086 +sk_rmem_schedule_56255 sk_rmem_schedule 3 56255 NULL
124087 +acpi_ex_get_serial_access_length_56275 acpi_ex_get_serial_access_length 0-2 56275 NULL
124088 +il4965_ucode_general_stats_read_56277 il4965_ucode_general_stats_read 3 56277 NULL
124089 +ieee80211_if_fmt_user_power_level_56283 ieee80211_if_fmt_user_power_level 3 56283 NULL
124090 +RESIZE_IF_NEEDED_56286 RESIZE_IF_NEEDED 2 56286 NULL
124091 +dvb_aplay_56296 dvb_aplay 3 56296 NULL
124092 +btmrvl_hscfgcmd_read_56303 btmrvl_hscfgcmd_read 3 56303 NULL
124093 +speakup_file_write_56310 speakup_file_write 3 56310 NULL
124094 +pipeline_pre_to_defrag_swi_read_56321 pipeline_pre_to_defrag_swi_read 3 56321 NULL
124095 +journal_init_revoke_table_56331 journal_init_revoke_table 1 56331 NULL
124096 +snd_rawmidi_read_56337 snd_rawmidi_read 3 56337 NULL
124097 +vxge_os_dma_malloc_async_56348 vxge_os_dma_malloc_async 3 56348 NULL
124098 +mite_device_bytes_transferred_56355 mite_device_bytes_transferred 0 56355 NULL
124099 +iov_iter_copy_from_user_atomic_56368 iov_iter_copy_from_user_atomic 0-4 56368 NULL
124100 +dev_read_56369 dev_read 3 56369 NULL
124101 +ath10k_read_simulate_fw_crash_56371 ath10k_read_simulate_fw_crash 3 56371 NULL
124102 +lnet_ping_56378 lnet_ping 4 56378 NULL
124103 +write_gssp_56404 write_gssp 3 56404 NULL
124104 +ocfs2_control_read_56405 ocfs2_control_read 3 56405 NULL
124105 +store_msg_56417 store_msg 3 56417 NULL
124106 +pppol2tp_sendmsg_56420 pppol2tp_sendmsg 4 56420 NULL
124107 +l2cap_segment_le_sdu_56426 l2cap_segment_le_sdu 4 56426 NULL
124108 +lprocfs_fid_space_seq_write_56431 lprocfs_fid_space_seq_write 3 56431 NULL nohasharray
124109 +ec_dbgfs_cmd_read_56431 ec_dbgfs_cmd_read 3 56431 &lprocfs_fid_space_seq_write_56431
124110 +fl_create_56435 fl_create 5 56435 NULL
124111 +gnttab_map_56439 gnttab_map 2 56439 NULL
124112 +cx231xx_init_isoc_56453 cx231xx_init_isoc 3-2-4 56453 NULL
124113 +set_connectable_56458 set_connectable 4 56458 NULL
124114 +osd_req_list_partition_objects_56464 osd_req_list_partition_objects 5 56464 NULL
124115 +putused_user_56467 putused_user 3 56467 NULL
124116 +ocfs2_zero_extend_range_56468 ocfs2_zero_extend_range 3-2 56468 NULL
124117 +lbs_rdmac_write_56471 lbs_rdmac_write 3 56471 NULL
124118 +crypto_shash_alignmask_56486 crypto_shash_alignmask 0 56486 NULL
124119 +ieee80211_rx_mgmt_probe_beacon_56491 ieee80211_rx_mgmt_probe_beacon 3 56491 NULL
124120 +memblock_virt_alloc_56501 memblock_virt_alloc 1 56501 NULL
124121 +init_map_ip_56508 init_map_ip 5 56508 NULL
124122 +lustre_posix_acl_xattr_reduce_space_56512 lustre_posix_acl_xattr_reduce_space 3 56512 NULL
124123 +cfg80211_connect_result_56515 cfg80211_connect_result 4-6 56515 NULL
124124 +ip_options_get_56538 ip_options_get 4 56538 NULL
124125 +ll_wr_track_id_56544 ll_wr_track_id 2 56544 NULL
124126 +alloc_apertures_56561 alloc_apertures 1 56561 NULL
124127 +rs_sta_dbgfs_stats_table_read_56573 rs_sta_dbgfs_stats_table_read 3 56573 NULL
124128 +portcntrs_2_read_56586 portcntrs_2_read 3 56586 NULL
124129 +gro_pull_from_frag0_56593 gro_pull_from_frag0 2 56593 NULL
124130 +event_filter_write_56609 event_filter_write 3 56609 NULL
124131 +nvme_trans_log_temperature_56613 nvme_trans_log_temperature 3 56613 NULL
124132 +gather_array_56641 gather_array 3 56641 NULL
124133 +lookup_extent_backref_56644 lookup_extent_backref 9 56644 NULL
124134 +uvc_debugfs_stats_read_56651 uvc_debugfs_stats_read 3 56651 NULL
124135 +nv50_gpio_intr_mask_56665 nv50_gpio_intr_mask 4-3 56665 NULL
124136 +tg3_nvram_write_block_56666 tg3_nvram_write_block 3 56666 NULL
124137 +snd_gus_dram_read_56686 snd_gus_dram_read 4 56686 NULL
124138 +dvb_ringbuffer_read_user_56702 dvb_ringbuffer_read_user 3-0 56702 NULL
124139 +sfw_alloc_pages_56709 sfw_alloc_pages 3 56709 NULL
124140 +sta_flags_read_56710 sta_flags_read 3 56710 NULL
124141 +ipv6_getsockopt_sticky_56711 ipv6_getsockopt_sticky 5 56711 NULL
124142 +__wa_xfer_setup_segs_56725 __wa_xfer_setup_segs 2 56725 NULL
124143 +__copy_from_user_ll_56738 __copy_from_user_ll 0-3 56738 NULL
124144 +drm_agp_bind_pages_56748 drm_agp_bind_pages 3 56748 NULL
124145 +btrfsic_map_block_56751 btrfsic_map_block 2 56751 NULL
124146 +ttm_alloc_new_pages_56792 ttm_alloc_new_pages 5 56792 NULL
124147 +ion_ioctl_56806 ion_ioctl 2 56806 NULL
124148 +do_syslog_56807 do_syslog 3 56807 NULL
124149 +mtdchar_write_56831 mtdchar_write 3 56831 NULL
124150 +snd_rawmidi_kernel_write1_56847 snd_rawmidi_kernel_write1 4-0 56847 NULL
124151 +si476x_radio_read_agc_blob_56849 si476x_radio_read_agc_blob 3 56849 NULL
124152 +gk20a_ram_get_56863 gk20a_ram_get 2 56863 NULL
124153 +ext3_xattr_ibody_get_56880 ext3_xattr_ibody_get 0 56880 NULL
124154 +pvr2_debugifc_print_status_56890 pvr2_debugifc_print_status 3 56890 NULL
124155 +debug_debug3_read_56894 debug_debug3_read 3 56894 NULL
124156 +le_auto_conn_write_56895 le_auto_conn_write 3 56895 NULL nohasharray
124157 +batadv_tt_update_changes_56895 batadv_tt_update_changes 3 56895 &le_auto_conn_write_56895
124158 +hfsplus_find_cat_56899 hfsplus_find_cat 0 56899 NULL
124159 +strcspn_56913 strcspn 0 56913 NULL
124160 +__kfifo_out_56927 __kfifo_out 0-3 56927 NULL
124161 +journal_init_revoke_56933 journal_init_revoke 2 56933 NULL
124162 +nouveau_xtensa_create__56952 nouveau_xtensa_create_ 8 56952 NULL
124163 +diva_get_driver_info_56967 diva_get_driver_info 0 56967 NULL
124164 +sptlrpc_secflags2str_56995 sptlrpc_secflags2str 3 56995 NULL
124165 +vlsi_alloc_ring_57003 vlsi_alloc_ring 3-4 57003 NULL
124166 +btrfs_super_csum_size_57004 btrfs_super_csum_size 0 57004 NULL
124167 +aircable_process_packet_57027 aircable_process_packet 4 57027 NULL
124168 +ieee80211_if_fmt_state_57043 ieee80211_if_fmt_state 3 57043 NULL nohasharray
124169 +skb_network_offset_57043 skb_network_offset 0 57043 &ieee80211_if_fmt_state_57043
124170 +bytes_to_samples_57049 bytes_to_samples 0-2 57049 NULL
124171 +xfs_buf_read_map_57053 xfs_buf_read_map 3 57053 NULL
124172 +cx2341x_ctrl_new_std_57061 cx2341x_ctrl_new_std 4 57061 NULL
124173 +sca3000_read_data_57064 sca3000_read_data 4 57064 NULL
124174 +pcmcia_replace_cis_57066 pcmcia_replace_cis 3 57066 NULL
124175 +tracing_set_trace_write_57096 tracing_set_trace_write 3 57096 NULL
124176 +altera_get_note_57099 altera_get_note 6 57099 NULL
124177 +hpfs_readpages_57106 hpfs_readpages 4 57106 NULL
124178 +crypto_compress_ctxsize_57109 crypto_compress_ctxsize 0 57109 NULL
124179 +cipso_v4_gentag_loc_57119 cipso_v4_gentag_loc 0 57119 NULL
124180 +ima_show_htable_value_57136 ima_show_htable_value 2 57136 NULL nohasharray
124181 +rds_ib_sub_signaled_57136 rds_ib_sub_signaled 2 57136 &ima_show_htable_value_57136 nohasharray
124182 +nl80211_send_deauth_57136 nl80211_send_deauth 4 57136 &rds_ib_sub_signaled_57136
124183 +snd_sonicvibes_getdmac_57140 snd_sonicvibes_getdmac 0 57140 NULL
124184 +_iwl_dbgfs_bf_params_write_57141 _iwl_dbgfs_bf_params_write 3 57141 NULL
124185 +acpi_gsb_i2c_read_bytes_57145 acpi_gsb_i2c_read_bytes 4 57145 NULL
124186 +udl_prime_create_57159 udl_prime_create 2 57159 NULL
124187 +stk_prepare_sio_buffers_57168 stk_prepare_sio_buffers 2 57168 NULL
124188 +rx_hw_stuck_read_57179 rx_hw_stuck_read 3 57179 NULL
124189 +hash_netnet6_expire_57191 hash_netnet6_expire 4 57191 NULL
124190 +tt3650_ci_msg_57219 tt3650_ci_msg 4 57219 NULL
124191 +dma_fifo_alloc_57236 dma_fifo_alloc 2-3-5 57236 NULL
124192 +drbg_blocklen_57239 drbg_blocklen 0 57239 NULL
124193 +rsxx_cram_write_57244 rsxx_cram_write 3 57244 NULL
124194 +ieee80211_if_fmt_tsf_57249 ieee80211_if_fmt_tsf 3 57249 NULL
124195 +oprofilefs_ulong_from_user_57251 oprofilefs_ulong_from_user 3 57251 NULL
124196 +alloc_flex_gd_57259 alloc_flex_gd 1 57259 NULL
124197 +lbs_sleepparams_write_57283 lbs_sleepparams_write 3 57283 NULL
124198 +pstore_file_read_57288 pstore_file_read 3 57288 NULL
124199 +snd_pcm_read_57289 snd_pcm_read 3 57289 NULL
124200 +string_length_no_trail_57290 string_length_no_trail 0-2 57290 NULL
124201 +ftdi_elan_write_57309 ftdi_elan_write 3 57309 NULL
124202 +write_file_regval_57313 write_file_regval 3 57313 NULL
124203 +__mxt_write_reg_57326 __mxt_write_reg 3 57326 NULL
124204 +usblp_read_57342 usblp_read 3 57342 NULL
124205 +print_devstats_dot11RTSFailureCount_57347 print_devstats_dot11RTSFailureCount 3 57347 NULL
124206 +dio_send_cur_page_57348 dio_send_cur_page 0 57348 NULL
124207 +tipc_bclink_stats_57372 tipc_bclink_stats 2 57372 NULL
124208 +tty_register_device_attr_57381 tty_register_device_attr 2 57381 NULL
124209 +bzImage64_load_57388 bzImage64_load 7 57388 NULL
124210 +read_file_blob_57406 read_file_blob 3 57406 NULL
124211 +enclosure_register_57412 enclosure_register 3 57412 NULL
124212 +compat_keyctl_instantiate_key_iov_57431 compat_keyctl_instantiate_key_iov 3 57431 NULL
124213 +copy_to_user_fromio_57432 copy_to_user_fromio 3 57432 NULL
124214 +__roundup_pow_of_two_57461 __roundup_pow_of_two 0 57461 NULL
124215 +sisusb_clear_vram_57466 sisusb_clear_vram 2-3 57466 NULL
124216 +ieee80211_if_read_flags_57470 ieee80211_if_read_flags 3 57470 NULL
124217 +read_file_skb_rx_57490 read_file_skb_rx 3 57490 NULL
124218 +bnad_debugfs_write_regwr_57500 bnad_debugfs_write_regwr 3 57500 NULL
124219 +skb_headlen_57501 skb_headlen 0 57501 NULL
124220 +copy_in_user_57502 copy_in_user 3 57502 NULL
124221 +ckhdid_printf_57505 ckhdid_printf 2 57505 NULL
124222 +init_tag_map_57515 init_tag_map 3 57515 NULL
124223 +wil_read_file_ssid_57517 wil_read_file_ssid 3 57517 NULL nohasharray
124224 +il_dbgfs_force_reset_read_57517 il_dbgfs_force_reset_read 3 57517 &wil_read_file_ssid_57517
124225 +cmm_read_57520 cmm_read 3 57520 NULL
124226 +inode_permission_57531 inode_permission 0 57531 NULL
124227 +acpi_dev_get_resources_57534 acpi_dev_get_resources 0 57534 NULL
124228 +ptlrpc_lprocfs_hp_ratio_seq_write_57537 ptlrpc_lprocfs_hp_ratio_seq_write 3 57537 NULL
124229 +compat_SyS_process_vm_writev_57542 compat_SyS_process_vm_writev 3-5 57542 NULL
124230 +ReadHDLCPnP_57559 ReadHDLCPnP 0 57559 NULL
124231 +snd_pcm_playback_ioctl1_57569 snd_pcm_playback_ioctl1 0 57569 NULL
124232 +get_bridge_ifindices_57579 get_bridge_ifindices 0 57579 NULL
124233 +ldlm_cli_enqueue_local_57582 ldlm_cli_enqueue_local 11 57582 NULL
124234 +il_dbgfs_interrupt_write_57591 il_dbgfs_interrupt_write 3 57591 NULL
124235 +read_file_spectral_fft_period_57593 read_file_spectral_fft_period 3 57593 NULL
124236 +tx_tx_retry_template_read_57623 tx_tx_retry_template_read 3 57623 NULL
124237 +sisusbcon_putcs_57630 sisusbcon_putcs 3 57630 NULL
124238 +mem_read_57631 mem_read 3 57631 NULL
124239 +r3964_write_57662 r3964_write 4 57662 NULL
124240 +proc_ns_readlink_57664 proc_ns_readlink 3 57664 NULL
124241 +__lgwrite_57669 __lgwrite 4 57669 NULL
124242 +f1x_match_to_this_node_57695 f1x_match_to_this_node 3 57695 NULL
124243 +i2400m_rx_stats_read_57706 i2400m_rx_stats_read 3 57706 NULL
124244 +ieee80211_if_read_dot11MeshHWMPconfirmationInterval_57722 ieee80211_if_read_dot11MeshHWMPconfirmationInterval 3 57722 NULL
124245 +pppol2tp_recvmsg_57742 pppol2tp_recvmsg 4 57742 NULL
124246 +ieee80211_if_fmt_dot11MeshHWMPpreqMinInterval_57762 ieee80211_if_fmt_dot11MeshHWMPpreqMinInterval 3 57762 NULL
124247 +SYSC_process_vm_writev_57776 SYSC_process_vm_writev 3-5 57776 NULL
124248 +ld2_57794 ld2 0 57794 NULL
124249 +ivtv_read_57796 ivtv_read 3 57796 NULL
124250 +ion_test_ioctl_57799 ion_test_ioctl 2 57799 NULL
124251 +bfad_debugfs_read_regrd_57830 bfad_debugfs_read_regrd 3 57830 NULL
124252 +copy_to_user_57835 copy_to_user 3-0 57835 NULL
124253 +flash_read_57843 flash_read 3 57843 NULL
124254 +kiblnd_create_tx_pool_57846 kiblnd_create_tx_pool 2 57846 NULL
124255 +radeon_ttm_gtt_read_57879 radeon_ttm_gtt_read 3 57879 NULL
124256 +xt_alloc_table_info_57903 xt_alloc_table_info 1 57903 NULL
124257 +iio_read_first_n_kfifo_57910 iio_read_first_n_kfifo 2 57910 NULL
124258 +ll_xattr_find_get_lock_57912 ll_xattr_find_get_lock 0 57912 NULL
124259 +memcg_caches_array_size_57918 memcg_caches_array_size 0-1 57918 NULL
124260 +mwifiex_hscfg_read_57920 mwifiex_hscfg_read 3 57920 NULL
124261 +twl_i2c_write_57923 twl_i2c_write 3-4 57923 NULL
124262 +__snd_gf1_look16_57925 __snd_gf1_look16 0 57925 NULL
124263 +sel_read_handle_unknown_57933 sel_read_handle_unknown 3 57933 NULL
124264 +xfs_mru_cache_create_57943 xfs_mru_cache_create 3 57943 NULL
124265 +key_algorithm_read_57946 key_algorithm_read 3 57946 NULL
124266 +arch_gnttab_init_57948 arch_gnttab_init 2-1 57948 NULL
124267 +ip_set_alloc_57953 ip_set_alloc 1 57953 NULL nohasharray
124268 +ioat3_dca_count_dca_slots_57953 ioat3_dca_count_dca_slots 0 57953 &ip_set_alloc_57953
124269 +iov_iter_npages_57979 iov_iter_npages 0-2 57979 NULL
124270 +do_rx_dma_57996 do_rx_dma 5 57996 NULL
124271 +rx_reset_counter_read_58001 rx_reset_counter_read 3 58001 NULL
124272 +iwl_dbgfs_ucode_rx_stats_read_58023 iwl_dbgfs_ucode_rx_stats_read 3 58023 NULL
124273 +io_playback_transfer_58030 io_playback_transfer 4 58030 NULL
124274 +mce_async_out_58056 mce_async_out 3 58056 NULL
124275 +ocfs2_find_leaf_58065 ocfs2_find_leaf 0 58065 NULL
124276 +dt3155_alloc_coherent_58073 dt3155_alloc_coherent 2 58073 NULL
124277 +cm4040_write_58079 cm4040_write 3 58079 NULL
124278 +savemem_58129 savemem 3 58129 NULL
124279 +ipv6_flowlabel_opt_58135 ipv6_flowlabel_opt 3 58135 NULL nohasharray
124280 +slhc_init_58135 slhc_init 1-2 58135 &ipv6_flowlabel_opt_58135
124281 +garmin_write_bulk_58191 garmin_write_bulk 3 58191 NULL
124282 +ieee80211_if_fmt_flags_58205 ieee80211_if_fmt_flags 3 58205 NULL
124283 +i40evf_allocate_virt_mem_d_58210 i40evf_allocate_virt_mem_d 3 58210 NULL
124284 +btrfsic_create_link_to_next_block_58246 btrfsic_create_link_to_next_block 4 58246 NULL
124285 +read_file_debug_58256 read_file_debug 3 58256 NULL
124286 +osc_max_dirty_mb_seq_write_58263 osc_max_dirty_mb_seq_write 3 58263 NULL
124287 +cfg80211_mgmt_tx_status_58266 cfg80211_mgmt_tx_status 4 58266 NULL
124288 +profile_load_58267 profile_load 3 58267 NULL
124289 +kstrtos8_from_user_58268 kstrtos8_from_user 2 58268 NULL
124290 +acpi_ds_build_internal_package_obj_58271 acpi_ds_build_internal_package_obj 3 58271 NULL
124291 +r100_mm_rreg_58276 r100_mm_rreg 0 58276 NULL
124292 +iscsi_decode_text_input_58292 iscsi_decode_text_input 4 58292 NULL
124293 +ieee80211_if_read_dot11MeshTTL_58307 ieee80211_if_read_dot11MeshTTL 3 58307 NULL
124294 +mic_virtio_copy_from_user_58323 mic_virtio_copy_from_user 3 58323 NULL
124295 +tx_tx_start_int_templates_read_58324 tx_tx_start_int_templates_read 3 58324 NULL
124296 +lstcon_rpc_prep_58325 lstcon_rpc_prep 4 58325 NULL
124297 +ext4_ext_truncate_extend_restart_58331 ext4_ext_truncate_extend_restart 3 58331 NULL
124298 +__copy_from_user_swizzled_58337 __copy_from_user_swizzled 2-4 58337 NULL
124299 +ec_i2c_parse_response_58347 ec_i2c_parse_response 0 58347 NULL
124300 +brcmf_debugfs_sdio_counter_read_58369 brcmf_debugfs_sdio_counter_read 3 58369 NULL
124301 +il_dbgfs_status_read_58388 il_dbgfs_status_read 3 58388 NULL
124302 +_drbd_md_sync_page_io_58403 _drbd_md_sync_page_io 6 58403 NULL
124303 +kvm_mmu_write_protect_pt_masked_58406 kvm_mmu_write_protect_pt_masked 3 58406 NULL nohasharray
124304 +idetape_pad_zeros_58406 idetape_pad_zeros 2 58406 &kvm_mmu_write_protect_pt_masked_58406
124305 +i2400m_pld_size_58415 i2400m_pld_size 0 58415 NULL
124306 +capabilities_read_58457 capabilities_read 3 58457 NULL
124307 +usnic_vnic_get_resources_58462 usnic_vnic_get_resources 3 58462 NULL
124308 +compat_do_ipt_set_ctl_58466 compat_do_ipt_set_ctl 4 58466 NULL nohasharray
124309 +lpfc_idiag_baracc_read_58466 lpfc_idiag_baracc_read 3 58466 &compat_do_ipt_set_ctl_58466
124310 +nv_rd08_58472 nv_rd08 0 58472 NULL
124311 +snd_gf1_read_addr_58483 snd_gf1_read_addr 0 58483 NULL
124312 +snd_rme96_capture_copy_58484 snd_rme96_capture_copy 5 58484 NULL
124313 +btrfs_cont_expand_58498 btrfs_cont_expand 2-3 58498 NULL
124314 +tcf_hash_create_58507 tcf_hash_create 4 58507 NULL
124315 +cifs_write_from_iter_58526 cifs_write_from_iter 2 58526 NULL
124316 +rndis_add_response_58544 rndis_add_response 2 58544 NULL
124317 +wep_decrypt_fail_read_58567 wep_decrypt_fail_read 3 58567 NULL
124318 +scnprint_mac_oui_58578 scnprint_mac_oui 3-0 58578 NULL
124319 +cur_wm_latency_write_58581 cur_wm_latency_write 3 58581 NULL
124320 +get_rhf_errstring_58582 get_rhf_errstring 3 58582 NULL
124321 +ea_read_inline_58589 ea_read_inline 0 58589 NULL
124322 +isku_sysfs_read_keys_thumbster_58590 isku_sysfs_read_keys_thumbster 6 58590 NULL
124323 +xip_file_read_58592 xip_file_read 3 58592 NULL
124324 +ecryptfs_write_end_58594 ecryptfs_write_end 5-3 58594 NULL
124325 +radeon_bo_size_58606 radeon_bo_size 0 58606 NULL
124326 +btrfs_direct_IO_58608 btrfs_direct_IO 4 58608 NULL
124327 +skb_copy_to_page_nocache_58624 skb_copy_to_page_nocache 6 58624 NULL
124328 +tx_tx_start_fw_gen_read_58648 tx_tx_start_fw_gen_read 3 58648 NULL
124329 +iwl_dbgfs_rx_handlers_write_58655 iwl_dbgfs_rx_handlers_write 3 58655 NULL
124330 +find_zero_58685 find_zero 0-1 58685 NULL
124331 +uwb_bce_print_IEs_58686 uwb_bce_print_IEs 4 58686 NULL
124332 +tps6586x_writes_58689 tps6586x_writes 2-3 58689 NULL
124333 +visor_charqueue_create_58703 visor_charqueue_create 1 58703 NULL
124334 +vx_send_msg_58711 vx_send_msg 0 58711 NULL
124335 +csum_exist_in_range_58730 csum_exist_in_range 2-3 58730 NULL
124336 +frames_to_bytes_58741 frames_to_bytes 0-2 58741 NULL
124337 +ieee80211_if_write_tkip_mic_test_58748 ieee80211_if_write_tkip_mic_test 3 58748 NULL
124338 +agp_allocate_memory_58761 agp_allocate_memory 2 58761 NULL
124339 +regmap_calc_reg_len_58795 regmap_calc_reg_len 0 58795 NULL
124340 +raw_send_hdrinc_58803 raw_send_hdrinc 4 58803 NULL
124341 +isku_sysfs_read_58806 isku_sysfs_read 5 58806 NULL
124342 +ep_read_58813 ep_read 3 58813 NULL
124343 +command_write_58841 command_write 3 58841 NULL
124344 +ath6kl_wmi_send_action_cmd_58860 ath6kl_wmi_send_action_cmd 7 58860 NULL
124345 +gs_alloc_req_58883 gs_alloc_req 2 58883 NULL
124346 +esas2r_change_queue_depth_58886 esas2r_change_queue_depth 2 58886 NULL
124347 +lprocfs_wr_pinger_recov_58914 lprocfs_wr_pinger_recov 3 58914 NULL
124348 +print_devstats_dot11FCSErrorCount_58919 print_devstats_dot11FCSErrorCount 3 58919 NULL
124349 +pipeline_cs_rx_packet_out_read_58926 pipeline_cs_rx_packet_out_read 3 58926 NULL
124350 +wait_table_hash_nr_entries_58962 wait_table_hash_nr_entries 0 58962 NULL
124351 +ieee80211_if_fmt_dot11MeshHWMPactivePathToRootTimeout_58965 ieee80211_if_fmt_dot11MeshHWMPactivePathToRootTimeout 3 58965 NULL
124352 +crypto_aead_ivsize_58970 crypto_aead_ivsize 0 58970 NULL
124353 +init_list_set_59005 init_list_set 3 59005 NULL
124354 +ep_write_59008 ep_write 3 59008 NULL
124355 +lpfc_idiag_baracc_write_59014 lpfc_idiag_baracc_write 3 59014 NULL
124356 +SyS_preadv_59029 SyS_preadv 3 59029 NULL
124357 +init_pci_cap_msi_perm_59033 init_pci_cap_msi_perm 2 59033 NULL
124358 +selinux_transaction_write_59038 selinux_transaction_write 3 59038 NULL
124359 +crypto_aead_reqsize_59039 crypto_aead_reqsize 0 59039 NULL
124360 +regmap_bulk_write_59049 regmap_bulk_write 2-4 59049 NULL
124361 +mmc_sd_num_wr_blocks_59112 mmc_sd_num_wr_blocks 0 59112 NULL
124362 +sta_tx_latency_stat_table_59122 sta_tx_latency_stat_table 0-4-5 59122 NULL nohasharray
124363 +scsi_io_completion_59122 scsi_io_completion 2 59122 &sta_tx_latency_stat_table_59122
124364 +nfc_llcp_send_i_frame_59130 nfc_llcp_send_i_frame 3 59130 NULL
124365 +framebuffer_alloc_59145 framebuffer_alloc 1 59145 NULL nohasharray
124366 +print_devstats_dot11RTSSuccessCount_59145 print_devstats_dot11RTSSuccessCount 3 59145 &framebuffer_alloc_59145
124367 +radeon_compat_ioctl_59150 radeon_compat_ioctl 2 59150 NULL
124368 +pvr2_hdw_report_clients_59152 pvr2_hdw_report_clients 3 59152 NULL
124369 +ksize_59176 ksize 0 59176 NULL
124370 +setup_window_59178 setup_window 4-2-5-7 59178 NULL
124371 +ocfs2_move_extent_59187 ocfs2_move_extent 2-5 59187 NULL
124372 +xfs_iext_realloc_indirect_59211 xfs_iext_realloc_indirect 2 59211 NULL
124373 +check_mapped_selector_name_59216 check_mapped_selector_name 5 59216 NULL
124374 +dt3155_read_59226 dt3155_read 3 59226 NULL
124375 +paging64_gpte_to_gfn_lvl_59229 paging64_gpte_to_gfn_lvl 0-1-2 59229 NULL
124376 +nla_len_59258 nla_len 0 59258 NULL
124377 +drbd_bm_write_page_59290 drbd_bm_write_page 2 59290 NULL
124378 +btrfs_insert_dir_item_59304 btrfs_insert_dir_item 4 59304 NULL
124379 +fd_copyout_59323 fd_copyout 3 59323 NULL
124380 +rx_defrag_in_process_called_read_59338 rx_defrag_in_process_called_read 3 59338 NULL
124381 +xfs_attrmulti_attr_set_59346 xfs_attrmulti_attr_set 4 59346 NULL
124382 +__map_request_59350 __map_request 0 59350 NULL
124383 +SyS_getrandom_59366 SyS_getrandom 2 59366 NULL
124384 +f2fs_fallocate_59377 f2fs_fallocate 4-3 59377 NULL
124385 +pvr2_debugifc_print_info_59380 pvr2_debugifc_print_info 3 59380 NULL
124386 +journal_init_dev_59384 journal_init_dev 5 59384 NULL
124387 +__net_get_random_once_59389 __net_get_random_once 2 59389 NULL
124388 +isku_sysfs_read_keys_function_59412 isku_sysfs_read_keys_function 6 59412 NULL
124389 +vxge_hw_ring_rxds_per_block_get_59425 vxge_hw_ring_rxds_per_block_get 0 59425 NULL
124390 +SyS_sched_setaffinity_59442 SyS_sched_setaffinity 2 59442 NULL
124391 +fs_path_ensure_buf_59445 fs_path_ensure_buf 2 59445 NULL
124392 +tipc_recv_stream_59456 tipc_recv_stream 4 59456 NULL
124393 +_iwl_dbgfs_bcast_filters_write_59491 _iwl_dbgfs_bcast_filters_write 3 59491 NULL
124394 +ib_copy_from_udata_59502 ib_copy_from_udata 3 59502 NULL
124395 +C_SYSC_get_mempolicy_59516 C_SYSC_get_mempolicy 3 59516 NULL
124396 +mic_vringh_copy_59523 mic_vringh_copy 4 59523 NULL
124397 +mpi_get_nbits_59551 mpi_get_nbits 0 59551 NULL
124398 +tunables_write_59563 tunables_write 3 59563 NULL
124399 +bio_split_59564 bio_split 2 59564 NULL
124400 +__copy_from_user_ll_nozero_59571 __copy_from_user_ll_nozero 0-3 59571 NULL
124401 +write_pbl_59583 write_pbl 4 59583 NULL
124402 +memdup_user_59590 memdup_user 2 59590 NULL
124403 +mem_fwlog_free_mem_blks_read_59616 mem_fwlog_free_mem_blks_read 3 59616 NULL nohasharray
124404 +xrcdn_free_res_59616 xrcdn_free_res 5 59616 &mem_fwlog_free_mem_blks_read_59616
124405 +ath6kl_endpoint_stats_write_59621 ath6kl_endpoint_stats_write 3 59621 NULL
124406 +mtrr_write_59622 mtrr_write 3 59622 NULL
124407 +find_first_zero_bit_59636 find_first_zero_bit 0 59636 NULL
124408 +SyS_setdomainname_59646 SyS_setdomainname 2 59646 NULL
124409 +hidraw_read_59650 hidraw_read 3 59650 NULL
124410 +v9fs_xattr_set_acl_59651 v9fs_xattr_set_acl 4 59651 NULL
124411 +__devcgroup_check_permission_59665 __devcgroup_check_permission 0 59665 NULL
124412 +iwl_dbgfs_mac_params_read_59666 iwl_dbgfs_mac_params_read 3 59666 NULL
124413 +alloc_dca_provider_59670 alloc_dca_provider 2 59670 NULL
124414 +mic_calc_failure_read_59700 mic_calc_failure_read 3 59700 NULL
124415 +ioperm_get_59701 ioperm_get 4-3 59701 NULL
124416 +prism2_info_scanresults_59729 prism2_info_scanresults 3 59729 NULL
124417 +ieee80211_if_read_fwded_unicast_59740 ieee80211_if_read_fwded_unicast 3 59740 NULL nohasharray
124418 +nv94_aux_mask_59740 nv94_aux_mask 2 59740 &ieee80211_if_read_fwded_unicast_59740
124419 +qib_decode_7220_sdma_errs_59745 qib_decode_7220_sdma_errs 4 59745 NULL
124420 +strnlen_59746 strnlen 0 59746 NULL
124421 +ext3_acl_count_59754 ext3_acl_count 0-1 59754 NULL
124422 +long_retry_limit_read_59766 long_retry_limit_read 3 59766 NULL
124423 +venus_remove_59781 venus_remove 4 59781 NULL
124424 +mei_nfc_recv_59784 mei_nfc_recv 3 59784 NULL
124425 +C_SYSC_preadv_59801 C_SYSC_preadv 3 59801 NULL
124426 +ipw_write_59807 ipw_write 3 59807 NULL
124427 +scsi_init_shared_tag_map_59812 scsi_init_shared_tag_map 2 59812 NULL
124428 +ieee80211_if_read_dot11MeshHWMPmaxPREQretries_59829 ieee80211_if_read_dot11MeshHWMPmaxPREQretries 3 59829 NULL
124429 +gspca_dev_probe2_59833 gspca_dev_probe2 4 59833 NULL
124430 +regmap_raw_write_async_59849 regmap_raw_write_async 2-4 59849 NULL
124431 +biovec_create_pool_59878 biovec_create_pool 1 59878 NULL
124432 +pvr2_ioread_set_sync_key_59882 pvr2_ioread_set_sync_key 3 59882 NULL
124433 +l2cap_sock_recvmsg_59886 l2cap_sock_recvmsg 4 59886 NULL
124434 +ffs_prepare_buffer_59892 ffs_prepare_buffer 2 59892 NULL
124435 +kvm_mmu_notifier_invalidate_range_start_59944 kvm_mmu_notifier_invalidate_range_start 3-4 59944 NULL
124436 +ath10k_read_dfs_stats_59949 ath10k_read_dfs_stats 3 59949 NULL
124437 +dapm_widget_power_read_file_59950 dapm_widget_power_read_file 3 59950 NULL nohasharray
124438 +il_dbgfs_rxon_flags_read_59950 il_dbgfs_rxon_flags_read 3 59950 &dapm_widget_power_read_file_59950
124439 +il_dbgfs_missed_beacon_read_59956 il_dbgfs_missed_beacon_read 3 59956 NULL
124440 +__arch_hweight16_59975 __arch_hweight16 0 59975 NULL
124441 +osd_req_read_kern_59990 osd_req_read_kern 5 59990 NULL
124442 +ghash_async_setkey_60001 ghash_async_setkey 3 60001 NULL
124443 +ieee80211_if_fmt_dot11MeshAwakeWindowDuration_60006 ieee80211_if_fmt_dot11MeshAwakeWindowDuration 3 60006 NULL
124444 +copy_items_60009 copy_items 7 60009 NULL
124445 +rawsock_sendmsg_60010 rawsock_sendmsg 4 60010 NULL
124446 +mthca_init_cq_60011 mthca_init_cq 2 60011 NULL
124447 +osd_req_list_dev_partitions_60027 osd_req_list_dev_partitions 4 60027 NULL
124448 +xlog_bread_offset_60030 xlog_bread_offset 3 60030 NULL
124449 +bio_integrity_hw_sectors_60039 bio_integrity_hw_sectors 0-2 60039 NULL
124450 +do_ip6t_set_ctl_60040 do_ip6t_set_ctl 4 60040 NULL
124451 +vcs_size_60050 vcs_size 0 60050 NULL
124452 +gru_alloc_gts_60056 gru_alloc_gts 3-2 60056 NULL
124453 +compat_writev_60063 compat_writev 3 60063 NULL
124454 +ath6kl_listen_int_write_60066 ath6kl_listen_int_write 3 60066 NULL
124455 +c4iw_num_stags_60073 c4iw_num_stags 0 60073 NULL
124456 +usb_os_desc_prepare_interf_dir_60075 usb_os_desc_prepare_interf_dir 2 60075 NULL
124457 +rxrpc_kernel_send_data_60083 rxrpc_kernel_send_data 3 60083 NULL
124458 +ieee80211_if_fmt_fwded_frames_60103 ieee80211_if_fmt_fwded_frames 3 60103 NULL
124459 +SYSC_msgsnd_60113 SYSC_msgsnd 3 60113 NULL
124460 +nfs_idmap_request_key_60124 nfs_idmap_request_key 2 60124 NULL
124461 +__mutex_lock_common_60134 __mutex_lock_common 0 60134 NULL
124462 +ld_usb_read_60156 ld_usb_read 3 60156 NULL
124463 +jmb38x_ms_count_slots_60164 jmb38x_ms_count_slots 0 60164 NULL
124464 +init_state_60165 init_state 2 60165 NULL
124465 +jffs2_alloc_full_dirent_60179 jffs2_alloc_full_dirent 1 60179 NULL nohasharray
124466 +sg_build_sgat_60179 sg_build_sgat 3 60179 &jffs2_alloc_full_dirent_60179
124467 +fuse_async_req_send_60183 fuse_async_req_send 0-3 60183 NULL
124468 +rx_rx_tkip_replays_read_60193 rx_rx_tkip_replays_read 3 60193 NULL
124469 +qib_reg_phys_mr_60202 qib_reg_phys_mr 3 60202 NULL
124470 +btrfs_get_token_16_60220 btrfs_get_token_16 0 60220 NULL
124471 +irq_alloc_domain_generic_chips_60264 irq_alloc_domain_generic_chips 2-3 60264 NULL
124472 +display_crc_ctl_write_60273 display_crc_ctl_write 3 60273 NULL
124473 +printer_write_60276 printer_write 3 60276 NULL
124474 +do_xip_mapping_read_60297 do_xip_mapping_read 5 60297 NULL
124475 +getDataLength_60301 getDataLength 0 60301 NULL
124476 +bch_subtract_dirty_60306 bch_subtract_dirty 3-4 60306 NULL
124477 +usb_alphatrack_write_60341 usb_alphatrack_write 3 60341 NULL
124478 +__kfifo_from_user_r_60345 __kfifo_from_user_r 5-3 60345 NULL
124479 +max_unfragmented_pages_60362 max_unfragmented_pages 0 60362 NULL
124480 +dccp_setsockopt_60367 dccp_setsockopt 5 60367 NULL
124481 +mthca_alloc_resize_buf_60394 mthca_alloc_resize_buf 3 60394 NULL
124482 +ocfs2_zero_extend_60396 ocfs2_zero_extend 3 60396 NULL
124483 +driver_names_read_60399 driver_names_read 3 60399 NULL
124484 +simple_alloc_urb_60420 simple_alloc_urb 3 60420 NULL
124485 +excessive_retries_read_60425 excessive_retries_read 3 60425 NULL
124486 +kmalloc_60432 kmalloc 1 60432 NULL nohasharray
124487 +tstats_write_60432 tstats_write 3 60432 &kmalloc_60432
124488 +snd_hda_get_num_raw_conns_60462 snd_hda_get_num_raw_conns 0 60462 NULL
124489 +crypto_shash_setkey_60483 crypto_shash_setkey 3 60483 NULL
124490 +lustre_msg_early_size_60496 lustre_msg_early_size 0 60496 NULL
124491 +compat_SyS_get_mempolicy_60527 compat_SyS_get_mempolicy 3 60527 NULL
124492 +v9fs_fid_readn_60544 v9fs_fid_readn 4 60544 NULL
124493 +nonpaging_map_60551 nonpaging_map 4 60551 NULL
124494 +osc_lockless_truncate_seq_write_60553 osc_lockless_truncate_seq_write 3 60553 NULL
124495 +xfs_vm_direct_IO_60557 xfs_vm_direct_IO 4 60557 NULL
124496 +tracing_entries_write_60563 tracing_entries_write 3 60563 NULL
124497 +memblock_virt_alloc_try_nid_nopanic_60604 memblock_virt_alloc_try_nid_nopanic 1 60604 NULL
124498 +skb_transport_offset_60619 skb_transport_offset 0 60619 NULL
124499 +wl1273_fm_fops_write_60621 wl1273_fm_fops_write 3 60621 NULL
124500 +acl_alloc_stack_init_60630 acl_alloc_stack_init 1 60630 NULL
124501 +__proc_lnet_stats_60647 __proc_lnet_stats 5 60647 NULL
124502 +if_sdio_host_to_card_60666 if_sdio_host_to_card 4 60666 NULL
124503 +ieee80211_if_read_dot11MeshConfirmTimeout_60670 ieee80211_if_read_dot11MeshConfirmTimeout 3 60670 NULL
124504 +snd_ice1712_ds_read_60754 snd_ice1712_ds_read 0 60754 NULL
124505 +raid_status_60755 raid_status 5 60755 NULL
124506 +sel_write_checkreqprot_60774 sel_write_checkreqprot 3 60774 NULL
124507 +opticon_write_60775 opticon_write 4 60775 NULL
124508 +acl_alloc_num_60778 acl_alloc_num 1-2 60778 NULL
124509 +snd_pcm_oss_readv3_60792 snd_pcm_oss_readv3 3 60792 NULL
124510 +nvif_object_init_60848 nvif_object_init 6 60848 NULL
124511 +pwr_tx_with_ps_read_60851 pwr_tx_with_ps_read 3 60851 NULL
124512 +alloc_buf_60864 alloc_buf 3-2 60864 NULL
124513 +generic_writepages_60871 generic_writepages 0 60871 NULL
124514 +ext4_update_inline_data_60888 ext4_update_inline_data 3 60888 NULL
124515 +iio_debugfs_read_reg_60908 iio_debugfs_read_reg 3 60908 NULL
124516 +libcfs_sock_ioctl_60915 libcfs_sock_ioctl 0 60915 NULL
124517 +mgt_set_varlen_60916 mgt_set_varlen 4 60916 NULL
124518 +submit_extent_page_60928 submit_extent_page 5 60928 NULL
124519 +pti_char_write_60960 pti_char_write 3 60960 NULL
124520 +mwifiex_alloc_sdio_mpa_buffers_60961 mwifiex_alloc_sdio_mpa_buffers 2-3 60961 NULL
124521 +__a2mp_build_60987 __a2mp_build 3 60987 NULL
124522 +hsc_msg_alloc_60990 hsc_msg_alloc 1 60990 NULL
124523 +generic_file_direct_write_60995 generic_file_direct_write 0 60995 NULL
124524 +ath6kl_lrssi_roam_read_61022 ath6kl_lrssi_roam_read 3 61022 NULL
124525 +graph_depth_write_61024 graph_depth_write 3 61024 NULL
124526 +sdhci_pltfm_register_61031 sdhci_pltfm_register 3 61031 NULL
124527 +lpfc_idiag_queacc_write_61043 lpfc_idiag_queacc_write 3 61043 NULL
124528 +symtab_init_61050 symtab_init 2 61050 NULL
124529 +fuse_send_write_61053 fuse_send_write 0-4 61053 NULL
124530 +bitmap_scnlistprintf_61062 bitmap_scnlistprintf 0-2 61062 NULL
124531 +ahash_align_buffer_size_61070 ahash_align_buffer_size 0-1-2 61070 NULL
124532 +get_derived_key_61100 get_derived_key 4 61100 NULL
124533 +i40e_calculate_l2fpm_size_61104 i40e_calculate_l2fpm_size 0-4-3-2-1 61104 NULL
124534 +alloc_chrdev_region_61112 alloc_chrdev_region 0 61112 NULL
124535 +__probe_kernel_read_61119 __probe_kernel_read 3 61119 NULL
124536 +vmemmap_alloc_block_buf_61126 vmemmap_alloc_block_buf 1 61126 NULL
124537 +afs_proc_cells_write_61139 afs_proc_cells_write 3 61139 NULL
124538 +pair_device_61175 pair_device 4 61175 NULL nohasharray
124539 +event_oom_late_read_61175 event_oom_late_read 3 61175 &pair_device_61175
124540 +dio_bio_add_page_61178 dio_bio_add_page 0 61178 NULL
124541 +SyS_prctl_61202 SyS_prctl 4 61202 NULL
124542 +srp_create_fr_pool_61207 srp_create_fr_pool 3 61207 NULL
124543 +arch_hibernation_header_save_61212 arch_hibernation_header_save 0 61212 NULL
124544 +smk_read_ambient_61220 smk_read_ambient 3 61220 NULL
124545 +v9fs_mmap_file_read_61262 v9fs_mmap_file_read 3 61262 NULL
124546 +find_get_pages_tag_61270 find_get_pages_tag 0 61270 NULL nohasharray
124547 +btrfs_bio_alloc_61270 btrfs_bio_alloc 3 61270 &find_get_pages_tag_61270 nohasharray
124548 +ifalias_store_61270 ifalias_store 4 61270 &btrfs_bio_alloc_61270
124549 +hfsplus_getxattr_finder_info_61283 hfsplus_getxattr_finder_info 0 61283 NULL nohasharray
124550 +vortex_adbdma_getlinearpos_61283 vortex_adbdma_getlinearpos 0 61283 &hfsplus_getxattr_finder_info_61283
124551 +nvme_trans_copy_to_user_61288 nvme_trans_copy_to_user 3 61288 NULL
124552 +xfer_from_user_61307 xfer_from_user 3 61307 NULL
124553 +xfrm_user_sec_ctx_size_61320 xfrm_user_sec_ctx_size 0 61320 NULL
124554 +C_SYSC_msgsnd_61330 C_SYSC_msgsnd 3 61330 NULL
124555 +write_file_spectral_short_repeat_61335 write_file_spectral_short_repeat 3 61335 NULL
124556 +st5481_setup_isocpipes_61340 st5481_setup_isocpipes 6-4 61340 NULL
124557 +rx_rx_wa_ba_not_expected_read_61341 rx_rx_wa_ba_not_expected_read 3 61341 NULL
124558 +__dm_get_reserved_ios_61342 __dm_get_reserved_ios 0-3-2 61342 NULL
124559 +f1x_map_sysaddr_to_csrow_61344 f1x_map_sysaddr_to_csrow 2 61344 NULL
124560 +debug_debug4_read_61367 debug_debug4_read 3 61367 NULL
124561 +system_enable_write_61396 system_enable_write 3 61396 NULL
124562 +xfs_zero_remaining_bytes_61423 xfs_zero_remaining_bytes 3 61423 NULL
124563 +unix_stream_sendmsg_61455 unix_stream_sendmsg 4 61455 NULL
124564 +snd_pcm_lib_writev_transfer_61483 snd_pcm_lib_writev_transfer 5-4-2 61483 NULL
124565 +btrfs_item_size_61485 btrfs_item_size 0 61485 NULL
124566 +erst_errno_61526 erst_errno 0 61526 NULL
124567 +proc_write_device_61541 proc_write_device 3 61541 NULL
124568 +compat_SyS_select_61542 compat_SyS_select 1 61542 NULL
124569 +trace_options_core_write_61551 trace_options_core_write 3 61551 NULL
124570 +dvb_net_ioctl_61559 dvb_net_ioctl 2 61559 NULL
124571 +parport_pc_fifo_write_block_dma_61568 parport_pc_fifo_write_block_dma 3 61568 NULL
124572 +fan_proc_write_61569 fan_proc_write 3 61569 NULL
124573 +ieee80211_if_read_rc_rateidx_mask_2ghz_61570 ieee80211_if_read_rc_rateidx_mask_2ghz 3 61570 NULL
124574 +ldlm_pool_rw_atomic_seq_write_61572 ldlm_pool_rw_atomic_seq_write 3 61572 NULL
124575 +seq_open_private_61589 seq_open_private 3 61589 NULL
124576 +ept_gpte_to_gfn_lvl_61591 ept_gpte_to_gfn_lvl 0-1-2 61591 NULL
124577 +netlink_recvmsg_61600 netlink_recvmsg 4 61600 NULL
124578 +nfs4_init_uniform_client_string_61601 nfs4_init_uniform_client_string 3 61601 NULL
124579 +configfs_write_file_61621 configfs_write_file 3 61621 NULL
124580 +ieee80211_if_fmt_hw_queues_61629 ieee80211_if_fmt_hw_queues 3 61629 NULL
124581 +i2o_parm_table_get_61635 i2o_parm_table_get 6 61635 NULL
124582 +snd_pcm_oss_read3_61643 snd_pcm_oss_read3 0-3 61643 NULL nohasharray
124583 +tcf_hashinfo_init_61643 tcf_hashinfo_init 2 61643 &snd_pcm_oss_read3_61643
124584 +resize_stripes_61650 resize_stripes 2 61650 NULL
124585 +ttm_page_pool_free_61661 ttm_page_pool_free 2-0 61661 NULL
124586 +insert_one_name_61668 insert_one_name 7 61668 NULL
124587 +qib_format_hwmsg_61679 qib_format_hwmsg 2 61679 NULL
124588 +lock_loop_61681 lock_loop 1 61681 NULL
124589 +__do_tune_cpucache_61684 __do_tune_cpucache 2 61684 NULL
124590 +filter_read_61692 filter_read 3 61692 NULL
124591 +SyS_kexec_file_load_61715 SyS_kexec_file_load 3 61715 NULL
124592 +iov_length_61716 iov_length 0 61716 NULL
124593 +fragmentation_threshold_read_61718 fragmentation_threshold_read 3 61718 NULL
124594 +null_alloc_reqbuf_61719 null_alloc_reqbuf 3 61719 NULL
124595 +read_file_interrupt_61742 read_file_interrupt 3 61742 NULL nohasharray
124596 +read_file_regval_61742 read_file_regval 3 61742 &read_file_interrupt_61742
124597 +SyS_sendto_61763 SyS_sendto 6 61763 NULL
124598 +mls_compute_context_len_61812 mls_compute_context_len 0 61812 NULL
124599 +bfad_debugfs_write_regwr_61841 bfad_debugfs_write_regwr 3 61841 NULL
124600 +regcache_sync_block_61846 regcache_sync_block 5-4 61846 NULL
124601 +ath9k_hw_def_dump_eeprom_61853 ath9k_hw_def_dump_eeprom 5-4 61853 NULL
124602 +evdev_compute_buffer_size_61863 evdev_compute_buffer_size 0 61863 NULL
124603 +SYSC_lsetxattr_61869 SYSC_lsetxattr 4 61869 NULL
124604 +get_fw_name_61874 get_fw_name 3 61874 NULL
124605 +btrfs_ioctl_clone_61886 btrfs_ioctl_clone 3-4-5 61886 NULL
124606 +lprocfs_write_frac_u64_helper_61897 lprocfs_write_frac_u64_helper 2 61897 NULL
124607 +clear_refs_write_61904 clear_refs_write 3 61904 NULL
124608 +kernfs_name_61910 kernfs_name 3 61910 NULL
124609 +rx_filter_arp_filter_read_61914 rx_filter_arp_filter_read 3 61914 NULL
124610 +au0828_init_isoc_61917 au0828_init_isoc 3-2-4 61917 NULL
124611 +sctp_sendmsg_61919 sctp_sendmsg 4 61919 NULL
124612 +efi_get_runtime_map_size_61927 efi_get_runtime_map_size 0 61927 NULL
124613 +SyS_kexec_load_61946 SyS_kexec_load 2 61946 NULL
124614 +il4965_ucode_rx_stats_read_61948 il4965_ucode_rx_stats_read 3 61948 NULL
124615 +squashfs_read_id_index_table_61961 squashfs_read_id_index_table 4 61961 NULL
124616 +fix_read_error_61965 fix_read_error 4 61965 NULL
124617 +ocfs2_quota_write_61972 ocfs2_quota_write 4-5 61972 NULL
124618 +fd_locked_ioctl_61978 fd_locked_ioctl 3 61978 NULL
124619 +cow_file_range_61979 cow_file_range 3 61979 NULL
124620 +dequeue_event_62000 dequeue_event 3 62000 NULL
124621 +xt_compat_match_offset_62011 xt_compat_match_offset 0 62011 NULL
124622 +SyS_setxattr_62019 SyS_setxattr 4 62019 NULL
124623 +jffs2_do_unlink_62020 jffs2_do_unlink 4 62020 NULL
124624 +SYSC_select_62024 SYSC_select 1 62024 NULL
124625 +pmcraid_build_passthrough_ioadls_62034 pmcraid_build_passthrough_ioadls 2 62034 NULL
124626 +sctp_user_addto_chunk_62047 sctp_user_addto_chunk 2-3 62047 NULL
124627 +do_pselect_62061 do_pselect 1 62061 NULL
124628 +pcpu_alloc_bootmem_62074 pcpu_alloc_bootmem 2 62074 NULL
124629 +jffs2_security_setxattr_62107 jffs2_security_setxattr 4 62107 NULL
124630 +ip_recv_error_62117 ip_recv_error 3 62117 NULL
124631 +generic_block_fiemap_62122 generic_block_fiemap 4 62122 NULL
124632 +llc_ui_header_len_62131 llc_ui_header_len 0 62131 NULL
124633 +qib_diag_write_62133 qib_diag_write 3 62133 NULL nohasharray
124634 +kobject_add_varg_62133 kobject_add_varg 0 62133 &qib_diag_write_62133
124635 +ql_status_62135 ql_status 5 62135 NULL nohasharray
124636 +device_add_attrs_62135 device_add_attrs 0 62135 &ql_status_62135
124637 +video_usercopy_62151 video_usercopy 2 62151 NULL
124638 +SyS_getxattr_62166 SyS_getxattr 4 62166 NULL
124639 +prism54_wpa_bss_ie_get_62173 prism54_wpa_bss_ie_get 0 62173 NULL
124640 +write_file_dfs_62180 write_file_dfs 3 62180 NULL
124641 +alloc_upcall_62186 alloc_upcall 2 62186 NULL
124642 +rounded_hashtable_size_62198 rounded_hashtable_size 0 62198 NULL
124643 +sock_kmalloc_62205 sock_kmalloc 2 62205 NULL
124644 +smk_read_syslog_62227 smk_read_syslog 3 62227 NULL
124645 +SYSC_setgroups16_62232 SYSC_setgroups16 1 62232 NULL
124646 +ion_handle_test_dma_62262 ion_handle_test_dma 4-5 62262 NULL
124647 +get_random_int_62279 get_random_int 0 62279 NULL
124648 +il_dbgfs_sram_read_62296 il_dbgfs_sram_read 3 62296 NULL
124649 +sparse_early_usemaps_alloc_pgdat_section_62304 sparse_early_usemaps_alloc_pgdat_section 2 62304 NULL
124650 +subsystem_filter_read_62310 subsystem_filter_read 3 62310 NULL
124651 +Wb35Reg_BurstWrite_62327 Wb35Reg_BurstWrite 4 62327 NULL
124652 +subseq_list_62332 subseq_list 3-0 62332 NULL
124653 +ll_statahead_max_seq_write_62333 ll_statahead_max_seq_write 3 62333 NULL
124654 +flash_write_62354 flash_write 3 62354 NULL
124655 +xfpregs_set_62363 xfpregs_set 4 62363 NULL
124656 +rx_rx_timeout_read_62389 rx_rx_timeout_read 3 62389 NULL
124657 +altera_irscan_62396 altera_irscan 2 62396 NULL
124658 +set_ssp_62411 set_ssp 4 62411 NULL
124659 +tracing_saved_cmdlines_size_read_62491 tracing_saved_cmdlines_size_read 3 62491 NULL
124660 +srpc_alloc_bulk_62522 srpc_alloc_bulk 2 62522 NULL
124661 +pep_sendmsg_62524 pep_sendmsg 4 62524 NULL
124662 +test_iso_queue_62534 test_iso_queue 5 62534 NULL
124663 +debugfs_read_62535 debugfs_read 3 62535 NULL
124664 +sco_sock_sendmsg_62542 sco_sock_sendmsg 4 62542 NULL
124665 +qib_refresh_qsfp_cache_62547 qib_refresh_qsfp_cache 0 62547 NULL
124666 +xfrm_user_policy_62573 xfrm_user_policy 4 62573 NULL
124667 +compat_SyS_rt_sigpending_62580 compat_SyS_rt_sigpending 2 62580 NULL
124668 +get_subdir_62581 get_subdir 3 62581 NULL
124669 +dut_mode_write_62630 dut_mode_write 3 62630 NULL
124670 +vfs_fsync_range_62635 vfs_fsync_range 0 62635 NULL
124671 +lpfc_sli4_queue_alloc_62646 lpfc_sli4_queue_alloc 3 62646 NULL
124672 +printer_req_alloc_62687 printer_req_alloc 2 62687 NULL
124673 +ieee80211_set_probe_resp_62700 ieee80211_set_probe_resp 3 62700 NULL
124674 +bioset_integrity_create_62708 bioset_integrity_create 2 62708 NULL
124675 +gfs2_log_write_62717 gfs2_log_write 3 62717 NULL
124676 +rdm_62719 rdm 0 62719 NULL
124677 +obd_ioctl_popdata_62741 obd_ioctl_popdata 3 62741 NULL
124678 +key_replays_read_62746 key_replays_read 3 62746 NULL
124679 +lov_verify_lmm_62747 lov_verify_lmm 2 62747 NULL
124680 +mwifiex_rdeeprom_write_62754 mwifiex_rdeeprom_write 3 62754 NULL
124681 +mxt_obj_instances_62764 mxt_obj_instances 0 62764 NULL
124682 +copy_page_to_iter_iovec_62770 copy_page_to_iter_iovec 0-3 62770 NULL nohasharray
124683 +ax25_sendmsg_62770 ax25_sendmsg 4 62770 &copy_page_to_iter_iovec_62770
124684 +C_SYSC_ipc_62776 C_SYSC_ipc 3 62776 NULL
124685 +ptlrpc_req_set_repsize_62784 ptlrpc_req_set_repsize 2 62784 NULL
124686 +SyS_sched_getaffinity_62786 SyS_sched_getaffinity 2 62786 NULL
124687 +dm_stats_account_io_62787 dm_stats_account_io 3 62787 NULL
124688 +tracing_total_entries_read_62817 tracing_total_entries_read 3 62817 NULL
124689 +__rounddown_pow_of_two_62836 __rounddown_pow_of_two 0 62836 NULL
124690 +bio_get_nr_vecs_62838 bio_get_nr_vecs 0 62838 NULL
124691 +xlog_recover_add_to_trans_62839 xlog_recover_add_to_trans 4 62839 NULL
124692 +rx_fcs_err_read_62844 rx_fcs_err_read 3 62844 NULL
124693 +l2tp_ip6_recvmsg_62874 l2tp_ip6_recvmsg 4 62874 NULL
124694 +aoechr_write_62883 aoechr_write 3 62883 NULL
124695 +if_spi_host_to_card_62890 if_spi_host_to_card 4 62890 NULL
124696 +mempool_create_slab_pool_62907 mempool_create_slab_pool 1 62907 NULL
124697 +getdqbuf_62908 getdqbuf 1 62908 NULL
124698 +ll_statahead_agl_seq_write_62928 ll_statahead_agl_seq_write 3 62928 NULL
124699 +agp_create_user_memory_62955 agp_create_user_memory 1 62955 NULL
124700 +nvif_object_mthd_62960 nvif_object_mthd 4 62960 NULL
124701 +hwdep_read_62992 hwdep_read 3 62992 NULL
124702 +kstrtoull_from_user_63026 kstrtoull_from_user 2 63026 NULL
124703 +__vb2_perform_fileio_63033 __vb2_perform_fileio 3 63033 NULL
124704 +pipeline_defrag_to_csum_swi_read_63037 pipeline_defrag_to_csum_swi_read 3 63037 NULL
124705 +scsi_host_alloc_63041 scsi_host_alloc 2 63041 NULL
124706 +unlink1_63059 unlink1 3 63059 NULL
124707 +xen_set_nslabs_63066 xen_set_nslabs 0 63066 NULL
124708 +iwl_dbgfs_fw_rx_stats_read_63070 iwl_dbgfs_fw_rx_stats_read 3 63070 NULL
124709 +sep_prepare_input_output_dma_table_in_dcb_63087 sep_prepare_input_output_dma_table_in_dcb 4-5 63087 NULL
124710 +iwl_dbgfs_sensitivity_read_63116 iwl_dbgfs_sensitivity_read 3 63116 NULL
124711 +ext4_chunk_trans_blocks_63123 ext4_chunk_trans_blocks 0-2 63123 NULL
124712 +iwl_mvm_coex_dump_mbox_63153 iwl_mvm_coex_dump_mbox 4-3-0 63153 NULL
124713 +smk_write_revoke_subj_63173 smk_write_revoke_subj 3 63173 NULL
124714 +SyS_syslog_63178 SyS_syslog 3 63178 NULL
124715 +vme_master_read_63221 vme_master_read 0 63221 NULL
124716 +SyS_gethostname_63227 SyS_gethostname 2 63227 NULL
124717 +ptp_read_63251 ptp_read 4 63251 NULL
124718 +xfs_dir2_leaf_getdents_63262 xfs_dir2_leaf_getdents 3 63262 NULL
124719 +iwl_dbgfs_fw_error_dump_read_63263 iwl_dbgfs_fw_error_dump_read 3 63263 NULL
124720 +raid5_resize_63306 raid5_resize 2 63306 NULL
124721 +nfsd_vfs_read_63307 nfsd_vfs_read 5 63307 NULL
124722 +ath10k_read_fw_dbglog_63323 ath10k_read_fw_dbglog 3 63323 NULL
124723 +proc_info_read_63344 proc_info_read 3 63344 NULL
124724 +nvif_device_new_63358 nvif_device_new 5 63358 NULL
124725 +ps_upsd_max_sptime_read_63362 ps_upsd_max_sptime_read 3 63362 NULL
124726 +idmouse_read_63374 idmouse_read 3 63374 NULL
124727 +edac_pci_alloc_ctl_info_63388 edac_pci_alloc_ctl_info 1 63388 NULL nohasharray
124728 +usbnet_read_cmd_nopm_63388 usbnet_read_cmd_nopm 7 63388 &edac_pci_alloc_ctl_info_63388
124729 +rxpipe_missed_beacon_host_int_trig_rx_data_read_63405 rxpipe_missed_beacon_host_int_trig_rx_data_read 3 63405 NULL
124730 +l2cap_sock_sendmsg_63427 l2cap_sock_sendmsg 4 63427 NULL
124731 +nfsd_symlink_63442 nfsd_symlink 6 63442 NULL
124732 +si5351_bulk_write_63468 si5351_bulk_write 2-3 63468 NULL
124733 +snd_info_entry_write_63474 snd_info_entry_write 3 63474 NULL
124734 +reada_find_extent_63486 reada_find_extent 2 63486 NULL
124735 +read_kcore_63488 read_kcore 3 63488 NULL
124736 +iwl_dbgfs_bcast_filters_read_63489 iwl_dbgfs_bcast_filters_read 3 63489 NULL
124737 +snd_pcm_plug_write_transfer_63503 snd_pcm_plug_write_transfer 0-3 63503 NULL
124738 +efx_mcdi_rpc_async_63529 efx_mcdi_rpc_async 4-5 63529 NULL
124739 +ubi_more_leb_change_data_63534 ubi_more_leb_change_data 4 63534 NULL
124740 +write_file_spectral_period_63536 write_file_spectral_period 3 63536 NULL
124741 +if_sdio_read_scratch_63540 if_sdio_read_scratch 0 63540 NULL
124742 +append_to_buffer_63550 append_to_buffer 3 63550 NULL
124743 +kvm_write_guest_page_63555 kvm_write_guest_page 5 63555 NULL
124744 +rproc_alloc_63577 rproc_alloc 5 63577 NULL
124745 +write_debug_level_63613 write_debug_level 3 63613 NULL
124746 +__spi_validate_63618 __spi_validate 0 63618 NULL
124747 +symbol_build_supp_rates_63634 symbol_build_supp_rates 0 63634 NULL
124748 +hid_report_len_63637 hid_report_len 0 63637 NULL
124749 +proc_loginuid_write_63648 proc_loginuid_write 3 63648 NULL
124750 +ValidateDSDParamsChecksum_63654 ValidateDSDParamsChecksum 3 63654 NULL
124751 +ldlm_cli_enqueue_63657 ldlm_cli_enqueue 8 63657 NULL
124752 +hidraw_ioctl_63658 hidraw_ioctl 2 63658 NULL
124753 +vbi_read_63673 vbi_read 3 63673 NULL
124754 +write_file_spectral_fft_period_63696 write_file_spectral_fft_period 3 63696 NULL
124755 +nouveau_object_create__63715 nouveau_object_create_ 5 63715 NULL
124756 +btrfs_insert_delayed_dir_index_63720 btrfs_insert_delayed_dir_index 4 63720 NULL
124757 +selinux_secctx_to_secid_63744 selinux_secctx_to_secid 2 63744 NULL
124758 +snd_pcm_oss_read1_63771 snd_pcm_oss_read1 3 63771 NULL
124759 +snd_opl4_mem_proc_read_63774 snd_opl4_mem_proc_read 5 63774 NULL
124760 +spidev_compat_ioctl_63778 spidev_compat_ioctl 2 63778 NULL
124761 +mwifiex_11n_create_rx_reorder_tbl_63806 mwifiex_11n_create_rx_reorder_tbl 4 63806 NULL
124762 +copy_nodes_to_user_63807 copy_nodes_to_user 2 63807 NULL
124763 +C_SYSC_process_vm_readv_63811 C_SYSC_process_vm_readv 3-5 63811 NULL
124764 +regmap_multi_reg_write_63826 regmap_multi_reg_write 3 63826 NULL nohasharray
124765 +prepare_copy_63826 prepare_copy 2 63826 &regmap_multi_reg_write_63826
124766 +sel_write_load_63830 sel_write_load 3 63830 NULL
124767 +proc_pid_attr_write_63845 proc_pid_attr_write 3 63845 NULL
124768 +nv10_gpio_intr_mask_63862 nv10_gpio_intr_mask 4-3 63862 NULL
124769 +xhci_alloc_stream_info_63902 xhci_alloc_stream_info 3 63902 NULL
124770 +uvc_alloc_urb_buffers_63922 uvc_alloc_urb_buffers 0-2-3 63922 NULL
124771 +snd_compr_write_63923 snd_compr_write 3 63923 NULL
124772 +afs_send_simple_reply_63940 afs_send_simple_reply 3 63940 NULL
124773 +__team_options_register_63941 __team_options_register 3 63941 NULL
124774 +macvtap_recvmsg_63949 macvtap_recvmsg 4 63949 NULL
124775 +set_bredr_63975 set_bredr 4 63975 NULL
124776 +construct_key_and_link_63985 construct_key_and_link 3 63985 NULL
124777 +rs_extent_to_bm_page_63996 rs_extent_to_bm_page 0-1 63996 NULL
124778 +read_file_frameerrors_64001 read_file_frameerrors 3 64001 NULL
124779 +SyS_rt_sigpending_64018 SyS_rt_sigpending 2 64018 NULL
124780 +dbAllocDmapLev_64030 dbAllocDmapLev 0 64030 NULL
124781 +SyS_fsetxattr_64039 SyS_fsetxattr 4 64039 NULL
124782 +__sock_create_64069 __sock_create 0 64069 NULL
124783 +get_u8_64076 get_u8 0 64076 NULL
124784 +xilly_malloc_64077 xilly_malloc 2 64077 NULL
124785 +sl_realloc_bufs_64086 sl_realloc_bufs 2 64086 NULL
124786 +vmci_handle_arr_get_size_64088 vmci_handle_arr_get_size 0 64088 NULL
124787 +lbs_highrssi_read_64089 lbs_highrssi_read 3 64089 NULL
124788 +SyS_set_mempolicy_64096 SyS_set_mempolicy 3 64096 NULL
124789 +to_bytes_64103 to_bytes 0-1 64103 NULL
124790 +SyS_mq_timedsend_64107 SyS_mq_timedsend 3 64107 NULL
124791 +rdma_addr_size_64116 rdma_addr_size 0 64116 NULL
124792 +do_load_xattr_datum_64118 do_load_xattr_datum 0 64118 NULL
124793 +bypass_wd_write_64120 bypass_wd_write 3 64120 NULL
124794 +ext4_prepare_inline_data_64124 ext4_prepare_inline_data 3 64124 NULL
124795 +init_bch_64130 init_bch 1-2 64130 NULL
124796 +ablkcipher_copy_iv_64140 ablkcipher_copy_iv 3 64140 NULL
124797 +dlfb_ops_write_64150 dlfb_ops_write 3 64150 NULL
124798 +number_of_tds_64156 number_of_tds 0 64156 NULL
124799 +bnx2x_vf_mcast_64166 bnx2x_vf_mcast 4 64166 NULL
124800 +cpumask_scnprintf_64170 cpumask_scnprintf 0-2 64170 NULL
124801 +kernfs_iop_setxattr_64220 kernfs_iop_setxattr 4 64220 NULL
124802 +read_pulse_64227 read_pulse 0-3 64227 NULL
124803 +ea_len_64229 ea_len 0 64229 NULL
124804 +io_capture_transfer_64276 io_capture_transfer 4 64276 NULL
124805 +btrfs_file_extent_offset_64278 btrfs_file_extent_offset 0 64278 NULL nohasharray
124806 +bpf_check_classic_64278 bpf_check_classic 2 64278 &btrfs_file_extent_offset_64278
124807 +sta_current_tx_rate_read_64286 sta_current_tx_rate_read 3 64286 NULL
124808 +xfs_dir_cilookup_result_64288 xfs_dir_cilookup_result 3 64288 NULL nohasharray
124809 +event_id_read_64288 event_id_read 3 64288 &xfs_dir_cilookup_result_64288
124810 +info_debugfs_read_64291 info_debugfs_read 3 64291 NULL
124811 +ocfs2_block_check_validate_bhs_64302 ocfs2_block_check_validate_bhs 0 64302 NULL
124812 +snd_hda_get_sub_nodes_64304 snd_hda_get_sub_nodes 0 64304 NULL
124813 +error_error_bar_retry_read_64305 error_error_bar_retry_read 3 64305 NULL
124814 +sisusbcon_clear_64329 sisusbcon_clear 4-3-5 64329 NULL
124815 +ts_write_64336 ts_write 3 64336 NULL
124816 +usbtmc_write_64340 usbtmc_write 3 64340 NULL
124817 +user_regset_copyin_64360 user_regset_copyin 7 64360 NULL
124818 +wlc_phy_loadsampletable_nphy_64367 wlc_phy_loadsampletable_nphy 3 64367 NULL
124819 +reg_create_64372 reg_create 5 64372 NULL
124820 +ilo_write_64378 ilo_write 3 64378 NULL
124821 +btrfs_map_block_64379 btrfs_map_block 3 64379 NULL
124822 +vmcs_readl_64381 vmcs_readl 0 64381 NULL
124823 +nilfs_alloc_seg_bio_64383 nilfs_alloc_seg_bio 3 64383 NULL
124824 +ir_lirc_transmit_ir_64403 ir_lirc_transmit_ir 3 64403 NULL
124825 +pidlist_allocate_64404 pidlist_allocate 1 64404 NULL
124826 +rx_hdr_overflow_read_64407 rx_hdr_overflow_read 3 64407 NULL
124827 +keyctl_get_security_64418 keyctl_get_security 3 64418 NULL
124828 +oom_adj_write_64428 oom_adj_write 3 64428 NULL
124829 +read_file_spectral_short_repeat_64431 read_file_spectral_short_repeat 3 64431 NULL
124830 +ax25_recvmsg_64441 ax25_recvmsg 4 64441 NULL
124831 +single_open_size_64483 single_open_size 4 64483 NULL
124832 +p54_parse_rssical_64493 p54_parse_rssical 3 64493 NULL
124833 +msg_data_sz_64503 msg_data_sz 0 64503 NULL
124834 +remove_uuid_64505 remove_uuid 4 64505 NULL
124835 +opera1_usb_i2c_msgxfer_64521 opera1_usb_i2c_msgxfer 4 64521 NULL
124836 +iwl_dbgfs_ucode_tracing_write_64524 iwl_dbgfs_ucode_tracing_write 3 64524 NULL
124837 +ses_send_diag_64527 ses_send_diag 4 64527 NULL
124838 +prctl_set_mm_64538 prctl_set_mm 3 64538 NULL
124839 +SyS_bind_64544 SyS_bind 3 64544 NULL
124840 +rbd_obj_read_sync_64554 rbd_obj_read_sync 3-4 64554 NULL
124841 +__btrfs_prealloc_file_range_64557 __btrfs_prealloc_file_range 3 64557 NULL
124842 +ll_max_rw_chunk_seq_write_64561 ll_max_rw_chunk_seq_write 3 64561 NULL nohasharray
124843 +__spi_sync_64561 __spi_sync 0 64561 &ll_max_rw_chunk_seq_write_64561
124844 +__apei_exec_run_64563 __apei_exec_run 0 64563 NULL
124845 +kstrtoul_from_user_64569 kstrtoul_from_user 2 64569 NULL
124846 +do_erase_64574 do_erase 4 64574 NULL
124847 +fanotify_write_64623 fanotify_write 3 64623 NULL
124848 +_iwl_dbgfs_d0i3_refs_write_64642 _iwl_dbgfs_d0i3_refs_write 3 64642 NULL
124849 +regmap_read_debugfs_64658 regmap_read_debugfs 5 64658 NULL
124850 +ocfs2_read_xattr_block_64661 ocfs2_read_xattr_block 0 64661 NULL nohasharray
124851 +tlbflush_read_file_64661 tlbflush_read_file 3 64661 &ocfs2_read_xattr_block_64661
124852 +efx_tsoh_get_buffer_64664 efx_tsoh_get_buffer 3 64664 NULL
124853 +rx_rx_out_of_mpdu_nodes_read_64668 rx_rx_out_of_mpdu_nodes_read 3 64668 NULL
124854 +nr_free_zone_pages_64680 nr_free_zone_pages 0 64680 NULL
124855 +snd_pcm_oss_capture_position_fixup_64713 snd_pcm_oss_capture_position_fixup 0 64713 NULL
124856 +dapm_bias_read_file_64715 dapm_bias_read_file 3 64715 NULL
124857 +atomic_add_return_64720 atomic_add_return 0-1 64720 NULL
124858 +i2400m_msg_to_dev_64722 i2400m_msg_to_dev 3 64722 NULL
124859 +squashfs_read_inode_lookup_table_64739 squashfs_read_inode_lookup_table 4 64739 NULL
124860 +bio_map_kern_64751 bio_map_kern 3 64751 NULL
124861 +rt2x00debug_write_csr_64753 rt2x00debug_write_csr 3 64753 NULL
124862 +hwdep_write_64776 hwdep_write 3 64776 NULL
124863 +message_for_md_64777 message_for_md 5 64777 NULL
124864 +isr_low_rssi_read_64789 isr_low_rssi_read 3 64789 NULL
124865 +regmap_reg_ranges_read_file_64798 regmap_reg_ranges_read_file 3 64798 NULL
124866 +nfsctl_transaction_write_64800 nfsctl_transaction_write 3 64800 NULL
124867 +rfkill_fop_write_64808 rfkill_fop_write 3 64808 NULL nohasharray
124868 +nv_mask_64808 nv_mask 0 64808 &rfkill_fop_write_64808
124869 +proc_projid_map_write_64810 proc_projid_map_write 3 64810 NULL
124870 +megaraid_change_queue_depth_64815 megaraid_change_queue_depth 2 64815 NULL
124871 +ecryptfs_send_miscdev_64816 ecryptfs_send_miscdev 2 64816 NULL
124872 +do_kimage_alloc_64827 do_kimage_alloc 3 64827 NULL
124873 +altera_set_dr_pre_64862 altera_set_dr_pre 2 64862 NULL
124874 +pci_vc_do_save_buffer_64876 pci_vc_do_save_buffer 0 64876 NULL
124875 +lprocfs_write_u64_helper_64880 lprocfs_write_u64_helper 2 64880 NULL
124876 +ieee80211_if_read_ave_beacon_64924 ieee80211_if_read_ave_beacon 3 64924 NULL
124877 +ip_options_get_from_user_64958 ip_options_get_from_user 4 64958 NULL nohasharray
124878 +tipc_port_iovec_reject_64958 tipc_port_iovec_reject 4 64958 &ip_options_get_from_user_64958
124879 +traceprobe_probes_write_64969 traceprobe_probes_write 3 64969 NULL
124880 +suspend_dtim_interval_read_64971 suspend_dtim_interval_read 3 64971 NULL
124881 +crypto_ahash_digestsize_65014 crypto_ahash_digestsize 0 65014 NULL
124882 +insert_dent_65034 insert_dent 7 65034 NULL
124883 +snd_hda_get_pin_label_65035 snd_hda_get_pin_label 5 65035 NULL
124884 +ext4_ind_trans_blocks_65053 ext4_ind_trans_blocks 0-2 65053 NULL
124885 +pcibios_enable_device_65059 pcibios_enable_device 0 65059 NULL
124886 +__alloc_bootmem_node_high_65076 __alloc_bootmem_node_high 2 65076 NULL
124887 +batadv_socket_write_65083 batadv_socket_write 3 65083 NULL
124888 +ocfs2_truncate_cluster_pages_65086 ocfs2_truncate_cluster_pages 2 65086 NULL
124889 +ath9k_dump_mci_btcoex_65090 ath9k_dump_mci_btcoex 0-3 65090 NULL
124890 +rx_rx_done_read_65217 rx_rx_done_read 3 65217 NULL
124891 +nouveau_event_create_65229 nouveau_event_create 2-1 65229 NULL
124892 +print_endpoint_stat_65232 print_endpoint_stat 0-4-3 65232 NULL
124893 +whci_n_caps_65247 whci_n_caps 0 65247 NULL
124894 +kmalloc_parameter_65279 kmalloc_parameter 1 65279 NULL
124895 +compat_core_sys_select_65285 compat_core_sys_select 1 65285 NULL
124896 +mpi_set_buffer_65294 mpi_set_buffer 3 65294 NULL
124897 +fat_direct_IO_65295 fat_direct_IO 4 65295 NULL
124898 +redirected_tty_write_65297 redirected_tty_write 3 65297 NULL
124899 +get_var_len_65304 get_var_len 0 65304 NULL
124900 +unpack_array_65318 unpack_array 0 65318 NULL
124901 +pci_vpd_find_tag_65325 pci_vpd_find_tag 0-2 65325 NULL
124902 +dccp_setsockopt_service_65336 dccp_setsockopt_service 4 65336 NULL
124903 +dma_rx_requested_read_65354 dma_rx_requested_read 3 65354 NULL
124904 +alloc_cpu_rmap_65363 alloc_cpu_rmap 1 65363 NULL
124905 +SyS_writev_65372 SyS_writev 3 65372 NULL
124906 +__alloc_bootmem_nopanic_65397 __alloc_bootmem_nopanic 1 65397 NULL
124907 +trace_seq_to_user_65398 trace_seq_to_user 3 65398 NULL
124908 +__read_vmcore_65402 __read_vmcore 2 65402 NULL
124909 +ocfs2_write_begin_nolock_65410 ocfs2_write_begin_nolock 3-4 65410 NULL
124910 +device_add_groups_65423 device_add_groups 0 65423 NULL
124911 +xpc_kzalloc_cacheline_aligned_65433 xpc_kzalloc_cacheline_aligned 1 65433 NULL
124912 +usb_alloc_coherent_65444 usb_alloc_coherent 2 65444 NULL
124913 +il_dbgfs_wd_timeout_write_65464 il_dbgfs_wd_timeout_write 3 65464 NULL
124914 +clear_user_65470 clear_user 2 65470 NULL
124915 +dpcm_state_read_file_65489 dpcm_state_read_file 3 65489 NULL
124916 +lookup_inline_extent_backref_65493 lookup_inline_extent_backref 9 65493 NULL
124917 +nvme_trans_standard_inquiry_page_65526 nvme_trans_standard_inquiry_page 4 65526 NULL
124918 +tree_mod_log_eb_copy_65535 tree_mod_log_eb_copy 6 65535 NULL
124919 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_hash_aux.data b/tools/gcc/size_overflow_plugin/size_overflow_hash_aux.data
124920 new file mode 100644
124921 index 0000000..560cd7b
124922 --- /dev/null
124923 +++ b/tools/gcc/size_overflow_plugin/size_overflow_hash_aux.data
124924 @@ -0,0 +1,92 @@
124925 +spa_set_aux_vdevs_746 spa_set_aux_vdevs 3 746 NULL
124926 +zfs_lookup_2144 zfs_lookup 0 2144 NULL
124927 +mappedread_2627 mappedread 2 2627 NULL
124928 +vdev_disk_dio_alloc_2957 vdev_disk_dio_alloc 1 2957 NULL
124929 +nv_alloc_pushpage_spl_4286 nv_alloc_pushpage_spl 2 4286 NULL
124930 +zpl_xattr_get_4574 zpl_xattr_get 0 4574 NULL
124931 +sa_replace_all_by_template_5699 sa_replace_all_by_template 3 5699 NULL
124932 +dmu_write_6048 dmu_write 4-3 6048 NULL
124933 +dmu_buf_hold_array_6095 dmu_buf_hold_array 4-3 6095 NULL
124934 +update_pages_6225 update_pages 2-3 6225 NULL
124935 +bio_nr_pages_7117 bio_nr_pages 0-2 7117 NULL
124936 +dmu_buf_hold_array_by_bonus_8562 dmu_buf_hold_array_by_bonus 3-2 8562 NULL
124937 +zpios_dmu_write_8858 zpios_dmu_write 4-5 8858 NULL
124938 +ddi_copyout_9401 ddi_copyout 3 9401 NULL
124939 +avl_numnodes_12384 avl_numnodes 0 12384 NULL
124940 +dmu_write_uio_dnode_12473 dmu_write_uio_dnode 3 12473 NULL
124941 +dmu_xuio_init_12866 dmu_xuio_init 2 12866 NULL
124942 +zpl_read_common_14389 zpl_read_common 0 14389 NULL
124943 +dmu_snapshot_realname_14632 dmu_snapshot_realname 4 14632 NULL
124944 +kmem_alloc_debug_14852 kmem_alloc_debug 1 14852 NULL
124945 +kmalloc_node_nofail_15151 kmalloc_node_nofail 1 15151 NULL
124946 +dmu_write_uio_16351 dmu_write_uio 4 16351 NULL
124947 +zfs_log_write_16524 zfs_log_write 6-5 16524 NULL
124948 +sa_build_layouts_16910 sa_build_layouts 3 16910 NULL
124949 +dsl_dir_namelen_17053 dsl_dir_namelen 0 17053 NULL
124950 +kcopy_copy_to_user_17336 kcopy_copy_to_user 5 17336 NULL
124951 +sa_add_layout_entry_17507 sa_add_layout_entry 3 17507 NULL
124952 +sa_attr_table_setup_18029 sa_attr_table_setup 3 18029 NULL
124953 +uiocopy_18680 uiocopy 2 18680 NULL
124954 +dmu_buf_hold_array_by_dnode_19125 dmu_buf_hold_array_by_dnode 2-3 19125 NULL
124955 +zpl_acl_from_xattr_21141 zpl_acl_from_xattr 2 21141 NULL
124956 +dsl_pool_tx_assign_init_22518 dsl_pool_tx_assign_init 2 22518 NULL
124957 +nvlist_lookup_byte_array_22527 nvlist_lookup_byte_array 0 22527 NULL
124958 +sa_replace_all_by_template_locked_22533 sa_replace_all_by_template_locked 3 22533 NULL
124959 +tsd_hash_table_init_22559 tsd_hash_table_init 1 22559 NULL
124960 +spa_vdev_remove_aux_23966 spa_vdev_remove_aux 4 23966 NULL
124961 +zpl_xattr_acl_set_access_24129 zpl_xattr_acl_set_access 4 24129 NULL
124962 +dmu_assign_arcbuf_24622 dmu_assign_arcbuf 2 24622 NULL
124963 +zap_lookup_norm_25166 zap_lookup_norm 9 25166 NULL
124964 +dmu_prealloc_25456 dmu_prealloc 4-3 25456 NULL
124965 +kmalloc_nofail_26347 kmalloc_nofail 1 26347 NULL
124966 +zfsctl_snapshot_zpath_27578 zfsctl_snapshot_zpath 2 27578 NULL
124967 +zpios_dmu_read_30015 zpios_dmu_read 4-5 30015 NULL
124968 +splat_write_30943 splat_write 3 30943 NULL
124969 +zpl_xattr_get_sa_31183 zpl_xattr_get_sa 0 31183 NULL
124970 +dmu_read_uio_31467 dmu_read_uio 4 31467 NULL
124971 +zfs_replay_fuids_31479 zfs_replay_fuids 4 31479 NULL
124972 +spa_history_log_to_phys_31632 spa_history_log_to_phys 0-1 31632 NULL
124973 +__zpl_xattr_get_32601 __zpl_xattr_get 0 32601 NULL
124974 +proc_copyout_string_34049 proc_copyout_string 2 34049 NULL
124975 +nv_alloc_sleep_spl_34544 nv_alloc_sleep_spl 2 34544 NULL
124976 +nv_alloc_nosleep_spl_34761 nv_alloc_nosleep_spl 2 34761 NULL
124977 +zap_leaf_array_match_36922 zap_leaf_array_match 4 36922 NULL
124978 +copyinstr_36980 copyinstr 3 36980 NULL
124979 +zpl_xattr_acl_set_default_37864 zpl_xattr_acl_set_default 4 37864 NULL
124980 +splat_read_38116 splat_read 3 38116 NULL
124981 +sa_setup_38756 sa_setup 4 38756 NULL
124982 +vdev_disk_physio_39898 vdev_disk_physio 3 39898 NULL
124983 +arc_buf_size_39982 arc_buf_size 0 39982 NULL
124984 +kzalloc_nofail_40719 kzalloc_nofail 1 40719 NULL
124985 +fuidstr_to_sid_40777 fuidstr_to_sid 4 40777 NULL
124986 +vdev_raidz_matrix_reconstruct_40852 vdev_raidz_matrix_reconstruct 2-3 40852 NULL
124987 +sa_find_layout_40892 sa_find_layout 4 40892 NULL
124988 +zpl_xattr_get_dir_41918 zpl_xattr_get_dir 0 41918 NULL
124989 +zfs_sa_get_xattr_42600 zfs_sa_get_xattr 0 42600 NULL
124990 +zpl_xattr_acl_set_42808 zpl_xattr_acl_set 4 42808 NULL
124991 +xdr_dec_array_43091 xdr_dec_array 5 43091 NULL
124992 +dsl_dataset_namelen_43136 dsl_dataset_namelen 0 43136 NULL
124993 +kcopy_write_43683 kcopy_write 3 43683 NULL
124994 +uiomove_44355 uiomove 2 44355 NULL
124995 +dmu_read_44418 dmu_read 4-3 44418 NULL
124996 +ddi_copyin_44846 ddi_copyin 3 44846 NULL
124997 +kcopy_do_get_45061 kcopy_do_get 5 45061 NULL
124998 +copyin_45945 copyin 3 45945 NULL
124999 +zil_itx_create_46555 zil_itx_create 2 46555 NULL
125000 +dmu_write_uio_dbuf_48064 dmu_write_uio_dbuf 3 48064 NULL
125001 +blk_rq_pos_48233 blk_rq_pos 0 48233 NULL
125002 +spa_history_write_49650 spa_history_write 3 49650 NULL
125003 +kcopy_copy_pages_to_user_49823 kcopy_copy_pages_to_user 3-4 49823 NULL
125004 +zfs_log_write_50162 zfs_log_write 6-5 50162 NULL
125005 +i_fm_alloc_51038 i_fm_alloc 2 51038 NULL
125006 +copyout_51409 copyout 3 51409 NULL
125007 +zvol_log_write_54898 zvol_log_write 4-3 54898 NULL
125008 +zfs_acl_node_alloc_55641 zfs_acl_node_alloc 1 55641 NULL
125009 +get_nvlist_56685 get_nvlist 2 56685 NULL
125010 +zprop_get_numprops_56820 zprop_get_numprops 0 56820 NULL
125011 +splat_taskq_test4_common_59829 splat_taskq_test4_common 5 59829 NULL
125012 +zfs_replay_domain_cnt_61399 zfs_replay_domain_cnt 0 61399 NULL
125013 +zpios_write_61823 zpios_write 3 61823 NULL
125014 +proc_copyin_string_62019 proc_copyin_string 4 62019 NULL
125015 +random_get_pseudo_bytes_64611 random_get_pseudo_bytes 2 64611 NULL
125016 +zpios_read_64734 zpios_read 3 64734 NULL
125017 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin/size_overflow_plugin.c
125018 new file mode 100644
125019 index 0000000..95f7abd
125020 --- /dev/null
125021 +++ b/tools/gcc/size_overflow_plugin/size_overflow_plugin.c
125022 @@ -0,0 +1,259 @@
125023 +/*
125024 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
125025 + * Licensed under the GPL v2, or (at your option) v3
125026 + *
125027 + * Homepage:
125028 + * http://www.grsecurity.net/~ephox/overflow_plugin/
125029 + *
125030 + * Documentation:
125031 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
125032 + *
125033 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
125034 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
125035 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
125036 + *
125037 + * Usage:
125038 + * $ make
125039 + * $ make run
125040 + */
125041 +
125042 +#include "gcc-common.h"
125043 +#include "size_overflow.h"
125044 +
125045 +int plugin_is_GPL_compatible;
125046 +
125047 +tree report_size_overflow_decl;
125048 +
125049 +tree size_overflow_type_HI;
125050 +tree size_overflow_type_SI;
125051 +tree size_overflow_type_DI;
125052 +tree size_overflow_type_TI;
125053 +
125054 +static struct plugin_info size_overflow_plugin_info = {
125055 + .version = "20140725",
125056 + .help = "no-size-overflow\tturn off size overflow checking\n",
125057 +};
125058 +
125059 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
125060 +{
125061 + unsigned int arg_count;
125062 + enum tree_code code = TREE_CODE(*node);
125063 +
125064 + switch (code) {
125065 + case FUNCTION_DECL:
125066 + arg_count = type_num_arguments(TREE_TYPE(*node));
125067 + break;
125068 + case FUNCTION_TYPE:
125069 + case METHOD_TYPE:
125070 + arg_count = type_num_arguments(*node);
125071 + break;
125072 + default:
125073 + *no_add_attrs = true;
125074 + error("%s: %qE attribute only applies to functions", __func__, name);
125075 + return NULL_TREE;
125076 + }
125077 +
125078 + for (; args; args = TREE_CHAIN(args)) {
125079 + tree position = TREE_VALUE(args);
125080 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_LOW(position) > arg_count ) {
125081 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
125082 + *no_add_attrs = true;
125083 + }
125084 + }
125085 + return NULL_TREE;
125086 +}
125087 +
125088 +static tree handle_intentional_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
125089 +{
125090 + unsigned int arg_count;
125091 + enum tree_code code = TREE_CODE(*node);
125092 +
125093 + switch (code) {
125094 + case FUNCTION_DECL:
125095 + arg_count = type_num_arguments(TREE_TYPE(*node));
125096 + break;
125097 + case FUNCTION_TYPE:
125098 + case METHOD_TYPE:
125099 + arg_count = type_num_arguments(*node);
125100 + break;
125101 + case FIELD_DECL:
125102 + return NULL_TREE;
125103 + default:
125104 + *no_add_attrs = true;
125105 + error("%qE attribute only applies to functions", name);
125106 + return NULL_TREE;
125107 + }
125108 +
125109 + if (TREE_INT_CST_HIGH(TREE_VALUE(args)) != 0)
125110 + return NULL_TREE;
125111 +
125112 + for (; args; args = TREE_CHAIN(args)) {
125113 + tree position = TREE_VALUE(args);
125114 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_LOW(position) > arg_count ) {
125115 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
125116 + *no_add_attrs = true;
125117 + }
125118 + }
125119 + return NULL_TREE;
125120 +}
125121 +
125122 +static struct attribute_spec size_overflow_attr = {
125123 + .name = "size_overflow",
125124 + .min_length = 1,
125125 + .max_length = -1,
125126 + .decl_required = true,
125127 + .type_required = false,
125128 + .function_type_required = false,
125129 + .handler = handle_size_overflow_attribute,
125130 +#if BUILDING_GCC_VERSION >= 4007
125131 + .affects_type_identity = false
125132 +#endif
125133 +};
125134 +
125135 +static struct attribute_spec intentional_overflow_attr = {
125136 + .name = "intentional_overflow",
125137 + .min_length = 1,
125138 + .max_length = -1,
125139 + .decl_required = true,
125140 + .type_required = false,
125141 + .function_type_required = false,
125142 + .handler = handle_intentional_overflow_attribute,
125143 +#if BUILDING_GCC_VERSION >= 4007
125144 + .affects_type_identity = false
125145 +#endif
125146 +};
125147 +
125148 +static void register_attributes(void __unused *event_data, void __unused *data)
125149 +{
125150 + register_attribute(&size_overflow_attr);
125151 + register_attribute(&intentional_overflow_attr);
125152 +}
125153 +
125154 +static tree create_typedef(tree type, const char* ident)
125155 +{
125156 + tree new_type, decl;
125157 +
125158 + new_type = build_variant_type_copy(type);
125159 + decl = build_decl(BUILTINS_LOCATION, TYPE_DECL, get_identifier(ident), new_type);
125160 + DECL_ORIGINAL_TYPE(decl) = type;
125161 + TYPE_NAME(new_type) = decl;
125162 + return new_type;
125163 +}
125164 +
125165 +// Create the noreturn report_size_overflow() function decl.
125166 +static void size_overflow_start_unit(void __unused *gcc_data, void __unused *user_data)
125167 +{
125168 + tree const_char_ptr_type_node;
125169 + tree fntype;
125170 +
125171 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
125172 +
125173 + size_overflow_type_HI = create_typedef(intHI_type_node, "size_overflow_type_HI");
125174 + size_overflow_type_SI = create_typedef(intSI_type_node, "size_overflow_type_SI");
125175 + size_overflow_type_DI = create_typedef(intDI_type_node, "size_overflow_type_DI");
125176 + size_overflow_type_TI = create_typedef(intTI_type_node, "size_overflow_type_TI");
125177 +
125178 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func, const char *ssa_var)
125179 + fntype = build_function_type_list(void_type_node,
125180 + const_char_ptr_type_node,
125181 + unsigned_type_node,
125182 + const_char_ptr_type_node,
125183 + const_char_ptr_type_node,
125184 + NULL_TREE);
125185 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
125186 +
125187 + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
125188 + TREE_PUBLIC(report_size_overflow_decl) = 1;
125189 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
125190 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
125191 + TREE_THIS_VOLATILE(report_size_overflow_decl) = 1;
125192 +}
125193 +
125194 +
125195 +extern struct gimple_opt_pass pass_dce;
125196 +
125197 +static struct opt_pass *make_dce_pass(void)
125198 +{
125199 +#if BUILDING_GCC_VERSION >= 4009
125200 + return make_pass_dce(g);
125201 +#else
125202 + return &pass_dce.pass;
125203 +#endif
125204 +}
125205 +
125206 +
125207 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
125208 +{
125209 + int i;
125210 + const char * const plugin_name = plugin_info->base_name;
125211 + const int argc = plugin_info->argc;
125212 + const struct plugin_argument * const argv = plugin_info->argv;
125213 + bool enable = true;
125214 + struct register_pass_info insert_size_overflow_asm_pass_info;
125215 + struct register_pass_info __unused dump_before_pass_info;
125216 + struct register_pass_info __unused dump_after_pass_info;
125217 + struct register_pass_info insert_size_overflow_check_info;
125218 + struct register_pass_info dce_pass_info;
125219 + static const struct ggc_root_tab gt_ggc_r_gt_size_overflow[] = {
125220 + {
125221 + .base = &report_size_overflow_decl,
125222 + .nelt = 1,
125223 + .stride = sizeof(report_size_overflow_decl),
125224 + .cb = &gt_ggc_mx_tree_node,
125225 + .pchw = &gt_pch_nx_tree_node
125226 + },
125227 + LAST_GGC_ROOT_TAB
125228 + };
125229 +
125230 + insert_size_overflow_asm_pass_info.pass = make_insert_size_overflow_asm_pass();
125231 + insert_size_overflow_asm_pass_info.reference_pass_name = "ssa";
125232 + insert_size_overflow_asm_pass_info.ref_pass_instance_number = 1;
125233 + insert_size_overflow_asm_pass_info.pos_op = PASS_POS_INSERT_AFTER;
125234 +
125235 + dump_before_pass_info.pass = make_dump_pass();
125236 + dump_before_pass_info.reference_pass_name = "increase_alignment";
125237 + dump_before_pass_info.ref_pass_instance_number = 1;
125238 + dump_before_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
125239 +
125240 + insert_size_overflow_check_info.pass = make_insert_size_overflow_check();
125241 + insert_size_overflow_check_info.reference_pass_name = "increase_alignment";
125242 + insert_size_overflow_check_info.ref_pass_instance_number = 1;
125243 + insert_size_overflow_check_info.pos_op = PASS_POS_INSERT_BEFORE;
125244 +
125245 + dump_after_pass_info.pass = make_dump_pass();
125246 + dump_after_pass_info.reference_pass_name = "increase_alignment";
125247 + dump_after_pass_info.ref_pass_instance_number = 1;
125248 + dump_after_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
125249 +
125250 + dce_pass_info.pass = make_dce_pass();
125251 + dce_pass_info.reference_pass_name = "vrp";
125252 + dce_pass_info.ref_pass_instance_number = 1;
125253 + dce_pass_info.pos_op = PASS_POS_INSERT_AFTER;
125254 +
125255 + if (!plugin_default_version_check(version, &gcc_version)) {
125256 + error(G_("incompatible gcc/plugin versions"));
125257 + return 1;
125258 + }
125259 +
125260 + for (i = 0; i < argc; ++i) {
125261 + if (!strcmp(argv[i].key, "no-size-overflow")) {
125262 + enable = false;
125263 + continue;
125264 + }
125265 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
125266 + }
125267 +
125268 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
125269 + if (enable) {
125270 + register_callback(plugin_name, PLUGIN_START_UNIT, &size_overflow_start_unit, NULL);
125271 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_size_overflow);
125272 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &insert_size_overflow_asm_pass_info);
125273 +// register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dump_before_pass_info);
125274 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &insert_size_overflow_check_info);
125275 +// register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dump_after_pass_info);
125276 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dce_pass_info);
125277 + }
125278 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
125279 +
125280 + return 0;
125281 +}
125282 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_plugin_hash.c b/tools/gcc/size_overflow_plugin/size_overflow_plugin_hash.c
125283 new file mode 100644
125284 index 0000000..0888f6c
125285 --- /dev/null
125286 +++ b/tools/gcc/size_overflow_plugin/size_overflow_plugin_hash.c
125287 @@ -0,0 +1,364 @@
125288 +/*
125289 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
125290 + * Licensed under the GPL v2, or (at your option) v3
125291 + *
125292 + * Homepage:
125293 + * http://www.grsecurity.net/~ephox/overflow_plugin/
125294 + *
125295 + * Documentation:
125296 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
125297 + *
125298 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
125299 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
125300 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
125301 + *
125302 + * Usage:
125303 + * $ make
125304 + * $ make run
125305 + */
125306 +
125307 +#include "gcc-common.h"
125308 +#include "size_overflow.h"
125309 +
125310 +#include "size_overflow_hash.h"
125311 +#include "size_overflow_hash_aux.h"
125312 +
125313 +#define CODES_LIMIT 32
125314 +
125315 +static unsigned char get_tree_code(const_tree type)
125316 +{
125317 + switch (TREE_CODE(type)) {
125318 + case ARRAY_TYPE:
125319 + return 0;
125320 + case BOOLEAN_TYPE:
125321 + return 1;
125322 + case ENUMERAL_TYPE:
125323 + return 2;
125324 + case FUNCTION_TYPE:
125325 + return 3;
125326 + case INTEGER_TYPE:
125327 + return 4;
125328 + case POINTER_TYPE:
125329 + return 5;
125330 + case RECORD_TYPE:
125331 + return 6;
125332 + case UNION_TYPE:
125333 + return 7;
125334 + case VOID_TYPE:
125335 + return 8;
125336 + case REAL_TYPE:
125337 + return 9;
125338 + case VECTOR_TYPE:
125339 + return 10;
125340 + case REFERENCE_TYPE:
125341 + return 11;
125342 + case OFFSET_TYPE:
125343 + return 12;
125344 + case COMPLEX_TYPE:
125345 + return 13;
125346 + default:
125347 + debug_tree((tree)type);
125348 + gcc_unreachable();
125349 + }
125350 +}
125351 +
125352 +struct function_hash {
125353 + size_t tree_codes_len;
125354 + unsigned char tree_codes[CODES_LIMIT];
125355 + const_tree fndecl;
125356 + unsigned int hash;
125357 +};
125358 +
125359 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
125360 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
125361 +{
125362 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
125363 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
125364 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
125365 +
125366 + unsigned int m = 0x57559429;
125367 + unsigned int n = 0x5052acdb;
125368 + const unsigned int *key4 = (const unsigned int *)key;
125369 + unsigned int h = len;
125370 + unsigned int k = len + seed + n;
125371 + unsigned long long p;
125372 +
125373 + while (len >= 8) {
125374 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
125375 + len -= 8;
125376 + }
125377 + if (len >= 4) {
125378 + cwmixb(key4[0]) key4 += 1;
125379 + len -= 4;
125380 + }
125381 + if (len)
125382 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
125383 + cwmixb(h ^ (k + n));
125384 + return k ^ h;
125385 +
125386 +#undef cwfold
125387 +#undef cwmixa
125388 +#undef cwmixb
125389 +}
125390 +
125391 +static void set_hash(const char *fn_name, struct function_hash *fn_hash_data)
125392 +{
125393 + unsigned int fn, codes, seed = 0;
125394 +
125395 + fn = CrapWow(fn_name, strlen(fn_name), seed) & 0xffff;
125396 + codes = CrapWow((const char*)fn_hash_data->tree_codes, fn_hash_data->tree_codes_len, seed) & 0xffff;
125397 +
125398 + fn_hash_data->hash = fn ^ codes;
125399 +}
125400 +
125401 +static void set_node_codes(const_tree type, struct function_hash *fn_hash_data)
125402 +{
125403 + gcc_assert(type != NULL_TREE);
125404 + gcc_assert(TREE_CODE_CLASS(TREE_CODE(type)) == tcc_type);
125405 +
125406 + while (type && fn_hash_data->tree_codes_len < CODES_LIMIT) {
125407 + fn_hash_data->tree_codes[fn_hash_data->tree_codes_len] = get_tree_code(type);
125408 + fn_hash_data->tree_codes_len++;
125409 + type = TREE_TYPE(type);
125410 + }
125411 +}
125412 +
125413 +static void set_result_codes(const_tree node, struct function_hash *fn_hash_data)
125414 +{
125415 + const_tree result;
125416 +
125417 + gcc_assert(node != NULL_TREE);
125418 +
125419 + if (DECL_P(node)) {
125420 + result = DECL_RESULT(node);
125421 + if (result != NULL_TREE)
125422 + return set_node_codes(TREE_TYPE(result), fn_hash_data);
125423 + return set_result_codes(TREE_TYPE(node), fn_hash_data);
125424 + }
125425 +
125426 + gcc_assert(TYPE_P(node));
125427 +
125428 + if (TREE_CODE(node) == FUNCTION_TYPE)
125429 + return set_result_codes(TREE_TYPE(node), fn_hash_data);
125430 +
125431 + return set_node_codes(node, fn_hash_data);
125432 +}
125433 +
125434 +static void set_function_codes(struct function_hash *fn_hash_data)
125435 +{
125436 + const_tree arg, type = TREE_TYPE(fn_hash_data->fndecl);
125437 + enum tree_code code = TREE_CODE(type);
125438 +
125439 + gcc_assert(code == FUNCTION_TYPE || code == METHOD_TYPE);
125440 +
125441 + set_result_codes(fn_hash_data->fndecl, fn_hash_data);
125442 +
125443 + for (arg = TYPE_ARG_TYPES(type); arg != NULL_TREE && fn_hash_data->tree_codes_len < CODES_LIMIT; arg = TREE_CHAIN(arg))
125444 + set_node_codes(TREE_VALUE(arg), fn_hash_data);
125445 +}
125446 +
125447 +static const struct size_overflow_hash *get_proper_hash_chain(const struct size_overflow_hash *entry, const char *func_name)
125448 +{
125449 + while (entry) {
125450 + if (!strcmp(entry->name, func_name))
125451 + return entry;
125452 + entry = entry->next;
125453 + }
125454 + return NULL;
125455 +}
125456 +
125457 +const struct size_overflow_hash *get_function_hash(const_tree fndecl)
125458 +{
125459 + const struct size_overflow_hash *entry;
125460 + struct function_hash fn_hash_data;
125461 + const char *func_name;
125462 +
125463 + // skip builtins __builtin_constant_p
125464 + if (DECL_BUILT_IN(fndecl))
125465 + return NULL;
125466 +
125467 + fn_hash_data.fndecl = fndecl;
125468 + fn_hash_data.tree_codes_len = 0;
125469 +
125470 + set_function_codes(&fn_hash_data);
125471 + gcc_assert(fn_hash_data.tree_codes_len != 0);
125472 +
125473 + func_name = DECL_NAME_POINTER(fn_hash_data.fndecl);
125474 + set_hash(func_name, &fn_hash_data);
125475 +
125476 + entry = size_overflow_hash[fn_hash_data.hash];
125477 + entry = get_proper_hash_chain(entry, func_name);
125478 + if (entry)
125479 + return entry;
125480 + entry = size_overflow_hash_aux[fn_hash_data.hash];
125481 + return get_proper_hash_chain(entry, func_name);
125482 +}
125483 +
125484 +static void print_missing_msg(const_tree func, unsigned int argnum)
125485 +{
125486 + location_t loc;
125487 + const char *curfunc;
125488 + struct function_hash fn_hash_data;
125489 +
125490 + fn_hash_data.fndecl = DECL_ORIGIN(func);
125491 + fn_hash_data.tree_codes_len = 0;
125492 +
125493 + loc = DECL_SOURCE_LOCATION(fn_hash_data.fndecl);
125494 + curfunc = DECL_NAME_POINTER(fn_hash_data.fndecl);
125495 +
125496 + set_function_codes(&fn_hash_data);
125497 + set_hash(curfunc, &fn_hash_data);
125498 +
125499 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%u+%u+", curfunc, curfunc, argnum, fn_hash_data.hash);
125500 +}
125501 +
125502 +unsigned int find_arg_number_tree(const_tree arg, const_tree func)
125503 +{
125504 + tree var;
125505 + unsigned int argnum = 1;
125506 +
125507 + if (TREE_CODE(arg) == SSA_NAME)
125508 + arg = SSA_NAME_VAR(arg);
125509 +
125510 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var), argnum++) {
125511 + if (!operand_equal_p(arg, var, 0) && strcmp(DECL_NAME_POINTER(var), DECL_NAME_POINTER(arg)))
125512 + continue;
125513 + if (!skip_types(var))
125514 + return argnum;
125515 + }
125516 +
125517 + return CANNOT_FIND_ARG;
125518 +}
125519 +
125520 +static const char *get_asm_string(const_gimple stmt)
125521 +{
125522 + if (!stmt)
125523 + return NULL;
125524 + if (gimple_code(stmt) != GIMPLE_ASM)
125525 + return NULL;
125526 +
125527 + return gimple_asm_string(stmt);
125528 +}
125529 +
125530 +bool is_size_overflow_intentional_asm_turn_off(const_gimple stmt)
125531 +{
125532 + const char *str;
125533 +
125534 + str = get_asm_string(stmt);
125535 + if (!str)
125536 + return false;
125537 + return !strncmp(str, TURN_OFF_ASM_STR, sizeof(TURN_OFF_ASM_STR) - 1);
125538 +}
125539 +
125540 +bool is_size_overflow_intentional_asm_yes(const_gimple stmt)
125541 +{
125542 + const char *str;
125543 +
125544 + str = get_asm_string(stmt);
125545 + if (!str)
125546 + return false;
125547 + return !strncmp(str, YES_ASM_STR, sizeof(YES_ASM_STR) - 1);
125548 +}
125549 +
125550 +bool is_size_overflow_asm(const_gimple stmt)
125551 +{
125552 + const char *str;
125553 +
125554 + str = get_asm_string(stmt);
125555 + if (!str)
125556 + return false;
125557 + return !strncmp(str, OK_ASM_STR, sizeof(OK_ASM_STR) - 1);
125558 +}
125559 +
125560 +bool is_a_return_check(const_tree node)
125561 +{
125562 + if (TREE_CODE(node) == FUNCTION_DECL)
125563 + return true;
125564 +
125565 + gcc_assert(TREE_CODE(node) == PARM_DECL);
125566 + return false;
125567 +}
125568 +
125569 +// Get the argnum of a function decl, if node is a return then the argnum is 0
125570 +unsigned int get_function_num(const_tree node, const_tree orig_fndecl)
125571 +{
125572 + if (is_a_return_check(node))
125573 + return 0;
125574 + else
125575 + return find_arg_number_tree(node, orig_fndecl);
125576 +}
125577 +
125578 +unsigned int get_correct_arg_count(unsigned int argnum, const_tree fndecl)
125579 +{
125580 + const struct size_overflow_hash *hash;
125581 + unsigned int new_argnum;
125582 + tree arg;
125583 + const_tree origarg;
125584 +
125585 + if (argnum == 0)
125586 + return argnum;
125587 +
125588 + hash = get_function_hash(fndecl);
125589 + if (hash && hash->param & (1U << argnum))
125590 + return argnum;
125591 +
125592 + if (DECL_EXTERNAL(fndecl))
125593 + return argnum;
125594 +
125595 + origarg = DECL_ARGUMENTS(DECL_ORIGIN(fndecl));
125596 + argnum--;
125597 + while (origarg && argnum) {
125598 + origarg = TREE_CHAIN(origarg);
125599 + argnum--;
125600 + }
125601 + gcc_assert(argnum == 0);
125602 + gcc_assert(origarg != NULL_TREE);
125603 +
125604 + for (arg = DECL_ARGUMENTS(fndecl), new_argnum = 1; arg; arg = TREE_CHAIN(arg), new_argnum++)
125605 + if (operand_equal_p(origarg, arg, 0) || !strcmp(DECL_NAME_POINTER(origarg), DECL_NAME_POINTER(arg)))
125606 + return new_argnum;
125607 +
125608 + return CANNOT_FIND_ARG;
125609 +}
125610 +
125611 +static bool is_in_hash_table(const_tree fndecl, unsigned int num)
125612 +{
125613 + const struct size_overflow_hash *hash;
125614 +
125615 + hash = get_function_hash(fndecl);
125616 + if (hash && (hash->param & (1U << num)))
125617 + return true;
125618 + return false;
125619 +}
125620 +
125621 +/* Check if the function has a size_overflow attribute or it is in the size_overflow hash table.
125622 + * If the function is missing everywhere then print the missing message into stderr.
125623 + */
125624 +bool is_missing_function(const_tree orig_fndecl, unsigned int num)
125625 +{
125626 + switch (DECL_FUNCTION_CODE(orig_fndecl)) {
125627 +#if BUILDING_GCC_VERSION >= 4008
125628 + case BUILT_IN_BSWAP16:
125629 +#endif
125630 + case BUILT_IN_BSWAP32:
125631 + case BUILT_IN_BSWAP64:
125632 + case BUILT_IN_EXPECT:
125633 + case BUILT_IN_MEMCMP:
125634 + return false;
125635 + default:
125636 + break;
125637 + }
125638 +
125639 + // skip test.c
125640 + if (strcmp(DECL_NAME_POINTER(current_function_decl), "coolmalloc")) {
125641 + if (lookup_attribute("size_overflow", DECL_ATTRIBUTES(orig_fndecl)))
125642 + warning(0, "unnecessary size_overflow attribute on: %s\n", DECL_NAME_POINTER(orig_fndecl));
125643 + }
125644 +
125645 + if (is_in_hash_table(orig_fndecl, num))
125646 + return false;
125647 +
125648 + print_missing_msg(orig_fndecl, num);
125649 + return true;
125650 +}
125651 +
125652 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
125653 new file mode 100644
125654 index 0000000..924652b
125655 --- /dev/null
125656 +++ b/tools/gcc/stackleak_plugin.c
125657 @@ -0,0 +1,395 @@
125658 +/*
125659 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
125660 + * Licensed under the GPL v2
125661 + *
125662 + * Note: the choice of the license means that the compilation process is
125663 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
125664 + * but for the kernel it doesn't matter since it doesn't link against
125665 + * any of the gcc libraries
125666 + *
125667 + * gcc plugin to help implement various PaX features
125668 + *
125669 + * - track lowest stack pointer
125670 + *
125671 + * TODO:
125672 + * - initialize all local variables
125673 + *
125674 + * BUGS:
125675 + * - none known
125676 + */
125677 +
125678 +#include "gcc-common.h"
125679 +
125680 +int plugin_is_GPL_compatible;
125681 +
125682 +static int track_frame_size = -1;
125683 +static const char track_function[] = "pax_track_stack";
125684 +static const char check_function[] = "pax_check_alloca";
125685 +static tree track_function_decl, check_function_decl;
125686 +static bool init_locals;
125687 +
125688 +static struct plugin_info stackleak_plugin_info = {
125689 + .version = "201408011900",
125690 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
125691 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
125692 +};
125693 +
125694 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
125695 +{
125696 + gimple check_alloca;
125697 + tree alloca_size;
125698 +
125699 + // insert call to void pax_check_alloca(unsigned long size)
125700 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
125701 + check_alloca = gimple_build_call(check_function_decl, 1, alloca_size);
125702 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
125703 +}
125704 +
125705 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
125706 +{
125707 + gimple track_stack;
125708 +
125709 + // insert call to void pax_track_stack(void)
125710 + track_stack = gimple_build_call(track_function_decl, 0);
125711 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
125712 +}
125713 +
125714 +static bool is_alloca(gimple stmt)
125715 +{
125716 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
125717 + return true;
125718 +
125719 +#if BUILDING_GCC_VERSION >= 4007
125720 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
125721 + return true;
125722 +#endif
125723 +
125724 + return false;
125725 +}
125726 +
125727 +static unsigned int execute_stackleak_tree_instrument(void)
125728 +{
125729 + basic_block bb, entry_bb;
125730 + bool prologue_instrumented = false, is_leaf = true;
125731 +
125732 + entry_bb = ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb;
125733 +
125734 + // 1. loop through BBs and GIMPLE statements
125735 + FOR_EACH_BB_FN(bb, cfun) {
125736 + gimple_stmt_iterator gsi;
125737 +
125738 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
125739 + gimple stmt;
125740 +
125741 + stmt = gsi_stmt(gsi);
125742 +
125743 + if (is_gimple_call(stmt))
125744 + is_leaf = false;
125745 +
125746 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
125747 + if (!is_alloca(stmt))
125748 + continue;
125749 +
125750 + // 2. insert stack overflow check before each __builtin_alloca call
125751 + stackleak_check_alloca(&gsi);
125752 +
125753 + // 3. insert track call after each __builtin_alloca call
125754 + stackleak_add_instrumentation(&gsi);
125755 + if (bb == entry_bb)
125756 + prologue_instrumented = true;
125757 + }
125758 + }
125759 +
125760 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
125761 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
125762 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
125763 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
125764 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
125765 + return 0;
125766 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
125767 + return 0;
125768 +
125769 + // 4. insert track call at the beginning
125770 + if (!prologue_instrumented) {
125771 + gimple_stmt_iterator gsi;
125772 +
125773 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
125774 + if (dom_info_available_p(CDI_DOMINATORS))
125775 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
125776 + gsi = gsi_start_bb(bb);
125777 + stackleak_add_instrumentation(&gsi);
125778 + }
125779 +
125780 + return 0;
125781 +}
125782 +
125783 +static unsigned int execute_stackleak_final(void)
125784 +{
125785 + rtx insn, next;
125786 +
125787 + if (cfun->calls_alloca)
125788 + return 0;
125789 +
125790 + // keep calls only if function frame is big enough
125791 + if (get_frame_size() >= track_frame_size)
125792 + return 0;
125793 +
125794 + // 1. find pax_track_stack calls
125795 + for (insn = get_insns(); insn; insn = next) {
125796 + // 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))
125797 + rtx body;
125798 +
125799 + next = NEXT_INSN(insn);
125800 + if (!CALL_P(insn))
125801 + continue;
125802 + body = PATTERN(insn);
125803 + if (GET_CODE(body) != CALL)
125804 + continue;
125805 + body = XEXP(body, 0);
125806 + if (GET_CODE(body) != MEM)
125807 + continue;
125808 + body = XEXP(body, 0);
125809 + if (GET_CODE(body) != SYMBOL_REF)
125810 + continue;
125811 +// if (strcmp(XSTR(body, 0), track_function))
125812 + if (SYMBOL_REF_DECL(body) != track_function_decl)
125813 + continue;
125814 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
125815 + // 2. delete call
125816 + delete_insn_and_edges(insn);
125817 +#if BUILDING_GCC_VERSION >= 4007
125818 + if (GET_CODE(next) == NOTE && NOTE_KIND(next) == NOTE_INSN_CALL_ARG_LOCATION) {
125819 + insn = next;
125820 + next = NEXT_INSN(insn);
125821 + delete_insn_and_edges(insn);
125822 + }
125823 +#endif
125824 + }
125825 +
125826 +// print_simple_rtl(stderr, get_insns());
125827 +// print_rtl(stderr, get_insns());
125828 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
125829 +
125830 + return 0;
125831 +}
125832 +
125833 +static bool gate_stackleak_track_stack(void)
125834 +{
125835 + tree section;
125836 +
125837 + if (ix86_cmodel != CM_KERNEL)
125838 + return false;
125839 +
125840 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
125841 + if (section && TREE_VALUE(section)) {
125842 + section = TREE_VALUE(TREE_VALUE(section));
125843 +
125844 + if (!strncmp(TREE_STRING_POINTER(section), ".init.text", 10))
125845 + return false;
125846 + if (!strncmp(TREE_STRING_POINTER(section), ".devinit.text", 13))
125847 + return false;
125848 + if (!strncmp(TREE_STRING_POINTER(section), ".cpuinit.text", 13))
125849 + return false;
125850 + if (!strncmp(TREE_STRING_POINTER(section), ".meminit.text", 13))
125851 + return false;
125852 + }
125853 +
125854 + return track_frame_size >= 0;
125855 +}
125856 +
125857 +static void stackleak_start_unit(void *gcc_data, void *user_data)
125858 +{
125859 + tree fntype;
125860 +
125861 + // void pax_track_stack(void)
125862 + fntype = build_function_type_list(void_type_node, NULL_TREE);
125863 + track_function_decl = build_fn_decl(track_function, fntype);
125864 + DECL_ASSEMBLER_NAME(track_function_decl); // for LTO
125865 + TREE_PUBLIC(track_function_decl) = 1;
125866 + DECL_EXTERNAL(track_function_decl) = 1;
125867 + DECL_ARTIFICIAL(track_function_decl) = 1;
125868 +
125869 + // void pax_check_alloca(unsigned long)
125870 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
125871 + check_function_decl = build_fn_decl(check_function, fntype);
125872 + DECL_ASSEMBLER_NAME(check_function_decl); // for LTO
125873 + TREE_PUBLIC(check_function_decl) = 1;
125874 + DECL_EXTERNAL(check_function_decl) = 1;
125875 + DECL_ARTIFICIAL(check_function_decl) = 1;
125876 +}
125877 +
125878 +#if BUILDING_GCC_VERSION >= 4009
125879 +static const struct pass_data stackleak_tree_instrument_pass_data = {
125880 +#else
125881 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
125882 + .pass = {
125883 +#endif
125884 + .type = GIMPLE_PASS,
125885 + .name = "stackleak_tree_instrument",
125886 +#if BUILDING_GCC_VERSION >= 4008
125887 + .optinfo_flags = OPTGROUP_NONE,
125888 +#endif
125889 +#if BUILDING_GCC_VERSION >= 4009
125890 + .has_gate = true,
125891 + .has_execute = true,
125892 +#else
125893 + .gate = gate_stackleak_track_stack,
125894 + .execute = execute_stackleak_tree_instrument,
125895 + .sub = NULL,
125896 + .next = NULL,
125897 + .static_pass_number = 0,
125898 +#endif
125899 + .tv_id = TV_NONE,
125900 + .properties_required = PROP_gimple_leh | PROP_cfg,
125901 + .properties_provided = 0,
125902 + .properties_destroyed = 0,
125903 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
125904 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa | TODO_rebuild_cgraph_edges
125905 +#if BUILDING_GCC_VERSION < 4009
125906 + }
125907 +#endif
125908 +};
125909 +
125910 +#if BUILDING_GCC_VERSION >= 4009
125911 +static const struct pass_data stackleak_final_rtl_opt_pass_data = {
125912 +#else
125913 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
125914 + .pass = {
125915 +#endif
125916 + .type = RTL_PASS,
125917 + .name = "stackleak_final",
125918 +#if BUILDING_GCC_VERSION >= 4008
125919 + .optinfo_flags = OPTGROUP_NONE,
125920 +#endif
125921 +#if BUILDING_GCC_VERSION >= 4009
125922 + .has_gate = true,
125923 + .has_execute = true,
125924 +#else
125925 + .gate = gate_stackleak_track_stack,
125926 + .execute = execute_stackleak_final,
125927 + .sub = NULL,
125928 + .next = NULL,
125929 + .static_pass_number = 0,
125930 +#endif
125931 + .tv_id = TV_NONE,
125932 + .properties_required = 0,
125933 + .properties_provided = 0,
125934 + .properties_destroyed = 0,
125935 + .todo_flags_start = 0,
125936 + .todo_flags_finish = TODO_dump_func
125937 +#if BUILDING_GCC_VERSION < 4009
125938 + }
125939 +#endif
125940 +};
125941 +
125942 +#if BUILDING_GCC_VERSION >= 4009
125943 +namespace {
125944 +class stackleak_tree_instrument_pass : public gimple_opt_pass {
125945 +public:
125946 + stackleak_tree_instrument_pass() : gimple_opt_pass(stackleak_tree_instrument_pass_data, g) {}
125947 + bool gate() { return gate_stackleak_track_stack(); }
125948 + unsigned int execute() { return execute_stackleak_tree_instrument(); }
125949 +};
125950 +
125951 +class stackleak_final_rtl_opt_pass : public rtl_opt_pass {
125952 +public:
125953 + stackleak_final_rtl_opt_pass() : rtl_opt_pass(stackleak_final_rtl_opt_pass_data, g) {}
125954 + bool gate() { return gate_stackleak_track_stack(); }
125955 + unsigned int execute() { return execute_stackleak_final(); }
125956 +};
125957 +}
125958 +
125959 +static opt_pass *make_stackleak_tree_instrument_pass(void)
125960 +{
125961 + return new stackleak_tree_instrument_pass();
125962 +}
125963 +
125964 +static opt_pass *make_stackleak_final_rtl_opt_pass(void)
125965 +{
125966 + return new stackleak_final_rtl_opt_pass();
125967 +}
125968 +#else
125969 +static struct opt_pass *make_stackleak_tree_instrument_pass(void)
125970 +{
125971 + return &stackleak_tree_instrument_pass.pass;
125972 +}
125973 +
125974 +static struct opt_pass *make_stackleak_final_rtl_opt_pass(void)
125975 +{
125976 + return &stackleak_final_rtl_opt_pass.pass;
125977 +}
125978 +#endif
125979 +
125980 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
125981 +{
125982 + const char * const plugin_name = plugin_info->base_name;
125983 + const int argc = plugin_info->argc;
125984 + const struct plugin_argument * const argv = plugin_info->argv;
125985 + int i;
125986 + struct register_pass_info stackleak_tree_instrument_pass_info;
125987 + struct register_pass_info stackleak_final_pass_info;
125988 + static const struct ggc_root_tab gt_ggc_r_gt_stackleak[] = {
125989 + {
125990 + .base = &track_function_decl,
125991 + .nelt = 1,
125992 + .stride = sizeof(track_function_decl),
125993 + .cb = &gt_ggc_mx_tree_node,
125994 + .pchw = &gt_pch_nx_tree_node
125995 + },
125996 + {
125997 + .base = &check_function_decl,
125998 + .nelt = 1,
125999 + .stride = sizeof(check_function_decl),
126000 + .cb = &gt_ggc_mx_tree_node,
126001 + .pchw = &gt_pch_nx_tree_node
126002 + },
126003 + LAST_GGC_ROOT_TAB
126004 + };
126005 +
126006 + stackleak_tree_instrument_pass_info.pass = make_stackleak_tree_instrument_pass();
126007 +// stackleak_tree_instrument_pass_info.reference_pass_name = "tree_profile";
126008 + stackleak_tree_instrument_pass_info.reference_pass_name = "optimized";
126009 + stackleak_tree_instrument_pass_info.ref_pass_instance_number = 1;
126010 + stackleak_tree_instrument_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
126011 +
126012 + stackleak_final_pass_info.pass = make_stackleak_final_rtl_opt_pass();
126013 + stackleak_final_pass_info.reference_pass_name = "final";
126014 + stackleak_final_pass_info.ref_pass_instance_number = 1;
126015 + stackleak_final_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
126016 +
126017 + if (!plugin_default_version_check(version, &gcc_version)) {
126018 + error(G_("incompatible gcc/plugin versions"));
126019 + return 1;
126020 + }
126021 +
126022 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
126023 +
126024 + for (i = 0; i < argc; ++i) {
126025 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
126026 + if (!argv[i].value) {
126027 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
126028 + continue;
126029 + }
126030 + track_frame_size = atoi(argv[i].value);
126031 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
126032 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
126033 + continue;
126034 + }
126035 + if (!strcmp(argv[i].key, "initialize-locals")) {
126036 + if (argv[i].value) {
126037 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
126038 + continue;
126039 + }
126040 + init_locals = true;
126041 + continue;
126042 + }
126043 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
126044 + }
126045 +
126046 + register_callback(plugin_name, PLUGIN_START_UNIT, &stackleak_start_unit, NULL);
126047 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_stackleak);
126048 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
126049 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
126050 +
126051 + return 0;
126052 +}
126053 diff --git a/tools/gcc/structleak_plugin.c b/tools/gcc/structleak_plugin.c
126054 new file mode 100644
126055 index 0000000..4ee2231
126056 --- /dev/null
126057 +++ b/tools/gcc/structleak_plugin.c
126058 @@ -0,0 +1,274 @@
126059 +/*
126060 + * Copyright 2013-2014 by PaX Team <pageexec@freemail.hu>
126061 + * Licensed under the GPL v2
126062 + *
126063 + * Note: the choice of the license means that the compilation process is
126064 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
126065 + * but for the kernel it doesn't matter since it doesn't link against
126066 + * any of the gcc libraries
126067 + *
126068 + * gcc plugin to forcibly initialize certain local variables that could
126069 + * otherwise leak kernel stack to userland if they aren't properly initialized
126070 + * by later code
126071 + *
126072 + * Homepage: http://pax.grsecurity.net/
126073 + *
126074 + * Usage:
126075 + * $ # for 4.5/4.6/C based 4.7
126076 + * $ 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
126077 + * $ # for C++ based 4.7/4.8+
126078 + * $ 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
126079 + * $ gcc -fplugin=./structleak_plugin.so test.c -O2
126080 + *
126081 + * TODO: eliminate redundant initializers
126082 + * increase type coverage
126083 + */
126084 +
126085 +#include "gcc-common.h"
126086 +
126087 +// unused C type flag in all versions 4.5-4.9
126088 +#define TYPE_USERSPACE(TYPE) TYPE_LANG_FLAG_3(TYPE)
126089 +
126090 +int plugin_is_GPL_compatible;
126091 +
126092 +static struct plugin_info structleak_plugin_info = {
126093 + .version = "201401260140",
126094 + .help = "disable\tdo not activate plugin\n",
126095 +};
126096 +
126097 +static tree handle_user_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
126098 +{
126099 + *no_add_attrs = true;
126100 +
126101 + // check for types? for now accept everything linux has to offer
126102 + if (TREE_CODE(*node) != FIELD_DECL)
126103 + return NULL_TREE;
126104 +
126105 + *no_add_attrs = false;
126106 + return NULL_TREE;
126107 +}
126108 +
126109 +static struct attribute_spec user_attr = {
126110 + .name = "user",
126111 + .min_length = 0,
126112 + .max_length = 0,
126113 + .decl_required = false,
126114 + .type_required = false,
126115 + .function_type_required = false,
126116 + .handler = handle_user_attribute,
126117 +#if BUILDING_GCC_VERSION >= 4007
126118 + .affects_type_identity = true
126119 +#endif
126120 +};
126121 +
126122 +static void register_attributes(void *event_data, void *data)
126123 +{
126124 + register_attribute(&user_attr);
126125 +// register_attribute(&force_attr);
126126 +}
126127 +
126128 +static tree get_field_type(tree field)
126129 +{
126130 + return strip_array_types(TREE_TYPE(field));
126131 +}
126132 +
126133 +static bool is_userspace_type(tree type)
126134 +{
126135 + tree field;
126136 +
126137 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
126138 + tree fieldtype = get_field_type(field);
126139 + enum tree_code code = TREE_CODE(fieldtype);
126140 +
126141 + if (code == RECORD_TYPE || code == UNION_TYPE)
126142 + if (is_userspace_type(fieldtype))
126143 + return true;
126144 +
126145 + if (lookup_attribute("user", DECL_ATTRIBUTES(field)))
126146 + return true;
126147 + }
126148 + return false;
126149 +}
126150 +
126151 +static void finish_type(void *event_data, void *data)
126152 +{
126153 + tree type = (tree)event_data;
126154 +
126155 + if (TYPE_USERSPACE(type))
126156 + return;
126157 +
126158 + if (is_userspace_type(type))
126159 + TYPE_USERSPACE(type) = 1;
126160 +}
126161 +
126162 +static void initialize(tree var)
126163 +{
126164 + basic_block bb;
126165 + gimple_stmt_iterator gsi;
126166 + tree initializer;
126167 + gimple init_stmt;
126168 +
126169 + // this is the original entry bb before the forced split
126170 + // TODO: check further BBs in case more splits occured before us
126171 + bb = ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb->next_bb;
126172 +
126173 + // first check if the variable is already initialized, warn otherwise
126174 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
126175 + gimple stmt = gsi_stmt(gsi);
126176 + tree rhs1;
126177 +
126178 + // we're looking for an assignment of a single rhs...
126179 + if (!gimple_assign_single_p(stmt))
126180 + continue;
126181 + rhs1 = gimple_assign_rhs1(stmt);
126182 +#if BUILDING_GCC_VERSION >= 4007
126183 + // ... of a non-clobbering expression...
126184 + if (TREE_CLOBBER_P(rhs1))
126185 + continue;
126186 +#endif
126187 + // ... to our variable...
126188 + if (gimple_get_lhs(stmt) != var)
126189 + continue;
126190 + // if it's an initializer then we're good
126191 + if (TREE_CODE(rhs1) == CONSTRUCTOR)
126192 + return;
126193 + }
126194 +
126195 + // these aren't the 0days you're looking for
126196 +// inform(DECL_SOURCE_LOCATION(var), "userspace variable will be forcibly initialized");
126197 +
126198 + // build the initializer expression
126199 + initializer = build_constructor(TREE_TYPE(var), NULL);
126200 +
126201 + // build the initializer stmt
126202 + init_stmt = gimple_build_assign(var, initializer);
126203 + gsi = gsi_start_bb(ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb);
126204 + gsi_insert_before(&gsi, init_stmt, GSI_NEW_STMT);
126205 + update_stmt(init_stmt);
126206 +}
126207 +
126208 +static unsigned int handle_function(void)
126209 +{
126210 + basic_block bb;
126211 + unsigned int ret = 0;
126212 + tree var;
126213 + unsigned int i;
126214 +
126215 + // split the first bb where we can put the forced initializers
126216 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
126217 + if (dom_info_available_p(CDI_DOMINATORS))
126218 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
126219 +
126220 + // enumarate all local variables and forcibly initialize our targets
126221 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
126222 + tree type = TREE_TYPE(var);
126223 +
126224 + gcc_assert(DECL_P(var));
126225 + if (!auto_var_in_fn_p(var, current_function_decl))
126226 + continue;
126227 +
126228 + // only care about structure types
126229 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
126230 + continue;
126231 +
126232 + // if the type is of interest, examine the variable
126233 + if (TYPE_USERSPACE(type))
126234 + initialize(var);
126235 + }
126236 +
126237 + return ret;
126238 +}
126239 +
126240 +#if BUILDING_GCC_VERSION >= 4009
126241 +static const struct pass_data structleak_pass_data = {
126242 +#else
126243 +static struct gimple_opt_pass structleak_pass = {
126244 + .pass = {
126245 +#endif
126246 + .type = GIMPLE_PASS,
126247 + .name = "structleak",
126248 +#if BUILDING_GCC_VERSION >= 4008
126249 + .optinfo_flags = OPTGROUP_NONE,
126250 +#endif
126251 +#if BUILDING_GCC_VERSION >= 4009
126252 + .has_gate = false,
126253 + .has_execute = true,
126254 +#else
126255 + .gate = NULL,
126256 + .execute = handle_function,
126257 + .sub = NULL,
126258 + .next = NULL,
126259 + .static_pass_number = 0,
126260 +#endif
126261 + .tv_id = TV_NONE,
126262 + .properties_required = PROP_cfg,
126263 + .properties_provided = 0,
126264 + .properties_destroyed = 0,
126265 + .todo_flags_start = 0,
126266 + .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
126267 +#if BUILDING_GCC_VERSION < 4009
126268 + }
126269 +#endif
126270 +};
126271 +
126272 +#if BUILDING_GCC_VERSION >= 4009
126273 +namespace {
126274 +class structleak_pass : public gimple_opt_pass {
126275 +public:
126276 + structleak_pass() : gimple_opt_pass(structleak_pass_data, g) {}
126277 + unsigned int execute() { return handle_function(); }
126278 +};
126279 +}
126280 +
126281 +static opt_pass *make_structleak_pass(void)
126282 +{
126283 + return new structleak_pass();
126284 +}
126285 +#else
126286 +static struct opt_pass *make_structleak_pass(void)
126287 +{
126288 + return &structleak_pass.pass;
126289 +}
126290 +#endif
126291 +
126292 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
126293 +{
126294 + int i;
126295 + const char * const plugin_name = plugin_info->base_name;
126296 + const int argc = plugin_info->argc;
126297 + const struct plugin_argument * const argv = plugin_info->argv;
126298 + bool enable = true;
126299 + struct register_pass_info structleak_pass_info;
126300 +
126301 + structleak_pass_info.pass = make_structleak_pass();
126302 + structleak_pass_info.reference_pass_name = "ssa";
126303 + structleak_pass_info.ref_pass_instance_number = 1;
126304 + structleak_pass_info.pos_op = PASS_POS_INSERT_AFTER;
126305 +
126306 + if (!plugin_default_version_check(version, &gcc_version)) {
126307 + error(G_("incompatible gcc/plugin versions"));
126308 + return 1;
126309 + }
126310 +
126311 + if (strcmp(lang_hooks.name, "GNU C")) {
126312 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
126313 + enable = false;
126314 + }
126315 +
126316 + for (i = 0; i < argc; ++i) {
126317 + if (!strcmp(argv[i].key, "disable")) {
126318 + enable = false;
126319 + continue;
126320 + }
126321 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
126322 + }
126323 +
126324 + register_callback(plugin_name, PLUGIN_INFO, NULL, &structleak_plugin_info);
126325 + if (enable) {
126326 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &structleak_pass_info);
126327 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
126328 + }
126329 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
126330 +
126331 + return 0;
126332 +}
126333 diff --git a/tools/include/linux/compiler.h b/tools/include/linux/compiler.h
126334 index 88461f0..6fb70a0 100644
126335 --- a/tools/include/linux/compiler.h
126336 +++ b/tools/include/linux/compiler.h
126337 @@ -35,6 +35,14 @@
126338 # define unlikely(x) __builtin_expect(!!(x), 0)
126339 #endif
126340
126341 +#ifndef __size_overflow
126342 +# define __size_overflow(...)
126343 +#endif
126344 +
126345 +#ifndef __intentional_overflow
126346 +# define __intentional_overflow(...)
126347 +#endif
126348 +
126349 #define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
126350
126351 #endif /* _TOOLS_LINUX_COMPILER_H */
126352 diff --git a/tools/lib/api/Makefile b/tools/lib/api/Makefile
126353 index ce00f7e..0aca5e4 100644
126354 --- a/tools/lib/api/Makefile
126355 +++ b/tools/lib/api/Makefile
126356 @@ -16,7 +16,7 @@ LIB_OBJS += $(OUTPUT)fs/fs.o
126357
126358 LIBFILE = libapikfs.a
126359
126360 -CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) -fPIC
126361 +CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) -fPIC
126362 EXTLIBS = -lelf -lpthread -lrt -lm
126363 ALL_CFLAGS = $(CFLAGS) $(BASIC_CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
126364 ALL_LDFLAGS = $(LDFLAGS)
126365 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
126366 index 6789d788..4afd019e 100644
126367 --- a/tools/perf/util/include/asm/alternative-asm.h
126368 +++ b/tools/perf/util/include/asm/alternative-asm.h
126369 @@ -5,4 +5,7 @@
126370
126371 #define altinstruction_entry #
126372
126373 + .macro pax_force_retaddr rip=0, reload=0
126374 + .endm
126375 +
126376 #endif
126377 diff --git a/tools/virtio/linux/uaccess.h b/tools/virtio/linux/uaccess.h
126378 index 0a578fe..b81f62d 100644
126379 --- a/tools/virtio/linux/uaccess.h
126380 +++ b/tools/virtio/linux/uaccess.h
126381 @@ -13,7 +13,7 @@ static inline void __chk_user_ptr(const volatile void *p, size_t size)
126382 ({ \
126383 typeof(ptr) __pu_ptr = (ptr); \
126384 __chk_user_ptr(__pu_ptr, sizeof(*__pu_ptr)); \
126385 - ACCESS_ONCE(*(__pu_ptr)) = x; \
126386 + ACCESS_ONCE_RW(*(__pu_ptr)) = x; \
126387 0; \
126388 })
126389
126390 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
126391 index 6a3f29b..a1d2e93 100644
126392 --- a/virt/kvm/kvm_main.c
126393 +++ b/virt/kvm/kvm_main.c
126394 @@ -77,12 +77,17 @@ LIST_HEAD(vm_list);
126395
126396 static cpumask_var_t cpus_hardware_enabled;
126397 static int kvm_usage_count = 0;
126398 -static atomic_t hardware_enable_failed;
126399 +static atomic_unchecked_t hardware_enable_failed;
126400
126401 struct kmem_cache *kvm_vcpu_cache;
126402 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
126403
126404 -static __read_mostly struct preempt_ops kvm_preempt_ops;
126405 +static void kvm_sched_in(struct preempt_notifier *pn, int cpu);
126406 +static void kvm_sched_out(struct preempt_notifier *pn, struct task_struct *next);
126407 +static struct preempt_ops kvm_preempt_ops = {
126408 + .sched_in = kvm_sched_in,
126409 + .sched_out = kvm_sched_out,
126410 +};
126411
126412 struct dentry *kvm_debugfs_dir;
126413
126414 @@ -780,7 +785,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
126415 /* We can read the guest memory with __xxx_user() later on. */
126416 if ((mem->slot < KVM_USER_MEM_SLOTS) &&
126417 ((mem->userspace_addr & (PAGE_SIZE - 1)) ||
126418 - !access_ok(VERIFY_WRITE,
126419 + !access_ok_noprefault(VERIFY_WRITE,
126420 (void __user *)(unsigned long)mem->userspace_addr,
126421 mem->memory_size)))
126422 goto out;
126423 @@ -1637,9 +1642,17 @@ EXPORT_SYMBOL_GPL(kvm_read_guest_cached);
126424
126425 int kvm_clear_guest_page(struct kvm *kvm, gfn_t gfn, int offset, int len)
126426 {
126427 - const void *zero_page = (const void *) __va(page_to_phys(ZERO_PAGE(0)));
126428 + int r;
126429 + unsigned long addr;
126430
126431 - return kvm_write_guest_page(kvm, gfn, zero_page, offset, len);
126432 + addr = gfn_to_hva(kvm, gfn);
126433 + if (kvm_is_error_hva(addr))
126434 + return -EFAULT;
126435 + r = __clear_user((void __user *)addr + offset, len);
126436 + if (r)
126437 + return -EFAULT;
126438 + mark_page_dirty(kvm, gfn);
126439 + return 0;
126440 }
126441 EXPORT_SYMBOL_GPL(kvm_clear_guest_page);
126442
126443 @@ -1889,7 +1902,7 @@ static int kvm_vcpu_release(struct inode *inode, struct file *filp)
126444 return 0;
126445 }
126446
126447 -static struct file_operations kvm_vcpu_fops = {
126448 +static file_operations_no_const kvm_vcpu_fops __read_only = {
126449 .release = kvm_vcpu_release,
126450 .unlocked_ioctl = kvm_vcpu_ioctl,
126451 #ifdef CONFIG_COMPAT
126452 @@ -2593,7 +2606,7 @@ out:
126453 }
126454 #endif
126455
126456 -static struct file_operations kvm_vm_fops = {
126457 +static file_operations_no_const kvm_vm_fops __read_only = {
126458 .release = kvm_vm_release,
126459 .unlocked_ioctl = kvm_vm_ioctl,
126460 #ifdef CONFIG_COMPAT
126461 @@ -2666,7 +2679,7 @@ out:
126462 return r;
126463 }
126464
126465 -static struct file_operations kvm_chardev_ops = {
126466 +static file_operations_no_const kvm_chardev_ops __read_only = {
126467 .unlocked_ioctl = kvm_dev_ioctl,
126468 .compat_ioctl = kvm_dev_ioctl,
126469 .llseek = noop_llseek,
126470 @@ -2692,7 +2705,7 @@ static void hardware_enable_nolock(void *junk)
126471
126472 if (r) {
126473 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
126474 - atomic_inc(&hardware_enable_failed);
126475 + atomic_inc_unchecked(&hardware_enable_failed);
126476 printk(KERN_INFO "kvm: enabling virtualization on "
126477 "CPU%d failed\n", cpu);
126478 }
126479 @@ -2748,10 +2761,10 @@ static int hardware_enable_all(void)
126480
126481 kvm_usage_count++;
126482 if (kvm_usage_count == 1) {
126483 - atomic_set(&hardware_enable_failed, 0);
126484 + atomic_set_unchecked(&hardware_enable_failed, 0);
126485 on_each_cpu(hardware_enable_nolock, NULL, 1);
126486
126487 - if (atomic_read(&hardware_enable_failed)) {
126488 + if (atomic_read_unchecked(&hardware_enable_failed)) {
126489 hardware_disable_all_nolock();
126490 r = -EBUSY;
126491 }
126492 @@ -3156,7 +3169,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
126493 kvm_arch_vcpu_put(vcpu);
126494 }
126495
126496 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
126497 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
126498 struct module *module)
126499 {
126500 int r;
126501 @@ -3203,7 +3216,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
126502 if (!vcpu_align)
126503 vcpu_align = __alignof__(struct kvm_vcpu);
126504 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
126505 - 0, NULL);
126506 + SLAB_USERCOPY, NULL);
126507 if (!kvm_vcpu_cache) {
126508 r = -ENOMEM;
126509 goto out_free_3;
126510 @@ -3213,9 +3226,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
126511 if (r)
126512 goto out_free;
126513
126514 + pax_open_kernel();
126515 kvm_chardev_ops.owner = module;
126516 kvm_vm_fops.owner = module;
126517 kvm_vcpu_fops.owner = module;
126518 + pax_close_kernel();
126519
126520 r = misc_register(&kvm_dev);
126521 if (r) {
126522 @@ -3225,9 +3240,6 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
126523
126524 register_syscore_ops(&kvm_syscore_ops);
126525
126526 - kvm_preempt_ops.sched_in = kvm_sched_in;
126527 - kvm_preempt_ops.sched_out = kvm_sched_out;
126528 -
126529 r = kvm_init_debug();
126530 if (r) {
126531 printk(KERN_ERR "kvm: create debugfs files failed\n");